Create stripe refund using php


Jun 25, 2021

Creating a new refund will refund a charge/payment that has previously been created but not yet refunded. Funds will be refunded to the credit or debit card that was originally paid to stripe.

You can partially refund multiple times, until the entire charge has been refunded. Once charged amount refunded, a charge can't be refunded again. You can refund amount through payment intent id or charge id. I will show you both way in this tutorial.

Download stripe SDK for PHP


require_once realpath(dirname(__FILE__)) . '/stripe/autoload.php';
\Stripe\Stripe::setApiKey('sk_test_XXXXXXXXX'); // stripe secret key

Refund via charge id


$refund_amount = 10;
$transaction_id = 'ch_XXXXXXXXXXX';
 $refund = \Stripe\Refund::create(array(
                        'amount' => $refund_amount*100, // add this key if you want to create a partial refund, otherwise, the stripe will refund the full amount.
                        'charge' => $transaction_id,
                    ));

Refund via payment intent id


$refund_amount = 10;
$transaction_id = 'pi_XXXXXXXXXXX';
 $refund = \Stripe\Refund::create(array(
                        'amount' => $refund_amount*100, // add this key if you want to create a partial refund, otherwise, the stripe will refund the full amount.
                        'payment_intent' => $transaction_id,
                    ));

Copyright 2018. All rights are reserved