payola-payments 1.1.4 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +5 -13
  2. data/app/assets/javascripts/payola/form.js +1 -0
  3. data/app/assets/javascripts/payola/subscription_form.js +74 -0
  4. data/app/controllers/payola/application_controller.rb +1 -2
  5. data/app/controllers/payola/subscriptions_controller.rb +94 -0
  6. data/app/models/concerns/payola/plan.rb +50 -0
  7. data/app/models/payola/subscription.rb +161 -0
  8. data/app/services/payola/cancel_subscription.rb +12 -0
  9. data/app/services/payola/change_subscription_plan.rb +29 -0
  10. data/app/services/payola/create_plan.rb +17 -0
  11. data/app/services/payola/create_subscription.rb +20 -0
  12. data/app/services/payola/invoice_failed.rb +42 -0
  13. data/app/services/payola/invoice_paid.rb +43 -0
  14. data/app/services/payola/process_subscription.rb +7 -0
  15. data/app/services/payola/start_subscription.rb +41 -0
  16. data/app/services/payola/sync_subscription.rb +11 -0
  17. data/app/services/payola/update_card.rb +27 -0
  18. data/app/services/payola/update_subscription.rb +11 -0
  19. data/app/views/payola/subscriptions/_cancel.html.erb +10 -0
  20. data/app/views/payola/subscriptions/_change_plan.html.erb +10 -0
  21. data/config/routes.rb +7 -0
  22. data/db/migrate/20141105043439_create_payola_subscriptions.rb +31 -0
  23. data/db/migrate/20141106034610_add_currency_to_payola_subscriptions.rb +6 -0
  24. data/db/migrate/20141107025420_add_guid_to_payola_subscriptions.rb +6 -0
  25. data/db/migrate/20141109203101_add_stripe_status_to_payola_subscription.rb +5 -0
  26. data/db/migrate/20141112024805_add_affiliate_id_to_payola_subscriptions.rb +5 -0
  27. data/db/migrate/20141114032013_add_coupon_code_to_payola_subscriptions.rb +5 -0
  28. data/db/migrate/20141114154223_add_signed_custom_fields_to_payola_subscription.rb +5 -0
  29. data/db/migrate/20141114163841_add_addresses_to_payola_subscription.rb +6 -0
  30. data/lib/payola.rb +11 -0
  31. data/lib/payola/engine.rb +10 -2
  32. data/lib/payola/version.rb +1 -1
  33. data/spec/concerns/plan_spec.rb +43 -0
  34. data/spec/controllers/payola/subscriptions_controller_spec.rb +148 -0
  35. data/spec/dummy/app/controllers/application_controller.rb +4 -0
  36. data/spec/dummy/app/controllers/home_controller.rb +6 -0
  37. data/spec/dummy/app/controllers/subscribe_controller.rb +11 -0
  38. data/spec/dummy/app/models/subscription_plan.rb +3 -0
  39. data/spec/dummy/app/views/home/index.html.erb +7 -0
  40. data/spec/dummy/app/views/subscribe/index.html.erb +21 -0
  41. data/spec/dummy/app/views/subscribe/show.html.erb +4 -0
  42. data/spec/dummy/config/initializers/payola.rb +4 -0
  43. data/spec/dummy/config/routes.rb +4 -0
  44. data/spec/dummy/db/development.sqlite3 +0 -0
  45. data/spec/dummy/db/migrate/20141105010234_create_subscription_plans.rb +14 -0
  46. data/spec/dummy/db/schema.rb +51 -1
  47. data/spec/dummy/db/test.sqlite3 +0 -0
  48. data/spec/dummy/log/development.log +275 -0
  49. data/spec/dummy/log/test.log +109420 -0
  50. data/spec/dummy/tmp/cache/assets/development/sprockets/0e585aeb88c1555ae8f5292f7c7a9068 +0 -0
  51. data/spec/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  52. data/spec/dummy/tmp/cache/assets/development/sprockets/1b54952339cbc96811097cee5f8923b4 +0 -0
  53. data/spec/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  54. data/spec/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  55. data/spec/dummy/tmp/cache/assets/development/sprockets/5afa4bc970e0bc781b3500c696ba25ff +0 -0
  56. data/spec/dummy/tmp/cache/assets/development/sprockets/664efeb51d1b486dcfc30d142db56f3c +0 -0
  57. data/spec/dummy/tmp/cache/assets/development/sprockets/68a3bbdc64a0729b5896fa1e33fce4b1 +0 -0
  58. data/spec/dummy/tmp/cache/assets/development/sprockets/96b1ccdc193a02b2bbea195310262fa5 +0 -0
  59. data/spec/dummy/tmp/cache/assets/development/sprockets/aea159adbc0944b120d91d5b578612ba +0 -0
  60. data/spec/dummy/tmp/cache/assets/development/sprockets/b20dab973e971c61bc7e334a38453ae0 +0 -0
  61. data/spec/dummy/tmp/cache/assets/development/sprockets/b83da90cb58011313e13a97a4a41cb6e +0 -0
  62. data/spec/dummy/tmp/cache/assets/development/sprockets/c0b954b40f2881a6d286061bc069643e +0 -0
  63. data/spec/dummy/tmp/cache/assets/development/sprockets/c5b3877d49b39932a7557611cefca9a6 +0 -0
  64. data/spec/dummy/tmp/cache/assets/development/sprockets/ca491e325ff6948be9292f701aa4ce64 +0 -0
  65. data/spec/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  66. data/spec/dummy/tmp/cache/assets/development/sprockets/d3f4b67cc032016dfeebc71f2148b9dc +0 -0
  67. data/spec/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  68. data/spec/dummy/tmp/cache/assets/development/sprockets/d9856638a3c7b9cfd9d1b884e3b33982 +0 -0
  69. data/spec/dummy/tmp/cache/assets/development/sprockets/ddba6e841f28d3005e828fbfffd18b74 +0 -0
  70. data/spec/dummy/tmp/cache/assets/development/sprockets/df935e399019055729aa968bd7062096 +0 -0
  71. data/spec/dummy/tmp/cache/assets/development/sprockets/ef82c31948061751bb026663b54484e1 +0 -0
  72. data/spec/dummy/tmp/cache/assets/development/sprockets/f0b5d4bea0c6cdd1904e1e9a0a45532f +0 -0
  73. data/spec/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  74. data/spec/factories/payola_subscriptions.rb +25 -0
  75. data/spec/factories/subscription_plan.rb +9 -0
  76. data/spec/models/payola/subscription_spec.rb +50 -0
  77. data/spec/services/payola/cancel_subscription_spec.rb +29 -0
  78. data/spec/services/payola/change_subscription_plan_spec.rb +31 -0
  79. data/spec/services/payola/charge_card_spec.rb +9 -5
  80. data/spec/services/payola/create_plan_spec.rb +24 -0
  81. data/spec/services/payola/create_subscription_spec.rb +65 -0
  82. data/spec/services/payola/invoice_failed_spec.rb +29 -0
  83. data/spec/services/payola/invoice_paid_spec.rb +49 -0
  84. data/spec/services/payola/start_subscription_spec.rb +36 -0
  85. data/spec/services/payola/sync_subscription_spec.rb +14 -0
  86. data/spec/services/payola/update_card_spec.rb +26 -0
  87. metadata +95 -30
@@ -0,0 +1,17 @@
1
+ module Payola
2
+ class CreatePlan
3
+ def self.call(plan)
4
+ secret_key = Payola.secret_key_for_sale(plan)
5
+
6
+ Stripe::Plan.create({
7
+ id: plan.stripe_id,
8
+ amount: plan.amount,
9
+ interval: plan.interval,
10
+ interval_count: plan.interval_count,
11
+ currency: plan.respond_to?(:currency) ? plan.currency : Payola.default_currency,
12
+ name: plan.name,
13
+ trial_period_days: plan.respond_to?(:trial_period_days) ? plan.trial_period_days : nil
14
+ }, secret_key)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,20 @@
1
+ module Payola
2
+ class CreateSubscription
3
+ def self.call(params)
4
+ plan = params[:plan]
5
+ affiliate = params[:affiliate]
6
+
7
+ Payola::Subscription.new do |s|
8
+ s.plan = plan
9
+ s.email = params[:stripeEmail]
10
+ s.stripe_token = params[:stripeToken]
11
+ s.affiliate_id = affiliate.try(:id)
12
+ s.currency = plan.respond_to?(:currency) ? plan.currency : Payola.default_currency
13
+ s.coupon = params[:coupon]
14
+ #s.signed_custom_fields = params[:signed_custom_fields]
15
+
16
+ s.amount = plan.amount
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,42 @@
1
+ module Payola
2
+ class InvoiceFailed
3
+ def self.call(event)
4
+ invoice = event.data.object
5
+
6
+ subscription = Payola::Subscription.find_by!(stripe_id: invoice.subscription)
7
+ secret_key = Payola.secret_key_for_sale(subscription)
8
+
9
+ stripe_sub = Stripe::Customer.retrieve(subscription.stripe_customer_id, secret_key).subscriptions.retrieve(invoice.subscription, secret_key)
10
+ subscription.sync_with!(stripe_sub)
11
+
12
+ sale = Payola::Sale.new do |s|
13
+ s.email = subscription.email
14
+ s.state = 'processing'
15
+ s.owner = subscription
16
+ s.product = subscription.plan
17
+ s.stripe_token = 'invoice'
18
+ s.amount = invoice.total
19
+ s.currency = invoice.currency
20
+ end
21
+
22
+ charge = Stripe::Charge.retrieve(invoice.charge, secret_key)
23
+
24
+ sale.stripe_id = charge.id
25
+ sale.card_type = charge.card.respond_to?(:brand) ? charge.card.brand : charge.card.type
26
+ sale.card_last4 = charge.card.last4
27
+
28
+ if charge.respond_to?(:fee)
29
+ sale.fee_amount = charge.fee
30
+ else
31
+ balance = Stripe::BalanceTransaction.retrieve(charge.balance_transaction, secret_key)
32
+ sale.fee_amount = balance.fee
33
+ end
34
+
35
+ sale.error = charge.failure_message
36
+ sale.save!
37
+ sale.fail!
38
+
39
+ sale
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,43 @@
1
+ module Payola
2
+ class InvoicePaid
3
+ def self.call(event)
4
+ invoice = event.data.object
5
+
6
+ return unless invoice.charge
7
+
8
+ subscription = Payola::Subscription.find_by!(stripe_id: invoice.subscription)
9
+
10
+ secret_key = Payola.secret_key_for_sale(subscription)
11
+ stripe_sub = Stripe::Customer.retrieve(subscription.stripe_customer_id, secret_key).subscriptions.retrieve(invoice.subscription, secret_key)
12
+ subscription.sync_with!(stripe_sub)
13
+
14
+ sale = Payola::Sale.new do |s|
15
+ s.email = subscription.email
16
+ s.state = 'processing'
17
+ s.owner = subscription
18
+ s.product = subscription.plan
19
+ s.stripe_token = 'invoice'
20
+ s.amount = invoice.total
21
+ s.currency = invoice.currency
22
+ end
23
+
24
+ charge = Stripe::Charge.retrieve(invoice.charge, secret_key)
25
+
26
+ sale.stripe_id = charge.id
27
+ sale.card_type = charge.card.respond_to?(:brand) ? charge.card.brand : charge.card.type
28
+ sale.card_last4 = charge.card.last4
29
+
30
+ if charge.respond_to?(:fee)
31
+ sale.fee_amount = charge.fee
32
+ else
33
+ balance = Stripe::BalanceTransaction.retrieve(charge.balance_transaction, secret_key)
34
+ sale.fee_amount = balance.fee
35
+ end
36
+
37
+ sale.save!
38
+ sale.finish!
39
+
40
+ sale
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,7 @@
1
+ module Payola
2
+ class ProcessSubscription
3
+ def self.call(guid)
4
+ Subscription.find_by(guid: guid).process!
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,41 @@
1
+ module Payola
2
+ class StartSubscription
3
+ def self.call(subscription)
4
+ subscription.save!
5
+ secret_key = Payola.secret_key_for_sale(subscription)
6
+
7
+ begin
8
+ subscription.verify_charge!
9
+
10
+ create_params = {
11
+ card: subscription.stripe_token,
12
+ email: subscription.email,
13
+ plan: subscription.plan.stripe_id,
14
+ }
15
+ create_params[:coupon] = subscription.coupon if subscription.coupon.present?
16
+
17
+ customer = Stripe::Customer.create(create_params, secret_key)
18
+
19
+ card = customer.cards.data.first
20
+ subscription.update_attributes(
21
+ stripe_id: customer.subscriptions.data.first.id,
22
+ stripe_customer_id: customer.id,
23
+ card_last4: card.last4,
24
+ card_expiration: Date.new(card.exp_year, card.exp_month, 1),
25
+ card_type: card.respond_to?(:brand) ? card.brand : card.type
26
+ )
27
+ subscription.activate!
28
+ rescue Stripe::StripeError => e
29
+ subscription.update_attributes(error: e.message)
30
+ subscription.fail!
31
+ rescue RuntimeError => e
32
+ subscription.update_attributes(error: e.message)
33
+ subscription.fail!
34
+ end
35
+
36
+ subscription
37
+ end
38
+
39
+ end
40
+ end
41
+
@@ -0,0 +1,11 @@
1
+ module Payola
2
+ class SyncSubscription
3
+ def self.call(event)
4
+ stripe_sub = event.data.object
5
+
6
+ sub = Payola::Subscription.find_by!(stripe_id: stripe_sub.id)
7
+
8
+ sub.sync_with!(stripe_sub)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,27 @@
1
+ module Payola
2
+ class UpdateCard
3
+ def self.call(subscription, token)
4
+ secret_key = Payola.secret_key_for_sale(subscription)
5
+ begin
6
+ customer = Stripe::Customer.retrieve(subscription.stripe_customer_id, secret_key)
7
+
8
+ customer.card = token
9
+ customer.save
10
+
11
+ customer = Stripe::Customer.retrieve(subscription.stripe_customer_id, secret_key)
12
+ card = customer.cards.retrieve(customer.default_card, secret_key)
13
+
14
+ subscription.update_attributes(
15
+ card_type: card.brand,
16
+ card_last4: card.last4,
17
+ card_expiration: Date.parse("#{card.exp_year}/#{card.exp_month}/1")
18
+ )
19
+ subscription.save!
20
+ rescue RuntimeError, Stripe::StripeError => e
21
+ subscription.errors[:base] << e.message
22
+ end
23
+
24
+ subscription
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,11 @@
1
+ module Payola
2
+ class UpdateSubscription
3
+ def self.call(event)
4
+ stripe_sub = event.data.object
5
+
6
+ sub = Payola::Subscription.find_by(stripe_id: stripe_sub.id)
7
+
8
+ sub.sync_with!(stripe_sub)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,10 @@
1
+ <%
2
+ button_class = local_assigns.fetch :button_class, 'stripe-button-el'
3
+ button_text = local_assigns.fetch :button_text, "Cancel Subscription"
4
+ confirm_text = local_assigns.fetch :confirm_text, "Are you sure?"
5
+ disabled = subscription.active?
6
+ %>
7
+
8
+ <%= form_tag payola.cancel_subscription_path(subscription.guid), :method => :delete do %>
9
+ <%= submit_tag button_text, html: { disabled: disabled, class: button_class }, data: { confirm: confirm_text } %>
10
+ <% end %>
@@ -0,0 +1,10 @@
1
+ <%
2
+ button_class = local_assigns.fetch :button_class, 'stripe-button-el'
3
+ button_text = local_assigns.fetch :button_text, "Update Plan"
4
+ %>
5
+
6
+ <%= form_for subscription, method: :post, url: change_subscription_plan(subscription) do |f| %>
7
+ <%= hidden_field_tag 'plan_class', new_plan.plan_class %>
8
+ <%= hidden_field_tag 'plan_id', new_plan.id %>
9
+ <%= button_tag button_text, class: button_class %>
10
+ <% end %>
data/config/routes.rb CHANGED
@@ -3,5 +3,12 @@ Payola::Engine.routes.draw do
3
3
  match '/confirm/:guid' => 'transactions#show', via: :get, as: :confirm
4
4
  match '/status/:guid' => 'transactions#status', via: :get, as: :status
5
5
 
6
+ match '/subscribe/:plan_class/:plan_id' => 'subscriptions#create', via: :post, as: :subscribe
7
+ match '/confirm_subscription/:guid' => 'subscriptions#show', via: :get, as: :confirm_subscription
8
+ match '/subscription_status/:guid' => 'subscriptions#status', via: :get, as: :subscription_status
9
+ match '/cancel_subscription/:guid' => 'subscriptions#destroy', via: :delete, as: :cancel_subscription
10
+ match '/change_plan/:guid' => 'subscriptions#change_plan', via: :post, as: :change_subscription_plan
11
+ match '/update_card/:guid' => 'subscriptions#update_card', via: :post, as: :update_card
12
+
6
13
  mount StripeEvent::Engine => '/events'
7
14
  end
@@ -0,0 +1,31 @@
1
+ class CreatePayolaSubscriptions < ActiveRecord::Migration
2
+ def change
3
+ create_table :payola_subscriptions do |t|
4
+ t.string :plan_type
5
+ t.integer :plan_id
6
+ t.timestamp :start
7
+ t.string :status
8
+ t.string :owner_type
9
+ t.integer :owner_id
10
+ t.string :stripe_customer_id
11
+ t.boolean :cancel_at_period_end
12
+ t.timestamp :current_period_start
13
+ t.timestamp :current_period_end
14
+ t.timestamp :ended_at
15
+ t.timestamp :trial_start
16
+ t.timestamp :trial_end
17
+ t.timestamp :canceled_at
18
+ t.integer :quantity
19
+ t.string :stripe_id
20
+ t.string :stripe_token
21
+ t.string :card_last4
22
+ t.date :card_expiration
23
+ t.string :card_type
24
+ t.text :error
25
+ t.string :state
26
+ t.string :email
27
+
28
+ t.timestamps
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,6 @@
1
+ class AddCurrencyToPayolaSubscriptions < ActiveRecord::Migration
2
+ def change
3
+ add_column :payola_subscriptions, :currency, :string
4
+ add_column :payola_subscriptions, :amount, :integer
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ class AddGuidToPayolaSubscriptions < ActiveRecord::Migration
2
+ def change
3
+ add_column :payola_subscriptions, :guid, :string
4
+ add_index :payola_subscriptions, :guid
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ class AddStripeStatusToPayolaSubscription < ActiveRecord::Migration
2
+ def change
3
+ add_column :payola_subscriptions, :stripe_status, :string
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddAffiliateIdToPayolaSubscriptions < ActiveRecord::Migration
2
+ def change
3
+ add_column :payola_subscriptions, :affiliate_id, :integer
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddCouponCodeToPayolaSubscriptions < ActiveRecord::Migration
2
+ def change
3
+ add_column :payola_subscriptions, :coupon, :string
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class AddSignedCustomFieldsToPayolaSubscription < ActiveRecord::Migration
2
+ def change
3
+ add_column :payola_subscriptions, :signed_custom_fields, :text
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ class AddAddressesToPayolaSubscription < ActiveRecord::Migration
2
+ def change
3
+ add_column :payola_subscriptions, :customer_address, :text
4
+ add_column :payola_subscriptions, :business_address, :text
5
+ end
6
+ end
data/lib/payola.rb CHANGED
@@ -13,6 +13,7 @@ module Payola
13
13
  :event_filter,
14
14
  :support_email,
15
15
  :sellables,
16
+ :subscribables,
16
17
  :charge_verifier,
17
18
  :default_currency,
18
19
  :additional_charge_attributes,
@@ -70,6 +71,7 @@ module Payola
70
71
  self.support_email = 'sales@example.com'
71
72
  self.default_currency = 'usd'
72
73
  self.sellables = {}
74
+ self.subscribables = {}
73
75
  self.additional_charge_attributes = lambda { |sale, customer| { } }
74
76
  self.pdf_receipt = false
75
77
  end
@@ -78,6 +80,10 @@ module Payola
78
80
  sellables[klass.product_class] = klass
79
81
  end
80
82
 
83
+ def register_subscribable(klass)
84
+ subscribables[klass.plan_class] = klass
85
+ end
86
+
81
87
  def send_email_for(*emails)
82
88
  possible_emails = {
83
89
  receipt: [ 'payola.sale.finished', Payola::ReceiptMailer, :receipt ],
@@ -92,6 +98,11 @@ module Payola
92
98
  spec = possible_emails[email].dup
93
99
  if spec
94
100
  Payola.subscribe(spec.shift) do |sale|
101
+
102
+ if sale.is_a?(Stripe::Event)
103
+ sale = Payola::Sale.find_by!(stripe_id: sale.data.object.id)
104
+ end
105
+
95
106
  Payola.send_mail(*(spec + [sale.guid]))
96
107
  end
97
108
  end
data/lib/payola/engine.rb CHANGED
@@ -20,11 +20,19 @@ module Payola
20
20
 
21
21
  initializer :inject_helpers do |app|
22
22
  ActiveSupport.on_load :action_controller do
23
- helper Payola::PriceHelper
23
+ ::ApplicationController.send(:helper, Payola::PriceHelper)
24
24
  end
25
25
 
26
26
  ActiveSupport.on_load :action_mailer do
27
- helper Payola::PriceHelper
27
+ ::ActionMailer::Base.send(:helper, Payola::PriceHelper)
28
+ end
29
+ end
30
+
31
+ initializer :configure_subscription_listeners do |app|
32
+ Payola.configure do |config|
33
+ config.subscribe 'invoice.payment_succeeded', Payola::InvoicePaid
34
+ config.subscribe 'invoice.payment_failed', Payola::InvoiceFailed
35
+ config.subscribe 'customer.subscription.updated', Payola::SyncSubscription
28
36
  end
29
37
  end
30
38
  end
@@ -1,3 +1,3 @@
1
1
  module Payola
2
- VERSION = "1.1.4"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ module Payola
4
+ describe Plan do
5
+
6
+ it "should validate" do
7
+ subscription_plan = build(:subscription_plan)
8
+ expect(subscription_plan.valid?).to be true
9
+ end
10
+
11
+ it "should validate amount" do
12
+ subscription_plan = build(:subscription_plan, amount: nil)
13
+ expect(subscription_plan.valid?).to be false
14
+ end
15
+
16
+ it "should validate interval" do
17
+ subscription_plan = build(:subscription_plan, interval: nil)
18
+ expect(subscription_plan.valid?).to be false
19
+ end
20
+
21
+ it "should validate interval_count" do
22
+ subscription_plan = build(:subscription_plan, interval_count: nil)
23
+ expect(subscription_plan.valid?).to be false
24
+ end
25
+
26
+ it "should validate stripe_id" do
27
+ subscription_plan = build(:subscription_plan, stripe_id: nil)
28
+ expect(subscription_plan.valid?).to be false
29
+ end
30
+
31
+ it "should validate name" do
32
+ subscription_plan = build(:subscription_plan, name: nil)
33
+ expect(subscription_plan.valid?).to be false
34
+ end
35
+
36
+ it "should create the plan at stripe before the model is created" do
37
+ subscription_plan = build(:subscription_plan)
38
+ Payola::CreatePlan.should_receive(:call)
39
+ subscription_plan.save!
40
+ end
41
+
42
+ end
43
+ end