#Jonah Librach
1 messages · Page 1 of 1 (latest)
hello! can you share the subscription id?
Sure, I just need to recreate an example. Might take a minute or so
sub_1N8F7nEqrfgopYncNpBxxwFE
According to the expiry_date it should expire/renew on July 31, 2000 at 10:00 AM, which would make sense... but it doesn't invoice again until Aug 3
Hi @rugged gale I'm taking over
Great. Thanks Jack
https://dashboard.stripe.com/test/subscriptions/sub_1N8F7nEqrfgopYncNpBxxwFE based on the logs, three invoices were created on 1 Jul, 31 Jul and 30 Aug 2000. So your question is why the 2nd invoice was created on 31 Jul instead of 1 Aug?
Okay wait, the invoices are created... which is good.
But then why is it taking so long to automatically pay those invoices?
Says finalized on Aug 2
Payment date Aug 2
So you are talking about this invoice in_1N8F86EqrfgopYncnU7vfmUY
I'm talking about this invoice which was paid 2 Aug 2000, 10:00 and created 31 Jul 2000, 10:00
in_1N8F7vEqrfgopYncdaWGLBuf
OK. From the event logs the invoice.created and invoice.paid happened almost at the same time.
It looks like be a bug with the test clocks, I'll feed back to the relevant team.
Where are you seeing that they are created and paid at nearly the same time?
https://dashboard.stripe.com/test/events/evt_1N8F84EqrfgopYncnwPD0HcN
https://dashboard.stripe.com/test/events/evt_1N8F7xEqrfgopYncvT2XXSGg
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
Last time the support said it could be a timezone issue, but it doesn't make any sense. It's off by several days
No, I don't think it's a timezone issue.
Okay, thanks.
Another question:
I'm trying to set up a test that pays out on the first cycle, but then fails (due to credit card expiry) on the second.
What should I expect to happen when I update payment details to a working card at some later date?
How can I get it so the subscription cycle start is the date that the card worked and it ends 30-days later?
So you want to pause the subscription until the customer has set up a new card that works?
Yes.
Once they set up the new card and it charges successfully, that should be the new period_start
P.S. working with subscriptions is really hard.. meaning it's taken me 2 weeks to write tests etc to integrate with my app. Is this normal?
Yes, subscription is hard.
You can listen to invoice.payment_failed event and call API to pause the subscription (https://stripe.com/docs/billing/subscriptions/pause), once your customer has successfully paid the invoice (i.e., invoice.paid) you can unset the pause, and update the subscription's billing_cycle_anchor to now (https://stripe.com/docs/api/subscriptions/update?lang=curl#update_subscription-billing_cycle_anchor) to reset the cycle.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
on a failed payment, will this failure be derivable from the customer.subscription.updated event
for example, will I get webhook_data.data.object.items.data[0].plan.active == False?
Sorry, that may be a tough one to answer lol
Not really, the subscritpiont's status won't be immediately updated upon a failed payment.
https://stripe.com/docs/billing/subscriptions/overview#settings depends on your settings, Stripe would retry a few times before changing its status
Okay, so I'm trying to test this on the CLI and UI now
Strategy is to use a card that just expires at the 2nd cycle.
How can I specify such a card in the Python bindings?
https://stripe.com/docs/testing#declined-payments you can use one of these card to simulate a decline
I want it to work the first time, then be decline the second time
So you create a subscription with 4242, once the inovice is paid, update its default_payment_method to one of the failing cards
stripe.error.InvalidRequestError: Request req_rpsBVQdWXGZqyg: The customer does not have a payment method with the ID pm_1N8GKgEqrfgopYncreB3dIG7. The payment method must be attached to the customer.
I create customer as follows:
creationArgs = {
"email":email,
"payment_method":payment_method,
"invoice_settings":invoice_settings,
"test_clock":CLOCK_ID
}
customer = stripe.Customer.create(**creationArgs)
You should create a new payment method with the test payment method token ID
https://stripe.com/docs/api/payment_methods/create?lang=curl#create_payment_method-card
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
And attach the newly created payment method to your customer
Ty.
For card,
stripe.PaymentMethod.create(
type="card",
card={
"number": "4242424242424242",
"exp_month": 8,
"exp_year": 2024,
"cvc": "314",
},
)
Should I set card="pm_card_visa_chargeDeclined""?
"token": "tok_visa_chargeDeclined"
}```
stripe.error.InvalidRequestError: Request req_7CbHBt8GTkeb9s: The customer does not have a pa
yment method with the ID pm_1N8GWTEqrfgopYncr1lsyvto. The payment method must be attached to
the customer.
This is after:
pm = stripe.PaymentMethod.create(
type="card",
card={ "token":"tok_visa_chargeDeclined" },
)
Oh, still need to attach. sry
I'm just confused why the default behaviour is to have the subscription continue to be active if the payment fails.
i'm not too sure what you mean? If you want to cancel the Subscription upon payment failure that's possible as well, you can configure that here : https://dashboard.stripe.com/settings/billing/automatic
How do I set that up from the API call on Subscription.create
you can't, it's an Account level setting
What? I'm not talking about my billing
I'm talking about creating a Subscription that cancels if the payment fails
if you want a Subscription to automatically cancel if a payment fails, like i mentioned, that's an account level setting
you cannot configure it per Subscription
Can you explain that to me?
Why that's the case?
What if I want one product to cancel on fail, but another one not to
then you would have to set the account level settings to leave the subscription and invoice "as it is" even if payment fails and implement your own logic to cancel subscriptions for a particular product if payment for it fails
Okay, thanks, that makes sense.
Which events should I be listening for to make sure that the payment has successfully gone through for my subscription?
Currently, I'm listening to customer.subscription.updated, but that obviously isn't going to work.
Hunch is invoice.payment_succeeded, but then there's the invoice.finalized that looks far more final, haha
ChatGPT says I should use invoice.payment_succeeded.
Can you confirm?
Listen to invoice.paid
Jack you're a hero
https://stripe.com/docs/billing/subscriptions/webhooks you can learn more about using webhooks for subscription here