PHP code example of islam016 / laravel-safe-checkout
1. Go to this page and download the library: Download islam016/laravel-safe-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/ */
islam016 / laravel-safe-checkout example snippets
use IslamGaber\SafeCheckout\Facades\Checkout;
use IslamGaber\SafeCheckout\Money;
public function pay(Order $order)
{
$payment = Checkout::start(
Money::fromMajor($order->total, 'SAR'), // "150.75" -> 15075 halalas
idempotencyKey: "order-{$order->id}", // same order = same checkout, never two
payable: $order,
options: ['description' => "Order #{$order->id}"],
);
return redirect()->away($payment->checkout_url);
}
use IslamGaber\SafeCheckout\Events\PaymentSucceeded;
use IslamGaber\SafeCheckout\Events\PaymentFailed;
Event::listen(function (PaymentSucceeded $event) {
$event->payment->payable->markAsPaid(); // fired exactly once per payment
});
Event::listen(function (PaymentFailed $event) {
// failed, expired, or amount_mismatch (see $event->payment->failure_reason)
});