How to get default shipping address with Payment Request button before customers clicks "Pay"? I'm using Stripe.js & Elements - stripe-payments

I'm using Stripe's PaymentRequest button to collect payment & shipping information to later process the payment with Stripe on the server side. I'm targeting ApplePay, but currently testing under PaymentRequest API (Chrome).
I need to know the customer's shipping address to calculate & show tax amount (and update grand total) before the payment form is submitted. I can easily get it via "shippingaddresschange" event, but only if the customer changes the address.
How can I get the default shipping address that the payment request form is automatically loaded with if customer doesn't change it later on? The initial (default) address does not seem to trigger "shippingaddresschange" event.

See examples at https://rsolomakhin.github.io/pr/single/ and https://rsolomakhin.github.io/pr/multi/. Chrome pre-selects an address if you pre-select a shipping option that you're OK using for any address in the world, i.e., flat rate shipping world-wide. Here you would not know the shipping address until the user authorizes the payment.
However, in your case, you need to know the shipping address to calculate & show the tax amount. This means that you don't have a world-wide flat rate, so you would not pre-select a shipping option. In this case, Chrome requires the user to explicitly approve providing their address to you, which means that the user's address will not be pre-selected in the UI as it is implemented right now.

I think this is a bug with Chrome. Safari/ApplePay will trigger an initial onshippingaddresschange when the payment sheet is displayed but Chrome does not.
I've also run into an issue with Chrome where I select a shipping address and onshippingaddresschange triggers. I then cancel/dismiss the dialog and re-open but the "default" shipping address is selected and all of the data (i.e. shipping option, tax, etc...) in my payment sheet is still set from the previous onshippingaddresschange event.
ApplePay doesn't have the same issue because it will trigger that onshippingaddresschange event as soon as it opens.
This isn't really an "answer" but I'm hoping this provides a little more context.

There's is no such thing like default shipping address. User always has to explicitly choose one before you get shippingaddresschange event. This is for privacy reasons.

Related

What's the best practice for handling bill details with Stripe?

In my mobile app when the user has selected some items, I would like them to be able to review their order and see a preview of their bill (the price of each item, subtotal, taxes and total). However I would not want them to pay immediately. Once they place the order, they will not be charged until the order is accepted.
Do I calculate the user's subtotal, tax and total on my server or does stripe provide an api to handle these?
I've read the docs on invoicing and checkout, and checkout seems to be the api for my situation but I'm not 100% sure.
It depends on how you define "place the order" and "order is accepted". Normally when the Stripe's Checkout Session page is displayed to your customer and they push the "Pay" button, the transaction will be executed immediately (they paid), then the customer can be redirected back to your page or app.
If you want to somehow delay the payment until a specific timing (that you want to review or execute some logic, before eventually "accept" the order), you can consider using Checkout with Setup Intent.

Rule builder shipping postal code exclusion leads to no shipping when not logged in yet

whe created shipping rules, because we have to have to exclude shipping to isles for some products and/or some shipping methods. therefore we used the built-in shipping address: postal code option.
Problem is, when someone is not logged in yet, they dont get any shipping methods that use a postal code rule. so they get the message
"%oldShippingMethodName%" shipping is not available for your current cart, the shipping was changed to "%newShippingMethodName%".
After login or adding the address without creating an account, the other shipping is available again, but not preset as default anymore, even if higher prioritised.
So we have a preferable shipping method, but thats not working as primary one, because of this. anything we can do here to make things right?
So the way I see it you want to keep the shipping method available as long as the customer is not logged in, respectively has no billing address yet. You could logically chain the billing-zip-code-condition with the customer-is-logged-in-condition so that either one has to be true to make the shipping method available.

Stripe PaymentElement UI "accepts" card types that aren't accepted

I'm using the PaymentElement UI component to accept Stripe payments, which seems to be the way they're encouraging most people to go.
The docs say it "Automatically adjusts input fields to collect information based on the payment method and country... [and] Reduces friction for card payments with input validation, masking, styling and error handling."
The problem I'm having is that scrolling list of supported cards includes icons for cards which are not, in fact, supported in my region. And if someone enters one of those cards, it correctly identifies the icon, but doesn't throw a validation error — it waits until form submission and then fails to charge the card.
From a UX perspective, this seems less than ideal. OK, I get that 3056930009020004 correctly "validates" as a Diners Club card, but it seems that it should invalidate it in advance rather than waiting to actually try and complete the charge and responding with a "Your card is not supported" charge failure.
Is there a way I can (ideally) tell it to only include the cards that are actually supported automatically, or (alternatively) provide a list of cards it should display and validate?
If "no" to both of those, is this a bug? Can/should I report it as a bug or feature request to Stripe?

Can I redirect customer back to my store from Stripe Hosted Invoice page?

I'm generating Invoice object in Stripe and then redirecting customer to the hosted_invoice_url (https://stripe.com/docs/api/invoices/object#invoice_object-hosted_invoice_url)
After customer completes the payment, in the final step they are presented with two buttons - Download Invoice and Download Receipt, but there is no button/link for going back to my store. So it's a dead end. Customer can only close their browser tab.
Is there a way to specify something like success_url or home_url that would add a button for getting the customer back to my store?
Right now as a workaround I'm forcing hosted_invoice_url to open in a new tab. Customer closes the tab after they are finished and they get back to my store in the original tab.
From what I know, this is not possible with hosted invoices pages. I'd recommend relaying this use case/feedback directly to Stripe.
However, if you were to use Stripe Checkout you can pass success_url and cancel_url parameters which will fulfil your requirements in this case. Perhaps Checkout might be a better product for your use case?

Tax From Changed for Nexus

I am trying to create sales orders using WebServices from our CRM (Salesforce) to NetSuite. I am having an issue with international sales orders, in particular I am hitting this issue with United Kingdom.
If I create a sales order in the UI and set a bunch of field values and then set the Address to United Kingdom, I get a popup with the following message:
The address you have selected is based in a nexus for which you are required to charge a different kind of tax. Click OK to change the form to one that is applicable for that Nexus.
In the UI, when you click "ok", the page reloads and a few new tax fields appear (the fields are built in, denoted by the field ids). The problem is when the page reloads, all of the data is wiped out.
I did this UI testing to determine what was causing this. However, in WebServices, all the data sets at once (not able to be done in any "order"). What is happening with my webservice call is that it gets this same warning and then all of the data it tried to send is lost and then it tries to submit the record, hitting validation rules we have in place.
Has anyone hit this before? Is there a field or something I can set via webservices that is what NS is doing on the backend when you click "ok"?
I am open to any solution. I do have a ticket open with NS Support, however so far they have not been helpful. If I do get a resolution, I intend to post it for others.
to get around it, you can access the vendor first then select dropdown icon to open the purchase order

Resources