Refunds
This function will be called any time a transaction is requested to be refunded from within WHASOLS.
It is supported by all payment gateway module types. If your payment gateway module does not support refunds, simply do not define this function within your module.
Like with a capture attempt, upon completion of the refund, you are expected to return an array containing the transaction details consisting of the status, and if successful a transaction ID and optionally some data to be recorded to the gateway log for debugging purposes.
Variables
The following parameters are passed to the
yourmodule_refund
function along with all defined configuration parameters and their values.Response Format
The following return parameters are supported.
Parameter | Type | Notes |
---|---|---|
status | string | One of either success ,error , or declined . |
message | string | The reason why a transaction was declined. |
transid | string | The Transaction ID returned by the payment gateway. |
fee | float | (Optional) The transaction fee returned by the payment gateway. |
rawdata | string or array | The raw data returned by the payment gateway for logging to the gateway log to aid in debugging. |
gatewayid | int | Payment Gateway ID within WHASOLS |
Example Return
The capture function should always return an array containing information about the transaction attempt. This should take the following format:
<?php return [
"status"=>"success",
"rawdata"=>$responseData,
"transid"=>$transactionId,
"fee"=>$feeAmount,
];
For a successful refund, the status should be returned as the string
success
.For anything else, return a status that indicates the reason for failure. Common failure response status values include
declined and error
.The raw data you return will be recorded to the gateway log to aide in debugging. It can accept either a string or an array.
Simple Example
Below is a demonstration of a refund function that submits a payment capture request and receives a JSON response.
<?php function yourmodulename_refund($arg) {
$invoiceid = $arg['invoice']['invoiceid'];
$description = $arg['invoice']['description'];
$amount = $arg['invoice']['amount'];
$currencyCode = $arg['invoice']['currency'];
$cardtype= $arg['cardtype']; //string The card type (for example, Visa or MasterCard).
$cardnum= $arg['cardnum']; //string The card number.
$cardexp= $arg['cardexp']; //string The card expiry date (format: MMYY).
$cardstart= $arg['cardstart']; //string The card start date (format: MMYY).
$cardissuenum= $arg['cardissuenum']; //string The card issue number.
$cccvv= $arg['cccvv']; //string Only available for card holder present initiated payment attempts.
$firstname = $arg['client']['firstname'];
$lastname = $arg['client']['lastname'];
$email = $arg['client']['email'];
$address1 = $arg['client']['address1'];
$address2 = $arg['client']['address2'];
$city = $arg['client']['city'];
$state = $arg['client']['state'];
$postcode = $arg['client']['postcode'];
$country = $arg['client']['country'];
$phonenumber = $arg['client']['phonenumber'];
//Your Gateway API code perform here
$data = json_decode($response);
if ($data->success == 1) return [
'status' => 'success',
'transid' => $data->transaction_id,
'fee' => $data->fee,
'rawdata' => $data,
];
return [
'status' => 'declined',
'message' => $data->decline_reason,
'rawdata' => $data,
];
}