Skip to content

Commit

Permalink
2.57.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Braintree committed Apr 19, 2016
1 parent de26431 commit 7fb6612
Show file tree
Hide file tree
Showing 15 changed files with 364 additions and 7 deletions.
60 changes: 60 additions & 0 deletions Braintree.Tests/CustomerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,37 @@ public void Create_CreateCustomerWithCreditCard()
Assert.AreEqual(DateTime.Now.Year, customer.CreditCards[0].UpdatedAt.Value.Year);
}

[Test]
[Category("Integration")]
public void Create_CreateCustomerWithCreditCardAndVerificationAmount()
{
var createRequest = new CustomerRequest()
{
FirstName = "Michael",
LastName = "Angelo",
Company = "Some Company",
Email = "hansolo64@example.com",
Phone = "312.555.1111",
Fax = "312.555.1112",
Website = "www.example.com",
CreditCard = new CreditCardRequest()
{
Number = "5555555555554444",
ExpirationDate = "05/12",
CVV = "123",
CardholderName = "Michael Angelo",
Options = new CreditCardOptionsRequest
{
VerifyCard = true,
VerificationAmount = "1.02"
}
}
};

Result<Customer> result = gateway.Customer.Create(createRequest);
Assert.IsTrue(result.IsSuccess());
}

[Test]
[Category("Integration")]
public void Create_CreateCustomerUsingAccessToken()
Expand Down Expand Up @@ -833,6 +864,35 @@ public void Update_UpdatesCustomerAndNestedValues()
Assert.AreEqual("148", updatedAddress.CountryCodeNumeric);
}

[Test]
[Category("Integration")]
public void Update_UpdatesCustomerWithVerificationAmount()
{
var createRequest = new CustomerRequest()
{
FirstName = "Joe",
LastName = "Shmo",
};
Customer customer = gateway.Customer.Create(createRequest).Target;

var updateRequest = new CustomerRequest()
{
CreditCard = new CreditCardRequest()
{
Number = "5555555555554444",
ExpirationDate = "10/10",
Options = new CreditCardOptionsRequest
{
VerifyCard = true,
VerificationAmount = "1.02"
}
}
};

Result<Customer> result = gateway.Customer.Create(updateRequest);
Assert.IsTrue(result.IsSuccess());
}

[Test]
[Category("Integration")]
public void Update_AcceptsNestedBillingAddressId()
Expand Down
213 changes: 213 additions & 0 deletions Braintree.Tests/MerchantTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
Expand Down Expand Up @@ -63,5 +64,217 @@ public void Create_FailsWithInvalidPaymentMethods()
result.Errors.ForObject("merchant").OnField("payment-methods")[0].Code
);
}

[Test]
[Category("Integration")]
public void Create_MultiCurrencyMerchant()
{
gateway = new BraintreeGateway(
"client_id$development$signup_client_id",
"client_secret$development$signup_client_secret"
);

ResultImpl<Merchant> result = gateway.Merchant.Create(new MerchantRequest {
Email = "name@email.com",
CountryCodeAlpha3 = "USA",
PaymentMethods = new string[] {"paypal"},
CompanyName = "Ziarog LTD",
Currencies = new string[] {"GBP", "USD"},
PayPalAccount = new PayPalOnlyAccountRequest {
ClientId = "paypal_client_id",
ClientSecret = "paypal_client_secret"
}
});

Assert.IsTrue(result.IsSuccess());
Assert.IsFalse(string.IsNullOrEmpty(result.Target.Id));
Assert.AreEqual("name@email.com", result.Target.Email);
Assert.AreEqual("Ziarog LTD", result.Target.CompanyName);
Assert.AreEqual("USA", result.Target.CountryCodeAlpha3);
Assert.AreEqual("US", result.Target.CountryCodeAlpha2);
Assert.AreEqual("840", result.Target.CountryCodeNumeric);
Assert.AreEqual("United States of America", result.Target.CountryName);

Assert.IsTrue(result.Target.Credentials.AccessToken.StartsWith("access_token$"));
Assert.IsTrue(result.Target.Credentials.RefreshToken.StartsWith("refresh_token$"));
Assert.IsTrue(result.Target.Credentials.ExpiresAt > DateTime.Now);
Assert.AreEqual("bearer", result.Target.Credentials.TokenType);

Assert.AreEqual(2, result.Target.MerchantAccounts.Length);

var usdMerchantAccount = (from ma in result.Target.MerchantAccounts where ma.Id == "USD" select ma).ToArray()[0];
Assert.AreEqual("USD", usdMerchantAccount.CurrencyIsoCode);
Assert.IsTrue(usdMerchantAccount.IsDefault.Value);

var gbpMerchantAccount = (from ma in result.Target.MerchantAccounts where ma.Id == "GBP" select ma).ToArray()[0];
Assert.AreEqual("GBP", gbpMerchantAccount.CurrencyIsoCode);
Assert.IsFalse(gbpMerchantAccount.IsDefault.Value);
}

[Test]
[Category("Integration")]
public void Create_AllowsCreationOfNonUSMerchantIfOnboardingApplicationIsInternal()
{
gateway = new BraintreeGateway(
"client_id$development$signup_client_id",
"client_secret$development$signup_client_secret"
);

ResultImpl<Merchant> result = gateway.Merchant.Create(new MerchantRequest {
Email = "name@email.com",
CountryCodeAlpha3 = "JPN",
PaymentMethods = new string[] {"paypal"},
PayPalAccount = new PayPalOnlyAccountRequest {
ClientId = "paypal_client_id",
ClientSecret = "paypal_client_secret"
}
});

Assert.IsTrue(result.IsSuccess());
Assert.IsFalse(string.IsNullOrEmpty(result.Target.Id));
Assert.AreEqual("name@email.com", result.Target.Email);
Assert.AreEqual("name@email.com", result.Target.CompanyName);
Assert.AreEqual("JPN", result.Target.CountryCodeAlpha3);
Assert.AreEqual("JP", result.Target.CountryCodeAlpha2);
Assert.AreEqual("392", result.Target.CountryCodeNumeric);
Assert.AreEqual("Japan", result.Target.CountryName);

Assert.IsTrue(result.Target.Credentials.AccessToken.StartsWith("access_token$"));
Assert.IsTrue(result.Target.Credentials.RefreshToken.StartsWith("refresh_token$"));
Assert.IsTrue(result.Target.Credentials.ExpiresAt > DateTime.Now);
Assert.AreEqual("bearer", result.Target.Credentials.TokenType);

Assert.AreEqual(1, result.Target.MerchantAccounts.Length);

var merchantAccount = result.Target.MerchantAccounts[0];
Assert.AreEqual("JPY", merchantAccount.CurrencyIsoCode);
Assert.IsTrue(merchantAccount.IsDefault.Value);
}

[Test]
[Category("Integration")]
public void Create_DefaultsToUSDForNonUSMerchantIfOnboardingApplicationIsInternalAndCountryCurrencyNotSupported()
{
gateway = new BraintreeGateway(
"client_id$development$signup_client_id",
"client_secret$development$signup_client_secret"
);

ResultImpl<Merchant> result = gateway.Merchant.Create(new MerchantRequest {
Email = "name@email.com",
CountryCodeAlpha3 = "YEM",
PaymentMethods = new string[] {"paypal"},
PayPalAccount = new PayPalOnlyAccountRequest {
ClientId = "paypal_client_id",
ClientSecret = "paypal_client_secret"
}
});

Assert.IsTrue(result.IsSuccess());
Assert.IsFalse(string.IsNullOrEmpty(result.Target.Id));
Assert.AreEqual("name@email.com", result.Target.Email);
Assert.AreEqual("name@email.com", result.Target.CompanyName);
Assert.AreEqual("YEM", result.Target.CountryCodeAlpha3);
Assert.AreEqual("YE", result.Target.CountryCodeAlpha2);
Assert.AreEqual("887", result.Target.CountryCodeNumeric);
Assert.AreEqual("Yemen", result.Target.CountryName);

Assert.IsTrue(result.Target.Credentials.AccessToken.StartsWith("access_token$"));
Assert.IsTrue(result.Target.Credentials.RefreshToken.StartsWith("refresh_token$"));
Assert.IsTrue(result.Target.Credentials.ExpiresAt > DateTime.Now);
Assert.AreEqual("bearer", result.Target.Credentials.TokenType);

Assert.AreEqual(1, result.Target.MerchantAccounts.Length);

var merchantAccount = result.Target.MerchantAccounts[0];
Assert.AreEqual("USD", merchantAccount.CurrencyIsoCode);
Assert.IsTrue(merchantAccount.IsDefault.Value);
}

[Test]
[Category("Integration")]
public void Create_IgnoresMultiCurrencyIfOnboardingApplicationIsNotInternal()
{
ResultImpl<Merchant> result = gateway.Merchant.Create(new MerchantRequest {
Email = "name@email.com",
CountryCodeAlpha3 = "USA",
PaymentMethods = new string[] {"paypal"},
Currencies = new string[] {"GBP", "USD"},
PayPalAccount = new PayPalOnlyAccountRequest {
ClientId = "paypal_client_id",
ClientSecret = "paypal_client_secret"
}
});

Assert.IsTrue(result.IsSuccess());
Assert.IsFalse(string.IsNullOrEmpty(result.Target.Id));
Assert.AreEqual("name@email.com", result.Target.Email);
Assert.AreEqual("name@email.com", result.Target.CompanyName);
Assert.AreEqual("USA", result.Target.CountryCodeAlpha3);
Assert.AreEqual("US", result.Target.CountryCodeAlpha2);
Assert.AreEqual("840", result.Target.CountryCodeNumeric);
Assert.AreEqual("United States of America", result.Target.CountryName);

Assert.IsTrue(result.Target.Credentials.AccessToken.StartsWith("access_token$"));
Assert.IsTrue(result.Target.Credentials.RefreshToken.StartsWith("refresh_token$"));
Assert.IsTrue(result.Target.Credentials.ExpiresAt > DateTime.Now);
Assert.AreEqual("bearer", result.Target.Credentials.TokenType);

Assert.AreEqual(1, result.Target.MerchantAccounts.Length);
}

[Test]
[Category("Integration")]
public void Create_ReturnsErrorIfValidPaymentMethodOtherThanPayPalPassedForMultiCurrency()
{
gateway = new BraintreeGateway(
"client_id$development$signup_client_id",
"client_secret$development$signup_client_secret"
);

ResultImpl<Merchant> result = gateway.Merchant.Create(new MerchantRequest {
Email = "name@email.com",
CountryCodeAlpha3 = "USA",
PaymentMethods = new string[] {"credit_card"},
Currencies = new string[] {"GBP", "USD"},
PayPalAccount = new PayPalOnlyAccountRequest {
ClientId = "paypal_client_id",
ClientSecret = "paypal_client_secret"
}
});

Assert.IsFalse(result.IsSuccess());
Assert.AreEqual(
ValidationErrorCode.MERCHANT_PAYMENT_METHODS_ARE_NOT_ALLOWED,
result.Errors.ForObject("merchant").OnField("payment-methods")[0].Code
);
}

[Test]
[Category("Integration")]
public void Create_ReturnsErrorIfInvalidCurrencyPassed()
{
gateway = new BraintreeGateway(
"client_id$development$signup_client_id",
"client_secret$development$signup_client_secret"
);

ResultImpl<Merchant> result = gateway.Merchant.Create(new MerchantRequest {
Email = "name@email.com",
CountryCodeAlpha3 = "USA",
PaymentMethods = new string[] {"paypal"},
Currencies = new string[] {"GBP", "FAKE"},
PayPalAccount = new PayPalOnlyAccountRequest {
ClientId = "paypal_client_id",
ClientSecret = "paypal_client_secret"
}
});

Assert.IsFalse(result.IsSuccess());
Assert.AreEqual(
ValidationErrorCode.MERCHANT_CURRENCIES_ARE_INVALID,
result.Errors.ForObject("merchant").OnField("currencies")[0].Code
);
}
}
}
2 changes: 2 additions & 0 deletions Braintree.Tests/OAuthTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public void ConnectUrl_ReturnsCorrectUrl()
FulfillmentCompletedIn = 7,
Currency = "USD",
Website = "http://example.com",
EstablishedOn = "2010-10",
},
});

Expand Down Expand Up @@ -181,6 +182,7 @@ public void ConnectUrl_ReturnsCorrectUrl()
Assert.AreEqual("7", query["business[fulfillment_completed_in]"]);
Assert.AreEqual("USD", query["business[currency]"]);
Assert.AreEqual("http://example.com", query["business[website]"]);
Assert.AreEqual("2010-10", query["business[established_on]"]);

Assert.AreEqual(64, query["signature"].Length);
var hexRegex = new Regex("^[a-f0-9]+$");
Expand Down
26 changes: 26 additions & 0 deletions Braintree.Tests/PaymentMethodTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,32 @@ public void Update_UpdatesTheCreditCard()
Assert.AreEqual("06/2013", updatedCreditCard.ExpirationDate);
}

[Test]
[Category("Integration")]
public void Update_UpdatesTheCoinbaseAccount()
{
var customer = gateway.Customer.Create().Target;
PaymentMethodRequest request = new PaymentMethodRequest()
{
CustomerId = customer.Id,
PaymentMethodNonce = Nonce.Coinbase
};
var coinbaseAccount = gateway.PaymentMethod.Create(request).Target;

var updateResult = gateway.PaymentMethod.Update(
coinbaseAccount.Token,
new PaymentMethodRequest
{
Options = new PaymentMethodOptionsRequest { MakeDefault = true }
});

Assert.IsTrue(updateResult.IsSuccess());
Assert.That(updateResult.Target, Is.InstanceOfType(typeof(CoinbaseAccount)));

var updatedCoinbaseAccount = (CoinbaseAccount)updateResult.Target;
Assert.IsTrue(updatedCoinbaseAccount.IsDefault.Value);
}

[Test]
[Category("Integration")]
public void Update_CreatesNewBillingAddressByDefault()
Expand Down
2 changes: 1 addition & 1 deletion Braintree.Tests/TransactionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ public void Sale_ReturnsUnsuccessfulResponseForPartialSettlementWithUnacceptedPa
var request = new TransactionRequest
{
Amount = SandboxValues.TransactionAmount.AUTHORIZE,
PaymentMethodNonce = Nonce.ApplePayAmex
PaymentMethodNonce = Nonce.AndroidPay
};

Result<Transaction> authorizationResult = gateway.Transaction.Sale(request);
Expand Down
Loading

0 comments on commit 7fb6612

Please sign in to comment.