PHP code example of psp-sdk / psp-sdk-php

1. Go to this page and download the library: Download psp-sdk/psp-sdk-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

psp-sdk / psp-sdk-php example snippets


use Omnipay\Api\Api;

$secret_key = 'dCtLbk5FYVFGMVYrbFNGZTdEdzVpbSt3TFlYOC9NczNLaDZ0ZFo1WHcwVT0=';
$api_user_name = 'psp_test.eaohcfml.ZWFvaGNmbWw=';
$api_password = 'L1VPcklHbnh6T3RyWkdEVWZhci9HR1hSaHlrb0MwVEN5R0VtcUxkWHMwWT0=';
$apiMode = 0; // 0=Test, 1=Live
$api = new Api($api_user_name, $api_password, $apiMode); 

    //$api->class->function() to access the API
    //Example
    //This is for encrypt decrypt before call API
    //Create Payment
    $paymentParm = array('customer' =>array('name'=>'Raj', 'email'=>'[email protected]') ,'order'=>array('amount'=>'1', 'currency' => 'SAR'),'sourceOfFunds' => array('provided'=>array('card'=>array('number'=>'5123450000000008','expiry'=>array('month'=>'12','year'=>'2023'), 'cvv'=>'999')), 'cardType' => 'C'), 'remark'=>array('description'=>'This payment is done by card'));
    $api->encryptDecrypt->create($paymentParm, $secret_key, 'encrypt');
    // Payment API
    //Alwase send $param['trandata'] in encrypted string
    $param['trandata'] = $encripted_result['content']['apiResponse'];
    $result = $api->payment->createPayment($param);

     //STC Pay Create Payment
    $stcParm = array('Customer' =>array('Name'=>'Dharmraj Kumhar', 'Email'=>'[email protected]'),'DirectPaymentAuthorizeV4RequestMessage' =>array('MobileNo'=>'966557877988','Amount'=>'11','MerchantNote'=>'STC Payment'));
    $encripted_result = $api->encryptDecrypt->create($stcParm, $secret_key, 'encrypt');  
    // Payment API
    //Alwase send $param['trandata'] in encrypted string
    $param['trandata'] = $encripted_result['content']['apiResponse'];
    $result = $api->payment->stcPay($param);

    //If you want to use our checkout page please follow these instructions
    //Create Payment
    $paymentParm = array('customer_name'=>'Raj', 'customer_email'=>'[email protected]', 'amount'=>'100', 'currency'=>'SAR', 'remark'=>'This payment is done by card');
    $checkout = $api->payment->checkout($paymentParm);
    
    //Refund Transaction
    $refundParm = array('transaction' =>array('id'=>'nt8my581z620365207292e','amount'=>'1', 'currency' => 'SAR'), 'remark'=>array('description'=>'Refund transaction'));
    $encripted_result = $api->encryptDecrypt->create($refundParm, $secret_key, 'encrypt');
    $param['trandata'] = $encripted_result['content']['apiResponse'];
    $result = $api->payment->refund($param);
    
    //Retrive Transaction
    $result = $api->payment->retriveTransaction($transactionId);
    
    //Transaction List between two date range
    $AllTransParm = array('transaction' =>array('startdate'=>'2022-01-15','enddate'=>'2022-02-09'));
    $result = $api->payment->transactionList($AllTransParm);

    //subscription
    $parms = array('customer' =>array('name'=>'Raj','email'=>'[email protected]', 'interval'=>'1','interval_type'=>'3','interval_count'=>''),'order'=>array('amount'=>'1','currency' => 'SAR'),'sourceOfFunds' => array('provided'=>array('card'=>array('number'=>'5123450000000008','expiry'=>array('month'=>'12','year'=>'2023'), 'cvv'=>'999')),'cardType' => 'C'));
    $encripted_result = $api->encryptDecrypt->create($parms, $secret_key, 'encrypt');
    $param['trandata'] = $encripted_result['content']['apiResponse'];
    if(!empty($encripted_result['content']['apiResponse']) && $encripted_result['code'] == 200){
        $result = $api->payment->subscription($param);
    }

    //subscription detail
    $customer_id = "202130020209387";
    $result = $api->payment->subscriptionDetail($customer_id);

    //subscription cancel
    $customer_id = "202130294267467";
    $result = $api->payment->cancelSubscription($customer_id);

composer