dotlines-io/ghoori-ondemand

This package can be used for OnDemand Payment integration with Ghoori Platform.

1.1.3 2021-05-22 12:02 UTC

This package is auto-updated.

Last update: 2024-10-25 18:42:49 UTC


README

Latest Version on Packagist Tests Psalm GitHub Code Style Action Status Total Downloads Total Downloads

This composer package can be used for OnDemand payment integration with Ghoori Platform. For the credentials, please contact with support@ghoori.com.bd or call 8809612332215

Installation

You can install the package via composer:

composer require dotlines-io/ghoori-ondemand

Usage

/**
 * ******************************************************
 * ******************* Token Fetching *******************
 * *********** Contact Ghoori For Credentials ***********
 * ******************************************************
 */
$tokenUrl = 'https://<SERVER_URL>/oauth/token';
$username = '';
$password = '';
$clientID = '';
$clientSecret = '';

$accessTokenRequest = \Dotlines\Ghoori\AccessTokenRequest::getInstance($tokenUrl, $username, $password, $clientID, $clientSecret);
$tokenResponse = $accessTokenRequest->send();
echo json_encode($tokenResponse) . '<br/>';

/**
 * Access Token Request Response looks like below:
 * {
 *  "token_type": "Bearer",
 *  "expires_in": 3600,
 *  "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdW.....",
 *  "refresh_token": "def50200284b2371cad76b4d2a4e24746c44fd6a322....."
 * }
 */

/**
 * Access Token can be cached and reused for 1 hour
 * Before the end of accessToken lifetime every hour
 * you can use the refresh token to fetch new accessToken & refreshToken
 */
$accessToken = $tokenResponse['access_token'];
$refreshToken = $tokenResponse['refresh_token'];

/**
 * ******************************************************
 * ******************* Charge Request *******************
 * ******************************************************
 */
$chargeUrl = 'https://<SERVER_URL>/api/v2.0/charge';
$orderID = ''; //must be unique for each request
$package = ''; //must be pre-registered with Ghoori
$amount = ''; //must be greater than or equal to BDT 2
$callBackURL = ''; //user will be redirected back this url
$details = ''; //optional
$mobile = ''; //optional
$email = ''; //optional
$reference = ''; //optional
$chargeRequest = \Dotlines\GhooriOnDemand\ChargeRequest::getInstance($chargeUrl, $accessToken, $clientID, $orderID, $package, $amount, $callBackURL, $details, $mobile, $email, $reference);
echo json_encode($chargeRequest->send()) . '<br/>';

/**
 * Success Charge Request Response looks like below.
 * You must redirect the user to the "url" for payment.
 * {
 *  "url": "https://sb-payments.ghoori.com.bd/v2.0/pay/BD/bKash?spTransID=5QUWSGRBP41EE46",
 *  "spTransID": "5QUWSGRBP41EE46",
 *  "errorCode": "00",
 *  "errorMessage": "Operation Success"
 * }
 * Fail response only contains errorCode & errorMessage
 */

/**
 * ******************************************************
 * ******************* Status Request *******************
 * ******************************************************
 */
$statusUrl = 'https://<SERVER_URL>/api/v2.0/status';
$spTransID = '';
$statusRequest = \Dotlines\GhooriOnDemand\StatusRequest::getInstance($statusUrl, $accessToken, $clientID, $spTransID);
echo json_encode($statusRequest->send()) . '<br/>';

/**
 * Status Request Response looks like below:
 * {
 *  "processingStatus": "CHARGED",
 *  "status": "DONE",
 *  "amount": "10.00",
 *  "errorCode": "00",
 *  "errorMessage": "Operation Successful",
 *  "bKashTransID": "6JS7L72YMV",
 *  "reference": "reference not provided"
 * }
 * Fail response only contains errorCode & errorMessage
 */

/**
 * ******************************************************
 * ******************* Refresh Token *******************
 * ******************************************************
 */
$refreshTokenRequest = \Dotlines\Ghoori\RefreshTokenRequest::getInstance($tokenUrl, $accessToken, $clientID, $clientSecret, $refreshToken);
$tokenResponse = $refreshTokenRequest->send();
echo json_encode($tokenResponse) . '<br/>';

/**
 * Refresh Token Request Response looks like below:
 * {
 *  "token_type": "Bearer",
 *  "expires_in": 3600,
 *  "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdW.....",
 *  "refresh_token": "def50200284b2371cad76b4d2a4e24746c44fd6a322....."
 * }
 */

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see License File for more information.