示例#1
0
        public async Task <ActionResult> OnceOff(string email)
        {
            var onceOffRequest = new PayGateRequest(payGateSettings.PayGateKey);

            onceOffRequest.PAYGATE_ID = payGateSettings.PayGateID;
            onceOffRequest.LOCALE     = payGateSettings.Locale;
            onceOffRequest.COUNTRY    = payGateSettings.Country;
            onceOffRequest.CURRENCY   = payGateSettings.Currency;
            onceOffRequest.RETURN_URL = payGateSettings.ReturnURL;
            onceOffRequest.NOTIFY_URL = payGateSettings.NotifyURL;

            // Get config setting for testing purposes.
            if (string.IsNullOrEmpty(email))
            {
                email = ConfigurationManager.AppSettings["ConfirmationEmail"];
            }
            // This should be the client's confirmation email address.
            onceOffRequest.EMAIL = email;

            onceOffRequest.AMOUNT           = 30000;
            onceOffRequest.REFERENCE        = "PayGate MVC Demo - R 300 Option";
            onceOffRequest.TRANSACTION_DATE = DateTime.Now;

            // TODO: Rethink this...
            var requestString = onceOffRequest.ToString();

            var content = new StringContent(requestString, Encoding.UTF8, "application/x-www-form-urlencoded");

            var response = await httpClient.PostAsync(payGateSettings.InitiateURL, content);

            var responseContent = await response.Content.ReadAsStringAsync();

            var results = ToDictionary(responseContent);

            if (results.Keys.Contains("ERROR"))
            {
                // TODO: Add proper error handling.
                return(View("Error"));
            }

            PayGateResponse payGateResponse = new PayGateResponse(payGateSettings.PayGateKey);

            payGateResponse.MapResponse(results);

            if (payGateResponse.CHECKSUM != results["CHECKSUM"])
            {
                // TODO: Add proper error handling.
                return(View("Error"));
            }

            // TODO: Reconsider this approach. Should we really add this to the session?
            Session.Add("PAY_REQUEST_ID", payGateResponse.PAY_REQUEST_ID);
            Session.Add("REFERENCE", onceOffRequest.REFERENCE);

            // This view should be used for confirmation from user.
            return(View("PayWeb", payGateResponse));
        }
示例#2
0
        public void CreateResponseChecksum()
        {
            // Arrange
            var secret          = "secret";
            var payGateResponse = new PayGateResponse(secret);

            payGateResponse.PAYGATE_ID     = "10011072130";
            payGateResponse.PAY_REQUEST_ID = "26F1EE9D-FB68-D6C2-5D36-ADA8C5F88BC9";
            payGateResponse.REFERENCE      = "PayGate Test";

            // Act
            var checksum = payGateResponse.CHECKSUM;

            // Assert
            Assert.AreEqual("f5563213b72cb405167ba53e8c3ee466", checksum);
        }