Reputation: 695
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!
Upvotes: 43
Views: 19154
Reputation: 1
With node js, you can use this code. This solution worked for me:
const stripe = require("stripe")(process.env.STRIPE_KEY);
#Id of payment intent
payment_intent_id = "pi_XXXXXXX"
const paymentIntent = await stripe.paymentIntents.retrieve(
payment_intent_id,
{
expand: ['latest_charge'],
}
);
console.log("receiptUrl: " ,paymentIntent?.latest_charge?.receipt_url);
Upvotes: 0
Reputation: 52198
The trick is to give expand: ['latest_charge']
as a parameter. That will return a lot more information for the payment_intent, including a receipt_url
.
(this uses ruby but it will be similar for other languages):
require 'stripe'
# Id of payment intent
payment_intent_id = "pi_3NcGv9Bn74CpQJ8BC8kJU"
# Call api
response = Stripe::PaymentIntent.retrieve(
{ id: payment_intent_id, expand: ['latest_charge'] }
)
# Access receipt_url
response.latest_charge.receipt_url
=> "https://pay.stripe.com/receipts/payment/CAcaFwmC71adF8xTlp5cVdSVDI4UU1SNUhXKP-SwP0majgw4UwY6LBYjNcus8XsJxgeD71QMWCmZWtZvMwc9hJpJwync86sjFH2gJ0-ukROFt6EA"
Specific styles can be configured here:
expand: ['latest_charge']
tells the API to return not just the id of the latest_charge, but all the associated info as well (including the receipt_url
)For Stripe Connect, you must give expand: ['latest_charge']
as a parameter and the stripe account id as an option.
Example:
require 'stripe'
# Id of payment intent
payment_intent_id = "pi_3NcGv9Bn74CpQJ8BC8kJU"
# Id of account funds were paid to
stripe_account_id = "acct_1NJyqN2Ab3GCK1HW"
# Call api
response = Stripe::PaymentIntent.retrieve(
{ id: payment_intent_id, expand: ['latest_charge'] },
{ stripe_account_id: stripe_account_id }
)
# Access receipt_url
response.latest_charge.receipt_url
=> "https://pay.stripe.com/receipts/payment/CAcaFwmC71adF8xTlp5cVdSVDI4UU1SNUhXKP-SwP0majgw4UwY6LBYjNcus8XsJxgeD71QMWCmZWtZvMwc9hJpJwync86sjFH2gJ0-ukROFt6EA"
Upvotes: 2
Reputation: 30736
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.
Upvotes: 5
Reputation: 11
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
Upvotes: 1
Reputation: 411
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).
Upvotes: 23
Reputation: 8528
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
Upvotes: 0