pay 6.1.2 → 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 +4 -4
- data/lib/pay/braintree/billable.rb +9 -1
- data/lib/pay/braintree/charge.rb +17 -0
- data/lib/pay/braintree/subscription.rb +37 -0
- data/lib/pay/braintree/webhooks/subscription_canceled.rb +1 -9
- data/lib/pay/braintree/webhooks/subscription_charged_successfully.rb +3 -3
- data/lib/pay/braintree/webhooks/subscription_expired.rb +1 -4
- data/lib/pay/braintree/webhooks/subscription_trial_ended.rb +1 -4
- data/lib/pay/braintree/webhooks/subscription_went_active.rb +1 -4
- data/lib/pay/braintree/webhooks/subscription_went_past_due.rb +1 -4
- data/lib/pay/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b9bea4dde4674321c5fcc0315db2fbd79afa882e329b6ba922aa0cc01c1a91e
|
4
|
+
data.tar.gz: 0fe8b739284c825223d0ec377407ddf2f3fef5f846a5b11e57cf80ea144de2a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/pay/braintree/charge.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
15
|
-
pay_charge = Pay::Braintree::
|
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:
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
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.
|
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-
|
12
|
+
date: 2022-12-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -220,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
220
220
|
- !ruby/object:Gem::Version
|
221
221
|
version: '0'
|
222
222
|
requirements: []
|
223
|
-
rubygems_version: 3.3.
|
223
|
+
rubygems_version: 3.3.7
|
224
224
|
signing_key:
|
225
225
|
specification_version: 4
|
226
226
|
summary: Payments engine for Ruby on Rails
|