Refunding money
When a payment has been completed, it is possible to refund the money back to the customer, usually if the order is returned. This article explains how to implement it in the payment provider plugin.
Refunding a payment may be possible only in certain payment methods depending on the payment provider. To implement refunding, implement the IPaymentProvider.ReturnPayment() method. This method is called when Return payment is clicked in the Payments view. The button is enabled when the payment status is Paid.
In the implementation it is necessary to check IPaymentProvider.CanReturnPayment flag so that all conditions to make a refund is fulfilled before the call to the payment provider is made.
/// <summary>
/// Returns the payment.
/// </summary>
public bool ReturnPayment(ReturnPaymentArgs args, Foundation.Security.SecurityToken token)
{
bool success = false;
if (CanReturnPayment)
{
//TODO: call the payment provider api to return the payment.
// success = CallPaymentProviderToReturnPayment(PaymentInfo.TransactionNumber);
if (success)
{
PaymentInfo.SetPaymentStatus((short)PaymentStatus.Returned, token);
PaymentInfo.AppendExternalMessage(DateTime.Now.ToString() + " payment returned", token);
}
}
if (!success)
PaymentInfo.AppendExternalMessage(DateTime.Now.ToString() + " payment return failed", token);
return success;
}