|
6 | 6 | function renderPaypal() { |
7 | 7 | paypal.Buttons({ |
8 | 8 |
|
9 | | - |
10 | 9 | onInit: function(data, actions) { |
11 | 10 | // Set up the buttons. |
12 | 11 | if (form.valid()) { |
13 | | - actions.enable() |
| 12 | + actions.enable(); |
14 | 13 | } |
15 | 14 | else { |
16 | 15 | actions.disable(); |
17 | 16 | } |
18 | 17 |
|
19 | 18 | form.on('blur keyup change', 'input', function (event) { |
20 | 19 | if (form.valid()) { |
21 | | - actions.enable() |
| 20 | + actions.enable(); |
22 | 21 | } |
23 | 22 | else { |
24 | 23 | actions.disable(); |
|
28 | 27 |
|
29 | 28 | createBillingAgreement: function (data, actions) { |
30 | 29 |
|
| 30 | + // CRM.payment.getTotalAmount is implemented by webform_civicrm and mjwshared. The plan is to |
| 31 | + // add CRM.payment.getTotalAmount() into CiviCRM core. This code allows it to work under any of |
| 32 | + // these circumstances as well as if CRM.payment does not exist. |
| 33 | + var totalAmount = 0.0; |
| 34 | + if ((typeof CRM.payment !== 'undefined') && (CRM.payment.hasOwnProperty('getTotalAmount'))) { |
| 35 | + totalAmount = CRM.payment.getTotalAmount(); |
| 36 | + } |
| 37 | + |
| 38 | + if (typeof calculateTotalFee == 'function') { |
| 39 | + // This is ONLY triggered in the following circumstances on a CiviCRM contribution page: |
| 40 | + // - With a priceset that allows a 0 amount to be selected. |
| 41 | + // - When we are the ONLY payment processor configured on the page. |
| 42 | + totalAmount = parseFloat(calculateTotalFee()); |
| 43 | + } |
| 44 | + else if (document.getElementById('total_amount')) { |
| 45 | + // The input#total_amount field exists on backend contribution forms |
| 46 | + totalAmount = parseFloat(document.getElementById('total_amount').value); |
| 47 | + } |
| 48 | + |
31 | 49 | var frequencyInterval = $('#frequency_interval').val() || 1; |
32 | 50 | var frequencyUnit = $('#frequency_unit').val() ? $('#frequency_interval').val() : CRM.vars.omnipay.frequency_unit; |
33 | | - var paymentAmount = calculateTotalFee(); |
34 | 51 | var isRecur = $('#is_recur').is(":checked"); |
35 | 52 | var recurText = isRecur ? ' recurring' : ''; |
36 | 53 |
|
37 | 54 | return new Promise(function (resolve, reject) { |
38 | 55 | CRM.api3('PaymentProcessor', 'preapprove', { |
39 | 56 | 'payment_processor_id': CRM.vars.omnipay.paymentProcessorId, |
40 | | - 'amount': paymentAmount, |
| 57 | + 'amount': totalAmount, |
41 | 58 | 'currencyID' : CRM.vars.omnipay.currency, |
42 | 59 | 'qf_key': qfKey, |
43 | 60 | 'is_recur' : isRecur, |
44 | 61 | 'installments' : $('#installments').val(), |
45 | 62 | 'frequency_unit' : frequencyUnit, |
46 | 63 | 'frequency_interval' : frequencyInterval, |
47 | | - 'description' : CRM.vars.omnipay.title + ' ' + CRM.formatMoney(paymentAmount) + recurText, |
| 64 | + 'description' : CRM.vars.omnipay.title + ' ' + CRM.formatMoney(totalAmount) + recurText, |
48 | 65 | } |
49 | 66 | ).then(function (result) { |
50 | 67 | if (result['is_error'] === 1) { |
|
0 commit comments