diff --git a/CHANGELOG.md b/CHANGELOG.md index c781cf2d..f1b0c60c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ -# unreleased +## 5.4.0 +- Add missing `ExpirationMonth`, `ExpirationYear`, and `IsNetworkTokenized` fields in `PaymentMethodNonceDetails` (thanks @glennsdavis for `ExpirationMonth` and `ExpirationYear`!) +- Add `ThreeDSecureAuthenticationInfo` and `ThreeDSecureLookupInfo` classes +- Add `AcsTransactionId`, `ParesStatus`, `ThreeDSecureTransactionId`, `Lookup`, and `Authentication` to `ThreeDSecureInfo` +- Add `DecisionReasons` and `TransactionRiskScore` fields to `RiskData` - Add overload on `SubmitForSettlementAsync` method to include `TransactionRequest` (thanks @edtyl3r!) -- Add `ExpirationMonth` and `ExpirationYear` to `PaymentMethodNonceDetails` (thanks @glennsdavis!) ## 5.3.0 - Add `scaExemption` to `Transaction` diff --git a/src/Braintree/Braintree.csproj b/src/Braintree/Braintree.csproj index d539ec95..393e6699 100644 --- a/src/Braintree/Braintree.csproj +++ b/src/Braintree/Braintree.csproj @@ -3,8 +3,8 @@ Braintree Client Library - Copyright © Braintree, a division of PayPal, Inc. 2020 - 5.3.0 + Copyright © Braintree, a division of PayPal, Inc. 2021 + 5.4.0 Braintree net452;netstandard2.0 @@ -12,17 +12,11 @@ Braintree braintree;paypal;venmo;intenational;payments;gateway;currencies;money;visa;mastercard;bitcoin;maestro;apple pay;android pay;amex;jcb;diners club;discover;american express - - Add scaExemption to Transaction - - Deprecate DeviceSessionId and FraudMerchantId in the CreditCardRequest and TransactionRequest classes - - Add currencyIsoCode field to TransactionRequest - - Add verificationCurrencyIsoCode field to CreditCardOptionsRequest and PaymentMethodOptionsRequest - - Add validation error codes: - - CREDIT_CARD_OPTIONS_VERIFICATION_INVALID_PRESENTMENT_CURRENCY - - TRANSACTION_INVALID_PRESENTMENT_CURRENCY - - Add Installments to TransactionRequest - - Add Count to InstallmentRequest - - Add Installments and RefundedInstallments to Transaction - - Add Adjustment to Installment + - Add missing `ExpirationMonth`, `ExpirationYear`, and `IsNetworkTokenized` fields in `PaymentMethodNonceDetails` (thanks @glennsdavis for `ExpirationMonth` and `ExpirationYear`!) + - Add `ThreeDSecureAuthenticationInfo` and `ThreeDSecureLookupInfo` classes + - Add `AcsTransactionId`, `ParesStatus`, `ThreeDSecureTransactionId`, `Lookup`, and `Authentication` to `ThreeDSecureInfo` + - Add `DecisionReasons` and `TransactionRiskScore` fields to `RiskData` + - Add overload on `SubmitForSettlementAsync` method to include `TransactionRequest` (thanks @edtyl3r!) https://github.com/braintree/braintree_dotnet false diff --git a/src/Braintree/PaymentMethodNonceDetails.cs b/src/Braintree/PaymentMethodNonceDetails.cs index 0c77aae3..a0a5d0af 100644 --- a/src/Braintree/PaymentMethodNonceDetails.cs +++ b/src/Braintree/PaymentMethodNonceDetails.cs @@ -4,27 +4,30 @@ namespace Braintree { public class PaymentMethodNonceDetails { + public virtual bool? IsNetworkTokenized { get; protected set; } public virtual string Bin { get; protected set; } - public virtual string LastTwo { get; protected set; } - public virtual string LastFour { get; protected set; } //NEXT_MAJOR_VERSION CardType should be an enum (see CreditCard class) public virtual string CardType { get; protected set; } - public virtual string ExpirationYear { get; protected set; } public virtual string ExpirationMonth { get; protected set; } + public virtual string ExpirationYear { get; protected set; } + public virtual string LastFour { get; protected set; } + public virtual string LastTwo { get; protected set; } public virtual string Username { get; protected set; } public virtual string VenmoUserId { get; protected set; } public virtual PaymentMethodNonceDetailsPayerInfo PayerInfo { get; protected set; } protected internal PaymentMethodNonceDetails(NodeWrapper node) { + IsNetworkTokenized = node.GetBoolean("is-network-tokenized"); Bin = node.GetString("bin"); CardType = node.GetString("card-type"); - LastTwo = node.GetString("last-two"); - LastFour = node.GetString("last-four"); - ExpirationYear = node.GetString("expiration-year"); ExpirationMonth = node.GetString("expiration-month"); + ExpirationYear = node.GetString("expiration-year"); + LastFour = node.GetString("last-four"); + LastTwo = node.GetString("last-two"); Username = node.GetString("username"); VenmoUserId = node.GetString("venmo-user-id"); + var payerInfoNode = node.GetNode("payer-info"); if (payerInfoNode != null) { @@ -34,12 +37,13 @@ protected internal PaymentMethodNonceDetails(NodeWrapper node) protected internal PaymentMethodNonceDetails(dynamic details) { + IsNetworkTokenized = details.isNetworkTokenized; Bin = details.bin; CardType = details.cardType; - LastTwo = details.lastTwo; - LastFour = details.lastFour; - ExpirationYear = details.expirationYear; ExpirationMonth = details.expirationMonth; + ExpirationYear = details.expirationYear; + LastFour = details.lastFour; + LastTwo = details.lastTwo; Username = details.username; VenmoUserId = details.venmoUserId; diff --git a/src/Braintree/Properties/AssemblyInfo.cs b/src/Braintree/Properties/AssemblyInfo.cs index 4cde110e..e09f9201 100644 --- a/src/Braintree/Properties/AssemblyInfo.cs +++ b/src/Braintree/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Braintree")] [assembly: AssemblyProduct("Braintree Payment Gateway Client API")] -[assembly: AssemblyCopyright("Copyright © Braintree, a division of PayPal, Inc. 2020")] +[assembly: AssemblyCopyright("Copyright © Braintree, a division of PayPal, Inc. 2021")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("Braintree.Tests")] @@ -32,5 +32,5 @@ // Build Number // Revision // -[assembly: AssemblyVersion("5.3.0.0")] -[assembly: AssemblyFileVersion("5.3.0.0")] +[assembly: AssemblyVersion("5.4.0.0")] +[assembly: AssemblyFileVersion("5.4.0.0")] diff --git a/src/Braintree/RiskData.cs b/src/Braintree/RiskData.cs index ffd758ac..82bc55fe 100644 --- a/src/Braintree/RiskData.cs +++ b/src/Braintree/RiskData.cs @@ -1,13 +1,19 @@ using System; +using System.Collections.Generic; namespace Braintree { public class RiskData { - public virtual string id { get; protected set; } + // NEXT_MAJOR_VERSION these should all be Pascal case, + // but we can't add those now without setting off a + // CLS-compliance error (CS3005) public virtual string decision { get; protected set; } + public virtual List DecisionReasons { get; protected set; } public virtual bool? deviceDataCaptured { get; protected set; } public virtual string fraudServiceProvider { get; protected set; } + public virtual string id { get; protected set; } + public virtual string TransactionRiskScore { get; protected set; } public RiskData(NodeWrapper node) { @@ -18,6 +24,12 @@ public RiskData(NodeWrapper node) decision = node.GetString("decision"); fraudServiceProvider = node.GetString("fraud-service-provider"); deviceDataCaptured = node.GetBoolean("device-data-captured"); + TransactionRiskScore = node.GetString("transaction-risk-score"); + DecisionReasons = new List(); + foreach (var stringNode in node.GetList("decision-reasons/item")) + { + DecisionReasons.Add(stringNode.GetString(".")); + } } [Obsolete("Mock Use Only")] diff --git a/src/Braintree/ThreeDSecureAuthenticationInfo.cs b/src/Braintree/ThreeDSecureAuthenticationInfo.cs new file mode 100644 index 00000000..008e5a64 --- /dev/null +++ b/src/Braintree/ThreeDSecureAuthenticationInfo.cs @@ -0,0 +1,30 @@ +using System; +namespace Braintree +{ + public class ThreeDSecureAuthenticationInfo + { + public virtual string TransStatus { get; protected set; } + public virtual string TransStatusReason { get; protected set; } + + public ThreeDSecureAuthenticationInfo(NodeWrapper node) + { + if (node == null) + return; + + TransStatus = node.GetString("trans-status"); + TransStatusReason = node.GetString("trans-status-reason"); + } + + public ThreeDSecureAuthenticationInfo(dynamic info) + { + if (info == null) + return; + + TransStatus = info.transStatus; + TransStatusReason = info.transStatusReason; + } + + [Obsolete("Mock Use Only")] + protected internal ThreeDSecureAuthenticationInfo() { } + } +} diff --git a/src/Braintree/ThreeDSecureInfo.cs b/src/Braintree/ThreeDSecureInfo.cs index bbd83be1..87203045 100644 --- a/src/Braintree/ThreeDSecureInfo.cs +++ b/src/Braintree/ThreeDSecureInfo.cs @@ -4,53 +4,79 @@ namespace Braintree { public class ThreeDSecureInfo { - public virtual string Status { get; protected set; } - public virtual string Enrolled { get; protected set; } - public virtual bool? LiabilityShifted { get; protected set; } + public virtual ThreeDSecureAuthenticationInfo Authentication { get; protected set; } + public virtual ThreeDSecureLookupInfo Lookup { get; protected set; } public virtual bool? LiabilityShiftPossible { get; protected set; } + public virtual bool? LiabilityShifted { get; protected set; } + public virtual string AcsTransactionId { get; protected set; } public virtual string Cavv { get; protected set; } - public virtual string Xid { get; protected set; } public virtual string DsTransactionId { get; protected set; } public virtual string EciFlag { get; protected set; } - public virtual string ThreeDSecureVersion { get; protected set; } + public virtual string Enrolled { get; protected set; } + public virtual string ParesStatus { get; protected set; } + public virtual string Status { get; protected set; } public virtual string ThreeDSecureAuthenticationId { get; protected set; } + public virtual string ThreeDSecureServerTransactionId { get; protected set; } + public virtual string ThreeDSecureVersion { get; protected set; } + public virtual string Xid { get; protected set; } public ThreeDSecureInfo(NodeWrapper node) { if (node == null) return; - Enrolled = node.GetString("enrolled"); - Status = node.GetString("status"); - LiabilityShifted = node.GetBoolean("liability-shifted"); - LiabilityShiftPossible = node.GetBoolean("liability-shift-possible"); + AcsTransactionId = node.GetString("acs-transaction-id"); Cavv = node.GetString("cavv"); - Xid = node.GetString("xid"); DsTransactionId = node.GetString("ds-transaction-id"); EciFlag = node.GetString("eci-flag"); - ThreeDSecureVersion = node.GetString("three-d-secure-version"); + Enrolled = node.GetString("enrolled"); + LiabilityShiftPossible = node.GetBoolean("liability-shift-possible"); + LiabilityShifted = node.GetBoolean("liability-shifted"); + ParesStatus = node.GetString("pares-status"); + Status = node.GetString("status"); ThreeDSecureAuthenticationId = node.GetString("three-d-secure-authentication-id"); + ThreeDSecureServerTransactionId = node.GetString("three-d-secure-server-transaction-id"); + ThreeDSecureVersion = node.GetString("three-d-secure-version"); + Xid = node.GetString("xid"); + + var AuthenticationNode = node.GetNode("authentication"); + if (AuthenticationNode != null) + { + Authentication = new ThreeDSecureAuthenticationInfo(AuthenticationNode); + } + + var LookupNode = node.GetNode("lookup"); + if (LookupNode != null) + { + Lookup = new ThreeDSecureLookupInfo(LookupNode); + } } + // this is used when constructing ThreeDSecureInfo within another response + // (like a PaymentMethodNonce class) public ThreeDSecureInfo(dynamic info) { if (info == null) return; + AcsTransactionId = info.acsTransactionId; Enrolled = info.enrolled; Status = info.status; LiabilityShifted = info.liabilityShifted; LiabilityShiftPossible = info.liabilityShiftPossible; + ParesStatus = info.paresStatus; Cavv = info.cavv; Xid = info.xid; DsTransactionId = info.dsTransactionId; EciFlag = info.eciFlag; ThreeDSecureVersion = info.threeDSecureVersion; ThreeDSecureAuthenticationId = info.threeDSecureAuthenticationId; + ThreeDSecureServerTransactionId = info.threeDSecureServerTransactionId; + Authentication = new ThreeDSecureAuthenticationInfo(info.authentication); + Lookup = new ThreeDSecureLookupInfo(info.lookup); } [Obsolete("Mock Use Only")] protected internal ThreeDSecureInfo() { } } -} - +} \ No newline at end of file diff --git a/src/Braintree/ThreeDSecureLookupInfo.cs b/src/Braintree/ThreeDSecureLookupInfo.cs new file mode 100644 index 00000000..a81137aa --- /dev/null +++ b/src/Braintree/ThreeDSecureLookupInfo.cs @@ -0,0 +1,30 @@ +using System; +namespace Braintree +{ + public class ThreeDSecureLookupInfo + { + public virtual string TransStatus { get; protected set; } + public virtual string TransStatusReason { get; protected set; } + + public ThreeDSecureLookupInfo(NodeWrapper node) + { + if (node == null) + return; + + TransStatus = node.GetString("trans-status"); + TransStatusReason = node.GetString("trans-status-reason"); + } + + public ThreeDSecureLookupInfo(dynamic info) + { + if (info == null) + return; + + TransStatus = info.transStatus; + TransStatusReason = info.transStatusReason; + } + + [Obsolete("Mock Use Only")] + protected internal ThreeDSecureLookupInfo() { } + } +} diff --git a/test/Braintree.Tests.Integration/CreditCardIntegrationTest.cs b/test/Braintree.Tests.Integration/CreditCardIntegrationTest.cs index cd594f2f..da40f1c2 100644 --- a/test/Braintree.Tests.Integration/CreditCardIntegrationTest.cs +++ b/test/Braintree.Tests.Integration/CreditCardIntegrationTest.cs @@ -28,14 +28,14 @@ public void Setup() service = new BraintreeService(gateway.Configuration); } - public void AdvancedFraudSetup() + public void FraudProtectionEnterpriseSetup() { gateway = new BraintreeGateway { Environment = Environment.DEVELOPMENT, - MerchantId = "advanced_fraud_integration_merchant_id", - PublicKey = "advanced_fraud_integration_public_key", - PrivateKey = "advanced_fraud_integration_private_key" + MerchantId = "fraud_protection_enterprise_integration_merchant_id", + PublicKey = "fraud_protection_enterprise_integration_public_key", + PrivateKey = "fraud_protection_enterprise_integration_private_key" }; service = new BraintreeService(gateway.Configuration); @@ -899,7 +899,7 @@ public void VerifyValidCreditCard() [Test] public void VerifyValidCreditCardWithVerificationRiskData() { - AdvancedFraudSetup(); + FraudProtectionEnterpriseSetup(); Customer customer = gateway.Customer.Create(new CustomerRequest()).Target; CreditCardRequest request = new CreditCardRequest { @@ -925,6 +925,9 @@ public void VerifyValidCreditCardWithVerificationRiskData() Assert.IsNotNull(verification.RiskData); Assert.IsNotNull(verification.RiskData.decision); + Assert.IsNotNull(verification.RiskData.DecisionReasons); + Assert.IsNotNull(verification.RiskData.fraudServiceProvider); + Assert.IsNotNull(verification.RiskData.id); } [Test] diff --git a/test/Braintree.Tests.Integration/PaymentMethodNonceIntegrationTest.cs b/test/Braintree.Tests.Integration/PaymentMethodNonceIntegrationTest.cs index 3e18e734..40a60a1e 100644 --- a/test/Braintree.Tests.Integration/PaymentMethodNonceIntegrationTest.cs +++ b/test/Braintree.Tests.Integration/PaymentMethodNonceIntegrationTest.cs @@ -132,6 +132,8 @@ public void Find_ExposesThreeDSecureInfo() Assert.AreEqual("1.0.2", info.ThreeDSecureVersion); Assert.AreEqual("test_xid", info.Xid); Assert.IsNotNull(info.ThreeDSecureAuthenticationId); + Assert.IsNotNull(info.Authentication); + Assert.IsNotNull(info.Lookup); } [Test] diff --git a/test/Braintree.Tests.Integration/ThreeDSecureIntegrationTest.cs b/test/Braintree.Tests.Integration/ThreeDSecureIntegrationTest.cs index 03fae785..dd601706 100644 --- a/test/Braintree.Tests.Integration/ThreeDSecureIntegrationTest.cs +++ b/test/Braintree.Tests.Integration/ThreeDSecureIntegrationTest.cs @@ -127,6 +127,7 @@ public void LookupThreeDSecure_IsSuccesfulWithPartialCustomerInfo() Assert.IsNotNull(paymentMethod.ThreeDSecureInfo); Assert.IsTrue(paymentMethod.ThreeDSecureInfo.LiabilityShiftPossible); Assert.IsFalse(paymentMethod.ThreeDSecureInfo.LiabilityShifted); + Assert.IsNull(paymentMethod.ThreeDSecureInfo.Lookup.TransStatus); Assert.IsNotNull(lookup.AcsUrl); Assert.IsNotNull(lookup.ThreeDSecureVersion); Assert.IsNotNull(lookup.TransactionId); diff --git a/test/Braintree.Tests.Integration/TransactionIntegrationTest.cs b/test/Braintree.Tests.Integration/TransactionIntegrationTest.cs index d872d42a..a01a9d49 100644 --- a/test/Braintree.Tests.Integration/TransactionIntegrationTest.cs +++ b/test/Braintree.Tests.Integration/TransactionIntegrationTest.cs @@ -31,7 +31,7 @@ public void Setup() service = new BraintreeService(gateway.Configuration); } - public void AdvancedFraudSetup() + public void AdvancedKountFraudSetup() { gateway = new BraintreeGateway { @@ -44,6 +44,19 @@ public void AdvancedFraudSetup() service = new BraintreeService(gateway.Configuration); } + public void FraudProtectionEnterpriseSetup() + { + gateway = new BraintreeGateway + { + Environment = Environment.DEVELOPMENT, + MerchantId = "fraud_protection_enterprise_integration_merchant_id", + PublicKey = "fraud_protection_enterprise_integration_public_key", + PrivateKey = "fraud_protection_enterprise_integration_private_key" + }; + + service = new BraintreeService(gateway.Configuration); + } + [Test] public void Search_OnAllTextFields() { @@ -1896,7 +1909,7 @@ public void Sale_ReturnsSuccessfulResponseUsingAccessToken() [Test] public void Sale_ReturnsSuccessfulResponseWithRiskData() { - AdvancedFraudSetup(); + FraudProtectionEnterpriseSetup(); var request = new TransactionRequest { Amount = SandboxValues.TransactionAmount.AUTHORIZE, @@ -1914,6 +1927,7 @@ public void Sale_ReturnsSuccessfulResponseWithRiskData() Assert.IsNotNull(transaction.RiskData); Assert.IsNotNull(transaction.RiskData.decision); + Assert.IsNotNull(transaction.RiskData.DecisionReasons); Assert.IsNotNull(transaction.RiskData.fraudServiceProvider); } @@ -1955,7 +1969,7 @@ public void Sale_WithDeviceData() [Test] public void Sale_WithRiskData() { - AdvancedFraudSetup(); + AdvancedKountFraudSetup(); var request = new TransactionRequest { Amount = SandboxValues.TransactionAmount.AUTHORIZE, @@ -1986,7 +2000,7 @@ public void Sale_WithRiskData() [Test] public void Sale_FailureResponseWithInvalidRiskData() { - AdvancedFraudSetup(); + AdvancedKountFraudSetup(); var request = new TransactionRequest { Amount = SandboxValues.TransactionAmount.AUTHORIZE, @@ -3632,7 +3646,7 @@ public void Sale_GatewayRejectedForCvv() [Test] public void Sale_GatewayRejectedForFraud() { - AdvancedFraudSetup(); + AdvancedKountFraudSetup(); var request = new TransactionRequest { Amount = SandboxValues.TransactionAmount.AUTHORIZE, @@ -3654,7 +3668,7 @@ public void Sale_GatewayRejectedForFraud() [Test] public void Sale_GatewayRejectedForRiskThresholds() { - AdvancedFraudSetup(); + AdvancedKountFraudSetup(); var request = new TransactionRequest { Amount = SandboxValues.TransactionAmount.AUTHORIZE, @@ -4874,9 +4888,9 @@ public void Sale_WithVenmoSdkSession() } [Test] - public void Sale_WithAdvancedFraudCheckingSkipped() + public void Sale_WithAdvancedKountFraudCheckingSkipped() { - AdvancedFraudSetup(); + AdvancedKountFraudSetup(); var request = new TransactionRequest { Amount = SandboxValues.TransactionAmount.AUTHORIZE, @@ -7195,6 +7209,9 @@ public void Find_ExposesThreeDSecureInfo() Assert.AreEqual("1.0.2", info.ThreeDSecureVersion); Assert.AreEqual("xidvalue", info.Xid); Assert.AreEqual("dstxnid", info.DsTransactionId); + Assert.IsInstanceOf(typeof(ThreeDSecureLookupInfo), info.Lookup); + Assert.IsInstanceOf(typeof(ThreeDSecureAuthenticationInfo), info.Authentication); + Assert.AreEqual("Y", info.ParesStatus); } [Test] diff --git a/test/Braintree.Tests/PaymentMethodNonceTest.cs b/test/Braintree.Tests/PaymentMethodNonceTest.cs index 3aed3dd4..b37bacc0 100644 --- a/test/Braintree.Tests/PaymentMethodNonceTest.cs +++ b/test/Braintree.Tests/PaymentMethodNonceTest.cs @@ -90,6 +90,35 @@ public void ParsesNodeCorrectlyWithPayPalDetails() Assert.AreEqual("US", result.Target.Details.PayerInfo.CountryCode); } + [Test] + public void ParsesNodeCorrectlyWithGooglePayDetails() + { + string xml = "" + + "" + + " AndroidPayCard" + + " fake-android-pay-nonce" + + " " + + " false" + + "
" + + " true" + + "
" + + "
"; + + XmlDocument doc = new XmlDocument(); + doc.LoadXml(xml); + XmlNode newNode = doc.DocumentElement; + + var node = new NodeWrapper(newNode); + + var result = new ResultImpl(node, gateway); + + Assert.IsNotNull(result.Target); + Assert.AreEqual("fake-android-pay-nonce", result.Target.Nonce); + Assert.AreEqual("AndroidPayCard", result.Target.Type); + Assert.IsNotNull(result.Target.Details); + Assert.IsTrue(result.Target.Details.IsNetworkTokenized); + } + [Test] public void ParsesNodeCorrectlyWithVenmoDetails() { @@ -124,16 +153,19 @@ public void ParsesNodeCorrectlyWithVenmoDetails() } [Test] - public void ParsesNodeCorrectlyWithOtherDetails() + public void ParsesNodeCorrectlyWithCreditCardDetails() { string xml = "" + "" + + " CreditCard" + + " fake-visa-nonce" + + " " + + " false" + "
" + - " 411111" + - " 1111" + - " Visa" + - " 01" + - " 9999" + + " 99" + + " 9999" + + " 12" + + " 2001" + "
" + "
"; @@ -146,11 +178,13 @@ public void ParsesNodeCorrectlyWithOtherDetails() var result = new ResultImpl(node, gateway); Assert.IsNotNull(result.Target); + Assert.AreEqual("fake-visa-nonce", result.Target.Nonce); + Assert.AreEqual("CreditCard", result.Target.Type); Assert.IsNotNull(result.Target.Details); - Assert.AreEqual("1111", result.Target.Details.LastFour); - Assert.AreEqual("Visa", result.Target.Details.CardType); - Assert.AreEqual("01", result.Target.Details.ExpirationMonth); - Assert.AreEqual("9999", result.Target.Details.ExpirationYear); + Assert.AreEqual("99", result.Target.Details.LastTwo); + Assert.AreEqual("9999", result.Target.Details.LastFour); + Assert.AreEqual("12", result.Target.Details.ExpirationMonth); + Assert.AreEqual("2001", result.Target.Details.ExpirationYear); } [Test] diff --git a/test/Braintree.Tests/RiskDataTest.cs b/test/Braintree.Tests/RiskDataTest.cs new file mode 100644 index 00000000..050ee61a --- /dev/null +++ b/test/Braintree.Tests/RiskDataTest.cs @@ -0,0 +1,39 @@ +using Newtonsoft.Json; +using NUnit.Framework; +using System.Text; +using System.Xml; + +namespace Braintree.Tests +{ + [TestFixture] + public class RiskDataTest + { + + [Test] + public void ConstructFromXMLResponse() + { + StringBuilder builder = new StringBuilder(); + builder.Append(""); + builder.Append(""); + builder.Append("it is decided"); + builder.Append("x,y,z"); + builder.Append("true"); + builder.Append("provider"); + builder.Append("imaid"); + builder.Append("05"); + builder.Append(""); + + + XmlDocument doc = new XmlDocument(); + doc.LoadXml(builder.ToString()); + + RiskData data = new RiskData(new NodeWrapper(doc).GetNode("//risk-data")); + Assert.IsTrue(data.deviceDataCaptured); + Assert.AreEqual("it is decided", data.decision); + Assert.AreEqual("provider", data.fraudServiceProvider); + Assert.AreEqual("imaid", data.id); + Assert.AreEqual("05", data.TransactionRiskScore); + Assert.IsNotNull(data.DecisionReasons); + } + } +} diff --git a/test/Braintree.Tests/ThreeDSecureAuthenticationInfoTest.cs b/test/Braintree.Tests/ThreeDSecureAuthenticationInfoTest.cs new file mode 100644 index 00000000..5395d7d6 --- /dev/null +++ b/test/Braintree.Tests/ThreeDSecureAuthenticationInfoTest.cs @@ -0,0 +1,45 @@ +using Newtonsoft.Json; +using NUnit.Framework; +using System.Text; +using System.Xml; + +namespace Braintree.Tests +{ + [TestFixture] + public class ThreeDSecureAuthenticationInfoTest + { + [Test] + public void ConstructFromXMLResponse() + { + StringBuilder builder = new StringBuilder(); + builder.Append(""); + builder.Append(" status"); + builder.Append(" reason"); + builder.Append(""); + + XmlDocument doc = new XmlDocument(); + doc.LoadXml(builder.ToString()); + + ThreeDSecureAuthenticationInfo info = new ThreeDSecureAuthenticationInfo(new NodeWrapper(doc).GetNode("//authentication")); + Assert.IsInstanceOf(typeof(ThreeDSecureAuthenticationInfo), info); + Assert.AreEqual("status", info.TransStatus); + Assert.AreEqual("reason", info.TransStatusReason); + } + + [Test] + public void ConstructFromDynamicObject() + { + var rawJSON = @"{ +'transStatus':'status', +'transStatusReason':'reason' +}"; + + dynamic json = JsonConvert.DeserializeObject(rawJSON); + ThreeDSecureAuthenticationInfo info = new ThreeDSecureAuthenticationInfo(json); + + Assert.IsInstanceOf(typeof(ThreeDSecureAuthenticationInfo), info); + Assert.AreEqual("status", info.TransStatus); + Assert.AreEqual("reason", info.TransStatusReason); + } + } +} diff --git a/test/Braintree.Tests/ThreeDSecureInfoTest.cs b/test/Braintree.Tests/ThreeDSecureInfoTest.cs new file mode 100644 index 00000000..a71e866a --- /dev/null +++ b/test/Braintree.Tests/ThreeDSecureInfoTest.cs @@ -0,0 +1,111 @@ +using Newtonsoft.Json; +using NUnit.Framework; +using System.Text; +using System.Xml; + +namespace Braintree.Tests +{ + [TestFixture] + public class ThreeDSecureInfoTest + { + + [Test] + public void ConstructFromXMLResponse() + { + StringBuilder builder = new StringBuilder(); + builder.Append(""); + builder.Append(""); + builder.Append("true"); + builder.Append("true"); + builder.Append("Y"); + builder.Append("status"); + builder.Append("imacavv"); + builder.Append("05"); + builder.Append("1234"); + builder.Append("2.0.0"); + builder.Append("5678"); + builder.Append("09"); + builder.Append("ACS123"); + builder.Append("Y"); + builder.Append("3DS456"); + builder.Append(""); + builder.Append(" status"); + builder.Append(" reason"); + builder.Append(""); + builder.Append(""); + builder.Append(" status"); + builder.Append(" reason"); + builder.Append(""); + builder.Append(""); + + + XmlDocument doc = new XmlDocument(); + doc.LoadXml(builder.ToString()); + + ThreeDSecureInfo info = new ThreeDSecureInfo(new NodeWrapper(doc).GetNode("//three-d-secure-info")); + Assert.IsTrue(info.LiabilityShifted); + Assert.IsTrue(info.LiabilityShiftPossible); + Assert.AreEqual("Y", info.Enrolled); + Assert.AreEqual("status", info.Status); + Assert.AreEqual("imacavv", info.Cavv); + Assert.AreEqual("05", info.EciFlag); + Assert.AreEqual("1234", info.Xid); + Assert.AreEqual("2.0.0", info.ThreeDSecureVersion); + Assert.AreEqual("5678", info.DsTransactionId); + Assert.AreEqual("09", info.ThreeDSecureAuthenticationId); + Assert.AreEqual("ACS123", info.AcsTransactionId); + Assert.AreEqual("Y", info.ParesStatus); + Assert.AreEqual("3DS456", info.ThreeDSecureServerTransactionId); + Assert.IsInstanceOf(typeof(ThreeDSecureLookupInfo), info.Lookup); + Assert.AreEqual("status", info.Lookup.TransStatus); + Assert.AreEqual("reason", info.Lookup.TransStatusReason); + Assert.IsInstanceOf(typeof(ThreeDSecureAuthenticationInfo), info.Authentication); + Assert.AreEqual("status", info.Authentication.TransStatus); + Assert.AreEqual("reason", info.Authentication.TransStatusReason); + } + + [Test] + public void ConstructFromDynamicObject() + { + var rawJSON = @"{ +'liabilityShifted':'true', +'liabilityShiftPossible':'true', +'status':'status', +'enrolled':'Y', +'cavv':'imacavv', +'xid':'1234', +'acsTransactionId':'ACS123', +'dsTransactionId':'5678', +'eciFlag':'05', +'paresStatus':'Y', +'threeDSecureAuthenticationId':'09', +'threeDSecureServerTransactionId':'3DS456', +'threeDSecureVersion':'2.0.0', +}"; + + dynamic json = JsonConvert.DeserializeObject(rawJSON); + ThreeDSecureInfo info = new ThreeDSecureInfo(json); + + Assert.IsTrue(info.LiabilityShifted); + Assert.IsTrue(info.LiabilityShiftPossible); + Assert.AreEqual("Y", info.Enrolled); + Assert.AreEqual("status", info.Status); + Assert.AreEqual("imacavv", info.Cavv); + Assert.AreEqual("05", info.EciFlag); + Assert.AreEqual("1234", info.Xid); + Assert.AreEqual("2.0.0", info.ThreeDSecureVersion); + Assert.AreEqual("5678", info.DsTransactionId); + Assert.AreEqual("09", info.ThreeDSecureAuthenticationId); + Assert.AreEqual("ACS123", info.AcsTransactionId); + Assert.AreEqual("Y", info.ParesStatus); + Assert.AreEqual("3DS456", info.ThreeDSecureServerTransactionId); + Assert.IsInstanceOf(typeof(ThreeDSecureLookupInfo), info.Lookup); + Assert.IsNull(info.Lookup.TransStatus); + Assert.IsNull(info.Lookup.TransStatusReason); + Assert.IsInstanceOf(typeof(ThreeDSecureAuthenticationInfo), info.Authentication); + Assert.IsNull(info.Authentication.TransStatus); + Assert.IsNull(info.Authentication.TransStatusReason); + + } + } +} \ No newline at end of file diff --git a/test/Braintree.Tests/ThreeDSecureLookupInfoTest.cs b/test/Braintree.Tests/ThreeDSecureLookupInfoTest.cs new file mode 100644 index 00000000..3f06d902 --- /dev/null +++ b/test/Braintree.Tests/ThreeDSecureLookupInfoTest.cs @@ -0,0 +1,46 @@ +using Newtonsoft.Json; +using NUnit.Framework; +using System.Text; +using System.Xml; + +namespace Braintree.Tests +{ + [TestFixture] + public class ThreeDSecureLookupInfoTest + { + + [Test] + public void ConstructFromXMLResponse() + { + StringBuilder builder = new StringBuilder(); + builder.Append(""); + builder.Append(" status"); + builder.Append(" reason"); + builder.Append(""); + + XmlDocument doc = new XmlDocument(); + doc.LoadXml(builder.ToString()); + + ThreeDSecureLookupInfo info = new ThreeDSecureLookupInfo(new NodeWrapper(doc).GetNode("//lookup")); + Assert.IsInstanceOf(typeof(ThreeDSecureLookupInfo), info); + Assert.AreEqual("status", info.TransStatus); + Assert.AreEqual("reason", info.TransStatusReason); + } + + [Test] + public void ConstructFromDynamicObject() + { + var rawJSON = @"{ +'transStatus':'status', +'transStatusReason':'reason' +}"; + + dynamic json = JsonConvert.DeserializeObject(rawJSON); + ThreeDSecureLookupInfo info = new ThreeDSecureLookupInfo(json); + + Assert.IsInstanceOf(typeof(ThreeDSecureLookupInfo), info); + Assert.AreEqual("status", info.TransStatus); + Assert.AreEqual("reason", info.TransStatusReason); + } + } +} \ No newline at end of file