Checkout
Checkout sessions
A checkout session is a PayMongo-hosted payment page for a set of line items. You send the customer to its checkout URL, and PayMongo sends them back to your success or cancel URL. A session is either active or expired: there is no canceled status, so to cancel a checkout your application expires the session. Sessions made here are separate from the Demo catalog's Guest checkouts, which this scenario never touches.
Every demonstration here makes a real PayMongo API call in test mode. Nothing is simulated, and no real money moves.
Create checkout session
Create a hosted checkout page for one line item. Open the checkout URL in the summary to see the page PayMongo hosts.
Test mode: To see a canceled checkout, open the checkout URL and leave through the page's back link. PayMongo only redirects to the cancel URL: the session stays active and could still be paid. Retrieve it to see that, then expire it, which is how an application cancels a checkout.
use Luigel\Paymongo\Facades\Paymongo;
$checkoutSession = Paymongo::checkoutSessions()->create(
attributes: [
'line_items' => [
[
'name' => 'Playground demo item',
'amount' => 10000,
'currency' => 'PHP',
'quantity' => 1,
],
],
'payment_method_types' => [
'card',
'gcash',
'paymaya',
],
'description' => 'Laravel PayMongo Playground demo',
'success_url' => 'https://paymongo.rigelkentcarbonel.com/scenarios/checkout-sessions?returned=success',
'cancel_url' => 'https://paymongo.rigelkentcarbonel.com/scenarios/checkout-sessions?returned=cancel',
'send_email_receipt' => false,
'show_line_items' => true,
],
);Retrieve checkout session
Fetch a session to see whether it is still active, and any payments made on it.
use Luigel\Paymongo\Facades\Paymongo;
$checkoutSession = Paymongo::checkoutSessions()->retrieve(
id: '{checkout_session id}',
);Expire checkout session
Cancel a checkout so it can no longer be paid. PayMongo also cancels the session's payment intent.
Test mode: PayMongo refuses with an HTTP 400 when the session is already expired, has been paid, or has a payment in progress. Expire the same session twice to see how the package surfaces that.
use Luigel\Paymongo\Facades\Paymongo;
$checkoutSession = Paymongo::checkoutSessions()->expire(
id: '{checkout_session id}',
);