#loterak_api
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1308430197133148270
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
hi! yeah, I don't think there's really a way to do that since we don't support sending line items for the PaymentElement. Apple Pay would just show the amount on the PaymentIntent from your Subscription's first invoice, which is the after-discount total.
Right now the user is seeing the following which is the amount sent when the payment element is created.
But as you can see in the background, we want to discount them for 25% of the price.
On the manual CC flow, when a user submits the payment we create a subscription with the necessary info, and get a client_secret that's later used by confirmPayment().
What happens with Apple pay and other payment methods that have their own UI? Does it do the whole confirm payment flow with whatever amount was first sent when creating the payment element?
I assume you mean are using what we call the "deferred" integration where you don't need a clientSecret at page load. If so, those wallet UIs use the amount set in the params , and you need to update that when it changes in your logic so the popup will show the correct total.
https://docs.stripe.com/js/elements_object/create_without_intent#stripe_elements_no_intent-options-amount
https://docs.stripe.com/js/elements_object/update#elements_update-options-amount
Okay so by updating the amount the user will get charged correctly at least.
The issue with that is we won't be able to link the amount to the actual promo-code/coupon that was used to grant them the discount.
true, yes
we have plans for future products that will let you use the PaymentElement but get the benefits of Checkout features like line items and discounts, so that will eventually be the solution here:
https://docs.stripe.com/checkout/custom-checkout
Okay so by updating the amount the user will get charged correctly at least.
to clarify, the user is charged the amount on your PaymentIntent. The amount on the frontend/popup doesn't change what their actual card is charged
but obviously yes you'd want them to match to avoid customer confusion/complaints/disputes etc
also I notice you say "we create a subscription on the default_incomplete state, and apply the discount to that" , does that actually work in practise or is it just your plan? Because I think you might have a common misunderstanding, which is that you expect that an incomplete subscription can be used as a "draft" while you edit/change details on the checkout page; but it doesn't, the Invoice of an incomplete Subscription is already finalized and locked. The only real solution to having a draft is to use our Checkout product, or build your own bespoke UI that manages all the updates and only creates the Subscription at the very end, or use that Custom Checkout product when that is fully ready
That seems to be working in practice yes, we've had the custom checkout UI running for a few months already.
I would say we are doing exaclty what you described here:
build your own bespoke UI that manages all the updates and only creates the Subscription at the very end
sounds good!
So the last piece I'm not fully understanding is when is that PaymentIntent getting created in the case of Apple/Google Pay.
becuase on the manual CC flow we get the payment intent after user submits all payment info. We create the subscription on our backend and use the subscription.latest_invoice.payment_intent&.client_secret to finalize the payment in the client
yes, that's when it's created, when you create the Subscription.
the flow here that I assume you're using is https://docs.stripe.com/payments/accept-a-payment-deferred?platform=web&type=subscription .
yeah pretty sure that's the doc we followed
you can see that the Subscription(and thus the PaymentIntent) is created when you submit the form and call your backend. This flow all works the same regardless of payment method overall
it is assumed that you're tracking the total on the frontend and updating it as you go using the method I mentioned earlier(so that at the point you call elements.submit() which show the Apple UI, it has the right amount), and that you end up creating the Subscription with details that lead it to having a matching amount
okay so users should be getting charged correctly, and it's just a matter of them not seeing the right UI because we are not changing it with the update
yep
for completeness I'll mention that the update function https://docs.stripe.com/js/elements_object/create_without_intent#stripe_elements_no_intent-options-amount is a bit of a pain to use. It's async but doesn't return a Promise, instead you have to listen to an event to know the update happened. https://docs.stripe.com/js/element/events/on_update_end That makes it more complicated to do something like "only update the amount when the form submits" , which otherwise is a good approach here.
(
i.e. if you do like elements.update({amount:finalSubtotal}); await elements.submit(), the Apple UI might still show the old amount because the update didn't finish
)
thank you for the heads up!
One last question! Because my region doesn't support Apple Pay so I won't be able to easily test it.
After you go through the Apple Pay flow you still need to click my custom submit button in order to subscribe?
๐ howdy, karllekko had to step away so I'm here to help now
Briefly, no, that should not be necessary unless you want an additional final step in your flow after payment details have been provided.
You can call confirmPayment after elements.submit() succeeds and you get your intent from the subscription creation
I'm doing that last piece in the logic after you click my custom submit button. But I'm having a hard time understanding if an Apple pay flow would go through that code or not.
If it doesn't then the subscription would never get the discount correctly applied.
Are you using confirmation tokens to create a two-step flow? I don't completely understan what you mean by this:
I'm doing that last piece in the logic after you click my custom submit button.
If you could share your submit handler sequence that might help
But I'd expect to you would handle Apple Pay the same way
not sure if this helps at all but here's the template of payment element component we created:
<form id="payment-form" data-test-stripe-payment-element>
<div
id="payment-element"
{{did-insert this.mountStripePaymentElement}}
data-test-payment-element-container
>
{{! Stripe will create form elements here }}
</div>
<BU::Divider id="payment-divider" class="my-24" />
{{yield}}
{{#if @paymentInProcess}}
<wb-loading-indicator class="my-24" data-test-payment-element-loading />
{{else}}
<BU::Button
@onClick={{@submitPayment}}
@variant="primary"
id="payment-submit"
class="w-full my-24"
data-test-payment-element-submit
>
{{t "buttons.subscribe"}}
</BU::Button>
{{/if}}
<p id="payment-terms" class="type-body-s">
{{t "consumer.checkout.paymentSection.terms"}}
</p>
</form>
The submitPayment function that gets triggered by clicking the subscribe button is the only logic that triggers:
-
a
stripeElements.submit() -
a request to create a
default_incompletesubscription so we can get the paymentIntentclient_secret -
a
stripeInstance.confirmPayment(client_secret)that finalizes the ceremony and charges the customer
Right, so that would apply to Apple Pay too then. The browser UI is triggered by that elements.submit() call and the details are using during confirmPayment.
Ohh okay so the Apple Pay UI won't show up until elements.submit() is executed?
Correct
Perfect! Thank you ๐