PHP code example of amwal / php-sdk-composer

1. Go to this page and download the library: Download amwal/php-sdk-composer 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/ */

    

amwal / php-sdk-composer example snippets

 
$amwal = new AmwalPay([
    'amwalPublicKey' => 'sandbox-XXXX', // or 'production-yyy'
    'amwalSecretAPIKey' => 'SECRET API Key',
]);


// validate merchant configuration
    $amwal->testConnection();

// Amwal Store ID
$storeId='Amwal-Store-ID';

// Payment Object
$paymentData=[
    'amount'=>100, // minimum   // 'callback_url'=>'https://example.com/callback',
    // 'client_phone_number'=>'+966501234567',
];

$payment=$amwal->createPayment($paymentData, $storeId);
echo 'Amwal Payment URL <a href="'.$payment['payment_url'].'">Click Here</a> <br/>'; 
echo 'Amwal Payment Link ID '.$payment['payment_link_id'];

    // Getting Payment Link ID details
    $paymentDetails=$amwal->getPaymentDetails('amwal-Payment-Link-ID');
    echo 'Payment Details: <pre>'; print_r($paymentDetails);

    // Getting Transaction ID details
    $transactionDetails=$amwal->getPaymentDetails('amwal-trx-ID',false);
    echo 'Specific Transaction Details: <pre>'; 
    print_r($transactionDetails);
 
    // refund an amount for specific transaction
    $refundData = ['refund_amount'=>10,
    'transaction_id'=>'amwal-trx-ID',
    ];
    $refundDetails=$amwal->refundPayment($refundData);
    echo 'Refund Details: <pre>'; 
    print_r($refundDetails);
bash
composer