Implementing UnionPay Refund Interface in C#

UnionPay Gateway Refund Implementation

    /// <summary>
    /// Process UnionPay gateway payment refund
    /// </summary>
    /// <param name="newTransactionId">New UnionPay transaction identifier</param>
    /// <param name="originalQueryId">Original UnionPay transaction reference ID</param>
    /// <param name="refundTimestamp">Current refund operation timestamp</param>
    /// <param name="refundAmount">Amount to be refunded</param>
    /// <param name="bankConfig">Bank configuration object</param>
    /// <returns>True if refund successful, false otherwise</returns>
    public static bool ProcessUnionPayRefund(string newTransactionId, string originalQueryId, DateTime refundTimestamp, decimal refundAmount, BankConfig bankConfig)
    {
        bool operationSuccess = false;
        try
        {
            UPOPSrv.LoadConf(new MemoryStream(configBuffer));
            var requestParams = new Dictionary();

            requestParams["transType"] = UPOPSrv.TransType.REFUND;
            requestParams["orderNumber"] = GenerateRefundPrefix() + newTransactionId;
            long amountInCents = (int)(refundAmount * 100); // This parameter took considerable effort to locate...
            requestParams["origQid"] = originalQueryId;
            requestParams["orderAmount"] = amountInCents.ToString();
            requestParams["orderCurrency"] = UPOPSrv.CURRENCY_CNY;
            requestParams["orderTime"] = refundTimestamp.ToString("yyyyMMddHHmmss");
            requestParams["customerIp"] = bankConfig.GetClientIP();

            requestParams["frontEndUrl"] = "http://www.example.com/";
            requestParams["backEndUrl"] = "http://www.example.com/";

            var refundService = new BackPaySrv(requestParams);
            var response = refundService.Request();
            if (response == null)
            {
                return operationSuccess;
            }
            if (response.ResponseCode == "00")
            {
                operationSuccess = true;
            }
            else
            {
                var logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
                logger.Error("Refund failed with code:\r\n" + JsonConvert.SerializeObject(response));
            }
        }
        catch (Exception ex)
        {
            var logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            logger.Error("Error occurred:\r\n" + ex.ToString());
        }
        return operationSuccess;
    }

Configuration parameters required for the interface:

  <paymentParameters>
    <string>version</string>
    <string>charset</string>
    <string>transType</string>
    <string>origQid</string>
    <string>merchantId</string>
    <string>merchantAbbreviation</string>
    <string>acquisitionCode</string>
    <string>merchantCode</string>
    <string>productUrl</string>
    <string>productName</string>
    <string>productUnitPrice</string>
    <string>productQuantity</string>
    <string>productDiscount</string>
    <string>transferFee</string>
    <string>orderNumber</string>
    <string>orderAmount</string>
    <string>orderCurrency</string>
    <string>orderTime</string>
    <string>customerIp</string>
    <string>customerName</string>
    <string>defaultPaymentType</string>
    <string>defaultBankCode</string>
    <string>transactionTimeout</string>
    <string>frontEndUrl</string>
    <string>backEndUrl</string>
    <string>merchantReserved</string>
  </paymentParameters>

Tags: UnionPay Payment Gateway Refund Interface C# UPOPSDK

Posted on Mon, 17 Aug 2026 16:57:04 +0000 by johnnyblaze9