pay 6.1.1 → 6.2.0

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: 17a91b33a5c76733e60014f15e285b51e77d1d4794456afba359691edc4e44c2
4
- data.tar.gz: f7b991d7a54f7fa57a54a56571f2ee4badeeb1aaaa62dc5f2cc6f889254818d3
3
+ metadata.gz: 9b9bea4dde4674321c5fcc0315db2fbd79afa882e329b6ba922aa0cc01c1a91e
4
+ data.tar.gz: 0fe8b739284c825223d0ec377407ddf2f3fef5f846a5b11e57cf80ea144de2a8
5
5
  SHA512:
6
- metadata.gz: 5ef34ddc4e6b0ba75abab2577d216a85af478fa22c0bc8a16d312b5979e782fac467204e66ac72f7fa4f9e0b4dfa16f879aad82b27251ed290e05353c48df92c
7
- data.tar.gz: e8dd4dbbdc01aa58ce21228b84a69bb70df05a814ab306b9e2b417b3e178bf50732117b73cad0f01dbb04035bbeb834f2aa2052b010c042b1d5e1f7660149188
6
+ metadata.gz: 54184916de0ec236cdfb4eef54ff62add646b7ddc1f4cb43fa150e5b7ef517f1a780603a63807c626ef41567522d765cce9a15390b728f98a2701e3b3ddd44ea
7
+ data.tar.gz: 256c12615777ed0933b41290e7f33a52e155e9be192f034ad9e95a1ae301198e1f8c3d4ceae6568e021612981b8c32de1cae80a65a15f548bc41b68c318dd4b1
@@ -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,43 @@ 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
+ ends_at: (object.updated_at if object.status == "Canceled"),
36
+ processor_plan: object.plan_id,
37
+ status: object.status.underscore,
38
+ trial_ends_at: (object.created_at + object.trial_duration.send(object.trial_duration_unit) if object.trial_period)
39
+ }
40
+
41
+ pay_subscription = pay_customer.subscriptions.find_by(processor_id: object.id)
42
+ if pay_subscription
43
+ pay_subscription.with_lock { pay_subscription.update!(attributes) }
44
+ else
45
+ name ||= Pay.default_product_name
46
+ pay_subscription = pay_customer.subscriptions.create!(attributes.merge(name: name, processor_id: object.id))
47
+ end
48
+
49
+ pay_subscription
50
+ rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotUnique
51
+ try += 1
52
+ if try <= retries
53
+ sleep 0.1
54
+ retry
55
+ else
56
+ raise
57
+ end
58
+ end
59
+
23
60
  def initialize(pay_subscription)
24
61
  @pay_subscription = pay_subscription
25
62
  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
@@ -6,8 +6,8 @@ module Pay
6
6
  locate_owner(event.data.object)
7
7
 
8
8
  if (payment_intent_id = event.data.object.payment_intent)
9
- payment_intent = ::Stripe::PaymentIntent.retrieve({id: payment_intent_id, expand: ["latest_charge"]}, {stripe_account: event.try(:account)}.compact)
10
- Pay::Stripe::Charge.sync(payment_intent.latest_charge.id, object: payment_intent.latest_charge, stripe_account: event.try(:account))
9
+ payment_intent = ::Stripe::PaymentIntent.retrieve({id: payment_intent_id}, {stripe_account: event.try(:account)}.compact)
10
+ Pay::Stripe::Charge.sync(payment_intent.latest_charge, stripe_account: event.try(:account))
11
11
  end
12
12
 
13
13
  if (subscription_id = event.data.object.subscription)
data/lib/pay/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pay
2
- VERSION = "6.1.1"
2
+ VERSION = "6.2.0"
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.1
4
+ version: 6.2.0
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-14 00:00:00.000000000 Z
12
+ date: 2022-12-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails