Пример #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 ChecksumWithAllOptionalFieldsEmpty()
        {
            // Arrange
            var secret         = "secret";
            var payGateRequest = new PayGateRequest(secret);

            payGateRequest.PAYGATE_ID       = "10011072130";
            payGateRequest.REFERENCE        = "PayGate Test";
            payGateRequest.AMOUNT           = 3299;
            payGateRequest.CURRENCY         = "ZAR";
            payGateRequest.RETURN_URL       = "https://www.paygate.co.za/thankyou";
            payGateRequest.TRANSACTION_DATE = DateTime.Parse("2016-03-10 10:49:16");
            payGateRequest.LOCALE           = "en";
            payGateRequest.COUNTRY          = "ZAF";
            payGateRequest.EMAIL            = "*****@*****.**";

            // Act
            var checksum = payGateRequest.CHECKSUM;

            // Assert
            Assert.AreEqual("0bcaea6fa6bc0337e066db9826088557", checksum);
        }