PluginProbe ʕ •ᴥ•ʔ
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress / 4.17.1
Paid Membership Plugin, Ecommerce, User Registration Form, Login Form, User Profile & Restrict Content – ProfilePress v4.17.1
4.17.1 4.17.0 4.16.19 4.16.18 4.16.17 4.16.16 trunk 1.0 1.0.1 1.0.2 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5a 1.1.6 1.1.7 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.4 1.4.1 1.4.2 1.5 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.7 1.7.1 1.7.2 1.8 1.8.1 1.8.10 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.1.9 2.2.10 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.2 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 3.0 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 3.1.19 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.10 3.2.11 3.2.12 3.2.13 3.2.14 3.2.15 3.2.16 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.2.7 3.2.8 3.2.9 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10.0 4.10.1 4.10.2 4.10.3 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.13.3 4.13.4 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.15.0 4.15.1 4.15.10 4.15.11 4.15.12 4.15.13 4.15.14 4.15.15 4.15.16 4.15.17 4.15.18 4.15.19 4.15.2 4.15.20 4.15.20.1 4.15.21 4.15.22 4.15.23 4.15.24 4.15.25 4.15.3 4.15.4 4.15.5 4.15.6 4.15.7 4.15.8 4.15.9 4.16.0 4.16.1 4.16.10 4.16.11 4.16.12 4.16.13 4.16.14 4.16.15 4.16.2 4.16.3 4.16.4 4.16.5 4.16.6 4.16.7 4.16.8 4.16.9 4.2.0 4.3.0 4.3.1 4.3.2 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.5.3 4.5.4 4.5.5 4.6.0 4.7.0 4.8.0 4.9.0
wp-user-avatar / assets / js / stripe / stripe.js
wp-user-avatar / assets / js / stripe Last commit date
index.php 2 months ago stripe.js 2 months ago stripe.min.js 2 months ago
stripe.js
220 lines
1 /* global ppress_stripe_vars */
2 /* global ppressCheckoutForm */
3 /* global pp_ajax_form */
4
5 (function ($) {
6
7 function PPressStripe() {
8
9 var _this = this,
10 stripe = Stripe(ppress_stripe_vars.publishable_key, {
11 'locale': ppress_stripe_vars.locale
12 });
13
14 this.init = function () {
15
16 window.processCheckoutFlag = false;
17 window.confirmPaymentFlag = false;
18
19 $(document).on('ppress_updated_checkout', _this.updated_checkout);
20
21 $(document).on('ppress_update_checkout', _this.unmountPaymentElement);
22
23 $(document).on('click', '#ppress-checkout-button', function () {
24 window.processCheckoutFlag = true;
25 });
26
27 _this.updatePaymentElement();
28 };
29
30 this.updated_checkout = function (e, response) {
31
32 _this.checkout_form = $('form#ppress_mb_checkout_form');
33
34 _this.checkout_form.on('ppress_checkout_place_order_stripe', _this.validateFormSubmission);
35 _this.checkout_form.on('ppress_process_checkout_stripe', _this.processCheckout);
36
37 _this.mountPaymentElement(response);
38 };
39
40 this.fieldValueOrEmpty = function (field) {
41 if (!field) return '';
42
43 return field;
44 };
45
46 this.getBillingDetails = function () {
47 var country = $('#stripe_ppress_billing_country').val(),
48 state = $('#stripe_ppress_billing_state').val(),
49 val = {
50 name: _this.fieldValueOrEmpty($('#stripe-card_name').val()),
51 email: _this.fieldValueOrEmpty($('#ppmb_email').val()),
52 phone: _this.fieldValueOrEmpty($('#stripe_ppress_billing_phone').val())
53 };
54
55 // only include address to billing details if the billing address fields are in the checkout form
56 if (country) {
57 val.address = {
58 line1: _this.fieldValueOrEmpty($('#stripe_ppress_billing_address').val()),
59 line2: '',
60 city: _this.fieldValueOrEmpty($('#stripe_ppress_billing_city').val()),
61 state: _this.fieldValueOrEmpty(state),
62 country: _this.fieldValueOrEmpty(country),
63 postal_code: _this.fieldValueOrEmpty($('#stripe_ppress_billing_postcode').val()),
64 }
65 }
66
67 return val;
68 };
69
70 this.updatePaymentElement = function () {
71
72 var callback = function () {
73
74 _this.unmountPaymentElement();
75
76 if (typeof window.elements.create !== 'undefined') {
77 window.paymentElement = window.elements.create('payment', _this.getPaymentOptions());
78 window.paymentElement.mount('#ppress-stripe-card-element');
79 }
80 };
81
82 // If the email address is changed, re-mount to allow the Link element to show.
83 $(document).on('change', '#ppmb_email', callback);
84 };
85
86 this.getPaymentOptions = function () {
87 var obj = {
88 layout: {type: 'tabs'},
89 fields: {
90 billingDetails: ppress_stripe_vars.hideBillingFields === 'true' ? 'never' : 'auto'
91 },
92 terms: {
93 card: 'never'
94 }
95 };
96
97 // [Fix] Passing "never" for fields.billingDetails in combination with defaultValues.billingDetails is not recommended.
98 // Instead pass billing_details when creating the payment method or confirming the payment.
99 if (obj.fields.billingDetails === 'auto') {
100 obj.defaultValues = {
101 billingDetails: _this.getBillingDetails()
102 };
103 }
104
105 return obj;
106 };
107
108 this.mountPaymentElement = function (response) {
109
110 if ($('#ppress-stripe-card-element').length === 0) return;
111
112 window.elements = stripe.elements(response.data.stripe_args);
113
114 window.paymentElement = window.elements.create('payment', _this.getPaymentOptions());
115
116 window.paymentElement.mount('#ppress-stripe-card-element');
117 };
118
119 this.unmountPaymentElement = function () {
120
121 if ($('#ppress-stripe-card-element').length === 0) return;
122
123 if (typeof window.paymentElement.destroy !== 'undefined') {
124 window.paymentElement.destroy();
125 }
126 };
127
128 this.validateFormSubmission = function () {
129
130 if (window.processCheckoutFlag === true) {
131
132 window.processCheckoutFlag = false;
133
134 window.elements.submit().then(function (result) {
135
136 if ('error' in result && typeof result.error.message !== 'undefined') {
137 ppressCheckoutForm.createAlertMessage(result.error.message);
138 } else {
139 _this.checkout_form.trigger('submit');
140 }
141 });
142
143 return false;
144 }
145 };
146
147 this.processCheckout = function (e, response, payment_method) {
148
149 if (ppressCheckoutForm.is_var_defined(response.gateway_response) === true) {
150
151 if (
152 ppressCheckoutForm.is_var_defined(response.gateway_response.latest_invoice) === true || // for subscription payments
153 ppressCheckoutForm.is_var_defined(response.gateway_response.status) === true // for one-time payments
154 ) {
155
156 // ensure the below block of code runs once
157 if (window.confirmPaymentFlag === false) {
158
159 window.confirmPaymentFlag = true;
160
161 var client_secret, stripeAction = 'confirmPayment', actionResultParam = 'paymentIntent';
162
163 if (ppressCheckoutForm.is_var_defined(response.gateway_response.client_secret)) {
164 client_secret = response.gateway_response.client_secret;
165 } else if (
166 ppressCheckoutForm.is_var_defined(response.gateway_response.latest_invoice.payment_intent) &&
167 ppressCheckoutForm.is_var_defined(response.gateway_response.latest_invoice.payment_intent.client_secret)
168 ) {
169 client_secret = response.gateway_response.latest_invoice.payment_intent.client_secret;
170 } else if (
171 ppressCheckoutForm.is_var_defined(response.gateway_response.setup_intent_response) &&
172 ppressCheckoutForm.is_var_defined(response.gateway_response.setup_intent_response.client_secret)
173 ) {
174 client_secret = response.gateway_response.setup_intent_response.client_secret;
175 stripeAction = 'confirmSetup';
176 actionResultParam = 'setupIntent';
177 }
178
179 if (typeof client_secret === 'undefined') {
180 $(document.body).trigger('ppress_checkout_success', [response, payment_method]);
181 window.location.assign(response.order_success_url);
182 }
183
184 var cp_getBillingDetails = _this.getBillingDetails();
185
186 stripe[stripeAction]({
187 elements: window.elements,
188 clientSecret: client_secret,
189 confirmParams: {
190 return_url: response.order_success_url,
191 payment_method_data: {
192 billing_details: cp_getBillingDetails
193 }
194 },
195 redirect: 'if_required'
196
197 }).then(function (result) {
198 if (result.error) {
199 window.confirmPaymentFlag = false;
200 ppressCheckoutForm.createAlertMessage(result.error.message);
201 } else {
202
203 if (result[actionResultParam]['status'] === 'succeeded') {
204 $(document.body).trigger('ppress_checkout_success', [response, payment_method]);
205 }
206
207 window.location.assign(response.order_success_url);
208 }
209 });
210 }
211
212 return false;
213 }
214 }
215 };
216 }
217
218 (new PPressStripe()).init();
219
220 })(jQuery);