pay 2.6.3 → 2.6.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of pay might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 429e92c76a90f5de0cec18dce219479de7ea172d6807c3b0d86d0a2fe4994b77
4
- data.tar.gz: 85b9e46b65d4ea0fa0e7255cc47e1e5c60e55e14f18fee9c567c4befb0e1dac7
3
+ metadata.gz: 2a72ff3544c6fa85675a96d650f152b8f3593211f0c205a5a10cddca5d1f7c35
4
+ data.tar.gz: b7593ef07b57654f4ee566cf2fc538b495d22a9667ec90c6695759a464968dae
5
5
  SHA512:
6
- metadata.gz: 577c6792e5ff3f60e01a02de38bdc414aa0c6178ec0927c6b5766051224f632f83d551a787888d196ac57cf7d4299786a5f1afbcfc0376b10b9115ca97c74dc7
7
- data.tar.gz: dc0da5b5df00f672cc621acf89168f7b3c8c1f419aaa7c5802f015cfb3a4c6cf95284310fc776ca67e51da69c803a24d9c66b50407bd08044492abff1444eb00
6
+ metadata.gz: 572f4f2989bce0a3afa7a483585e3e6f7e96f0487eb34bf5cb790a60a3b66bc0eeafa4ed48a011e00232770b565d1c592491eb613465054cf5de34bae58b168c
7
+ data.tar.gz: cd5059977bd91e4c72b8c51a7f8584b23d15e7bc988ca3421400e39232b781481271a57f06777c71c83cfee73bcab03312de35734c3138e3101e2aa125e4db27
data/README.md CHANGED
@@ -11,6 +11,7 @@ Pay is a payments engine for Ruby on Rails 4.2 and higher.
11
11
  - Stripe ([SCA Compatible](https://stripe.com/docs/strong-customer-authentication) using API version `2020-08-27`)
12
12
  - Paddle (SCA Compatible & supports PayPal)
13
13
  - Braintree (supports PayPal)
14
+ - [Fake Processor](docs/fake_processor.md)
14
15
 
15
16
  Want to add a new payment provider? Contributions are welcome and the instructions [are here](https://github.com/jasoncharnes/pay/wiki/New-Payment-Provider).
16
17
 
data/lib/pay.rb CHANGED
@@ -10,6 +10,7 @@ module Pay
10
10
 
11
11
  # Payment processors
12
12
  autoload :Braintree, "pay/braintree"
13
+ autoload :FakeProcessor, "pay/fake_processor"
13
14
  autoload :Paddle, "pay/paddle"
14
15
  autoload :Stripe, "pay/stripe"
15
16
 
data/lib/pay/billable.rb CHANGED
@@ -24,6 +24,9 @@ module Pay
24
24
  attribute :plan, :string
25
25
  attribute :quantity, :integer
26
26
  attribute :card_token, :string
27
+ attribute :pay_fake_processor_allowed, :boolean, default: false
28
+
29
+ validate :pay_fake_processor_is_allowed, if: :processor_changed?
27
30
  end
28
31
 
29
32
  def payment_processor
@@ -155,5 +158,10 @@ module Pay
155
158
  # Generic trials don't have plans or custom names
156
159
  plan.nil? && name == "default" && on_generic_trial?
157
160
  end
161
+
162
+ def pay_fake_processor_is_allowed
163
+ return unless processor == "fake_processor"
164
+ errors.add(:processor, "must be a valid payment processor") unless pay_fake_processor_allowed?
165
+ end
158
166
  end
159
167
  end
@@ -9,13 +9,13 @@ module Pay
9
9
  :name,
10
10
  :on_trial?,
11
11
  :owner,
12
- :processor_subscription,
13
12
  :processor_id,
13
+ :processor_plan,
14
+ :processor_subscription,
14
15
  :prorate,
15
16
  :prorate?,
16
- :processor_plan,
17
- :quantity?,
18
17
  :quantity,
18
+ :quantity?,
19
19
  :trial_ends_at,
20
20
  to: :pay_subscription
21
21
 
@@ -0,0 +1,8 @@
1
+ module Pay
2
+ module FakeProcessor
3
+ autoload :Billable, "pay/fake_processor/billable"
4
+ autoload :Charge, "pay/fake_processor/charge"
5
+ autoload :Subscription, "pay/fake_processor/subscription"
6
+ autoload :Error, "pay/fake_processor/error"
7
+ end
8
+ end
@@ -0,0 +1,60 @@
1
+ module Pay
2
+ module FakeProcessor
3
+ class Billable
4
+ attr_reader :billable
5
+
6
+ delegate :processor_id,
7
+ :processor_id?,
8
+ :email,
9
+ :customer_name,
10
+ :card_token,
11
+ to: :billable
12
+
13
+ def initialize(billable)
14
+ @billable = billable
15
+ end
16
+
17
+ def customer
18
+ billable
19
+ end
20
+
21
+ def charge(amount, options = {})
22
+ billable.charges.create(
23
+ processor: :fake_processor,
24
+ processor_id: rand(100_000_000),
25
+ amount: amount,
26
+ card_type: :fake,
27
+ card_last4: 1234,
28
+ card_exp_month: Date.today.month,
29
+ card_exp_year: Date.today.year
30
+ )
31
+ end
32
+
33
+ def subscribe(name: Pay.default_product_name, plan: Pay.default_plan_name, **options)
34
+ subscription = OpenStruct.new id: rand(1_000_000)
35
+ billable.create_pay_subscription(subscription, :fake_processor, name, plan, status: :active, quantity: options.fetch(:quantity, 1))
36
+ end
37
+
38
+ def update_card(payment_method_id)
39
+ billable.update(
40
+ card_type: :fake,
41
+ card_last4: 1234,
42
+ card_exp_month: Date.today.month,
43
+ card_exp_year: Date.today.year
44
+ )
45
+ end
46
+
47
+ def update_email!
48
+ # pass
49
+ end
50
+
51
+ def processor_subscription(subscription_id, options = {})
52
+ billable.subscriptions.find_by(processor: :fake_processor, processor_id: subscription_id)
53
+ end
54
+
55
+ def trial_end_date(subscription)
56
+ Date.today
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,21 @@
1
+ module Pay
2
+ module FakeProcessor
3
+ class Charge
4
+ attr_reader :pay_charge
5
+
6
+ delegate :processor_id, :owner, to: :pay_charge
7
+
8
+ def initialize(pay_charge)
9
+ @pay_charge = pay_charge
10
+ end
11
+
12
+ def charge
13
+ pay_charge
14
+ end
15
+
16
+ def refund!(amount_to_refund)
17
+ pay_charge.update(amount_refunded: amount_to_refund)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,6 @@
1
+ module Pay
2
+ module FakeProcessor
3
+ class Error < Pay::Error
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,55 @@
1
+ module Pay
2
+ module FakeProcessor
3
+ class Subscription
4
+ attr_reader :pay_subscription
5
+
6
+ delegate :canceled?,
7
+ :ends_at,
8
+ :on_trial?,
9
+ :owner,
10
+ :processor_subscription,
11
+ :processor_id,
12
+ :prorate,
13
+ :processor_plan,
14
+ :quantity?,
15
+ :quantity,
16
+ to: :pay_subscription
17
+
18
+ def initialize(pay_subscription)
19
+ @pay_subscription = pay_subscription
20
+ end
21
+
22
+ def cancel
23
+ pay_subscription.update(ends_at: Time.current.end_of_month)
24
+ end
25
+
26
+ def cancel_now!
27
+ pay_subscription.update(ends_at: Time.current, status: :canceled)
28
+ end
29
+
30
+ def on_grace_period?
31
+ canceled? && Time.zone.now < ends_at
32
+ end
33
+
34
+ def paused?
35
+ false
36
+ end
37
+
38
+ def pause
39
+ raise NotImplementedError, "FakeProcessor does not support pausing subscriptions"
40
+ end
41
+
42
+ def resume
43
+ unless on_grace_period?
44
+ raise StandardError, "You can only resume subscriptions within their grace period."
45
+ end
46
+
47
+ pay_subscription.update(ends_at: nil, status: :active)
48
+ end
49
+
50
+ def swap(plan)
51
+ pay_subscription.update(processor_plan: plan)
52
+ end
53
+ end
54
+ end
55
+ end
@@ -3,8 +3,10 @@ module Pay
3
3
  class Subscription
4
4
  attr_reader :pay_subscription
5
5
 
6
- delegate :canceled?,
6
+ delegate :active?,
7
+ :canceled?,
7
8
  :ends_at,
9
+ :name,
8
10
  :on_trial?,
9
11
  :owner,
10
12
  :paddle_paused_from,
@@ -12,8 +14,10 @@ module Pay
12
14
  :processor_plan,
13
15
  :processor_subscription,
14
16
  :prorate,
17
+ :prorate?,
15
18
  :quantity,
16
19
  :quantity?,
20
+ :trial_ends_at,
17
21
  to: :pay_subscription
18
22
 
19
23
  def initialize(pay_subscription)
@@ -3,16 +3,20 @@ module Pay
3
3
  class Subscription
4
4
  attr_reader :pay_subscription
5
5
 
6
- delegate :canceled?,
6
+ delegate :active?,
7
+ :canceled?,
7
8
  :ends_at,
9
+ :name,
8
10
  :on_trial?,
9
11
  :owner,
10
- :processor_subscription,
11
12
  :processor_id,
12
- :prorate,
13
13
  :processor_plan,
14
- :quantity?,
14
+ :processor_subscription,
15
+ :prorate,
16
+ :prorate?,
15
17
  :quantity,
18
+ :quantity?,
19
+ :trial_ends_at,
16
20
  to: :pay_subscription
17
21
 
18
22
  def initialize(pay_subscription)
data/lib/pay/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pay
2
- VERSION = "2.6.3"
2
+ VERSION = "2.6.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pay
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.3
4
+ version: 2.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Charnes
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-02-23 00:00:00.000000000 Z
12
+ date: 2021-02-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -166,6 +166,11 @@ files:
166
166
  - lib/pay/engine.rb
167
167
  - lib/pay/env.rb
168
168
  - lib/pay/errors.rb
169
+ - lib/pay/fake_processor.rb
170
+ - lib/pay/fake_processor/billable.rb
171
+ - lib/pay/fake_processor/charge.rb
172
+ - lib/pay/fake_processor/error.rb
173
+ - lib/pay/fake_processor/subscription.rb
169
174
  - lib/pay/paddle.rb
170
175
  - lib/pay/paddle/billable.rb
171
176
  - lib/pay/paddle/charge.rb