Refund

There are cases when you want to return customer’s money – either the whole amount or just a part of it. This is exactly what a refund is for – it allows you to return funds in reference to a specific transaction.

In order to perform a refund, you must know the transaction ID number. This ID number identifies the transaction in PayLane’s systems. You can easily retrieve this number while performing the transaction, for example:

1
2
$status = $client->directDebitSale($ddebit_params);
$id_sale = $status['id_sale'];
1
2
status = client.direct_debit_sale(ddebit_params)
id_sale = status["id_sale"]
1
2
status = client.direct_debit_sale(ddebit_params)
id_sale = status['id_sale']
1
2
3
4
5
6
api.directDebitSale(sale, customer, account, new Callback<SaleResult>() {
    @Override
    public void onFinish(SaleResult result) {
        long idSale=result.getIdSale();
    }
});
See the Single transaction page for more details on performing a single sale.

Usually merchants store such ID numbers in their database. This way they do not have to store any sensitive data, yet they are still able to refer to a specific transaction.

Now prepare the data required to perform the refund. Note that you can provide the amount of the transaction or less; if you enter a greater value than the transaction amount, you will receive an error message. You can also specify the refund’s reason and currency. Simply call the refund method. Just like with any other transaction, you can also check whether the refund was performed successfully by calling the isSuccess method.
Retrieving the refund ID number (or error details, if anything goes wrong) is also very simple and can be done as shown below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$refund_params = array(
    'id_sale'  => $id_sale,
    'amount'   => 9.99,
    'reason'   => 'Partial refund',
);

try {
    $status = $client->refund($refund_params);
} catch (Exception $e) {
    // handle exceptions here
}

if ($client->isSuccess()) {
    echo "Success, id_refund: {$status['id_refund']} \n";
} else {
    die("Error ID: {$status['error']['id_error']}, \n".
        "Error number: {$status['error']['error_number']}, \n".
        "Error description: {$status['error']['error_description']}");
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
refund_params = {
    'id_sale'  => id_sale,
    'amount'   => 9.99,
    'reason'   => 'Partial refund.'
}

begin
    status = client.refund(refund_params)
rescue PayLane::ClientError => e
    # handle exceptions here
end

if client.success?
    puts "Success, id_refund: #{status["id_refund"]}"
else
    puts "Error ID: #{status["error"]["id_error"]}, \n"\
         "Error number: #{status["error"]["error_number"]}, \n"\
         "Error description: #{status["error"]["error_description"]}"
    exit
end
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
refund_params = {
  'id_sale'  : id_sale,
  'amount'   : 9.99,
  'reason'   : 'Partial refund'
}

try:
    status = client.refund(refund_params)
except Exception, e:
    # handle exceptions here

if client.is_success():
    print 'Success, id_refund: %s' % status['id_refund']
else:
    sys.exit('Error ID: ' + str(status["error"]["id_error"]) + '\n' \
             'Error number: ' + str(status["error"]["error_number"]) + '\n' \
             'Error description: ' + str(status["error"]["error_description"]))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
api.refund(idSale, 9.99, "EUR", "Partial refund", new Callback<FraudSaleResult>() {

    @Override
    public void onFinish(FraudSaleResult result) {
        // success
    }

    @HandleException
    public void onProtocolError(ProtocolException e) {
        // invoke if not success
        // e.getCode() - error code
        // e.getMessage() - error message
    }

    @Override
    public void onError(Exception e) {
        // connection error etc.
    }
});