diff --git a/README.md b/README.md index 84cf113..2986717 100644 --- a/README.md +++ b/README.md @@ -185,7 +185,12 @@ The Stripe plugin handles this relationship using [nested elements](https://craf {{ price.data|unitAmount }} {{ tag('a', { text: "Buy now", - href: price.getCheckoutUrl(), + href: price.getCheckoutUrl( + currentUser ?? false, + 'shop/thank-you?session={CHECKOUT_SESSION_ID}', + product.url, + {} + ), }) }} {% endfor %} @@ -198,20 +203,20 @@ When a customer is ready to buy a product or start a subscription, you’ll prov Clicking a checkout link takes the customer to Stripe’s hosted checkout page, where they can complete a payment using whatever methods are available and enabled in your account. -To output a checkout link, use the `craft.stripeCheckoutUrl()` function: +To output a checkout link, use the `stripeCheckoutUrl()` function: ```twig {% set price = product.prices.one() %} {{ tag('a', { - href: craft.stripe.checkout.getCheckoutUrl( + href: stripeCheckoutUrl( [ { price: price.stripeId, quantity: 1, }, ], - null, + currentUser ?? false, 'shop/thank-you?session={CHECKOUT_SESSION_ID}', product.url, {} @@ -220,6 +225,9 @@ To output a checkout link, use the `craft.stripeCheckoutUrl()` function: }) }} ``` +> [!TIP] +> Passing `false` as the second parameter to the `stripeCheckoutUrl()` allows you to create an anonymous checkout URL. + ### Checkout Form As an alternative to generating static Checkout links, you can build a [form](https://craftcms.com/docs/5.x/development/forms.html) that sends a list of items and other params to Craft, which will create a checkout session on-the-fly, then redirect the customer to the Stripe-hosted checkout page: @@ -232,6 +240,9 @@ As an alternative to generating static Checkout links, you can build a [form](ht {{ actionInput('stripe/checkout') }} {{ hiddenInput('successUrl', 'shop/thank-you?session={CHECKOUT_SESSION_ID}'|hash) }} {{ hiddenInput('cancelUrl', 'shop'|hash) }} + {% if not currentUser %} + {{ hiddenInput('customer', 'false') }} + {% endif %}