PHP - Composer SDK

Integrating Amwal's installment into PHP applications using Composer package.

🚀 Introduction

This composer library provides a simple, object-oriented interface to interact with the Amwal APIs, allowing you to manage transactions, handle callbacks, and process refunds seamlessly.

📘

Information

This PHP composer library is designed for use with Composer and supports PHP 7.4 and higher.

📦 Installation

To install the SDK via Composer, run the following command in your terminal:

composer require amwal/php-sdk-composer

🛠 Configuration

Before making API calls, you need to initialize the client with your Merchant ID and Secret Key.

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

Validate Keys

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

Create Installment Payment Link

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

// Payment Object
$paymentData=[
    'amount'=>100, // minimum requirement 
    // 'language'=>'en',
    // 'description'=>'Test Payment',
    // 'client_email'=>'[email protected]',
    // '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'];

Get Payment / Transaction Details

There are two ways to retrieve the details: either fetch the complete information using the payment link ID, or obtain specific details for a particular transaction using its transaction 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 / Partial refund amount for specific transaction

// 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);