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.
- checksums.yaml +4 -4
- data/app/assets/javascripts/payola/checkout_button.js +9 -5
- data/app/assets/javascripts/payola/form.js +10 -4
- data/app/assets/javascripts/payola/subscription_checkout_button.js +41 -24
- data/app/assets/javascripts/payola/subscription_form_onestep.js +13 -6
- data/app/assets/javascripts/payola/subscription_form_register.js +97 -0
- data/app/assets/javascripts/payola/subscription_form_twostep.js +14 -7
- data/app/controllers/payola/cards_controller.rb +40 -0
- data/app/controllers/payola/customers_controller.rb +37 -0
- data/app/controllers/payola/subscriptions_controller.rb +1 -1
- data/app/models/concerns/payola/plan.rb +1 -1
- data/app/models/payola/subscription.rb +15 -1
- data/app/services/payola/cancel_subscription.rb +6 -3
- data/app/services/payola/change_subscription_plan.rb +15 -7
- data/app/services/payola/create_card.rb +13 -0
- data/app/services/payola/create_subscription.rb +14 -6
- data/app/services/payola/destroy_card.rb +9 -0
- data/app/services/payola/process_refund.rb +20 -0
- data/app/services/payola/start_subscription.rb +30 -15
- data/app/services/payola/subscription_deleted.rb +11 -0
- data/app/services/payola/update_customer.rb +9 -0
- data/app/views/payola/subscriptions/_cancel.html.erb +2 -0
- data/app/views/payola/subscriptions/_checkout.html.erb +13 -4
- data/app/views/payola/transactions/_form.html.erb +1 -1
- data/config/routes.rb +8 -3
- data/db/migrate/20150930164135_add_tax_percent_to_payola_subscriptions.rb +5 -0
- data/lib/generators/payola/templates/initializer.rb +1 -1
- data/lib/payola.rb +5 -1
- data/lib/payola/engine.rb +1 -0
- data/lib/payola/version.rb +1 -1
- data/spec/concerns/plan_spec.rb +34 -11
- data/spec/controllers/payola/cards_controller_spec.rb +78 -0
- data/spec/controllers/payola/customers_controller_spec.rb +41 -0
- data/spec/controllers/payola/subscriptions_controller_spec.rb +14 -5
- data/spec/dummy/db/schema.rb +8 -7
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +83 -0
- data/spec/dummy/log/test.log +15285 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/05-CimMmYqCyJHDw0mlYlY8QTYNZWxvvjXNzt99raT8.cache +1 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/0cwo25M79KGYxnM1Fn5aVXuB5Vx5NXDeI1mauCHJ6C0.cache +1 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/1RezgAqI3WpLjtCkf15A28C_C_ZggGaTUJVj_0OtZt0.cache +2 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/1sN5oeTaBcGDHbdpHx7u12CUoshmGO0a8n6wvOZ8e9g.cache +2 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/4Huwm41yGPbqU_ktIlyb9x7zWCBrETs8Hi1vod_h6CM.cache +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/6GYiGbi_eHKrkW4pmMOQc-YcJd5yjqypkSSVsmvLdGQ.cache +2 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/6jBC_ionlG5SaNmx7QnmYyHapApzfD7gO7iacmF7A-o.cache +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/8PuswVUdqRS0_2AjXzB3SJnp0T6R4XDd52aXU8HUb20.cache +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/93_-tHqt48795qdk0JqDUZvfu8txM-kzSbHHwUHfUg4.cache +2 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/BJ9VCB2p3PpqouoGa_QmkGjFv4aPZWzCCDiFpknRFCA.cache +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/Cvp1E8cK9iR8ZIyJng_CyOI5-lFm_PpQuqJpfpdsFJQ.cache +1 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/D3ZSFffpWANPSAj2gTmelfr4w-KkX84C0EgyPOy6Y6o.cache +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/DBdvUpmp3qMac1HkOn7D-0WoON1Vn4n0VkmcBo9PYTE.cache +1 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/EM3Tna1A9GSD2IeCpTZmuINPPHpdTXPbCG6sbLXHKPI.cache +1 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/FJ2Xe7ZXhQCx8O6gziOCZXLYIMDdWQElTtXlygmzDP0.cache +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/GDXP5hnN5ycGmMuaWltb9AFtcEBq7WXRfWTLjBgSK8I.cache +1 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/GFxndLm-jxLvxsJ4aUJ54BUZ32Ypzp7mLCmArWCOIa4.cache +1 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/GJmK02s0v61jK_BI__yUZI7NpGUVtXfur9ZiQGwOYyU.cache +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/MrKh1ye7y3UHd5ox4OgIUhcXyLvEN5FWvs6v7CzqFWI.cache +3 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/Nl0Imk9BLfXqZ83k4_-tB2g0aevktUZocldLZzEE8DM.cache +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/Nz8cUs5LShWxHeARb_8KNPjYZGYN8tCqWa2OoovieYg.cache +1 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/OWrok24obbylOHeAaps9WA5SBwjpaEd0xnQqBWOc-mQ.cache +2 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/QVhitoXuP03xtsfQo4gH_mAw16dk1EPH7Xf8JlXVLpk.cache +1 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/QrIfBX9SocQINdKbcOGU2ZplYq_3lE7-CgPvvFRZUPs.cache +3 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/RSFirXKeTuMV9nWIeu-30jvOMVQTdZQUugyREItprkE.cache +1 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/S5giqzoBdK-jXI6AoAelpiCYhMTwMFNaxjUJj816KdM.cache +2 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/Se3LTfrl02BuX--hLV7cqyaPT9b9ydVPYsWlXjSvQ6Q.cache +1 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/SwyH6o1ZPaOTMGyVqMXuWtYuyf9yBl0NRSVjvv2HQGo.cache +1 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/T8VFzmrZkpfAHu4YyuwEfZWPF3sv77n7comxiwI6yK4.cache +1 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/Te0Swu57VjhvpFOJV5fIm9X9C-tiyuF486pgN6gWuvs.cache +2 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/TolX3hiRfWiUWMlwHiH5G7KZZuFKPV2geKgORhx1kbc.cache +1 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/W5-aJJXrwJHHZ2LUNvSZJDuDWnf-nXHn_RrdHm8Dsy4.cache +1 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/WwYeCgq1wE5ouj5QoNsFDYa_K0Hw5SNPPPyzZ9JRk_M.cache +1 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/WxGjqpQ1GofgXtH2VW51hBdHzehHiH9QQSzeFwvPa04.cache +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/X-OoOAyH7movCISCvhiawWmwCODe3fN7ymRIQEQJGWs.cache +1 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/YUqxvOCuXaKKNVrkC0BmaxSs-ae8k61lE-cXvNvp6ts.cache +2 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/ald4YZEKpA5mAmBUBRLwntPH1BB--dukFx4hRB1G8Sc.cache +2 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/coggheKLeRswSaNoMMz-DG4eSncE1LfiKd6ebpHdcDQ.cache +1 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/ctvwDGAdKE_Nmp-gIQsb4edj11gnDV2HvIb4f_hTr1A.cache +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/d1MBBmJw2iL1O_NLFnwSRJlDR2VB-Au8nckF0HcpAjU.cache +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/fQIfzJDoR7LlNPN5nxZ-wlReF7b9zJ71zPnU-mwz0tU.cache +1 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/if00l9X27C69IaQ5LW33GQ76AK8TNTK2x_mAtUBiK_Y.cache +2 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/mFdDv_nbtZKHUux_oAK4OmPBu8TJ62BtWnklHAw52lk.cache +1 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/nGRK5RyFWrQfZM7AqkyVNDZrMJny5SvIThqdcSaF7s4.cache +1 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/nxuLyls6X-Txo4fYUEBKChRSnonW6fR3e3hy60jNKDk.cache +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/o8Pe3_OPNi7cpOIjfFsLK0KP_hLNPoR0eO61oXCo40Q.cache +2 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/oiIb0gmeFbc8wNdBNqzP6QepH1VG7L6rOwt7JRjLF6Y.cache +1 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/os-IBWzcQaIeJAr-eZ0ISapp8u6ViHJBDVl3zsSnAxs.cache +1 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/p8-Esy85oOHbF8SlC_ADEPGi7AjMurnoYSdCD3V0QHo.cache +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/rDG6NUIkefVSkt66sViHIj-M-YmUVD3LC383yOQZE3Y.cache +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/rT-10_0UmPqfTi7e_RvVV2oVVrZPcnzEVxYryWf0AWk.cache +1 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/rgRsqTnAPvMJlyOn2tOMsfX1YNwqiKZprIoYnBtUIao.cache +2 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/tZkY3_ZombuoVZpSwY2dfvHcyD88nyqaNHLzVfrlSbA.cache +1 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/v8-7s6wdUoobgWtvSQPJYtNsLoojslrMGambhfCbLBo.cache +2 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/xAmLB93l5rnHnPfuqo_rdVoCN4PRE5-22KU8O3LNn5U.cache +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/xFmik7WLB1nL3qhSnRWbIEXIwMG1K_dLc1ymZ3hNJ_8.cache +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/z5DZtajWt8UQUvtzye6ncruhskjV7HVUOKWv800kzrE.cache +2 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/v3.0/zPJ93ju23hj65NVsVWOgNlvHe3OjA-SGQ9nU2oupKlI.cache +2 -0
- data/spec/factories/payola_subscriptions.rb +2 -3
- data/spec/models/payola/subscription_spec.rb +35 -1
- data/spec/payola_spec.rb +7 -0
- data/spec/services/payola/change_subscription_plan_spec.rb +70 -7
- data/spec/services/payola/create_card_spec.rb +42 -0
- data/spec/services/payola/create_subscription_spec.rb +12 -10
- data/spec/services/payola/destroy_card_spec.rb +28 -0
- data/spec/services/payola/process_refund_spec.rb +35 -0
- data/spec/services/payola/start_subscription_spec.rb +27 -3
- data/spec/services/payola/subscription_deleted_spec.rb +11 -0
- data/spec/services/payola/update_customer_spec.rb +26 -0
- metadata +142 -6
- data/app/services/payola/#update_card.rb# +0 -27
- 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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 09b8e76fdaef1aec8962ac64e436a9b578fd78af
|
4
|
+
data.tar.gz: bc890a26821355bbb8d58b9e98814ab0f4e609a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0716e1222343a26dae355bfed19b2b817f42141cb707573b00599930f01bde231f0ee4b2a3f7eb0d625b755121778bc86641aab08a7a147d4b26d16ae6358dcb
|
7
|
+
data.tar.gz: 95d657b2c1e81e7c5dcbf565008145cc26cd4ed6ab9ae25536a43f7431448943b557559fc623b852ac04e7d499dd691d135f656e5989a1b4ea4ca7a272280864
|
@@ -1,6 +1,6 @@
|
|
1
1
|
var PayolaCheckout = {
|
2
2
|
initialize: function() {
|
3
|
-
$(
|
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.
|
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
|
-
|
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
|
-
$(
|
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.
|
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')
|
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
|
-
|
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
|
-
$(
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
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:
|
48
|
-
data:
|
58
|
+
url: url,
|
59
|
+
data: data,
|
49
60
|
success: function(data) { PayolaSubscriptionCheckout.poll(data.guid, 60, options); },
|
50
|
-
error: function(data) { PayolaSubscriptionCheckout.showError(data.
|
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
|
-
|
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
|
-
$(
|
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.
|
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.
|
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
|
-
$(
|
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
|
-
|
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
|
-
$(
|
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.
|
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
|
-
|
60
|
-
|
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
|
-
$(
|
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
|
-
|
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
|