Skip to content

Commit

Permalink
Merge pull request #6 from segsalerty2013/dev
Browse files Browse the repository at this point in the history
v3 support
  • Loading branch information
segsalerty2013 committed Mar 29, 2020
2 parents fa6410e + 5a37e3b commit 8a0db7c
Show file tree
Hide file tree
Showing 13 changed files with 444 additions and 151 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/vendor/
composer.lock
composer.lock
/.idea
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "opay/merchant-cashier-php",
"description": "Merchant Pre-Order API",
"description": "Merchant Pre-Order API v3",
"type": "library",
"authors": [
{
Expand Down
26 changes: 26 additions & 0 deletions example/order.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

use Opay\MerchantCashier;
use Opay\Payload\OrderRequest;
use Opay\Utility\OpayConstants;

$merchantCashier = new MerchantCashier(
"http://api.test.opaydev.com:8081",
"qazwert12345!@#$",
"xxxxxxxxxxxxx",
"XXXXXXXXXXXXX");
$_orderRequest = new OrderRequest([OpayConstants::PAYMENT_CHANNEL_BALANCE_PAYMENT, OpayConstants::PAYMENT_CHANNEL_BONUS_PAYMENT], "test_201966864458800",
"WOW. The best wireless earphone in history. Cannot agree more! Right!", [OpayConstants::PAYMENT_METHODS_ACCOUNT, OpayConstants::PAYMENT_METHODS_QRCODE], OpayConstants::CURRENCY_NAIRA,
"10", "+2349876543210", "0:0:0:0:0:0:0:1", "https://yourdomain/callback",
"https://yourdomain/return", "Jerry's shop", "Apple AirPods Pro");

$merchantCashier->order($_orderRequest);

$response = $merchantCashier->getOrderApiResult();

if($response->getCode() === "00000") {
var_dump($response->getData());
}



24 changes: 24 additions & 0 deletions example/order_cancel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

use Opay\MerchantCashier;
use Opay\Payload\OrderCloseRequest;

$merchantCashier = new MerchantCashier(
"http://api.test.opaydev.com:8081",
"qazwert12345!@#$",
"xxxxxxxxxxxxx",
"XXXXXXXXXXXXX");

$orderNo = "94578465746574654";

$_orderCloseRequest = new OrderCloseRequest($orderNo);
$merchantCashier->orderClose($_orderCloseRequest);

$response = $merchantCashier->getOrderCloseApiResult();

if($response->getCode() === "00000") {;
echo $response->getData();
}



26 changes: 26 additions & 0 deletions example/order_status.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

use Opay\MerchantCashier;
use Opay\Payload\OrderStatusRequest;

$merchantCashier = new MerchantCashier(
"http://api.test.opaydev.com:8081",
"qazwert12345!@#$",
"xxxxxxxxxxxxx",
"XXXXXXXXXXXXX");

$orderNo = "94578465746574654";
$reference = "ref-94857846574654";

$_orderStatusRequest = new OrderStatusRequest($orderNo, $reference);

$merchantCashier->orderStatus($_orderStatusRequest);

$response = $merchantCashier->getOrderStatusApiResult();

if($response->getCode() === "00000") {
echo $response->getData();
}



11 changes: 7 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Opay Merchant Cashier
## Opay Merchant Cashier v3

![](https://github.com/actions/opay-merchant-cashier-php/workflows/.github/workflows/php.yml/badge.svg)

Expand All @@ -23,9 +23,9 @@ use Opay\Payload\OrderStatusRequest;
use Opay\Payload\OrderCloseRequest;
use Opay\Utility\OpayConstants;

$merchantCashier = new MerchantCashier("environment-endpoint-url", "AES-IV", "AES-KEY", "your-merchant-id");
$merchantCashier = new MerchantCashier("environment-endpoint-url", "Public_Key", "Private_Key", "your-merchant-id");
```
##### Merchant Pre-Order Call
##### Merchant Initialize Call

- Request

Expand All @@ -35,13 +35,15 @@ $merchantCashier = new MerchantCashier("environment-endpoint-url", "AES-IV", "AE
| 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` |
| userMobile | User phone number sent by merchant | `23480254xxxxx` |
| 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

Expand All @@ -51,6 +53,7 @@ $orderRequest = new OrderRequest([OpayConstants::PAYMENT_CHANNEL_BALANCE_PAYMENT
"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
Expand Down
84 changes: 40 additions & 44 deletions src/MerchantCashier.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,101 +8,97 @@
use Opay\Payload\OrderRequest;
use Opay\Payload\OrderStatusRequest;
use Opay\Result\OrderResponse;
use Opay\Utility\AesCipher;

class MerchantCashier
{

private $merchantId;

private $cryptor;
private $orderData;
private $orderStatusData;
private $orderCloseData;

private $networkClient;

public function __construct(string $environmentBaseUrl, string $aesIv, string $aesKey, string $merchantId) {
private $publicKey;
private $privateKey;

public function __construct(string $environmentBaseUrl, string $pbKey, string $pvKey, string $merchantId) {
$this->merchantId = $merchantId;
$this->cryptor = new AesCipher($aesIv, $aesKey);
$this->publicKey = $pbKey;
$this->privateKey = $pvKey;
$this->networkClient = new Client([
'base_uri'=> $environmentBaseUrl
]);
}

public final function order(OrderRequest $order) {
$this->orderData = $this->cryptor->encrypt(json_encode($order, JSON_UNESCAPED_SLASHES));
public final function order(OrderRequest $order) : void {
$this->orderData = $order;
}

public final function orderStatus(OrderStatusRequest $orderStatus) {
$this->orderStatusData = $this->cryptor->encrypt(json_encode($orderStatus));
public final function orderStatus(OrderStatusRequest $orderStatus) : void {
$this->orderStatusData = $orderStatus;
}

public final function orderClose(OrderCloseRequest $orderClose) {
$this->orderCloseData = $this->cryptor->encrypt(json_encode($orderClose));
public final function orderClose(OrderCloseRequest $orderClose) : void {
$this->orderCloseData = $orderClose;
}

public final function getOrderApiResult() : ?OrderResponse {
$response = $this->networkClient->post("/api/cashier/order", [
RequestOptions::JSON => [
'data' => $this->orderData,
'merchantId' => $this->merchantId
]
]);
$_resp = json_decode($response->getBody()->getContents(), true);
return new OrderResponse($this, $_resp);
$response = $this->networkClient->post('/api/v3/cashier/initialize', [
RequestOptions::JSON=> $this->orderData,
RequestOptions::HEADERS=> [
'Authorization'=> 'Bearer '.$this->publicKey,
'MerchantId'=> $this->merchantId
]
]);
return OrderResponse::cast(new OrderResponse(), json_decode($response->getBody()->getContents(), false));
}

public final function getOrderStatusApiResult() : ?OrderResponse {
$response = $this->networkClient->post("/api/cashier/merchantOrderStatus", [
RequestOptions::JSON => [
'data' => $this->orderStatusData,
'merchantId' => $this->merchantId
$_signature = hash_hmac('sha512', json_encode($this->orderStatusData) , $this->privateKey);
$response = $this->networkClient->post("/api/v3/cashier/status", [
RequestOptions::JSON=> $this->orderStatusData,
RequestOptions::HEADERS=> [
'Authorization'=> 'Bearer '.$_signature,
'MerchantId'=> $this->merchantId
]
]);
$_resp = json_decode($response->getBody()->getContents(), true);
return new OrderResponse($this, $_resp);
return OrderResponse::cast(new OrderResponse(), json_decode($response->getBody()->getContents(), false));
}

public final function getOrderCloseApiResult() : ?OrderResponse {
$response = $this->networkClient->post("/api/cashier/merchantCloseOrder", [
RequestOptions::JSON => [
'data' => $this->orderCloseData,
'merchantId' => $this->merchantId
$_signature = hash_hmac('sha512', $this->orderCloseData , $this->privateKey);
$response = $this->networkClient->post("/api/v3/cashier/close", [
RequestOptions::JSON=> $this->orderCloseData,
RequestOptions::HEADERS=> [
'Authorization'=> 'Bearer '.$_signature,
'MerchantId'=> $this->merchantId
]
]);
$_resp = json_decode($response->getBody()->getContents(), true);
return new OrderResponse($this, $_resp);
}

/**
* @return AES
*/
public final function getCryptor(): AesCipher
{
return $this->cryptor;
return OrderResponse::cast(new OrderResponse(), json_decode($response->getBody()->getContents(), false));
}

/**
* @return string
* @return OrderRequest
*/
public final function getOrderData() : string
public final function getOrderData() : OrderRequest
{
return $this->orderData;
}

/**
* @return string
* @return OrderStatusRequest
*/
public final function getOrderStatusData() : string
public final function getOrderStatusData() : OrderStatusRequest
{
return $this->orderStatusData;
}

/**
* @return string
* @return OrderCloseRequest
*/
public final function getOrderCloseData() : string
public final function getOrderCloseData() : OrderCloseRequest
{
return $this->orderCloseData;
}
Expand Down
Loading

0 comments on commit 8a0db7c

Please sign in to comment.