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