-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaymentForm.js
More file actions
110 lines (103 loc) · 2.8 KB
/
paymentForm.js
File metadata and controls
110 lines (103 loc) · 2.8 KB
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
$("#current-page").val(location.href);
var datamail;
$(document).ready(function () {
$("form#wf-form-Payment-Form").on("submit", function (event) {
var query_string = $(this).serialize();
console.log(query_string);
var form_data = objectFromWebFlowQuerystring(query_string);
console.log(form_data);
datamail = form_data;
form_data["Current Page"] = window.location.href;
form_data.form_name = "Payment Form";
hitWebhook(
form_data,
(url = "https://analytics.blackboardradio.com/webhook")
);
hitWebhook(
form_data,
(url = "https://analytics.blackboardradio.com/webflow_webhook")
);
event.preventDefault();
setTimeout(function () {
redirectToPaymentPage();
}, 1000);
return false;
});
function redirectToPaymentPage() {
var params = window.location.search;
var url;
var emailParam = "&billing_email=" + datamail["email"];
if (params) {
url = datamail["email"]
? "https://pay.blackboardradio.com/cartflows_step/checkout" +
params +
"&billing_phone=" +
datamail["Phone"] +
"&add-to-cart=1515" +
emailParam
: "https://pay.blackboardradio.com/cartflows_step/checkout" +
params +
"&billing_phone=" +
datamail["Phone"] +
"&add-to-cart=1515";
} else {
url = datamail["email"]
? "https://pay.blackboardradio.com/cartflows_step/checkout" +
"?billing_phone=" +
datamail["Phone"] +
"&add-to-cart=1515" +
emailParam
: "https://pay.blackboardradio.com/cartflows_step/checkout" +
"?billing_phone=" +
datamail["Phone"] +
"&add-to-cart=1515";
}
window.location.href = url;
}
function objectFromWebFlowQuerystring(
query_string,
required_keys = [
"Child-s-Name",
"Phone",
"City",
"Class",
"Current Page",
"LeadSource",
"parental-expectation",
"Language-at-Home",
"email",
]
) {
var params = new URLSearchParams(query_string);
var obj = {};
for (const key of params.keys()) {
if (required_keys.includes(key)) {
obj[key] = params.get(key);
}
}
if ($("#Child-s-Name").val()) {
obj["Child's Name"] = $("#Child-s-Name").val();
}
if ($("input#WhatsappConsent:checked").length > 1) {
obj["WhatsappConsent"] = "true";
} else {
obj["WhatsappConsent"] = "false";
}
obj["LeadSource"] = "Website";
return obj;
}
function hitWebhook(form_data, url) {
$.ajax({
url: url,
data: form_data,
type: "POST",
dataType: "json",
error: function () {
console.log("error");
},
success: function (data) {
console.log("success");
},
});
}
});