Ejemplo n.º 1
0
        public void ThreeDSecurePayment()
        {
            PayOnClient threeDSecureClient = new PayOnClient(EntityId_ThreeDPayment, UserId, Password, BaseUrl, TestMode);

            CardAccount[] cardAccounts = TestData.GetTestPaymentCardAccounts()
                                         .Where(x => x.ThreeDSecure)
                                         .ToArray();

            foreach (var cardAccount in cardAccounts)
            {
                int idx = Array.FindIndex(cardAccounts, x => x == cardAccount) + 1;
                Log($"\nTest card: {idx}/{cardAccounts.Count()}");

                ThreeDSecurePaymentRequest request = new ThreeDSecurePaymentRequest
                {
                    PaymentBrand     = cardAccount.PaymentBrand,
                    Amount           = "123.45",
                    Card             = cardAccount,
                    Currency         = "ZAR",
                    Timestamp        = DateTime.Now.ToIso8601String(),
                    ShopperResultUrl = "https://newco/payment/confirm"
                };

                Log("3D Secure Request", JsonConvert.SerializeObject(request));
                ThreeDSecurePaymentResponse response = threeDSecureClient.RequestThreeDSecurePayment(request);
                Log("3D Secure Response", JsonConvert.SerializeObject(response));

                Assert.Equal(ResultStatus.Pending, response.Result.GetResultStatus());

                AcsRequest acsRequest = _payOnHttpClient.GetAcsRequestAsync(response).Result;

                Log("ACS Request", JsonConvert.SerializeObject(acsRequest));
                Assert.True(acsRequest.IsValid);
                AcsResponse acsResponse = _payOnHttpClient.PostAcsRequestAsync(acsRequest).Result;
                Log("ACS Response", JsonConvert.SerializeObject(acsResponse));

                Assert.True(acsResponse.IsValid);

                AcsRedirectResponse acsRedirectResponse = _payOnHttpClient.GetAcsRedirectResponseAsync(acsResponse).Result;

                Log("ACS Redirect Response", JsonConvert.SerializeObject(acsRedirectResponse));
                Assert.True(acsRedirectResponse.IsValid);
                ThreeDSecurePaymentStatusResponse paymentStatus = threeDSecureClient.RequestThreeDSecurePaymentStatus(acsRedirectResponse.Id);
                Log("3D Secure Payment Status", JsonConvert.SerializeObject(paymentStatus));

                Assert.Equal(ResultStatus.Approved, paymentStatus.Result.GetResultStatus());
            }
        }
Ejemplo n.º 2
0
        public async Task <AcsRedirectResponse> GetAcsRedirectResponseAsync(AcsResponse acsResponse)
        {
            HttpClient         client  = new HttpClient();
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, acsResponse.RedirectUrl);

            LogRequest(request);

            HttpResponseMessage response = await client.SendAsync(request);

            string html = await response.Content.ReadAsStringAsync();

            HtmlDocument htmlDoc = new HtmlDocument(html);

            return(new AcsRedirectResponse {
                Id = htmlDoc.GetValue("input[name$=\"id\"]")
            });
        }
Ejemplo n.º 3
0
        private PaymentStatusResponse RequestPaymentStatus(PayOnClient threeDSecureClient, CardAccount cardAccount, Redirect redirect)
        {
            AcsRequest acsRequest = _payOnHttpClient.GetAcsRequestAsync(redirect).Result;

            Log("ACS Request", JsonConvert.SerializeObject(acsRequest));
            AcsResponse acsResponse = _payOnHttpClient.PostAcsRequestAsync(acsRequest).Result;

            Log("ACS Response", JsonConvert.SerializeObject(acsResponse));

            AcsRedirectResponse acsRedirectResponse = _payOnHttpClient.GetAcsRedirectResponseAsync(acsResponse).Result;

            Log("ACS Redirect Response", JsonConvert.SerializeObject(acsRedirectResponse));
            PaymentStatusResponse paymentStatus = threeDSecureClient.RequestPaymentStatus(acsRedirectResponse.Id);

            Log("3D Secure Payment Status", JsonConvert.SerializeObject(paymentStatus));

            return(paymentStatus);
        }