Reputation:
I am using Stripe for handling the payment process,and I come to the point when I have to refund the customers.
So far I am using this code:
$customer = \Stripe\Customer::create(array(
"source" => $token,
"description" => $email)
);
$charge = \Stripe\Charge::create(array(
'amount' => $amount, // Amount in cents!
'currency' => $this->currency,
"description" => $email,
"customer" => $customer->id
));
Once this is done, I store customer id to my users table customers. I have the customer stored id and later I wanna refund him, How do I do that?
I know you can refund using this code:
$charge = \Stripe\Charge::retrieve($charge_id);
$refund = $charge->refunds->create();
My case is a bit different that how do I find the charge_id using customer id, somewhat?
Thanks
Upvotes: 1
Views: 1327
Reputation: 166
$charge = \Stripe\Charge::create(array(
'amount' => $amount, // Amount in cents!
'currency' => $this->currency,
"description" => $email,
"customer" => $customer->id
));
Then add this lines :
$details = json_decode($charge);
$result = get_object_vars($details);
Now you get all the result in $result variable then you find:
$charge_id = $result['id'];
Upvotes: 1