Refunds
If your payment service provider supports refund, you can easily integrate it into the module.
There should be a function called "refund" inside your module class.
The parameter passed to the function is explained in detail in the "Checkout" document.
Sample Usage
public function refund($checkout=[])
{
$custom_id = $checkout["id"];
$api_key = $this->config["settings"]["example1"] ?? 'N/A';
$secret_key = $this->config["settings"]["example2"] ?? 'N/A';
$amount = $checkout["data"]["total"];
$currency = $this->currency($checkout["data"]["currency"]);
$invoice_id = $checkout["data"]["invoice_id"] ?? 0;
$invoice = Invoices::get($invoice_id);
$method_msg = $invoice["pmethod_msg"] ?? [];
$transaction_id = $method_msg["Transaction ID"] ?? false;
$force_curr = $this->config["settings"]["force_convert_to"] ?? 0;
if($force_curr > 0)
{
$amount = Money::exChange($amount,$currency,$force_curr);
$currency = $this->currency($force_curr);
}
// Here we are making an API call.
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "api.sample.com/refund/".$transaction_id);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'APIKEY: '.$api_key,
'SECRET: '.$secret_key,
'Content-Type: application/json',
));
$result = curl_exec($curl);
if(curl_errno($curl))
{
$result = false;
$this->error = curl_error($curl);
}
$result = json_decode($result,true);
if($result && $result['status'] == 'OK') $result = true;
else
{
$this->error = $result['message'] ?? 'something went wrong';
$result = false;
}
return $result;
}
The value to return from the function must be of the "boolean" data type.