I have a use case where I need to find that whether applied code is valid for a specific customer or not before making the payment using the Stripe. Assume there is one coupon code as "50%off" created in the Stripe which can only be used once by customers. There will be two scenario:
- If customer using it for first time, they discount will be applied which is fine.
- If customer using it second time, I dont want to show them discounted price at application level. And at the Stripe level, discount will not be provided as well.
I am not managing coupon code at my application level and using below code to retrieve coupon code data:
\Stripe\Stripe::setApiKey($this->config->item('stripe_secret_key'));
$couponData = \Stripe\Coupon::retrieve($coupon);
The above code share with me below details
[body] => {
"id": "50%off",
"object": "coupon",
"amount_off": 600,
"created": 1494427220,
"currency": "usd",
"duration": "once",
"duration_in_months": null,
"livemode": false,
"max_redemptions": null,
"metadata": {
},
"name": null,
"percent_off": null,
"percent_off_precise": null,
"redeem_by": null,
"times_redeemed": 4,
"valid": true
}
but I can not figure out if the customer has already used this coupon code earlier or not. I tried to pass customer id as well as below:
\Stripe\Stripe::setApiKey($this->config->item('stripe_secret_key'));
$couponData = \Stripe\Coupon::retrieve($coupon, ['customer' => $stripe_customer_id]);
but it shares the same response.
Can anyone please help me in this, thanks!