1. Go to this page and download the library: Download scanandpay/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/ */
scanandpay / php example snippets
use ScanAndPay\ScanAndPay;
use ScanAndPay\Exceptions\WebhookSignatureException;
$client = new ScanAndPay(
merchantId: getenv('SCANANDPAY_MERCHANT_ID'),
apiSecret: getenv('SCANANDPAY_API_SECRET'),
webhookSecret: getenv('SCANANDPAY_WEBHOOK_SECRET'), // optional
baseUrl: getenv('SCANANDPAY_API_BASE_URL') ?: 'https://api.scanandpay.com.au',
);
// 1. Create a session at checkout. Amount is float dollars.
$session = $client->createSession(
amount: 19.90, // $19.90
platformOrderId: 'order_456',
payId: '[email protected]',
merchantName: 'Acme Coffee',
);
// 2. Render the QR widget on the page.
echo scanandpay_checkout($session, pollUrl: '/scanandpay/status');
// 3. In your webhook handler, verify and consume the event.
try {
$event = $client->webhooks()->verify(
signature: $_SERVER['HTTP_X_SCANPAY_SIGNATURE'] ?? '',
body: file_get_contents('php://input'),
);
if ($event->isPaid()) {
// Mark order paid using $event->orderId, $event->txId, ...
}
} catch (WebhookSignatureException $e) {
http_response_code(401);
exit('Invalid webhook');
}