@@ -97,7 +97,7 @@ def create_subscription(route, method_url, params, headers)
97
97
customer [ :default_source ] = new_card [ :id ]
98
98
end
99
99
100
- allowed_params = %w( customer application_fee_percent coupon items metadata plan quantity source tax_percent trial_end trial_period_days current_period_start created prorate billing_cycle_anchor billing days_until_due idempotency_key enable_incomplete_payments cancel_at_period_end default_tax_rates payment_behavior pending_invoice_item_interval default_payment_method collection_method off_session trial_from_plan proration_behavior backdate_start_date expand )
100
+ allowed_params = %w( customer application_fee_percent coupon items metadata plan quantity source tax_percent trial_end trial_period_days current_period_start created prorate billing_cycle_anchor billing days_until_due idempotency_key enable_incomplete_payments cancel_at_period_end default_tax_rates payment_behavior pending_invoice_item_interval default_payment_method collection_method off_session trial_from_plan proration_behavior backdate_start_date transfer_data expand )
101
101
unknown_params = params . keys - allowed_params . map ( &:to_sym )
102
102
if unknown_params . length > 0
103
103
raise Stripe ::InvalidRequestError . new ( "Received unknown parameter: #{ unknown_params . join } " , unknown_params . first . to_s , http_status : 400 )
@@ -132,11 +132,36 @@ def create_subscription(route, method_url, params, headers)
132
132
subscription [ :status ] = 'trialing'
133
133
end
134
134
135
+ if params [ :payment_behavior ] == 'default_incomplete'
136
+ subscription [ :status ] = 'incomplete'
137
+ end
138
+
135
139
if params [ :cancel_at_period_end ]
136
140
subscription [ :cancel_at_period_end ] = true
137
141
subscription [ :canceled_at ] = Time . now . utc . to_i
138
142
end
139
143
144
+ if params [ :transfer_data ] && !params [ :transfer_data ] . empty?
145
+ throw Stripe ::InvalidRequestError . new ( missing_param_message ( "transfer_data[destination]" ) ) unless params [ :transfer_data ] [ :destination ]
146
+ subscription [ :transfer_data ] = params [ :transfer_data ] . dup
147
+ subscription [ :transfer_data ] [ :amount_percent ] ||= 100
148
+ end
149
+
150
+ if ( s = params [ :expand ] &.first { |s | s . starts_with? 'latest_invoice' } )
151
+ payment_intent = nil
152
+ unless subscription [ :status ] == 'trialing'
153
+ intent_status = subscription [ :status ] == 'incomplete' ? 'requires_payment_method' : 'succeeded'
154
+ intent = Data . mock_payment_intent ( {
155
+ status : intent_status ,
156
+ amount : subscription [ :plan ] [ :amount ] ,
157
+ currency : subscription [ :plan ] [ :currency ]
158
+ } )
159
+ payment_intent = s . include? ( 'latest_invoice.payment_intent' ) ? intent : intent . id
160
+ end
161
+ invoice = Data . mock_invoice ( [ ] , { payment_intent : payment_intent } )
162
+ subscription [ :latest_invoice ] = invoice
163
+ end
164
+
140
165
subscriptions [ subscription [ :id ] ] = subscription
141
166
add_subscription_to_customer ( customer , subscription )
142
167
@@ -298,6 +323,7 @@ def verify_card_present(customer, plan, subscription, params={})
298
323
return if customer [ :invoice_settings ] [ :default_payment_method ]
299
324
return if customer [ :trial_end ]
300
325
return if params [ :trial_end ]
326
+ return if params [ :payment_behavior ] == 'default_incomplete'
301
327
return if subscription [ :default_payment_method ]
302
328
303
329
plan_trial_period_days = plan [ :trial_period_days ] || 0
0 commit comments