#Simon_WS-Checkout
1 messages · Page 1 of 1 (latest)
sure - we have already implemented using an ApplePay "Payment Request" button in our checkout (final step) along with Stripe Elements (Card) and using the PaymentIntentService API to retrieve charge data upon payment completion.
https://stripe.com/docs/stripe-js/elements/payment-request-button
Example/test Apple Pay payment completed this way:
https://dashboard.stripe.com/test/payments/pi_3LFb7FK5LTv40UrO1AyaZ0JI
I am now working on adding an "Express Checkout" alternative for Apple Pay including the PaymentRequst.requestShipping option to allow customers to bypass checkout on the website and complete via ApplePay
Example payment:
https://dashboard.stripe.com/test/payments/pi_3LFbdDK5LTv40UrO01Yde1ZF
My problem is when the payment is completed "
charge.succeeded" callback from Stripe I am not able to retrieve the customer_ID or shipping details
Please can you confirm how I can retrieve the customer_id linked to a PaymentIntent/Charge and also it's Shipping Address
Note: we use the synchronous client initiated callback for Payment Intent and Charge - we are not listening for the "
charge.updated" event
Sorry for the late reply, could you just bare with me for a minute?
and it's quite a busy discord shift 🙈
is this pi_3LFbdDK5LTv40UrO01Yde1ZF the PI that you used to generate the payment for your custom checkout flow?
Yes - for Express Checkout
what do you mean by express checkout?
ok
I mean, initiating a ui.stripeInstance.paymentRequest on the basket page to allow ApplePay customers to bypass the usual checkout flow (eg login, billing, shipping) and to instead jump straight to ApplePay and we then get the billing and shipping back from Stripe
but in that Payment Intent you haven't passed any customer Id nor metadata to store information
regarding the order
That is because at this point there is no customer
please can you provide me with an example / doc link?
there is no specific doc for this
Please can you clarify by what you mean by passing in metaData in the PaymentIntent? At this stage there is no customer record
you're not passing nor a customer nor shipping info
actually let me correct myself, you are passing the customer
but you need to listen to payment_intent.succeeded to get that info on the PaymentIntent Object
in the client ui.stripeInstance.paymentRequest, I am passing the options requestPayerName, requestPayerEmail, requestPayerPhone and requestShipping as true
but regarding the shipping, it's not passed so unless you do pass it you wouldn't see it on the Payment Intent
when creating the PaymentIntent:
var options = new PaymentIntentCreateOptions {
Amount = Convert.ToInt32(paymentTotal * 100), // in pence
Description = (stripeTestMode ? "Test_" : string.Empty) + "Order ID : " + order.OrderID.ToString(),
Currency = order.Currency.ISO3Code,
CaptureMethod = captureAuthImmediately ? "automatic" : "manual",
SetupFutureUsage = "off_session",
AutomaticPaymentMethods = new PaymentIntentAutomaticPaymentMethodsOptions {
Enabled = true,
}
};
... I am not passing in options.Customer at this stage as there is no customer to link to
yes I agree
so flow is:
- Create ui.stripeInstance.paymentRequest with options for shipping etc set to true
- if paymentRequest.canMakePayment then Create Payment Intent (serverside)
- When payment completed in Stripe we handle callback for payment_intent.succeeded
it is in step 3 that I am expecting to retrieve the Guest customer_id and shipping address details
I think what you are saying is that I have to pass in an empty record /metadata for step 2 PaymentIntent customer. Is that correct?
The summary of this property in the Stripe.cs library states this is "ID of the Customer this PaymentIntent belongs to, if one exists.Payment methods attached to other Customers cannot be used with this PaymentIntent. If present in combination with setup_future_usage this PaymentIntent's payment method will be attached to the Customer after the PaymentIntent has been confirmed and any required actions from the user are complete".
But as stated, no customer exists at this stage
Hi! I'm taking over this thread.
Hi Soma
Please give me a few minutes to catchup.
sure
just to add to this!
I can see in the article here: https://stripe.com/docs/stripe-js/elements/payment-request-button?html-or-react=html#html-js-collecting-shipping-info
that I can retrieve selected shipping address data from ApplePay via this callback endpoint - however the notes also state "The address data on the shippingaddresschange event may be anonymized by the browser to not reveal sensitive information that is not necessary for shipping cost calculation." - ie the purpose of this is to check shipping cost is valid, not to actually get the shipping address - I am therefore not wanting to use this method to get the delivery address and I am expecting to see it in the payment_intent.succeeded JSON > "shipping"
So if I understand correctly, your integration with Apple Pay is working, but you think some data is missing in the payment_intent.succeeded event?
yes!
Can you share an event ID (evt_xxx)? And clarify what information exactly you are looking for?
I am expecting to see:
"customer": "cus_LxWiSOCv4Z72Yl",
and also not:
"shipping": null,
but a populated "shipping" node
Thanks! Give me a few minutes to look into this.
around 30 seconds later the charge.updated event is fired (we don't listen for this as payment flow is synchronous) - at this point there is a value for customer
but shipping is still "null"
you have to add it yourself
the PaymentRequestButton just gives you the shipping info in your own code(in the on('paymentmethod') callback)
How do I add it myself?
you read it from the event https://stripe.com/docs/js/appendix/payment_response#payment_response_object-shippingAddress
and then you can use it to .e.g pass into confirmCardPayment
or just use the PaymentElement/Checkout which do this for you rather than the separate PaymentRequestButton
see myt comment for:
I can see in the article here: https://stripe.com/docs/stripe-js/elements/payment-request-button?html-or-react=html#html-js-collecting-shipping-info
that I can retrieve selected shipping address data from ApplePay via this callback endpoint - however the notes also state "The address data on the shippingaddresschange event may be anonymized by the browser to not reveal sensitive information that is not necessary for shipping cost calculation." - ie the purpose of this is to check shipping cost is valid, not to actually get the shipping address - I am therefore not wanting to use this method to get the delivery address and I am expecting to see it in the payment_intent.succeeded JSON > "shipping"
this to me implies I cannot trust the data in:
https://stripe.com/docs/js/appendix/payment_response#payment_response_object-shippingAddress
you can trust it
it's truncated in the on(shippingaddresschange) event
it's complete in the on(paymentmethod) event
The full shipping address appears in the PaymentResponse object after the purchase is confirmed in the browser’s payment interface
ah, ok. We are using stripe.js for handling the ui.stripeInstance.confirmCardPayment event.
If this succeeds I think what you are saying is that the confirmResult object will also include a populated shipping address - is that right?!
no
I mean in
paymentRequest.on('paymentmethod', function(ev) {
, you can access ev.shippingAddress , that is the final shipping address the customer entered in the popup
you can then write custom code to read that value, parse it, and then pass it into https://stripe.com/docs/js/payment_intents/confirm_card_payment#stripe_confirm_card_payment-data-shipping when you call confirmCardPayment within the callback, so that the shipping information appears in Stripe, you have to do that manual "gluing together" for this to work
right! I think I assumed that Stripe / Apple Pay would already deal with storing the Shipping details (as is already done for card details such as billing_details
Is there any way I can also retrieve the customerID ("cus_") or is this also something I need to push to Stripe?
not sure I follow exactly. The Customer object is something you create by calling the API before a payment(and then generally store the returned cus_xxx ID in your database). What's the context?
again, I think down to a misunderstanding on my part in thinking the customer is automatically created in Stripe as opposed to needing to be created. In our current flow (for card elements) we are doing this (ie creating a new Stripe Customer and retriving it's cus_ id) after the payment has been captured
Thanks for your help - the main aim of this thread was to help me retrieve a shipping address entered or selected during an ApplePay checkout and I will go away and look at implementing the changes you have suggsted above
the customer doesn't get automatically created unless you're using our hosted Checkout page for example