seitime-frappe/frappe/templates/includes/integrations/stripe_checkout.js
Saurabh 286b79bd90 Stripe payment integration (#2867)
* [fix] setting page for stripe

* checkout flow for stripe payment

* controller to handle stripe checkout and authorization
2017-04-06 17:27:23 +05:30

47 lines
1.3 KiB
JavaScript

$(document).ready(function(){
(function(e){
var handler = StripeCheckout.configure({
key: "{{ publishable_key }}",
token: function(token) {
// You can access the token ID with `token.id`.
// Get the token ID to your server-side code for use.
stripe.make_payment_log(token, {{ frappe.form_dict|json }}, "{{ reference_doctype }}", "{{ reference_docname }}");
}
});
handler.open({
name: "{{payer_name}}",
description: "{{description}}",
amount: cint("{{ amount }}" * 100), // 2000 paise = INR 20
email: "{{payer_email}}",
currency: "{{currency}}"
});
})();
})
frappe.provide('stripe');
stripe.make_payment_log = function(token, data, doctype, docname){
$('.stripe-loading').addClass('hidden');
$('.stripe-confirming').removeClass('hidden');
frappe.call({
method:"frappe.templates.pages.integrations.stripe_checkout.make_payment",
freeze:true,
headers: {"X-Requested-With": "XMLHttpRequest"},
args: {
"stripe_token_id": token.id,
"data": JSON.stringify(data),
"reference_doctype": doctype,
"reference_docname": docname
},
callback: function(r){
if (r.message && r.message.status == 200) {
window.location.href = r.message.redirect_to
}
else if (r.message && ([401,400,500].indexOf(r.message.status) > -1)) {
window.location.href = r.message.redirect_to
}
}
})
}