PHP code example of azozzalfiras / payment-gateway
1. Go to this page and download the library: Download azozzalfiras/payment-gateway 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/ */
azozzalfiras / payment-gateway example snippets
use AzozzALFiras\PaymentGateway\PaymentGateway;
use AzozzALFiras\PaymentGateway\Enums\Gateway;
use AzozzALFiras\PaymentGateway\Enums\PaymentStatus;
use AzozzALFiras\PaymentGateway\DTOs\PaymentRequest;
use AzozzALFiras\PaymentGateway\DTOs\Customer;
// Create gateway from enum
$gateway = PaymentGateway::create(Gateway::TAP->value, [
'secret_key' => 'sk_test_xxx',
'testMode' => true,
]);
// Or use typed static factory
$gateway = PaymentGateway::stripe(['secret_key' => 'sk_test_xxx', 'testMode' => true]);
// Purchase
$response = $gateway->purchase(new PaymentRequest(
amount: 100.00,
currency: 'SAR',
orderId: 'ORDER-001',
description: 'Premium Plan',
callbackUrl: 'https://yoursite.com/callback',
customer: new Customer(name: 'Ahmed', email: '[email protected]'),
));
// Redirect customer to payment page
header("Location: {$response->paymentUrl}");
// Check payment status
$status = $gateway->status($response->transactionId);
// Gateway metadata from enum
echo Gateway::TAP->label(); // "Tap Payments"
echo Gateway::TAP->region(); // "MiddleEast"
echo Gateway::TAP->supportsRefund(); // true
echo Gateway::TAP->countries(); // ['KWT', 'SAU', 'ARE', ...]