Skip to content

Commit

Permalink
2.37.0
Browse files Browse the repository at this point in the history
  • Loading branch information
braintreeps committed Nov 21, 2014
1 parent 8be5443 commit 0327c78
Show file tree
Hide file tree
Showing 23 changed files with 521 additions and 73 deletions.
24 changes: 15 additions & 9 deletions Braintree.Tests/ClientTokenTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public void Generate_GatewayRespectsMakeDefault()
}

[Test]
public void Generate_GatewayAcceptsMerchantAccountId()
public void Generate_ThrowExceptionWhenCustomerNotFound()
{
BraintreeGateway gateway = new BraintreeGateway
{
Expand All @@ -316,15 +316,21 @@ public void Generate_GatewayAcceptsMerchantAccountId()
PrivateKey = "integration_private_key"
};

var clientToken = TestHelper.GenerateDecodedClientToken(gateway,
new ClientTokenRequest
{
MerchantAccountId = "my_merchant_account"
}
);
var merchantAccountId = TestHelper.extractParamFromJson("merchantAccountId", clientToken);
string encodedClientToken = "";

Assert.AreEqual(merchantAccountId, "my_merchant_account");
try
{
encodedClientToken += gateway.ClientToken.generate(
new ClientTokenRequest
{
CustomerId = "NON_EXISTENT_CUSTOMER_ID"
}
);
Assert.Fail("Should raise ArgumentException");
} catch (ArgumentException e) {
Match match = Regex.Match(e.Message, @"customer_id");
Assert.IsTrue(match.Success);
}
}
}
}
118 changes: 82 additions & 36 deletions Braintree.Tests/CreditCardTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using NUnit.Framework;
using Braintree;
using Braintree.Exceptions;
Expand Down Expand Up @@ -509,42 +510,6 @@ public void FromNonce_ReturnsErrorWhenProvidedConsumedNonce()
}
}

[Test]
public void FromNonce_ReturnsErrorWhenProvidedLockedNonce()
{
var httpService = new BraintreeTestHttpService();
var clientToken = TestHelper.GenerateDecodedClientToken(gateway);
var authorizationFingerprint = TestHelper.extractParamFromJson("authorizationFingerprint", clientToken);
RequestBuilder builder = new RequestBuilder("");
builder.AddTopLevelElement("authorization_fingerprint", authorizationFingerprint).
AddTopLevelElement("shared_customer_identifier_type", "testing").
AddTopLevelElement("shared_customer_identifier", "test-identifier").
AddTopLevelElement("credit_card[number]", "4012888888881881").
AddTopLevelElement("share", "true").
AddTopLevelElement("credit_card[expiration_month]", "11").
AddTopLevelElement("credit_card[expiration_year]", "2099");

httpService.Post(gateway.MerchantId, "v1/payment_methods/credit_cards.json", builder.ToQueryString());

builder = new RequestBuilder("");
builder.AddTopLevelElement("authorization_fingerprint", authorizationFingerprint).
AddTopLevelElement("shared_customer_identifier_type", "testing").
AddTopLevelElement("shared_customer_identifier", "test-identifier");

HttpWebResponse response = httpService.Get(gateway.MerchantId, "v1/payment_methods.json?" + builder.ToQueryString());
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
String responseBody = reader.ReadToEnd();

Regex regex = new Regex("nonce\":\"(?<nonce>[a-f0-9\\-]+)\"");
Match match = regex.Match(responseBody);
var nonce = match.Groups["nonce"].Value;
try {
gateway.CreditCard.FromNonce(nonce);
Assert.Fail("Should throw NotFoundException");
} catch (NotFoundException e) {
StringAssert.Contains("locked", e.Message);
}
}

[Test]
public void Update_UpdatesCreditCardByToken()
Expand Down Expand Up @@ -893,6 +858,56 @@ public void VerifyValidCreditCard()
Assert.IsTrue(result.IsSuccess());
}

[Test]
public void VerifyValidCreditCardWithVerificationRiskData()
{
Customer customer = gateway.Customer.Create(new CustomerRequest()).Target;
CreditCardRequest request = new CreditCardRequest
{
CustomerId = customer.Id,
CardholderName = "John Doe",
CVV = "123",
Number = "4111111111111111",
ExpirationDate = "05/12",
Options = new CreditCardOptionsRequest
{
VerifyCard = true
}
};

Result<CreditCard> result = gateway.CreditCard.Create(request);
Assert.IsTrue(result.IsSuccess());

CreditCard card = result.Target;

CreditCardVerification verification = card.Verification;
Assert.IsNotNull(verification);

Assert.IsNotNull(verification.RiskData);
}

[Test]
public void VerifyValidCreditCardWithVerificationAmount()
{
Customer customer = gateway.Customer.Create(new CustomerRequest()).Target;
CreditCardRequest request = new CreditCardRequest
{
CustomerId = customer.Id,
CardholderName = "John Doe",
CVV = "123",
Number = "4111111111111111",
ExpirationDate = "05/12",
Options = new CreditCardOptionsRequest
{
VerifyCard = true,
VerificationAmount = "1.02"
}
};

Result<CreditCard> result = gateway.CreditCard.Create(request);
Assert.IsTrue(result.IsSuccess());
}

[Test]
public void VerifyValidCreditCardSpecifyingMerhantAccount()
{
Expand Down Expand Up @@ -1245,5 +1260,36 @@ public void CreateWithPaymentMethodNonce()
Result<CreditCard> result = gateway.CreditCard.Create(request);
Assert.IsTrue(result.IsSuccess());
}

[Test]
public void VerificationIsLatestVerification()
{
String xml = "<credit-card>"
+ "<verifications>"
+ " <verification>"
+ " <created-at type=\"datetime\">2014-11-20T17:27:15Z</created-at>"
+ " <id>123</id>"
+ " </verification>"
+ " <verification>"
+ " <created-at type=\"datetime\">2014-11-20T17:27:18Z</created-at>"
+ " <id>932</id>"
+ " </verification>"
+ " <verification>"
+ " <created-at type=\"datetime\">2014-11-20T17:27:17Z</created-at>"
+ " <id>456</id>"
+ " </verification>"
+ "</verifications>"
+ "</credit-card>";

XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
XmlNode newNode = doc.DocumentElement;

var node = new NodeWrapper(newNode);

var result = new ResultImpl<CreditCard>(node, service);

Assert.AreEqual("932", result.Target.Verification.Id);
}
}
}
15 changes: 15 additions & 0 deletions Braintree.Tests/CustomerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,21 @@ public void Find_FindsCustomerWithGivenId()
Assert.AreEqual("United States of America", customer.Addresses[0].CountryName);
}

[Test]
public void Find_IncludesPaymentMethods()
{
var createRequest = new CustomerRequest
{
PaymentMethodNonce = Nonce.ApplePayAmex
};
Customer createdCustomer = gateway.Customer.Create(createRequest).Target;
Customer customer = gateway.Customer.Find(createdCustomer.Id);
Assert.IsNotNull(customer.ApplePayCards);
Assert.IsNotNull(customer.PaymentMethods);
Assert.IsNotNull(customer.ApplePayCards[0].Token);
Assert.AreEqual(customer.ApplePayCards[0], customer.PaymentMethods[0]);
}

[Test]
public void Find_RaisesIfIdIsInvalid()
{
Expand Down
51 changes: 50 additions & 1 deletion Braintree.Tests/PaymentMethodTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void Create_CreatesApplePayCardWithNonce()
var request = new PaymentMethodRequest
{
CustomerId = result.Target.Id,
PaymentMethodNonce = SandboxValues.Nonce.APPLE_PAY_AMEX
PaymentMethodNonce = Nonce.ApplePayAmex
};
Result<PaymentMethod> paymentMethodResult = gateway.PaymentMethod.Create(request);

Expand All @@ -114,6 +114,24 @@ public void Create_CreatesApplePayCardWithNonce()
Assert.IsNotNull(applePayCard.Subscriptions);
}

[Test]
public void Create_CreatesAbstractPaymentMethod()
{
Result<Customer> result = gateway.Customer.Create(new CustomerRequest());
Assert.IsTrue(result.IsSuccess());

var request = new PaymentMethodRequest
{
CustomerId = result.Target.Id,
PaymentMethodNonce = Nonce.AbstractTransactable
};
Result<PaymentMethod> paymentMethodResult = gateway.PaymentMethod.Create(request);

Assert.IsTrue(paymentMethodResult.IsSuccess());
Assert.IsNotNull(paymentMethodResult.Target.Token);
Assert.IsNotNull(paymentMethodResult.Target.ImageUrl);
}

[Test]
public void Create_CanMakeDefaultAndSetToken()
{
Expand Down Expand Up @@ -539,6 +557,37 @@ public void Find_FindsPayPalAccount()
Assert.AreEqual(result.Target.Token, found.Token);
}

[Test]
public void Find_FindsApplePayCard()
{
var request = new PaymentMethodRequest
{
CustomerId = gateway.Customer.Create(new CustomerRequest()).Target.Id,
PaymentMethodNonce = Nonce.ApplePayAmex
};
Result<PaymentMethod> result = gateway.PaymentMethod.Create(request);
Assert.IsTrue(result.IsSuccess());

PaymentMethod found = gateway.PaymentMethod.Find(result.Target.Token);
Assert.AreEqual(result.Target.Token, found.Token);
Assert.IsInstanceOfType(typeof(ApplePayCard), found);
}

[Test]
public void Find_FindsAbstractPaymentMethod()
{
var request = new PaymentMethodRequest
{
CustomerId = gateway.Customer.Create(new CustomerRequest()).Target.Id,
PaymentMethodNonce = Nonce.AbstractTransactable
};
Result<PaymentMethod> result = gateway.PaymentMethod.Create(request);
Assert.IsTrue(result.IsSuccess());

PaymentMethod found = gateway.PaymentMethod.Find(result.Target.Token);
Assert.AreEqual(result.Target.Token, found.Token);
}

[Test]
public void Find_RaisesNotFoundErrorWhenTokenIsBlank()
{
Expand Down
Loading

0 comments on commit 0327c78

Please sign in to comment.