#sw-svl_code
1 messages ¡ Page 1 of 1 (latest)
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1384483660300026027
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
The relevant code:
price = create_price(donation[:reference], monetised_amount, interval, interval_count)
customer = create_customer(donation)
subscription = create_subscription(price, customer, "#{donation[:forename]} #{donation[:surname]}", donation[:email])
invoice = ::Stripe::Invoice.retrieve(subscription.latest_invoice.id, { api_key: private_api_key })
{
payment_intent_client_secret: invoice.confirmation_secret.client_secret,
subscription_id: subscription.id
}
and:
def create_price(reference, amount, interval, interval_count)
::Stripe::Price.create(
{
currency: amount.currency,
unit_amount: amount.cents,
recurring: {
interval: interval,
interval_count: interval_count
},
billing_scheme: 'per_unit',
product_data: { name: "Recurring Donation - Reference: #{reference}" }
},
{ api_key: private_api_key }
)
end
def create_customer(donation)
::Stripe::Customer.create(
{
email: donation[:email],
name: "#{donation[:forename]} #{donation[:surname]}",
address: {
city: donation[:city],
country: donation[:country],
line1: donation[:street],
postal_code: donation[:zip],
state: donation[:state]
}
},
{ api_key: private_api_key }
)
end
def create_subscription(price, customer, full_name, email)
::Stripe::Subscription.create(
{
customer: customer.id,
items: [{ price: price.id }],
payment_behavior: 'default_incomplete',
payment_settings: { save_default_payment_method: 'on_subscription' },
collection_method: 'charge_automatically',
expand: ['latest_invoice'],
metadata: { name: full_name, email: email }
},
{ api_key: private_api_key }
)
end
hello! this change is documented here:
https://docs.stripe.com/changelog/basil/2025-03-31/add-support-for-multiple-partial-payments-on-invoices#use-for-payment-element-integrations
you should be able to get this from the new confirmation_secret property by expanding that and referencing invoice.confirmation_secret.client_secret
As I said the confirmation_secret returned from the invoice is nil
ahhh sorry i missed that. can you share an example subscription ID? e.g. sub_***
From the stripe dashboard or just from how I'm creating it in the code I shared above?
from the dashboard works, i'm looking for the actual ID of the subscription object, e.g. sub_1MowQVLkdIwHu7ixeRlqHVzs
Sure, one second.
And this will be from 'test mode' if thats fine
Here: sub_1Rax8HFpgOJXHv3IoQQ2SunF
yep test mode is perfect! looking now
it looks like you're just expanding on latest_invoice, what happens if you expand on latest_invoice.confirmation_secret?
it's a little confusing but that property only shows if you expand it
Thanks I'll give that a try
I'm still getting nil returned, the sub ID: sub_1RaxCjFpgOJXHv3IqDAFk0Ty
hi! I'm taking over this thread. having a look
`NoMethodError - undefined method 'client_secret' for nil:
payment_intent_client_secret: invoice.confirmation_secret.client_secret,`
Here's the request you made: https://dashboard.stripe.com/test/logs/req_cK9AHwDKjUkzpv
and in the response from Stripe I do see confirmation_secret.client_secret
I think it's because it's not invoice but latest_invoice you should use.
on the subscription object it:s latest_invoice.confirmation_secret.client_secret
So I should change from 'retrieving' it to just chaing from the subscription?
currently:
invoice = ::Stripe::Invoice.retrieve(subscription.latest_invoice.id, { api_key: private_api_key })
you don't need to retrive the invoice at all, the subscription directly conntains the information you need since you are using expand.
to learn more about how expand works, I recommend reading this guide: https://docs.stripe.com/expand