]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/js/ui/default/circ/selfcheck/payment.js
Separate payment form code from the rest of the self check interface
[Evergreen.git] / Open-ILS / web / js / ui / default / circ / selfcheck / payment.js
1 var proto = (
2     (typeof(SelfCheckManager) == "undefined") ?
3         (function PaymentForm() {}) : SelfCheckManager
4 ).prototype;
5
6 proto.drawPayFinesPage = function(patron, onPaymentSubmit) {
7     if (!this.finesTBody)
8         this.finesTBody = dojo.byId("oils-selfck-fines-tbody");
9
10     // find the total selected amount
11     var total = 0;
12     dojo.forEach(
13         dojo.query('[name=selector]', this.finesTbody),
14         function(input) {
15             if(input.checked)
16                 total += Number(input.getAttribute('balance_owed'));
17         }
18     );
19     total = total.toFixed(2);
20
21     dojo.query("span", "oils-selfck-cc-payment-summary")[0].innerHTML = total;
22
23     oilsSelfckCCNumber.attr('value', '');
24     oilsSelfckCCMonth.attr('value', '01');
25     oilsSelfckCCYear.attr('value', new Date().getFullYear());
26     oilsSelfckCCFName.attr('value', patron.first_given_name());
27     oilsSelfckCCLName.attr('value', patron.family_name());
28     var addr = patron.billing_address() || patron.mailing_address();
29
30     if(addr) {
31         oilsSelfckCCStreet.attr('value', addr.street1()+' '+addr.street2());
32         oilsSelfckCCCity.attr('value', addr.city());
33         oilsSelfckCCState.attr('value', addr.state());
34         oilsSelfckCCZip.attr('value', addr.post_code());
35     }
36
37     dojo.connect(oilsSelfckEditDetails, 'onChange',
38         function(newVal) {
39             dojo.forEach(
40                 [   oilsSelfckCCFName,
41                     oilsSelfckCCLName,
42                     oilsSelfckCCStreet,
43                     oilsSelfckCCCity,
44                     oilsSelfckCCState,
45                     oilsSelfckCCZip
46                 ],
47                 function(dij) { dij.attr('disabled', !newVal); }
48             );
49         }
50     );
51
52
53     var self = this;
54     dojo.connect(oilsSelfckCCSubmit, 'onClick',
55         function() {
56             progressDialog.show(true);
57             self.sendCCPayment(onPaymentSubmit);
58         }
59     );
60 }
61
62 // In this form, this code only supports global on/off credit card
63 // payments and does not dissallow payments to transactions that started
64 // at remote locations or transactions that have accumulated billings at
65 // remote locations that dissalow credit card payments.
66 // TODO add per-transaction blocks for orgs that do not support CC payments
67
68 proto.sendCCPayment = function(onPaymentSubmit) {
69
70     var args = {
71         userid : this.patron.id(),
72         payment_type : 'credit_card_payment',
73         payments : [],
74         cc_args : {
75             where_process : 1,
76             number : oilsSelfckCCNumber.attr('value'),
77             expire_year : oilsSelfckCCYear.attr('value'),
78             expire_month : oilsSelfckCCMonth.attr('value'),
79             billing_first : oilsSelfckCCFName.attr('value'),
80             billing_last : oilsSelfckCCLName.attr('value'),
81             billing_address : oilsSelfckCCStreet.attr('value'),
82             billing_city : oilsSelfckCCCity.attr('value'),
83             billing_state : oilsSelfckCCState.attr('value'),
84             billing_zip : oilsSelfckCCZip.attr('value')
85         }
86     }
87
88
89     // find the selected transactions
90     dojo.forEach(
91         dojo.query('[name=selector]', this.finesTbody),
92         function(input) {
93             if(input.checked) {
94                 args.payments.push([
95                     input.getAttribute('xact'),
96                     Number(input.getAttribute('balance_owed')).toFixed(2)
97                 ]);
98             }
99         }
100     );
101
102
103     var resp = fieldmapper.standardRequest(
104         ['open-ils.circ', 'open-ils.circ.money.payment'],
105         {params : [this.authtoken, args]}
106     );
107
108     progressDialog.hide();
109
110     var evt = openils.Event.parse(resp);
111     if (evt)
112         alert(evt);
113     else if (typeof(onPaymentSubmit) == "function")
114         onPaymentSubmit();
115 }