From 414e72df687f00fb09de5eedd76092252db78cf4 Mon Sep 17 00:00:00 2001 From: Segun Mustafa Date: Fri, 20 Nov 2020 02:25:02 +0100 Subject: [PATCH] Upgrade implementation --- .gitignore | 3 +- composer.json | 3 +- example/order.php | 26 --- example/order_cancel.php | 24 --- example/order_status.php | 26 --- .../{ => accept_payment}/callback.php | 3 +- http_example/{ => accept_payment}/order.php | 26 +-- http_example/accept_payment/order_cancel.php | 21 ++ http_example/accept_payment/order_status.php | 17 ++ http_example/init.php | 21 +- http_example/order_status.php | 7 - http_example/transfer/bank/get_banks.php | 17 ++ http_example/transfer/bank/get_countries.php | 13 ++ http_example/transfer/bank/initiate.php | 18 ++ http_example/transfer/bank/order_status.php | 18 ++ .../transfer/bank/validate_account.php | 16 ++ http_example/transfer/wallet/initiate.php | 26 +++ http_example/transfer/wallet/order_status.php | 18 ++ .../transfer/wallet/validate_merchant.php | 16 ++ .../transfer/wallet/validate_user.php | 16 ++ readme.md | 171 ++++------------ src/Merchant.php | 37 ++++ src/MerchantCashier.php | 40 +--- src/MerchantTransfer.php | 190 ++++++++++++++++++ src/Payload/BankTransferRequest.php | 48 +++++ src/Payload/BanksRequest.php | 22 ++ src/Payload/OpayTransferRequest.php | 63 ++++++ src/Payload/OrderRequest.php | 9 +- src/Payload/ValidateBankAccountRequest.php | 28 +++ src/Payload/ValidateOpayMerchantRequest.php | 22 ++ src/Payload/ValidateOpayUserRequest.php | 22 ++ src/Result/BankTransferResponse.php | 21 ++ src/Result/BankTransferResponseData.php | 107 ++++++++++ src/Result/BanksResponse.php | 21 ++ src/Result/BanksResponseData.php | 44 ++++ src/Result/CountriesResponse.php | 22 ++ src/Result/CountriesResponseData.php | 53 +++++ src/Result/OpayTransferResponse.php | 21 ++ src/Result/OpayTransferResponseData.php | 116 +++++++++++ src/Result/OrderResponse.php | 39 +--- src/Result/Response.php | 63 ++++++ src/Result/ValidateBankAccountResponse.php | 21 ++ .../ValidateBankAccountResponseData.php | 44 ++++ src/Result/ValidateOpayMerchantResponse.php | 21 ++ .../ValidateOpayMerchantResponseData.php | 53 +++++ src/Result/ValidateOpayUserResponse.php | 21 ++ src/Result/ValidateOpayUserResponseData.php | 80 ++++++++ src/Utility/OpayConstants.php | 10 +- tests/Unit/MerchantCashierTest.php | 20 +- 49 files changed, 1449 insertions(+), 315 deletions(-) delete mode 100644 example/order.php delete mode 100644 example/order_cancel.php delete mode 100644 example/order_status.php rename http_example/{ => accept_payment}/callback.php (96%) rename http_example/{ => accept_payment}/order.php (57%) create mode 100644 http_example/accept_payment/order_cancel.php create mode 100644 http_example/accept_payment/order_status.php delete mode 100644 http_example/order_status.php create mode 100644 http_example/transfer/bank/get_banks.php create mode 100644 http_example/transfer/bank/get_countries.php create mode 100644 http_example/transfer/bank/initiate.php create mode 100644 http_example/transfer/bank/order_status.php create mode 100644 http_example/transfer/bank/validate_account.php create mode 100644 http_example/transfer/wallet/initiate.php create mode 100644 http_example/transfer/wallet/order_status.php create mode 100644 http_example/transfer/wallet/validate_merchant.php create mode 100644 http_example/transfer/wallet/validate_user.php create mode 100644 src/Merchant.php create mode 100644 src/MerchantTransfer.php create mode 100644 src/Payload/BankTransferRequest.php create mode 100644 src/Payload/BanksRequest.php create mode 100644 src/Payload/OpayTransferRequest.php create mode 100644 src/Payload/ValidateBankAccountRequest.php create mode 100644 src/Payload/ValidateOpayMerchantRequest.php create mode 100644 src/Payload/ValidateOpayUserRequest.php create mode 100644 src/Result/BankTransferResponse.php create mode 100644 src/Result/BankTransferResponseData.php create mode 100644 src/Result/BanksResponse.php create mode 100644 src/Result/BanksResponseData.php create mode 100644 src/Result/CountriesResponse.php create mode 100644 src/Result/CountriesResponseData.php create mode 100644 src/Result/OpayTransferResponse.php create mode 100644 src/Result/OpayTransferResponseData.php create mode 100644 src/Result/Response.php create mode 100644 src/Result/ValidateBankAccountResponse.php create mode 100644 src/Result/ValidateBankAccountResponseData.php create mode 100644 src/Result/ValidateOpayMerchantResponse.php create mode 100644 src/Result/ValidateOpayMerchantResponseData.php create mode 100644 src/Result/ValidateOpayUserResponse.php create mode 100644 src/Result/ValidateOpayUserResponseData.php diff --git a/.gitignore b/.gitignore index abd781f..4f1ecd7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /vendor/ composer.lock -/.idea \ No newline at end of file +/.idea +.phpunit.result.cache \ No newline at end of file diff --git a/composer.json b/composer.json index 234b01d..4da365c 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,8 @@ "php": ">=7.1", "guzzlehttp/guzzle": "~6.0", "ext-openssl": "*", - "ext-json": "*" + "ext-json": "*", + "symfony/var-dumper": "^5.1" }, "require-dev":{ "phpunit/phpunit": "^8.4" diff --git a/example/order.php b/example/order.php deleted file mode 100644 index 910b531..0000000 --- a/example/order.php +++ /dev/null @@ -1,26 +0,0 @@ -order($_orderRequest); - -$response = $merchantCashier->getOrderApiResult(); - -if($response->getCode() === "00000") { - var_dump($response->getData()); -} - - - diff --git a/example/order_cancel.php b/example/order_cancel.php deleted file mode 100644 index 69283ba..0000000 --- a/example/order_cancel.php +++ /dev/null @@ -1,24 +0,0 @@ -orderClose($_orderCloseRequest); - -$response = $merchantCashier->getOrderCloseApiResult(); - -if($response->getCode() === "00000") {; - echo $response->getData(); -} - - - diff --git a/example/order_status.php b/example/order_status.php deleted file mode 100644 index 238e7f2..0000000 --- a/example/order_status.php +++ /dev/null @@ -1,26 +0,0 @@ -orderStatus($_orderStatusRequest); - -$response = $merchantCashier->getOrderStatusApiResult(); - -if($response->getCode() === "00000") { - echo $response->getData(); -} - - - diff --git a/http_example/callback.php b/http_example/accept_payment/callback.php similarity index 96% rename from http_example/callback.php rename to http_example/accept_payment/callback.php index 59324de..f92064e 100644 --- a/http_example/callback.php +++ b/http_example/accept_payment/callback.php @@ -1,6 +1,5 @@ order($_orderRequest); $response = $merchantCashier->getOrderApiResult(); -echo "status : ". $response->getCode(). "
"; - +dump("status : ". $response->getCode()); if($response->getCode() === "00000") { - var_dump($response->getData()); + $_SESSION['orderNumberInSession'] = $response->getData()->getOrderNo(); + dump($response->getData()); +} else { + dump($response); } function getUserIP() { @@ -42,5 +44,5 @@ function getUserIP() { $ipaddress = 'UNKNOWN'; return $ipaddress; } -?> + diff --git a/http_example/accept_payment/order_cancel.php b/http_example/accept_payment/order_cancel.php new file mode 100644 index 0000000..5f6c15e --- /dev/null +++ b/http_example/accept_payment/order_cancel.php @@ -0,0 +1,21 @@ +orderClose($_orderCloseRequest); + +$response = $merchantCashier->getOrderCloseApiResult(); + +dump("status : ". $response->getCode()); +if ($response->getCode() === "00000") { + dump($response->getData()); +} else { + dump($response); +} + + + + + diff --git a/http_example/accept_payment/order_status.php b/http_example/accept_payment/order_status.php new file mode 100644 index 0000000..2731480 --- /dev/null +++ b/http_example/accept_payment/order_status.php @@ -0,0 +1,17 @@ +orderStatus($_orderStatusRequest); + +$response = $merchantCashier->getOrderStatusApiResult(); + +dump("status : ". $response->getCode()); +if($response->getCode() === "00000") { + dump($response->getData()); +} else { + dump($response); +} diff --git a/http_example/init.php b/http_example/init.php index 66a877c..9aa43b2 100644 --- a/http_example/init.php +++ b/http_example/init.php @@ -1,11 +1,18 @@ getBanks($getBanksRequest); +$response = $merchantTransfer->getBanksApiResult(); + +dump("status : ". $response->getCode()); + +if($response->getCode() === "00000") { + dump($response->getData()); +} else { + dump($response); +} \ No newline at end of file diff --git a/http_example/transfer/bank/get_countries.php b/http_example/transfer/bank/get_countries.php new file mode 100644 index 0000000..61a5a60 --- /dev/null +++ b/http_example/transfer/bank/get_countries.php @@ -0,0 +1,13 @@ +getCountries(); +$response = $merchantTransfer->getCountriesApiResult(); + +dump("status : ". $response->getCode()); + +if($response->getCode() === "00000") { + dump($response->getData()); +} else { + dump($response); +} \ No newline at end of file diff --git a/http_example/transfer/bank/initiate.php b/http_example/transfer/bank/initiate.php new file mode 100644 index 0000000..6923918 --- /dev/null +++ b/http_example/transfer/bank/initiate.php @@ -0,0 +1,18 @@ +bankTransfer($bankTransferRequest); +$response = $merchantTransfer->bankTransferApiResult(); + +dump("status : ". $response->getCode()); + +if($response->getCode() === "00000") { + $_SESSION['orderNumberInSession'] = $response->getData()->getOrderNo(); + dump($response->getData()); +} else { + dump($response); +} diff --git a/http_example/transfer/bank/order_status.php b/http_example/transfer/bank/order_status.php new file mode 100644 index 0000000..3e4d158 --- /dev/null +++ b/http_example/transfer/bank/order_status.php @@ -0,0 +1,18 @@ +transferStatus($_orderStatusRequest); +$response = $merchantTransfer->bankTransferStatusApiResult(); + +dump("status : ". $response->getCode()); + +if($response->getCode() === "00000") { + $_SESSION['orderNumberInSession'] = $response->getData()->getOrderNo(); + dump($response->getData()); +} else { + dump($response); +} \ No newline at end of file diff --git a/http_example/transfer/bank/validate_account.php b/http_example/transfer/bank/validate_account.php new file mode 100644 index 0000000..305625b --- /dev/null +++ b/http_example/transfer/bank/validate_account.php @@ -0,0 +1,16 @@ +validateAccount($validateBankAccountRequest); +$response = $merchantTransfer->validateBankAccountApiResult(); + +dump("status : ". $response->getCode()); + +if($response->getCode() === "00000") { + dump($response->getData()); +} else { + dump($response); +} diff --git a/http_example/transfer/wallet/initiate.php b/http_example/transfer/wallet/initiate.php new file mode 100644 index 0000000..18d5178 --- /dev/null +++ b/http_example/transfer/wallet/initiate.php @@ -0,0 +1,26 @@ +opayTransfer($opayTransferRequest); +$response = $merchantTransfer->opayTransferApiResult(); + +dump("status : ". $response->getCode()); + +if($response->getCode() === "00000") { + $_SESSION['orderNumberInSession'] = $response->getData()->getOrderNo(); + dump($response->getData()); +} else { + dump($response); +} diff --git a/http_example/transfer/wallet/order_status.php b/http_example/transfer/wallet/order_status.php new file mode 100644 index 0000000..3e25e96 --- /dev/null +++ b/http_example/transfer/wallet/order_status.php @@ -0,0 +1,18 @@ +transferStatus($_orderStatusRequest); +$response = $merchantTransfer->opayTransferStatusApiResult(); + +dump("status : ". $response->getCode()); + +if($response->getCode() === "00000") { + $_SESSION['orderNumberInSession'] = $response->getData()->getOrderNo(); + dump($response->getData()); +} else { + dump($response); +} \ No newline at end of file diff --git a/http_example/transfer/wallet/validate_merchant.php b/http_example/transfer/wallet/validate_merchant.php new file mode 100644 index 0000000..a6e9c97 --- /dev/null +++ b/http_example/transfer/wallet/validate_merchant.php @@ -0,0 +1,16 @@ +validateOpayMerchant($validateOpayMerchantRequest); +$response = $merchantTransfer->validateOpayMerchantApiResult(); + +dump("status : ". $response->getCode()); + +if($response->getCode() === "00000") { + dump($response->getData()); +} else { + dump($response); +} diff --git a/http_example/transfer/wallet/validate_user.php b/http_example/transfer/wallet/validate_user.php new file mode 100644 index 0000000..55c0d13 --- /dev/null +++ b/http_example/transfer/wallet/validate_user.php @@ -0,0 +1,16 @@ +validateOpayUser($validateOpayUserRequest); +$response = $merchantTransfer->validateOpayUserApiResult(); + +dump("status : ". $response->getCode()); + +if($response->getCode() === "00000") { + dump($response->getData()); +} else { + dump($response); +} diff --git a/readme.md b/readme.md index 5d9dfc4..a34d673 100644 --- a/readme.md +++ b/readme.md @@ -1,145 +1,54 @@ -## Opay Merchant Cashier v3 +## OPay Payment v3 ![](https://github.com/actions/opay-merchant-cashier-php/workflows/.github/workflows/php.yml/badge.svg) -Merchant Pre-Order API (For onboarded OPay merchants only) +PHP Library that wraps endpoints documented [https://documentation.opayweb.com/](https://documentation.opayweb.com/) -### Installation: +##### Services available for merchants includes and not limited to: +- Cashier/Checkout - Get Paid with OPay +- Bank Transfer - Send money to any Nigerian bank account(s) +- OPay wallet Transfer - Send money to OPay USER/MERCHANT seamlessly + +#### Installation: ```sh $ composer require opay/merchant-cashier-php ``` -### Examples: - -- `example` folder -- `http_example` folder - #### Setup: -You need the following initialized +You need the library initialized as follows: (example in [http_example/init.php](http_example/init.php) file) ```php use Opay\MerchantCashier; -use Opay\Payload\OrderRequest; -use Opay\Payload\OrderStatusRequest; -use Opay\Payload\OrderCloseRequest; -use Opay\Utility\OpayConstants; - -$merchantCashier = new MerchantCashier("environment-endpoint-url", "Public_Key", "Private_Key", "your-merchant-id"); -``` -##### Merchant Initialize Call - -- Request - -| Parameter | Description | Sample Value | -| ------ | ------ | ------ | -| mchShortName | The short name of a Merchant. It's displayed on the payment confirmation page. | Jerry's shop | -| payMethod | Payment method 1. account (Balance payment) 2. qrcode (QRcode payment). | `OpayConstants::PAYMENT_METHODS_ACCOUNT` | -| payChannel | Payment type 1. BalancePayment (Balance account payment) 2. BonusPayment (Bonus account payment). | `OpayConstants::PAYMENT_CHANNEL_BALANCE_PAYMENT` | -| reference | Order number of merchant (unique order number from merchant platform) | `test_20191123132233` | -| userPhone | User phone number sent by merchant | `23480254xxxxx` | -| payAmount | Payment amount (payment amount of the order generated by the merchant platform, integer only, the minimum unit is kobo) | `1000` | -| currency | Currency charge should be performed in. Default is NGN | `NGN` | -| userRequestIp | The IP address requested by user, need pass-through by merchant, user Anti-phishing verification. | `10.xx.xx.xxx` | -| callbackUrl | The asynchronous callback address after transaction successful. | `http://XXXXXXXXXXXXX/callback` | -| returnUrl | The address that browser go to after transaction successful | `http://XXXXXXXXXXXXXXX/return` | -| productName | Product name, utf-8 encoded | `Apple AirPods Pro` | -| productDesc | Product description, utf-8 encoded | `DESCR` | -| expireAt | Transaction would be closed within specific time. Value is in minute | `3` | - -Example - -```php -$orderRequest = new OrderRequest([OpayConstants::PAYMENT_CHANNEL_BALANCE_PAYMENT, OpayConstants::PAYMENT_CHANNEL_BONUS_PAYMENT], "test_20191123132233", - "DESCR", [OpayConstants::PAYMENT_METHODS_ACCOUNT, OpayConstants::PAYMENT_METHODS_QRCODE], OpayConstants::CURRENCY_NAIRA, - "1000", "+23480254xxxxx", "10.xx.xx.xxx", "http://XXXXXXXXXXXXX/callback", - "http://XXXXXXXXXXXXXXX/return", "Jerry's shop", "Apple AirPods Pro"); - -// also have setters and getters for use -// then call -$merchantCashier->order($orderRequest); -$response = $merchantCashier->getOrderApiResult(); // returns OrderResponse object -// when $response->getStatus() == "00000" -// do $response->getData() to read response Data for your app usage - -``` - -- Response - -| Parameter | Description | -| ------ | ------ | -| code | 00000 : Request successful 00001:Decrypt failed 00002:Verification of merchant's whitelisted IPs failed | -| message | response message | -| data[orderNo] | order number from OPay payment | -| data[reference] | Order number of merchant (unique order number from merchant platform) | -| data[cashierUrl] | Cashier URL address requested for user‘s browser | -| data[payAmount] | Actual payment amount, integer only, minimum unit in kobo | -| data[orderStatus] | Status like : INITIAL, PENDING, SUCCESS, or FAIL | - -##### Merchant payment status query - -- Request +use Opay\MerchantTransfer; -| Parameter | Description | -| ------ | ------ | -| orderNo | order number from OPay payment | -| reference | Order number of merchant (unique order number from merchant platform) | - -Example - -```php -// $orderData is response from 'getOrderApiResult()' -$orderStatusRequest = new OrderStatusRequest($orderData['orderNo'], $orderData['reference']); - -// then call -$merchantCashier->orderStatus($orderStatusRequest); -$result = $merchantCashier->getOrderStatusApiResult(); // returns OrderResponse object -// when $response->getStatus() == "00000" -// do $response->getData() to read response Data for your app usage - -``` - -- Response - -| Parameter | Description | -| ------ | ------ | -| code | 00000 : Request successful 00001:Decrypt failed 00002:Verification of merchant's whitelisted IPs failed | -| message | response message | -| data[reference] | Order number of merchant (unique order number from merchant platform) | -| data[mchShortName] | Merchant's short name | -| data[userMobile] | Merchant's user Phone No. | -| data[orderNo] | order number from OPay payment | -| data[payAmount] | Actual payment amount, integer only, minimum unit in kobo | -| data[payChannel] | Payment type 1. BalancePayment (Balance account payment) 2. BonusPayment (Bonus account payment). | -| data[orderStatus] | Status like : INITIAL, PENDING, SUCCESS, or FAIL | - -##### Merchant close the order - -- Request - -| Parameter | Description | -| ------ | ------ | -| orderNo | order number from OPay payment | - -Example - -```php -// $orderData is response from 'getOrderApiResult()' -$orderCloseRequest = new OrderCloseRequest($orderData['orderNo']); - -// then call -$merchantCashier->orderClose($orderCloseRequest); -$response = $merchantCashier->getOrderCloseApiResult() // returns OrderResponse object -// when $response->getStatus() == "00000" -// do $response->getData() to read response Data for your app usage +$endpointBaseUrl = 'http://sandbox-cashierapi.opayweb.com'; +$pubKey = 'OPAYPUBxxxxxxxxxxxxx.xxxxxxxxxxxxx'; +$prvKey = 'OPAYPRVxxxxxxxxxxxxx.xxxxxxxxxxxxx'; +$merchantId = '256620xxxxxxxxxxxxx'; +$merchantCashier = new MerchantCashier("environment-endpoint-url", "Public_Key", "Private_Key", "your-merchant-id"); +$merchantTransfer = new MerchantTransfer("environment-endpoint-url", "Public_Key", "Private_Key", "your-merchant-id"); ``` - -- Response - -| Parameter | Description | -| ------ | ------ | -| code | 00000 : Request successful 00001:Decrypt failed 00002:Verification of merchant's whitelisted IPs failed | -| message | response message | -| data[reference] | Order number of merchant (unique order number from merchant platform) | -| data[orderNo] | order number from OPay payment | -| data[payAmount] | Actual payment amount, integer only, minimum unit in kobo | -| data[orderStatus] | Status like : INITIAL, PENDING, SUCCESS, or FAIL | \ No newline at end of file +#### Examples: +Access sample codes & implementations right inside the `http_example` folder + +##### Accept Payment +- initiate: [http_example/accept_payment/order.php](http_example/accept_payment/order.php) +- status query: [http_example/accept_payment/order_status.php](http_example/accept_payment/order_status.php) +- cancel payment: [http_example/accept_payment/order_cancel.php](http_example/accept_payment/order_cancel.php) +- handling payment callback: [http_example/accept_payment/callback.php](http_example/accept_payment/callback.php) + +##### Transfer +###### Bank +- get supported countries: [http_example/transfer/bank/get_countries.php](http_example/transfer/bank/get_countries.php) +- get supported banks: [http_example/transfer/bank/get_banks.php](http_example/transfer/bank/get_banks.php) +- validate a bank account: [http_example/transfer/bank/validate_account.php](http_example/transfer/bank/validate_account.php) +- initiate transfer: [http_example/transfer/bank/initiate.php](http_example/transfer/bank/initiate.php) +- status query: [http_example/transfer/bank/order_status.php](http_example/transfer/bank/order_status.php) + +###### Opay Wallet +- validate a user/customer: [http_example/transfer/wallet/validate_user.php](http_example/transfer/wallet/validate_user.php) +- validate a merchant: [http_example/transfer/wallet/validate_merchant.php](http_example/transfer/wallet/validate_merchant.php) +- initiate transfer: [http_example/transfer/wallet/initiate.php](http_example/transfer/wallet/initiate.php) +- status query: [http_example/transfer/wallet/order_status.php](http_example/transfer/wallet/order_status.php) + +##### Need Help? Feel free to open an issue. \ No newline at end of file diff --git a/src/Merchant.php b/src/Merchant.php new file mode 100644 index 0000000..8e4c542 --- /dev/null +++ b/src/Merchant.php @@ -0,0 +1,37 @@ +merchantId = $merchantId; + $this->publicKey = $pbKey; + $this->privateKey = $pvKey; + $this->networkClient = new Client([ + 'base_uri'=> $environmentBaseUrl + ]); + $this->proxyAddress = $proxyAddress; + } + + protected function buildRequestOptions(array $options) : array { + if ($this->proxyAddress) { + $options[RequestOptions::PROXY] = $this->proxyAddress; + } + return $options; + } + +} \ No newline at end of file diff --git a/src/MerchantCashier.php b/src/MerchantCashier.php index c41a34a..44a2738 100644 --- a/src/MerchantCashier.php +++ b/src/MerchantCashier.php @@ -2,45 +2,22 @@ namespace Opay; -use GuzzleHttp\Client; use GuzzleHttp\RequestOptions; use Opay\Payload\OrderCloseRequest; use Opay\Payload\OrderRequest; use Opay\Payload\OrderStatusRequest; use Opay\Result\OrderResponse; +use Opay\Result\Response; -class MerchantCashier +class MerchantCashier extends Merchant { - - private $merchantId; - private $orderData; private $orderStatusData; private $orderCloseData; - private $networkClient; - - private $publicKey; - private $privateKey; - - private $proxyAddress; - public function __construct(string $environmentBaseUrl, string $pbKey, string $pvKey, string $merchantId, ?array $proxyAddress = null) { - $this->merchantId = $merchantId; - $this->publicKey = $pbKey; - $this->privateKey = $pvKey; - $this->networkClient = new Client([ - 'base_uri'=> $environmentBaseUrl - ]); - $this->proxyAddress = $proxyAddress; - } - - private function buildRequestOptions(array $options) : array { - if ($this->proxyAddress) { - $options[RequestOptions::PROXY] = $this->proxyAddress; - } - return $options; + parent::__construct($environmentBaseUrl, $pbKey, $pvKey, $merchantId, $proxyAddress); } public final function order(OrderRequest $order) : void { @@ -55,7 +32,8 @@ public final function orderClose(OrderCloseRequest $orderClose) : void { $this->orderCloseData = $orderClose; } - public final function getOrderApiResult() : ?OrderResponse { + public final function getOrderApiResult() : Response + { $response = $this->networkClient->post('/api/v3/cashier/initialize', $this->buildRequestOptions([ RequestOptions::JSON=> $this->orderData, RequestOptions::HEADERS=> [ @@ -66,8 +44,9 @@ public final function getOrderApiResult() : ?OrderResponse { return OrderResponse::cast(new OrderResponse(), json_decode($response->getBody()->getContents(), false)); } - public final function getOrderStatusApiResult() : ?OrderResponse { - $_signature = hash_hmac('sha512', json_encode($this->orderStatusData) , $this->privateKey); + public final function getOrderStatusApiResult() : Response + { + $_signature = hash_hmac('sha512', json_encode($this->orderStatusData), $this->privateKey); $response = $this->networkClient->post("/api/v3/cashier/status",$this->buildRequestOptions([ RequestOptions::JSON=> $this->orderStatusData, RequestOptions::HEADERS=> [ @@ -78,7 +57,8 @@ public final function getOrderStatusApiResult() : ?OrderResponse { return OrderResponse::cast(new OrderResponse(), json_decode($response->getBody()->getContents(), false)); } - public final function getOrderCloseApiResult() : ?OrderResponse { + public final function getOrderCloseApiResult() : Response + { $_signature = hash_hmac('sha512', json_encode($this->orderCloseData) , $this->privateKey); $response = $this->networkClient->post("/api/v3/cashier/close", $this->buildRequestOptions([ RequestOptions::JSON=> $this->orderCloseData, diff --git a/src/MerchantTransfer.php b/src/MerchantTransfer.php new file mode 100644 index 0000000..2c4be86 --- /dev/null +++ b/src/MerchantTransfer.php @@ -0,0 +1,190 @@ +banksData = $bank; + } + + public final function validateAccount(ValidateBankAccountRequest $validateBankAccount) : void { + $this->validateBankAccountData = $validateBankAccount; + } + + public final function bankTransfer(BankTransferRequest $bankTransfer) : void { + $this->bankTransferData = $bankTransfer; + } + + public final function transferStatus(OrderStatusRequest $orderStatus) : void { + $this->orderStatusData = $orderStatus; + } + + public final function validateOpayMerchant(ValidateOpayMerchantRequest $validateOpayMerchant) : void { + $this->validateOpayMerchantData = $validateOpayMerchant; + } + + public final function validateOpayUser(ValidateOpayUserRequest $validateOpayUser) : void { + $this->validateOpayUserData = $validateOpayUser; + } + + public final function opayTransfer(OpayTransferRequest $opayTransfer) : void { + $this->opayTransferData = $opayTransfer; + } + + public final function getCountriesApiResult() : Response + { + $response = $this->networkClient->post("/api/v3/countries", $this->buildRequestOptions([ + RequestOptions::HEADERS=> [ + 'Authorization'=> 'Bearer '.$this->publicKey, + 'MerchantId'=> $this->merchantId + ] + ])); + return CountriesResponse::cast(new CountriesResponse(), json_decode($response->getBody()->getContents(), false)); + } + + public final function getBanksApiResult() : Response + { + $response = $this->networkClient->post("/api/v3/banks", $this->buildRequestOptions([ + RequestOptions::JSON=> $this->banksData, + RequestOptions::HEADERS=> [ + 'Authorization'=> 'Bearer '.$this->publicKey, + 'MerchantId'=> $this->merchantId + ] + ])); + return BanksResponse::cast(new BanksResponse(), json_decode($response->getBody()->getContents(), false)); + } + + public final function bankTransferApiResult() : Response + { + $requestString = json_encode($this->bankTransferData); + $_signature = hash_hmac('sha512', $requestString, $this->privateKey); + dump($requestString); + $response = $this->networkClient->post("/api/v3/transfer/toBank", $this->buildRequestOptions([ + RequestOptions::JSON=> json_decode($requestString, true), + RequestOptions::HEADERS=> [ + 'Authorization'=> 'Bearer '.$_signature, + 'MerchantId'=> $this->merchantId + ] + ])); + return BankTransferResponse::cast(new BankTransferResponse(), json_decode($response->getBody()->getContents(), false)); + } + + public final function bankTransferStatusApiResult() : Response + { + $_signature = hash_hmac('sha512', json_encode($this->orderStatusData), $this->privateKey); + $response = $this->networkClient->post("/api/v3/transfer/status/toBank", $this->buildRequestOptions([ + RequestOptions::JSON=> $this->orderStatusData, + RequestOptions::HEADERS=> [ + 'Authorization'=> 'Bearer '.$_signature, + 'MerchantId'=> $this->merchantId + ] + ])); + return BankTransferResponse::cast(new BankTransferResponse(), json_decode($response->getBody()->getContents(), false)); + } + + public final function validateBankAccountApiResult() : Response + { + $response = $this->networkClient->post("/api/v3/verification/accountNumber/resolve", $this->buildRequestOptions([ + RequestOptions::JSON=> $this->validateBankAccountData, + RequestOptions::HEADERS=> [ + 'Authorization'=> 'Bearer '.$this->publicKey, + 'MerchantId'=> $this->merchantId + ] + ])); + return ValidateBankAccountResponse::cast(new ValidateBankAccountResponse(), json_decode($response->getBody()->getContents(), false)); + } + + public final function validateOpayMerchantApiResult() : Response + { + $response = $this->networkClient->post("/api/v3/info/merchant", $this->buildRequestOptions([ + RequestOptions::JSON=> $this->validateOpayMerchantData, + RequestOptions::HEADERS=> [ + 'Authorization'=> 'Bearer '.$this->publicKey, + 'MerchantId'=> $this->merchantId + ] + ])); + return ValidateOpayMerchantResponse::cast(new ValidateOpayMerchantResponse(), json_decode($response->getBody()->getContents(), false)); + } + + public final function validateOpayUserApiResult() : Response + { + $response = $this->networkClient->post("/api/v3/info/user", $this->buildRequestOptions([ + RequestOptions::JSON=> $this->validateOpayUserData, + RequestOptions::HEADERS=> [ + 'Authorization'=> 'Bearer '.$this->publicKey, + 'MerchantId'=> $this->merchantId + ] + ])); + return ValidateOpayUserResponse::cast(new ValidateOpayUserResponse(), json_decode($response->getBody()->getContents(), false)); + } + + public final function opayTransferApiResult() : Response + { + $requestString = json_encode($this->opayTransferData); + $_signature = hash_hmac('sha512', $requestString, $this->privateKey); + $response = $this->networkClient->post("/api/v3/transfer/toWallet", $this->buildRequestOptions([ + RequestOptions::JSON=> json_decode($requestString, true), + RequestOptions::HEADERS=> [ + 'Authorization'=> 'Bearer '.$_signature, + 'MerchantId'=> $this->merchantId + ] + ])); + return OpayTransferResponse::cast(new OpayTransferResponse(), json_decode($response->getBody()->getContents(), false)); + } + + public final function opayTransferStatusApiResult() : Response + { + $_signature = hash_hmac('sha512', json_encode($this->orderStatusData), $this->privateKey); + $response = $this->networkClient->post("/api/v3/transfer/status/toWallet", $this->buildRequestOptions([ + RequestOptions::JSON=> $this->orderStatusData, + RequestOptions::HEADERS=> [ + 'Authorization'=> 'Bearer '.$_signature, + 'MerchantId'=> $this->merchantId + ] + ])); + return OpayTransferResponse::cast(new OpayTransferResponse(), json_decode($response->getBody()->getContents(), false)); + } +} \ No newline at end of file diff --git a/src/Payload/BankTransferRequest.php b/src/Payload/BankTransferRequest.php new file mode 100644 index 0000000..53ed66a --- /dev/null +++ b/src/Payload/BankTransferRequest.php @@ -0,0 +1,48 @@ +reference = $reference; + $this->amount = $amount; + $this->currency = $currency; + $this->country = $country; + $this->receiverName = $receiverName; + $this->receiverBankCode = $receiverBankCode; + $this->receiverBankAccountNumber = $receiverBankAccountNumber; + $this->reason = $reason; + } + + public function jsonSerialize() : array + { + return [ + 'amount'=> (string)$this->amount, + 'country'=> $this->country, + 'currency'=> $this->currency, + 'reason'=> $this->reason, + 'receiver'=> [ + 'bankAccountNumber'=> $this->receiverBankAccountNumber, + 'bankCode'=> $this->receiverBankCode, + 'name'=> $this->receiverName + ], + 'reference'=> $this->reference + ]; + } +} \ No newline at end of file diff --git a/src/Payload/BanksRequest.php b/src/Payload/BanksRequest.php new file mode 100644 index 0000000..1f79291 --- /dev/null +++ b/src/Payload/BanksRequest.php @@ -0,0 +1,22 @@ +countryCode = $countryCode; + } + + public function jsonSerialize() : array + { + return [ + 'countryCode'=> $this->countryCode + ]; + } +} \ No newline at end of file diff --git a/src/Payload/OpayTransferRequest.php b/src/Payload/OpayTransferRequest.php new file mode 100644 index 0000000..601ae38 --- /dev/null +++ b/src/Payload/OpayTransferRequest.php @@ -0,0 +1,63 @@ +reference = $reference; + $this->amount = $amount; + $this->currency = $currency; + $this->country = $country; + $this->receiverName = $receiverName; + $this->receiverType = $receiverType; + if ($receiverType === OpayConstants::TRANSFER_RECEIVER_TYPE_MERCHANT) { + $this->receiverMerchantId = $receiverNumber; + } else { + $this->receiverPhoneNumber = $receiverNumber; + } + $this->reason = $reason; + } + + public function jsonSerialize() : array + { + if ($this->receiverType === OpayConstants::TRANSFER_RECEIVER_TYPE_MERCHANT) { + $receiver = [ + 'merchantId'=> $this->receiverMerchantId, + 'name'=> $this->receiverName, + 'type'=> $this->receiverType + ]; + } else { + $receiver = [ + 'name'=> $this->receiverName, + 'phoneNumber'=> $this->receiverPhoneNumber, + 'type'=> $this->receiverType + ]; + } + return [ + 'amount'=> (string)$this->amount, + 'currency'=> $this->currency, + 'reason'=> $this->reason, + 'receiver'=> $receiver, + 'reference'=> $this->reference + ]; + } +} \ No newline at end of file diff --git a/src/Payload/OrderRequest.php b/src/Payload/OrderRequest.php index 389ecbb..acad1d1 100644 --- a/src/Payload/OrderRequest.php +++ b/src/Payload/OrderRequest.php @@ -25,7 +25,7 @@ public function __construct(array $paymentMethods, string $reference, string $payCurrency, string $payAmount, string $userPhone, string $userRequestIp, string $callbackUrl, string $returnUrl, - string $mchShortName, string $productName) + string $mchShortName, string $productName, int $expireAt = 0) { $this->payMethods = $paymentMethods; $this->reference = $reference; @@ -39,7 +39,12 @@ public function __construct(array $paymentMethods, string $reference, $this->returnUrl = $returnUrl; $this->mchShortName = $mchShortName; $this->productName = $productName; - $this->expireAt = (string) OpayConstants::ORDER_EXPIRY; + if ($expireAt) { + $this->expireAt = (string) $expireAt; + } else { + // use the default + $this->expireAt = (string) OpayConstants::ORDER_EXPIRY; + } } /** diff --git a/src/Payload/ValidateBankAccountRequest.php b/src/Payload/ValidateBankAccountRequest.php new file mode 100644 index 0000000..82ae4bd --- /dev/null +++ b/src/Payload/ValidateBankAccountRequest.php @@ -0,0 +1,28 @@ +countryCode = $countryCode; + $this->bankCode = $bankCode; + $this->bankAccountNo = $bankAccountNumber; + } + + public function jsonSerialize() : array + { + return [ + 'countryCode'=> $this->countryCode, + 'bankCode'=> $this->bankCode, + 'bankAccountNo'=> $this->bankAccountNo + ]; + } +} \ No newline at end of file diff --git a/src/Payload/ValidateOpayMerchantRequest.php b/src/Payload/ValidateOpayMerchantRequest.php new file mode 100644 index 0000000..ca223e5 --- /dev/null +++ b/src/Payload/ValidateOpayMerchantRequest.php @@ -0,0 +1,22 @@ +email = $email; + } + + public function jsonSerialize() : array + { + return [ + 'email'=> $this->email + ]; + } +} \ No newline at end of file diff --git a/src/Payload/ValidateOpayUserRequest.php b/src/Payload/ValidateOpayUserRequest.php new file mode 100644 index 0000000..b8be860 --- /dev/null +++ b/src/Payload/ValidateOpayUserRequest.php @@ -0,0 +1,22 @@ +phoneNumber = $phoneNumber; + } + + public function jsonSerialize() : array + { + return [ + 'phoneNumber'=> $this->phoneNumber + ]; + } +} \ No newline at end of file diff --git a/src/Result/BankTransferResponse.php b/src/Result/BankTransferResponse.php new file mode 100644 index 0000000..bb4a558 --- /dev/null +++ b/src/Result/BankTransferResponse.php @@ -0,0 +1,21 @@ +data; + } +} \ No newline at end of file diff --git a/src/Result/BankTransferResponseData.php b/src/Result/BankTransferResponseData.php new file mode 100644 index 0000000..f659cc9 --- /dev/null +++ b/src/Result/BankTransferResponseData.php @@ -0,0 +1,107 @@ +getProperties(); + foreach ($sourceProperties as $sourceProperty) { + $name = $sourceProperty->getName(); + $destination->{$name} = $source->$name; + } + } + return $destination; + } + + public function toArray() : array { + return (array) $this; + } + + /** + * @return mixed + */ + public function getReference() + { + return $this->reference; + } + + /** + * @return mixed + */ + public function getOrderNo() + { + return $this->orderNo; + } + + /** + * @return mixed + */ + public function getAmount() + { + return $this->amount; + } + + /** + * @return mixed + */ + public function getCurrency() + { + return $this->currency; + } + + /** + * @return mixed + */ + public function getFee() + { + return $this->fee; + } + + /** + * @return mixed + */ + public function getStatus() + { + return $this->status; + } + + /** + * @return mixed + */ + public function getFailureReason() + { + return $this->failureReason; + } + + /** + * @return mixed + */ + public function getBankCode() + { + return $this->bankCode; + } + + /** + * @return mixed + */ + public function getBankAccountNumber() + { + return $this->bankAccountNumber; + } +} \ No newline at end of file diff --git a/src/Result/BanksResponse.php b/src/Result/BanksResponse.php new file mode 100644 index 0000000..83e6e84 --- /dev/null +++ b/src/Result/BanksResponse.php @@ -0,0 +1,21 @@ +data; + } +} \ No newline at end of file diff --git a/src/Result/BanksResponseData.php b/src/Result/BanksResponseData.php new file mode 100644 index 0000000..08da965 --- /dev/null +++ b/src/Result/BanksResponseData.php @@ -0,0 +1,44 @@ +getProperties(); + foreach ($sourceProperties as $sourceProperty) { + $name = $sourceProperty->getName(); + $destination->{$name} = $source->$name; + } + } + return $destination; + } + + public function toArray() : array { + return (array) $this; + } + + /** + * @return mixed + */ + public function getName() + { + return $this->name; + } + + /** + * @return mixed + */ + public function getCode() + { + return $this->code; + } +} \ No newline at end of file diff --git a/src/Result/CountriesResponse.php b/src/Result/CountriesResponse.php new file mode 100644 index 0000000..08b323d --- /dev/null +++ b/src/Result/CountriesResponse.php @@ -0,0 +1,22 @@ +data; + } +} \ No newline at end of file diff --git a/src/Result/CountriesResponseData.php b/src/Result/CountriesResponseData.php new file mode 100644 index 0000000..f1e3996 --- /dev/null +++ b/src/Result/CountriesResponseData.php @@ -0,0 +1,53 @@ +getProperties(); + foreach ($sourceProperties as $sourceProperty) { + $name = $sourceProperty->getName(); + $destination->{$name} = $source->$name; + } + } + return $destination; + } + + public function toArray() : array { + return (array) $this; + } + + /** + * @return mixed + */ + public function getName() + { + return $this->name; + } + + /** + * @return mixed + */ + public function getCode() + { + return $this->code; + } + + /** + * @return mixed + */ + public function getCurrency() + { + return $this->currency; + } +} diff --git a/src/Result/OpayTransferResponse.php b/src/Result/OpayTransferResponse.php new file mode 100644 index 0000000..a256cbd --- /dev/null +++ b/src/Result/OpayTransferResponse.php @@ -0,0 +1,21 @@ +data; + } +} \ No newline at end of file diff --git a/src/Result/OpayTransferResponseData.php b/src/Result/OpayTransferResponseData.php new file mode 100644 index 0000000..03a2ad2 --- /dev/null +++ b/src/Result/OpayTransferResponseData.php @@ -0,0 +1,116 @@ +getProperties(); + foreach ($sourceProperties as $sourceProperty) { + $name = $sourceProperty->getName(); + $destination->{$name} = $source->$name; + } + } + return $destination; + } + + public function toArray() : array { + return (array) $this; + } + + /** + * @return mixed + */ + public function getReference() + { + return $this->reference; + } + + /** + * @return mixed + */ + public function getOrderNo() + { + return $this->orderNo; + } + + /** + * @return mixed + */ + public function getAmount() + { + return $this->amount; + } + + /** + * @return mixed + */ + public function getCurrency() + { + return $this->currency; + } + + /** + * @return mixed + */ + public function getFee() + { + return $this->fee; + } + + /** + * @return mixed + */ + public function getStatus() + { + return $this->status; + } + + /** + * @return mixed + */ + public function getFailureReason() + { + return $this->failureReason; + } + + /** + * @return mixed + */ + public function getType() + { + return $this->type; + } + + /** + * @return mixed + */ + public function getMerchantId() + { + return $this->merchantId; + } + + /** + * @return mixed + */ + public function getPhoneNumber() + { + return $this->phoneNumber; + } +} \ No newline at end of file diff --git a/src/Result/OrderResponse.php b/src/Result/OrderResponse.php index 52d8608..26774b4 100644 --- a/src/Result/OrderResponse.php +++ b/src/Result/OrderResponse.php @@ -2,45 +2,12 @@ namespace Opay\Result; -class OrderResponse +class OrderResponse extends Response { - public $code; - public $message; - public $data; - public static function cast(OrderResponse $destination, \stdClass $source) : OrderResponse + static function parseData(?\stdClass $s) { - $sourceReflection = new \ReflectionObject($source); - $sourceProperties = $sourceReflection->getProperties(); - foreach ($sourceProperties as $sourceProperty) { - $name = $sourceProperty->getName(); - if ($name === 'data') { - $destination->{$name} = OrderResponseData::cast(new OrderResponseData(), $source->$name); - } else { - $destination->{$name} = $source->$name; - } - } - return $destination; - } - - public function toArray() : array { - return (array) $this; - } - - /** - * @return mixed - */ - public function getCode() - { - return $this->code; - } - - /** - * @return mixed - */ - public function getMessage() - { - return $this->message; + return OrderResponseData::cast(new OrderResponseData(), $s); } /** diff --git a/src/Result/Response.php b/src/Result/Response.php new file mode 100644 index 0000000..a6c87e4 --- /dev/null +++ b/src/Result/Response.php @@ -0,0 +1,63 @@ +getProperties(); + foreach ($sourceProperties as $sourceProperty) { + $name = $sourceProperty->getName(); + if ($name === 'data') { + if (is_array($source->$name)) { + $arrIn = (array) $source->$name; + $arrOut = array(); + foreach ($arrIn as $value) { + $arrOut[] = static::parseData($value); + } + $destination->{$name} = $arrOut; + } else { + $destination->{$name} = static::parseData($source->$name); + } + } else { + $destination->{$name} = $source->$name; + } + } + return $destination; + } + + public function toArray() : array { + return (array) $this; + } + + /** + * @return mixed + */ + public function getCode() + { + return $this->code; + } + + /** + * @return mixed + */ + public function getMessage() + { + return $this->message; + } +} \ No newline at end of file diff --git a/src/Result/ValidateBankAccountResponse.php b/src/Result/ValidateBankAccountResponse.php new file mode 100644 index 0000000..158e436 --- /dev/null +++ b/src/Result/ValidateBankAccountResponse.php @@ -0,0 +1,21 @@ +data; + } +} \ No newline at end of file diff --git a/src/Result/ValidateBankAccountResponseData.php b/src/Result/ValidateBankAccountResponseData.php new file mode 100644 index 0000000..ca31406 --- /dev/null +++ b/src/Result/ValidateBankAccountResponseData.php @@ -0,0 +1,44 @@ +getProperties(); + foreach ($sourceProperties as $sourceProperty) { + $name = $sourceProperty->getName(); + $destination->{$name} = $source->$name; + } + } + return $destination; + } + + public function toArray() : array { + return (array) $this; + } + + /** + * @return mixed + */ + public function getAccountNo() + { + return $this->accountNo; + } + + /** + * @return mixed + */ + public function getAccountName() + { + return $this->accountName; + } +} \ No newline at end of file diff --git a/src/Result/ValidateOpayMerchantResponse.php b/src/Result/ValidateOpayMerchantResponse.php new file mode 100644 index 0000000..d39c22b --- /dev/null +++ b/src/Result/ValidateOpayMerchantResponse.php @@ -0,0 +1,21 @@ +data; + } +} \ No newline at end of file diff --git a/src/Result/ValidateOpayMerchantResponseData.php b/src/Result/ValidateOpayMerchantResponseData.php new file mode 100644 index 0000000..b84d7eb --- /dev/null +++ b/src/Result/ValidateOpayMerchantResponseData.php @@ -0,0 +1,53 @@ +getProperties(); + foreach ($sourceProperties as $sourceProperty) { + $name = $sourceProperty->getName(); + $destination->{$name} = $source->$name; + } + } + return $destination; + } + + public function toArray() : array { + return (array) $this; + } + + /** + * @return mixed + */ + public function getMerchantId() + { + return $this->merchantId; + } + + /** + * @return mixed + */ + public function getEmail() + { + return $this->email; + } + + /** + * @return mixed + */ + public function getBusinessName() + { + return $this->businessName; + } +} \ No newline at end of file diff --git a/src/Result/ValidateOpayUserResponse.php b/src/Result/ValidateOpayUserResponse.php new file mode 100644 index 0000000..bd11737 --- /dev/null +++ b/src/Result/ValidateOpayUserResponse.php @@ -0,0 +1,21 @@ +data; + } +} \ No newline at end of file diff --git a/src/Result/ValidateOpayUserResponseData.php b/src/Result/ValidateOpayUserResponseData.php new file mode 100644 index 0000000..cc2767b --- /dev/null +++ b/src/Result/ValidateOpayUserResponseData.php @@ -0,0 +1,80 @@ +getProperties(); + foreach ($sourceProperties as $sourceProperty) { + $name = $sourceProperty->getName(); + $destination->{$name} = $source->$name; + } + } + return $destination; + } + + public function toArray() : array { + return (array) $this; + } + + /** + * @return mixed + */ + public function getUserId() + { + return $this->userId; + } + + /** + * @return mixed + */ + public function getPhoneNumber() + { + return $this->phoneNumber; + } + + /** + * @return mixed + */ + public function getFirstName() + { + return $this->firstName; + } + + /** + * @return mixed + */ + public function getLastName() + { + return $this->lastName; + } + + /** + * @return mixed + */ + public function getEmail() + { + return $this->email; + } + + /** + * @return mixed + */ + public function getAddress() + { + return $this->address; + } +} \ No newline at end of file diff --git a/src/Utility/OpayConstants.php b/src/Utility/OpayConstants.php index 65f0e24..7c53be4 100644 --- a/src/Utility/OpayConstants.php +++ b/src/Utility/OpayConstants.php @@ -6,15 +6,19 @@ class OpayConstants { - public const PAYMENT_METHODS_ACCOUNT = "account"; public const PAYMENT_METHODS_QRCODE = "qrcode"; + public const PAYMENT_METHODS_BANK_CARD = "bankCard"; + public const PAYMENT_METHODS_BANK_ACCOUNT = "bankAccount"; public const PAYMENT_CHANNEL_BALANCE_PAYMENT = "BalancePayment"; public const PAYMENT_CHANNEL_BONUS_PAYMENT = "BonusPayment"; + public const PAYMENT_CHANNEL_O_WEALTH_PAYMENT = "OWealth"; - public const CURRENCY_NAIRA = "NGN"; + public const TRANSFER_RECEIVER_TYPE_USER = "USER"; + public const TRANSFER_RECEIVER_TYPE_MERCHANT = "MERCHANT"; - public const ORDER_EXPIRY = 5; + public const CURRENCY_NAIRA = "NGN"; + public const ORDER_EXPIRY = 10; } \ No newline at end of file diff --git a/tests/Unit/MerchantCashierTest.php b/tests/Unit/MerchantCashierTest.php index 064573f..d8942ab 100644 --- a/tests/Unit/MerchantCashierTest.php +++ b/tests/Unit/MerchantCashierTest.php @@ -1,7 +1,11 @@ merchantCashier->getOrderApiResult(); // var_dump($response->getData()); - return \Opay\Result\OrderResponse::cast(new \Opay\Result\OrderResponse(), (object)[ + return OrderResponse::cast(new OrderResponse(), (object)[ 'code'=> '00000', 'message'=> 'SUCCESSFUL', 'data'=> (object)[ @@ -54,13 +58,14 @@ public final function testOrderPayload() : \Opay\Result\OrderResponse /** * testOrderStatusPayload * @depends testOrderPayload + * @param OrderResponse $orderResponse * @return void */ - public final function testOrderStatusPayload(\Opay\Result\OrderResponse $orderResponse) : void + public final function testOrderStatusPayload(OrderResponse $orderResponse) : void { $orderData = $orderResponse->getData()->toArray(); $this->assertIsArray($orderData); - $_orderStatusRequest = new \Opay\Payload\OrderStatusRequest($orderData['orderNo'], $orderData['reference']); + $_orderStatusRequest = new OrderStatusRequest($orderData['orderNo'], $orderData['reference']); $this->merchantCashier->orderStatus($_orderStatusRequest); $this->assertEquals(json_encode($_orderStatusRequest), json_encode($this->merchantCashier->getOrderStatusData())); @@ -73,12 +78,13 @@ public final function testOrderStatusPayload(\Opay\Result\OrderResponse $orderRe * testOrderClosePayload * @depends testOrderPayload * return void + * @param OrderResponse $orderResponse */ - public final function testOrderClosePayload(\Opay\Result\OrderResponse $orderResponse) : void + public final function testOrderClosePayload(OrderResponse $orderResponse) : void { $orderData = $orderResponse->getData()->toArray(); $this->assertIsArray($orderData); - $_orderCloseRequest = new \Opay\Payload\OrderCloseRequest($orderData['orderNo'], $orderData['reference']); + $_orderCloseRequest = new OrderCloseRequest($orderData['orderNo'], $orderData['reference']); $this->merchantCashier->orderClose($_orderCloseRequest); $this->assertEquals(json_encode($_orderCloseRequest), json_encode($this->merchantCashier->getOrderCloseData()));