iqex/cashier-client-yii2

Yii2 package client for iqex.pro


Keywords
php, rest, api, client, extension, yii2, iqex.pro
License
MIT

Documentation

PHP API client for iqex.pro

A simple API client, written with PHP for iqex.pro.

IQEX.PRO provides ...

For additional information about API visit

IQEX.PRO API Terms of Service

Requirements

  • PHP >=5.6
  • ext-json
  • guzzlehttp/guzzle ~7.0

Installation

The preferred way to install this extension is through composer.

Either run

$ composer require iqex/cashier-client-yii2:*

or add

"iqex/cashier-client-yii2": "*"

Basic usage

Set config to config/params.php

<?php

return [
    'iqexCashier' => [
        'sec_key' => 'd2fdc44a3effff549892683a24793cb08fd7956057b72202f7b99a5cb8c13318', // Generated code for payment module on your website, example: 07b32232ea89cc2324780b7e22e7bdddd08b66c473800ef10fb8ba09af7171b1
        'merchant_id' => 7, // Your merchant id
        'environment' => ''
    ]
];

Example

use Iqex\MerchantApi\MerchantClient;

$client = new MerchantClient();
$data = $client->ping();

You can get last response (ResponseInterface::class) uses getLastResponse method:

use Iqex\MerchantApi\MerchantClient;

$checkoutData = [
     'order_id' => '92f91094',
     'products' => [
         'title' => 'My product title',
         'price' => 1200,
         'thumb' => 'Path to product thumb'
      ],
     'currency' => 'USD',
     'amount' => 1,
     'lang' => 'EN',
     'callback_url' => 'https://skortabeast.com/callback-url',
     'success_url' => 'https://skortabeast.com/success-url',
     'cancel_url' => 'https://skortabeast.com/cancel-url',
     'redirect_url' => 'https://skortabeast.com/redirect-url'
];

$data = (new Payment)->make($checkoutData);

$response = $data->getLastResponse();
$headers = $response->getHeaders();

Available methods

Ping

ping

Check API server status

$data = $client->ping();

Pay

storeInvoice

Make invoice to your market (order_id, merchant_id, products, currency, amount, lang, callback_url, success_url, cancel_url, redirect_url, signature)

Description:


order_id - Your order id
merchant_id - Your ID from dashboard
products - JSON representation of a value in array. e.g.:  [{'title':'My product title','price':1200,'thumb':'Path to product thumb'}]
currency - Product currency code, e.g.: USD
amount
lang - Lang payment page, (e.g., EN)
callback_url - The URL of your webhook endpoint, (e.g.: https://example.com/callback-url)

Payment statuses: 
10 - CREATED
15 - PENDING
20 - CANCELED
25 - DECLINED
30 - EXPIRED
35 - ERROR
50 - APPROVED

Example notification:
{
     'signature':'HASH',
     'payment_id':'92f91094-c6ce-4c6e-9e81-37b67ef94838',
     'merchant_id':'1',
     'order_id':'1',
     'status':'30'
}
You should return in response with http-status 200. *
success_url - URL for success page - make sure they are publicly accessible so we can redirect customers to them. You can also handle both the success, pending and canceled states with the same URL.
              (e.g.: https://example.com/success-url)
cancel_url - URL for cancel page - make sure they are publicly accessible so we can redirect customers to them. You can also handle both the success, pending and canceled states with the same URL.
              (e.g.: https://example.com/cancel-url)
redirect_url - URL for pending page - make sure they are publicly accessible so we can redirect customers to them. You can also handle both the success, pending and canceled states with the same URL.
               (e.g.: https://example.com/redirect-url)
signature - The signature is generated by generating a hash code based on the secret key using the HMAC method and the sha512 algorithm which is applied to the string string consisting of the merchant sec key and all parameters concatenated to it in alphabetical order and separated by the pipe |

$checkoutData = [
     'order_id' => '92f91094',
     'products' => [
             'title' => 'My product title',
             'price' => 1200,
             'thumb' => 'Path to product thumb'
          ],
     'currency' => 'USD',
     'amount' => 1,
     'lang' => 'EN',
     'callback_url' => 'https://skortabeast.com/callback-url',
     'success_url' => 'https://skortabeast.com/success-url',
     'cancel_url' => 'https://skortabeast.com/cancel-url',
     'redirect_url' => 'https://skortabeast.com/redirect-url'
];

$data = (new Payment)->make($checkoutData);

Withdrawal

make

Make withdrawal(order_id, merchant_id, currency, amount, address, type, callback_url, signature)

Description:


order_id - Your order id
merchant_id - Your ID from dashboard
currency - Product currency code, e.g.: USD
amount
address - Withdrawal address
type - Withdrawal type:
       1 - withdrawal,
       2 - refund,
       3 - payout,
callback_url - The URL of your webhook endpoint, (e.g.: https://example.com/callback-url)

Payment statuses: 
5 - CREATED
10 - PENDING
20 - APPROVED
30 - CANCELED
40 - INTERNAL ERROR
45 - INTERNAL ERROR
50 - ERROR

Example notification:
{
      'amount':'54140.04',
      'address':'111111111111111111111111111',
      'errors': [],
      'withdrawal_currency_id':'BTC',
      'signature':'HASH',
      'status':'20',
      'order_id':'1',
      'currency_id':'USD',
      'hash':222222222222222,
      'withdrawal_amount':'1'
}
You should return in response with http-status 200. *
signature - The signature is generated by generating a hash code based on the secret key using the HMAC method and the sha512 algorithm which is applied to the string string consisting of the merchant sec key and all parameters concatenated to it in alphabetical order and separated by the pipe |

$checkoutData = [
     'order_id' => '92f91094',
     'currency' => 'USD',
     'amount' => 1,
     'address' => 'your_address',
     'type' => 1,
     'callback_url' => 'https://skortabeast.com/callback-url',
];

$data = (new Withdrawal)->make($checkoutData);

Validate callback

make

Validate callback

Description:

//withdrawal
$checkoutPayload = [
   'payment_id' => 'your payment id',
   'status' => 1,
   'order_id' => '92f91094',
   'signature' => 'your signature'
];

//or
//withdrawal

$checkoutWithdrawal = [
   'currency_code' => 'USD',
   'withdrawal_currency_code' => 'USD',
   'address' => '1231',
   'amount' => 1,
   'withdrawal_amount' => 1,
   'hash' => '1231',
   'order_id' => '92f91094',
   'status' => '45',
   'error_msg' => 'iternal error',
   'signature' => 'your signature'
];

if ((new SignatureValidate())->isValidSignature($payload)) {
      return [
         'success' => true
      ];
}

return [
       'success' => false,
       'error' => 'Signature is not valid'
 ];

License

iqex/cashier-client-yii2 is released under the MIT License. See the bundled LICENSE for details.