stripe refunds api using php

how to use stripe refunds api using php

In this post we will show you stripe refunds api using php, hear for stripe refunds api using php we will give you demo and example for implement.

stripe refunds api using

To refund a charge via the API, perform a create refund call, providing the ID of the charge to be refunded.

curl https://api.stripe.com/v1/refunds \
-u sk_test_BQokikJO95gRg5lWgH4olfQ2: \
-d charge=ch_ATbg9FdMpO4hlv

To refund part of a charge, provide an amount parameter, as an integer in cents (or the charge currency’s smallest currency unit):

curl https://api.stripe.com/v1/refunds \
-u sk_test_BQokikJO95gRg5lWgH4olfQ2: \
-d charge=ch_ATbg9FdMpO4hlv \
-d amount=9999

stripe refunds api using php code

Hear is php code for stripe refunds api, you need to pass your STRIPE_API_KEY, charge key and amount.

<?php
class Stripe {
public $headers;
// set url
public $set_url = 'https://api.stripe.com/v1/';

//all fields array
public $setfields = array();
// ADD HERE STRIPE_API_KEY = your application stripe api key
function __construct () {
$this->headers = array('Authorization: Bearer sk_test_a12RX6Z485fgh596dsGd1fp');
}

// PHP functions to curl call
function call () {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers);
curl_setopt($ch, CURLOPT_URL, $this->set_url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($this->setfields));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$output = curl_exec($ch);
curl_close($ch);

return json_decode($output, true); // return here php array with stripe api response
}
}

$set_subscription = new Stripe();

$set_subscription->set_url .= 'refunds';
// set charge fields for setfields array
$set_subscription->setfields['charge'] = 'ch_ATbg9FdMpO4hlv';
$set_subscription->setfields['amount'] = '9999';

$subscription_add = $set_subscription->call();
echo "<pre>";
print_r($subscription_add);
echo "</pre>";
if(isset($subscription_add['error']['message']))
{
echo "error :: ".$subscription_add['error']['message'];
}
?>

stripe refunds api destination

refunds are constantly sent back to the first charge source. It’s impractical to discount a charge to an alternate goal (e.g., another card or financial balance). In the event that the charge card lapsed or was wiped out, the client’s new card will be credited with the discount. In the uncommon case that the client doesn’t have another card, the bank generally sends the discount to the client’s financial balance.

On the off chance that the bank doesn’t recognize what to do with a discount, they send the discount back to Stripe and we reach you by means of email to ask how you might want to deal with the discount.

Hope this code and post will helped you for implement stripe refunds api using php. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve onlincode. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs onlincode.org

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  45  =  51

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US