Skip to content

Commit a1a0e4e

Browse files
committed
More flexible payment element options
1 parent 1fdcb18 commit a1a0e4e

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,21 @@ $payment->setDetails([
5656
'email' => $email, // Used for the customer to be able to save payment details
5757
],
5858
'limit_payment_type' => 'card', // Optionally limit to card transactions only, to disable Afterpay / Klarna / Zip etc.
59-
'payment_method_order' => ['apple_pay', 'google_pay', 'card'], // Optionally re-order the wallets to be before card if they apply to the transaction
59+
'payment_method_options' => [
60+
'layout' => 'tabs',
61+
'paymentMethodOrder' =>
62+
[
63+
'apple_pay',
64+
'google_pay',
65+
'card',
66+
], // Optionally re-order the wallets to be before card if they apply to the transaction
67+
'defaultValues' => [
68+
'billingDetails' => [
69+
'name' => $customer_name,
70+
'email' => $customer_email,
71+
], // Optionally prefill some fields for some payment types
72+
],
73+
],
6074
]);
6175
$storage->setInternalDetails($payment, $request);
6276

src/Action/ObtainNonceAction.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,14 @@ public function execute($request) {
7070
}
7171

7272
$model['stripePaymentIntent'] = \Stripe\PaymentIntent::create($paymentIntentData);
73+
$payment_element_options = $model['payment_element_options'] ?? [];
7374
$this->gateway->execute($renderTemplate = new RenderTemplate($this->templateName, array(
7475
'amount' => $model['currencySymbol'] . ' ' . number_format($model['amount'], $model['currencyDigits']),
7576
'client_secret' => $model['stripePaymentIntent']->client_secret,
7677
'publishable_key' => $model['publishable_key'],
7778
'actionUrl' => $uri->withPath('')->withFragment('')->withQuery('')->__toString() . $getHttpRequest->uri,
7879
'imgUrl' => $model['img_url'],
79-
'payment_method_order' => json_encode($model['payment_method_order'] ?? []),
80+
'payment_element_options' => json_encode($payment_element_options),
8081
'billing' => $model['billing'] ?? [],
8182
)));
8283

src/Resources/views/Action/obtain_nonce.html.twig

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@
4646
clientSecret: '{{ client_secret }}',
4747
});
4848
49-
const paymentElementOptions = {
50-
layout: "tabs",
51-
paymentMethodOrder: {{ payment_method_order|raw }},
52-
};
49+
const paymentElementOptions = {{ payment_element_options|raw }}
5350
5451
const paymentElement = elements.create("payment", paymentElementOptions);
5552
paymentElement.mount("#payment-element");

0 commit comments

Comments
 (0)