payola 0.0.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4a5f9f9570731a822d865ec6abfd4aef221d840a
4
- data.tar.gz: cadca3b23c1c6d61c0fb5664036375c5f942cd01
3
+ metadata.gz: d5b3e4ad6b2234c61f66034e64ed2642636df5db
4
+ data.tar.gz: 5f2ccdbe97a48efcf360cf92dc47d52b5c372b0c
5
5
  SHA512:
6
- metadata.gz: 7c8983ee536d696b6c0794d2b5a3ffbc0387eedbd5e9bf1f96eb3348fbd12ce1bdc6e9513019eee8cd958896300c1e1aa66bd7524da61e189e367f04fe177205
7
- data.tar.gz: 39a09db8dceeb5288596cf34900041af2b1773d27aff8e1efec9f95081c9ba5cea475f7b7fb50adce696c5033b9316994d3f49857b31268ee932d1003960ac62
6
+ metadata.gz: 94e1958ee706fb242a1329cd303950faa3944fe49511c70f62aed5e8e5040c843486316abb73d22769055e165ceab56d8036d26ec6c5dab72fd68b4563f61b77
7
+ data.tar.gz: a43622ec27a325b2b118c6d0dc52d7e9a6057e9b665ad798e7b1a5a399f032c051696016b14e2087edc27f5acc317726c848bedc65ec8aa8e2cdd2e18d7eb0b1
@@ -1,6 +1,11 @@
1
1
  module Payola
2
2
  class Configuration
3
- attr_accessor :payment_gateway_api_key
3
+ attr_accessor :payment_gateway_adapter,
4
+ :payment_gateway_api_key
5
+
6
+ def payment_gateway_adapter=(other)
7
+ Payola::Registry[:payment_gateway_adapter] = other
8
+ end
4
9
  end
5
10
 
6
11
  def self.config
@@ -28,12 +28,13 @@ class StripePaymentGateway
28
28
 
29
29
  def apply_subscription
30
30
  update_subscription_plan
31
+ update_subscription_payment_token
31
32
 
32
33
  {
33
34
  status: subscription.status,
34
35
  plan: subscription.plan[:id],
35
36
  subscription_id: "#{subscription.customer}:#{subscription.id}",
36
- last_four_of_credit_card: customer_default_card.last4,
37
+ last_four_of_credit_card: last_four_of_credit_card,
37
38
  }
38
39
  end
39
40
 
@@ -52,6 +53,16 @@ class StripePaymentGateway
52
53
  raise Payola::Errors::PaymentGatewayRequestError.wrap(e)
53
54
  end
54
55
 
56
+ def update_subscription_payment_token
57
+ subscription.save(card: payment_token)
58
+ rescue Stripe::InvalidRequestError => e
59
+ raise Payola::Errors::PaymentGatewayRequestError.wrap(e) unless e.message.match 'cannot use a Stripe token more than once'
60
+ end
61
+
62
+ def last_four_of_credit_card
63
+ customer_default_card.last4 unless plan.amount.zero?
64
+ end
65
+
55
66
  def customer_default_card
56
67
  customer.cards.retrieve(customer.default_card)
57
68
  end
@@ -1,3 +1,3 @@
1
1
  module Payola
2
- VERSION = '0.0.4'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -8,8 +8,8 @@ module Payola
8
8
  module PaymentGateways
9
9
  describe StripePaymentGateway, :stripe, :vcr do
10
10
  before(:each) do
11
- Payola.config.payment_gateway_api_key = 'sk_test_ouP1BhLytHhz96J1VuNPmiJZ'
12
- Stripe.api_key = 'sk_test_ouP1BhLytHhz96J1VuNPmiJZ'
11
+ Payola.config.payment_gateway_api_key = 'sk_test_AyJNzC2ZSmR8u13Ja33D8Gey'
12
+ Stripe.api_key = 'sk_test_AyJNzC2ZSmR8u13Ja33D8Gey'
13
13
  end
14
14
 
15
15
  let(:credit_card_token) do
@@ -129,6 +129,50 @@ describe StripePaymentGateway, :stripe, :vcr do
129
129
  raise_error(Payola::Errors::PaymentGatewayRequestError).
130
130
  with_message("RuntimeError: error creating customer")
131
131
  end
132
+
133
+ it 'allows a free subscription to be created without a previous paid subscription' do
134
+ subscription = StripePaymentGateway.apply_subscription \
135
+ subscription_id: nil,
136
+ plan_id: 'my test plan id',
137
+ amount: Money.new(0, 'USD'),
138
+ interval: 'month',
139
+ interval_count: 1,
140
+ plan_name: 'my test plan name'
141
+
142
+ expect(subscription[:plan]).to eql 'my test plan id'
143
+ expect(subscription[:subscription_id]).to match /\Acus_[A-Za-z0-9]{14}\:sub_[A-Za-z0-9]{14}\z/
144
+ expect(subscription[:status]).to eql 'active'
145
+ expect(subscription[:last_four_of_credit_card]).to eql nil
146
+ end
147
+
148
+ it 'can update a subscription with a new payment token' do
149
+ customer = Stripe::Customer.create
150
+ plan = Stripe::Plan.create id: 'my other existing test plan id',
151
+ amount: 200,
152
+ currency: 'USD',
153
+ interval: 'week',
154
+ name: 'what you talkin bout'
155
+ existing_subscription = customer.subscriptions.create(
156
+ plan: plan.id,
157
+ card: credit_card_token)
158
+
159
+ new_credit_card_token = Payola::Factories::StripePaymentToken.create( card: {
160
+ number: '4012888888881881',
161
+ exp_month: 3,
162
+ exp_year: 2015,
163
+ cvc: '314' })
164
+
165
+ subscription = StripePaymentGateway.apply_subscription \
166
+ subscription_id: "#{customer.id}:#{existing_subscription.id}",
167
+ plan_id: 'my other existing plan id',
168
+ amount: Money.new(200, 'USD'),
169
+ interval: 'week',
170
+ interval_count: 1,
171
+ plan_name: 'what you talking bout',
172
+ payment_token: new_credit_card_token
173
+
174
+ expect(subscription[:last_four_of_credit_card]).to eql '1881'
175
+ end
132
176
  end
133
177
  end
134
178
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: payola
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jfelchner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-28 00:00:00.000000000 Z
11
+ date: 2014-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: stripe
@@ -30,42 +30,42 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.7'
33
+ version: '1.11'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '1.7'
40
+ version: '1.11'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 3.0.0beta
47
+ version: 3.0.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 3.0.0beta
54
+ version: 3.0.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspectacular
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.38.0
61
+ version: 0.47.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.38.0
68
+ version: 0.47.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: money
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -150,9 +150,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  version: '0'
151
151
  requirements: []
152
152
  rubyforge_project: payola
153
- rubygems_version: 2.2.2
153
+ rubygems_version: 2.3.0
154
154
  signing_key:
155
155
  specification_version: 4
156
156
  summary: Abstraction layer on top of Stripe/Braintree, etc so we can get Payola'ed
157
157
  test_files:
158
158
  - spec/lib/payola/payment_gateways/stripe_payment_gateway_spec.rb
159
+ has_rdoc: