diff --git a/README.md b/README.md index 7085c8e..99e0788 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,7 @@ use RevenueMonster\SDK\Exceptions\ApiException; use RevenueMonster\SDK\Exceptions\ValidationException; use RevenueMonster\SDK\Request\WebPayment; use RevenueMonster\SDK\Request\QRPay; +use RevenueMonster\SDK\Request\QuickPay; // Initialise sdk instance $rm = new RevenueMonster([ @@ -144,7 +145,7 @@ try { echo $e->getMessage(); } - +// create Web payment try { $wp = new WebPayment; $wp->order->id = '10020'; @@ -165,7 +166,29 @@ try { echo "statusCode : {$e->getCode()}, errorCode : {$e->getErrorCode()}, errorMessage : {$e->getMessage()}"; } catch(ValidationException $e) { var_dump($e->getMessage()); -} catch(Exception $e) { +} catch(Exception $e) { + echo $e->getMessage(); +} + +// create Quick pay +try { + $qp = new QuickPay; + $qp->authCode = '281011026026517778602435'; + $qp->order->id = '443'; + $qp->order->title = '【原味系列】 猫山王榴'; + $qp->order->currencyType = 'MYR'; + $qp->order->amount = 10; + $qp->order->detail = ''; + $qp->order->additionalData = 'SH20190819100656262762'; + $qp->ipAddress = '8.8.8.8'; + $qp->storeId = "1553067342153519097"; + + $response = $rm->payment->quickPay($qp); +} catch(ApiException $e) { + echo "statusCode : {$e->getCode()}, errorCode : {$e->getErrorCode()}, errorMessage : {$e->getMessage()}"; +} catch(ValidationException $e) { + var_dump($e->getMessage()); +} catch(Exception $e) { echo $e->getMessage(); } ``` diff --git a/src/Modules/PaymentModule.php b/src/Modules/PaymentModule.php index 380e588..72af955 100644 --- a/src/Modules/PaymentModule.php +++ b/src/Modules/PaymentModule.php @@ -4,6 +4,7 @@ use RevenueMonster\SDK\Request\WebPayment; use RevenueMonster\SDK\Request\QRPay; +use RevenueMonster\SDK\Request\QuickPay; class PaymentModule extends Module { @@ -40,7 +41,7 @@ public function transactionsByQrCode(string $qrCode, int $limit = 10) return $this->mapResponse($this->callApi('get', $uri)->send()); } - public function quickPay(array $args = []) + public function quickPay($args = []) { if ($args instanceof QuickPay) { $args = $args->jsonSerialize(); diff --git a/src/Request/QuickPay.php b/src/Request/QuickPay.php new file mode 100644 index 0000000..1032f48 --- /dev/null +++ b/src/Request/QuickPay.php @@ -0,0 +1,50 @@ +order = new Order; + } + + public function jsonSerialize() + { + $data = [ + 'authCode' => $this->authCode, + 'order' => $this->order->jsonSerialize(), + 'ipAddress' => $this->ipAddress, + 'terminalId' => $this->terminalId, + 'storeId' => $this->storeId, + ]; + + $validator = new Validator; + $validation = $validator->make($data, [ + 'authCode' => 'required', + 'order' => 'required', + 'ipAddress' => 'required|ip', + 'storeId' => 'required', + ]); + + $validation->validate(); + + if ($validation->fails()) { + throw new ValidationException($validation->errors()); + } + + return $data; + } +} diff --git a/tests/index.php b/tests/index.php index 9fc8b73..44c5c07 100644 --- a/tests/index.php +++ b/tests/index.php @@ -7,6 +7,7 @@ use RevenueMonster\SDK\Exceptions\ApiException; use RevenueMonster\SDK\Exceptions\ValidationException; use RevenueMonster\SDK\Request\QRPay; +use RevenueMonster\SDK\Request\QuickPay; use RevenueMonster\SDK\Request\WebPayment; echo '
'; @@ -84,6 +85,7 @@ // echo '

'; // $response = $rm->payment->qrCode('732eb1e935983d274695f250dee9eb75'); // echo '

'; + echo '

QR Payment

'; var_dump($response); // echo '

'; // $response = $rm->payment->transactionsByQrCode('732eb1e935983d274695f250dee9eb75'); @@ -117,7 +119,7 @@ echo '

'.$response->checkoutId.'

'; // Checkout ID echo '

'.$response->url.'

'; // Payment gateway url - $wp->order->id = '442'; + $wp->order->id = '48842'; $wp->order->title = '【原味系列】 猫山王榴'; $wp->order->currencyType = 'MYR'; $wp->order->amount = 13800; @@ -133,6 +135,22 @@ var_dump($response); echo '

'.$response->checkoutId.'

'; // Checkout ID echo '

'.$response->url.'

'; + + $qp = new QuickPay; + $qp->authCode = '281011026026517778602435'; + $qp->order->id = '443'; + $qp->order->title = '【原味系列】 猫山王榴'; + $qp->order->currencyType = 'MYR'; + $qp->order->amount = 10; + $qp->order->detail = ''; + $qp->order->additionalData = 'SH20190819100656262762'; + $qp->ipAddress = '8.8.8.8'; + $qp->storeId = "1553067342153519097"; + + echo '

QuickPay

'; + $response = $rm->payment->quickPay($qp); + var_dump($response); + } catch(ApiException $e) { echo "statusCode : {$e->getCode()}, errorCode : {$e->getErrorCode()}, errorMessage : {$e->getMessage()}"; } catch(ValidationException $e) {