Exemple #1
0
        public async Task InitPayment_SpecifiedRequestEncodingAndReturnType_Succeeds(
            HttpRequestEncodingType encodingType, InitPaymentResponseType responseType)
        {
            var connection = new Connection(PlatronClient.PlatronUrl, SettingsStorage.Credentials, encodingType);
            var client     = new PlatronClient(connection);
            // To find out what really happens enable proxy (thru fiddler)
            // and use custom connection over http to watch plain requests
            //.EnableProxy(new WebProxy("http://localhost:8888", false));

            var initPayment = new InitPaymentRequest(1.Rub(), "Money first");

            initPayment.InTestMode();
            initPayment.OrderId = Guid.NewGuid().ToString("N");

            switch (responseType)
            {
            case InitPaymentResponseType.RedirectLink:
                var response = await client.InitPaymentAsync(initPayment);

                Assert.NotNull(response);
                break;

            case InitPaymentResponseType.HtmlForm:
                var html = await client.InitPaymentAsHtmlAsync(initPayment);

                Assert.NotNull(html);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(responseType), responseType, null);
            }
        }
        public void ResultUrl_ReturnOk_ValidXml()
        {
            var client = new PlatronClient(Samples.Credentials);
            var resultUrl = client.ResultUrl.Parse(Samples.ResultUrlWithValidSignature);

            var ok = client.ResultUrl.ReturnOk(resultUrl, "all done");
            Assert.NotNull(ok);
            Assert.NotNull(ok.Content);
        }
        public async Task InitPayment_InvalidMerchant_ThrowsInvalidResponse()
        {
            var initPayment = new InitPaymentRequest(1.Rur(), "sample description");
            var client = new PlatronClient("0000", "secret");

            var exception =
                await Assert.ThrowsAsync<ErrorApiException>(() => client.InitPaymentAsync(initPayment));
            Assert.Equal(ErrorCode.InvalidMerchant, exception.Error.Code);
        }
        public async Task InitPayment_InvalidSecretKey_ThrowsInvalidResponse()
        {
            var initPayment = new InitPaymentRequest(1.Rur(), "sample description");
            var client = new PlatronClient(SettingsStorage.Credentials.MerchantId, "secret");

            var exception =
                await Assert.ThrowsAsync<ErrorApiException>(() => client.InitPaymentAsync(initPayment));
            Assert.Equal(ErrorCode.InvalidSignature, exception.Error.Code);
        }
Exemple #5
0
        public async Task InitPayment_PlatronNotAvailableOrNotResolvable_ThrowsServiceNotAvailable(
            string notAvailableUrl, string description)
        {
            var initPayment = new InitPaymentRequest(1.Rub(), "sample description");

            var connection = new Connection(new Uri(notAvailableUrl), new Credentials("0000", "secret"), TimeSpan.FromSeconds(5));
            var client     = new PlatronClient(connection);

            await Assert.ThrowsAsync <ServiceNotAvailableApiException>(() => client.InitPaymentAsync(initPayment));
        }
Exemple #6
0
        public async Task InitPayment_InvalidMerchant_ThrowsInvalidResponse()
        {
            var initPayment = new InitPaymentRequest(1.Rub(), "sample description");
            var client      = new PlatronClient("0000", "secret");

            var exception =
                await Assert.ThrowsAsync <ErrorApiException>(() => client.InitPaymentAsync(initPayment));

            Assert.Equal(ErrorCode.InvalidMerchant, exception.Error.Code);
        }
        public async Task InitPayment_PlatronNotAvailableOrNotResolvable_ThrowsServiceNotAvailable(
            string notAvailableUrl, string description)
        {
            var initPayment = new InitPaymentRequest(1.Rur(), "sample description");

            var connection = new Connection(new Uri(notAvailableUrl), new Credentials("0000", "secret"), TimeSpan.FromSeconds(5));
            var client = new PlatronClient(connection);

            await Assert.ThrowsAsync<ServiceNotAvailableApiException>(() => client.InitPaymentAsync(initPayment));
        }
Exemple #8
0
        public async Task InitPayment_InvalidSecretKey_ThrowsInvalidResponse()
        {
            var initPayment = new InitPaymentRequest(1.Usd(), "sample description");
            var client      = new PlatronClient(SettingsStorage.Credentials.MerchantId, "secret");

            var exception =
                await Assert.ThrowsAsync <ErrorApiException>(() => client.InitPaymentAsync(initPayment));

            Assert.Equal(ErrorCode.InvalidSignature, exception.Error.Code);
        }
        public void ResultUrl_ReturnOk_ValidXml()
        {
            var client    = new PlatronClient(Samples.Credentials);
            var resultUrl = client.ResultUrl.Parse(Samples.ResultUrlWithValidSignature);

            var ok = client.ResultUrl.ReturnOk(resultUrl, "all done");

            Assert.NotNull(ok);
            Assert.NotNull(ok.Content);
        }
        public async Task InitPayment_ValidMerchant_Succeeds()
        {
            var initPayment = new InitPaymentRequest(1.Usd(), "sample description");
            var client = new PlatronClient(SettingsStorage.Credentials);

            initPayment.InTestMode();
            var response = await client.InitPaymentAsync(initPayment);

            Assert.NotNull(response);
            Assert.NotNull(response.RedirectUrl);
        }
Exemple #11
0
        public async Task InitPayment_ValidMerchant_Succeeds()
        {
            var initPayment = new InitPaymentRequest(1.Rub(), "sample description");
            var client      = new PlatronClient(SettingsStorage.Credentials);

            initPayment.InTestMode();
            var response = await client.InitPaymentAsync(initPayment);

            Assert.NotNull(response);
            Assert.NotNull(response.RedirectUrl);
        }
            public PlatronModule(PlatronClient platronClient)
            {
                // IoC container will make us super-duper happy and gives us a client.
                _platronClient = platronClient;

                Get["/platron/result", true] = async (_, ct) =>
                {
                    CallbackResponse response = await CompleteOrderAsync(Request.Url);
                    return AsXml(response);
                };
            }
            public PlatronModule(PlatronClient platronClient)
            {
                // IoC container will make us super-duper happy and gives us a client.
                _platronClient = platronClient;

                Get["/platron/result", true] = async(_, ct) =>
                {
                    CallbackResponse response = await CompleteOrderAsync(Request.Url);

                    return(AsXml(response));
                };
            }
Exemple #14
0
        public async Task InitPaymentAsHtml_InvalidMerchant_ReturnsHtml()
        {
            var initPayment = new InitPaymentRequest(1.Rub(), "sample description");

            initPayment.Language = PlatronLanguage.English; // doesn't work. still in russian

            var client = new PlatronClient("0000", "secret");

            initPayment.InTestMode();
            var html = await client.InitPaymentAsHtmlAsync(initPayment);

            Assert.True(html.Content.Contains("Incorrect merchant"));
        }
        public async Task InitPaymentAsHtml_ValidMerchant_ReturnsHtml()
        {
            var initPayment = new InitPaymentRequest(1.Eur(), "sample description");
            var client = new PlatronClient(SettingsStorage.Credentials);

            initPayment.InTestMode();
            var html = await client.InitPaymentAsHtmlAsync(initPayment);

            // requestUri contains redirect uri: https://www.platron.ru/payment_params.php?customer=f00e1b48ea91013cc7a40242f218e68821586740
            Assert.NotNull(html.RequestUri);

            // and requestUri contains 'customer' which hides inside html too:
            // <input type="hidden" name="customer" value="f00e1b48ea91013cc7a40242f218e68821586740">
            var customer = html.RequestUri.Query.Split('=').Last();
            Assert.True(html.Content.Contains(customer));
        }
Exemple #16
0
        public async Task InitPaymentAsHtml_ValidMerchant_ReturnsHtml()
        {
            var initPayment = new InitPaymentRequest(1.Eur(), "sample description");
            var client      = new PlatronClient(SettingsStorage.Credentials);

            initPayment.InTestMode();
            var html = await client.InitPaymentAsHtmlAsync(initPayment);

            // requestUri contains redirect uri: https://www.platron.ru/payment_params.php?customer=f00e1b48ea91013cc7a40242f218e68821586740
            Assert.NotNull(html.RequestUri);

            // and requestUri contains 'customer' which hides inside html too:
            // <input type="hidden" name="customer" value="f00e1b48ea91013cc7a40242f218e68821586740">
            var customer = html.RequestUri.Query.Split('=').Last();

            Assert.True(html.Content.Contains(customer));
        }
        public async Task GettingStarted_SampleClient_Succeeds()
        {
            var credentials = new Credentials("0000", "asdffsasdfasdfasdf");
            var client = new PlatronClient(credentials);

            // ensure that your server listens on that address and accepts GET request
            var resultUrl = new Uri("https://my.server.com/platron/result");

            var request = new InitPaymentRequest(1.Rub(), "Order payment")
            {
                OrderId = "#1234567890",
                UserPhone = "+79990001112",
                ResultUrl = resultUrl
            };

            InitPaymentResponse response = await client.InitPaymentAsync(request).ConfigureAwait(false);
            await SendToUserAsync(response.RedirectUrl).ConfigureAwait(false);
        }
        public async Task GettingStarted_SampleClient_Succeeds()
        {
            var credentials = new Credentials("0000", "asdffsasdfasdfasdf");
            var client      = new PlatronClient(credentials);

            // ensure that your server listens on that address and accepts GET request
            var resultUrl = new Uri("https://my.server.com/platron/result");

            var request = new InitPaymentRequest(1.Rub(), "Order payment")
            {
                OrderId   = "#1234567890",
                UserPhone = "+79990001112",
                ResultUrl = resultUrl
            };

            InitPaymentResponse response = await client.InitPaymentAsync(request).ConfigureAwait(false);

            await SendToUserAsync(response.RedirectUrl).ConfigureAwait(false);
        }
Exemple #19
0
        public async Task FullPayment_ManualPaymentThruBrowser_Succeeds()
        {
            var connection = new Connection(PlatronClient.PlatronUrl, SettingsStorage.Credentials,
                                            HttpRequestEncodingType.PostWithQueryString);

            var client = new PlatronClient(connection);

            var initPaymentRequest = new InitPaymentRequest(1.01.Rub(), "verifying resulturl")
            {
                ResultUrl = _server.ResultUrl,
                UserPhone = SettingsStorage.PhoneNumber,
                OrderId   = Guid.NewGuid().ToString("N"),
                NeedUserPhoneNotification = true
            };

            // enables only test systems
            //initPaymentRequest.InTestMode();

            var response = await client.InitPaymentAsync(initPaymentRequest);

            // open browser = selenium can be here ^)
            Assert.NotNull(response);
            Assert.NotNull(response.RedirectUrl);
            Browser.Open(response.RedirectUrl);

            // we have some time to manually finish payment.
            var request = _server.WaitForRequest(TimeSpan.FromMinutes(3));

            _output.WriteLine(request.Uri.AbsoluteUri);

            var resultUrl = client.ResultUrl.Parse(request.Uri);

            // to return money back - it's enough to reject payment
            // and hope that your payment service supports it.
            var resultUrlResponse = client.ResultUrl.TryReturnReject(resultUrl, "sorry, my bad...");

            _output.WriteLine(resultUrlResponse.Content);

            request.SendResponse(resultUrlResponse.Content);
        }
        public void ResultUrl_ValidUri_Succeeds()
        {
            var client = new PlatronClient(Samples.Credentials);

            client.ResultUrl.Parse(Samples.ResultUrlWithValidSignature);
        }
        public async Task InitPayment_SpecifiedRequestEncodingAndReturnType_Succeeds(
            HttpRequestEncodingType encodingType, InitPaymentResponseType responseType)
        {
            var connection = new Connection(PlatronClient.PlatronUrl, SettingsStorage.Credentials, encodingType);
            var client = new PlatronClient(connection);
            // To find out what really happens enable proxy (thru fiddler)
            // and use custom connection over http to watch plain requests
            //.EnableProxy(new WebProxy("http://localhost:8888", false));

            var initPayment = new InitPaymentRequest(1.Rur(), "Money first");
            initPayment.InTestMode();
            initPayment.OrderId = Guid.NewGuid().ToString("N");

            switch (responseType)
            {
                case InitPaymentResponseType.RedirectLink:
                    var response = await client.InitPaymentAsync(initPayment);
                    Assert.NotNull(response);
                    break;
                case InitPaymentResponseType.HtmlForm:
                    var html = await client.InitPaymentAsHtmlAsync(initPayment);
                    Assert.NotNull(html);
                    break;
                default:
                    throw new ArgumentOutOfRangeException(nameof(responseType), responseType, null);
            }
        }
        public async Task InitPaymentAsHtml_InvalidMerchant_ReturnsHtml()
        {
            var initPayment = new InitPaymentRequest(1.Rur(), "sample description");
            initPayment.Language = PlatronLanguage.English; // doesn't work. still in russian

            var client = new PlatronClient("0000", "secret");

            initPayment.InTestMode();
            var html = await client.InitPaymentAsHtmlAsync(initPayment);

            Assert.True(html.Content.Contains("Incorrect merchant"));
        }
 public void ResultUrl_ValidUri_Succeeds()
 {
     var client = new PlatronClient(Samples.Credentials);
     client.ResultUrl.Parse(Samples.ResultUrlWithValidSignature);
 }