belt-pay 0.0.4 → 0.0.5

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: 225d94bd8d7f1b25849f237c4bb8432ce5b485b3a7ca5b88aee833d928481c4d
4
- data.tar.gz: 7cabb1843e20857030506f0a3efe42a26aa375563f65c8ffb14334d84dc39b07
3
+ metadata.gz: 937d9e1a7ca86c274b1dd20feb2ad16b2f9f9aa8544b0bffd6d72ed1550768f7
4
+ data.tar.gz: f33e95b73bd5f8104d3da45c34ce7e3e4e6ca329224721c80271af3f8e7c85d3
5
5
  SHA512:
6
- metadata.gz: ccf4f5972eabe4ffa0aa4c4d4be3207ac640970cea1ddaae857043bdf7d81a6df507932cc8c7704020326f578c46ee73ef0ea8e978b1443f761ca34f59deb960
7
- data.tar.gz: 91f585c4b462664b2f193d8575fd5b551e969d613456ada465c4d3fa83387b4577b910fa64dd6e49f51b903082788ad8e48532a84174a76003368b5471ab40d1
6
+ metadata.gz: b1c7f6bb3f97548a05e060090f47b586aaf0435237931cd1c67b55534efd72eb706cf6af1d7294f07a5210268fdd6c232ef951d410722b00de1bdc56f43c30cc
7
+ data.tar.gz: 73e0341c2f2441a279814645e959df9f1b94c41d88ba70018bac6b3ef10c144583288e945ee0a1d22e955c057361dc5e71858c5e4a63769e9a2fb47af3d4ad38
data/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.0.5 — 2026-10-31
4
+
5
+ - **`create_checkout` no longer drops Checkout Session options.** The Stripe provider used
6
+ to copy only `line_items`, `mode`, `success_url`, `cancel_url`, `metadata` and
7
+ `subscription_data` into `Stripe::Checkout::Session.create` and silently discard
8
+ everything else. It now forwards every option in
9
+ `Belt::Pay::Providers::Stripe::CHECKOUT_SESSION_OPTIONS` — including
10
+ `allow_promotion_codes`, `discounts`, `automatic_tax`, `payment_intent_data`,
11
+ `setup_intent_data`, `tax_id_collection`, `customer_update`, `locale`, `expires_at`,
12
+ `ui_mode`/`return_url` and the rest of the documented Checkout Session params.
13
+ - Unknown keys raise `ArgumentError` naming the offending option, so the next missing
14
+ param fails loudly instead of vanishing.
15
+ - `extra: { ... }` merges any additional params in unvalidated, for Stripe options the
16
+ list doesn't know about yet.
17
+ - Options given as `nil` are omitted from the request.
18
+
3
19
  ## 0.0.4 — 2026-10-20
4
20
 
5
21
  - **`belt pay:setup` creates the Stripe webhook endpoint for you.** After the secret-key
data/README.md CHANGED
@@ -100,6 +100,18 @@ Belt::Pay.create_checkout(customer,
100
100
  success_url: 'https://app.example.com/success?session_id={CHECKOUT_SESSION_ID}',
101
101
  cancel_url: 'https://app.example.com/cancel')
102
102
 
103
+ # Any Stripe Checkout Session option passes straight through
104
+ Belt::Pay.create_checkout(customer,
105
+ line_items: [{ price: 'price_xxx', quantity: 1 }],
106
+ success_url: 'https://app.example.com/success?session_id={CHECKOUT_SESSION_ID}',
107
+ cancel_url: 'https://app.example.com/cancel',
108
+ allow_promotion_codes: true, # Dashboard coupons / promo codes
109
+ automatic_tax: { enabled: true }, # Stripe Tax
110
+ payment_intent_data: { metadata: { pass_id: 42 } }) # carried onto the charge, so a
111
+ # Dashboard refund still knows the app record
112
+ # Unknown keys raise ArgumentError instead of being silently dropped.
113
+ # Use `extra: { ... }` to forward a Stripe param this gem doesn't list yet.
114
+
103
115
  # Subscribe directly (when payment method is already attached)
104
116
  customer.subscribe!(price_id: 'price_xxx')
105
117
 
@@ -12,6 +12,9 @@ module Belt
12
12
  # @param success_url [String]
13
13
  # @param cancel_url [String]
14
14
  # @param metadata [Hash]
15
+ # @param options [Hash] Any other Checkout Session option the provider supports
16
+ # (e.g. allow_promotion_codes:, automatic_tax:, payment_intent_data:,
17
+ # subscription_data:). Forwarded verbatim; unknown keys raise ArgumentError.
15
18
  # @return [Hash] { url:, session_id: }
16
19
  def create(customer, line_items:, mode: 'payment', success_url:, cancel_url:, metadata: {}, **options)
17
20
  # Ensure provider customer exists
@@ -67,24 +67,54 @@ module Belt
67
67
  { client_secret: setup_intent.client_secret, setup_intent_id: setup_intent.id }
68
68
  end
69
69
 
70
+ # Stripe Checkout Session options that #create_checkout_session forwards verbatim
71
+ # when given. Anything else raises ArgumentError so a missing option fails loudly
72
+ # instead of being silently dropped; pass `extra:` to send a key not listed here.
73
+ # @see https://docs.stripe.com/api/checkout/sessions/create
74
+ CHECKOUT_SESSION_OPTIONS = %i[
75
+ subscription_data payment_intent_data setup_intent_data
76
+ allow_promotion_codes discounts automatic_tax tax_id_collection
77
+ customer_update customer_creation client_reference_id currency locale expires_at
78
+ payment_method_types payment_method_collection payment_method_options
79
+ payment_method_configuration saved_payment_method_options
80
+ billing_address_collection shipping_address_collection shipping_options
81
+ phone_number_collection consent_collection custom_fields custom_text submit_type
82
+ invoice_creation after_expiration adaptive_pricing optional_items
83
+ ui_mode return_url redirect_on_completion
84
+ ].freeze
85
+
70
86
  # Create a Checkout Session.
87
+ #
88
+ # Every key in CHECKOUT_SESSION_OPTIONS (e.g. `allow_promotion_codes:`,
89
+ # `automatic_tax:`, `payment_intent_data:`, `subscription_data:`) is forwarded to
90
+ # Stripe as-is. Keys with a nil value are omitted. Unknown keys raise
91
+ # ArgumentError; use `extra:` for a Stripe option this list doesn't know about yet.
92
+ #
71
93
  # @param pay_customer_id [String] Stripe customer ID
72
- # @param options [Hash] line_items, mode, success_url, cancel_url, metadata
94
+ # @param line_items [Array<Hash>]
95
+ # @param mode [String] 'payment', 'subscription' or 'setup' (default 'payment')
96
+ # @param success_url [String, nil]
97
+ # @param cancel_url [String, nil]
98
+ # @param metadata [Hash]
99
+ # @param extra [Hash] Additional Checkout Session params merged in last, unvalidated
100
+ # @param options [Hash] Any key in CHECKOUT_SESSION_OPTIONS
73
101
  # @return [Hash] { url:, session_id: }
74
- def create_checkout_session(pay_customer_id, **options)
102
+ # @raise [ArgumentError] when an option is not a known Checkout Session param
103
+ def create_checkout_session(pay_customer_id, line_items:, mode: 'payment', success_url: nil,
104
+ cancel_url: nil, metadata: {}, extra: {}, **options)
75
105
  ensure_api_key!
76
106
  params = {
77
107
  customer: pay_customer_id,
78
- line_items: options[:line_items],
79
- mode: options[:mode] || 'payment',
80
- success_url: options[:success_url],
81
- cancel_url: options[:cancel_url],
82
- metadata: options[:metadata] || {}
108
+ line_items: line_items,
109
+ mode: mode || 'payment',
110
+ success_url: success_url,
111
+ cancel_url: cancel_url,
112
+ metadata: metadata || {}
83
113
  }
84
- # For subscription mode, allow trial periods
85
- params[:subscription_data] = options[:subscription_data] if options[:subscription_data]
114
+ params.merge!(checkout_session_options(options))
115
+ params.merge!(extra) if extra
86
116
 
87
- session = ::Stripe::Checkout::Session.create(params)
117
+ session = ::Stripe::Checkout::Session.create(params.compact)
88
118
  { url: session.url, session_id: session.id }
89
119
  end
90
120
 
@@ -178,6 +208,19 @@ module Belt
178
208
 
179
209
  private
180
210
 
211
+ # Validate and compact the pass-through Checkout Session options.
212
+ def checkout_session_options(options)
213
+ unknown = options.keys - CHECKOUT_SESSION_OPTIONS
214
+ if unknown.any?
215
+ raise ArgumentError,
216
+ "Unknown Checkout Session option(s): #{unknown.map(&:inspect).join(', ')}. " \
217
+ "Supported: #{CHECKOUT_SESSION_OPTIONS.join(', ')}. " \
218
+ 'Pass `extra: { ... }` to forward a param not listed here.'
219
+ end
220
+
221
+ options.compact
222
+ end
223
+
181
224
  def fetch_api_key
182
225
  secret_name = Belt::Pay.configuration.secret_name
183
226
  return nil unless secret_name
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Belt
4
4
  module Pay
5
- VERSION = '0.0.4'
5
+ VERSION = '0.0.5'
6
6
  end
7
7
  end
data/lib/belt/pay.rb CHANGED
@@ -94,7 +94,11 @@ module Belt
94
94
 
95
95
  # Create a checkout session for one-time or subscription payments.
96
96
  # @param customer [Object] Your app's user/customer model instance
97
- # @param options [Hash] Checkout options (line_items, mode, success_url, cancel_url, metadata)
97
+ # @param options [Hash] Checkout options: line_items, mode, success_url, cancel_url,
98
+ # metadata, plus any Stripe Checkout Session option such as allow_promotion_codes,
99
+ # automatic_tax, payment_intent_data or subscription_data (see
100
+ # Providers::Stripe::CHECKOUT_SESSION_OPTIONS). Unknown keys raise ArgumentError;
101
+ # pass extra: { ... } to forward a param the list doesn't know yet.
98
102
  # @return [Hash] { url:, session_id: }
99
103
  def create_checkout(customer, **options)
100
104
  Checkout.create(customer, **options)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: belt-pay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stowzilla