PageSourceSearch

https://makerealmoneypodcasting.com/cf_stripe_orders.js

js makerealmoneypodcasting.com collected 2026-09-30 18:27:30 UTC 18,201 bytes, 554 lines download raw bytes

1const applyAvalaraTaxAmount = function(amount) {
2  const canChargeTax = ClickFunnels.CalculateTaxes.canCalcTaxes();
3  const taxAmount = _.property(['cfpe'])(window).avalaraTaxAmount;
4
5  if(canChargeTax && taxAmount) {
6    return amount + taxAmount;
7  }
8
9  return amount;
10}
11
12var stripeResponseHandler = function(status, response) {
13  var $form = $('#cfAR');
14  if(typeof($form) != 'undefined'){
15    if (response.error) {
16      $('[data-href-original]').each(function(){
17        $(this).attr('href', $(this).data('href-original'));
18        $(this).removeAttr('data-href-original');
19      });
20
21      // Show the errors on the form
22      console.log(response.error);
23      $('#order-declined-message').html(response.error.message);
24      $('#order-declined-message').show();
25      window.location = "#order-declined-message";
26      $('button').prop('disabled', false);
27      $('[href=#submit-form], [href=#submit-form-2step-order]').text('Submit and Retry');
28      $('[href=#submit-form], [href=#submit-form-2step-order]').prop('disabled', false);
29
30    } else {
31      // token contains id, last4, and card type
32      var token = response.id;
33      // Insert the token into the form so it gets submitted to the server
34      $form.append($('<input type="hidden" name="purchase[stripe_customer_token]" />').val(token));
35      // and submit
36      //alert("submitting form");
37      $form.get(0).submit();
38    }
39  }
40};
41
42
43function objectifyForm(formArray) {//serialize data function
44  var returnArray = {};
45  for (var i = 0; i < formArray.length; i++){
46    returnArray[formArray[i]['name']] = formArray[i]['value'];
47  }
48  return returnArray;
49}
50
51function updatePurchase() {
52
53}
54
55function InitializeStripe() {
56  var enabledForDomain = $("meta[name='stripe_enabled_for_domain']").attr("content") === "true";
57  var stripeV3PlaceholderOnPage = $('#payment-request-button').length > 0;
58
59  if (typeof Stripe !== 'undefined') {
60    var publishableKey = $("meta[name='stripe_publishable_key']").attr("content");
61    var stripeUserID = $("meta[name='stripe_user_id']").attr("content");
62    if (typeof(publishableKey) !== 'string') {
63      throw new Error("Missing stripe publishable key");
64    }
65    if (stripeUserID) {
66      window.stripe = Stripe(publishableKey, { stripeAccount: stripeUserID });
67      Stripe.applePay.stripeAccount = stripeUserID;
68    } else {
69      window.stripe = Stripe(publishableKey);
70    }
71
72    Stripe.setPublishableKey(publishableKey);
73
74    // v3 - apple and google pay
75    if (stripeV3PlaceholderOnPage && enabledForDomain) {
76      beginV3PaymentRequest();
77    }
78  }
79}
80
81window.addEventListener('load', InitializeStripe);
82
83function beginV3PaymentRequest(){
84  var mainProduct = $('#cfAR input[name="purchase[product_ids][]"][data-product-currency-code]:checked').first();
85  var lineItems = [];
86  var total = 0;
87  var mainLabel = mainProduct.data('business-name');
88  var totalHash = { amount: 0 };
89  var requestPayerPhone = false;
90  var requestPayerName = false;
91  var requestPayerEmail = true;
92  var requestShipping = false;
93
94  function updateOrder() {
95    // v3 payment request button
96
97    if(mainLabel == '' || mainLabel == 'undefined'){
98      mainLabel = "Seller"
99    }
100
101    lineItems = [];
102    total = 0;
103    $('#cfAR input[name="purchase[product_ids][]"][data-product-currency-code]:checked').each(function(){
104      var productAmt = parseFloat($(this).data('product-amount'))
105      lineItems.push({ label: $(this).data('product-label'), amount: Math.round(productAmt*100) });
106      if(typeof(productAmt) != "undefined"){
107        total = total + Math.round(productAmt*100);
108      }
109    });
110
111    if(window.cfpe.avalaraTaxAmount){
112      total = applyAvalaraTaxAmount(total);
113    }
114    totalHash = { amount: parseFloat(total.toFixed()) };
115
116    if( total == 0 ) {
117      total = 1;
118    }
119
120    $('.required1').each(function(){
121      switch($(this).attr('name')){
122        case "phone":
123          requestPayerPhone = true;
124          break;
125        case "address":
126        case "shipping_address":
127          requestShipping = true;
128          break;
129        case "zip":
130        case "shipping_zip":
131          requestShipping = true;
132          break;
133        case /(name|first_name|last_name)/i.test($(this).attr('name')):
134          requestPayerName = true;
135          break;
136      }
137    });
138
139    if (typeof window.paymentRequest != 'undefined') {
140      var options = {
141        displayItems: lineItems,
142        shippingOptions: [
143          // The first shipping option in this list appears as the default
144          // option in the browser payment interface.
145          {
146            id: 'shipping-included',
147            label: 'Shipping Included',
148            amount: 0,
149          }
150        ],
151        total: {
152          label: mainLabel,
153          amount: parseFloat(total.toFixed())
154        }
155      };
156      window.paymentRequest.update(options);
157    }
158  }
159
160  updateOrder();
161
162  $('input[name*="purchase[product_id"]').on('change', function () { updateOrder(); });
163
164  function finalizeOrder(result) {
165
166    // Include contact/purchase json
167    formData = objectifyForm($('#cfAR').serializeArray());
168
169    formData['purchase[stripe_customer_token]'] = result.token.id;
170    $('#cfAR').append($('<input/>',{"name":"purchase[stripe_customer_token]","value":result.token.id,"type":"hidden"}));
171    // TODO: populate fields from apple pay to formData
172
173    // Contact Information
174    // emailAddress
175    // An email address for the contact.
176    // familyName
177    // The contact’s family name.
178    // givenName
179    // The contact’s given name.
180    // phoneNumber
181    // A phone number for the contact.
182    if(result.payerEmail != null && result.payerEmail != ''){
183      formData['contact[email]'] = result.payerEmail;
184      $('#cfAR input[name="contact[email]"]').val(result.payerEmail);
185    }
186    if(result.payerName == null){
187      if(result.shippingAddress != null){
188        formData['contact[name]'] = result.shippingAddress.recipient;
189        $('#cfAR input[name="contact[name]"]').val(result.shippingAddress.recipient);
190      }
191    }else{
192      formData['contact[name]'] = result.payerName;
193      $('#cfAR input[name="contact[name]"]').val(result.payerName);
194    }
195    if(result.phoneNumber != null && result.phoneNumber != ''){
196      formData['contact[phone]'] = result.payerPhone;
197      $('#cfAR input[name="contact[phone]"]').val(result.payerPhone);
198    }
199
200    // Address Information
201    // addressLines
202    // The address for the contact.
203    // locality
204    // The city for the contact.
205    // administrativeArea
206    // The state for the contact.
207    // postalCode
208    // The zip code, where applicable, for the contact.
209    // country
210    // The colloquial country name for the contact.
211    // countryCode
212    // The contact’s ISO country code.
213    if(result.shippingAddress && result.shippingAddress.addressLine != ''){
214      formData['contact[shipping_address]'] = result.shippingAddress.addressLine;
215      $('#cfAR input[name="contact[shipping_address]"]').val(result.shippingAddress.addressLine);
216    }
217    if(result.shippingAddress && result.shippingAddress.city != ''){
218      formData['contact[shipping_city]'] = result.shippingAddress.city;
219      $('#cfAR input[name="contact[shipping_city]"]').val(result.shippingAddress.city);
220    }
221    if(result.shippingAddress && result.shippingAddress.region != ''){
222      formData['contact[shipping_state]'] = result.shippingAddress.region;
223      $('#cfAR input[name="contact[shipping_state]"]').val(result.shippingAddress.region);
224    }
225    if(result.shippingAddress && result.shippingAddress.postalCode != ''){
226      formData['contact[shipping_zip]'] = result.shippingAddress.postalCode;
227      $('#cfAR input[name="contact[shipping_zip]"]').val(result.shippingAddress.postalCode);
228    }
229    if(result.shippingAddress && result.shippingAddress.country != ''){
230      formData['contact[shipping_country]'] = result.shippingAddress.country;
231      $('#cfAR input[name="contact[shipping_country]"]').val(result.shippingAddress.country);
232    }
233
234    url = document.location.href;
235
236    formData = $('#cfAR').serializeArray();
237
238    $.post(url, formData, '', 'json')
239    .success(function( data ) {
240      result.complete('success');
241      // You can now redirect the user to a receipt page, etc.
242      window.location.href = data.redirect_url;
243    })
244    .fail(function(data) {
245      //alert(' data: '+data.redirect_url);
246      //alert(' failure ');
247      $('.otoloading').hide();
248      result.complete('fail');
249    });
250
251    // result.complete('success');
252    // $('#cfAR').submit();
253  }
254
255  window.paymentRequest = stripe.paymentRequest({
256    country: 'US',
257    currency: mainProduct.data('product-currency-code').toLowerCase(),
258    requestPayerName: requestPayerName,
259    requestPayerPhone: requestPayerPhone,
260    requestPayerEmail: requestPayerEmail,
261    requestShipping: requestShipping,
262    displayItems: lineItems,
263    shippingOptions: [
264      // The first shipping option in this list appears as the default
265      // option in the browser payment interface.
266      {
267        id: 'shipping-included',
268        label: 'Shipping Included',
269        amount: 0,
270      }
271    ],
272    total: {
273      label: mainLabel,
274      amount: parseFloat(total.toFixed())
275    }
276  });
277
278  var elements = stripe.elements();
279  var stripePaymentRequestButton = elements.create('paymentRequestButton', {
280    paymentRequest: window.paymentRequest,
281  });
282
283  // This weird construction of getting an element by ID is used
284  // because document.getElementById and $("#...") only return
285  // the first element with that ID. If multiple #payment-request-buttons
286  // end up on the page accidentally, we need to hide all of them if
287  // mobile pay is not available, or hide all but the last
288  // if mobile pay is available.
289  var allPaymentButtons = $('[id="payment-request-button"]');
290  let availablePaymentButtons = allPaymentButtons.filter(function() {
291      var button = $(this);
292      var ccForm = button.closest(".elCreditCardForm");
293      if (ccForm.length === 0) {
294        return true;
295      }
296
297      var overridden = ccForm.data('hide-mobile-pay');
298
299      return overridden !== "true";
300  });
301
302  var lastPaymentButton = availablePaymentButtons.last().get(0);
303  var remainingPaymentButtons = availablePaymentButtons.not(":last");
304
305  remainingPaymentButtons.hide();
306
307  // Check the availability of the Payment Request API first.
308  window.paymentRequest.canMakePayment().then(function(result) {
309    if (result && lastPaymentButton) {
310      stripePaymentRequestButton.mount(lastPaymentButton);
311      $(lastPaymentButton).show();
312    } else {
313      allPaymentButtons.hide();
314    }
315  });
316
317  window.paymentRequest.on('token', function(ev) {
318    $('.otoloading').show();
319    // Send the token to your server to charge it!
320    finalizeOrder(ev);
321  });
322}
323
324// v2 apple pay only
325// Apple Pay Support
326if(document.getElementById('apple-pay-button') !== null){
327  document.getElementById('apple-pay-button').addEventListener('click', beginApplePay);
328}
329
330function updateApplePay(){
331  var mainProduct = $('#cfAR input[name="purchase[product_ids][]"][data-product-currency-code]:checked').first();
332  var mainLabel = mainProduct.data('business-name');
333
334  if(mainLabel == '' || mainLabel == 'undefined'){
335    mainLabel = "Seller"
336  }
337
338  lineItems = [];
339  total = 0;
340  $('#cfAR input[name="purchase[product_ids][]"][data-product-currency-code]:checked').each(function(){
341    var productAmt = parseFloat($(this).data('product-amount'))
342    lineItems.push({ label: $(this).data('product-label'), amount: Math.round(productAmt*100) });
343    if(typeof(productAmt) != "undefined"){
344      total = total + Math.round(productAmt*100);
345    }
346  });
347
348  if(window.cfpe.avalaraTaxAmount){
349    total = applyAvalaraTaxAmount(total);
350  }
351  totalHash = { amount: parseFloat(total.toFixed()) };
352
353  if( total == 0 ) {
354    total = 1;
355  }
356
357  $('.required1').each(function(){
358    switch($(this).attr('name')){
359      case "phone":
360        requestPayerPhone = true;
361        break;
362      case "address":
363      case "shipping_address":
364        requestShipping = true;
365        break;
366      case "zip":
367      case "shipping_zip":
368        requestShipping = true;
369        break;
370      case /(name|first_name|last_name)/i.test($(this).attr('name')):
371        requestPayerName = true;
372        break;
373    }
374  });
375
376  if (typeof window.paymentRequest != 'undefined') {
377    var options = {
378      displayItems: lineItems,
379      shippingOptions: [
380        // The first shipping option in this list appears as the default
381        // option in the browser payment interface.
382        {
383          id: 'shipping-included',
384          label: 'Shipping Included',
385          amount: 0,
386        }
387      ],
388      total: {
389        label: mainLabel,
390        amount: parseFloat(total.toFixed())
391      }
392    };
393    window.paymentRequest.update(options);
394  }
395}
396
397function beginApplePay() {
398  // https://stripe.com/docs/stripe.js#collecting-apple-pay-detail
398s
399
400  var mainProduct = $('#cfAR input[name="purchase[product_ids][]"][data-product-currency-code]:checked').first();
401  var lineItems = [];
402  var total = 0.0;
403  var mainLabel = mainProduct.data('business-name');
404  if(mainLabel == '' || mainLabel == 'undefined'){
405    mainLabel = "Seller"
406  }
407
408  $('#cfAR input[name="purchase[product_ids][]"][data-product-currency-code]:checked').each(function(){
409    var productAmt = parseFloat($(this).data('product-amount').toFixed(2));
410    lineItems.push({ type: 'final', label: $(this).data('product-label'), amount: productAmt });
411    if(typeof(productAmt) != "undefined"){
412      total = total + productAmt;
413    }
414  });
415
416  if(window.cfpe.avalaraTaxAmount){
417    total = applyAvalaraTaxAmount(total);
418  }
419  if( total == 0.0 ){
420    total = 0.01;
421  }
422
423  var totalHash = { amount: parseFloat(total.toFixed()) }
424
425  // TODO: Add required fields from page
426  var requiredBillingContactFields = [];
427  // "requiredBillingContactFields": [
428  //   "postalAddress"
429  // ]
430  var requiredShippingContactFields = ['email'];
431  // "requiredShippingContactFields": [
432  //     "postalAddress",
433  //     "name",
434  //     "phone",
435  //     "email"
436  // ]
437
438
439  $('.required1').each(function(){
440    //console.log('required; ' + $(this).attr('name'))
441    switch($(this).attr('name')){
442      case "phone":
443        requiredShippingContactFields.push('phone');
444        break;
445      case "address":
446        requiredShippingContactFields.push('postalAddress');
447        break;
448      case "zip":
449        requiredShippingContactFields.push('postalAddress');
450        break;
451      case /(name|first_name|last_name)/i.test($(this).attr('name')):
452        requiredShippingContactFields.push('name');
453        break;
454    }
455  });
456
457  window.paymentRequest = {
458    countryCode: 'US',
459    currencyCode: mainProduct.data('product-currency-code'),
460    requiredBillingContactFields: requiredBillingContactFields,
461    requiredShippingContactFields: requiredShippingContactFields,
462    lineItems: lineItems,
463    total: {
464      label: mainLabel,
465      amount: parseFloat(total.toFixed())
466    }
467  };
468
469  var session = Stripe.applePay.buildSession(window.paymentRequest,
470    function(result, completion) {
471      console.log("result: "+ JSON.stringify(result) );
472
473    // Include contact/purchase json
474    formData = objectifyForm($('#cfAR').serializeArray());
475
476    formData['purchase[stripe_customer_token]'] = result.token.id
477    // TODO: populate fields from apple pay to formData
478
479    // Contact Information
480    // emailAddress
481    // An email address for the contact.
482    // familyName
483    // The contact’s family name.
484    // givenName
485    // The contact’s given name.
486    // phoneNumber
487    // A phone number for the contact.
488    if(result.shippingContact && result.shippingContact.emailAddress != ''){
489      formData['contact[email]'] = result.shippingContact.emailAddress;
490    }
491    if(result.shippingContact && result.shippingContact.familyName != ''){
492      formData['contact[last_name]'] = result.shippingContact.familyName;
493    }
494    if(result.shippingContact && result.shippingContact.givenName != ''){
495      formData['contact[first_name]'] = result.shippingContact.givenName;
496    }
497    if(result.shippingContact && result.shippingContact.phoneNumber != ''){
498      formData['contact[phone]'] = result.shippingContact.phoneNumber;
499    }
500
501    // Address Information
502    // addressLines
503    // The address for the contact.
504    // locality
505    // The city for the contact.
506    // administrativeArea
507    // The state for the contact.
508    // postalCode
509    // The zip code, where applicable, for the contact.
510    // country
511    // The colloquial country name for the contact.
512    // countryCode
513    // The contact’s ISO country code.
514    if(result.shippingContact && result.shippingContact.addressLines != ''){
515      formData['contact[shipping_address]'] = result.shippingContact.addressLines;
516    }
517    if(result.shippingContact && result.shippingContact.locality != ''){
518      formData['contact[shipping_city]'] = result.shippingContact.locality;
519    }
520    if(result.shippingContact && result.shippingContact.administrativeArea != ''){
521      formData['contact[shipping_state]'] = result.shippingContact.administrativeArea;
522    }
523    if(result.shippingContact && result.shippingContact.postalCode != ''){
524      formData['contact[shipping_zip]'] = result.shippingContact.postalCode;
525    }
526    if(result.shippingContact && result.shippingContact.country != ''){
527      formData['contact[shipping_country]'] = result.shippingContact.country;
528    }
529    if(result.shippingContact && result.shippingContact.countryCode != ''){
530      //formData['contact[shipping_country]'] = result.shippingContact.countryCode;
531    }
532
533    url = document.location.href;
534
535    $.post(url, formData, '', 'json').done(function( data ) {
536      completion(ApplePaySession.STATUS_SUCCESS);
537      // You can now redirect the user to a receipt page, etc.
538      window.location.href = data.redirect_url;
539    }).fail(function(data) {
540      //alert(' data: '+data.redirect_url);
541      //alert(' failure ');
542      completion(ApplePaySession.STATUS_FAILURE);
543    });
544
545  }, function(error) {
546    alert(error.message);
547  });
548
549  session.oncancel = function() {
550    //alert("User hit the cancel button in the payment window");
551  };
552
553  session.begin();
554}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.