-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_billing.js
141 lines (115 loc) · 4.86 KB
/
_billing.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
function addBillingAddressHandler(ev) {
ev.preventDefault();
let title = ev.target.closest("[data-add-billing-address]").dataset.title;
ReCharge.Novum.sidebarHeading.innerHTML = title;
ReCharge.Novum.sidebarContent.innerHTML = `{% include '_billing_address_details.html' %}`;
let actionUrl = ReCharge.Endpoints.create_billing_address();
let billingForm = document.querySelector("#ReChargeForm_customer");
billingForm.setAttribute("action", actionUrl);
getShippingBillingCountries('billing');
ReCharge.Novum.Utils.getZipLabel();
billingForm.querySelector('.rc_btn').innerHTML = `{{ 'cp_create' | t }}`;
ReCharge.Novum.toggleSidebar();
}
function renderBillingAddressHandler(event) {
event.preventDefault();
let title = event.target.closest(".rc-card").dataset.title;
ReCharge.Novum.sidebarHeading.innerHTML = title;
ReCharge.Novum.sidebarContent.innerHTML = `{% include '_billing_address_details.html' %}`;
let actionUrl = ReCharge.Endpoints.update_billing_address();
let billingForm = document.querySelector("#ReChargeForm_customer");
billingForm.setAttribute("action", actionUrl);
let address = ReCharge.Novum.payment_sources[0].billing_address;
ReCharge.Forms.populateAddressData(address);
getShippingBillingCountries('billing');
ReCharge.Novum.Utils.getZipLabel(address.country);
ReCharge.Novum.toggleSidebar();
}
function renderPaymentMethod(ev) {
ev.preventDefault();
document.querySelector("body").classList.toggle("locked");
document
.getElementById("sidebar-card-underlay")
.classList.toggle("visible");
document
.getElementById("te-card-modal")
.classList.toggle("visible");
window.addEventListener("message", handleCardFrameMessage, false);
}
function handleCardFrameMessage(event) {
if (
event.origin.includes('shopifysubscriptions.com') ||
event.origin.includes('admin.rechargeapps.com')
) {
if (event.data && event.data.billingComplete) {
window.location.reload();
}
}
return;
}
{% if settings['has_shopify_connector'] %}
async function sendEmailRequest(ev) {
ev.preventDefault();
if (window.locked) {
return false;
}
window.locked = true;
const button = ev.target;
const buttonInitWidth = button.offsetWidth;
const data = {
'template_type': 'shopify_update_payment_information',
'type': 'email'
};
const url = ReCharge.Endpoints.send_shopify_connector_email();
ReCharge.Forms.toggleSubmitButton(button);
button.setAttribute('data-text', '{{ "cp_send_email_to_update" | t }}');
button.style.width = `${buttonInitWidth}px`;
button.style.pointerEvents = 'none';
try {
await axios({
url,
method: 'post',
data
});
ReCharge.Toast.addToast(`{{ 'cp_toast_success' | t }}`, `{{ 'cp_update_email_sent' | t }}`);
ReCharge.Forms.toggleSubmitButton(button);
button.removeAttribute('data-text');
button.disabled = true;
button.innerHTML = `{% include '_check-mark-sign.svg' %}`;
setTimeout(() => {
button.disabled = false;
button.innerHTML = `{{ "cp_send_email_to_update" | t }}`;
button.style.pointerEvents = 'auto';
}, 180000);
} catch (error) {
console.log(error);
let errorMessage = `{{ "cp_something_went_wrong" | t }}`;
if (error.response && error.response.data && error.response.data.error) {
errorMessage = error.response.data.error;
}
ReCharge.Forms.toggleSubmitButton(button);
button.removeAttribute('data-text');
ReCharge.Toast.addToast(`{{ 'cp_toast_error' | t }}`, errorMessage);
button.style.pointerEvents = 'auto';
} finally {
delete window.locked;
}
}
{% endif %}
(function() {
let closeCardSidebars = document.querySelectorAll(".close-card-sidebar");
closeCardSidebars.forEach(sidebar => {
sidebar.addEventListener("click", (event) => {
window.removeEventListener("message", handleCardFrameMessage, false);
renderPaymentMethod(event);
const creditCardForm = window[0].document.getElementById('credit-card-form'),
sepaDebitForm = window[0].document.getElementById('sepa-debit-form'),
paymentSelector = window[0].document.getElementById('payment-form-selection-page');
if (paymentSelector) {
paymentSelector.style.display = 'block';
creditCardForm.style.display = 'none';
sepaDebitForm.style.display = 'none';
}
});
});
})();