· 4 years ago · Apr 08, 2021, 03:16 PM
1<script type="text/javascript">
2 // Create an instance of the Stripe object with your publishable API key
3 var stripe = Stripe(
4 "pk_test_51IHRZWC1cqUw70bvsmHdJHaL9SEqXyzyJrBF70xdsrrPR24vPed9UuIA14QS3IgRnFTvzyZKoA9mu9qpVL5Orhr500lhojwakR"
5 );
6
7 const getPriceFromPlan = (plan) => {
8 const pricePlans = { nike10: 4.94 };
9 return pricePlans[plan];
10 };
11
12 const paymentFunctions = (plan) => {
13 var checkoutButton = document.getElementById(`${plan}-checkout-button`);
14
15 checkoutButton.addEventListener("click", function () {
16 const amount = document.getElementById(`${plan}-quantity`).value;
17 const currentCoupon = document.getElementById(`${plan}-coupon-field`).value;
18 fetch(
19 `/checkout_session?product=${plan}&amount=${amount}&discount=${currentCoupon}`,
20 {
21 method: "POST",
22 }
23 )
24 .then(function (response) {
25 return response.json();
26 })
27 .then(function (session) {
28 if (session.id === "stock_error") {
29 alert(
30 "We ran out of stock on this item. Please check back later!"
31 );
32 } else {
33 return stripe.redirectToCheckout({ sessionId: session.id });
34 }
35 })
36 .then(function (result) {
37 if (result.error) {
38 alert(result.error.message);
39 }
40 })
41 .catch(function (error) {
42 console.error("Error:", error);
43 });
44 });
45
46 var discountVerifyButton = document.getElementById(
47 `${plan}-verify-discount`
48 );
49
50 discountVerifyButton.addEventListener("click", function () {
51 const currentCoupon = document.getElementById(`${plan}-coupon-field`)
52 .value;
53 document.getElementById(`error-message-${plan}`).innerHTML = "";
54 fetch(`/verify_discount?discount=${currentCoupon}`)
55 .then((response) => {
56 return response.json();
57 })
58 .then((data) => {
59 console.log(data.discount);
60 document.getElementById(`${plan}-price`).innerHTML =
61 "$" + getPriceFromPlan(plan) * data.discount;
62 if (data.discount === 1) {
63 document.getElementById(`error-message-${plan}`).innerHTML =
64 "Coupon not found";
65 }
66 });
67 });
68 };
69
70 const proxyFunctions = (proxyBrand) => {
71 var proxyBox = document.getElementById(`${proxyBrand}-proxies`);
72 const allProxyProducts = [document.getElementById(`ping-products`), document.getElementById(`stat-products`), document.getElementById(`space-products`)]
73
74 proxyBox.addEventListener("click", function () {
75 for (var p = 0; p < allProxyProducts.length; p++) {
76 allProxyProducts[p].style = "background-image: none; display: none;"
77 }
78 document.getElementById(`${proxyBrand}-products`).style = "background-image: none; opacity: 0;"
79 setTimeout(function () {
80 document.getElementById(`${proxyBrand}-products`).style = "background-image: none; opacity: 1;"
81 }, 500)
82 })
83
84 }
85
86 paymentFunctions("nike10");
87 // paymentFunctions("charge");
88 // paymentFunctions("volt");
89 // paymentFunctions("elite");
90 // paymentFunctions("statcharge");
91 // paymentFunctions("statelite");
92 // paymentFunctions("spacecharge");
93 // paymentFunctions("spaceelite");
94 // paymentFunctions("pingcharge");
95 // paymentFunctions("pingelite");
96 // paymentFunctions("blankcharge");
97 // paymentFunctions("blankelite");
98
99 // proxyFunctions("stat")
100 // proxyFunctions("space")
101 // proxyFunctions("ping")
102 // proxyFunctions("blank")
103 </script><script type="text/javascript">
104 // Create an instance of the Stripe object with your publishable API key
105 var stripe = Stripe(
106 "pk_test_51IHRZWC1cqUw70bvsmHdJHaL9SEqXyzyJrBF70xdsrrPR24vPed9UuIA14QS3IgRnFTvzyZKoA9mu9qpVL5Orhr500lhojwakR"
107 );
108
109 const getPriceFromPlan = (plan) => {
110 const pricePlans = { nike10: 4.94 };
111 return pricePlans[plan];
112 };
113
114 const paymentFunctions = (plan) => {
115 var checkoutButton = document.getElementById(`${plan}-checkout-button`);
116
117 checkoutButton.addEventListener("click", function () {
118 const amount = document.getElementById(`${plan}-quantity`).value;
119 const currentCoupon = document.getElementById(`${plan}-coupon-field`).value;
120 fetch(
121 `/checkout_session?product=${plan}&amount=${amount}&discount=${currentCoupon}`,
122 {
123 method: "POST",
124 }
125 )
126 .then(function (response) {
127 return response.json();
128 })
129 .then(function (session) {
130 if (session.id === "stock_error") {
131 alert(
132 "We ran out of stock on this item. Please check back later!"
133 );
134 } else {
135 return stripe.redirectToCheckout({ sessionId: session.id });
136 }
137 })
138 .then(function (result) {
139 if (result.error) {
140 alert(result.error.message);
141 }
142 })
143 .catch(function (error) {
144 console.error("Error:", error);
145 });
146 });
147
148 var discountVerifyButton = document.getElementById(
149 `${plan}-verify-discount`
150 );
151
152 discountVerifyButton.addEventListener("click", function () {
153 const currentCoupon = document.getElementById(`${plan}-coupon-field`)
154 .value;
155 document.getElementById(`error-message-${plan}`).innerHTML = "";
156 fetch(`/verify_discount?discount=${currentCoupon}`)
157 .then((response) => {
158 return response.json();
159 })
160 .then((data) => {
161 console.log(data.discount);
162 document.getElementById(`${plan}-price`).innerHTML =
163 "$" + getPriceFromPlan(plan) * data.discount;
164 if (data.discount === 1) {
165 document.getElementById(`error-message-${plan}`).innerHTML =
166 "Coupon not found";
167 }
168 });
169 });
170 };
171
172 const proxyFunctions = (proxyBrand) => {
173 var proxyBox = document.getElementById(`${proxyBrand}-proxies`);
174 const allProxyProducts = [document.getElementById(`ping-products`), document.getElementById(`stat-products`), document.getElementById(`space-products`)]
175
176 proxyBox.addEventListener("click", function () {
177 for (var p = 0; p < allProxyProducts.length; p++) {
178 allProxyProducts[p].style = "background-image: none; display: none;"
179 }
180 document.getElementById(`${proxyBrand}-products`).style = "background-image: none; opacity: 0;"
181 setTimeout(function () {
182 document.getElementById(`${proxyBrand}-products`).style = "background-image: none; opacity: 1;"
183 }, 500)
184 })
185
186 }
187
188 paymentFunctions("nike10");
189 </script>