-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmembership-handler.js
57 lines (47 loc) · 1.79 KB
/
membership-handler.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function handleMembershipPage($) {
console.log('Running handleMembershipPage()');
var stripe = Stripe('pk_live_51Hdye3KZR9nDGYgsq1hcFQtKBdlsOZN2PQtXwkYGj0Ng4g3wDpJ8mEKH1xsmDC1FxUbGPgTloqLcG7E8WWtg92SR00tCV2q23g');
$('#membership-form').on('submit', function(event) {
event.preventDefault();
var requestBody = {
payment: {
frequency: 'recurring',
product: 'prod_IMhoqk3abIHKhu',
amount: $(this.amount).val(),
currency: $(this.currency).val(),
interval: $(this.interval).val(),
},
checkout: {
cancel_url: $(this.cancel_url).val(),
success_url: $(this.success_url).val(),
},
customer: {
name: $(this.first_name).val() + ' ' + $(this.last_name).val(),
email: $(this.email).val(),
phone: $(this.phone).val(),
address: {
line1: $(this.address_line_1).val(),
line2: $(this.address_line_2).val(),
city: $(this.city).val(),
postal_code: $(this.postal_code).val(),
}
},
meta: {}
};
$.ajax({
url: "https://stripe-donation-worker.theideabureau.co/api/checkout/coSANnEP5sk2ONLJ",
method: 'POST',
data: requestBody,
accepts: {
text: "application/json"
}
})
.done(function( data ) {
stripe.redirectToCheckout({
sessionId: data.session_id
}).then((result) => {
alert("There was an error directing you to the payment, please refresh and try again.");
});
});
});
}