pay 2.7.1 → 2.7.2

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: a90781f9b476b2396d1ab4ea8d1a6317b46ac6289f5c4afef96dc991af035fd0
4
- data.tar.gz: 8d20e7c6edcb13eb62d5ad398c4ab12a353e3be784c7651d795efd9feeb18402
3
+ metadata.gz: 2cb954b3125acb413cdebfcf57687b4ff9f33987c0500dd72f350c293f491322
4
+ data.tar.gz: b4f9b23d452a3ab76b21902ebcad03b2c927a7e7eb17f58c9ac06d3df22232a3
5
5
  SHA512:
6
- metadata.gz: 11f281fe1df7c9eabfef2d4a0242257001115b3f7eaaa5571d73cbdacb1810891a0a57ab24a23caa01458de399093b3c82a3c251237e9d3d13f993e670f06b04
7
- data.tar.gz: 11d760da77af12107686c4e91fcbec0f7bf4aa91e99d41281f1510bedabc00406146ade7656477ffa5ee4dda4e7b07af55a9dd0ae7675d1e780e8f4f121d6cc5
6
+ metadata.gz: 60d31163be2531db82eb4eb1cd6218f83e3b88d4a2a18821f4f88f19465f9e6bf2c7215f4a3ac00348582f98b3122f3820a54bdb6d19e338d6d37e68b14e0803
7
+ data.tar.gz: 6cc782accfeea3325fb93c6c15d3044efb08de166a07c90f868fc202cbc99d6fd9eda5d07db8cb97f14edff4c1d257be6261d408deafc8d967e399b6107e1cf5
data/README.md CHANGED
@@ -74,7 +74,7 @@ To sync customer names, your `Billable` model should respond to the `first_name`
74
74
  Finally, run the migrations
75
75
 
76
76
  ```bash
77
- rake db:migrate
77
+ bin/rails db:migrate
78
78
  ```
79
79
 
80
80
  > If you run into `NoMethodError (undefined method 'stripe_customer' for #<User:0x00007fbc34b9bf20>)`, fully restart your Rails application `bin/spring stop && rails s`
@@ -134,21 +134,23 @@ Pay automatically looks up credentials for each payment provider. We recommend s
134
134
  You'll need to add your API keys to your Rails credentials. You can do this by running:
135
135
 
136
136
  ```bash
137
- rails credentials:edit --environment=development
137
+ bin/rails credentials:edit --environment=development
138
138
  ```
139
139
 
140
140
  They should be formatted like the following:
141
141
 
142
142
  ```yaml
143
143
  stripe:
144
- private_key: xxxx
145
- public_key: yyyy
146
- signing_secret: zzzz
144
+ private_key: sk_test_xxxx
145
+ public_key: pk_test_yyyy
146
+ signing_secret: whsec_zzzz
147
+
147
148
  braintree:
148
149
  private_key: xxxx
149
150
  public_key: yyyy
150
151
  merchant_id: aaaa
151
152
  environment: sandbox
153
+
152
154
  paddle:
153
155
  vendor_id: xxxx
154
156
  vendor_auth_code: yyyy
@@ -161,7 +163,9 @@ You can also nest these credentials under the Rails environment if using a share
161
163
  ```yaml
162
164
  development:
163
165
  stripe:
164
- private_key: xxxx
166
+ private_key: sk_test_xxxx
167
+ public_key: pk_test_yyyy
168
+ signing_secret: whsec_zzzz
165
169
  # ...
166
170
  ```
167
171
 
@@ -608,10 +612,18 @@ If you have a catch all route (for 404s etc) and need to control where/when the
608
612
 
609
613
  ```ruby
610
614
  # config/initializers/pay.rb
611
- config.automount_routes = false
615
+ Pay.setup do |config|
616
+ # ...
617
+
618
+ config.automount_routes = false
619
+ end
612
620
 
613
621
  # config/routes.rb
614
- mount Pay::Engine, at: '/secret-webhook-path'
622
+ Rails.application.routes.draw do
623
+ mount Pay::Engine, at: '/pay' # You can change the `at` path to feed your needs.
624
+
625
+ # Other routes here
626
+ end
615
627
  ```
616
628
 
617
629
  If you just want to modify where the engine mounts it's routes then you can change the path.
@@ -619,7 +631,11 @@ If you just want to modify where the engine mounts it's routes then you can chan
619
631
  ```ruby
620
632
  # config/initializers/pay.rb
621
633
 
622
- config.routes_path = '/secret-webhook-path'
634
+ Pay.setup do |config|
635
+ # ...
636
+
637
+ config.routes_path = '/pay'
638
+ end
623
639
  ```
624
640
 
625
641
  ## Payment Providers
@@ -1,6 +1,7 @@
1
1
  module Pay
2
2
  class ApplicationRecord < Pay.model_parent_class.constantize
3
3
  self.abstract_class = true
4
+ self.table_name_prefix = "pay_"
4
5
 
5
6
  def self.json_column?(name)
6
7
  return unless connected? && table_exists?
@@ -16,7 +16,7 @@ module Pay
16
16
  # Validations
17
17
  validates :amount, presence: true
18
18
  validates :processor, presence: true
19
- validates :processor_id, presence: true
19
+ validates :processor_id, presence: true, uniqueness: {scope: :processor, case_sensitive: false}
20
20
  validates :card_type, presence: true
21
21
 
22
22
  store_accessor :data, :paddle_receipt_url
@@ -14,7 +14,7 @@ module Pay
14
14
  # Validations
15
15
  validates :name, presence: true
16
16
  validates :processor, presence: true
17
- validates :processor_id, presence: true
17
+ validates :processor_id, presence: true, uniqueness: {scope: :processor, case_sensitive: false}
18
18
  validates :processor_plan, presence: true
19
19
  validates :quantity, presence: true
20
20
  validates :status, presence: true
@@ -0,0 +1,6 @@
1
+ class AddUniquenessToPayModels < ActiveRecord::Migration[6.1]
2
+ def change
3
+ add_index :pay_charges, [:processor, :processor_id], unique: true
4
+ add_index :pay_subscriptions, [:processor, :processor_id], unique: true
5
+ end
6
+ end
@@ -5,6 +5,7 @@ class AddPayBillableTo<%= table_name.camelize %> < ActiveRecord::Migration<%= mi
5
5
  change_table :<%= table_name %>, bulk: true do |t|
6
6
  t.string :processor
7
7
  t.string :processor_id
8
+ t.public_send(Pay::Adapter.json_column_type, :pay_data)
8
9
  t.datetime :trial_ends_at
9
10
  t.string :card_type
10
11
  t.string :card_last4
@@ -92,6 +92,8 @@ module Pay
92
92
  end
93
93
 
94
94
  def swap(plan)
95
+ raise ArgumentError, "plan must be a string" unless plan.is_a?(String)
96
+
95
97
  if on_grace_period? && processor_plan == plan
96
98
  resume
97
99
  return
@@ -52,6 +52,8 @@ module Pay
52
52
  end
53
53
 
54
54
  def swap(plan)
55
+ raise ArgumentError, "plan must be a string" unless plan.is_a?(String)
56
+
55
57
  pay_subscription.update(processor_plan: plan)
56
58
  end
57
59
  end
@@ -79,6 +79,8 @@ module Pay
79
79
  end
80
80
 
81
81
  def swap(plan)
82
+ raise ArgumentError, "plan must be a string" unless plan.is_a?(String)
83
+
82
84
  attributes = {plan_id: plan, prorate: prorate}
83
85
  attributes[:quantity] = quantity if quantity?
84
86
  PaddlePay::Subscription::User.update(processor_id, attributes)
@@ -28,17 +28,17 @@ module Pay
28
28
  # Returns Stripe::Customer
29
29
  def customer
30
30
  stripe_customer = if processor_id?
31
- ::Stripe::Customer.retrieve(processor_id, {stripe_account: stripe_account})
31
+ ::Stripe::Customer.retrieve(processor_id, stripe_options)
32
32
  else
33
- sc = ::Stripe::Customer.create({email: email, name: customer_name}, {stripe_account: stripe_account})
33
+ sc = ::Stripe::Customer.create({email: email, name: customer_name}, stripe_options)
34
34
  billable.update(processor: :stripe, processor_id: sc.id, stripe_account: stripe_account)
35
35
  sc
36
36
  end
37
37
 
38
38
  # Update the user's card on file if a token was passed in
39
39
  if card_token.present?
40
- payment_method = ::Stripe::PaymentMethod.attach(card_token, {customer: stripe_customer.id}, {stripe_account: stripe_account})
41
- stripe_customer = ::Stripe::Customer.update(stripe_customer.id, {invoice_settings: {default_payment_method: payment_method.id}}, {stripe_account: stripe_account})
40
+ payment_method = ::Stripe::PaymentMethod.attach(card_token, {customer: stripe_customer.id}, stripe_options)
41
+ stripe_customer = ::Stripe::Customer.update(stripe_customer.id, {invoice_settings: {default_payment_method: payment_method.id}}, stripe_options)
42
42
  update_card_on_file(payment_method.card)
43
43
  end
44
44
 
@@ -61,7 +61,7 @@ module Pay
61
61
  payment_method: stripe_customer.invoice_settings.default_payment_method
62
62
  }.merge(options)
63
63
 
64
- payment_intent = ::Stripe::PaymentIntent.create(args, {stripe_account: stripe_account})
64
+ payment_intent = ::Stripe::PaymentIntent.create(args, stripe_options)
65
65
  Pay::Payment.new(payment_intent).validate
66
66
 
67
67
  # Create a new charge object
@@ -89,7 +89,7 @@ module Pay
89
89
  opts[:customer] = customer.id
90
90
 
91
91
  # Create subscription on Stripe
92
- stripe_sub = ::Stripe::Subscription.create(opts, {stripe_account: stripe_account})
92
+ stripe_sub = ::Stripe::Subscription.create(opts, stripe_options)
93
93
 
94
94
  # Save Pay::Subscription
95
95
  subscription = Pay::Stripe::Subscription.sync(stripe_sub.id, object: stripe_sub, name: name)
@@ -97,10 +97,6 @@ module Pay
97
97
  # No trial, card requires SCA
98
98
  if subscription.incomplete?
99
99
  Pay::Payment.new(stripe_sub.latest_invoice.payment_intent).validate
100
-
101
- # Trial, card requires SCA
102
- elsif subscription.on_trial? && stripe_sub.pending_setup_intent
103
- Pay::Payment.new(stripe_sub.pending_setup_intent).validate
104
100
  end
105
101
 
106
102
  subscription
@@ -116,8 +112,8 @@ module Pay
116
112
 
117
113
  return true if payment_method_id == stripe_customer.invoice_settings.default_payment_method
118
114
 
119
- payment_method = ::Stripe::PaymentMethod.attach(payment_method_id, {customer: stripe_customer.id}, {stripe_account: stripe_account})
120
- ::Stripe::Customer.update(stripe_customer.id, {invoice_settings: {default_payment_method: payment_method.id}}, {stripe_account: stripe_account})
115
+ payment_method = ::Stripe::PaymentMethod.attach(payment_method_id, {customer: stripe_customer.id}, stripe_options)
116
+ ::Stripe::Customer.update(stripe_customer.id, {invoice_settings: {default_payment_method: payment_method.id}}, stripe_options)
121
117
 
122
118
  update_card_on_file(payment_method.card)
123
119
  true
@@ -126,33 +122,33 @@ module Pay
126
122
  end
127
123
 
128
124
  def update_email!
129
- ::Stripe::Customer.update(processor_id, {email: email, name: customer_name}, {stripe_account: stripe_account})
125
+ ::Stripe::Customer.update(processor_id, {email: email, name: customer_name}, stripe_options)
130
126
  end
131
127
 
132
128
  def processor_subscription(subscription_id, options = {})
133
- ::Stripe::Subscription.retrieve(options.merge(id: subscription_id), {stripe_account: stripe_account})
129
+ ::Stripe::Subscription.retrieve(options.merge(id: subscription_id), stripe_options)
134
130
  end
135
131
 
136
132
  def invoice!(options = {})
137
133
  return unless processor_id?
138
- ::Stripe::Invoice.create(options.merge(customer: processor_id), {stripe_account: stripe_account}).pay
134
+ ::Stripe::Invoice.create(options.merge(customer: processor_id), stripe_options).pay
139
135
  end
140
136
 
141
137
  def upcoming_invoice
142
- ::Stripe::Invoice.upcoming({customer: processor_id}, {stripe_account: stripe_account})
138
+ ::Stripe::Invoice.upcoming({customer: processor_id}, stripe_options)
143
139
  end
144
140
 
145
141
  # Used by webhooks when the customer or source changes
146
142
  def sync_card_from_stripe
147
143
  if (payment_method_id = customer.invoice_settings.default_payment_method)
148
- update_card_on_file ::Stripe::PaymentMethod.retrieve(payment_method_id, {stripe_account: stripe_account}).card
144
+ update_card_on_file ::Stripe::PaymentMethod.retrieve(payment_method_id, stripe_options).card
149
145
  else
150
146
  billable.update(card_type: nil, card_last4: nil)
151
147
  end
152
148
  end
153
149
 
154
150
  def create_setup_intent
155
- ::Stripe::SetupIntent.create({customer: processor_id, usage: :off_session}, {stripe_account: stripe_account})
151
+ ::Stripe::SetupIntent.create({customer: processor_id, usage: :off_session}, stripe_options)
156
152
  end
157
153
 
158
154
  def trial_end_date(stripe_sub)
@@ -172,6 +168,16 @@ module Pay
172
168
  billable.card_token = nil
173
169
  end
174
170
 
171
+ # Syncs a customer's subscriptions from Stripe to the database
172
+ def sync_subscriptions
173
+ subscriptions = ::Stripe::Subscription.list({customer: customer}, stripe_options)
174
+ subscriptions.map do |subscription|
175
+ Pay::Stripe::Subscription.sync(subscription.id)
176
+ end
177
+ rescue ::Stripe::StripeError => e
178
+ raise Pay::Stripe::Error, e
179
+ end
180
+
175
181
  # https://stripe.com/docs/api/checkout/sessions/create
176
182
  #
177
183
  # checkout(mode: "payment")
@@ -203,7 +209,7 @@ module Pay
203
209
  }
204
210
  end
205
211
 
206
- ::Stripe::Checkout::Session.create(args.merge(options), {stripe_account: stripe_account})
212
+ ::Stripe::Checkout::Session.create(args.merge(options), stripe_options)
207
213
  end
208
214
 
209
215
  # https://stripe.com/docs/api/checkout/sessions/create
@@ -230,7 +236,14 @@ module Pay
230
236
  customer: processor_id,
231
237
  return_url: options.delete(:return_url) || root_url
232
238
  }
233
- ::Stripe::BillingPortal::Session.create(args.merge(options), {stripe_account: stripe_account})
239
+ ::Stripe::BillingPortal::Session.create(args.merge(options), stripe_options)
240
+ end
241
+
242
+ private
243
+
244
+ # Options for Stripe requests
245
+ def stripe_options
246
+ {stripe_account: stripe_account}.compact
234
247
  end
235
248
  end
236
249
  end
@@ -5,8 +5,10 @@ module Pay
5
5
 
6
6
  delegate :processor_id, :owner, :stripe_account, to: :pay_charge
7
7
 
8
- def self.sync(charge_id, object: nil)
8
+ def self.sync(charge_id, object: nil, try: 0, retries: 1)
9
+ # Skip loading the latest charge details from the API if we already have it
9
10
  object ||= ::Stripe::Charge.retrieve(id: charge_id)
11
+
10
12
  owner = Pay.find_billable(processor: :stripe, processor_id: object.customer)
11
13
  return unless owner
12
14
 
@@ -29,9 +31,24 @@ module Pay
29
31
  attrs[:subscription] = Pay::Subscription.find_by(processor: :stripe, processor_id: invoice.subscription)
30
32
  end
31
33
 
32
- pay_charge = owner.charges.find_or_initialize_by(processor: :stripe, processor_id: object.id)
33
- pay_charge.update(attrs)
34
- pay_charge
34
+ # Update or create the charge
35
+ processor_details = {processor: :stripe, processor_id: object.id}
36
+ if (pay_charge = owner.charges.find_by(processor_details))
37
+ pay_charge.with_lock do
38
+ pay_charge.update!(attrs)
39
+ end
40
+ pay_charge
41
+ else
42
+ owner.charges.create!(attrs.merge(processor_details))
43
+ end
44
+ rescue ActiveRecord::RecordInvalid
45
+ try += 1
46
+ if try <= retries
47
+ sleep 0.1
48
+ retry
49
+ else
50
+ raise
51
+ end
35
52
  end
36
53
 
37
54
  def initialize(pay_charge)
@@ -39,7 +56,7 @@ module Pay
39
56
  end
40
57
 
41
58
  def charge
42
- ::Stripe::Charge.retrieve({id: processor_id, expand: ["customer", "invoice.subscription"]}, {stripe_account: stripe_account})
59
+ ::Stripe::Charge.retrieve({id: processor_id, expand: ["customer", "invoice.subscription"]}, stripe_options)
43
60
  rescue ::Stripe::StripeError => e
44
61
  raise Pay::Stripe::Error, e
45
62
  end
@@ -50,11 +67,18 @@ module Pay
50
67
  # refund!(5_00)
51
68
  # refund!(5_00, refund_application_fee: true)
52
69
  def refund!(amount_to_refund, **options)
53
- ::Stripe::Refund.create(options.merge(charge: processor_id, amount: amount_to_refund), {stripe_account: stripe_account})
70
+ ::Stripe::Refund.create(options.merge(charge: processor_id, amount: amount_to_refund), stripe_options)
54
71
  pay_charge.update(amount_refunded: amount_to_refund)
55
72
  rescue ::Stripe::StripeError => e
56
73
  raise Pay::Stripe::Error, e
57
74
  end
75
+
76
+ private
77
+
78
+ # Options for Stripe requests
79
+ def stripe_options
80
+ {stripe_account: stripe_account}.compact
81
+ end
58
82
  end
59
83
  end
60
84
  end
@@ -20,9 +20,9 @@ module Pay
20
20
  :trial_ends_at,
21
21
  to: :pay_subscription
22
22
 
23
- def self.sync(subscription_id, object: nil, name: Pay.default_product_name)
23
+ def self.sync(subscription_id, object: nil, name: Pay.default_product_name, try: 0, retries: 1)
24
24
  # Skip loading the latest subscription details from the API if we already have it
25
- object ||= ::Stripe::Subscription.retrieve(id: subscription_id, expand: ["pending_setup_intent", "latest_invoice.payment_intent"])
25
+ object ||= ::Stripe::Subscription.retrieve({id: subscription_id, expand: ["pending_setup_intent", "latest_invoice.payment_intent"]})
26
26
 
27
27
  owner = Pay.find_billable(processor: :stripe, processor_id: object.customer)
28
28
  return unless owner
@@ -37,16 +37,35 @@ module Pay
37
37
  trial_ends_at: (object.trial_end ? Time.at(object.trial_end) : nil)
38
38
  }
39
39
 
40
- # Subscriptions cancelling in the future
41
- attributes[:ends_at] = Time.at(object.current_period_end) if object.cancel_at_period_end
42
-
43
- # Fully cancelled subscription
44
- attributes[:ends_at] = Time.at(object.ended_at) if object.ended_at
40
+ attributes[:ends_at] = if object.ended_at
41
+ # Fully cancelled subscription
42
+ Time.at(object.ended_at)
43
+ elsif object.cancel_at
44
+ # subscription cancelling in the future
45
+ Time.at(object.cancel_at)
46
+ elsif object.cancel_at_period_end
47
+ # Subscriptions cancelling in the future
48
+ Time.at(object.current_period_end)
49
+ end
45
50
 
46
51
  # Update or create the subscription
47
- pay_subscription = owner.subscriptions.find_or_initialize_by(processor: :stripe, processor_id: object.id)
48
- pay_subscription.update(attributes)
49
- pay_subscription
52
+ processor_details = {processor: :stripe, processor_id: object.id}
53
+ if (pay_subscription = owner.subscriptions.find_by(processor_details))
54
+ pay_subscription.with_lock do
55
+ pay_subscription.update!(attributes)
56
+ end
57
+ pay_subscription
58
+ else
59
+ owner.subscriptions.create!(attributes.merge(processor_details))
60
+ end
61
+ rescue ActiveRecord::RecordInvalid
62
+ try += 1
63
+ if try <= retries
64
+ sleep 0.1
65
+ retry
66
+ else
67
+ raise
68
+ end
50
69
  end
51
70
 
52
71
  def initialize(pay_subscription)
@@ -58,21 +77,21 @@ module Pay
58
77
  end
59
78
 
60
79
  def cancel
61
- stripe_sub = ::Stripe::Subscription.update(processor_id, {cancel_at_period_end: true}, {stripe_account: stripe_account})
80
+ stripe_sub = ::Stripe::Subscription.update(processor_id, {cancel_at_period_end: true}, stripe_options)
62
81
  pay_subscription.update(ends_at: (on_trial? ? trial_ends_at : Time.at(stripe_sub.current_period_end)))
63
82
  rescue ::Stripe::StripeError => e
64
83
  raise Pay::Stripe::Error, e
65
84
  end
66
85
 
67
86
  def cancel_now!
68
- ::Stripe::Subscription.delete(processor_id, {stripe_account: stripe_account})
87
+ ::Stripe::Subscription.delete(processor_id, {}, stripe_options)
69
88
  pay_subscription.update(ends_at: Time.current, status: :canceled)
70
89
  rescue ::Stripe::StripeError => e
71
90
  raise Pay::Stripe::Error, e
72
91
  end
73
92
 
74
93
  def change_quantity(quantity)
75
- ::Stripe::Subscription.update(processor_id, quantity: quantity)
94
+ ::Stripe::Subscription.update(processor_id, {quantity: quantity}, stripe_options)
76
95
  rescue ::Stripe::StripeError => e
77
96
  raise Pay::Stripe::Error, e
78
97
  end
@@ -101,13 +120,15 @@ module Pay
101
120
  trial_end: (on_trial? ? trial_ends_at.to_i : "now"),
102
121
  cancel_at_period_end: false
103
122
  },
104
- {stripe_account: stripe_account}
123
+ stripe_options
105
124
  )
106
125
  rescue ::Stripe::StripeError => e
107
126
  raise Pay::Stripe::Error, e
108
127
  end
109
128
 
110
129
  def swap(plan)
130
+ raise ArgumentError, "plan must be a string" unless plan.is_a?(String)
131
+
111
132
  ::Stripe::Subscription.update(
112
133
  processor_id,
113
134
  {
@@ -117,11 +138,18 @@ module Pay
117
138
  trial_end: (on_trial? ? trial_ends_at.to_i : "now"),
118
139
  quantity: quantity
119
140
  },
120
- {stripe_account: stripe_account}
141
+ stripe_options
121
142
  )
122
143
  rescue ::Stripe::StripeError => e
123
144
  raise Pay::Stripe::Error, e
124
145
  end
146
+
147
+ private
148
+
149
+ # Options for Stripe requests
150
+ def stripe_options
151
+ {stripe_account: stripe_account}.compact
152
+ end
125
153
  end
126
154
  end
127
155
  end
@@ -0,0 +1,17 @@
1
+ module Pay
2
+ module Stripe
3
+ module Webhooks
4
+ class PaymentMethodAttached
5
+ def call(event)
6
+ object = event.data.object
7
+ pay_customer = Pay::Customer.find_by(processor: :stripe, processor_id: object.customer)
8
+
9
+ # Couldn't find user, we can skip
10
+ return unless pay_customer.present?
11
+
12
+ Pay::Stripe::Billable.new(pay_customer).sync_payment_method(payment_method_id: object.id)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Pay
2
+ module Stripe
3
+ module Webhooks
4
+ class PaymentMethodAutomaticallyUpdated
5
+ def call(event)
6
+ object = event.data.object
7
+ pay_customer = Pay::Customer.find_by(processor: :stripe, processor_id: object.customer)
8
+
9
+ # Couldn't find user, we can skip
10
+ return unless pay_customer.present?
11
+
12
+ Pay::Stripe::Billable.new(pay_customer).sync_payment_method(payment_method_id: object.id)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Pay
2
+ module Stripe
3
+ module Webhooks
4
+ class PaymentMethodDetached
5
+ def call(event)
6
+ object = event.data.object
7
+ pay_customer = Pay::Customer.find_by(processor: :stripe, processor_id: object.customer)
8
+
9
+ # Couldn't find user, we can skip
10
+ return unless pay_customer.present?
11
+
12
+ Pay::Stripe::Billable.new(pay_customer).sync_payment_method(payment_method_id: object.id)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
data/lib/pay/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pay
2
- VERSION = "2.7.1"
2
+ VERSION = "2.7.2"
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.7.1
4
+ version: 2.7.2
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-06-22 00:00:00.000000000 Z
12
+ date: 2021-08-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -125,7 +125,6 @@ files:
125
125
  - app/jobs/pay/email_sync_job.rb
126
126
  - app/mailers/pay/application_mailer.rb
127
127
  - app/mailers/pay/user_mailer.rb
128
- - app/models/pay.rb
129
128
  - app/models/pay/application_record.rb
130
129
  - app/models/pay/charge.rb
131
130
  - app/models/pay/subscription.rb
@@ -145,6 +144,7 @@ files:
145
144
  - db/migrate/20210309004259_add_data_to_pay_billable.rb
146
145
  - db/migrate/20210406215234_add_currency_to_pay_charges.rb
147
146
  - db/migrate/20210406215506_add_application_fee_to_pay_models.rb
147
+ - db/migrate/20210714175351_add_uniqueness_to_pay_models.rb
148
148
  - lib/generators/active_record/billable_generator.rb
149
149
  - lib/generators/active_record/merchant_generator.rb
150
150
  - lib/generators/active_record/templates/billable_migration.rb
@@ -208,6 +208,9 @@ files:
208
208
  - lib/pay/stripe/webhooks/customer_updated.rb
209
209
  - lib/pay/stripe/webhooks/payment_action_required.rb
210
210
  - lib/pay/stripe/webhooks/payment_intent_succeeded.rb
211
+ - lib/pay/stripe/webhooks/payment_method_attached.rb
212
+ - lib/pay/stripe/webhooks/payment_method_automatically_updated.rb
213
+ - lib/pay/stripe/webhooks/payment_method_detached.rb
211
214
  - lib/pay/stripe/webhooks/payment_method_updated.rb
212
215
  - lib/pay/stripe/webhooks/subscription_created.rb
213
216
  - lib/pay/stripe/webhooks/subscription_deleted.rb
data/app/models/pay.rb DELETED
@@ -1,5 +0,0 @@
1
- module Pay
2
- def self.table_name_prefix
3
- "pay_"
4
- end
5
- end