-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstripePay.js
More file actions
31 lines (28 loc) · 1.16 KB
/
stripePay.js
File metadata and controls
31 lines (28 loc) · 1.16 KB
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
27
28
29
30
31
window.onload = function() {
// Your code, and code from Stripe's walkthrough goes here.
var stripe = Stripe('pk_test_nHbbAEYUN1yjjvLjl33Drozr');
document.getElementById("btn").addEventListener('click',
function() {
let numberInputs=document.getElementsByClassName("quantity");
let items = [];
for (i=0; i<numberInputs.length; i++){
let item = {
sku: numberInputs[i].dataset.sku,
quantity: parseInt(numberInputs[i].value)
}
items.push(item)
}
console.log(items);
stripe.redirectToCheckout({
items:items,
successUrl: 'http://localhost:8000/success.html',
cancelUrl: 'http://localhost:8000/cancel.html',
}).then(function (result) {
// If `redirectToCheckout` fails due to a browser or network
// error, display the localized error message to your customer
// using `result.error.message`.
console.log(result.error.message) // ADD THIS LINE!
});
}
);
}