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