faizpay/php-payment-sdk

SDK for working with FaizPay payment APIs.

v1.0.4 2021-09-05 14:23 UTC

This package is auto-updated.

Last update: 2024-04-05 20:02:53 UTC


README

SDK for working with FaizPay payment APIs.

Documentation

Full documentation can be found at: https://documentation.faizpay.com

Requirements

PHP 7.0.0 and later.

Installation

You can install the bindings via Composer. Run the following command:

composer require faizpay/php-payment-sdk

To use the bindings, use Composer's autoload:

require_once('vendor/autoload.php');

Dependencies

Getting Started

Simple new payment looks like:

use FaizPay\PaymentSDK\Connection;
use FaizPay\PaymentSDK\Payment;

$connection = Connection::createConnection(
    $terminalId = '8afa74ae-6ef9-48bb-93b2-9fe8be53db50',
    $terminalSecret = '55d7d5ed-be22-4321-bb3f-aec8524d8be2'
);

$payment = Payment::createPayment(
    $connection,
    $orderId = 'AA-11', 
    $amount = '10.00'
);
 
$payment->process();

Webhook / Notification Handling

use FaizPay\PaymentSDK\Connection;
use FaizPay\PaymentSDK\NotificationHandler;

$connection = Connection::createConnection($terminalId, $terminalSecret);
$notificationHandler = NotificationHandler::createNotificationHandler($connection, $token = $_POST['token']);

// extract the order id
$orderId = $notificationHandler->getOrderID();

// fetch the order from your database
$data = findFromDatabase($orderId);

// if order is not found in system
if (checkIfEntryFound($data)) {
    echo "Invalid Token";
    die();
}

// validate if the requested payment matches with token
if (!$notificationHandler->validateAmount($data['amount'])) {
    echo "Invalid Token";
    die();
}

// all checks are passed - update the database to mark payment complete
updateDatabase($orderId, ['completed' => true]);

Optional: Set User or Pre Selected Provider For New Payment

use FaizPay\PaymentSDK\Connection;
use FaizPay\PaymentSDK\Payment;
use FaizPay\PaymentSDK\Provider;
use FaizPay\PaymentSDK\User;

$connection = Connection::createConnection($terminalId, $terminalSecret);
$payment = Payment::createPayment(
    $connection,
    $orderId = 'AA-11', 
    $amount = '10.00'
);

$user = User::createUser(
    $email = 'john.doe@test.com',
    $firstName = 'John',
    $lastName = 'Doe',
    $contactNumber = '07000845953'
);
$payment->setUser($user);

$provider = Provider::createProvider(
    $providerId = 'lloyds-bank',
    $sortCode = '123456',
    $accountNumber = '12345678'
);
$payment->setProvider($provider);