Refund payment

After Setup, and given that you have completed a successful payment, you can now refund it!

If you don't have, or don't want to use, the original payment's reference, use an Unreferenced Refund instead, but be aware that it can fail more often, so use it only as a last resort.

Following the example on Connecting to the SDK, you can add a method on C# like this:

public async Task<JsonElement> RefundPayment(string id, int refundAmount)
{
    var refundParams = new
    {
        gatewayPaymentId = id, // id sent from the SDK as response for the makePayment method with name "gatewayPaymentId" in case of a successful payment
        amount = refundAmount, // amount to be refunded in minor units
        currency = "GBP", // The ISO 4217 currency code (e.g., "GBP", "EUR"). Should match the original payment one
    };
    return await SendRequestAsync("refundPayment", refundParams);
}

The SDK app will respond to this request with a JSON object in the "result" field of the json-rpc message like this:

{
  "type": "refundPayment->onResult",
  "gatewayRefundId": "tr_01985b55-b781-7ff5-937f-11e901cd0068",
  "result": "SUCCESS"
}

For non "SUCCESS" cases, gatewayRefundId will not be present. There may be a debugErrorMessage instead in that case.
The expected results are:

SUCCESS
INVALID_AMOUNT_OR_PAYMENT_ID
AMOUNT_EXCEEDS_ALLOWED
DECLINED
NETWORK_ERROR
CANCELLED
FAILED

For NETWORK_ERROR you can retry, maybe after telling the user that he may have connecting issues.

For now, the Teya SDK app will not show any UI for "in progress" refunds, as it is just a loading state and a final result. But let us know if you find that it would still be valuable.