Esempio n. 1
0
        public void CardHolderIsEnrolledACSInvalid()
        {
            var card = new CreditCardData {
                Number         = "4012001037490006",
                ExpMonth       = 12,
                ExpYear        = 2025,
                CardHolderName = "John Smith"
            };

            var enrolled = card.VerifyEnrolled(10m, "USD");

            Assert.IsTrue(enrolled);

            // authenticate
            var secureEcom   = card.ThreeDSecure;
            var authClient   = new ThreeDSecureAcsClient(secureEcom.IssuerAcsUrl);
            var authResponse = authClient.Authenticate(secureEcom.PayerAuthenticationRequest, secureEcom.MerchantData.ToString());

            // expand return data
            string payerAuthenticationResponse = authResponse.pares;
            MerchantDataCollection md          = MerchantDataCollection.Parse(authResponse.md);

            // verify signature
            card.VerifySignature(payerAuthenticationResponse, md);
        }
Esempio n. 2
0
        public void CardHolderIsEnrolledACSUnavailable()
        {
            var card = new CreditCardData {
                Number         = "4012001037484447",
                ExpMonth       = 12,
                ExpYear        = 2025,
                CardHolderName = "John Smith"
            };

            var enrolled = card.VerifyEnrolled(10m, "USD");

            Assert.IsTrue(enrolled);

            // authenticate
            var secureEcom   = card.ThreeDSecure;
            var authClient   = new ThreeDSecureAcsClient(secureEcom.IssuerAcsUrl);
            var authResponse = authClient.Authenticate(secureEcom.PayerAuthenticationRequest, secureEcom.MerchantData.ToString());

            // expand return data
            string payerAuthenticationResponse = authResponse.pares;
            MerchantDataCollection md          = MerchantDataCollection.Parse(authResponse.md);

            // verify signature
            var verified = card.VerifySignature(payerAuthenticationResponse, md);

            Assert.IsFalse(verified);
            Assert.AreEqual("U", card.ThreeDSecure.Status);
            Assert.AreEqual(7, card.ThreeDSecure.Eci);

            // complete the charge anyways
            var response = card.Charge().Execute();

            Assert.IsNotNull(response);
            Assert.AreEqual("00", response.ResponseCode);
        }
Esempio n. 3
0
        public void FullCycleWithMerchantData()
        {
            var card = new CreditCardData {
                Number         = "4012001037141112",
                ExpMonth       = 12,
                ExpYear        = 2025,
                CardHolderName = "John Smith"
            };

            var enrolled = card.VerifyEnrolled(1m, "USD");

            if (enrolled)
            {
                var secureEcom = card.ThreeDSecure;
                if (secureEcom != null)
                {
                    // reset merchant data
                    secureEcom.MerchantData = new MerchantDataCollection {
                        { "client_txn_id", "123456" }
                    };

                    // authenticate
                    var authClient   = new ThreeDSecureAcsClient(secureEcom.IssuerAcsUrl);
                    var authResponse = authClient.Authenticate(secureEcom.PayerAuthenticationRequest, secureEcom.MerchantData.ToString());

                    // expand return data
                    string payerAuthenticationResponse = authResponse.pares;
                    MerchantDataCollection md          = MerchantDataCollection.Parse(authResponse.md);

                    // verify signature
                    if (card.VerifySignature(payerAuthenticationResponse, md))
                    {
                        var response = card.Charge()
                                       .Execute();
                        Assert.IsNotNull(response);
                        Assert.AreEqual("00", response.ResponseCode);
                    }
                    else
                    {
                        Assert.Fail("Signature verification failed.");
                    }
                }
                else
                {
                    Assert.Fail("Secure3Data was null.");
                }
            }
            else
            {
                Assert.Fail("Card not enrolled.");
            }
        }
Esempio n. 4
0
        public void FullCycle_v1()
        {
            CreditCardData card = new CreditCardData {
                Number         = "4012001037141112",
                ExpMonth       = 12,
                ExpYear        = 2025,
                CardHolderName = "John Smith"
            };

            ThreeDSecure secureEcom = Secure3dService.CheckEnrollment(card)
                                      .WithAmount(1m)
                                      .WithCurrency("USD")
                                      .Execute(Secure3dVersion.One);

            Assert.AreEqual(Secure3dVersion.One, secureEcom.Version);

            if (secureEcom.Enrolled.Equals("Y"))
            {
                // authenticate
                ThreeDSecureAcsClient authClient = new ThreeDSecureAcsClient(secureEcom.IssuerAcsUrl);
                var authResponse = authClient.Authenticate(secureEcom.PayerAuthenticationRequest, secureEcom.MerchantData.ToString());

                string payerAuthenticationResponse = authResponse.pares;
                MerchantDataCollection md          = MerchantDataCollection.Parse(authResponse.md);

                // verify signature through the service and affix to the card object
                secureEcom = Secure3dService.GetAuthenticationData()
                             .WithPayerAuthenticationResponse(payerAuthenticationResponse)
                             .WithMerchantData(md)
                             .Execute();
                card.ThreeDSecure = secureEcom;

                if (secureEcom.Status.Equals("Y"))
                {
                    Transaction response = card.Charge().Execute();
                    Assert.IsNotNull(response);
                    Assert.AreEqual("00", response.ResponseCode);
                }
                else
                {
                    Assert.Fail("Signature verification Assert.Failed.");
                }
            }
            else
            {
                Assert.Fail("Card not enrolled.");
            }
        }
Esempio n. 5
0
        public void MerchantDataEncryptAndDecrypt()
        {
            var merchantData = new MerchantDataCollection {
                { "customer_id", "12345" },
                { "invoice_number", "54321" }
            };

            var encrypted = merchantData.ToString((input) => {
                var encoded = string.Format("{0}.{1}", input, "secret");
                return(Convert.ToBase64String(Encoding.UTF8.GetBytes(encoded)));
            });

            var decrypted = MerchantDataCollection.Parse(encrypted, (input) => {
                var decoded = Encoding.UTF8.GetString(Convert.FromBase64String(input)).Split('.');
                Assert.AreEqual("secret", decoded[1]);
                return(decoded[0]);
            });

            Assert.IsNotNull(decrypted);
            Assert.IsNotNull(decrypted["customer_id"]);
            Assert.AreEqual("12345", decrypted["customer_id"]);
            Assert.IsNotNull(decrypted["invoice_number"]);
            Assert.AreEqual("54321", decrypted["invoice_number"]);
        }
Esempio n. 6
0
        public void FullCycle_Any()
        {
            ThreeDSecure secureEcom = Secure3dService.CheckEnrollment(card)
                                      .WithAmount(1m)
                                      .WithCurrency("USD")
                                      .Execute(Secure3dVersion.Any);

            Assert.IsNotNull(secureEcom);

            if (secureEcom.Enrolled.Equals("True"))
            {
                if (secureEcom.Version.Equals(Secure3dVersion.Two))
                {
                    // initiate authentication
                    ThreeDSecure initAuth = Secure3dService.InitiateAuthentication(card, secureEcom)
                                            .WithAmount(10.01m)
                                            .WithCurrency("USD")
                                            .WithOrderCreateDate(DateTime.Now)
                                            .WithAddress(billingAddress, AddressType.Billing)
                                            .WithAddress(shippingAddress, AddressType.Shipping)
                                            .WithBrowserData(browserData)
                                            .Execute();
                    Assert.IsNotNull(initAuth);

                    // get authentication data
                    secureEcom = Secure3dService.GetAuthenticationData()
                                 .WithServerTransactionId(initAuth.ServerTransactionId)
                                 .Execute();
                    card.ThreeDSecure = secureEcom;

                    if (secureEcom.Status.Equals("AUTHENTICATION_SUCCESSFUL"))
                    {
                        Transaction response = card.Charge(10.01m)
                                               .WithCurrency("USD")
                                               .Execute();
                        Assert.IsNotNull(response);
                        Assert.AreEqual("00", response.ResponseCode);
                    }
                    else
                    {
                        Assert.Fail("Signature verification Assert.Failed.");
                    }
                }
                else
                {
                    // authenticate
                    ThreeDSecureAcsClient authClient = new ThreeDSecureAcsClient(secureEcom.IssuerAcsUrl);
                    var authResponse = authClient.Authenticate(secureEcom.PayerAuthenticationRequest, secureEcom.MerchantData.ToString());

                    string payerAuthenticationResponse = authResponse.getAuthResponse();
                    MerchantDataCollection md          = MerchantDataCollection.Parse(authResponse.getMerchantData());

                    // verify signature through the service and affix to the card object
                    secureEcom = Secure3dService.GetAuthenticationData()
                                 .WithPayerAuthenticationResponse(payerAuthenticationResponse)
                                 .WithMerchantData(md)
                                 .Execute();
                    card.ThreeDSecure = secureEcom;

                    if (secureEcom.Status.Equals("Y"))
                    {
                        Transaction response = card.Charge().Execute();
                        Assert.IsNotNull(response);
                        Assert.AreEqual("00", response.ResponseCode);
                    }
                    else
                    {
                        Assert.Fail("Signature verification Assert.Failed.");
                    }
                }
            }
            else
            {
                Assert.Fail("Card not enrolled.");
            }
        }