Skip to content

Commit

Permalink
feat: add quick pay function and add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
si3nloong committed Nov 15, 2019
1 parent e9b9daa commit 33fe83c
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 4 deletions.
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -144,7 +145,7 @@ try {
echo $e->getMessage();
}


// create Web payment
try {
$wp = new WebPayment;
$wp->order->id = '10020';
Expand All @@ -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();
}
```
3 changes: 2 additions & 1 deletion src/Modules/PaymentModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use RevenueMonster\SDK\Request\WebPayment;
use RevenueMonster\SDK\Request\QRPay;
use RevenueMonster\SDK\Request\QuickPay;

class PaymentModule extends Module
{
Expand Down Expand Up @@ -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();
Expand Down
50 changes: 50 additions & 0 deletions src/Request/QuickPay.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace RevenueMonster\SDK\Request;

use Exception;
use JsonSerializable;
use Rakit\Validation\Validator;
use RevenueMonster\SDK\Request\Order;
use RevenueMonster\SDK\Exceptions\ValidationException;

class QuickPay implements JsonSerializable
{
public $authCode;
public $order;
public $ipAddress;
public $terminalId;
public $storeId;

public function __construct(array $arguments = [])
{
$this->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;
}
}
20 changes: 19 additions & 1 deletion tests/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<div style="width: 100%; word-break: break-all;">';
Expand Down Expand Up @@ -84,6 +85,7 @@
// echo '</p>';
// $response = $rm->payment->qrCode('732eb1e935983d274695f250dee9eb75');
// echo '<p>';
echo '<p><b>QR Payment</b><p>';
var_dump($response);
// echo '</p>';
// $response = $rm->payment->transactionsByQrCode('732eb1e935983d274695f250dee9eb75');
Expand Down Expand Up @@ -117,7 +119,7 @@
echo '<p>'.$response->checkoutId.'</p>'; // Checkout ID
echo '<p>'.$response->url.'</p>'; // Payment gateway url

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

$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 '<p>QuickPay</p>';
$response = $rm->payment->quickPay($qp);
var_dump($response);

} catch(ApiException $e) {
echo "statusCode : {$e->getCode()}, errorCode : {$e->getErrorCode()}, errorMessage : {$e->getMessage()}";
} catch(ValidationException $e) {
Expand Down

0 comments on commit 33fe83c

Please sign in to comment.