pay 2.6.0 → 2.6.5
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 +4 -4
- data/README.md +24 -6
- data/app/models/pay/charge.rb +1 -13
- data/app/models/pay/subscription.rb +1 -1
- data/lib/pay.rb +1 -0
- data/lib/pay/billable.rb +13 -1
- data/lib/pay/braintree/billable.rb +10 -8
- data/lib/pay/braintree/charge.rb +0 -1
- data/lib/pay/braintree/error.rb +16 -2
- data/lib/pay/braintree/subscription.rb +3 -3
- data/lib/pay/errors.rb +1 -5
- data/lib/pay/fake_processor.rb +8 -0
- data/lib/pay/fake_processor/billable.rb +60 -0
- data/lib/pay/fake_processor/charge.rb +21 -0
- data/lib/pay/fake_processor/error.rb +6 -0
- data/lib/pay/fake_processor/subscription.rb +55 -0
- data/lib/pay/paddle.rb +5 -0
- data/lib/pay/paddle/error.rb +1 -1
- data/lib/pay/paddle/subscription.rb +5 -1
- data/lib/pay/stripe/billable.rb +10 -1
- data/lib/pay/stripe/error.rb +1 -1
- data/lib/pay/stripe/merchant.rb +28 -0
- data/lib/pay/stripe/subscription.rb +8 -4
- data/lib/pay/stripe/webhooks/customer_updated.rb +1 -1
- data/lib/pay/stripe/webhooks/payment_method_updated.rb +1 -1
- data/lib/pay/version.rb +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8d82f8b92018a0af540a835677d44a4b364bc37472ceb2869e6f78b81cb88df
|
4
|
+
data.tar.gz: 369d7fdc1dd186a8ab6ac4c964fb3983db4f5d1bc7ab856669b65c3f4696f658
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afb95708b3a2e08b44f6236e1ff51268b8287691206ce8a050bea609d88555f87feb295ed14d1dfa671982a365d0a7099a7cee6cd0b191cbae60647cf1097505
|
7
|
+
data.tar.gz: 05bc21e7a17c88c1d6ecaae86afd1f36c3e90ffd0e6f200cc9c360b5d5a400dfd28ac75c361eccd9d3e6ee8d52f3862044fed40da3eebf8ff101d591d35ffe0c
|
data/README.md
CHANGED
@@ -1,16 +1,19 @@
|
|
1
|
-
<p align="center"><img src="docs/logo.svg" height="50px"></p>
|
1
|
+
<p align="center"><img src="docs/images/logo.svg" height="50px"></p>
|
2
2
|
|
3
3
|
## Pay - Payments engine for Ruby on Rails
|
4
4
|
|
5
|
-
[![Build Status](https://github.com/pay-rails/pay/workflows/Tests/badge.svg)](https://github.com/pay-rails/pay/actions) [![Gem Version](https://badge.fury.io/rb/pay.svg)](https://badge.fury.io/rb/pay)
|
5
|
+
[![Build Status](https://github.com/pay-rails/pay/workflows/Tests/badge.svg)](https://github.com/pay-rails/pay/actions) [![Gem Version](https://badge.fury.io/rb/pay.svg)](https://badge.fury.io/rb/pay)
|
6
|
+
|
7
|
+
<img src="docs/images/stripe_partner_badge.svg" height="26px">
|
6
8
|
|
7
9
|
Pay is a payments engine for Ruby on Rails 4.2 and higher.
|
8
10
|
|
9
11
|
**Current Payment Providers**
|
10
12
|
|
11
|
-
- Stripe ([
|
13
|
+
- Stripe ([SCA Compatible](https://stripe.com/docs/strong-customer-authentication) using API version `2020-08-27`)
|
14
|
+
- Paddle (SCA Compatible & supports PayPal)
|
12
15
|
- Braintree (supports PayPal)
|
13
|
-
-
|
16
|
+
- [Fake Processor](docs/fake_processor.md)
|
14
17
|
|
15
18
|
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
19
|
|
@@ -36,7 +39,7 @@ gem 'stripe', '< 6.0', '>= 2.8'
|
|
36
39
|
gem 'braintree', '< 3.0', '>= 2.92.0'
|
37
40
|
|
38
41
|
# To use Paddle, also include:
|
39
|
-
gem 'paddle_pay', '~> 0.
|
42
|
+
gem 'paddle_pay', '~> 0.1'
|
40
43
|
|
41
44
|
# To use Receipts
|
42
45
|
gem 'receipts', '~> 1.0.0'
|
@@ -48,6 +51,13 @@ And then execute:
|
|
48
51
|
bundle
|
49
52
|
```
|
50
53
|
|
54
|
+
Make sure you've configured your ActionMailer default_url_options so Pay can generate links to for features like Stripe Checkout.
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
# config/application.rb
|
58
|
+
config.action_mailer.default_url_options = { host: "example.com" }
|
59
|
+
```
|
60
|
+
|
51
61
|
#### Migrations
|
52
62
|
|
53
63
|
To add the migrations to your application, run the following migration:
|
@@ -143,11 +153,12 @@ development:
|
|
143
153
|
vendor_id: xxxx
|
144
154
|
vendor_auth_code: yyyy
|
145
155
|
public_key_base64: MII...==
|
156
|
+
environment: sandbox
|
146
157
|
```
|
147
158
|
|
148
159
|
For Stripe, you can also use the `STRIPE_PUBLIC_KEY`, `STRIPE_PRIVATE_KEY` and `STRIPE_SIGNING_SECRET` environment variables.
|
149
160
|
For Braintree, you can also use `BRAINTREE_MERCHANT_ID`, `BRAINTREE_PUBLIC_KEY`, `BRAINTREE_PRIVATE_KEY`, and `BRAINTREE_ENVIRONMENT` environment variables.
|
150
|
-
For Paddle, you can also use `PADDLE_VENDOR_ID`, `PADDLE_VENDOR_AUTH_CODE` and `
|
161
|
+
For Paddle, you can also use `PADDLE_VENDOR_ID`, `PADDLE_VENDOR_AUTH_CODE`, `PADDLE_PUBLIC_KEY_BASE64` and `PADDLE_ENVIRONMENT` environment variables.
|
151
162
|
|
152
163
|
### Generators
|
153
164
|
|
@@ -613,6 +624,7 @@ development:
|
|
613
624
|
vendor_id: xxxx
|
614
625
|
vendor_auth_code: yyyy
|
615
626
|
public_key_base64: MII...==
|
627
|
+
environment: sandbox
|
616
628
|
```
|
617
629
|
|
618
630
|
Paddle receipts can be retrieved by a charge receipt URL.
|
@@ -678,6 +690,12 @@ If you'd like to change the views of the payment confirmation page, you can inst
|
|
678
690
|
|
679
691
|
[<img src="https://d1jfzjx68gj8xs.cloudfront.net/items/2s3Z0J3Z3b1J1v2K2O1a/Screen%20Shot%202019-10-10%20at%2012.56.32%20PM.png?X-CloudApp-Visitor-Id=51470" alt="Stripe SCA Payment Confirmation" style="zoom: 25%;" />](https://d1jfzjx68gj8xs.cloudfront.net/items/2s3Z0J3Z3b1J1v2K2O1a/Screen%20Shot%202019-10-10%20at%2012.56.32%20PM.png)
|
680
692
|
|
693
|
+
If you use the default views for payment confirmations, and also have a Content Security Policy in place for your application, make sure to add the following domains to their respective configurations in your `content_security_policy.rb` (otherwise these views won't load properly):
|
694
|
+
|
695
|
+
* `style_src`: `https://unpkg.com`
|
696
|
+
* `script_src`: `https://cdn.jsdelivr.net` and `https://js.stripe.com`
|
697
|
+
* `frame_src`: `https://js.stripe.com`
|
698
|
+
|
681
699
|
#### Background jobs
|
682
700
|
|
683
701
|
If a user's email is updated and they have a `processor_id` set, Pay will enqueue a background job (EmailSyncJob) to sync the email with the payment processor.
|
data/app/models/pay/charge.rb
CHANGED
@@ -21,7 +21,7 @@ module Pay
|
|
21
21
|
store_accessor :data, :paddle_receipt_url
|
22
22
|
|
23
23
|
# Helpers for payment processors
|
24
|
-
%w[braintree stripe paddle].each do |processor_name|
|
24
|
+
%w[braintree stripe paddle fake_processor].each do |processor_name|
|
25
25
|
define_method "#{processor_name}?" do
|
26
26
|
processor == processor_name
|
27
27
|
end
|
@@ -50,20 +50,8 @@ module Pay
|
|
50
50
|
"#{card_type} (**** **** **** #{card_last4})"
|
51
51
|
end
|
52
52
|
|
53
|
-
def stripe?
|
54
|
-
processor == "stripe"
|
55
|
-
end
|
56
|
-
|
57
|
-
def braintree?
|
58
|
-
processor == "braintree"
|
59
|
-
end
|
60
|
-
|
61
53
|
def paypal?
|
62
54
|
braintree? && card_type == "PayPal"
|
63
55
|
end
|
64
|
-
|
65
|
-
def paddle?
|
66
|
-
processor == "paddle"
|
67
|
-
end
|
68
56
|
end
|
69
57
|
end
|
@@ -35,7 +35,7 @@ module Pay
|
|
35
35
|
attribute :prorate, :boolean, default: true
|
36
36
|
|
37
37
|
# Helpers for payment processors
|
38
|
-
%w[braintree stripe paddle].each do |processor_name|
|
38
|
+
%w[braintree stripe paddle fake_processor].each do |processor_name|
|
39
39
|
define_method "#{processor_name}?" do
|
40
40
|
processor == processor_name
|
41
41
|
end
|
data/lib/pay.rb
CHANGED
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
|
@@ -31,6 +34,7 @@ module Pay
|
|
31
34
|
end
|
32
35
|
|
33
36
|
def payment_processor_for(name)
|
37
|
+
raise Error, "No payment processor set. Assign a payment processor with 'object.processor = :stripe' or any supported processor." if name.blank?
|
34
38
|
"Pay::#{name.to_s.classify}::Billable".constantize
|
35
39
|
end
|
36
40
|
|
@@ -42,7 +46,7 @@ module Pay
|
|
42
46
|
end
|
43
47
|
|
44
48
|
def processor
|
45
|
-
super
|
49
|
+
super&.inquiry
|
46
50
|
end
|
47
51
|
|
48
52
|
delegate :charge, to: :payment_processor
|
@@ -112,10 +116,12 @@ module Pay
|
|
112
116
|
end
|
113
117
|
|
114
118
|
def stripe?
|
119
|
+
ActiveSupport::Deprecation.warn("This will be removed in the next release. Use `@billable.processor.stripe?` instead.")
|
115
120
|
processor == "stripe"
|
116
121
|
end
|
117
122
|
|
118
123
|
def braintree?
|
124
|
+
ActiveSupport::Deprecation.warn("This will be removed in the next release. Use `@billable.processor.braintree?` instead.")
|
119
125
|
processor == "braintree"
|
120
126
|
end
|
121
127
|
|
@@ -124,6 +130,7 @@ module Pay
|
|
124
130
|
end
|
125
131
|
|
126
132
|
def paddle?
|
133
|
+
ActiveSupport::Deprecation.warn("This will be removed in the next release. Use `@billable.processor.paddle?` instead.")
|
127
134
|
processor == "paddle"
|
128
135
|
end
|
129
136
|
|
@@ -152,5 +159,10 @@ module Pay
|
|
152
159
|
# Generic trials don't have plans or custom names
|
153
160
|
plan.nil? && name == "default" && on_generic_trial?
|
154
161
|
end
|
162
|
+
|
163
|
+
def pay_fake_processor_is_allowed
|
164
|
+
return unless processor == "fake_processor"
|
165
|
+
errors.add(:processor, "must be a valid payment processor") unless pay_fake_processor_allowed?
|
166
|
+
end
|
155
167
|
end
|
156
168
|
end
|
@@ -37,8 +37,8 @@ module Pay
|
|
37
37
|
|
38
38
|
result.customer
|
39
39
|
end
|
40
|
-
rescue ::Braintree::AuthorizationError
|
41
|
-
raise Pay::Braintree::AuthorizationError
|
40
|
+
rescue ::Braintree::AuthorizationError => e
|
41
|
+
raise Pay::Braintree::AuthorizationError, e
|
42
42
|
rescue ::Braintree::BraintreeError => e
|
43
43
|
raise Pay::Braintree::Error, e
|
44
44
|
end
|
@@ -57,8 +57,8 @@ module Pay
|
|
57
57
|
raise Pay::Braintree::Error, result unless result.success?
|
58
58
|
|
59
59
|
save_transaction(result.transaction)
|
60
|
-
rescue ::Braintree::AuthorizationError
|
61
|
-
raise Pay::Braintree::AuthorizationError
|
60
|
+
rescue ::Braintree::AuthorizationError => e
|
61
|
+
raise Pay::Braintree::AuthorizationError, e
|
62
62
|
rescue ::Braintree::BraintreeError => e
|
63
63
|
raise Pay::Braintree::Error, e
|
64
64
|
end
|
@@ -84,8 +84,8 @@ module Pay
|
|
84
84
|
raise Pay::Braintree::Error, result unless result.success?
|
85
85
|
|
86
86
|
billable.create_pay_subscription(result.subscription, "braintree", name, plan, status: :active)
|
87
|
-
rescue ::Braintree::AuthorizationError
|
88
|
-
raise Pay::Braintree::AuthorizationError
|
87
|
+
rescue ::Braintree::AuthorizationError => e
|
88
|
+
raise Pay::Braintree::AuthorizationError, e
|
89
89
|
rescue ::Braintree::BraintreeError => e
|
90
90
|
raise Pay::Braintree::Error, e
|
91
91
|
end
|
@@ -94,6 +94,8 @@ module Pay
|
|
94
94
|
#
|
95
95
|
# Returns true if successful
|
96
96
|
def update_card(token)
|
97
|
+
customer unless processor_id?
|
98
|
+
|
97
99
|
result = gateway.payment_method.create(
|
98
100
|
customer_id: processor_id,
|
99
101
|
payment_method_nonce: token,
|
@@ -107,8 +109,8 @@ module Pay
|
|
107
109
|
update_card_on_file result.payment_method
|
108
110
|
update_subscriptions_to_payment_method(result.payment_method.token)
|
109
111
|
true
|
110
|
-
rescue ::Braintree::AuthorizationError
|
111
|
-
raise Pay::Braintree::AuthorizationError
|
112
|
+
rescue ::Braintree::AuthorizationError => e
|
113
|
+
raise Pay::Braintree::AuthorizationError, e
|
112
114
|
rescue ::Braintree::BraintreeError => e
|
113
115
|
raise Pay::Braintree::Error, e
|
114
116
|
end
|
data/lib/pay/braintree/charge.rb
CHANGED
@@ -17,7 +17,6 @@ module Pay
|
|
17
17
|
|
18
18
|
def refund!(amount_to_refund)
|
19
19
|
Pay.braintree_gateway.transaction.refund(processor_id, amount_to_refund / 100.0)
|
20
|
-
|
21
20
|
pay_charge.update(amount_refunded: amount_to_refund)
|
22
21
|
rescue ::Braintree::BraintreeError => e
|
23
22
|
raise Pay::Braintree::Error, e
|
data/lib/pay/braintree/error.rb
CHANGED
@@ -1,8 +1,22 @@
|
|
1
1
|
module Pay
|
2
2
|
module Braintree
|
3
3
|
class Error < Pay::Error
|
4
|
-
|
5
|
-
|
4
|
+
# For any manually raised Braintree error results (for failure responses)
|
5
|
+
# we can raise this exception manually but treat it as if we wrapped an exception
|
6
|
+
|
7
|
+
attr_reader :result
|
8
|
+
|
9
|
+
def initialize(result)
|
10
|
+
if result.is_a?(::Braintree::ErrorResult)
|
11
|
+
super(result.message)
|
12
|
+
@result = result
|
13
|
+
else
|
14
|
+
super
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def cause
|
19
|
+
super || result
|
6
20
|
end
|
7
21
|
end
|
8
22
|
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
|
|
data/lib/pay/errors.rb
CHANGED
@@ -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,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
|
data/lib/pay/paddle.rb
CHANGED
@@ -19,6 +19,7 @@ module Pay
|
|
19
19
|
def self.setup
|
20
20
|
::PaddlePay.config.vendor_id = vendor_id
|
21
21
|
::PaddlePay.config.vendor_auth_code = vendor_auth_code
|
22
|
+
::PaddlePay.config.environment = environment
|
22
23
|
|
23
24
|
configure_webhooks
|
24
25
|
end
|
@@ -31,6 +32,10 @@ module Pay
|
|
31
32
|
find_value_by_name(:paddle, :vendor_auth_code)
|
32
33
|
end
|
33
34
|
|
35
|
+
def self.environment
|
36
|
+
find_value_by_name(:paddle, :environment) || "production"
|
37
|
+
end
|
38
|
+
|
34
39
|
def self.public_key_base64
|
35
40
|
find_value_by_name(:paddle, :public_key_base64)
|
36
41
|
end
|
data/lib/pay/paddle/error.rb
CHANGED
@@ -3,8 +3,10 @@ module Pay
|
|
3
3
|
class Subscription
|
4
4
|
attr_reader :pay_subscription
|
5
5
|
|
6
|
-
delegate :
|
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)
|
data/lib/pay/stripe/billable.rb
CHANGED
@@ -14,7 +14,7 @@ module Pay
|
|
14
14
|
|
15
15
|
class << self
|
16
16
|
def default_url_options
|
17
|
-
Rails.application.config.action_mailer.default_url_options
|
17
|
+
Rails.application.config.action_mailer.default_url_options || {}
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -194,6 +194,7 @@ module Pay
|
|
194
194
|
#
|
195
195
|
def checkout(**options)
|
196
196
|
args = {
|
197
|
+
customer: processor_id,
|
197
198
|
payment_method_types: ["card"],
|
198
199
|
mode: "payment",
|
199
200
|
# These placeholder URLs will be replaced in a following step.
|
@@ -232,6 +233,14 @@ module Pay
|
|
232
233
|
**options
|
233
234
|
)
|
234
235
|
end
|
236
|
+
|
237
|
+
def billing_portal(**options)
|
238
|
+
args = {
|
239
|
+
customer: processor_id,
|
240
|
+
return_url: options[:return_url] || root_url
|
241
|
+
}
|
242
|
+
::Stripe::BillingPortal::Session.create(args.merge(options))
|
243
|
+
end
|
235
244
|
end
|
236
245
|
end
|
237
246
|
end
|
data/lib/pay/stripe/error.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
module Pay
|
2
|
+
module Stripe
|
3
|
+
module Merchant
|
4
|
+
included do
|
5
|
+
store_accessor :stripe_connect_account_id
|
6
|
+
end
|
7
|
+
|
8
|
+
def create_account(**options)
|
9
|
+
defaults = {
|
10
|
+
type: "standard"
|
11
|
+
}
|
12
|
+
|
13
|
+
stripe_account = ::Stripe::Account.create(defaults.merge(options))
|
14
|
+
update(stripe_connect_account_id: stripe_account.id)
|
15
|
+
stripe_account
|
16
|
+
end
|
17
|
+
|
18
|
+
def account_link(refresh_url:, return_url:, type: "account_onboarding", **options)
|
19
|
+
Stripe::AccountLink.create({
|
20
|
+
account: stripe_connect_account_id,
|
21
|
+
refresh_url: refresh_url,
|
22
|
+
return_url: return_url,
|
23
|
+
type: type,
|
24
|
+
})
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -3,16 +3,20 @@ module Pay
|
|
3
3
|
class Subscription
|
4
4
|
attr_reader :pay_subscription
|
5
5
|
|
6
|
-
delegate :
|
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
|
-
:
|
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
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.
|
4
|
+
version: 2.6.5
|
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-
|
12
|
+
date: 2021-03-30 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
|
@@ -183,6 +188,7 @@ files:
|
|
183
188
|
- lib/pay/stripe/billable.rb
|
184
189
|
- lib/pay/stripe/charge.rb
|
185
190
|
- lib/pay/stripe/error.rb
|
191
|
+
- lib/pay/stripe/merchant.rb
|
186
192
|
- lib/pay/stripe/subscription.rb
|
187
193
|
- lib/pay/stripe/webhooks/charge_refunded.rb
|
188
194
|
- lib/pay/stripe/webhooks/charge_succeeded.rb
|