コード例 #1
0
ファイル: MomoHelper.cs プロジェクト: viettd1190/Momo
        /// <summary>
        ///     Refund tien cho giao dich thanh toan offline
        /// </summary>
        /// <param name="partnerCode">Ma doi tac do momo cung cap</param>
        /// <param name="requestId">Request id</param>
        /// <param name="merchantRefId">Ma don hang luu tren he thong momo</param>
        /// <param name="amount">So tien can refund</param>
        /// <param name="momoTransId">Ma giao dich momo</param>
        /// <param name="description"></param>
        /// <param name="publicKey">Public key do momo cung cap</param>
        /// <param name="test">Test=true la moi truong test, test=false la moi truong production. Mac dinh la false</param>
        /// <returns></returns>
        public static string RefundTransactionPayOffline(string partnerCode,
                                                         string requestId,
                                                         string merchantRefId,
                                                         string amount,
                                                         string momoTransId,
                                                         string description,
                                                         string publicKey,
                                                         bool test = false)
        {
            string endpoint = test
                                      ? "https://test-payment.momo.vn/pay/refund"
                                      : "https://payment.momo.vn/pay/refund";
            string version = CommonConstant.MOMO_VERSION;

            publicKey = RsaKeyConverter.PemToXml(RsaKeyConverter.FormatPem(publicKey,
                                                                           "PUBLIC KEY"));

            //get hash
            MoMoSecurity momoCrypto = new MoMoSecurity();
            string       hash       = momoCrypto.buildRefundHash(partnerCode,
                                                                 merchantRefId,
                                                                 momoTransId,
                                                                 Convert.ToInt64(amount),
                                                                 description,
                                                                 publicKey);

            //request to MoMo
            string jsonRequest = "{\"partnerCode\":\"" + partnerCode + "\",\"requestId\":\"" + requestId + "\",\"version\":" + version + ",\"hash\":\"" + hash + "\"}";

            //response from MoMo
            string responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint,
                                                                        jsonRequest);

            Logger.Debug(responseFromMomo);

            return(responseFromMomo);
        }