Merx

Checkout with Stripe’s Payment Intents

For Credit Card and SEPA Direct Debit payments, you need to use Stripe Payment Elements. During the payment flow, you need to create a Payment Intent. You can use the Cart::getStripePaymentIntent() method to create this Payment Intent.

The Merx Starterkit includes the complete payment flow for Stripe Elements. Feel free to look at the source code of the Starterkit to learn more about the implementation.

1. Get Payment Intent

Use $cart->getStripePaymentIntent() to get the client_secret and save the Payment Intent ID in a user session.

<?php
$paymentIntent = $cart->getStripePaymentIntent();
$clientSecret = $paymentIntent->client_secret;
$kirby->session()->set('stripePaymentIntentId', $paymentIntent->id);

You need the $clientSecret for the Stripe payment flow in step 2.
stripePaymentIntentId is required for initializePayment() in step 3.

2. Authorize the Payment Intent

Authorize the Payment Intent by following step 2 to 4 of Accept a payment (Custom payment flow) guide.

3. Initialize Payment

Use the Payment Intent ID saved in the user’s session and merge it with other user data.

<?php
$data = [
  'paymentMethod' => 'credit-card-sca',
  'email' => 'chuck@example.com',
  'name' => 'Chuck Norris',
  …
];
$stripePaymentIntentId = $kirby->session()->get('stripePaymentIntentId');
$data = array_merge($data, [
  'stripePaymentIntentId' => $stripePaymentIntentId,
]);
$redirect = merx()->initializePayment($data);
…