daily pastebin goal
6%
SHARE
TWEET

stripe_js.js

a guest Jun 29th, 2015 211 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.             // Setting the error class and error element for form validation.
  3.             jQuery.validator.setDefaults({
  4.             //    errorClass: "text-danger",
  5.             //    errorElement: "small"
  6.             });
  7.            
  8.             function showProcessing() {
  9.                 $('.subscribe-process').show();
  10.             }
  11.  
  12.             function hideProcessing() {
  13.                 $('.subscribe-process').hide();
  14.            }
  15.            
  16.             // Handling and displaying error during form submit.
  17.            function subscribeErrorHandler(jqXHR, textStatus, errorThrown) {
  18.                     try{
  19.                         var resp = JSON.parse(jqXHR.responseText);
  20.                         if ('error_param' in resp) {
  21.                            var errorMap = {};
  22.                             var errParam = resp.error_param;
  23.                             var errMsg = resp.error_msg;
  24.                             errorMap[errParam] = errMsg;
  25.                             $("#subscribe-form").validate().showErrors(errorMap);
  26.                        } else {
  27.                             var errMsg = resp.error_msg;
  28.                             $(".alert-danger").show().text(errMsg);
  29.                         }
  30.                     } catch(err) {
  31.                         $(".alert-danger").show().text("");
  32.                     }
  33.             }
  34.            
  35.             // Forward to thank you page after receiving success response.
  36.             function subscribeResponseHandler(responseJSON) {
  37.                 window.location.replace(responseJSON.forward);
  38.             }
  39.  
  40.            
  41.             function handleStripeToken(token, args) {
  42.                         form = $("#subscribe-form");
  43.                         $("input[name='stripeToken']").val(token.id );
  44.                         var options = {
  45.                             beforeSend: showProcessing,
  46.                             // post-submit callback when error returns
  47.                             error: subscribeErrorHandler,
  48.                             // post-submit callback when success returns
  49.                             success: subscribeResponseHandler,
  50.                             complete: hideProcessing,
  51.                             contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
  52.                             dataType: 'json'
  53.                         };
  54.                         // Doing AJAX form submit to your server.
  55.                         form.ajaxSubmit(options);
  56.                         return false;
  57.                     }
  58.            
  59.                    
  60.             $(document).ready(function() {
  61.                 $("#subscribe-form").validate({
  62.                     rules: {
  63.                         //zip_code: {number: false},
  64.                         //phone: {number: false}
  65.                     }
  66.                 });
  67.  
  68.                 // Creating Stripe Checkout handler object and also
  69.                 // configuring Stripe publishable key and setting the options in Stripe Js.
  70.                 var handler = StripeCheckout.configure({
  71.                     //Replace it with your stripe publishable key
  72.                     key: 'pk_test_EJ8PRnnt5IJTwypSzkyAgbAv',
  73.                     currency: 'gbp',
  74.                     allowRememberMe: false,
  75.                     token: handleStripeToken
  76.                 });
  77.  
  78.                 // Calling Stripe Js to display pop up on button click event
  79.                 $("#submit-btn").on('click', function(e) {
  80.                     var amount = $("#due").val() * 100;
  81.                     var form = $("#subscribe-form");
  82.                     if(!$(form).valid()) {
  83.                         return false;
  84.                     }
  85.                     handler.open({
  86.                            name: 'Test',
  87.                            description: $('#plan-desc').val(),
  88.                            amount: amount,
  89.                            email: $('#email').val(),
  90.                            billingAddress: 'true',
  91.                            zipCode: 'true',
  92.                     });
  93.                     return false;
  94.                 });
  95.                
  96.                
  97.             });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top