payola-payments 1.3.2 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/payola/checkout_button.js +9 -5
  3. data/app/assets/javascripts/payola/form.js +10 -4
  4. data/app/assets/javascripts/payola/subscription_checkout_button.js +41 -24
  5. data/app/assets/javascripts/payola/subscription_form_onestep.js +13 -6
  6. data/app/assets/javascripts/payola/subscription_form_register.js +97 -0
  7. data/app/assets/javascripts/payola/subscription_form_twostep.js +14 -7
  8. data/app/controllers/payola/cards_controller.rb +40 -0
  9. data/app/controllers/payola/customers_controller.rb +37 -0
  10. data/app/controllers/payola/subscriptions_controller.rb +1 -1
  11. data/app/models/concerns/payola/plan.rb +1 -1
  12. data/app/models/payola/subscription.rb +15 -1
  13. data/app/services/payola/cancel_subscription.rb +6 -3
  14. data/app/services/payola/change_subscription_plan.rb +15 -7
  15. data/app/services/payola/create_card.rb +13 -0
  16. data/app/services/payola/create_subscription.rb +14 -6
  17. data/app/services/payola/destroy_card.rb +9 -0
  18. data/app/services/payola/process_refund.rb +20 -0
  19. data/app/services/payola/start_subscription.rb +30 -15
  20. data/app/services/payola/subscription_deleted.rb +11 -0
  21. data/app/services/payola/update_customer.rb +9 -0
  22. data/app/views/payola/subscriptions/_cancel.html.erb +2 -0
  23. data/app/views/payola/subscriptions/_checkout.html.erb +13 -4
  24. data/app/views/payola/transactions/_form.html.erb +1 -1
  25. data/config/routes.rb +8 -3
  26. data/db/migrate/20150930164135_add_tax_percent_to_payola_subscriptions.rb +5 -0
  27. data/lib/generators/payola/templates/initializer.rb +1 -1
  28. data/lib/payola.rb +5 -1
  29. data/lib/payola/engine.rb +1 -0
  30. data/lib/payola/version.rb +1 -1
  31. data/spec/concerns/plan_spec.rb +34 -11
  32. data/spec/controllers/payola/cards_controller_spec.rb +78 -0
  33. data/spec/controllers/payola/customers_controller_spec.rb +41 -0
  34. data/spec/controllers/payola/subscriptions_controller_spec.rb +14 -5
  35. data/spec/dummy/db/schema.rb +8 -7
  36. data/spec/dummy/db/test.sqlite3 +0 -0
  37. data/spec/dummy/log/development.log +83 -0
  38. data/spec/dummy/log/test.log +15285 -0
  39. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/05-CimMmYqCyJHDw0mlYlY8QTYNZWxvvjXNzt99raT8.cache +1 -0
  40. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/0cwo25M79KGYxnM1Fn5aVXuB5Vx5NXDeI1mauCHJ6C0.cache +1 -0
  41. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/1RezgAqI3WpLjtCkf15A28C_C_ZggGaTUJVj_0OtZt0.cache +2 -0
  42. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/1sN5oeTaBcGDHbdpHx7u12CUoshmGO0a8n6wvOZ8e9g.cache +2 -0
  43. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/4Huwm41yGPbqU_ktIlyb9x7zWCBrETs8Hi1vod_h6CM.cache +0 -0
  44. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/6GYiGbi_eHKrkW4pmMOQc-YcJd5yjqypkSSVsmvLdGQ.cache +2 -0
  45. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/6jBC_ionlG5SaNmx7QnmYyHapApzfD7gO7iacmF7A-o.cache +0 -0
  46. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/8PuswVUdqRS0_2AjXzB3SJnp0T6R4XDd52aXU8HUb20.cache +0 -0
  47. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/93_-tHqt48795qdk0JqDUZvfu8txM-kzSbHHwUHfUg4.cache +2 -0
  48. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/BJ9VCB2p3PpqouoGa_QmkGjFv4aPZWzCCDiFpknRFCA.cache +0 -0
  49. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/Cvp1E8cK9iR8ZIyJng_CyOI5-lFm_PpQuqJpfpdsFJQ.cache +1 -0
  50. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/D3ZSFffpWANPSAj2gTmelfr4w-KkX84C0EgyPOy6Y6o.cache +0 -0
  51. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/DBdvUpmp3qMac1HkOn7D-0WoON1Vn4n0VkmcBo9PYTE.cache +1 -0
  52. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/EM3Tna1A9GSD2IeCpTZmuINPPHpdTXPbCG6sbLXHKPI.cache +1 -0
  53. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/FJ2Xe7ZXhQCx8O6gziOCZXLYIMDdWQElTtXlygmzDP0.cache +0 -0
  54. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/GDXP5hnN5ycGmMuaWltb9AFtcEBq7WXRfWTLjBgSK8I.cache +1 -0
  55. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/GFxndLm-jxLvxsJ4aUJ54BUZ32Ypzp7mLCmArWCOIa4.cache +1 -0
  56. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/GJmK02s0v61jK_BI__yUZI7NpGUVtXfur9ZiQGwOYyU.cache +0 -0
  57. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/MrKh1ye7y3UHd5ox4OgIUhcXyLvEN5FWvs6v7CzqFWI.cache +3 -0
  58. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/Nl0Imk9BLfXqZ83k4_-tB2g0aevktUZocldLZzEE8DM.cache +0 -0
  59. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/Nz8cUs5LShWxHeARb_8KNPjYZGYN8tCqWa2OoovieYg.cache +1 -0
  60. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/OWrok24obbylOHeAaps9WA5SBwjpaEd0xnQqBWOc-mQ.cache +2 -0
  61. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/QVhitoXuP03xtsfQo4gH_mAw16dk1EPH7Xf8JlXVLpk.cache +1 -0
  62. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/QrIfBX9SocQINdKbcOGU2ZplYq_3lE7-CgPvvFRZUPs.cache +3 -0
  63. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/RSFirXKeTuMV9nWIeu-30jvOMVQTdZQUugyREItprkE.cache +1 -0
  64. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/S5giqzoBdK-jXI6AoAelpiCYhMTwMFNaxjUJj816KdM.cache +2 -0
  65. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/Se3LTfrl02BuX--hLV7cqyaPT9b9ydVPYsWlXjSvQ6Q.cache +1 -0
  66. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/SwyH6o1ZPaOTMGyVqMXuWtYuyf9yBl0NRSVjvv2HQGo.cache +1 -0
  67. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/T8VFzmrZkpfAHu4YyuwEfZWPF3sv77n7comxiwI6yK4.cache +1 -0
  68. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/Te0Swu57VjhvpFOJV5fIm9X9C-tiyuF486pgN6gWuvs.cache +2 -0
  69. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/TolX3hiRfWiUWMlwHiH5G7KZZuFKPV2geKgORhx1kbc.cache +1 -0
  70. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/W5-aJJXrwJHHZ2LUNvSZJDuDWnf-nXHn_RrdHm8Dsy4.cache +1 -0
  71. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/WwYeCgq1wE5ouj5QoNsFDYa_K0Hw5SNPPPyzZ9JRk_M.cache +1 -0
  72. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/WxGjqpQ1GofgXtH2VW51hBdHzehHiH9QQSzeFwvPa04.cache +0 -0
  73. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/X-OoOAyH7movCISCvhiawWmwCODe3fN7ymRIQEQJGWs.cache +1 -0
  74. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/YUqxvOCuXaKKNVrkC0BmaxSs-ae8k61lE-cXvNvp6ts.cache +2 -0
  75. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/ald4YZEKpA5mAmBUBRLwntPH1BB--dukFx4hRB1G8Sc.cache +2 -0
  76. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/coggheKLeRswSaNoMMz-DG4eSncE1LfiKd6ebpHdcDQ.cache +1 -0
  77. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/ctvwDGAdKE_Nmp-gIQsb4edj11gnDV2HvIb4f_hTr1A.cache +0 -0
  78. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/d1MBBmJw2iL1O_NLFnwSRJlDR2VB-Au8nckF0HcpAjU.cache +0 -0
  79. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/fQIfzJDoR7LlNPN5nxZ-wlReF7b9zJ71zPnU-mwz0tU.cache +1 -0
  80. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/if00l9X27C69IaQ5LW33GQ76AK8TNTK2x_mAtUBiK_Y.cache +2 -0
  81. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/mFdDv_nbtZKHUux_oAK4OmPBu8TJ62BtWnklHAw52lk.cache +1 -0
  82. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/nGRK5RyFWrQfZM7AqkyVNDZrMJny5SvIThqdcSaF7s4.cache +1 -0
  83. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/nxuLyls6X-Txo4fYUEBKChRSnonW6fR3e3hy60jNKDk.cache +0 -0
  84. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/o8Pe3_OPNi7cpOIjfFsLK0KP_hLNPoR0eO61oXCo40Q.cache +2 -0
  85. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/oiIb0gmeFbc8wNdBNqzP6QepH1VG7L6rOwt7JRjLF6Y.cache +1 -0
  86. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/os-IBWzcQaIeJAr-eZ0ISapp8u6ViHJBDVl3zsSnAxs.cache +1 -0
  87. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/p8-Esy85oOHbF8SlC_ADEPGi7AjMurnoYSdCD3V0QHo.cache +0 -0
  88. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/rDG6NUIkefVSkt66sViHIj-M-YmUVD3LC383yOQZE3Y.cache +0 -0
  89. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/rT-10_0UmPqfTi7e_RvVV2oVVrZPcnzEVxYryWf0AWk.cache +1 -0
  90. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/rgRsqTnAPvMJlyOn2tOMsfX1YNwqiKZprIoYnBtUIao.cache +2 -0
  91. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/tZkY3_ZombuoVZpSwY2dfvHcyD88nyqaNHLzVfrlSbA.cache +1 -0
  92. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/v8-7s6wdUoobgWtvSQPJYtNsLoojslrMGambhfCbLBo.cache +2 -0
  93. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/xAmLB93l5rnHnPfuqo_rdVoCN4PRE5-22KU8O3LNn5U.cache +0 -0
  94. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/xFmik7WLB1nL3qhSnRWbIEXIwMG1K_dLc1ymZ3hNJ_8.cache +0 -0
  95. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/z5DZtajWt8UQUvtzye6ncruhskjV7HVUOKWv800kzrE.cache +2 -0
  96. data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/zPJ93ju23hj65NVsVWOgNlvHe3OjA-SGQ9nU2oupKlI.cache +2 -0
  97. data/spec/factories/payola_subscriptions.rb +2 -3
  98. data/spec/models/payola/subscription_spec.rb +35 -1
  99. data/spec/payola_spec.rb +7 -0
  100. data/spec/services/payola/change_subscription_plan_spec.rb +70 -7
  101. data/spec/services/payola/create_card_spec.rb +42 -0
  102. data/spec/services/payola/create_subscription_spec.rb +12 -10
  103. data/spec/services/payola/destroy_card_spec.rb +28 -0
  104. data/spec/services/payola/process_refund_spec.rb +35 -0
  105. data/spec/services/payola/start_subscription_spec.rb +27 -3
  106. data/spec/services/payola/subscription_deleted_spec.rb +11 -0
  107. data/spec/services/payola/update_customer_spec.rb +26 -0
  108. metadata +142 -6
  109. data/app/services/payola/#update_card.rb# +0 -27
  110. data/spec/services/payola/#start_subscription_spec.rb# +0 -95
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 090fead9a7f25882ede8a67d5d6838ac806a8eb2
4
- data.tar.gz: 6e679e1f803897af7c7a41b459b1db6dfa5f1479
3
+ metadata.gz: 09b8e76fdaef1aec8962ac64e436a9b578fd78af
4
+ data.tar.gz: bc890a26821355bbb8d58b9e98814ab0f4e609a8
5
5
  SHA512:
6
- metadata.gz: ee0d82de19027fc019b8dc1646e619ac1042d7a3bbe58899da628e19370c1fb98834bee37b85b674b5a30857b8a7b5f87738509e3424b7eee9607696f0dd4464
7
- data.tar.gz: 43ea81aebd4eded6a5ad94a7a4fb798396260627da5648dc8541844b51be8b70d9fe8a615919415271acaba2d3c0295f72d831892812421252c73dee3b52ad9e
6
+ metadata.gz: 0716e1222343a26dae355bfed19b2b817f42141cb707573b00599930f01bde231f0ee4b2a3f7eb0d625b755121778bc86641aab08a7a147d4b26d16ae6358dcb
7
+ data.tar.gz: 95d657b2c1e81e7c5dcbf565008145cc26cd4ed6ab9ae25536a43f7431448943b557559fc623b852ac04e7d499dd691d135f656e5989a1b4ea4ca7a272280864
@@ -1,6 +1,6 @@
1
1
  var PayolaCheckout = {
2
2
  initialize: function() {
3
- $(document).on('click', '.payola-checkout-button', function(e) {
3
+ $('.payola-checkout-button').on('click', function(e) {
4
4
  e.preventDefault();
5
5
  PayolaCheckout.handleCheckoutButtonClick($(this));
6
6
  });
@@ -32,7 +32,6 @@ var PayolaCheckout = {
32
32
 
33
33
  tokenHandler: function(token, options) {
34
34
  var form = $("#" + options.form_id);
35
- console.log(options.form_id);
36
35
  form.append($('<input type="hidden" name="stripeToken">').val(token.id));
37
36
  form.append($('<input type="hidden" name="stripeEmail">').val(token.email));
38
37
  if (options.signed_custom_fields) {
@@ -47,7 +46,7 @@ var PayolaCheckout = {
47
46
  url: options.base_path + "/buy/" + options.product_class + "/" + options.product_permalink,
48
47
  data: form.serialize(),
49
48
  success: function(data) { PayolaCheckout.poll(data.guid, 60, options); },
50
- error: function(data) { PayolaCheckout.showError(data.responseJSON.error, options); }
49
+ error: function(data) { PayolaCheckout.showError(jQuery.parseJSON(data.responseText).error, options); }
51
50
  });
52
51
  },
53
52
 
@@ -80,8 +79,13 @@ var PayolaCheckout = {
80
79
  type: "GET",
81
80
  url: options.base_path + "/status/" + guid,
82
81
  success: handler,
83
- error: handler
82
+ error: function(xhr){ handler(jQuery.parseJSON(xhr.responseText)) }
84
83
  });
85
84
  }
86
85
  };
87
- $(function() { PayolaCheckout.initialize(); });
86
+
87
+ if ('undefined' !== typeof Turbolinks) {
88
+ $(document).on('page:change', PayolaCheckout.initialize);
89
+ } else {
90
+ $(document).ready(PayolaCheckout.initialize);
91
+ }
@@ -1,6 +1,6 @@
1
1
  var PayolaPaymentForm = {
2
2
  initialize: function() {
3
- $(document).on('submit', '.payola-payment-form', function() {
3
+ $('.payola-payment-form').on('submit', function() {
4
4
  return PayolaPaymentForm.handleSubmit($(this));
5
5
  });
6
6
  },
@@ -34,7 +34,7 @@ var PayolaPaymentForm = {
34
34
  url: base_path + "/buy/" + product + "/" + permalink,
35
35
  data: data_form.serialize(),
36
36
  success: function(data) { PayolaPaymentForm.poll(form, 60, data.guid, base_path); },
37
- error: function(data) { PayolaPaymentForm.showError(form, data.responseJSON.error); }
37
+ error: function(data) { PayolaPaymentForm.showError(form, jQuery.parseJSON(data.responseText).error); }
38
38
  });
39
39
  }
40
40
  },
@@ -58,7 +58,9 @@ var PayolaPaymentForm = {
58
58
 
59
59
  showError: function(form, message) {
60
60
  $('.payola-spinner').hide();
61
- form.find(':submit').prop('disabled', false);
61
+ $(form).find(':submit')
62
+ .prop('disabled', false)
63
+ .trigger('error', message);
62
64
  var error_selector = form.data('payola-error-selector');
63
65
  if (error_selector) {
64
66
  $(error_selector).text(message);
@@ -72,4 +74,8 @@ var PayolaPaymentForm = {
72
74
  }
73
75
  };
74
76
 
75
- $(function() { PayolaPaymentForm.initialize(); } );
77
+ if ('undefined' !== typeof Turbolinks) {
78
+ $(document).on('page:change', PayolaPaymentForm.initialize);
79
+ } else {
80
+ $(document).ready(PayolaPaymentForm.initialize);
81
+ }
@@ -1,6 +1,6 @@
1
1
  var PayolaSubscriptionCheckout = {
2
2
  initialize: function() {
3
- $(document).on('click', '.payola-subscription-checkout-button', function(e) {
3
+ $('.payola-subscription-checkout-button').on('click', function(e) {
4
4
  e.preventDefault();
5
5
  PayolaSubscriptionCheckout.handleCheckoutButtonClick($(this));
6
6
  });
@@ -10,44 +10,55 @@ var PayolaSubscriptionCheckout = {
10
10
  var form = button.parent('form');
11
11
  var options = form.data();
12
12
 
13
- var handler = StripeCheckout.configure({
14
- key: options.publishable_key,
15
- image: options.plan_image_path,
16
- token: function(token) { PayolaSubscriptionCheckout.tokenHandler(token, options); },
17
- name: options.name,
18
- description: options.description,
19
- amount: options.price,
20
- panelLabel: options.panel_label,
21
- allowRememberMe: options.allow_remember_me,
22
- zipCode: options.verify_zip_code,
23
- billingAddress: options.billing_address,
24
- shippingAddress: options.shipping_address,
25
- currency: options.currency,
26
- email: options.email || undefined
27
- });
13
+ if (options.stripe_customer_id) {
14
+ // If an existing Stripe customer id is specified, don't open the Stripe Checkout - just AJAX submit the form
15
+ PayolaSubscriptionCheckout.submitForm(form.attr('action'), { stripe_customer_id: options.stripe_customer_id }, options);
16
+ } else {
17
+ // Open a Stripe Checkout to collect the customer's billing details
18
+ var handler = StripeCheckout.configure({
19
+ key: options.publishable_key,
20
+ image: options.plan_image_path,
21
+ token: function(token) { PayolaSubscriptionCheckout.tokenHandler(token, options); },
22
+ name: options.name,
23
+ description: options.description,
24
+ amount: options.price+(options.price*(options.tax_percent/100)),
25
+ panelLabel: options.panel_label,
26
+ allowRememberMe: options.allow_remember_me,
27
+ zipCode: options.verify_zip_code,
28
+ billingAddress: options.billing_address,
29
+ shippingAddress: options.shipping_address,
30
+ currency: options.currency,
31
+ email: options.email || undefined
32
+ });
28
33
 
29
- handler.open();
34
+ handler.open();
35
+ }
30
36
  },
31
37
 
32
38
  tokenHandler: function(token, options) {
33
39
  var form = $("#" + options.form_id);
34
- console.log(options.form_id);
35
40
  form.append($('<input type="hidden" name="stripeToken">').val(token.id));
36
41
  form.append($('<input type="hidden" name="stripeEmail">').val(token.email));
37
42
  form.append($('<input type="hidden" name="quantity">').val(options.quantity));
43
+ form.append($('<input type="hidden" name="coupon">').val(options.coupon));
44
+ form.append($('<input type="hidden" name="tax_percent">').val(options.tax_percent));
38
45
  if (options.signed_custom_fields) {
39
46
  form.append($('<input type="hidden" name="signed_custom_fields">').val(options.signed_custom_fields));
40
47
  }
41
48
 
49
+ PayolaSubscriptionCheckout.submitForm(form.attr('action'), form.serialize(), options);
50
+ },
51
+
52
+ submitForm: function(url, data, options) {
42
53
  $(".payola-subscription-checkout-button").prop("disabled", true);
43
54
  $(".payola-subscription-checkout-button-text").hide();
44
55
  $(".payola-subscription-checkout-button-spinner").show();
45
56
  $.ajax({
46
57
  type: "POST",
47
- url: form.attr('action'),
48
- data: form.serialize(),
58
+ url: url,
59
+ data: data,
49
60
  success: function(data) { PayolaSubscriptionCheckout.poll(data.guid, 60, options); },
50
- error: function(data) { PayolaSubscriptionCheckout.showError(data.responseJSON.error, options); }
61
+ error: function(data) { PayolaSubscriptionCheckout.showError(jQuery.parseJSON(data.responseText).error, options); }
51
62
  });
52
63
  },
53
64
 
@@ -55,7 +66,8 @@ var PayolaSubscriptionCheckout = {
55
66
  var error_div = $("#" + options.error_div_id);
56
67
  error_div.html(error);
57
68
  error_div.show();
58
- $(".payola-subscription-checkout-button").prop("disabled", false);
69
+ $(".payola-subscription-checkout-button").prop("disabled", false)
70
+ .trigger("error", error);
59
71
  $(".payola-subscription-checkout-button-spinner").hide();
60
72
  $(".payola-subscription-checkout-button-text").show();
61
73
  },
@@ -80,8 +92,13 @@ var PayolaSubscriptionCheckout = {
80
92
  type: "GET",
81
93
  url: options.base_path + "/subscription_status/" + guid,
82
94
  success: handler,
83
- error: handler
95
+ error: function(xhr) { handler(jQuery.parseJSON(xhr.responseText)) }
84
96
  });
85
97
  }
86
98
  };
87
- $(function() { PayolaSubscriptionCheckout.initialize(); });
99
+
100
+ if ('undefined' !== typeof Turbolinks) {
101
+ $(document).on('page:change', PayolaSubscriptionCheckout.initialize);
102
+ } else {
103
+ $(document).ready(PayolaSubscriptionCheckout.initialize);
104
+ }
@@ -1,12 +1,12 @@
1
1
  var PayolaOnestepSubscriptionForm = {
2
2
  initialize: function() {
3
- $(document).on('submit', '.payola-onestep-subscription-form', function() {
3
+ $('.payola-onestep-subscription-form').on('submit', function() {
4
4
  return PayolaOnestepSubscriptionForm.handleSubmit($(this));
5
5
  });
6
6
  },
7
7
 
8
8
  handleSubmit: function(form) {
9
- $(':submit').prop('disabled', true);
9
+ $(form).find(':submit').prop('disabled', true);
10
10
  $('.payola-spinner').show();
11
11
  Stripe.card.createToken(form, function(status, response) {
12
12
  PayolaOnestepSubscriptionForm.stripeResponseHandler(form, status, response);
@@ -40,7 +40,7 @@ var PayolaOnestepSubscriptionForm = {
40
40
  url: action,
41
41
  data: form.serialize(),
42
42
  success: function(data) { PayolaOnestepSubscriptionForm.poll(form, 60, data.guid, base_path); },
43
- error: function(data) { PayolaOnestepSubscriptionForm.showError(form, data.responseJSON.error); }
43
+ error: function(data) { PayolaOnestepSubscriptionForm.showError(form, jQuery.parseJSON(data.responseText).error); }
44
44
  });
45
45
  }
46
46
  },
@@ -57,7 +57,7 @@ var PayolaOnestepSubscriptionForm = {
57
57
  }
58
58
  };
59
59
  var errorHandler = function(jqXHR){
60
- PayolaOnestepSubscriptionForm.showError(form, jqXHR.responseJSON.error);
60
+ PayolaOnestepSubscriptionForm.showError(form, jQuery.parseJSON(jqXHR.responseText).error);
61
61
  };
62
62
 
63
63
  $.ajax({
@@ -71,7 +71,10 @@ var PayolaOnestepSubscriptionForm = {
71
71
 
72
72
  showError: function(form, message) {
73
73
  $('.payola-spinner').hide();
74
- $(':submit').prop('disabled', false);
74
+ $(form).find(':submit')
75
+ .prop('disabled', false)
76
+ .trigger('error', message);
77
+
75
78
  var error_selector = form.data('payola-error-selector');
76
79
  if (error_selector) {
77
80
  $(error_selector).text(message);
@@ -87,4 +90,8 @@ var PayolaOnestepSubscriptionForm = {
87
90
  }
88
91
  };
89
92
 
90
- $(function() { PayolaOnestepSubscriptionForm.initialize() } );
93
+ if ('undefined' !== typeof Turbolinks) {
94
+ $(document).on('page:change', PayolaOnestepSubscriptionForm.initialize);
95
+ } else {
96
+ $(document).ready(PayolaOnestepSubscriptionForm.initialize);
97
+ }
@@ -0,0 +1,97 @@
1
+ var PayolaRegistrationForm = {
2
+ initialize: function() {
3
+ $('.payola-register-form').on('submit', function(e) {
4
+ e.preventDefault();
5
+ return PayolaRegistrationForm.handleSubmit($(this));
6
+ });
7
+ },
8
+
9
+ handleSubmit: function(form) {
10
+ $(form).find(':submit').prop('disabled', true);
11
+ $('.payola-spinner').show();
12
+ PayolaRegistrationForm.makeCustomer(form);
13
+ return false;
14
+ },
15
+
16
+ // Could be more DRY
17
+ makeCustomer: function(form) {
18
+
19
+ var email = form.find("[data-payola='email']").val();
20
+ var coupon = form.find("[data-payola='coupon']").val();
21
+ var quantity = form.find("[data-payola='quantity']").val();
22
+
23
+ var base_path = form.data('payola-base-path');
24
+ var plan_type = form.data('payola-plan-type');
25
+ var plan_id = form.data('payola-plan-id');
26
+
27
+ var action = $(form).attr('action');
28
+
29
+ form.append($('<input type="hidden" name="[user]plan_id">').val(plan_id));
30
+ form.append($('<input type="hidden" name="plan_type">').val(plan_type));
31
+ form.append($('<input type="hidden" name="plan_id">').val(plan_id));
32
+ form.append($('<input type="hidden" name="stripeEmail">').val(email));
33
+ form.append($('<input type="hidden" name="coupon">').val(coupon));
34
+ form.append($('<input type="hidden" name="quantity">').val(quantity));
35
+ form.append(PayolaRegistrationForm.authenticityTokenInput());
36
+
37
+ $.ajax({
38
+ type: "POST",
39
+ url: action,
40
+ data: form.serialize(),
41
+ success: function(data) { PayolaRegistrationForm.poll(form, 60, data.guid, base_path); },
42
+ error: function(data) { PayolaRegistrationForm.showError(form, jQuery.parseJSON(data.responseText).error); }
43
+ });
44
+ },
45
+
46
+ poll: function(form, num_retries_left, guid, base_path) {
47
+ if (num_retries_left === 0) {
48
+ PayolaRegistrationForm.showError(form, "This seems to be taking too long. Please contact support and give them transaction ID: " + guid);
49
+ }
50
+ var handler = function(data) {
51
+ if (data.status === "active") {
52
+ form.append($('<input type="hidden" name="payola_subscription_guid"></input>').val(guid));
53
+ form.append(PayolaRegistrationForm.authenticityTokenInput());
54
+ form.get(0).submit();
55
+ } else {
56
+ setTimeout(function() { PayolaRegistrationForm.poll(form, num_retries_left - 1, guid, base_path); }, 500);
57
+ }
58
+ };
59
+ var errorHandler = function(jqXHR){
60
+ var responseJSON = jQuery.parseJSON(jqXHR.responseText);
61
+ if(responseJSON.status === "errored"){
62
+ PayolaRegistrationForm.showError(form, responseJSON.error);
63
+ }
64
+ };
65
+
66
+ $.ajax({
67
+ type: 'GET',
68
+ dataType: 'json',
69
+ url: base_path + '/subscription_status/' + guid,
70
+ success: handler,
71
+ error: errorHandler
72
+ });
73
+ },
74
+
75
+ showError: function(form, message) {
76
+ $('.payola-spinner').hide();
77
+ $(form).find(':submit').prop('disabled', false);
78
+ var error_selector = form.data('payola-error-selector');
79
+ if (error_selector) {
80
+ $(error_selector).text(message);
81
+ $(error_selector).show();
82
+ } else {
83
+ form.find('.payola-payment-error').text(message);
84
+ form.find('.payola-payment-error').show();
85
+ }
86
+ },
87
+
88
+ authenticityTokenInput: function() {
89
+ return $('<input type="hidden" name="authenticity_token"></input>').val($('meta[name="csrf-token"]').attr("content"));
90
+ }
91
+ };
92
+
93
+ if ('undefined' !== typeof Turbolinks) {
94
+ $(document).on('page:change', PayolaRegistrationForm.initialize);
95
+ } else {
96
+ $(document).ready(PayolaRegistrationForm.initialize);
97
+ }
@@ -1,12 +1,12 @@
1
1
  var PayolaSubscriptionForm = {
2
2
  initialize: function() {
3
- $(document).on('submit', '.payola-subscription-form', function() {
3
+ $('.payola-subscription-form').on('submit', function() {
4
4
  return PayolaSubscriptionForm.handleSubmit($(this));
5
5
  });
6
6
  },
7
7
 
8
8
  handleSubmit: function(form) {
9
- $(':submit').prop('disabled', true);
9
+ $(form).find(':submit').prop('disabled', true);
10
10
  $('.payola-spinner').show();
11
11
  Stripe.card.createToken(form, function(status, response) {
12
12
  PayolaSubscriptionForm.stripeResponseHandler(form, status, response);
@@ -37,7 +37,7 @@ var PayolaSubscriptionForm = {
37
37
  url: base_path + "/subscribe/" + plan_type + "/" + plan_id,
38
38
  data: data_form.serialize(),
39
39
  success: function(data) { PayolaSubscriptionForm.poll(form, 60, data.guid, base_path); },
40
- error: function(data) { PayolaSubscriptionForm.showError(form, data.responseJSON.error); }
40
+ error: function(data) { PayolaSubscriptionForm.showError(form, jQuery.parseJSON(data.responseText).error); }
41
41
  });
42
42
  }
43
43
  },
@@ -56,8 +56,9 @@ var PayolaSubscriptionForm = {
56
56
  }
57
57
  };
58
58
  var errorHandler = function(jqXHR){
59
- if(jqXHR.responseJSON.status === "errored"){
60
- PayolaSubscriptionForm.showError(form, jqXHR.responseJSON.error);
59
+ var responseJSON = jQuery.parseJSON(jqXHR.responseText);
60
+ if(responseJSON.status === "errored"){
61
+ PayolaSubscriptionForm.showError(form, responseJSON.error);
61
62
  }
62
63
  };
63
64
 
@@ -72,7 +73,9 @@ var PayolaSubscriptionForm = {
72
73
 
73
74
  showError: function(form, message) {
74
75
  $('.payola-spinner').hide();
75
- $(':submit').prop('disabled', false);
76
+ $(form).find(':submit')
77
+ .prop('disabled', false)
78
+ .trigger('error', message);
76
79
  var error_selector = form.data('payola-error-selector');
77
80
  if (error_selector) {
78
81
  $(error_selector).text(message);
@@ -88,4 +91,8 @@ var PayolaSubscriptionForm = {
88
91
  }
89
92
  };
90
93
 
91
- $(function() { PayolaSubscriptionForm.initialize() } );
94
+ if ('undefined' !== typeof Turbolinks) {
95
+ $(document).on('page:change', PayolaSubscriptionForm.initialize);
96
+ } else {
97
+ $(document).ready(PayolaSubscriptionForm.initialize);
98
+ }
@@ -0,0 +1,40 @@
1
+ module Payola
2
+ class CardsController < ApplicationController
3
+
4
+ before_filter :check_modify_permissions, only: [:create, :destroy]
5
+
6
+ def create
7
+ if params[:customer_id].present? && params[:stripeToken].present?
8
+ Payola::CreateCard.call(params[:customer_id], params[:stripeToken])
9
+ redirect_to return_to, notice: "Succesfully created new card"
10
+ else
11
+ redirect_to return_to, alert: "Could not create new card"
12
+ end
13
+ end
14
+
15
+ def destroy
16
+ if params[:id].present? && params[:customer_id].present?
17
+ Payola::DestroyCard.call(params[:id], params[:customer_id])
18
+ redirect_to return_to, notice: "Succesfully removed the card"
19
+ else
20
+ redirect_to return_to, alert: "Could not remove the card"
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def check_modify_permissions
27
+ if self.respond_to?(:payola_can_modify_customer?)
28
+ redirect_to(
29
+ return_to,
30
+ alert: "You cannot modify this customer."
31
+ ) and return unless self.payola_can_modify_customer?(params[:customer_id])
32
+ end
33
+ end
34
+
35
+ def return_to
36
+ params[:return_to] || :back
37
+ end
38
+
39
+ end
40
+ end