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

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?

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.

How to use stripe checkout for first come, first served buying experience

I'm trying to use Stripe checkout in a first-come, first-served buying process. Multiple buyers may be trying to buy the same item at the same time, and only the one who completes the stripe checkout process first should get it. At the moment, the stripe checkout session duration requires me to 'book' the stock item and only release them back into stock once the session duration expires (even if they close the tab).
Is there a way to set up Stripe Checkout in a way that would detect whether the item has already been purchased by another buyer (e.g. the stock is no longer available), and for example show an error when the user tries to pay?
If not, any suggestions as to alternative ways of implementing this functionality while still using Stripe?
You can listen for checkout.session.completed events and add some event handler logic to retrieve the Session object while expanding the line_items:
https://stripe.com/docs/payments/checkout/fulfill-orders
https://stripe.com/docs/api/expanding_objects
This will allow you to inspect the price and product IDs for the completed Session. You could then have some logic to expire any other Checkout sessions so no other customers are able to go through the payment flow:
https://stripe.com/docs/payments/checkout/managing-limited-inventory
https://stripe.com/docs/api/checkout/sessions/expire
You can use the paymentIntent that allows you to confirm or reject the payment later. You can create the paymentIntent for all the customers are trying at the same time and next take the first one and confirm only this paymentIntent and reject the others
Read the Stripe documentation:
Stripe | PaymentIntent

Connect order number on Wix module page from a stripe order link

I am trying to create an ordering process that starts from the product page, than a button links to a stripe checkout link and from there I would like (when the user completes the checkout) to show a link that has a custom parameter or a query argument that is referring to the order number that will be passed/retrieved (when the user clicks) to the Wix page on a custom label that shows the order number.
When you create a Checkout Session, you can pass a success_url where your customer will be redirected after a successful payment. You control that URL so you can put what you need in it to identify the customer when they come back.
Separately, you can use metadata to store information such as the Wix order number that you want to map them with.
After a successful payment, your customer is redirected back to your Wix page where you will be able to write code to retrieve the Session via the API and find the corresponding Wix order number.

Stripe receipt url

From the Stripe dashboard I can view a receipt (click preview link in invoice details). The receipt is then shown inside a popup but there is a permalink in it, so it can be viewed as a separate page. The URL of an emailed receipt looks like this:
https://dashboard.stripe.com/emails/receipts/invrc_xxxxxxxxxxxx
This URL does not require authentication, and so would be perfect for allowing me to show links to receipt details from inside my app's billing page. Except that there seems to be no way to get the magical invrc_xxxxxxxxxxxx id from the API, so I am unable construct the URL.
Or for some strange reason, Stripe engineers went through the trouble of designing an unauthenticated receipt view page, but have decided not to expose it via the API. Why??
This issue has been brought up in Stripe API - Receipts Listing (see comments section at the bottom), but no explanation, solution or justification was provided. Hope this more specific question can help.
UPDATE: As of January 17 2019, this is now possible to do. The Charge object has the receipt_url property that lets you access this information whether an email receipt was sent or not!
That's unfortunately not something currently supported. There isn't any way through the API to get an receipt ID to be used here. That endpoint was built with the intent that it would only be used to permalink to a receipt from the body of a receipt email. That said, we are considering building out this functionality at some point in the future.
EDIT: Looks like my colleagues in Stripe support beat me to the punch here.
UPDATE: as of 2019-01-17, this is now supported via the receipt_url property on Charges (https://stripe.com/docs/api/charges/object#charge_object-receipt_url).
The invoice object has attributes for this:
hosted_invoice_url - string - The URL for the hosted invoice page, which allows customers to view and pay an invoice. If the invoice has not been finalized yet, this will be null.
invoice_pdf - string - The link to download the PDF for the invoice. If the invoice has not been finalized yet, this will be null.
Solved using screenshot API
If you are using React try this but you can just use the ajax request to show the receipt in your app
const [recipt, setrecipt] = useState({loading: false,img: '',});
get the url from the strip response receipt_url
const url = receipt_url
const result = await axios.get(`https://screenshotapi.net/api/v1/screenshot url=${url}&token=yourtokenhere`,);
then you can find the png URL from result.data.screenshot
then you can use img tag to display it make sure to replace token with yours
Is this to resend a new email? There is an option send emails to the customer in the settings on successful payment. Another idea is to have the email send to something like Mandrill for processing and extract the URL:
http://help.mandrill.com/entries/21699367-Inbound-Email-Processing-Overview

Security: Passing payment amount to PayPal

From what I understand, using the PayPal api, you can pass your payment amount by populating a hidden HTML input field which will be submitted to PayPal.
What I've got so far looks somewhat like this:
<input type="hidden" name="amount" value="60.00">
My question is - isn't this super unsafe? What's there to stop someone from changing the payment value in the element inspector for instance?
You may want to use PayPal ButtonManager API operation in order to programatically create, manage, edit, and delete PayPal Payment Standard buttons, which are the same kind of buttons that you can create from the PayPal Profile.
Hosted buttons created by this API reside on PayPal and can use all features, including inventory management; however, you can use this API to create code for non-hosted Standard buttons as well.
The button you will create from this API request will look like:
https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=19218
As you can see no values like "business", "amount" or others are visible and for this reason this would be a safe solution and personally I'd recommend it.
Back to your question "What's there to stop someone from changing the payment value in the element inspector for instance?"
We recommend to use API requests (see ExpressCheckout or ButtonManager to create Standard buttons) and Instant Payment Notifications service (IPN), which is a message service that notifies you of events related to PayPal transactions. You can use IPN messages to automate back-office and administrative functions, such as fulfilling orders, tracking customers, and providing status and other transaction-related information.

Resources