Ejemplo n.º 1
0
        /// <summary>
        ///     Kiem tra trang thai giao dich offline
        /// </summary>
        /// <param name="partnerCode">Ma doi tac do momo cung cap</param>
        /// <param name="merchantRefId">Ma don hang luu tren he thong momo</param>
        /// <param name="publicKey">Public key do momo cung cap</param>
        /// <param name="requestId">Request id</param>
        /// <param name="description"></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 QueryTransactionStatusPayOffline(string partnerCode,
                                                              string merchantRefId,
                                                              string publicKey,
                                                              string requestId,
                                                              string description,
                                                              bool test = false)
        {
            string endpoint = test
                                      ? "https://test-payment.momo.vn/pay/query-status"
                                      : "https://payment.momo.vn/pay/query-status";
            string version = CommonConstant.MOMO_VERSION;

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

            //get hash
            MoMoSecurity momoCrypto = new MoMoSecurity();
            string       hash       = momoCrypto.buildQueryHash(partnerCode,
                                                                merchantRefId,
                                                                requestId,
                                                                publicKey);

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

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

            Logger.Debug(responseFromMomo);

            return(responseFromMomo);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Thanh toan momo offline bang cach quet ma vach tren app momo
        /// </summary>
        /// <param name="partnerCode">Ma doi tac do momo cung cap</param>
        /// <param name="merchantRefId">Ma don hang luu tren he thong momo</param>
        /// <param name="amount">So tien can thanh toan</param>
        /// <param name="paymentCode">Ma so quet tren app momo cua khach hang</param>
        /// <param name="storeId">Store id cua hang</param>
        /// <param name="storeName">Store name cua hang</param>
        /// <param name="description">Thong tin don hang</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 SendPayOffline(string partnerCode,
                                            string merchantRefId,
                                            string amount,
                                            string paymentCode,
                                            string storeId,
                                            string storeName,
                                            string description,
                                            string publicKey,
                                            bool test = false)
        {
            try
            {
                var endpoint = test
                                       ? "https://test-payment.momo.vn/pay/pos"
                                       : "https://payment.momo.vn/pay/pos";
                var version = CommonConstant.MOMO_VERSION;

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

                //get hash
                var momoCrypto = new MoMoSecurity();
                var hash       = momoCrypto.getHash(partnerCode,
                                                    merchantRefId,
                                                    amount,
                                                    paymentCode,
                                                    storeId,
                                                    storeName,
                                                    publicKey);

                //request to MoMo
                var jsonRequest = "{\"partnerCode\":\"" + partnerCode + "\",\"partnerRefId\":\"" + merchantRefId + "\",\"description\":\"" + description + "\",\"amount\":" + amount + ",\"version\":" + version + ",\"hash\":\"" + hash + "\"}";
                Logger.Debug(jsonRequest);

                //response from MoMo
                var responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint,
                                                                         jsonRequest);
                Logger.Debug(responseFromMomo);

                return(responseFromMomo);
            }
            catch (Exception exception)
            {
                Logger.Debug(exception);
            }

            return(string.Empty);
        }