1. Go to this page and download the library: Download onepay/laravel-checkout 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/ */
onepay / laravel-checkout example snippets
use OnePay\Checkout\Services\OnePayService;
use OnePay\Checkout\Exceptions\OnePayException;
public function pay(OnePayService $onePay)
{
try {
$response = $onePay->createCheckoutLink([
'reference' => 'ORD-' . $order->id, // hone_number' => '+94771234567',
'customer_email' => '[email protected]',
'transaction_redirect_url' => 'https://yoursite.test/payment/return',
// optional:
// 'additionalData' => 'extra context for the transaction',
// 'items' => ['item_id_1', 'item_id_2'],
]);
if (! $response->succeeded()) {
// Handle logical failure using $response->rawResponse
}
return redirect()->away($response->redirectUrl);
} catch (OnePayException $e) {
if ($e->hasRemoteErrorPayload()) {
// OnePay JSON: message + error — see $e->getRemoteMessage(), getRemoteError()
}
throw $e;
}
}