ea4ca04a61c8b86374d759b334d58d97a190b6b2
[Evergreen.git] / Open-ILS / src / templates-bootstrap / opac / parts / stripe.tt2
1 [%- PROCESS "opac/parts/header.tt2" %]
2 [% IF ctx.use_stripe %]
3         <script type="text/javascript" src="https://js.stripe.com/v2/"></script> <!-- use an ou setting for this url? -->
4         <script type="text/javascript">
5         // This script is only displayed when logged in, so ctx.user.home_ou is always available
6         Stripe.setPublishableKey('[% ctx.get_org_setting(ctx.user.home_ou.id, 'credit.processor.stripe.pubkey') %]');
7
8         function stripe_onsubmit() {
9             var form = document.getElementById("payment_form");
10             var button = document.getElementById("payment_submit");
11
12             button.disabled = true;
13
14             Stripe.card.createToken(form, stripe_callback);
15
16             return false;
17         }
18
19         function stripe_callback(status, response) {
20             var form = document.getElementById("payment_form");
21             var button = document.getElementById("payment_submit");
22             var stripe_token = document.getElementById("stripe_token");
23
24             if(response.error) {
25                 alert(response.error.message);
26                 button.disabled = false;
27                 return;
28             }
29
30             stripe_token.value = response.id; // response.id is the token id, though there are more fields available if needed.
31             form.setAttribute("onsubmit","");
32             form.submit();
33         }
34         </script>
35 [%- END %]