示例#1
0
        private void payOfflinebtn_Click(object sender, EventArgs e)
        {
            string endpoint      = textEndpointPos.Text;
            string partnerCode   = "MOMO5RGX20191128";
            string merchantRefId = Guid.NewGuid().ToString();
            string amount        = textAmountPos.Text;
            string paymentCode   = textPaymentCode.Text;
            string storeId       = "1";
            string storeName     = "cua hang netika";
            string description   = "";
            string version       = "2.0";
            string publicKey     = textPubkey.Text;

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

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

            log.Debug(jsonRequest);

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

            log.Debug(responseFromMomo);
            log.Debug(hash);

            JObject jmessage = JObject.Parse(responseFromMomo);

            log.Debug("Return from MoMo: " + jmessage.ToString());
            DialogResult result = MessageBox.Show(responseFromMomo, "MoMo response", MessageBoxButtons.OKCancel);

            if (result == DialogResult.OK)
            {
                //yes...
            }
            else if (result == DialogResult.Cancel)
            {
                //no...
            }
        }
示例#2
0
        private void button3_Click(object sender, EventArgs e)
        {
            string endpoint      = "https://test-payment.momo.vn/pay/refund";
            string partnerCode   = "MOMO";
            string merchantRefId = "1519717410468";
            string momoTransId   = "137489899";
            string version       = "2.0";
            string publicKey     = textPubkey.Text;
            string requestId     = Guid.NewGuid().ToString();
            string description   = "";
            long   amount        = 5000;

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

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

            log.Debug(jsonRequest);

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

            log.Debug(responseFromMomo);
            log.Debug(hash);
            JObject jmessage = JObject.Parse(responseFromMomo);

            log.Debug("Return from MoMo: " + jmessage.ToString());
            DialogResult result = MessageBox.Show(responseFromMomo, "MoMo response", MessageBoxButtons.OKCancel);

            if (result == DialogResult.OK)
            {
                //yes...
            }
            else if (result == DialogResult.Cancel)
            {
                //no...
            }
        }
示例#3
0
        private void button1_Click(object sender, EventArgs e)
        {
            //request params need to request to MoMo system
            string endpoint    = textEndpoint.Text.Equals("") ? "https://test-payment.momo.vn/gw_payment/transactionProcessor" : textEndpoint.Text;
            string partnerCode = textPartnerCode.Text;
            string accessKey   = textAccessKey.Text;
            string serectkey   = "K951B6PE1waDMi640xX08PD3vg6EkVlz";
            string orderInfo   = textOrderInfo.Text;
            string returnUrl   = textReturn.Text;
            string notifyurl   = textNotify.Text;

            string amount    = textAmount.Text;
            string orderid   = Guid.NewGuid().ToString();
            string requestId = Guid.NewGuid().ToString();
            string extraData = "merchantName=;merchantId=";//pass empty value if your merchant does not have stores else merchantName=[storeName]; merchantId=[storeId] to identify a transaction map with a physical store

            //before sign HMAC SHA256 signature
            string rawHash = "partnerCode=" +
                             partnerCode + "&accessKey=" +
                             accessKey + "&requestId=" +
                             requestId + "&amount=" +
                             amount + "&orderId=" +
                             orderid + "&orderInfo=" +
                             orderInfo + "&returnUrl=" +
                             returnUrl + "&notifyUrl=" +
                             notifyurl + "&extraData=" +
                             extraData;

            log.Debug("rawHash = " + rawHash);

            MoMoSecurity crypto = new MoMoSecurity();
            //sign signature SHA256
            string signature = crypto.signSHA256(rawHash, serectkey);

            log.Debug("Signature = " + signature);

            //build body json request
            JObject message = new JObject
            {
                { "partnerCode", partnerCode },
                { "accessKey", accessKey },
                { "requestId", requestId },
                { "amount", amount },
                { "orderId", orderid },
                { "orderInfo", orderInfo },
                { "returnUrl", returnUrl },
                { "notifyUrl", notifyurl },
                { "requestType", "captureMoMoWallet" },
                { "signature", signature }
            };

            log.Debug("Json request to MoMo: " + message.ToString());
            string responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString());

            textPubkey.Text = responseFromMomo;
            JObject jmessage = JObject.Parse(responseFromMomo);

            log.Debug("Return from MoMo: " + jmessage.ToString());
            DialogResult result = MessageBox.Show(responseFromMomo, "Open in browser", MessageBoxButtons.OKCancel);

            if (result == DialogResult.OK)
            {
                //yes...
                System.Diagnostics.Process.Start(jmessage.GetValue("payUrl").ToString());
            }
            else if (result == DialogResult.Cancel)
            {
                //no...
            }
        }
示例#4
0
        private void button1_Click(object sender, EventArgs e)
        {
            //request params need to request to MoMo system
            string endpoint    = textEndpoint.Text.Equals("") ? "https://test-payment.momo.vn/v2/gateway/api/create" : textEndpoint.Text;
            string partnerCode = textPartnerCode.Text;
            string accessKey   = textAccessKey.Text;
            string serectkey   = "nqQiVSgDMy809JoPF6OzP5OdBUB550Y4";
            string orderInfo   = textOrderInfo.Text;
            string redirectUrl = textReturn.Text;
            string ipnUrl      = textNotify.Text;
            string requestType = "captureWallet";

            string amount    = textAmount.Text;
            string orderId   = Guid.NewGuid().ToString();
            string requestId = Guid.NewGuid().ToString();
            string extraData = "";

            //Before sign HMAC SHA256 signature
            string rawHash = "accessKey=" + accessKey +
                             "&amount=" + amount +
                             "&extraData=" + extraData +
                             "&ipnUrl=" + ipnUrl +
                             "&orderId=" + orderId +
                             "&orderInfo=" + orderInfo +
                             "&partnerCode=" + partnerCode +
                             "&redirectUrl=" + redirectUrl +
                             "&requestId=" + requestId +
                             "&requestType=" + requestType
            ;

            log.Debug("rawHash = " + rawHash);

            MoMoSecurity crypto = new MoMoSecurity();
            //sign signature SHA256
            string signature = crypto.signSHA256(rawHash, serectkey);

            log.Debug("Signature = " + signature);

            //build body json request
            JObject message = new JObject
            {
                { "partnerCode", partnerCode },
                { "partnerName", "Test" },
                { "storeId", "MomoTestStore" },
                { "requestId", requestId },
                { "amount", amount },
                { "orderId", orderId },
                { "orderInfo", orderInfo },
                { "redirectUrl", redirectUrl },
                { "ipnUrl", ipnUrl },
                { "lang", "en" },
                { "extraData", extraData },
                { "requestType", requestType },
                { "signature", signature }
            };

            log.Debug("Json request to MoMo: " + message.ToString());
            string responseFromMomo = PaymentRequest.sendPaymentRequest(endpoint, message.ToString());

            JObject jmessage = JObject.Parse(responseFromMomo);

            log.Debug("Return from MoMo: " + jmessage.ToString());
            DialogResult result = MessageBox.Show(responseFromMomo, "Open in browser", MessageBoxButtons.OKCancel);

            if (result == DialogResult.OK)
            {
                //yes...
                System.Diagnostics.Process.Start(jmessage.GetValue("payUrl").ToString());
            }
            else if (result == DialogResult.Cancel)
            {
                //no...
            }
        }