pay 6.1.2 → 6.2.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: 863cb9c39a6232694d37073f367ebc22f78a0fc7c4c775e9f0b9b64555fc5534
4
- data.tar.gz: 0c2bae743a6e14f8f3608e76f7d515e3411d1d417e74e7e1a1a5dc8a99ec2b07
3
+ metadata.gz: 9d8242bdc260e76f9e9c077f041ee09da8fded112a04fc89f2974976b92e7406
4
+ data.tar.gz: 87b7f3b72d0b2b1340a4403405ad3b64139e93e524d73ed5335e3e6ad3a67778
5
5
  SHA512:
6
- metadata.gz: 9af822c88226e681feb85f173a9eb15ab161926be39b08d6e4944b50db67f4b5dcf95b6fa443b3dd460b592627539cdc9769fccd82552ee36c90735201411782
7
- data.tar.gz: a81b84cc6fe417b823b7b109066b0ed39da420fe2fe611b28e87feaff7ffb084b1c2fd8b65b163317fc033911277d070f73c33edf122c00aff89031a9644d633
6
+ metadata.gz: ea09e83ce4431f9653b9c3d97a5cb2dbdde7e19cc2d38bd6e074ad01519e5d3c4ecdd1eabfbb985e05981c7d706f8ba37e5563901cf93693f9da0f0ef4afba68
7
+ data.tar.gz: 9f3500262f3bc1686f0620f7b10e69b562fb983113cd9c6213a1b75868d72b2c6aa1da27b4f15dda3a964e028d892c3e66daef029816860c79c7a2fd8863759a
@@ -108,7 +108,7 @@ module Pay
108
108
  result = gateway.subscription.create(subscription_options)
109
109
  raise Pay::Braintree::Error, result unless result.success?
110
110
 
111
- pay_customer.subscriptions.create!(
111
+ subscription = pay_customer.subscriptions.create!(
112
112
  name: name,
113
113
  processor_id: result.subscription.id,
114
114
  processor_plan: plan,
@@ -117,6 +117,12 @@ module Pay
117
117
  ends_at: nil,
118
118
  metadata: metadata
119
119
  )
120
+
121
+ if (charge = result.subscription.transactions.first)
122
+ save_transaction(charge)
123
+ end
124
+
125
+ subscription
120
126
  rescue ::Braintree::AuthorizationError => e
121
127
  raise Pay::Braintree::AuthorizationError, e
122
128
  rescue ::Braintree::BraintreeError => e
@@ -268,6 +274,7 @@ module Pay
268
274
  {
269
275
  payment_method_type: :paypal,
270
276
  brand: "PayPal",
277
+ email: transaction.paypal_details.payer_email,
271
278
  last4: transaction.paypal_details.payer_email,
272
279
  exp_month: nil,
273
280
  exp_year: nil
@@ -277,6 +284,7 @@ module Pay
277
284
  {
278
285
  payment_method_type: :venmo,
279
286
  brand: "Venmo",
287
+ username: transaction.venmo_account_details.username,
280
288
  last4: transaction.venmo_account_details.username,
281
289
  exp_month: nil,
282
290
  exp_year: nil
@@ -5,6 +5,23 @@ module Pay
5
5
 
6
6
  delegate :processor_id, to: :pay_charge
7
7
 
8
+ def self.sync(charge_id, object: nil, try: 0, retries: 1)
9
+ object ||= Pay.braintree_gateway.transaction.find(charge_id)
10
+
11
+ pay_customer = Pay::Customer.find_by(processor: :braintree, processor_id: object.customer_details.id)
12
+ return unless pay_customer
13
+
14
+ pay_customer.save_transaction(object)
15
+ rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotUnique
16
+ try += 1
17
+ if try <= retries
18
+ sleep 0.1
19
+ retry
20
+ else
21
+ raise
22
+ end
23
+ end
24
+
8
25
  def initialize(pay_charge)
9
26
  @pay_charge = pay_charge
10
27
  end
@@ -20,6 +20,48 @@ module Pay
20
20
  :trial_ends_at,
21
21
  to: :pay_subscription
22
22
 
23
+ def self.sync(subscription_id, object: nil, name: nil, try: 0, retries: 1)
24
+ object ||= Pay.braintree_gateway.subscription.find(subscription_id)
25
+
26
+ # Retrieve Pay::Customer
27
+ payment_method = Pay.braintree_gateway.payment_method.find(object.payment_method_token)
28
+ pay_customer = Pay::Customer.find_by(processor: :braintree, processor_id: payment_method.customer_id)
29
+ return unless pay_customer
30
+
31
+ attributes = {
32
+ created_at: object.created_at,
33
+ current_period_end: object.billing_period_end_date,
34
+ current_period_start: object.billing_period_start_date,
35
+ processor_plan: object.plan_id,
36
+ status: object.status.underscore,
37
+ trial_ends_at: (object.created_at + object.trial_duration.send(object.trial_duration_unit) if object.trial_period)
38
+ }
39
+
40
+ # Set ends at to paid through date
41
+ # On trial, paid through date is nil, so fallback to updated_at
42
+ if object.status == "Canceled"
43
+ attributes[:ends_at] = object.paid_through_date&.end_of_day || object.updated_at
44
+ end
45
+
46
+ pay_subscription = pay_customer.subscriptions.find_by(processor_id: object.id)
47
+ if pay_subscription
48
+ pay_subscription.with_lock { pay_subscription.update!(attributes) }
49
+ else
50
+ name ||= Pay.default_product_name
51
+ pay_subscription = pay_customer.subscriptions.create!(attributes.merge(name: name, processor_id: object.id))
52
+ end
53
+
54
+ pay_subscription
55
+ rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotUnique
56
+ try += 1
57
+ if try <= retries
58
+ sleep 0.1
59
+ retry
60
+ else
61
+ raise
62
+ end
63
+ end
64
+
23
65
  def initialize(pay_subscription)
24
66
  @pay_subscription = pay_subscription
25
67
  end
@@ -8,15 +8,7 @@ module Pay
8
8
  subscription = event.subscription
9
9
  return if subscription.nil?
10
10
 
11
- pay_subscription = Pay::Subscription.find_by_processor_and_id(:braintree, subscription.id)
12
- return unless pay_subscription.present?
13
-
14
- ends_at = Time.current
15
- pay_subscription.update!(
16
- status: :canceled,
17
- trial_ends_at: (ends_at if pay_subscription.trial_ends_at?),
18
- ends_at: ends_at
19
- )
11
+ Pay::Braintree::Subscription.sync(subscription.id)
20
12
  end
21
13
  end
22
14
  end
@@ -11,11 +11,11 @@ module Pay
11
11
  pay_subscription = Pay::Subscription.find_by_processor_and_id(:braintree, subscription.id)
12
12
  return unless pay_subscription.present?
13
13
 
14
- pay_customer = pay_subscription.customer
15
- pay_charge = Pay::Braintree::Billable.new(pay_customer).save_transaction(subscription.transactions.first)
14
+ charge = subscription.transactions.first
15
+ pay_charge = Pay::Braintree::Charge.sync(charge.id, object: charge)
16
16
 
17
17
  if pay_charge && Pay.send_email?(:receipt, pay_charge)
18
- Pay.mailer.with(pay_customer: pay_customer, pay_charge: pay_charge).receipt.deliver_later
18
+ Pay.mailer.with(pay_customer: pay_subscription.customer, pay_charge: pay_charge).receipt.deliver_later
19
19
  end
20
20
  end
21
21
  end
@@ -8,10 +8,7 @@ module Pay
8
8
  subscription = event.subscription
9
9
  return if subscription.nil?
10
10
 
11
- pay_subscription = Pay::Subscription.find_by_processor_and_id(:braintree, subscription.id)
12
- return unless pay_subscription.present?
13
-
14
- pay_subscription.update!(ends_at: Time.current, status: :canceled)
11
+ Pay::Braintree::Subscription.sync(subscription.id)
15
12
  end
16
13
  end
17
14
  end
@@ -8,10 +8,7 @@ module Pay
8
8
  subscription = event.subscription
9
9
  return if subscription.nil?
10
10
 
11
- pay_subscription = Pay::Subscription.find_by_processor_and_id(:braintree, subscription.id)
12
- return unless pay_subscription.present?
13
-
14
- pay_subscription.update!(trial_ends_at: Time.current)
11
+ Pay::Braintree::Subscription.sync(subscription.id)
15
12
  end
16
13
  end
17
14
  end
@@ -8,10 +8,7 @@ module Pay
8
8
  subscription = event.subscription
9
9
  return if subscription.nil?
10
10
 
11
- pay_subscription = Pay::Subscription.find_by_processor_and_id(:braintree, subscription.id)
12
- return unless pay_subscription.present?
13
-
14
- pay_subscription.update!(status: :active)
11
+ Pay::Braintree::Subscription.sync(subscription.id)
15
12
  end
16
13
  end
17
14
  end
@@ -8,10 +8,7 @@ module Pay
8
8
  subscription = event.subscription
9
9
  return if subscription.nil?
10
10
 
11
- pay_subscription = Pay::Subscription.find_by_processor_and_id(:braintree, subscription.id)
12
- return unless pay_subscription.present?
13
-
14
- pay_subscription.update!(status: :past_due)
11
+ Pay::Braintree::Subscription.sync(subscription.id)
15
12
  end
16
13
  end
17
14
  end
data/lib/pay/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pay
2
- VERSION = "6.1.2"
2
+ VERSION = "6.2.1"
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: 6.1.2
4
+ version: 6.2.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: 2022-12-17 00:00:00.000000000 Z
12
+ date: 2023-01-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails