pay 3.0.20 → 3.0.24

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: fc336f11aa6bdd63887622dd48fbec5a3f52b440b41a73d63478a0239d4c787a
4
- data.tar.gz: 31e98a7bbe5a0c9ba92201964aab99b3a3743cc42f15eac275f6032a9f52293f
3
+ metadata.gz: 5b3ebc48aeb54c0c71ccb8570c00ca5194258982fc06f00a51e2b49211dd82f0
4
+ data.tar.gz: f13ea4e812837ce733f797b9165ad798a0920e80e95b201a26a83c12c5c91f1f
5
5
  SHA512:
6
- metadata.gz: 194be2c0276670440ff121b00048eedba5f91f1a85b53be9bd0145f5147f78d14ab739e57ae90590f6a751c5b3f2013e139650201bfe2b19d455b28c40c896dc
7
- data.tar.gz: 9cc1c6d63c0360ccd54b2ee0143b933b292279016618e7e3130b97c150c64350756d7663682f1235f86d7a4983c971def19a7fef13d8148124040b1fccf39c63
6
+ metadata.gz: 44a72ba1d1c77004f2e98a20a0a6014030614be04027b6f2341d58523af3fb686bcef8ebdbde9233f52fc65c7578863430b60e2a0a73feadcf79d95043a94c38
7
+ data.tar.gz: acf91b1679dabc86e8199a28b5fd87a72a18362c8436dac3fc3318b624896bbce92b6936f8694250e4a46ca84c03defe3209e1d074273abae87fe96fcef4b448
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # 💳 Pay - Payments engine for Ruby on Rails
4
4
 
5
- [![Build Status](https://github.com/pay-rails/pay/workflows/Tests/badge.svg)](https://github.com/pay-rails/pay/actions) [![Gem Version](https://badge.fury.io/rb/pay.svg)](https://badge.fury.io/rb/pay)
5
+ [![Build Status](https://github.com/pay-rails/pay/workflows/Tests/badge.svg)](https://github.com/pay-rails/pay/actions) [![Gem Version](https://badge.fury.io/rb/pay.svg)](https://badge.fury.io/rb/pay) [![Tuple](https://img.shields.io/badge/Pairing%20with-Tuple-5A67D8)](https://tuple.app)
6
6
 
7
7
  <img src="docs/images/stripe_partner_badge.svg" height="26px">
8
8
 
@@ -49,7 +49,7 @@ Want to add a new payment provider? Contributions are welcome.
49
49
  * **Marketplaces**
50
50
  * [Stripe Connect](docs/marketplaces/stripe_connect.md)
51
51
  * **Contributing**
52
- * [Adding A Payment Processor](docs/contributing/8_adding_a_payment_processor.md)
52
+ * [Adding A Payment Processor](docs/contributing/adding_a_payment_processor.md)
53
53
 
54
54
  ## 🙏 Contributing
55
55
 
@@ -5,7 +5,7 @@ module Pay
5
5
  def perform(pay_customer_id)
6
6
  Pay::Customer.find(pay_customer_id).update_customer!
7
7
  rescue ActiveRecord::RecordNotFound
8
- Rails.logger.info "Couldn't find a #{class_name} with ID = #{id}"
8
+ Rails.logger.info "Couldn't find a Pay::Customer with ID = #{pay_customer_id}"
9
9
  end
10
10
  end
11
11
  end
@@ -66,7 +66,7 @@
66
66
  <script type="module">
67
67
  window.stripe = Stripe('<%= Pay::Stripe.public_key %>');
68
68
 
69
- import { Application, Controller } from 'https://cdn.skypack.dev/stimulus'
69
+ import { Application, Controller } from 'https://cdn.skypack.dev/@hotwired/stimulus'
70
70
  const application = Application.start()
71
71
 
72
72
  application.register('payment-intent', class extends Controller {
@@ -30,7 +30,8 @@ module Pay
30
30
 
31
31
  customer
32
32
  else
33
- result = gateway.customer.create(email: email, first_name: try(:first_name), last_name: try(:last_name), payment_method_nonce: payment_method_token)
33
+ first_name, last_name = customer_name.split(" ", 2)
34
+ result = gateway.customer.create(email: email, first_name: first_name, last_name: last_name, payment_method_nonce: payment_method_token)
34
35
  raise Pay::Braintree::Error, result unless result.success?
35
36
  pay_customer.update!(processor_id: result.customer.id)
36
37
 
@@ -47,6 +48,13 @@ module Pay
47
48
  raise Pay::Braintree::Error, e
48
49
  end
49
50
 
51
+ # Syncs name and email to Braintree::Customer
52
+ def update_customer!
53
+ return unless processor_id?
54
+ first_name, last_name = customer_name.split(" ", 2)
55
+ gateway.customer.update(processor_id, first_name: first_name, last_name: last_name, email: email)
56
+ end
57
+
50
58
  def charge(amount, options = {})
51
59
  args = {
52
60
  amount: amount.to_i / 100.0,
@@ -19,6 +19,10 @@ module Pay
19
19
  pay_customer
20
20
  end
21
21
 
22
+ def update_customer!
23
+ # pass
24
+ end
25
+
22
26
  def charge(amount, options = {})
23
27
  # Make to generate a processor_id
24
28
  customer
@@ -27,8 +31,8 @@ module Pay
27
31
  processor_id: NanoId.generate,
28
32
  amount: amount,
29
33
  data: {
30
- kind: :card,
31
- type: :fake,
34
+ payment_method_type: :card,
35
+ brand: "Fake",
32
36
  last4: 1234,
33
37
  exp_month: Date.today.month,
34
38
  exp_year: Date.today.year
@@ -40,7 +44,6 @@ module Pay
40
44
  def subscribe(name: Pay.default_product_name, plan: Pay.default_plan_name, **options)
41
45
  # Make to generate a processor_id
42
46
  customer
43
-
44
47
  attributes = options.merge(
45
48
  processor_id: NanoId.generate,
46
49
  name: name,
@@ -48,6 +51,11 @@ module Pay
48
51
  status: :active,
49
52
  quantity: options.fetch(:quantity, 1)
50
53
  )
54
+
55
+ if (trial_period_days = attributes.delete(:trial_period_days))
56
+ attributes[:trial_ends_at] = trial_period_days.to_i.days.from_now
57
+ end
58
+
51
59
  pay_customer.subscriptions.create!(attributes)
52
60
  end
53
61
 
@@ -55,10 +63,10 @@ module Pay
55
63
  # Make to generate a processor_id
56
64
  customer
57
65
 
58
- pay_customer.payment_methods.create!(
66
+ pay_payment_method = pay_customer.payment_methods.create!(
59
67
  processor_id: NanoId.generate,
60
68
  default: default,
61
- type: :fake,
69
+ type: :card,
62
70
  data: {
63
71
  brand: "Fake",
64
72
  last4: 1234,
@@ -66,6 +74,9 @@ module Pay
66
74
  exp_year: Date.today.year
67
75
  }
68
76
  )
77
+
78
+ pay_customer.reload_default_payment_method if default
79
+ pay_payment_method
69
80
  end
70
81
 
71
82
  def update_email!
@@ -57,6 +57,9 @@ module Pay
57
57
 
58
58
  def swap(plan)
59
59
  end
60
+
61
+ def change_quantity(quantity)
62
+ end
60
63
  end
61
64
  end
62
65
  end
@@ -18,6 +18,10 @@ module Pay
18
18
  # pass
19
19
  end
20
20
 
21
+ def update_customer!
22
+ # pass
23
+ end
24
+
21
25
  def charge(amount, options = {})
22
26
  subscription = pay_customer.subscription
23
27
  return unless subscription.processor_id
@@ -44,6 +44,12 @@ module Pay
44
44
  raise Pay::Stripe::Error, e
45
45
  end
46
46
 
47
+ # Syncs name and email to Stripe::Customer
48
+ def update_customer!
49
+ return unless processor_id?
50
+ ::Stripe::Customer.update(processor_id, {name: customer_name, email: email}, stripe_options)
51
+ end
52
+
47
53
  def charge(amount, options = {})
48
54
  add_payment_method(payment_method_token, default: true) if payment_method_token?
49
55
 
@@ -171,8 +177,8 @@ module Pay
171
177
  # checkout(mode: "subscription")
172
178
  #
173
179
  # checkout(line_items: "price_12345", quantity: 2)
174
- # checkout(line_items [{ price: "price_123" }, { price: "price_456" }])
175
- # checkout(line_items, "price_12345", allow_promotion_codes: true)
180
+ # checkout(line_items: [{ price: "price_123" }, { price: "price_456" }])
181
+ # checkout(line_items: "price_12345", allow_promotion_codes: true)
176
182
  #
177
183
  def checkout(**options)
178
184
  customer unless processor_id?
@@ -181,17 +187,22 @@ module Pay
181
187
  payment_method_types: ["card"],
182
188
  mode: "payment",
183
189
  # These placeholder URLs will be replaced in a following step.
184
- success_url: options.delete(:success_url) || root_url(session_id: "{CHECKOUT_SESSION_ID}"),
185
- cancel_url: options.delete(:cancel_url) || root_url(session_id: "{CHECKOUT_SESSION_ID}")
190
+ success_url: merge_session_id_param(options.delete(:success_url) || root_url),
191
+ cancel_url: merge_session_id_param(options.delete(:cancel_url) || root_url)
186
192
  }
187
193
 
188
194
  # Line items are optional
189
195
  if (line_items = options.delete(:line_items))
196
+ quantity = options.delete(:quantity) || 1
197
+
190
198
  args[:line_items] = Array.wrap(line_items).map { |item|
191
199
  if item.is_a? Hash
192
200
  item
193
201
  else
194
- {price: item, quantity: options.fetch(:quantity, 1)}
202
+ {
203
+ price: item,
204
+ quantity: quantity
205
+ }
195
206
  end
196
207
  }
197
208
  end
@@ -234,6 +245,13 @@ module Pay
234
245
  def stripe_options
235
246
  {stripe_account: stripe_account}.compact
236
247
  end
248
+
249
+ # Includes the `session_id` param for Stripe Checkout with existing params (and makes sure the curly braces aren't escaped)
250
+ def merge_session_id_param(url)
251
+ uri = URI.parse(url)
252
+ uri.query = URI.encode_www_form(URI.decode_www_form(uri.query.to_s).to_h.merge("session_id" => "{CHECKOUT_SESSION_ID}").to_a)
253
+ uri.to_s.gsub("%7BCHECKOUT_SESSION_ID%7D", "{CHECKOUT_SESSION_ID}")
254
+ end
237
255
  end
238
256
  end
239
257
  end
data/lib/pay/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pay
2
- VERSION = "3.0.20"
2
+ VERSION = "3.0.24"
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: 3.0.20
4
+ version: 3.0.24
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-09-16 00:00:00.000000000 Z
12
+ date: 2021-12-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails