pay 3.0.0 → 3.0.1

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: 6a85b63ecf485a80f4825041bdfc4d66be639b65060c1836135422f367e0b878
4
- data.tar.gz: d43a4bf47062f27d6fcdc4771517a2d2911bb3c38298d0c66b883446a42ac8ed
3
+ metadata.gz: b07034cf63312114cc2f7b73a505672c0d23bc6cd45c2ca66f8da64f2a1b0e6b
4
+ data.tar.gz: d87d2538c18f81fed51cc8540ad00bb35d5035e0d55a12ade4d80552a0a45642
5
5
  SHA512:
6
- metadata.gz: 88701e517c153b29434b56132cc567145f5c6bce65d0e6592c3118cd700147c45616840bb246df12c6d9999940c4e44147d332af7d4857b0ea02dcd2699d0d34
7
- data.tar.gz: d57a35f69149eb0a49a9417fef01f9e3b70703bc077a3fcc7a2b7c6acb1f5f228570f695942ab75a67fd6f664baee7e6aa58ef7b16e1744b7633a4d7caec31e1
6
+ metadata.gz: 29baa34daa342750337e17206ede9bc0e94c5ec212f5f68eca67abed83da8ca62b805be97c91f164c99db940e6b415c343b3f506518d05f3b4eac9892911920e
7
+ data.tar.gz: fc921354cb86b8b150bc78f29a8efb86f438700f668273e002dbdecac6f10069604227f7cfecba2cc10beec25c6ac74f7ceba083427ce353ebce0b0cc3b0578a
data/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  Pay is a payments engine for Ruby on Rails 6.0 and higher.
10
10
 
11
- **Upgrading?** Check the [UPGRADE](UPGRADE.md) guide for required changes and/or migration when upgrading from a previous version of Pay.
11
+ ⚠️ **Upgrading?** Check the [UPGRADE](UPGRADE.md) guide for required changes and/or migration when upgrading from a previous version of Pay.
12
12
 
13
13
  ## 🧑‍💻 Tutorial
14
14
 
@@ -18,7 +18,7 @@ module Pay
18
18
  scope :with_deleted_customer, -> { joins(:customer).merge(Customer.deleted) }
19
19
 
20
20
  # Callbacks
21
- before_destroy :cancel_now!, if: :active?
21
+ before_destroy :cancel_if_active
22
22
 
23
23
  store_accessor :data, :paddle_update_url
24
24
  store_accessor :data, :paddle_cancel_url
@@ -127,5 +127,15 @@ module Pay
127
127
  def latest_payment
128
128
  processor_subscription(expand: ["latest_invoice.payment_intent"]).latest_invoice.payment_intent
129
129
  end
130
+
131
+ private
132
+
133
+ def cancel_if_active
134
+ if active?
135
+ cancel_now!
136
+ end
137
+ rescue => e
138
+ Rails.logger.info "[Pay] Unable to automatically cancel subscription `#{processor} #{id}`: #{e.message}"
139
+ end
130
140
  end
131
141
  end
@@ -160,8 +160,6 @@ module Pay
160
160
  charge
161
161
  end
162
162
 
163
- private
164
-
165
163
  def gateway
166
164
  Pay.braintree_gateway
167
165
  end
@@ -197,7 +195,14 @@ module Pay
197
195
  }
198
196
  else
199
197
  {
200
- payment_method_type: payment_method.class.name.demodulize.underscore
198
+ payment_method_type: payment_method.class.name.demodulize.underscore,
199
+ brand: payment_method.try(:card_type),
200
+ last4: payment_method.try(:last_4),
201
+ exp_month: payment_method.try(:expiration_month),
202
+ exp_year: payment_method.try(:expiration_year),
203
+ bank: payment_method.try(:bank_name),
204
+ username: payment_method.try(:username),
205
+ email: payment_method.try(:email)
201
206
  }
202
207
  end
203
208
 
@@ -5,6 +5,15 @@ module Pay
5
5
 
6
6
  delegate :customer, :processor_id, to: :pay_payment_method
7
7
 
8
+ def self.sync(id, object: nil, try: 0, retries: 1)
9
+ object ||= gateway.payment_method.find(id)
10
+
11
+ pay_customer = Pay::Customer.find_by(processor: :braintree, processor_id: object.customer_id)
12
+ return unless pay_customer
13
+
14
+ pay_customer.save_payment_method(object, default: object.default?)
15
+ end
16
+
8
17
  def initialize(pay_payment_method)
9
18
  @pay_payment_method = pay_payment_method
10
19
  end
@@ -7,6 +7,8 @@ module Pay
7
7
 
8
8
  # Paddle doesn't provide PaymentMethod IDs, so we have to lookup via the Customer
9
9
  def self.sync(pay_customer:, attributes: nil)
10
+ return unless pay_customer.subscription
11
+
10
12
  payment_method = pay_customer.default_payment_method || pay_customer.build_default_payment_method
11
13
  payment_method.processor_id ||= NanoId.generate
12
14
 
data/lib/pay/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pay
2
- VERSION = "3.0.0"
2
+ VERSION = "3.0.1"
3
3
  end
@@ -0,0 +1,20 @@
1
+ namespace :pay do
2
+ namespace :payment_methods do
3
+ desc "Sync default payment methods for Pay::Customers"
4
+ task sync_default: :environment do
5
+ Pay::Customer.find_each do |pay_customer|
6
+ puts "Syncing Pay::Customer ##{pay_customer.id}: #{pay_customer.processor.titleize} #{pay_customer.processor_id}"
7
+ case pay_customer.processor
8
+ when "braintree"
9
+ payment_method = pay_customer.customer.payment_methods.find(&:default?)
10
+ Pay::Braintree::PaymentMethod.sync(payment_method.token, object: payment_method) if payment_method
11
+ when "stripe"
12
+ payment_method_id = pay_customer.customer.invoice_settings.default_payment_method
13
+ Pay::Stripe::PaymentMethod.sync(payment_method_id) if payment_method_id
14
+ when "paddle"
15
+ Pay::Paddle::PaymentMethod.sync(pay_customer)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ 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: 3.0.0
4
+ version: 3.0.1
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-09-01 00:00:00.000000000 Z
12
+ date: 2021-09-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -202,6 +202,7 @@ files:
202
202
  - lib/pay/webhooks.rb
203
203
  - lib/pay/webhooks/delegator.rb
204
204
  - lib/pay/webhooks/process_job.rb
205
+ - lib/tasks/pay.rake
205
206
  homepage: https://github.com/pay-rails/pay
206
207
  licenses:
207
208
  - MIT