pay 2.6.4 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a72ff3544c6fa85675a96d650f152b8f3593211f0c205a5a10cddca5d1f7c35
4
- data.tar.gz: b7593ef07b57654f4ee566cf2fc538b495d22a9667ec90c6695759a464968dae
3
+ metadata.gz: a8d82f8b92018a0af540a835677d44a4b364bc37472ceb2869e6f78b81cb88df
4
+ data.tar.gz: 369d7fdc1dd186a8ab6ac4c964fb3983db4f5d1bc7ab856669b65c3f4696f658
5
5
  SHA512:
6
- metadata.gz: 572f4f2989bce0a3afa7a483585e3e6f7e96f0487eb34bf5cb790a60a3b66bc0eeafa4ed48a011e00232770b565d1c592491eb613465054cf5de34bae58b168c
7
- data.tar.gz: cd5059977bd91e4c72b8c51a7f8584b23d15e7bc988ca3421400e39232b781481271a57f06777c71c83cfee73bcab03312de35734c3138e3101e2aa125e4db27
6
+ metadata.gz: afb95708b3a2e08b44f6236e1ff51268b8287691206ce8a050bea609d88555f87feb295ed14d1dfa671982a365d0a7099a7cee6cd0b191cbae60647cf1097505
7
+ data.tar.gz: 05bc21e7a17c88c1d6ecaae86afd1f36c3e90ffd0e6f200cc9c360b5d5a400dfd28ac75c361eccd9d3e6ee8d52f3862044fed40da3eebf8ff101d591d35ffe0c
data/README.md CHANGED
@@ -1,8 +1,10 @@
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
 
@@ -37,7 +39,7 @@ gem 'stripe', '< 6.0', '>= 2.8'
37
39
  gem 'braintree', '< 3.0', '>= 2.92.0'
38
40
 
39
41
  # To use Paddle, also include:
40
- gem 'paddle_pay', '~> 0.0.1'
42
+ gem 'paddle_pay', '~> 0.1'
41
43
 
42
44
  # To use Receipts
43
45
  gem 'receipts', '~> 1.0.0'
@@ -151,11 +153,12 @@ development:
151
153
  vendor_id: xxxx
152
154
  vendor_auth_code: yyyy
153
155
  public_key_base64: MII...==
156
+ environment: sandbox
154
157
  ```
155
158
 
156
159
  For Stripe, you can also use the `STRIPE_PUBLIC_KEY`, `STRIPE_PRIVATE_KEY` and `STRIPE_SIGNING_SECRET` environment variables.
157
160
  For Braintree, you can also use `BRAINTREE_MERCHANT_ID`, `BRAINTREE_PUBLIC_KEY`, `BRAINTREE_PRIVATE_KEY`, and `BRAINTREE_ENVIRONMENT` environment variables.
158
- For Paddle, you can also use `PADDLE_VENDOR_ID`, `PADDLE_VENDOR_AUTH_CODE` and `PADDLE_PUBLIC_KEY_BASE64` environment variables.
161
+ For Paddle, you can also use `PADDLE_VENDOR_ID`, `PADDLE_VENDOR_AUTH_CODE`, `PADDLE_PUBLIC_KEY_BASE64` and `PADDLE_ENVIRONMENT` environment variables.
159
162
 
160
163
  ### Generators
161
164
 
@@ -621,6 +624,7 @@ development:
621
624
  vendor_id: xxxx
622
625
  vendor_auth_code: yyyy
623
626
  public_key_base64: MII...==
627
+ environment: sandbox
624
628
  ```
625
629
 
626
630
  Paddle receipts can be retrieved by a charge receipt URL.
@@ -686,6 +690,12 @@ If you'd like to change the views of the payment confirmation page, you can inst
686
690
 
687
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)
688
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
+
689
699
  #### Background jobs
690
700
 
691
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.
@@ -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/billable.rb CHANGED
@@ -34,6 +34,7 @@ module Pay
34
34
  end
35
35
 
36
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?
37
38
  "Pay::#{name.to_s.classify}::Billable".constantize
38
39
  end
39
40
 
@@ -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
@@ -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
@@ -1,8 +1,22 @@
1
1
  module Pay
2
2
  module Braintree
3
3
  class Error < Pay::Error
4
- def message
5
- result.message
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
data/lib/pay/errors.rb CHANGED
@@ -1,10 +1,6 @@
1
1
  module Pay
2
+ # https://avdi.codes/exception-causes-in-ruby-2-1/
2
3
  class Error < StandardError
3
- attr_reader :result
4
-
5
- def initialize(result = nil)
6
- @result = result
7
- end
8
4
  end
9
5
 
10
6
  class PaymentError < StandardError
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
@@ -2,7 +2,7 @@ module Pay
2
2
  module Paddle
3
3
  class Error < Pay::Error
4
4
  def message
5
- I18n.t("errors.paddle.#{result.code}", default: result.message)
5
+ I18n.t("errors.paddle.#{cause.code}", default: cause.message)
6
6
  end
7
7
  end
8
8
  end
@@ -2,7 +2,7 @@ module Pay
2
2
  module Stripe
3
3
  class Error < Pay::Error
4
4
  def message
5
- I18n.t("errors.stripe.#{result.code}", default: result.message)
5
+ I18n.t("errors.stripe.#{cause.code}", default: cause.message)
6
6
  end
7
7
  end
8
8
  end
@@ -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
data/lib/pay/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pay
2
- VERSION = "2.6.4"
2
+ VERSION = "2.6.5"
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.4
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-02-25 00:00:00.000000000 Z
12
+ date: 2021-03-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -188,6 +188,7 @@ files:
188
188
  - lib/pay/stripe/billable.rb
189
189
  - lib/pay/stripe/charge.rb
190
190
  - lib/pay/stripe/error.rb
191
+ - lib/pay/stripe/merchant.rb
191
192
  - lib/pay/stripe/subscription.rb
192
193
  - lib/pay/stripe/webhooks/charge_refunded.rb
193
194
  - lib/pay/stripe/webhooks/charge_succeeded.rb