I am currently creating a customer in stripe and assigning a recurring plan ti them to receive recurring monthly payment.
//Create Customer: $customer = StripeCustomer::create(array( 'source' => $token, 'email' => $_POST['email'], 'plan' => "monthly_recurring_setupfee", )); // Charge the order: $subscription = StripeSubscription::create(array( "customer" => $customer->id, "items" => array( array( "plan" => $plan->id, ), ), ));
but after few months i can see that few customer can still use my services but their recurring payment failed.
i know there is a webhook but i cant figure it out & cant test webhook if its working properly or not. how can i check if a recurring payment failed or succeed
Advertisement
Answer
You’re right about webhooks: it’s a way to go. They allow you to get the recurring payment information close to real-time. Also, I’d recommend saving the subscription ID along with Stripe’s customer ID in your user entity.
The process is the following:
- You create a webhook to your endpoint using this guide: https://stripe.com/docs/webhooks
- You test it: https://stripe.com/docs/testing#webhooks
- You provide the service based on received webhooks.
Here is the detailed documentation about subscription webhooks: https://stripe.com/docs/billing/subscriptions/webhooks
If it’s still complicated, you can use some background job to check the subscription status.
You have two options:
- Traverse through all subscriptions in Stripe and discontinue your service for users with expired subscriptions. Stripe endpoint for this case will be https://stripe.com/docs/api/subscriptions/list
- This option will work only if you store the subscription ID (and preferably, subscription renewal/end date) in the user entity. Traverse through the list of users in your system with expiring subscription date, fetch their subscriptions from Stripe and check the subscription status. Stripe’s API to use in this case: https://stripe.com/docs/api/subscriptions/retrieve