#Simon_WS-Checkout

1 messages · Page 1 of 1 (latest)

hoary lagoon
#

👋 happy to help

#

could you please elaborate more?

full bough
#

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

hoary lagoon
#

Sorry for the late reply, could you just bare with me for a minute?

full bough
#

no worries tarzan

#

sorry, I did type a lot!

hoary lagoon
#

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?

full bough
#

Yes - for Express Checkout

hoary lagoon
#

what do you mean by express checkout?

full bough
hoary lagoon
#

ok

full bough
#

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

hoary lagoon
#

but in that Payment Intent you haven't passed any customer Id nor metadata to store information

#

regarding the order

full bough
#

That is because at this point there is no customer

#

please can you provide me with an example / doc link?

hoary lagoon
#

there is no specific doc for this

full bough
#

Please can you clarify by what you mean by passing in metaData in the PaymentIntent? At this stage there is no customer record

hoary lagoon
#

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

full bough
#

in the client ui.stripeInstance.paymentRequest, I am passing the options requestPayerName, requestPayerEmail, requestPayerPhone and requestShipping as true

hoary lagoon
#

but regarding the shipping, it's not passed so unless you do pass it you wouldn't see it on the Payment Intent

full bough
#

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

hoary lagoon
#

yes I agree

full bough
#

so flow is:

  1. Create ui.stripeInstance.paymentRequest with options for shipping etc set to true
  2. if paymentRequest.canMakePayment then Create Payment Intent (serverside)
  3. 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

molten wing
#

Hi! I'm taking over this thread.

full bough
#

Hi Soma

molten wing
#

Please give me a few minutes to catchup.

full bough
#

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"

molten wing
#

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?

full bough
#

yes!

molten wing
#

Can you share an event ID (evt_xxx)? And clarify what information exactly you are looking for?

full bough
#

I am expecting to see:
"customer": "cus_LxWiSOCv4Z72Yl",

#

and also not:

#

"shipping": null,

#

but a populated "shipping" node

molten wing
#

Thanks! Give me a few minutes to look into this.

full bough
#

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"

sinful tangle
#

you have to add it yourself

#

the PaymentRequestButton just gives you the shipping info in your own code(in the on('paymentmethod') callback)

full bough
#

How do I add it myself?

sinful tangle
#

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

full bough
#

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"

sinful tangle
#

you can trust it

#

it's truncated in the on(shippingaddresschange) event

#

it's complete in the on(paymentmethod) event

full bough
#

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?!

sinful tangle
#

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

full bough
#

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?

sinful tangle
#

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?

full bough
#

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

sinful tangle