Permalink
Browse files

2.6.0

  • Loading branch information...
1 parent c19c7eb commit f54545ffb20e483a8a012d5de7ae6f6b7f91e6b9 @braintreeps braintreeps committed Aug 19, 2010
Showing with 2,828 additions and 675 deletions.
  1. +5 −5 Braintree.Tests/AddressTest.cs
  2. +2 −2 Braintree.Tests/Braintree.Tests.csproj
  3. +5 −17 Braintree.Tests/{WebServiceGatewayTest.cs → BraintreeServiceTest.cs}
  4. +28 −21 Braintree.Tests/ConfigurationTest.cs
  5. +29 −11 Braintree.Tests/CreditCardTest.cs
  6. +2 −2 Braintree.Tests/CreditCardVerificationTest.cs
  7. +18 −8 Braintree.Tests/CustomerTest.cs
  8. +0 −26 Braintree.Tests/MultipleValueNodeTest.cs
  9. +28 −1 Braintree.Tests/Plan.cs
  10. +2 −2 Braintree.Tests/RequestTest.cs
  11. +70 −0 Braintree.Tests/StringUtilTest.cs
  12. +172 −12 Braintree.Tests/SubscriptionSearchRequestTest.cs
  13. +885 −30 Braintree.Tests/SubscriptionTest.cs
  14. +8 −2 Braintree.Tests/TestHelper.cs
  15. +13 −9 Braintree.Tests/TrUtilTest.cs
  16. +521 −61 Braintree.Tests/TransactionTest.cs
  17. +20 −12 Braintree.Tests/TransparentRedirectRequestTest.cs
  18. +8 −6 Braintree.Tests/TransparentRedirectTest.cs
  19. +24 −0 Braintree.Tests/ValidationErrorsTest.cs
  20. +1 −1 Braintree.Tests/app.config
  21. +10 −0 Braintree/AddAddOnRequest.cs
  22. +10 −0 Braintree/AddDiscountRequest.cs
  23. +22 −0 Braintree/AddModificationRequest.cs
  24. +10 −0 Braintree/AddOn.cs
  25. +25 −0 Braintree/AddOnsRequest.cs
  26. +13 −6 Braintree/AddressGateway.cs
  27. +49 −0 Braintree/BaseCreditCardRequest.cs
  28. +47 −30 Braintree/Braintree.csproj
  29. +19 −7 Braintree/BraintreeGateway.cs
  30. +53 −13 Braintree/{WebServiceGateway.cs → BraintreeService.cs}
  31. +10 −14 Braintree/Configuration.cs
  32. +31 −25 Braintree/CreditCard.cs
  33. +0 −10 Braintree/CreditCardAddressOptionsRequest.cs
  34. +25 −18 Braintree/CreditCardGateway.cs
  35. +0 −10 Braintree/CreditCardOptionsRequest.cs
  36. +5 −36 Braintree/CreditCardRequest.cs
  37. +18 −3 Braintree/CreditCardVerification.cs
  38. +2 −2 Braintree/Customer.cs
  39. +22 −15 Braintree/CustomerGateway.cs
  40. +10 −0 Braintree/Discount.cs
  41. +25 −0 Braintree/DiscountsRequest.cs
  42. +1 −3 Braintree/Exceptions/AuthenticationException.cs
  43. +1 −3 Braintree/Exceptions/AuthorizationException.cs
  44. +12 −0 Braintree/Exceptions/BraintreeException.cs
  45. +1 −3 Braintree/Exceptions/DownForMaintenanceException.cs
  46. +1 −3 Braintree/Exceptions/ForgedQueryStringException.cs
  47. +1 −3 Braintree/Exceptions/NotFoundException.cs
  48. +1 −3 Braintree/Exceptions/ServerException.cs
  49. +1 −3 Braintree/Exceptions/UnexpectedException.cs
  50. +1 −3 Braintree/Exceptions/UpgradeRequiredException.cs
  51. +2 −2 Braintree/IdsSearchRequest.cs
  52. +24 −0 Braintree/Modification.cs
  53. +24 −0 Braintree/ModificationRequest.cs
  54. +3 −28 Braintree/MultipleValueNode.cs
  55. +20 −0 Braintree/MultipleValueOrTextNode.cs
  56. +2 −2 Braintree/Properties/AssemblyInfo.cs
  57. +5 −0 Braintree/RangeNode.cs
  58. +19 −4 Braintree/Request.cs
  59. +15 −1 Braintree/RequestBuilder.cs
  60. +8 −8 Braintree/Result.cs
  61. +1 −0 Braintree/SandboxValues.cs
  62. +0 −15 Braintree/SearchRequest.cs
  63. +22 −0 Braintree/StringUtil.cs
  64. +33 −5 Braintree/Subscription.cs
  65. +20 −13 Braintree/SubscriptionGateway.cs
  66. +27 −0 Braintree/SubscriptionOptionsRequest.cs
  67. +19 −10 Braintree/SubscriptionRequest.cs
  68. +36 −8 Braintree/SubscriptionSearchRequest.cs
  69. +0 −14 Braintree/SubscriptionTransactionRequest.cs
  70. +8 −8 Braintree/TrUtil.cs
  71. +31 −11 Braintree/Transaction.cs
  72. +30 −23 Braintree/TransactionGateway.cs
  73. +0 −10 Braintree/TransactionOptionsRequest.cs
  74. +4 −4 Braintree/TransactionRequest.cs
  75. +72 −16 Braintree/TransactionSearchRequest.cs
  76. +15 −12 Braintree/TransparentRedirectGateway.cs
  77. +3 −18 Braintree/TransparentRedirectRequest.cs
  78. +10 −0 Braintree/UpdateAddOnRequest.cs
  79. +10 −0 Braintree/UpdateDiscountRequest.cs
  80. +22 −0 Braintree/UpdateModificationRequest.cs
  81. +40 −2 Braintree/ValidationErrorCode.cs
  82. +9 −2 Braintree/ValidationErrors.cs
  83. +1 −1 Braintree/app.config
  84. +18 −0 CHANGELOG.md
  85. +5 −0 README.md
  86. BIN Thumbs.db
  87. +2 −16 cruise.rake
  88. +1 −1 cruise_config.rb
  89. BIN icons/Thumbs.db
  90. BIN styles/Thumbs.db
  91. BIN styles/icons/Thumbs.db
View
10 Braintree.Tests/AddressTest.cs
@@ -191,7 +191,7 @@ public void Update_UpdatesAddress_WithInconsistenCounty()
Assert.AreEqual(
ValidationErrorCode.ADDRESS_INCONSISTENT_COUNTRY,
- result.Errors.ForObject("address").OnField("base")[0].Code
+ result.Errors.ForObject("Address").OnField("Base")[0].Code
);
}
@@ -248,7 +248,7 @@ public void Create_ReturnsAnErrorResult_ForInconsistentCountry()
Assert.IsFalse(createResult.IsSuccess());
Assert.AreEqual(
ValidationErrorCode.ADDRESS_INCONSISTENT_COUNTRY,
- createResult.Errors.ForObject("address").OnField("base")[0].Code
+ createResult.Errors.ForObject("Address").OnField("Base")[0].Code
);
}
@@ -265,7 +265,7 @@ public void Create_ReturnsAnErrorResult_ForIncorrectAlpha2()
Assert.IsFalse(createResult.IsSuccess());
Assert.AreEqual(
ValidationErrorCode.ADDRESS_COUNTRY_CODE_ALPHA2_IS_NOT_ACCEPTED,
- createResult.Errors.ForObject("address").OnField("country_code_alpha2")[0].Code
+ createResult.Errors.ForObject("Address").OnField("CountryCodeAlpha2")[0].Code
);
}
@@ -282,7 +282,7 @@ public void Create_ReturnsAnErrorResult_ForIncorrectAlpha3()
Assert.IsFalse(createResult.IsSuccess());
Assert.AreEqual(
ValidationErrorCode.ADDRESS_COUNTRY_CODE_ALPHA3_IS_NOT_ACCEPTED,
- createResult.Errors.ForObject("address").OnField("country_code_alpha3")[0].Code
+ createResult.Errors.ForObject("Address").OnField("CountryCodeAlpha3")[0].Code
);
}
@@ -299,7 +299,7 @@ public void Create_ReturnsAnErrorResult_ForIncorrectNumeric()
Assert.IsFalse(createResult.IsSuccess());
Assert.AreEqual(
ValidationErrorCode.ADDRESS_COUNTRY_CODE_NUMERIC_IS_NOT_ACCEPTED,
- createResult.Errors.ForObject("address").OnField("country_code_numeric")[0].Code
+ createResult.Errors.ForObject("Address").OnField("CountryCodeNumeric")[0].Code
);
}
}
View
4 Braintree.Tests/Braintree.Tests.csproj
@@ -68,14 +68,14 @@
<Compile Include="TransparentRedirectRequestTest.cs" />
<Compile Include="TrUtilTest.cs" />
<Compile Include="ValidationErrorsTest.cs" />
- <Compile Include="WebServiceGatewayTest.cs" />
<Compile Include="MerchantAccount.cs" />
<Compile Include="SubscriptionSearchRequestTest.cs" />
<Compile Include="CollectionUtilTest.cs" />
<Compile Include="RequestTest.cs" />
<Compile Include="ResourceCollectionTest.cs" />
- <Compile Include="MultipleValueNodeTest.cs" />
<Compile Include="TransparentRedirectTest.cs" />
+ <Compile Include="BraintreeServiceTest.cs" />
+ <Compile Include="StringUtilTest.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Braintree\Braintree.csproj">
View
22 Braintree.Tests/WebServiceGatewayTest.cs → Braintree.Tests/BraintreeServiceTest.cs
@@ -7,23 +7,13 @@
namespace Braintree.Tests
{
[TestFixture]
- public class WebServiceGatewayTest
+ public class BraintreeServiceTest
{
-
- [SetUp]
- public void Setup()
- {
- Configuration.MerchantId = "dummy";
- Configuration.PublicKey = "dummy";
- Configuration.PrivateKey = "dummy";
- }
-
[Test]
public void QASSLCertificateSuccessful()
{
try {
- Configuration.Environment = Environment.QA;
- WebServiceGateway.Get("/");
+ new BraintreeService(new Configuration(Environment.QA, "dummy", "dummy", "dummy")).Get("/");
Assert.Fail ("Expected an AuthenticationException but none was thrown.");
} catch (Braintree.Exceptions.AuthenticationException) {
// expected
@@ -34,8 +24,7 @@ public void QASSLCertificateSuccessful()
public void SandboxSSLCertificateSuccessful()
{
try {
- Configuration.Environment = Environment.SANDBOX;
- WebServiceGateway.Get("/");
+ new BraintreeService(new Configuration(Environment.SANDBOX, "dummy", "dummy", "dummy")).Get("/");
Assert.Fail ("Expected an AuthenticationException but none was thrown.");
} catch (Braintree.Exceptions.AuthenticationException) {
// expected
@@ -46,8 +35,7 @@ public void SandboxSSLCertificateSuccessful()
public void ProductionSSLCertificateSuccessful()
{
try {
- Configuration.Environment = Environment.PRODUCTION;
- WebServiceGateway.Get("/");
+ new BraintreeService(new Configuration(Environment.PRODUCTION, "dummy", "dummy", "dummy")).Get("/");
Assert.Fail ("Expected an AuthenticationException but none was thrown.");
} catch (Braintree.Exceptions.AuthenticationException) {
// expected
@@ -58,7 +46,7 @@ public void ProductionSSLCertificateSuccessful()
public void ThrowExceptionIfErrorStatusCodeIsUpgradeRequired()
{
try {
- WebServiceGateway.ThrowExceptionIfErrorStatusCode((HttpStatusCode) 426, null);
+ BraintreeService.ThrowExceptionIfErrorStatusCode((HttpStatusCode) 426, null);
Assert.Fail ("Expected an AuthenticationException but none was thrown.");
} catch (Braintree.Exceptions.UpgradeRequiredException) {
// expected
View
49 Braintree.Tests/ConfigurationTest.cs
@@ -12,49 +12,56 @@ public class ConfigurationTest
[Test]
public void BaseMerchantURL_ReturnsDevelopmentURL()
{
- Configuration.Environment = Environment.DEVELOPMENT;
- Configuration.MerchantId = "integration_merchant_id";
- Configuration.PublicKey = "integration_public_key";
- Configuration.PrivateKey = "integration_private_key";
+ BraintreeService service = new BraintreeService(new Configuration(
+ Environment.DEVELOPMENT,
+ "integration_merchant_id",
+ "integration_public_key",
+ "integration_private_key"
+ ));
var host = System.Environment.GetEnvironmentVariable("GATEWAY_HOST") ?? "localhost";
var port = System.Environment.GetEnvironmentVariable("GATEWAY_PORT") ?? "3000";
var expected = String.Format("http://{0}:{1}/merchants/integration_merchant_id", host, port);
- Assert.AreEqual(expected, Configuration.BaseMerchantURL());
+ Assert.AreEqual(expected, service.BaseMerchantURL());
}
[Test]
public void BaseMerchantURL_ReturnsSandboxURL()
{
- Configuration.Environment = Environment.SANDBOX;
- Configuration.MerchantId = "integration_merchant_id";
- Configuration.PublicKey = "integration_public_key";
- Configuration.PrivateKey = "integration_private_key";
+ BraintreeService service = new BraintreeService(new Configuration(
+ Environment.SANDBOX,
+ "integration_merchant_id",
+ "integration_public_key",
+ "integration_private_key"
+ ));
- Assert.AreEqual("https://sandbox.braintreegateway.com:443/merchants/integration_merchant_id", Configuration.BaseMerchantURL());
+ Assert.AreEqual("https://sandbox.braintreegateway.com:443/merchants/integration_merchant_id", service.BaseMerchantURL());
}
[Test]
public void BaseMerchantURL_ReturnsProductionURL()
{
- Configuration.Environment = Environment.PRODUCTION;
- Configuration.MerchantId = "integration_merchant_id";
- Configuration.PublicKey = "integration_public_key";
- Configuration.PrivateKey = "integration_private_key";
+ BraintreeService service = new BraintreeService(new Configuration(
+ Environment.PRODUCTION,
+ "integration_merchant_id",
+ "integration_public_key",
+ "integration_private_key"
+ ));
-
- Assert.AreEqual("https://www.braintreegateway.com:443/merchants/integration_merchant_id", Configuration.BaseMerchantURL());
+ Assert.AreEqual("https://www.braintreegateway.com:443/merchants/integration_merchant_id", service.BaseMerchantURL());
}
[Test]
public void GetAuthorizationHeader_ReturnsBase64EncodePublicAndPrivateKeys()
{
- Configuration.Environment = Environment.DEVELOPMENT;
- Configuration.MerchantId = "integration_merchant_id";
- Configuration.PublicKey = "integration_public_key";
- Configuration.PrivateKey = "integration_private_key";
- Assert.AreEqual("Basic aW50ZWdyYXRpb25fcHVibGljX2tleTppbnRlZ3JhdGlvbl9wcml2YXRlX2tleQ==", Configuration.GetAuthorizationHeader());
+ BraintreeService service = new BraintreeService(new Configuration(
+ Environment.DEVELOPMENT,
+ "integration_merchant_id",
+ "integration_public_key",
+ "integration_private_key"
+ ));
+ Assert.AreEqual("Basic aW50ZWdyYXRpb25fcHVibGljX2tleTppbnRlZ3JhdGlvbl9wcml2YXRlX2tleQ==", service.GetAuthorizationHeader());
}
}
View
40 Braintree.Tests/CreditCardTest.cs
@@ -10,6 +10,7 @@ namespace Braintree.Tests
public class CreditCardTest
{
private BraintreeGateway gateway;
+ private BraintreeService service;
[SetUp]
public void Setup()
@@ -21,27 +22,32 @@ public void Setup()
PublicKey = "integration_public_key",
PrivateKey = "integration_private_key"
};
+ service = new BraintreeService(gateway.Configuration);
}
+ #pragma warning disable 0618
[Test]
public void TransparentRedirectURLForCreate_ReturnsCorrectValue()
{
- Assert.AreEqual(Configuration.BaseMerchantURL() + "/payment_methods/all/create_via_transparent_redirect_request",
+ Assert.AreEqual(service.BaseMerchantURL() + "/payment_methods/all/create_via_transparent_redirect_request",
gateway.CreditCard.TransparentRedirectURLForCreate());
}
+ #pragma warning restore 0618
+ #pragma warning disable 0618
[Test]
public void TransparentRedirectURLForUpdate_ReturnsCorrectValue()
{
- Assert.AreEqual(Configuration.BaseMerchantURL() + "/payment_methods/all/update_via_transparent_redirect_request",
+ Assert.AreEqual(service.BaseMerchantURL() + "/payment_methods/all/update_via_transparent_redirect_request",
gateway.CreditCard.TransparentRedirectURLForUpdate());
}
+ #pragma warning restore 0618
[Test]
public void TrData_ReturnsValidTrDataHash()
{
String trData = gateway.TrData(new CreditCardRequest(), "http://example.com");
- Assert.IsTrue(TrUtil.IsTrDataValid(trData));
+ Assert.IsTrue(TrUtil.IsTrDataValid(trData, service));
}
@@ -86,6 +92,7 @@ public void Create_CreatesCreditCardForGivenCustomerId()
Assert.AreEqual("148", billingAddress.CountryCodeNumeric);
}
+ #pragma warning disable 0618
[Test]
public void ConfirmTransparentRedirectCreate_CreatesTheCreditCard()
{
@@ -107,7 +114,7 @@ public void ConfirmTransparentRedirectCreate_CreatesTheCreditCard()
}
};
- String queryString = TestHelper.QueryStringForTR(trParams, request, gateway.CreditCard.TransparentRedirectURLForCreate());
+ String queryString = TestHelper.QueryStringForTR(trParams, request, gateway.CreditCard.TransparentRedirectURLForCreate(), service);
Result<CreditCard> result = gateway.CreditCard.ConfirmTransparentRedirect(queryString);
Assert.IsTrue(result.IsSuccess());
CreditCard card = result.Target;
@@ -125,7 +132,9 @@ public void ConfirmTransparentRedirectCreate_CreatesTheCreditCard()
Assert.AreEqual("GRC", billingAddress.CountryCodeAlpha3);
Assert.AreEqual("300", billingAddress.CountryCodeNumeric);
}
+ #pragma warning restore 0618
+ #pragma warning disable 0618
[Test]
public void ConfirmTransparentRedirectCreate_CreatesTheCreditCardObservingMakeDefaultInTRParams()
{
@@ -150,12 +159,14 @@ public void ConfirmTransparentRedirectCreate_CreatesTheCreditCardObservingMakeDe
}
};
- String queryString = TestHelper.QueryStringForTR(trParams, request, gateway.CreditCard.TransparentRedirectURLForCreate());
+ String queryString = TestHelper.QueryStringForTR(trParams, request, gateway.CreditCard.TransparentRedirectURLForCreate(), service);
CreditCard card = gateway.CreditCard.ConfirmTransparentRedirect(queryString).Target;
Assert.IsTrue(card.IsDefault.Value);
}
+ #pragma warning restore 0618
+ #pragma warning disable 0618
[Test]
public void ConfirmTransparentRedirectCreate_CreatesTheCreditCardObservingMakeDefaultInRequest()
{
@@ -180,12 +191,14 @@ public void ConfirmTransparentRedirectCreate_CreatesTheCreditCardObservingMakeDe
CustomerId = customer.Id,
};
- String queryString = TestHelper.QueryStringForTR(trParams, request, gateway.CreditCard.TransparentRedirectURLForCreate());
+ String queryString = TestHelper.QueryStringForTR(trParams, request, gateway.CreditCard.TransparentRedirectURLForCreate(), service);
CreditCard card = gateway.CreditCard.ConfirmTransparentRedirect(queryString).Target;
Assert.IsTrue(card.IsDefault.Value);
}
+ #pragma warning restore 0618
+ #pragma warning disable 0618
[Test]
public void ConfirmTransparentRedirectCreate_WithErrors()
{
@@ -205,15 +218,16 @@ public void ConfirmTransparentRedirectCreate_WithErrors()
}
};
- String queryString = TestHelper.QueryStringForTR(trParams, request, gateway.CreditCard.TransparentRedirectURLForCreate());
+ String queryString = TestHelper.QueryStringForTR(trParams, request, gateway.CreditCard.TransparentRedirectURLForCreate(), service);
Result<CreditCard> result = gateway.CreditCard.ConfirmTransparentRedirect(queryString);
Assert.IsFalse(result.IsSuccess());
Assert.AreEqual(
ValidationErrorCode.ADDRESS_INCONSISTENT_COUNTRY,
- result.Errors.ForObject("credit-card").ForObject("billing-address").OnField("base")[0].Code
+ result.Errors.ForObject("CreditCard").ForObject("BillingAddress").OnField("Base")[0].Code
);
}
+ #pragma warning restore 0618
[Test]
public void Find_FindsCreditCardByToken()
@@ -458,6 +472,7 @@ public void Update_UpdatesExistingBillingAddressWhenUpdateExistingIsTrue()
Assert.AreEqual(creditCard.BillingAddress.Id, updatedCreditCard.BillingAddress.Id);
}
+ #pragma warning disable 0618
[Test]
public void Update_UpdatesExistingBillingAddressWhenUpdateExistingIsTrueViaTransparentRedirect()
{
@@ -496,14 +511,16 @@ public void Update_UpdatesExistingBillingAddressWhenUpdateExistingIsTrueViaTrans
}
};
- String queryString = TestHelper.QueryStringForTR(trParams, updateRequest, gateway.CreditCard.TransparentRedirectURLForUpdate());
+ String queryString = TestHelper.QueryStringForTR(trParams, updateRequest, gateway.CreditCard.TransparentRedirectURLForUpdate(), service);
CreditCard updatedCreditCard = gateway.CreditCard.ConfirmTransparentRedirect(queryString).Target;
Assert.AreEqual("John", updatedCreditCard.BillingAddress.FirstName);
Assert.AreEqual("Jones", updatedCreditCard.BillingAddress.LastName);
Assert.AreEqual(creditCard.BillingAddress.Id, updatedCreditCard.BillingAddress.Id);
}
+ #pragma warning restore 0618
+ #pragma warning disable 0618
[Test]
public void UpdateViaTransparentRedirect()
{
@@ -531,13 +548,14 @@ public void UpdateViaTransparentRedirect()
CardholderName = "Joe Cool"
};
- String queryString = TestHelper.QueryStringForTR(trParams, request, gateway.CreditCard.TransparentRedirectURLForUpdate());
+ String queryString = TestHelper.QueryStringForTR(trParams, request, gateway.CreditCard.TransparentRedirectURLForUpdate(), service);
Result<CreditCard> result = gateway.CreditCard.ConfirmTransparentRedirect(queryString);
Assert.IsTrue(result.IsSuccess());
CreditCard card = result.Target;
Assert.AreEqual("Joe Cool", card.CardholderName);
Assert.AreEqual("44444", card.BillingAddress.PostalCode);
}
+ #pragma warning restore 0618
[Test]
public void Delete_DeletesTheCreditCard()
@@ -632,7 +650,7 @@ public void VerifyInvalidCreditCard()
Result<CreditCard> result = gateway.CreditCard.Create(request);
Assert.IsFalse(result.IsSuccess());
CreditCardVerification verification = result.CreditCardVerification;
- Assert.AreEqual("processor_declined", verification.Status);
+ Assert.AreEqual(VerificationStatus.PROCESSOR_DECLINED, verification.Status);
Assert.IsNull(verification.GatewayRejectionReason);
}
View
4 Braintree.Tests/CreditCardVerificationTest.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
@@ -36,7 +36,7 @@ public void ConstructFromResponse()
CreditCardVerification verification = new CreditCardVerification(new NodeWrapper(doc).GetNode("//verification"));
Assert.AreEqual(null, verification.AvsErrorResponseCode);
Assert.AreEqual("I", verification.AvsPostalCodeResponseCode);
- Assert.AreEqual("processor_declined", verification.Status);
+ Assert.AreEqual(VerificationStatus.PROCESSOR_DECLINED, verification.Status);
Assert.AreEqual("2000", verification.ProcessorResponseCode);
Assert.AreEqual("I", verification.AvsStreetAddressResponseCode);
Assert.AreEqual("Do Not Honor", verification.ProcessorResponseText);
View
26 Braintree.Tests/CustomerTest.cs
@@ -9,6 +9,7 @@ namespace Braintree.Tests
public class CustomerTest
{
private BraintreeGateway gateway;
+ private BraintreeService service;
[SetUp]
public void Setup()
@@ -20,6 +21,7 @@ public void Setup()
PublicKey = "integration_public_key",
PrivateKey = "integration_private_key"
};
+ service = new BraintreeService(gateway.Configuration);
}
[Test]
@@ -194,19 +196,19 @@ public void Create_withErrorsOnCountry()
Assert.AreEqual(
ValidationErrorCode.ADDRESS_COUNTRY_NAME_IS_NOT_ACCEPTED,
- result.Errors.ForObject("customer").ForObject("credit-card").ForObject("billing-address").OnField("country_name")[0].Code
+ result.Errors.ForObject("Customer").ForObject("CreditCard").ForObject("BillingAddress").OnField("CountryName")[0].Code
);
Assert.AreEqual(
ValidationErrorCode.ADDRESS_COUNTRY_CODE_ALPHA2_IS_NOT_ACCEPTED,
- result.Errors.ForObject("customer").ForObject("credit-card").ForObject("billing-address").OnField("country_code_alpha2")[0].Code
+ result.Errors.ForObject("Customer").ForObject("CreditCard").ForObject("BillingAddress").OnField("CountryCodeAlpha2")[0].Code
);
Assert.AreEqual(
ValidationErrorCode.ADDRESS_COUNTRY_CODE_ALPHA3_IS_NOT_ACCEPTED,
- result.Errors.ForObject("customer").ForObject("credit-card").ForObject("billing-address").OnField("country_code_alpha3")[0].Code
+ result.Errors.ForObject("Customer").ForObject("CreditCard").ForObject("BillingAddress").OnField("CountryCodeAlpha3")[0].Code
);
Assert.AreEqual(
ValidationErrorCode.ADDRESS_COUNTRY_CODE_NUMERIC_IS_NOT_ACCEPTED,
- result.Errors.ForObject("customer").ForObject("credit-card").ForObject("billing-address").OnField("country_code_numeric")[0].Code
+ result.Errors.ForObject("Customer").ForObject("CreditCard").ForObject("BillingAddress").OnField("CountryCodeNumeric")[0].Code
);
}
@@ -314,6 +316,7 @@ public void Create_CreateCustomerWithCreditCardAndBillingAddress()
Assert.AreEqual("United States of America", customer.Addresses[0].CountryName);
}
+ #pragma warning disable 0618
[Test]
public void ConfirmTransparentRedirect_CreatesTheCustomer()
{
@@ -325,14 +328,16 @@ public void ConfirmTransparentRedirect_CreatesTheCustomer()
LastName = "Doe"
};
- String queryString = TestHelper.QueryStringForTR(trParams, request, gateway.Customer.TransparentRedirectURLForCreate());
+ String queryString = TestHelper.QueryStringForTR(trParams, request, gateway.Customer.TransparentRedirectURLForCreate(), service);
Result<Customer> result = gateway.Customer.ConfirmTransparentRedirect(queryString);
Assert.IsTrue(result.IsSuccess());
Customer customer = result.Target;
Assert.AreEqual("John", customer.FirstName);
Assert.AreEqual("Doe", customer.LastName);
}
+ #pragma warning restore 0618
+ #pragma warning disable 0618
[Test]
public void ConfirmTransparentRedirect_CreatesNestedElementsAndCustomFields()
{
@@ -361,7 +366,7 @@ public void ConfirmTransparentRedirect_CreatesNestedElementsAndCustomFields()
}
};
- String queryString = TestHelper.QueryStringForTR(trParams, request, gateway.Customer.TransparentRedirectURLForCreate());
+ String queryString = TestHelper.QueryStringForTR(trParams, request, gateway.Customer.TransparentRedirectURLForCreate(), service);
Result<Customer> result = gateway.Customer.ConfirmTransparentRedirect(queryString);
Assert.IsTrue(result.IsSuccess());
Customer customer = result.Target;
@@ -376,7 +381,9 @@ public void ConfirmTransparentRedirect_CreatesNestedElementsAndCustomFields()
Assert.AreEqual("MEX", address.CountryCodeAlpha3);
Assert.AreEqual("484", address.CountryCodeNumeric);
}
+ #pragma warning restore 0618
+ #pragma warning disable 0618
[Test]
public void ConfirmTransparentRedirect_UpdatesTheCustomer()
{
@@ -398,14 +405,16 @@ public void ConfirmTransparentRedirect_UpdatesTheCustomer()
LastName = "Doe"
};
- String queryString = TestHelper.QueryStringForTR(trParams, request, gateway.Customer.TransparentRedirectURLForUpdate());
+ String queryString = TestHelper.QueryStringForTR(trParams, request, gateway.Customer.TransparentRedirectURLForUpdate(), service);
Result<Customer> result = gateway.Customer.ConfirmTransparentRedirect(queryString);
Assert.IsTrue(result.IsSuccess());
Customer customer = result.Target;
Assert.AreEqual("John", customer.FirstName);
Assert.AreEqual("Doe", customer.LastName);
}
+ #pragma warning restore 0618
+ #pragma warning disable 0618
[Test]
public void Update_UpdatesCustomerAndNestedValuesViaTr()
{
@@ -455,7 +464,7 @@ public void Update_UpdatesCustomerAndNestedValuesViaTr()
}
};
- String queryString = TestHelper.QueryStringForTR(trParams, new CustomerRequest(), gateway.Customer.TransparentRedirectURLForUpdate());
+ String queryString = TestHelper.QueryStringForTR(trParams, new CustomerRequest(), gateway.Customer.TransparentRedirectURLForUpdate(), service);
Customer updatedCustomer = gateway.Customer.ConfirmTransparentRedirect(queryString).Target;
CreditCard updatedCreditCard = gateway.CreditCard.Find(creditCard.Token);
@@ -470,6 +479,7 @@ public void Update_UpdatesCustomerAndNestedValuesViaTr()
Assert.AreEqual("TCD", updatedAddress.CountryCodeAlpha3);
Assert.AreEqual("148", updatedAddress.CountryCodeNumeric);
}
+ #pragma warning restore 0618
[Test]
public void Update_UpdatesCustomerWithNewValues()
View
26 Braintree.Tests/MultipleValueNodeTest.cs
@@ -1,26 +0,0 @@
-using System;
-using NUnit.Framework;
-using Braintree;
-
-namespace Braintree.Tests
-{
- [TestFixture]
- public class MultipleValueNodeTest
- {
- [Test]
- public void IncludedIn_RaisesErrorIfProvidedInvalidValue()
- {
- String[] allowedValues = {"good", "better"};
- MultipleValueNode<TransactionSearchRequest> node = new MultipleValueNode<TransactionSearchRequest>("test", new TransactionSearchRequest(), allowedValues);
- try
- {
- node.IncludedIn("bad");
- Assert.Fail();
- }
- catch(ArgumentOutOfRangeException)
- {
- // expect to raise
- }
- }
- }
-}
View
29 Braintree.Tests/Plan.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.Collections.Generic;
using System.Text;
using Braintree;
@@ -7,18 +7,44 @@ namespace Braintree.Tests
{
public class Plan
{
+ public Int32 BillingDayOfMonth { get; set; }
public Int32 BillingFrequency { get; set; }
public String Description { get; set; }
public String Id { get; set; }
+ public Int32 NumberOfBillingCycles { get; set; }
public Decimal Price { get; set; }
public Boolean TrialPeriod { get; set; }
public Int32 TrialDuration { get; set; }
public SubscriptionDurationUnit TrialDurationUnit { get; set; }
+
+ public static Plan ADD_ON_DISCOUNT_PLAN = new Plan
+ {
+ Description = "Plan for integration tests -- with add-ons and discounts",
+ Id = "integration_plan_with_add_ons_and_discounts",
+ NumberOfBillingCycles = 12,
+ Price = 9.99M,
+ BillingFrequency = 1,
+ TrialPeriod = true,
+ TrialDuration = 2,
+ TrialDurationUnit = SubscriptionDurationUnit.DAY
+ };
+
+ public static Plan BILLING_DAY_OF_MONTH_PLAN = new Plan
+ {
+ Description = "Plan for integration tests -- with billing day of month",
+ Id = "integration_plan_with_billing_day_of_month",
+ NumberOfBillingCycles = 12,
+ Price = 8.88M,
+ BillingFrequency = 1,
+ TrialPeriod = false,
+ BillingDayOfMonth = 5
+ };
public static Plan PLAN_WITHOUT_TRIAL = new Plan
{
Description = "Plan for integration tests -- without a trial",
Id = "integration_trialless_plan",
+ NumberOfBillingCycles = 12,
Price = 12.34M,
BillingFrequency = 1,
TrialPeriod = false
@@ -28,6 +54,7 @@ public class Plan
{
Description = "Plan for integration tests -- with a trial",
Id = "integration_trial_plan",
+ NumberOfBillingCycles = 12,
Price = 43.21M,
BillingFrequency = 1,
TrialPeriod = true,
View
4 Braintree.Tests/RequestTest.cs
@@ -38,9 +38,9 @@ public void ToXML_EscapesGeneratedXMLForNestedSearchCriteria()
public void ToXML_EscapesGeneratedXMLForArrayElements()
{
SubscriptionSearchRequest request = new SubscriptionSearchRequest().
- Status.IncludedIn("<active");
+ Ids.IncludedIn("<active");
- TestHelper.AssertIncludes("<status type=\"array\"><item>&lt;active</item></status>", request.ToXml());
+ TestHelper.AssertIncludes("<ids type=\"array\"><item>&lt;active</item></ids>", request.ToXml());
}
[Test]
View
70 Braintree.Tests/StringUtilTest.cs
@@ -0,0 +1,70 @@
+using System;
+using NUnit.Framework;
+
+namespace Braintree.Tests
+{
+ [TestFixture]
+ public class StringUtilTest
+ {
+ [Test]
+ public void Dasherize_ReturnsNullForNullString()
+ {
+ Assert.IsNull(StringUtil.Dasherize(null));
+ }
+
+ [Test]
+ public void Dasherize_WorksForDasherizedString()
+ {
+ Assert.AreEqual("foo-bar", StringUtil.Dasherize("foo-bar"));
+ }
+
+ [Test]
+ public void Dasherize_WorksForCamelCaseString()
+ {
+ Assert.AreEqual("first-name", StringUtil.Dasherize("firstName"));
+ }
+
+ [Test]
+ public void Dasherize_WorksForCamelCaseStringWithLeadingUppercaseLetter()
+ {
+ Assert.AreEqual("first-name", StringUtil.Dasherize("FirstName"));
+ }
+
+ [Test]
+ public void Dasherize_WorksForUnderscoreString()
+ {
+ Assert.AreEqual("first-name", StringUtil.Dasherize("first_name"));
+ }
+
+ [Test]
+ public void Underscore_ReturnsNullForNullString()
+ {
+ Assert.IsNull(StringUtil.Underscore(null));
+ }
+
+ [Test]
+ public void Underscore_WorksForDasherizedString()
+ {
+ Assert.AreEqual("foo_bar", StringUtil.Underscore("foo-bar"));
+ }
+
+ [Test]
+ public void Underscore_WorksForCamelCaseString()
+ {
+ Assert.AreEqual("first_name", StringUtil.Underscore("firstName"));
+ }
+
+ [Test]
+ public void Underscore_WorksForCamelCaseStringWithLeadingUppercaseLetter()
+ {
+ Assert.AreEqual("first_name", StringUtil.Underscore("FirstName"));
+ }
+
+ [Test]
+ public void Underscore_WorksForUnderscoreString()
+ {
+ Assert.AreEqual("first_name", StringUtil.Underscore("first_name"));
+ }
+ }
+}
+
View
184 Braintree.Tests/SubscriptionSearchRequestTest.cs
@@ -9,6 +9,102 @@ namespace Braintree.Tests
public class SubscriptionSearchRequestTest
{
[Test]
+ public void ToXml_BillingCyclesRemainingIs()
+ {
+ SubscriptionSearchRequest request = new SubscriptionSearchRequest().BillingCyclesRemaining.Is(1);
+ var xml = "<search><billing-cycles-remaining><is>1</is></billing-cycles-remaining></search>";
+ Assert.AreEqual(xml, request.ToXml());
+ }
+
+ [Test]
+ public void ToXml_BillingCyclesRemainingBetween()
+ {
+ SubscriptionSearchRequest request = new SubscriptionSearchRequest().BillingCyclesRemaining.Between(1, 2);
+ var xml = "<search><billing-cycles-remaining><min>1</min><max>2</max></billing-cycles-remaining></search>";
+ Assert.AreEqual(xml, request.ToXml());
+ }
+
+ [Test]
+ public void ToXml_BillingCyclesRemainingGreaterThanOrEqualTo()
+ {
+ SubscriptionSearchRequest request = new SubscriptionSearchRequest().BillingCyclesRemaining.GreaterThanOrEqualTo(12.34);
+ var xml = "<search><billing-cycles-remaining><min>12.34</min></billing-cycles-remaining></search>";
+ Assert.AreEqual(xml, request.ToXml());
+ }
+
+ [Test]
+ public void ToXml_BillingCyclesRemainingLessThanOrEqualTo()
+ {
+ SubscriptionSearchRequest request = new SubscriptionSearchRequest().BillingCyclesRemaining.LessThanOrEqualTo(12.34);
+ var xml = "<search><billing-cycles-remaining><max>12.34</max></billing-cycles-remaining></search>";
+ Assert.AreEqual(xml, request.ToXml());
+ }
+
+ [Test]
+ public void ToXml_IdIs()
+ {
+ SubscriptionSearchRequest request = new SubscriptionSearchRequest().Id.Is("30");
+ var xml = "<search><id><is>30</is></id></search>";
+ Assert.AreEqual(xml, request.ToXml());
+ }
+
+ [Test]
+ public void ToXml_IdIsNot()
+ {
+ SubscriptionSearchRequest request = new SubscriptionSearchRequest().Id.IsNot("30");
+ var xml = "<search><id><is-not>30</is-not></id></search>";
+ Assert.AreEqual(xml, request.ToXml());
+ }
+
+ [Test]
+ public void ToXml_IdStartsWith()
+ {
+ SubscriptionSearchRequest request = new SubscriptionSearchRequest().Id.StartsWith("30");
+ var xml = "<search><id><starts-with>30</starts-with></id></search>";
+ Assert.AreEqual(xml, request.ToXml());
+ }
+
+ [Test]
+ public void ToXml_IdEndsWith()
+ {
+ SubscriptionSearchRequest request = new SubscriptionSearchRequest().Id.EndsWith("30");
+ var xml = "<search><id><ends-with>30</ends-with></id></search>";
+ Assert.AreEqual(xml, request.ToXml());
+ }
+
+ [Test]
+ public void ToXml_IdContains()
+ {
+ SubscriptionSearchRequest request = new SubscriptionSearchRequest().Id.Contains("30");
+ var xml = "<search><id><contains>30</contains></id></search>";
+ Assert.AreEqual(xml, request.ToXml());
+ }
+
+ [Test]
+ public void ToXml_MerchantAccountIdIncludedIn()
+ {
+ SubscriptionSearchRequest request = new SubscriptionSearchRequest().MerchantAccountId.IncludedIn("abc", "def");
+ var xml = "<search><merchant-account-id type=\"array\"><item>abc</item><item>def</item></merchant-account-id></search>";
+ Assert.AreEqual(xml, request.ToXml());
+ }
+
+ [Test]
+ public void ToXml_MerchantAccountIdIncludedInWithExplicitArray()
+ {
+ SubscriptionSearchRequest request = new SubscriptionSearchRequest().MerchantAccountId.IncludedIn(new string[] {"abc", "def"});
+ var xml = "<search><merchant-account-id type=\"array\"><item>abc</item><item>def</item></merchant-account-id></search>";
+ Assert.AreEqual(xml, request.ToXml());
+ }
+
+ [Test]
+ public void ToXml_MerchantAccountIdIs()
+ {
+ SubscriptionSearchRequest request = new SubscriptionSearchRequest().MerchantAccountId.Is("abc");
+ var xml = "<search><merchant-account-id type=\"array\"><item>abc</item></merchant-account-id></search>";
+ Assert.AreEqual(xml, request.ToXml());
+ }
+
+ [Test]
public void ToXml_PlanIdIs()
{
SubscriptionSearchRequest request = new SubscriptionSearchRequest().PlanId.Is("abc");
@@ -17,6 +113,46 @@ public void ToXml_PlanIdIs()
}
[Test]
+ public void ToXml_PlanIdIsNot()
+ {
+ SubscriptionSearchRequest request = new SubscriptionSearchRequest().PlanId.IsNot("30");
+ var xml = "<search><plan-id><is-not>30</is-not></plan-id></search>";
+ Assert.AreEqual(xml, request.ToXml());
+ }
+
+ [Test]
+ public void ToXml_PlanIdStartsWith()
+ {
+ SubscriptionSearchRequest request = new SubscriptionSearchRequest().PlanId.StartsWith("30");
+ var xml = "<search><plan-id><starts-with>30</starts-with></plan-id></search>";
+ Assert.AreEqual(xml, request.ToXml());
+ }
+
+ [Test]
+ public void ToXml_PlanIdEndsWith()
+ {
+ SubscriptionSearchRequest request = new SubscriptionSearchRequest().PlanId.EndsWith("30");
+ var xml = "<search><plan-id><ends-with>30</ends-with></plan-id></search>";
+ Assert.AreEqual(xml, request.ToXml());
+ }
+
+ [Test]
+ public void ToXml_PlanIdContains()
+ {
+ SubscriptionSearchRequest request = new SubscriptionSearchRequest().PlanId.Contains("30");
+ var xml = "<search><plan-id><contains>30</contains></plan-id></search>";
+ Assert.AreEqual(xml, request.ToXml());
+ }
+
+ [Test]
+ public void ToXml_PlanIdIncludedIn()
+ {
+ SubscriptionSearchRequest request = new SubscriptionSearchRequest().PlanId.IncludedIn("abc", "def");
+ var xml = "<search><plan-id type=\"array\"><item>abc</item><item>def</item></plan-id></search>";
+ Assert.AreEqual(xml, request.ToXml());
+ }
+
+ [Test]
public void ToXml_DaysPastDueIs()
{
SubscriptionSearchRequest request = new SubscriptionSearchRequest().DaysPastDue.Is("30");
@@ -25,34 +161,58 @@ public void ToXml_DaysPastDueIs()
}
[Test]
- public void ToXml_DaysPastDueIsNot()
+ public void ToXml_DaysPastDueBetween()
+ {
+ SubscriptionSearchRequest request = new SubscriptionSearchRequest().DaysPastDue.Between(2, 3);
+ var xml = "<search><days-past-due><min>2</min><max>3</max></days-past-due></search>";
+ Assert.AreEqual(xml, request.ToXml());
+ }
+
+ [Test]
+ public void ToXml_DaysPastDueGreaterThanOrEqualTo()
+ {
+ SubscriptionSearchRequest request = new SubscriptionSearchRequest().DaysPastDue.GreaterThanOrEqualTo(3);
+ var xml = "<search><days-past-due><min>3</min></days-past-due></search>";
+ Assert.AreEqual(xml, request.ToXml());
+ }
+
+ [Test]
+ public void ToXml_DaysPastDueLessThanOrEqualTo()
+ {
+ SubscriptionSearchRequest request = new SubscriptionSearchRequest().DaysPastDue.LessThanOrEqualTo(4);
+ var xml = "<search><days-past-due><max>4</max></days-past-due></search>";
+ Assert.AreEqual(xml, request.ToXml());
+ }
+
+ [Test]
+ public void ToXml_PriceIs()
{
- SubscriptionSearchRequest request = new SubscriptionSearchRequest().DaysPastDue.IsNot("30");
- var xml = "<search><days-past-due><is-not>30</is-not></days-past-due></search>";
+ SubscriptionSearchRequest request = new SubscriptionSearchRequest().Price.Is(1M);
+ var xml = "<search><price><is>1</is></price></search>";
Assert.AreEqual(xml, request.ToXml());
}
[Test]
- public void ToXml_DaysPastDueStartsWith()
+ public void ToXml_PriceBetween()
{
- SubscriptionSearchRequest request = new SubscriptionSearchRequest().DaysPastDue.StartsWith("30");
- var xml = "<search><days-past-due><starts-with>30</starts-with></days-past-due></search>";
+ SubscriptionSearchRequest request = new SubscriptionSearchRequest().Price.Between(1M, 2M);
+ var xml = "<search><price><min>1</min><max>2</max></price></search>";
Assert.AreEqual(xml, request.ToXml());
}
[Test]
- public void ToXml_DaysPastDueEndsWith()
+ public void ToXml_PriceGreaterThanOrEqualTo()
{
- SubscriptionSearchRequest request = new SubscriptionSearchRequest().DaysPastDue.EndsWith("30");
- var xml = "<search><days-past-due><ends-with>30</ends-with></days-past-due></search>";
+ SubscriptionSearchRequest request = new SubscriptionSearchRequest().Price.GreaterThanOrEqualTo(12.34M);
+ var xml = "<search><price><min>12.34</min></price></search>";
Assert.AreEqual(xml, request.ToXml());
}
[Test]
- public void ToXml_DaysPastDueContains()
+ public void ToXml_PriceLessThanOrEqualTo()
{
- SubscriptionSearchRequest request = new SubscriptionSearchRequest().DaysPastDue.Contains("30");
- var xml = "<search><days-past-due><contains>30</contains></days-past-due></search>";
+ SubscriptionSearchRequest request = new SubscriptionSearchRequest().Price.LessThanOrEqualTo(12.34M);
+ var xml = "<search><price><max>12.34</max></price></search>";
Assert.AreEqual(xml, request.ToXml());
}
}
View
915 Braintree.Tests/SubscriptionTest.cs
@@ -58,6 +58,7 @@ public void Create_SubscriptionWithoutTrial()
Assert.AreEqual(plan.Id, subscription.PlanId);
Assert.AreEqual(MerchantAccount.DEFAULT_MERCHANT_ACCOUNT_ID, subscription.MerchantAccountId);
Assert.AreEqual(plan.Price, subscription.Price);
+ Assert.AreEqual(plan.Price, subscription.NextBillAmount);
Assert.IsTrue(Regex.IsMatch(subscription.Id, "^\\w{6}$"));
Assert.AreEqual(SubscriptionStatus.ACTIVE, subscription.Status);
Assert.AreEqual(0, subscription.FailureCount);
@@ -176,6 +177,137 @@ public void Create_OverridePlanPrice()
}
[Test]
+ public void Create_OverrideNumberOfBillingCycles()
+ {
+ Plan plan = Plan.PLAN_WITH_TRIAL;
+ SubscriptionRequest request = new SubscriptionRequest
+ {
+ PaymentMethodToken = creditCard.Token,
+ PlanId = plan.Id
+ };
+
+ Subscription subscription = gateway.Subscription.Create(request).Target;
+
+ Assert.AreEqual(12, subscription.NumberOfBillingCycles);
+
+ SubscriptionRequest overrideRequest = new SubscriptionRequest
+ {
+ PaymentMethodToken = creditCard.Token,
+ PlanId = plan.Id,
+ NumberOfBillingCycles = 10
+ };
+
+ Subscription overridenSubscription = gateway.Subscription.Create(overrideRequest).Target;
+ Assert.AreEqual(10, overridenSubscription.NumberOfBillingCycles);
+ Assert.IsFalse(overridenSubscription.NeverExpires.Value);
+ }
+
+ [Test]
+ public void Create_OverrideNumberOfBillingCyclesToNeverExpire()
+ {
+ Plan plan = Plan.PLAN_WITH_TRIAL;
+ SubscriptionRequest request = new SubscriptionRequest
+ {
+ PaymentMethodToken = creditCard.Token,
+ PlanId = plan.Id,
+ NeverExpires = true
+ };
+
+ Subscription subscription = gateway.Subscription.Create(request).Target;
+
+ Assert.IsNull(subscription.NumberOfBillingCycles);
+ Assert.IsTrue(subscription.NeverExpires.Value);
+ }
+
+ [Test]
+ public void Create_InheritBillingDayOfMonth()
+ {
+ SubscriptionRequest request = new SubscriptionRequest
+ {
+ PaymentMethodToken = creditCard.Token,
+ PlanId = Plan.BILLING_DAY_OF_MONTH_PLAN.Id
+ };
+
+ Result<Subscription> result = gateway.Subscription.Create(request);
+ Assert.IsTrue(result.IsSuccess());
+ Subscription subscription = result.Target;
+
+ Assert.AreEqual(5, subscription.BillingDayOfMonth);
+ }
+
+ [Test]
+ public void Create_OverrideBillingDayOfMonth()
+ {
+ SubscriptionRequest request = new SubscriptionRequest
+ {
+ PaymentMethodToken = creditCard.Token,
+ PlanId = Plan.BILLING_DAY_OF_MONTH_PLAN.Id,
+ BillingDayOfMonth = 19
+ };
+
+ Result<Subscription> result = gateway.Subscription.Create(request);
+ Assert.IsTrue(result.IsSuccess());
+ Subscription subscription = result.Target;
+
+ Assert.AreEqual(19, subscription.BillingDayOfMonth);
+ }
+
+ [Test]
+ public void Create_OverrideBillingDayOfMonthWithStartImmediately()
+ {
+ SubscriptionRequest request = new SubscriptionRequest
+ {
+ PaymentMethodToken = creditCard.Token,
+ PlanId = Plan.BILLING_DAY_OF_MONTH_PLAN.Id,
+ Options = new SubscriptionOptionsRequest
+ {
+ StartImmediately = true
+ }
+ };
+
+ Result<Subscription> result = gateway.Subscription.Create(request);
+ Assert.IsTrue(result.IsSuccess());
+ Subscription subscription = result.Target;
+
+ Assert.AreEqual(1, subscription.Transactions.Count);
+ }
+
+ [Test]
+ public void Create_SetFirstBillingDate()
+ {
+ SubscriptionRequest request = new SubscriptionRequest
+ {
+ PaymentMethodToken = creditCard.Token,
+ PlanId = Plan.BILLING_DAY_OF_MONTH_PLAN.Id,
+ FirstBillingDate = DateTime.Now.AddDays(3)
+ };
+
+ Result<Subscription> result = gateway.Subscription.Create(request);
+ Assert.IsTrue(result.IsSuccess());
+ Subscription subscription = result.Target;
+
+ Assert.AreEqual(DateTime.Now.AddDays(3).ToShortDateString(), subscription.FirstBillingDate.Value.ToShortDateString());
+ Assert.AreEqual(SubscriptionStatus.PENDING, subscription.Status);
+ }
+
+ [Test]
+ public void Create_SetFirstBillingDateInThePast()
+ {
+ SubscriptionRequest request = new SubscriptionRequest
+ {
+ PaymentMethodToken = creditCard.Token,
+ PlanId = Plan.BILLING_DAY_OF_MONTH_PLAN.Id,
+ FirstBillingDate = DateTime.Now.AddDays(-3)
+ };
+
+ Result<Subscription> result = gateway.Subscription.Create(request);
+ Assert.IsFalse(result.IsSuccess());
+
+ Assert.AreEqual(ValidationErrorCode.SUBSCRIPTION_FIRST_BILLING_DATE_CANNOT_BE_IN_THE_PAST,
+ result.Errors.ForObject("Subscription").OnField("FirstBillingDate")[0].Code);
+ }
+
+ [Test]
public void Create_SetId()
{
Plan plan = Plan.PLAN_WITH_TRIAL;
@@ -254,9 +386,281 @@ public void Create_HasNoTransactionOnCreateWithATrial()
}
[Test]
+ public void Create_InheritsNoAddOnsAndDiscountsWhenOptionIsPassed()
+ {
+ Plan plan = Plan.ADD_ON_DISCOUNT_PLAN;
+ SubscriptionRequest request = new SubscriptionRequest
+ {
+ PaymentMethodToken = creditCard.Token,
+ PlanId = plan.Id,
+ Options = new SubscriptionOptionsRequest
+ {
+ DoNotInheritAddOnsOrDiscounts = true
+ }
+ };
+
+ Result<Subscription> result = gateway.Subscription.Create(request);
+ Assert.IsTrue(result.IsSuccess());
+ Subscription subscription = result.Target;
+
+ Assert.AreEqual(0, subscription.AddOns.Count);
+ Assert.AreEqual(0, subscription.Discounts.Count);
+ }
+
+ [Test]
+ public void Create_InheritsAddOnsAndDiscountsFromPlan() {
+ Plan plan = Plan.ADD_ON_DISCOUNT_PLAN;
+ SubscriptionRequest request = new SubscriptionRequest
+ {
+ PaymentMethodToken = creditCard.Token,
+ PlanId = plan.Id
+ };
+
+ Result<Subscription> result = gateway.Subscription.Create(request);
+ Assert.IsTrue(result.IsSuccess());
+ Subscription subscription = result.Target;
+
+ List<AddOn> addOns = subscription.AddOns;
+ addOns.Sort(TestHelper.CompareModificationsById);
+
+ Assert.AreEqual(2, addOns.Count);
+
+ Assert.AreEqual(10M, addOns[0].Amount);
+ Assert.AreEqual(1, addOns[0].Quantity);
+ Assert.IsTrue(addOns[0].NeverExpires.Value);
+ Assert.IsNull(addOns[0].NumberOfBillingCycles);
+
+ Assert.AreEqual(20.00M, addOns[1].Amount);
+ Assert.AreEqual(1, addOns[1].Quantity);
+ Assert.IsTrue(addOns[1].NeverExpires.Value);
+ Assert.IsNull(addOns[1].NumberOfBillingCycles);
+
+ List<Discount> discounts = subscription.Discounts;
+ discounts.Sort(TestHelper.CompareModificationsById);
+
+ Assert.AreEqual(2, discounts.Count);
+
+ Assert.AreEqual(11M, discounts[0].Amount);
+ Assert.AreEqual(1, discounts[0].Quantity);
+ Assert.IsTrue(discounts[0].NeverExpires.Value);
+ Assert.IsNull(discounts[0].NumberOfBillingCycles);
+
+ Assert.AreEqual(7M, discounts[1].Amount);
+ Assert.AreEqual(1, discounts[1].Quantity);
+ Assert.IsTrue(discounts[1].NeverExpires.Value);
+ Assert.IsNull(discounts[1].NumberOfBillingCycles);
+ }
+
+ [Test]
+ public void Create_CanOverrideInheritedAddOnsAndDiscountsFromPlan()
+ {
+ Plan plan = Plan.ADD_ON_DISCOUNT_PLAN;
+ SubscriptionRequest request = new SubscriptionRequest
+ {
+ PaymentMethodToken = creditCard.Token,
+ PlanId = plan.Id,
+ AddOns = new AddOnsRequest
+ {
+ Update = new UpdateAddOnRequest[]
+ {
+ new UpdateAddOnRequest
+ {
+ ExistingId = "increase_10",
+ Amount = 30M,
+ Quantity = 9,
+ NeverExpires = true
+ },
+ new UpdateAddOnRequest
+ {
+ ExistingId = "increase_20",
+ Amount = 40M,
+ NumberOfBillingCycles = 20
+ }
+ }
+ },
+ Discounts = new DiscountsRequest
+ {
+ Update = new UpdateDiscountRequest[]
+ {
+ new UpdateDiscountRequest
+ {
+ ExistingId = "discount_7",
+ Amount = 15M,
+ Quantity = 7,
+ NeverExpires = true
+ },
+ new UpdateDiscountRequest
+ {
+ ExistingId = "discount_11",
+ Amount = 23M,
+ NumberOfBillingCycles = 11
+ }
+ }
+ }
+ };
+
+ Result<Subscription> result = gateway.Subscription.Create(request);
+ Assert.IsTrue(result.IsSuccess());
+ Subscription subscription = result.Target;
+
+ List<AddOn> addOns = subscription.AddOns;
+ addOns.Sort(TestHelper.CompareModificationsById);
+
+ Assert.AreEqual(2, addOns.Count);
+
+ Assert.AreEqual(30M, addOns[0].Amount);
+ Assert.AreEqual(9, addOns[0].Quantity);
+ Assert.IsTrue(addOns[0].NeverExpires.Value);
+ Assert.IsNull(addOns[0].NumberOfBillingCycles);
+
+ Assert.AreEqual(40.00M, addOns[1].Amount);
+ Assert.AreEqual(1, addOns[1].Quantity);
+ Assert.IsFalse(addOns[1].NeverExpires.Value);
+ Assert.AreEqual(20, addOns[1].NumberOfBillingCycles);
+
+ List<Discount> discounts = subscription.Discounts;
+ discounts.Sort(TestHelper.CompareModificationsById);
+
+ Assert.AreEqual(2, discounts.Count);
+
+ Assert.AreEqual(23M, discounts[0].Amount);
+ Assert.AreEqual(1, discounts[0].Quantity);
+ Assert.IsFalse(discounts[0].NeverExpires.Value);
+ Assert.AreEqual(11, discounts[0].NumberOfBillingCycles);
+
+ Assert.AreEqual(15M, discounts[1].Amount);
+ Assert.AreEqual(7, discounts[1].Quantity);
+ Assert.IsTrue(discounts[1].NeverExpires.Value);
+ Assert.IsNull(discounts[1].NumberOfBillingCycles);
+ }
+
+ [Test]
+ public void Create_CanRemoveInheritedAddOnsAndDiscounts()
+ {
+ Plan plan = Plan.ADD_ON_DISCOUNT_PLAN;
+ SubscriptionRequest request = new SubscriptionRequest
+ {
+ PaymentMethodToken = creditCard.Token,
+ PlanId = plan.Id,
+ AddOns = new AddOnsRequest
+ {
+ Remove = new String[] { "increase_10", "increase_20" }
+ },
+ Discounts = new DiscountsRequest
+ {
+ Remove = new String[] { "discount_11" }
+ }
+ };
+
+ Result<Subscription> result = gateway.Subscription.Create(request);
+ Assert.IsTrue(result.IsSuccess());
+ Subscription subscription = result.Target;
+
+ Assert.AreEqual(0, subscription.AddOns.Count);
+ Assert.AreEqual(1, subscription.Discounts.Count);
+
+ Assert.AreEqual("discount_7", subscription.Discounts[0].Id);
+ }
+
+ [Test]
+ public void Create_CanAddAddOnsAndDiscounts()
+ {
+ Plan plan = Plan.ADD_ON_DISCOUNT_PLAN;
+ SubscriptionRequest request = new SubscriptionRequest
+ {
+ PaymentMethodToken = creditCard.Token,
+ PlanId = plan.Id,
+ AddOns = new AddOnsRequest
+ {
+ Add = new AddAddOnRequest[]
+ {
+ new AddAddOnRequest
+ {
+ InheritedFromId = "increase_30",
+ Amount = 35M,
+ NumberOfBillingCycles = 3,
+ Quantity = 8
+ }
+ },
+ Remove = new String[] { "increase_10", "increase_20" }
+ },
+ Discounts = new DiscountsRequest
+ {
+ Add = new AddDiscountRequest[]
+ {
+ new AddDiscountRequest
+ {
+ InheritedFromId = "discount_15",
+ Amount = 17M,
+ NeverExpires = true,
+ Quantity = 9
+ }
+ },
+ Remove = new String[] { "discount_7", "discount_11" }
+ }
+ };
+
+ Result<Subscription> result = gateway.Subscription.Create(request);
+ Assert.IsTrue(result.IsSuccess());
+ Subscription subscription = result.Target;
+
+ Assert.AreEqual(1, subscription.AddOns.Count);
+
+ Assert.AreEqual("increase_30", subscription.AddOns[0].Id);
+ Assert.AreEqual(35M, subscription.AddOns[0].Amount);
+ Assert.AreEqual(8, subscription.AddOns[0].Quantity);
+ Assert.IsFalse(subscription.AddOns[0].NeverExpires.Value);
+ Assert.AreEqual(3, subscription.AddOns[0].NumberOfBillingCycles);
+
+ Assert.AreEqual(1, subscription.Discounts.Count);
+
+ Assert.AreEqual("discount_15", subscription.Discounts[0].Id);
+ Assert.AreEqual(17M, subscription.Discounts[0].Amount);
+ Assert.AreEqual(9, subscription.Discounts[0].Quantity);
+ Assert.IsTrue(subscription.Discounts[0].NeverExpires.Value);
+ Assert.IsNull(subscription.Discounts[0].NumberOfBillingCycles);
+ }
+
+ [Test]
+ public void Create_WithBadAddOnParamsCorrectlyParsesValidationErrors()
+ {
+ Plan plan = Plan.ADD_ON_DISCOUNT_PLAN;
+ SubscriptionRequest request = new SubscriptionRequest
+ {
+ PaymentMethodToken = creditCard.Token,
+ PlanId = plan.Id,
+ AddOns = new AddOnsRequest
+ {
+ Update = new UpdateAddOnRequest[]
+ {
+ new UpdateAddOnRequest
+ {
+ ExistingId = "increase_10",
+ Amount = -200M
+ },
+ new UpdateAddOnRequest
+ {
+ ExistingId = "increase_20",
+ Quantity = -9
+ }
+ }
+ }
+ };
+
+ Result<Subscription> result = gateway.Subscription.Create(request);
+ Assert.IsFalse(result.IsSuccess());
+
+ Assert.AreEqual(ValidationErrorCode.SUBSCRIPTION_MODIFICATION_AMOUNT_IS_INVALID,
+ result.Errors.ForObject("Subscription").ForObject("AddOns").ForObject("Update").ForIndex(0).OnField("Amount")[0].Code);
+
+ Assert.AreEqual(ValidationErrorCode.SUBSCRIPTION_MODIFICATION_QUANTITY_IS_INVALID,
+ result.Errors.ForObject("Subscription").ForObject("AddOns").ForObject("Update").ForIndex(1).OnField("Quantity")[0].Code);
+ }
+
+ [Test]
public void Find()
{
- Plan plan = Plan.PLAN_WITHOUT_TRIAL;
+ Plan plan = Plan.PLAN_WITH_TRIAL;
SubscriptionRequest request = new SubscriptionRequest
{
PaymentMethodToken = creditCard.Token,
@@ -272,27 +676,140 @@ public void Find()
}
[Test]
+ public void Search_OnBillingCyclesRemainingIs()
+ {
+ SubscriptionRequest request1 = new SubscriptionRequest
+ {
+ NumberOfBillingCycles = 5,
+ PaymentMethodToken = creditCard.Token,
+ PlanId = Plan.PLAN_WITH_TRIAL.Id,
+ Price = 4M
+ };
+
+ SubscriptionRequest request2 = new SubscriptionRequest
+ {
+ NumberOfBillingCycles = 10,
+ PaymentMethodToken = creditCard.Token,
+ PlanId = Plan.PLAN_WITH_TRIAL.Id,
+ Price = 4M
+ };
+
+ Subscription subscription1 = gateway.Subscription.Create(request1).Target;
+ Subscription subscription2 = gateway.Subscription.Create(request2).Target;
+
+ SubscriptionSearchRequest request = new SubscriptionSearchRequest().
+ BillingCyclesRemaining.Is(5).
+ Price.Is(4M);
+
+ ResourceCollection<Subscription> collection = gateway.Subscription.Search(request);
+
+ Assert.IsTrue(TestHelper.IncludesSubscription(collection, subscription1));
+ Assert.IsFalse(TestHelper.IncludesSubscription(collection, subscription2));
+ }
+
+ [Test]
+ public void Search_OnDaysPastDueBetween()
+ {
+ SubscriptionSearchRequest request = new SubscriptionSearchRequest().
+ DaysPastDue.Between(2, 10);
+
+ ResourceCollection<Subscription> collection = gateway.Subscription.Search(request);
+ Assert.IsTrue(collection.MaximumCount > 0);
+
+ foreach (Subscription subscription in collection) {
+ Assert.IsTrue(subscription.DaysPastDue >= 2 && subscription.DaysPastDue <= 10);
+ }
+ }
+
+ [Test]
+ public void Search_OnIdIs()
+ {
+ SubscriptionRequest request1 = new SubscriptionRequest
+ {
+ Id = String.Format("find_me{0}", new Random().Next(1000000)),
+ PaymentMethodToken = creditCard.Token,
+ PlanId = Plan.PLAN_WITH_TRIAL.Id,
+ Price = 3M
+ };
+
+ SubscriptionRequest request2 = new SubscriptionRequest
+ {
+ Id = String.Format("do_not_find_me{0}", new Random().Next(1000000)),
+ PaymentMethodToken = creditCard.Token,
+ PlanId = Plan.PLAN_WITH_TRIAL.Id,
+ Price = 3M
+ };
+
+ Subscription subscription1 = gateway.Subscription.Create(request1).Target;
+ Subscription subscription2 = gateway.Subscription.Create(request2).Target;
+
+ SubscriptionSearchRequest request = new SubscriptionSearchRequest().
+ Id.StartsWith("find_me").
+ Price.Is(3M);
+
+ ResourceCollection<Subscription> collection = gateway.Subscription.Search(request);
+
+ Assert.IsTrue(TestHelper.IncludesSubscription(collection, subscription1));
+ Assert.IsFalse(TestHelper.IncludesSubscription(collection, subscription2));
+ }
+
+ [Test]
+ public void Search_OnMerchantAccountIdIs()
+ {
+ SubscriptionRequest request1 = new SubscriptionRequest
+ {
+ MerchantAccountId = MerchantAccount.DEFAULT_MERCHANT_ACCOUNT_ID,
+ PaymentMethodToken = creditCard.Token,
+ PlanId = Plan.PLAN_WITH_TRIAL.Id,
+ Price = 2M
+ };
+
+ SubscriptionRequest request2 = new SubscriptionRequest
+ {
+ MerchantAccountId = MerchantAccount.NON_DEFAULT_MERCHANT_ACCOUNT_ID,
+ PaymentMethodToken = creditCard.Token,
+ PlanId = Plan.PLAN_WITH_TRIAL.Id,
+ Price = 2M
+ };
+
+ Subscription defaultMerchantAccountSubscription = gateway.Subscription.Create(request1).Target;
+ Subscription nonDefaultMerchantAccountSubscription = gateway.Subscription.Create(request2).Target;
+
+ SubscriptionSearchRequest request = new SubscriptionSearchRequest().
+ MerchantAccountId.Is(MerchantAccount.NON_DEFAULT_MERCHANT_ACCOUNT_ID).
+ Price.Is(2M);
+
+ ResourceCollection<Subscription> collection = gateway.Subscription.Search(request);
+
+ Assert.IsTrue(TestHelper.IncludesSubscription(collection, nonDefaultMerchantAccountSubscription));
+ Assert.IsFalse(TestHelper.IncludesSubscription(collection, defaultMerchantAccountSubscription));
+ }
+
+ [Test]
public void Search_OnPlanIdIs()
{
Plan triallessPlan = Plan.PLAN_WITHOUT_TRIAL;
Plan trialPlan = Plan.PLAN_WITH_TRIAL;
SubscriptionRequest request1 = new SubscriptionRequest
{
PaymentMethodToken = creditCard.Token,
- PlanId = trialPlan.Id
+ PlanId = trialPlan.Id,
+ Price = 5M
};
SubscriptionRequest request2 = new SubscriptionRequest
{
PaymentMethodToken = creditCard.Token,
- PlanId = triallessPlan.Id
+ PlanId = triallessPlan.Id,
+ Price = 5M
};
Subscription trialSubscription = gateway.Subscription.Create(request1).Target;
Subscription triallessSubscription = gateway.Subscription.Create(request2).Target;
SubscriptionSearchRequest request = new SubscriptionSearchRequest().
- PlanId.Is(trialPlan.Id);
+ PlanId.Is(trialPlan.Id).
+ Price.Is(5M);
ResourceCollection<Subscription> collection = gateway.Subscription.Search(request);
@@ -301,27 +818,69 @@ public void Search_OnPlanIdIs()
}
[Test]
+ public void Search_OnPrice()
+ {
+ SubscriptionRequest request10 = new SubscriptionRequest
+ {
+ PaymentMethodToken = creditCard.Token,
+ PlanId = Plan.PLAN_WITH_TRIAL.Id,
+ Price = 10M
+ };
+
+ SubscriptionRequest request20 = new SubscriptionRequest
+ {
+ PaymentMethodToken = creditCard.Token,
+ PlanId = Plan.PLAN_WITH_TRIAL.Id,
+ Price = 20M
+ };
+
+ SubscriptionRequest request30 = new SubscriptionRequest
+ {
+ PaymentMethodToken = creditCard.Token,
+ PlanId = Plan.PLAN_WITH_TRIAL.Id,
+ Price = 30M
+ };
+
+ Subscription subscription10 = gateway.Subscription.Create(request10).Target;
+ Subscription subscription20 = gateway.Subscription.Create(request20).Target;
+ Subscription subscription30 = gateway.Subscription.Create(request30).Target;
+
+ SubscriptionSearchRequest request = new SubscriptionSearchRequest().
+ Price.Between(15M, 20M);
+
+ ResourceCollection<Subscription> collection = gateway.Subscription.Search(request);
+
+ Assert.IsFalse(TestHelper.IncludesSubscription(collection, subscription10));
+ Assert.IsTrue(TestHelper.IncludesSubscription(collection, subscription20));
+ Assert.IsFalse(TestHelper.IncludesSubscription(collection, subscription30));
+ }
+
+
+ [Test]
public void Search_OnPlanIdIsWithDelegate()
{
Plan triallessPlan = Plan.PLAN_WITHOUT_TRIAL;
Plan trialPlan = Plan.PLAN_WITH_TRIAL;
SubscriptionRequest request1 = new SubscriptionRequest
{
PaymentMethodToken = creditCard.Token,
- PlanId = trialPlan.Id
+ PlanId = trialPlan.Id,
+ Price = 6M
};
SubscriptionRequest request2 = new SubscriptionRequest
{
PaymentMethodToken = creditCard.Token,
- PlanId = triallessPlan.Id
+ PlanId = triallessPlan.Id,
+ Price = 6M
};
Subscription trialSubscription = gateway.Subscription.Create(request1).Target;
Subscription triallessSubscription = gateway.Subscription.Create(request2).Target;
ResourceCollection<Subscription> collection = gateway.Subscription.Search(delegate(SubscriptionSearchRequest search) {
search.PlanId.Is(trialPlan.Id);
+ search.Price.Is(6M);
});
Assert.IsTrue(TestHelper.IncludesSubscription(collection, trialSubscription));
@@ -336,20 +895,23 @@ public void Search_OnPlanIdIsNot()
SubscriptionRequest request1 = new SubscriptionRequest
{
PaymentMethodToken = creditCard.Token,
- PlanId = trialPlan.Id
+ PlanId = trialPlan.Id,
+ Price = 7M
};
SubscriptionRequest request2 = new SubscriptionRequest
{
PaymentMethodToken = creditCard.Token,
- PlanId = triallessPlan.Id
+ PlanId = triallessPlan.Id,
+ Price = 7M
};
Subscription trialSubscription = gateway.Subscription.Create(request1).Target;
Subscription triallessSubscription = gateway.Subscription.Create(request2).Target;
SubscriptionSearchRequest request = new SubscriptionSearchRequest().
- PlanId.IsNot(triallessPlan.Id);
+ PlanId.IsNot(triallessPlan.Id).
+ Price.Is(7M);
ResourceCollection<Subscription> collection = gateway.Subscription.Search(request);
@@ -365,20 +927,23 @@ public void Search_OnPlanIdStartsWith()
SubscriptionRequest request1 = new SubscriptionRequest
{
PaymentMethodToken = creditCard.Token,
- PlanId = trialPlan.Id
+ PlanId = trialPlan.Id,
+ Price = 8M
};
SubscriptionRequest request2 = new SubscriptionRequest
{
PaymentMethodToken = creditCard.Token,
- PlanId = triallessPlan.Id
+ PlanId = triallessPlan.Id,
+ Price = 8M
};
Subscription trialSubscription = gateway.Subscription.Create(request1).Target;
Subscription triallessSubscription = gateway.Subscription.Create(request2).Target;
SubscriptionSearchRequest request = new SubscriptionSearchRequest().
- PlanId.StartsWith("integration_trial_p");
+ PlanId.StartsWith("integration_trial_p").
+ Price.Is(8M);
ResourceCollection<Subscription> collection = gateway.Subscription.Search(request);
@@ -394,20 +959,23 @@ public void Search_OnPlanIdEndsWith()
SubscriptionRequest request1 = new SubscriptionRequest
{
PaymentMethodToken = creditCard.Token,
- PlanId = trialPlan.Id
+ PlanId = trialPlan.Id,
+ Price = 9M
};
SubscriptionRequest request2 = new SubscriptionRequest
{
PaymentMethodToken = creditCard.Token,
- PlanId = triallessPlan.Id
+ PlanId = triallessPlan.Id,
+ Price = 9M
};
Subscription trialSubscription = gateway.Subscription.Create(request1).Target;
Subscription triallessSubscription = gateway.Subscription.Create(request2).Target;
SubscriptionSearchRequest request = new SubscriptionSearchRequest().
- PlanId.EndsWith("trial_plan");
+ PlanId.EndsWith("trial_plan").
+ Price.Is(9M);
ResourceCollection<Subscription> collection = gateway.Subscription.Search(request);
@@ -423,20 +991,23 @@ public void Search_OnPlanIdContains()
SubscriptionRequest request1 = new SubscriptionRequest
{
PaymentMethodToken = creditCard.Token,
- PlanId = trialPlan.Id
+ PlanId = trialPlan.Id,
+ Price = 10M
};
SubscriptionRequest request2 = new SubscriptionRequest
{
PaymentMethodToken = creditCard.Token,
- PlanId = triallessPlan.Id
+ PlanId = triallessPlan.Id,
+ Price = 10M
};
Subscription trialSubscription = gateway.Subscription.Create(request1).Target;
Subscription triallessSubscription = gateway.Subscription.Create(request2).Target;
SubscriptionSearchRequest request = new SubscriptionSearchRequest().
- PlanId.Contains("ion_trial_pl");
+ PlanId.Contains("ion_trial_pl").
+ Price.Is(10M);
ResourceCollection<Subscription> collection = gateway.Subscription.Search(request);
@@ -445,20 +1016,61 @@ public void Search_OnPlanIdContains()
}
[Test]
+ public void Search_OnPlanIdIncludedIn()
+ {
+ SubscriptionRequest request1 = new SubscriptionRequest
+ {
+ PaymentMethodToken = creditCard.Token,
+ PlanId = Plan.PLAN_WITH_TRIAL.Id,
+ Price = 5M
+ };
+
+ SubscriptionRequest request2 = new SubscriptionRequest
+ {
+ PaymentMethodToken = creditCard.Token,
+ PlanId = Plan.PLAN_WITHOUT_TRIAL.Id,
+ Price = 5M
+ };
+
+ SubscriptionRequest request3 = new SubscriptionRequest
+ {
+ PaymentMethodToken = creditCard.Token,
+ PlanId = Plan.ADD_ON_DISCOUNT_PLAN.Id,
+ Price = 5M
+ };
+
+ Subscription subscription1 = gateway.Subscription.Create(request1).Target;
+ Subscription subscription2 = gateway.Subscription.Create(request2).Target;
+ Subscription subscription3 = gateway.Subscription.Create(request3).Target;
+
+ SubscriptionSearchRequest request = new SubscriptionSearchRequest().
+ PlanId.IncludedIn(Plan.ADD_ON_DISCOUNT_PLAN.Id, Plan.PLAN_WITH_TRIAL.Id).
+ Price.Is(5M);
+
+ ResourceCollection<Subscription> collection = gateway.Subscription.Search(request);
+
+ Assert.IsTrue(TestHelper.IncludesSubscription(collection, subscription1));
+ Assert.IsFalse(TestHelper.IncludesSubscription(collection, subscription2));
+ Assert.IsTrue(TestHelper.IncludesSubscription(collection, subscription3));
+ }
+
+ [Test]
public void Search_OnStatusIn()
{
Plan triallessPlan = Plan.PLAN_WITHOUT_TRIAL;
SubscriptionRequest request1 = new SubscriptionRequest
{
PaymentMethodToken = creditCard.Token,
- PlanId = triallessPlan.Id
+ PlanId = triallessPlan.Id,
+ Price = 11M
};
SubscriptionRequest request2 = new SubscriptionRequest
{
PaymentMethodToken = creditCard.Token,
- PlanId = triallessPlan.Id
+ PlanId = triallessPlan.Id,
+ Price = 11M
};
Subscription activeSubscription = gateway.Subscription.Create(request1).Target;
@@ -467,27 +1079,43 @@ public void Search_OnStatusIn()
ResourceCollection<Subscription> collection = gateway.Subscription.Search(delegate(SubscriptionSearchRequest search) {
search.Status.IncludedIn(SubscriptionStatus.ACTIVE);
+ search.Price.Is(11M);
});
Assert.IsTrue(TestHelper.IncludesSubscription(collection, activeSubscription));
Assert.IsFalse(TestHelper.IncludesSubscription(collection, canceledSubscription));
}
[Test]
+ public void Search_OnStatusExpired()
+ {
+ ResourceCollection<Subscription> collection = gateway.Subscription.Search(delegate(SubscriptionSearchRequest search) {
+ search.Status.IncludedIn(SubscriptionStatus.EXPIRED);
+ });
+
+ Assert.IsTrue(collection.MaximumCount > 0);
+ foreach(Subscription subscription in collection) {
+ Assert.AreEqual(SubscriptionStatus.EXPIRED, subscription.Status);
+ }
+ }
+
+ [Test]
public void Search_OnStatusInMultipleValues()
{
Plan triallessPlan = Plan.PLAN_WITHOUT_TRIAL;
SubscriptionRequest request1 = new SubscriptionRequest
{
PaymentMethodToken = creditCard.Token,
- PlanId = triallessPlan.Id
+ PlanId = triallessPlan.Id,
+ Price = 12M
};
SubscriptionRequest request2 = new SubscriptionRequest
{
PaymentMethodToken = creditCard.Token,
- PlanId = triallessPlan.Id
+ PlanId = triallessPlan.Id,
+ Price = 12M
};
Subscription activeSubscription = gateway.Subscription.Create(request1).Target;
@@ -496,6 +1124,7 @@ public void Search_OnStatusInMultipleValues()
ResourceCollection<Subscription> collection = gateway.Subscription.Search(delegate(SubscriptionSearchRequest search) {
search.Status.IncludedIn(SubscriptionStatus.ACTIVE, SubscriptionStatus.CANCELED);
+ search.Price.Is(12M);
});
Assert.IsTrue(TestHelper.IncludesSubscription(collection, activeSubscription));
@@ -604,6 +1233,151 @@ public void UpdateMerchantAccountId()
}
[Test]
+ public void Update_UpdatesAddOnsAndDiscounts()
+ {
+ Plan plan = Plan.ADD_ON_DISCOUNT_PLAN;
+ SubscriptionRequest createRequest = new SubscriptionRequest
+ {
+ PaymentMethodToken = creditCard.Token,
+ PlanId = plan.Id
+ };
+
+ Subscription subscription = gateway.Subscription.Create(createRequest).Target;
+
+ SubscriptionRequest request = new SubscriptionRequest
+ {
+ AddOns = new AddOnsRequest
+ {
+ Add = new AddAddOnRequest[] {
+ new AddAddOnRequest{
+ InheritedFromId = "increase_30",
+ Amount = 31M,
+ NumberOfBillingCycles = 3,
+ Quantity = 7
+ }
+ },
+ Remove = new String[] { "increase_20" },
+ Update = new UpdateAddOnRequest[] {
+ new UpdateAddOnRequest
+ {
+ ExistingId = "increase_10",
+ Amount = 30M,
+ NeverExpires = true,
+ Quantity = 9
+ }
+ }
+ },
+ Discounts = new DiscountsRequest
+ {
+ Add = new AddDiscountRequest[] {
+ new AddDiscountRequest{
+ InheritedFromId = "discount_15",
+ Amount = 23M,
+ NumberOfBillingCycles = 2,
+ Quantity = 9
+ }
+ },
+ Remove = new String[] { "discount_11" },
+ Update = new UpdateDiscountRequest[] {
+ new UpdateDiscountRequest
+ {
+ ExistingId = "discount_7",
+ Amount = 15M,
+ }
+ }
+ }
+ };
+
+ Result<Subscription> result = gateway.Subscription.Update(subscription.Id, request);
+ Assert.IsTrue(result.IsSuccess());
+ subscription = result.Target;
+
+ List<AddOn> addOns = subscription.AddOns;
+ addOns.Sort(TestHelper.CompareModificationsById);
+
+ Assert.AreEqual(2, addOns.Count);
+
+ Assert.AreEqual("increase_10", addOns[0].Id);
+ Assert.AreEqual(30M, addOns[0].Amount);
+ Assert.AreEqual(9, addOns[0].Quantity);
+ Assert.IsTrue(addOns[0].NeverExpires.Value);
+ Assert.IsNull(addOns[0].NumberOfBillingCycles);
+
+ Assert.AreEqual("increase_30", addOns[1].Id);
+ Assert.AreEqual(31M, addOns[1].Amount);
+ Assert.AreEqual(7, addOns[1].Quantity);
+ Assert.IsFalse(addOns[1].NeverExpires.Value);
+ Assert.AreEqual(3, addOns[1].NumberOfBillingCycles);
+
+ List<Discount> discounts = subscription.Discounts;
+ discounts.Sort(TestHelper.CompareModificationsById);
+
+ Assert.AreEqual(2, discounts.Count);
+
+ Assert.AreEqual("discount_15", discounts[0].Id);
+ Assert.AreEqual(23M, discounts[0].Amount);
+ Assert.AreEqual(9, discounts[0].Quantity);
+ Assert.IsFalse(discounts[0].NeverExpires.Value);
+ Assert.AreEqual(2, discounts[0].NumberOfBillingCycles);
+
+ Assert.AreEqual("discount_7", discounts[1].Id);
+ Assert.AreEqual(15M, discounts[1].Amount);
+ Assert.AreEqual(1, discounts[1].Quantity);
+ Assert.IsTrue(discounts[1].NeverExpires.Value);
+ Assert.IsNull(discounts[1].NumberOfBillingCycles);
+ }
+
+ [Test]
+ public void Update_CanReplaceAllAddOnsAndDiscounts()
+ {
+ Plan plan = Plan.ADD_ON_DISCOUNT_PLAN;
+ SubscriptionRequest createRequest = new SubscriptionRequest
+ {
+ PaymentMethodToken = creditCard.Token,
+ PlanId = plan.Id
+ };
+
+ Subscription subscription = gateway.Subscription.Create(createRequest).Target;
+
+ SubscriptionRequest request = new SubscriptionRequest
+ {
+ PaymentMethodToken = creditCard.Token,
+ PlanId = plan.Id,
+ AddOns = new AddOnsRequest
+ {
+ Add = new AddAddOnRequest[]
+ {
+ new AddAddOnRequest
+ {
+ InheritedFromId = "increase_30"
+ }
+ },
+ },
+ Discounts = new DiscountsRequest
+ {
+ Add = new AddDiscountRequest[]
+ {
+ new AddDiscountRequest
+ {
+ InheritedFromId = "discount_15",
+ }
+ },
+ },
+ Options = new SubscriptionOptionsRequest
+ {
+ ReplaceAllAddOnsAndDiscounts = true
+ }
+ };
+
+ Result<Subscription> result = gateway.Subscription.Update(subscription.Id, request);
+ Assert.IsTrue(result.IsSuccess());
+ subscription = result.Target;
+
+ Assert.AreEqual(1, subscription.AddOns.Count);
+ Assert.AreEqual(1, subscription.Discounts.Count);
+ }
+
+ [Test]
public void IncreasePriceAndTransaction()
{
Plan originalPlan = Plan.PLAN_WITHOUT_TRIAL;
@@ -627,6 +1401,68 @@ public void IncreasePriceAndTransaction()
}
[Test]
+ public void Update_ProratesChargesWhenSpecified()
+ {
+ Plan originalPlan = Plan.PLAN_WITHOUT_TRIAL;
+ SubscriptionRequest request = new SubscriptionRequest
+ {
+ PaymentMethodToken = creditCard.Token,
+ PlanId = originalPlan.Id,
+ Price = 1.23M
+ };
+
+ Subscription subscription = gateway.Subscription.Create(request).Target;
+
+ SubscriptionRequest updateRequest = new SubscriptionRequest
+ {
+ Price = 4.56M,
+ Options = new SubscriptionOptionsRequest
+ {
+ ProrateCharges = true
+ }
+ };
+
+ Result<Subscription> result = gateway.Subscription.Update(subscription.Id, updateRequest);
+
+ Assert.IsTrue(result.IsSuccess());
+ subscription = result.Target;
+
+ Assert.AreEqual(4.56M, subscription.Price);
+ Assert.AreEqual(2, subscription.Transactions.Count);
+ }
+
+ [Test]
+ public void Update_DoesNotProrateChargesWhenSpecifiedToNotProrate()
+ {
+ Plan originalPlan = Plan.PLAN_WITHOUT_TRIAL;
+ SubscriptionRequest request = new SubscriptionRequest
+ {
+ PaymentMethodToken = creditCard.Token,
+ PlanId = originalPlan.Id,
+ Price = 1.23M
+ };
+
+ Subscription subscription = gateway.Subscription.Create(request).Target;
+
+ SubscriptionRequest updateRequest = new SubscriptionRequest
+ {
+ Price = 4.56M,
+ Options = new SubscriptionOptionsRequest
+ {
+ ProrateCharges = false
+ }
+ };
+
+ Result<Subscription> result = gateway.Subscription.Update(subscription.Id, updateRequest);
+
+ Assert.IsTrue(result.IsSuccess());
+ subscription = result.Target;
+
+ Assert.AreEqual(4.56M, subscription.Price);
+ Assert.AreEqual(1, subscription.Transactions.Count);
+ }
+
+ [Test]
public void Update_DontIncreasePriceAndDontAddTransaction()
{
Plan originalPlan = Plan.PLAN_WITHOUT_TRIAL;
@@ -661,7 +1497,7 @@ public void Create_WithBadPlanId()
Result<Subscription> result = gateway.Subscription.Create(createRequest);
Assert.IsFalse(result.IsSuccess());
- Assert.AreEqual(ValidationErrorCode.SUBSCRIPTION_PLAN_ID_IS_INVALID, result.Errors.ForObject("subscription").OnField("plan_id")[0].Code);
+ Assert.AreEqual(ValidationErrorCode.SUBSCRIPTION_PLAN_ID_IS_INVALID, result.Errors.ForObject("Subscription").OnField("PlanId")[0].Code);
}
[Test]
@@ -676,7 +1512,7 @@ public void Create_WithBadPaymentMethod()
Result<Subscription> result = gateway.Subscription.Create(createRequest);
Assert.IsFalse(result.IsSuccess());
- Assert.AreEqual(ValidationErrorCode.SUBSCRIPTION_PAYMENT_METHOD_TOKEN_IS_INVALID, result.Errors.ForObject("subscription").OnField("payment_method_token")[0].Code);
+ Assert.AreEqual(ValidationErrorCode.SUBSCRIPTION_PAYMENT_METHOD_TOKEN_IS_INVALID, result.Errors.ForObject("Subscription").OnField("PaymentMethodToken")[0].Code);
}
[Test]
@@ -694,7 +1530,7 @@ public void Create_WithValidationErrors()
Assert.IsFalse(createResult.IsSuccess());
Assert.IsNull(createResult.Target);
ValidationErrors errors = createResult.Errors;
- Assert.AreEqual(ValidationErrorCode.SUBSCRIPTION_TOKEN_FORMAT_IS_INVALID, errors.ForObject("subscription").OnField("id")[0].Code);
+ Assert.AreEqual(ValidationErrorCode.SUBSCRIPTION_TOKEN_FORMAT_IS_INVALID, errors.ForObject("Subscription").OnField("Id")[0].Code);
}
[Test]
@@ -716,7 +1552,7 @@ public void Create_WithValidationErrors()
Assert.IsFalse(result.IsSuccess());
Assert.IsNull(result.Target);
ValidationErrors errors = result.Errors;
- Assert.AreEqual(ValidationErrorCode.SUBSCRIPTION_TOKEN_FORMAT_IS_INVALID, errors.ForObject("subscription").OnField("id")[0].Code);
+ Assert.AreEqual(ValidationErrorCode.SUBSCRIPTION_TOKEN_FORMAT_IS_INVALID, errors.ForObject("Subscription").OnField("Id")[0].Code);
}
[Test]
@@ -761,8 +1597,14 @@ public void Cancel()
[Test]
public void RetryCharge_WithoutAmount()
{
- SubscriptionSearchRequest search = new SubscriptionSearchRequest().Status.IncludedIn(SubscriptionStatus.PAST_DUE);
- Subscription subscription = gateway.Subscription.Search(search).FirstItem;
+ SubscriptionRequest request = new SubscriptionRequest
+ {
+ PaymentMethodToken = creditCard.Token,
+ PlanId = Plan.PLAN_WITHOUT_TRIAL.Id
+ };
+
+ Subscription subscription = gateway.Subscription.Create(request).Target;
+ MakePastDue(subscription, 1);
Result<Transaction> result = gateway.Subscription.RetryCharge(subscription.Id);
@@ -778,8 +1620,14 @@ public void RetryCharge_WithoutAmount()