Refund charges (SDK)

United States
Canada

Businesses need to provide their customers with refunds for many different reasons. For example, the customer may be dissatisfied with the product or the product may not function correctly. The SDK provides easy access to the API's refund functions.

Refund a specific charge

To refund a charge, call the create a refund endpoint and pass in the identifier of the charge to be refunded.

from clover import Refund

refund = clover.Refund.create(charge=chargeId)
require('dotenv').config();
const Clover = require("clover-ecomm-sdk");

let ACCESS_TOKEN = process.env.ACCESS_TOKEN;
let ENVIRONMENT = process.env.ENVIRONMENT;

const cloverInst = new Clover(ACCESS_TOKEN, {
  environment: ENVIRONMENT
});

let chargeId = charge.id;
return cloverInst.refunds.create({
  charge: chargeId,
  reason: 'requested_by_customer' 
}, function(err){
  console.error(err.raw.response.message.type)
  })
});

This returns a refund object in JSON. The id value is the unique identifier of the refund.

{
  'id': 'T6WW3H5DHHWN4',
  'object': 'refund',
  'amount': 5000,
  'charge': 'HGZF4HB58BT62',
  'created': 1582324384476,
  'status': 'succeeded'
}

Refund a partial amount

There are cases where the merchant may want to refund only some of the original charge. If the customer is returning one item of a multi-item purchase, the merchant will only want to refund the amount of that specific item. To refund a partial amount, call the create a refund endpoint and pass in the identifier of the charge to be refunded and the amount to be refunded.

from clover import Refund

refund = clover.Refund.create(charge=chargeId, amount=partialRefundAmount)
require('dotenv').config();
const Clover = require("clover-ecomm-sdk");

let ACCESS_TOKEN = process.env.ACCESS_TOKEN;
let ENVIRONMENT = process.env.ENVIRONMENT;

const cloverInst = new Clover(ACCESS_TOKEN, {
  environment: ENVIRONMENT
});

let chargeId = charge.id;
return cloverInst.refunds.create({
  charge: chargeId,
  amount: 200,
  reason: 'requested_by_customer' 
}, function(err){
  console.error(err.raw.response.message.type)
  })
});

This returns a refund object in JSON, and you can confirm the refunded value in the amount field. See the REST API Reference for complete information about the returned values.

{
  'id': '62YFNXDSYZT52',
  'object': 'refund',
  'amount': 2000,
  'charge': 'HGZF4HB58BT62',
  'created': 1582562317398,
  'status': 'succeeded'
}