1. Go to this page and download the library: Download payriff/payriff-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/ */
payriff / payriff-php example snippets
use Payriff\Payriff;
$payriff = new Payriff(appKey: getenv('PAYRIFF_APP_KEY'));
$order = $payriff->orders->create([
'amount' => '10.00',
'description' => 'Order #1001',
'callbackUrl' => 'https://shop.example/payriff/callback',
'requestRrn' => 'order-1001',
]);
// Send the customer to the hosted payment page
header('Location: ' . $order['paymentUrl']);
use Payriff\Payriff;
use Payriff\Region;
$payriff = new Payriff(appKey: getenv('PAYRIFF_APP_KEY'), region: Region::SAUDI);
$created = $payriff->orders->create([
'amount' => '25.00',
'currency' => 'AZN', // default: the region currency
'operation' => 'PRE_AUTH', // default PURCHASE
'language' => 'AZ',
'description' => 'Booking #77',
'callbackUrl' => 'https://shop.example/payriff/callback',
'metadata' => ['bookingId' => '77'],
]);
$info = $payriff->orders->get($created['orderId']);
$byRef = $payriff->orders->getByRequestRrn('order-1001'); // the requestRrn you sent on create
$payriff->orders->complete(['orderId' => $created['orderId'], 'amount' => '25.00']);
$payriff->orders->refund(['orderId' => $created['orderId'], 'amount' => '5.00', 'refundReason' => 'Partial return']);
$payriff->orders->expire($created['orderId']); // cancel an unpaid order
$receiptPdf = $payriff->orders->downloadReceipt($created['orderId']);
use Payriff\Webhook;
$notified = Webhook::parseOrderCallback(file_get_contents('php://input')); // also accepts a decoded array
// Callbacks are not signed: confirm the state with Payriff before fulfilling.
$confirmed = $payriff->orders->get($notified['orderId']);
if ($confirmed['paymentStatus'] === 'APPROVED') {
// fulfil the order (make this idempotent: the same callback can arrive more than once)
}
http_response_code(200);