pay 6.7.2 → 6.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1af316b3951f2b2d0844c3fcfebc005f43a42cca3f2704eb19cde32df968f787
4
- data.tar.gz: d22bc794be545843843ba97e03ac9190e3835ec61c288aeb2e14fe562be055dc
3
+ metadata.gz: bcbe66e7978f3f589514c71a54b0f7450b41b57ddcd7025ce17e93130e42e1dd
4
+ data.tar.gz: e6168b5908003c44a5bf494d93590c4eaed7e2777178e66aa3303c72e2ffea2a
5
5
  SHA512:
6
- metadata.gz: a855e7acead57687470d16476fdee052649ae15977f21e611fbf529d337551895696310fbdc7f62d9242142f737de3c4045077c4208d79aa6bb38313467003c9
7
- data.tar.gz: d9071f2afbb72357256e78997a0617d4edbc5fbb1f904fc2a9afaff3078e2f19fbe8fa6b9b39708e75b0cba27b16f9dd9778be86514f0fdaabaacf86aa105be3
6
+ metadata.gz: 3c5ed3d8be3d803c66091d647957a8dc115c298de1daa4a8f53a69aae55ff7a8df406835718feafe231437f842a1770dedadac1cf9b8ac81a9494ee31e1ccc8e
7
+ data.tar.gz: 2571ba9c847b47ad74fe3996b159bac179b553dc1bc1d673f52194fbd6a17f381a27ebace5668254f13c17dd288a6bba0d6f93d51c809d0474ac28b68f0f42b4
@@ -5,11 +5,11 @@ module Pay
5
5
  module Webhooks
6
6
  class SubscriptionChargedUnsuccessfully
7
7
  def call(event)
8
- subscription = event.subscription
9
- return if subscription.nil?
8
+ # subscription = event.subscription
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?
11
+ # pay_subscription = Pay::Subscription.find_by_processor_and_id(:braintree, subscription.id)
12
+ # return unless pay_subscription.present?
13
13
 
14
14
  # pay_customer = pay_subscription.customer
15
15
  # pay_charge = Pay::Braintree::Billable.new(pay_customer).save_transaction(subscription.transactions.first)
@@ -77,20 +77,17 @@ module Pay
77
77
  )
78
78
  end
79
79
 
80
+ # Charges an amount to the customer's default payment method
80
81
  def charge(amount, options = {})
81
82
  add_payment_method(payment_method_token, default: true) if payment_method_token?
82
83
 
83
84
  payment_method = pay_customer.default_payment_method
84
85
  args = {
85
- amount: amount,
86
86
  confirm: true,
87
- currency: "usd",
88
- customer: processor_id,
89
- expand: ["latest_charge.refunds"],
90
87
  payment_method: payment_method&.processor_id
91
88
  }.merge(options)
92
89
 
93
- payment_intent = ::Stripe::PaymentIntent.create(args, stripe_options)
90
+ payment_intent = create_payment_intent(amount, args)
94
91
  Pay::Payment.new(payment_intent).validate
95
92
 
96
93
  charge = payment_intent.latest_charge
@@ -99,6 +96,24 @@ module Pay
99
96
  raise Pay::Stripe::Error, e
100
97
  end
101
98
 
99
+ # Creates and returns a Stripe::PaymentIntent
100
+ def create_payment_intent(amount, options = {})
101
+ args = {
102
+ amount: amount,
103
+ currency: "usd",
104
+ customer: processor_id,
105
+ expand: ["latest_charge.refunds"],
106
+ return_url: root_url
107
+ }.merge(options)
108
+
109
+ ::Stripe::PaymentIntent.create(args, stripe_options)
110
+ end
111
+
112
+ # Used for creating Stripe Terminal charges
113
+ def terminal_charge(amount, options = {})
114
+ create_payment_intent(amount, options.merge(payment_method_types: ["card_present"], capture_method: "manual"))
115
+ end
116
+
102
117
  def subscribe(name: Pay.default_product_name, plan: Pay.default_plan_name, **options)
103
118
  quantity = options.delete(:quantity)
104
119
  opts = {
@@ -15,12 +15,16 @@ module Pay
15
15
  def self.sync(charge_id, object: nil, stripe_account: nil, try: 0, retries: 1)
16
16
  # Skip loading the latest charge details from the API if we already have it
17
17
  object ||= ::Stripe::Charge.retrieve({id: charge_id, expand: ["invoice.total_discount_amounts.discount", "invoice.total_tax_amounts.tax_rate", "refunds"]}, {stripe_account: stripe_account}.compact)
18
-
19
- # Ignore charges without a Customer
20
- return if object.customer.blank?
18
+ if object.customer.blank?
19
+ Rails.logger.debug "Stripe Charge #{object.id} does not have a customer"
20
+ return
21
+ end
21
22
 
22
23
  pay_customer = Pay::Customer.find_by(processor: :stripe, processor_id: object.customer)
23
- return unless pay_customer
24
+ if pay_customer.blank?
25
+ Rails.logger.debug "Pay::Customer #{object.customer} is not in the database while syncing Stripe Charge #{object.id}"
26
+ return
27
+ end
24
28
 
25
29
  refunds = []
26
30
  object.refunds.auto_paging_each { |refund| refunds << refund }
@@ -28,9 +28,16 @@ module Pay
28
28
  # Syncs PaymentMethod objects from Stripe
29
29
  def self.sync(id, object: nil, stripe_account: nil, try: 0, retries: 1)
30
30
  object ||= ::Stripe::PaymentMethod.retrieve(id, {stripe_account: stripe_account}.compact)
31
+ if object.customer.blank?
32
+ Rails.logger.debug "Stripe PaymentMethod #{object.id} does not have a customer"
33
+ return
34
+ end
31
35
 
32
36
  pay_customer = Pay::Customer.find_by(processor: :stripe, processor_id: object.customer)
33
- return unless pay_customer
37
+ if pay_customer.blank?
38
+ Rails.logger.debug "Pay::Customer #{object.customer} is not in the database while syncing Stripe PaymentMethod #{object.id}"
39
+ return
40
+ end
34
41
 
35
42
  default_payment_method_id = pay_customer.customer.invoice_settings.default_payment_method
36
43
  default = (id == default_payment_method_id)
@@ -31,9 +31,16 @@ module Pay
31
31
  def self.sync(subscription_id, object: nil, name: nil, stripe_account: nil, try: 0, retries: 1)
32
32
  # Skip loading the latest subscription details from the API if we already have it
33
33
  object ||= ::Stripe::Subscription.retrieve({id: subscription_id}.merge(expand_options), {stripe_account: stripe_account}.compact)
34
+ if object.customer.blank?
35
+ Rails.logger.debug "Stripe Subscription #{object.id} does not have a customer"
36
+ return
37
+ end
34
38
 
35
39
  pay_customer = Pay::Customer.find_by(processor: :stripe, processor_id: object.customer)
36
- return unless pay_customer
40
+ if pay_customer.blank?
41
+ Rails.logger.debug "Pay::Customer #{object.customer} is not in the database while syncing Stripe Subscription #{object.id}"
42
+ return
43
+ end
37
44
 
38
45
  attributes = {
39
46
  application_fee_percent: object.application_fee_percent,
data/lib/pay/stripe.rb CHANGED
@@ -30,6 +30,8 @@ module Pay
30
30
 
31
31
  extend Env
32
32
 
33
+ REQUIRED_VERSION = "~> 9"
34
+
33
35
  # A list of database model names that include Pay
34
36
  # Used for safely looking up models with client_reference_id
35
37
  mattr_accessor :model_names, default: Set.new
@@ -37,12 +39,12 @@ module Pay
37
39
  def self.enabled?
38
40
  return false unless Pay.enabled_processors.include?(:stripe) && defined?(::Stripe)
39
41
 
40
- Pay::Engine.version_matches?(required: "~> 8", current: ::Stripe::VERSION) || (raise "[Pay] stripe gem must be version ~> 8")
42
+ Pay::Engine.version_matches?(required: REQUIRED_VERSION, current: ::Stripe::VERSION) || (raise "[Pay] stripe gem must be version #{REQUIRED_VERSION}")
41
43
  end
42
44
 
43
45
  def self.setup
44
46
  ::Stripe.api_key = private_key
45
- ::Stripe.api_version ||= "2022-11-15"
47
+ ::Stripe.api_version ||= "2023-08-16"
46
48
 
47
49
  # Used by Stripe to identify Pay for support
48
50
  ::Stripe.set_app_info("PayRails", partner_id: "pp_partner_IqhY0UExnJYLxg", version: Pay::VERSION, url: "https://github.com/pay-rails/pay")
data/lib/pay/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pay
2
- VERSION = "6.7.2"
2
+ VERSION = "6.8.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.7.2
4
+ version: 6.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Charnes
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-08-17 00:00:00.000000000 Z
13
+ date: 2023-09-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -168,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
168
  - !ruby/object:Gem::Version
169
169
  version: '0'
170
170
  requirements: []
171
- rubygems_version: 3.4.18
171
+ rubygems_version: 3.4.19
172
172
  signing_key:
173
173
  specification_version: 4
174
174
  summary: Payments engine for Ruby on Rails