Skip to content

Commit 73430a8

Browse files
committed
Add basic Subscription.transfer_data support
1 parent aefc082 commit 73430a8

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/stripe_mock/request_handlers/subscriptions.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def create_subscription(route, method_url, params, headers)
9797
customer[:default_source] = new_card[:id]
9898
end
9999

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 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 expand transfer_data)
101101
unknown_params = params.keys - allowed_params.map(&:to_sym)
102102
if unknown_params.length > 0
103103
raise Stripe::InvalidRequestError.new("Received unknown parameter: #{unknown_params.join}", unknown_params.first.to_s, http_status: 400)
@@ -141,6 +141,12 @@ def create_subscription(route, method_url, params, headers)
141141
subscription[:canceled_at] = Time.now.utc.to_i
142142
end
143143

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+
144150
if (s = params[:expand]&.first { |s| s.starts_with? 'latest_invoice' })
145151
payment_intent = nil
146152
unless subscription[:status] == 'trialing'

spec/shared_stripe_examples/subscription_examples.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,15 @@
302302
expect(customer.subscriptions.data.first.status).to eq('incomplete')
303303
end
304304

305+
it "allows setting transfer_data" do
306+
customer = Stripe::Customer.create(id: 'test_customer_sub', source: gen_card_tk)
307+
308+
sub = Stripe::Subscription.create({ customer: customer.id, plan: plan.id, transfer_data: {destination: "acct_0000000000000000", amount_percent: 50} })
309+
310+
expect(sub.transfer_data.destination).to eq("acct_0000000000000000")
311+
expect(sub.transfer_data.amount_percent).to eq(50)
312+
end
313+
305314
it "throws an error when subscribing a customer with no card" do
306315
plan = stripe_helper.create_plan(id: 'enterprise', product: product.id, amount: 499)
307316
customer = Stripe::Customer.create(id: 'cardless')
@@ -1305,7 +1314,6 @@
13051314
expect(customer.subscriptions.first.metadata['foo']).to eq('bar')
13061315
end
13071316
end
1308-
13091317
end
13101318

13111319
shared_examples 'Customer Subscriptions with prices' do

0 commit comments

Comments
 (0)