forked from stripe-samples/accept-a-payment
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreturn.js
More file actions
26 lines (23 loc) · 857 Bytes
/
return.js
File metadata and controls
26 lines (23 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
document.addEventListener('DOMContentLoaded', async () => {
// Load the publishable key from the server. The publishable key
// is set in your .env file.
const {publishableKey} = await fetch('/config').then((r) => r.json());
if (!publishableKey) {
addMessage(
'No publishable key returned from the server. Please check `.env` and try again'
);
alert('Please set your Stripe publishable API key in the .env file');
}
const stripe = Stripe(publishableKey, {
apiVersion: '2020-08-27',
});
const url = new URL(window.location);
const clientSecret = url.searchParams.get('payment_intent_client_secret');
const {error, paymentIntent} = await stripe.retrievePaymentIntent(
clientSecret
);
if (error) {
addMessage(error.message);
}
addMessage(`Payment ${paymentIntent.status}: ${paymentIntent.id}`);
});