I am Implementing a case in which i need to cancel customer subscription and refund amount for the same. I am able to cancel Subscription using
$sub = \Stripe\Subscription::retrieve({SUBSCRIPTION_ID});
$sub->cancel();
now i have to refund charged amount
$refund = \Stripe\Refund::create(array(
"charge" => "{CHARGE_ID}"
));
here CHARGE_ID
is compulsory. no option like SUBSCRIPTION_ID
.
As it charged customer automatically i am not able to store CHARGE_ID
. so how can i refund that subscription amount??
Please Help
Thanks
@Meera, I see you solved your problem, my solution was:
1. once you've cancelled your Subscription
2. get all Invoice Collection using the subscriptionId from the Subscription
3. pull the first Invoice from the Invoice Collection
4. create a Refund using the chargeId from the Invoice
$subscriptionId = $objSubscription->id;
$objInvoiceCollection = \Stripe\Invoice::all([
'subscription' => $subscriptionId
]);
if ($objInvoiceCollection->total_count === 0) {
throw new \Exception("warning: \$subscriptionId={$subscriptionId} - no invoices found!");
} else {
$objInvoice = current($objInvoiceCollection);
}
$chargeId = $objInvoice->charge;
$objRefund = \Stripe\Refund::create(['charge' => $chargeId]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With