Example #1
0
        public void MGClientConstructorShouldFail()
        {
            // Arrange
            MGClient         client  = new MGClient(useConstantUrl: false);
            MGDepositRequest request = new MGDepositRequest();
            string           expectedErrorMessage = "MGClient missing parameters: endpoint merchantSecret requestUrl merchantId";

            // Act
            MGDepositResult actual = client.InitDeposit(request).Result;

            // Assert
            Assert.IsFalse(actual.IsSuccess);
            Assert.AreEqual(expectedErrorMessage, actual.Message);
        }
Example #2
0
        public void DepositSuccess()
        {
            // Arrange
            MGDepositResult expectedResult = new MGDepositResult()
            {
                IsSuccess = true,
                Code      = "200",
                Message   = null,
                Data      = new DepositResponseData()
                {
                    DepositUrl      = "https://api.zotapay.com/api/v1/deposit/init/8b3a6b89697e8ac8f45d964bcc90c7ba41764acd/",
                    MerchantOrderID = "QvE8dZshpKhaOmHY",
                    OrderID         = "8b3a6b89697e8ac8f45d964bcc90c7ba41764acd",
                }
            };
            string   messageSuccess = "{ \"code\": \"200\", \"data\": { \"depositUrl\": \"https://api.zotapay.com/api/v1/deposit/init/8b3a6b89697e8ac8f45d964bcc90c7ba41764acd/\", \"merchantOrderID\": \"QvE8dZshpKhaOmHY\", \"orderID\": \"8b3a6b89697e8ac8f45d964bcc90c7ba41764acd\" } }";
            var      httpMock       = Mocks.GetMockedHttp(HttpStatusCode.OK, messageSuccess);
            MGClient client         = Mocks.GetMockedMGClient(httpClient: httpMock);
            var      DepositRequest = new MGDepositRequest
            {
                MerchantOrderID     = "QvE8dZshpKhaOmHY",
                OrderAmount         = "100.00",
                CustomerEmail       = "*****@*****.**",
                OrderCurrency       = "USD",
                MerchantOrderDesc   = "desc",
                CustomerFirstName   = "John",
                CustomerLastName    = "Doe",
                CustomerAddress     = "The Moon, hill 42",
                CustomerCity        = "Sofia",
                CustomerCountryCode = "BG",
                CustomerZipCode     = "1303",
                CustomerPhone       = "123",
                CustomerIP          = "127.0.0.1",
                RedirectUrl         = "https://example-merchant.com/payment/return",
                CheckoutUrl         = "https://example-merchant.com/deposit"
            };

            // Act
            MGDepositResult actual = client.InitDeposit(DepositRequest).Result;

            // Assert
            Assert.IsTrue(actual.IsSuccess);
            Assert.AreEqual(expectedResult.Data.DepositUrl, actual.Data.DepositUrl);
            Assert.AreEqual(expectedResult.Data.MerchantOrderID, actual.Data.MerchantOrderID);
            Assert.AreEqual(expectedResult.Data.OrderID, actual.Data.OrderID);
            Assert.AreEqual(expectedResult.Code, actual.Code);
            Assert.AreEqual(expectedResult.Message, actual.Message);
        }
Example #3
0
        public void DepositCatchesUnexpectedResponse()
        {
            // Arrange
            string   responseMessage      = "!@#$%^&*() -- not a valid json message, that will cause an exception -- !@#$%^&*()";
            var      httpMock             = Mocks.GetMockedHttp(HttpStatusCode.InternalServerError, responseMessage);
            MGClient client               = Mocks.GetMockedMGClient(httpClient: httpMock);
            var      DepositRequest       = Mocks.GetFullDepositRequest();
            string   expectedErrorMessage = "Unexpected character encountered while parsing value: !. Path '', line 0, position 0.: \n" +
                                            "Raw Response: !@#$%^&*() -- not a valid json message, that will cause an exception -- !@#$%^&*()";

            // Act
            MGDepositResult actual = client.InitDeposit(DepositRequest).Result;

            // Assert
            Assert.IsFalse(actual.IsSuccess);
            Assert.AreEqual(expectedErrorMessage, actual.Message);
        }
Example #4
0
        public void EmptyRequestShowsFullErrorMessage()
        {
            // Arrange
            MGClient         clientMock           = Mocks.GetMockedMGClient(null);
            MGDepositRequest depositRequest       = new MGDepositRequest();
            string           expectedErrorMessage = "The MerchantOrderID field is required. | The MerchantOrderDesc field is required. |" +
                                                    " The OrderAmount field is required. | The OrderCurrency field is required. | The CustomerFirstName field is required. |" +
                                                    " The CustomerLastName field is required. | The CustomerAddress field is required. | The CustomerCountryCode field is required. |" +
                                                    " The CustomerCity field is required. | The CustomerZipCode field is required. | The CustomerPhone field is required. |" +
                                                    " The CustomerIP field is required. | The RedirectUrl field is required. | The CheckoutUrl field is required.";

            // Act
            MGDepositResult actualDepositResult = clientMock.InitDeposit(depositRequest).Result;

            // Assert
            Assert.IsFalse(actualDepositResult.IsSuccess);
            Assert.AreEqual(expectedErrorMessage, actualDepositResult.Message);
        }
Example #5
0
        public static void DepositExample(MGClient client)
        {
            // Assemble deposit order data
            MGDepositRequest DepositOrderRequest = new MGDepositRequest
            {
                MerchantOrderID     = "QvE8dZshpKhaOmHY1",
                OrderAmount         = "100.00",
                CustomerEmail       = "*****@*****.**",
                OrderCurrency       = "USD",
                MerchantOrderDesc   = "desc",
                CustomerFirstName   = "John",
                CustomerLastName    = "Doe",
                CustomerAddress     = "The Moon, hill 42",
                CustomerCity        = "Sofia",
                CustomerCountryCode = "BG",
                CustomerZipCode     = "1303",
                CustomerPhone       = "123",
                CustomerIP          = "127.0.0.1",
                RedirectUrl         = "https://example-merchant.com/payment/return",
                CheckoutUrl         = "https://example-merchant.com/deposit",
                CallbackUrl         = "https://example-merchant.com/payment/callback",
            };

            // Initiate deposit order request
            MGDepositResult resp = client.InitDeposit(DepositOrderRequest).Result;

            // Check the request status
            if (!resp.IsSuccess)
            {
                // handle unsuccessful request
                string reasonForFailure = resp.Message;
                // ...
                return;
            }

            // Redirect the end user to the payment url
            string paymentUrl = resp.Data.DepositUrl;

            Console.WriteLine(paymentUrl);
        }
Example #6
0
        public void DepositUnsuccessful()
        {
            // Arrange
            MGDepositResult expectedResult = new MGDepositResult()
            {
                IsSuccess = false,
                Code      = "400",
                Message   = "endpoint currency mismatch",
                Data      = null,
            };
            string   responseMessage = "{ \"code\": \"400\", \"message\": \"endpoint currency mismatch\" } ";
            var      httpMock        = Mocks.GetMockedHttp(HttpStatusCode.BadRequest, responseMessage);
            MGClient client          = Mocks.GetMockedMGClient(httpClient: httpMock);
            var      DepositRequest  = Mocks.GetFullDepositRequest();

            // Act
            MGDepositResult actual = client.InitDeposit(DepositRequest).Result;

            // Assert
            Assert.IsFalse(actual.IsSuccess);
            Assert.AreEqual(expectedResult.Data, actual.Data);
            Assert.AreEqual(expectedResult.Code, actual.Code);
            Assert.AreEqual(expectedResult.Message, actual.Message);
        }