Skip to content

Commit

Permalink
Merge pull request #2 from segsalerty2013/dev
Browse files Browse the repository at this point in the history
Add http example for integrations
  • Loading branch information
segsalerty2013 committed Dec 18, 2019
2 parents 83062a1 + 2ef30e9 commit c48631e
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 1 deletion.
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",
"version": "1.0.0",
"version": "1.0.1",
"description": "Merchant Pre-Order API",
"type": "library",
"authors": [
Expand Down
48 changes: 48 additions & 0 deletions http_example/callback.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
require_once('./vendor/autoload.php');
require_once('init.php');

use Opay\Payload\OrderStatusRequest;

$inputJSON = file_get_contents('php://input');
$input = json_decode($inputJSON, TRUE); //convert JSON into array
$payload = $input['payload'];
file_put_contents('./log_'.date("j.n.Y").'.log', 'payload: '.json_encode($payload). "\n", FILE_APPEND);

$_orderStatusRequest = new OrderStatusRequest($payload['transactionId'], $payload['reference']);

$merchantCashier->orderStatus($_orderStatusRequest);

$response = $merchantCashier->getOrderStatusApiResult();

file_put_contents('./log_'.date("j.n.Y").'.log', 'code: '.json_encode($response->getCode()). "\n", FILE_APPEND);
file_put_contents('./log_'.date("j.n.Y").'.log', 'data: '.json_encode($response->getData()). "\n", FILE_APPEND);

// Example of data posted in callback
// {
// "payload": {
// "country": "NG",
// "instrumentId": "useless",
// "fee": "0.00",
// "channel": "Web",
// "reference": "test_20196699559858800",
// "updated_at": "2019-12-13T09:36:58Z",
// "currency": "NGN",
// "refunded": false,
// "instrument-id": "useless",
// "timestamp": "2019-12-13T09:36:58Z",
// "amount": "0.10",
// "instrumentType": "coins",
// "instrument_id": "useless",
// "transactionId": "191213140104849949",
// "token": "191213140104849949",
// "bussinessType": "Consumption_H5",
// "payChannel": "BalancePayment",
// "status": "failed"
// },
// "sha512": "9cc847600cb7104b0a5a48976e70cf74763eb69f123a282975de1c3a751128c12d437b1f7c7d4a24bdb82b79aaa477e98e81bc66be8e8d8c3c15cdfcea730553",
// "type": "transaction-status"
// }



11 changes: 11 additions & 0 deletions http_example/init.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

require_once('./vendor/autoload.php');

use Opay\MerchantCashier;

$merchantCashier = new MerchantCashier(
"http://api.test.opaydev.com:8081",
"qazwert12345!@#$",
"fKJ8jwsj1nHNkKon",
"256619112122000");
46 changes: 46 additions & 0 deletions http_example/order.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
require_once('./vendor/autoload.php');
require_once('init.php');

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

$reference = "test_20196659118854400";

$_orderRequest = new OrderRequest([OpayConstants::PAYMENT_CHANNEL_BALANCE_PAYMENT, OpayConstants::PAYMENT_CHANNEL_BONUS_PAYMENT], $reference,
"WOW. The best wireless earphone in history. Cannot agree more! Right!", [OpayConstants::PAYMENT_METHODS_ACCOUNT, OpayConstants::PAYMENT_METHODS_QRCODE], OpayConstants::CURRENCY_NAIRA,
"100", "+2349876543210", getUserIP(), "http://a7384c7d.ngrok.io/callback.php",
"http://a7384c7d.ngrok.io/order_status.php", "Jerry's shop", "Apple AirPods Pro");

$merchantCashier->order($_orderRequest);

$response = $merchantCashier->getOrderApiResult();

echo "status : ". $response->getCode(). "<br/>";

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

function getUserIP() {
$ipaddress = '';
if (isset($_SERVER['HTTP_CLIENT_IP']))
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if(isset($_SERVER['HTTP_X_FORWARDED']))
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
else if(isset($_SERVER['HTTP_X_CLUSTER_CLIENT_IP']))
$ipaddress = $_SERVER['HTTP_X_CLUSTER_CLIENT_IP'];
else if(isset($_SERVER['HTTP_FORWARDED_FOR']))
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
else if(isset($_SERVER['HTTP_FORWARDED']))
$ipaddress = $_SERVER['HTTP_FORWARDED'];
else if(isset($_SERVER['REMOTE_ADDR']))
$ipaddress = $_SERVER['REMOTE_ADDR'];
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
?>

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

var_dump($_REQUEST);




5 changes: 5 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ Merchant Pre-Order API (For onboarded OPay merchants only)
$ composer require opay/merchant-cashier-php
```

### Examples:

- `example` folder
- `http_example` folder

#### Setup:
You need the following initialized
```php
Expand Down

0 comments on commit c48631e

Please sign in to comment.