Skip to content

Commit

Permalink
RC v2.0.2: Patch: fix taxReportable handling, set paypal as primary a…
Browse files Browse the repository at this point in the history
…ccount (#31)

<!--
We appreciate the effort for this pull request but before that please
make sure you read the contribution guidelines, then fill out the blanks
below.

Please format the PR title appropriately based on the type of change:
  <type>[!]: <description>
Where <type> is one of: docs, chore, feat, fix, test.
Add a '!' after the type for breaking changes (e.g. feat!: new breaking
feature).

**All third-party contributors acknowledge that any contributions they
provide will be made under the same open-source license that the
open-source project is provided under.**

Please enter each Issue number you are resolving in your PR after one of
the following words [Fixes, Closes, Resolves]. This will auto-link these
issues and close them when this PR is merged!
e.g.
Fixes #1
Closes #2
-->

# Patches
 - fix `taxReportable` handling
- make it easy to set `paypal` account as primary via an
RecipientAccount.Update request.

### Checklist

- [x] I acknowledge that all my contributions will be made under the
project's license
- [x] I have made a material change to the repo (functionality, testing,
spelling, grammar)
- [x] I have titled the PR appropriately
- [x] I have updated my branch with the main branch
- [x] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have added the necessary documentation about the functionality
in the appropriate .md file
- [x] I have added inline documentation to the code I modified

If you have questions, create a GitHub Issue in this repository.
  • Loading branch information
Aman-Aalam authored Jul 18, 2024
1 parent 4f46659 commit 6c1e0d6
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 1,709 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ TestResults
.vscode/**
tests/bin/**
tests/bin/
tests/obj/**
tests/obj/*
tests/obj/
tests/.vs/**
tests/.env
.DS_Store
tests/obj/project.assets.json
tests/obj/project.nuget.cache
tests/obj/tests.csproj.nuget.dgspec.json
2 changes: 2 additions & 0 deletions tests/PaymentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ public void testCreatePayments()
//Create Payment
Payment payment = new Payment(recipient, 1.20, "USD");
payment.batchId = batch.id;
payment.taxReportable = false;
payment = trolley.payment.Create(payment);
Assert.IsNotNull(payment);
Assert.IsFalse(payment.taxReportable);

//Cleanup - Delete Recipient
Boolean deleteResult = trolley.recipient.Delete(recipient.id);
Expand Down
59 changes: 49 additions & 10 deletions tests/RecipientTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public void testCreate()
Assert.AreEqual("Jones", recipient.lastName);
Assert.IsNotNull(recipient.email.IndexOf(uuid));
Assert.IsNotNull(recipient.id);

// Cleanup - delete Recipient
bool delResult = gateway.recipient.Delete(recipient.id);
Assert.IsTrue(delResult);
}

[TestMethod]
Expand All @@ -55,15 +59,10 @@ public void testCreateASCII()
Assert.AreEqual("Jónes", recipient.lastName);
Assert.IsNotNull(recipient.email.IndexOf(uuid));
Assert.IsNotNull(recipient.id);
}

public static string Serialize(object o, StringEscapeHandling stringEscapeHandling)
{
StringWriter wr = new StringWriter();
var jsonWriter = new JsonTextWriter(wr);
jsonWriter.StringEscapeHandling = stringEscapeHandling;
new JsonSerializer().Serialize(jsonWriter, o);
return wr.ToString();
// Cleanup - delete Recipient
bool delResult = gateway.recipient.Delete(recipient.id);
Assert.IsTrue(delResult);
}

[TestMethod]
Expand All @@ -77,6 +76,7 @@ public void testLifecycle()
recipient.lastName = "Jones";
recipient.dob = "1990-01-01";

// Create a Recipient
recipient = gateway.recipient.Create(recipient);
Assert.IsNotNull(recipient);
Assert.AreEqual("Tom", recipient.firstName);
Expand All @@ -86,23 +86,28 @@ public void testLifecycle()
recipient.address.Country = "US";
recipient.status = null;

// Update a Recipient
bool response = gateway.recipient.Update(recipient.id, recipient);
Assert.IsNotNull(recipient);
Assert.IsTrue(response);

// Find a Recipient
Recipient fetchResult = gateway.recipient.Get(recipient.id);
Assert.AreEqual("Bób", fetchResult.firstName);

// Cleanup - Delete a Recipient
bool result = gateway.recipient.Delete(fetchResult.id);
Assert.IsTrue(result);

// Confirm the Recipient is archived
Recipient fetchDeletedResult = gateway.recipient.Get(fetchResult.id);
Assert.AreEqual("archived", fetchDeletedResult.status);
}

[TestMethod]
public void testAddress()
{
// Create a new Recipient with Address
string uuid = Guid.NewGuid().ToString();
Recipient recipient = new Recipient();
recipient.type = "individual";
Expand All @@ -114,13 +119,17 @@ public void testAddress()
Recipient createdRecipient = gateway.recipient.Create(recipient);

Assert.AreEqual("US", createdRecipient.address.Country);

// Cleanup - delete Recipient
bool delResult = gateway.recipient.Delete(createdRecipient.id);
Assert.IsTrue(delResult);
}

[TestMethod]
public void testAccount()
{
string uuid = Guid.NewGuid().ToString();

// Create new Recipient
Address address = new Address("123 Wolfstrasse", "Berlin", "DE", "123123");
Recipient recipient = new Recipient();
recipient.type = "individual";
Expand All @@ -138,6 +147,7 @@ public void testAccount()
Assert.IsNotNull(recipient.email.IndexOf(uuid));
Assert.IsNotNull(recipient.id);

// Create a new RecipientAccount (bank-transfer)
RecipientAccount recipientAccount = new RecipientAccount("bank-transfer", "CAD", null, true, "CA");
recipientAccount.accountNum = "1234567";
recipientAccount.bankId = "003";
Expand All @@ -146,22 +156,25 @@ public void testAccount()
recipientAccount = gateway.recipientAccount.create(recipient.id, recipientAccount);
Assert.IsNotNull(recipientAccount);

// Create another new RecipientAccount (bank-transfer)
recipientAccount = new RecipientAccount("bank-transfer", "CAD", null, true, "CA");
recipientAccount.accountNum = "1234578";
recipientAccount.bankId = "003";
recipientAccount.branchId = "47261";
recipientAccount = gateway.recipientAccount.create(recipient.id, recipientAccount);
Assert.IsNotNull(recipientAccount);

// Create another Recipient
Recipient usRecipient = new Recipient();
usRecipient.type = "individual";
usRecipient.email = "test.accountCheck" + uuid + "@example.com";
usRecipient.firstName = "Tom";
usRecipient.lastName = "Jones Check";
usRecipient.dob = "1990-01-01";
usRecipient.address = new Address("719 anderson dr", "Los Altos", "US", "CA", "94024");

usRecipient = gateway.recipient.Create(usRecipient);

// Create another new account (check)
RecipientAccount recipientCheckAccount = new RecipientAccount
{
type = "check",
Expand All @@ -171,23 +184,47 @@ public void testAccount()
recipientCheckAccount = gateway.recipientAccount.create(usRecipient.id, recipientCheckAccount);
Assert.IsNotNull(recipientCheckAccount);

// Create a PayPal account
RecipientAccount paypalAccount = new RecipientAccount();
paypalAccount.type = "paypal";
paypalAccount.emailAddress = "test.accountCheck" + uuid + "@example.com";
paypalAccount = gateway.recipientAccount.create(usRecipient.id, paypalAccount);
Assert.IsNotNull(paypalAccount.id);
Assert.IsFalse(paypalAccount.primary);

// Set Paypal account as primary
RecipientAccount recipientPayPalAccount = new RecipientAccount();
recipientPayPalAccount.id = paypalAccount.id;
recipientPayPalAccount.primary = true;
RecipientAccount payPalAccountUpdate = gateway.recipientAccount.update(usRecipient.id, recipientPayPalAccount);
Assert.IsTrue(payPalAccountUpdate.primary);

// Find an account
RecipientAccount findAccount = gateway.recipientAccount.find(recipient.id, recipientAccount.id);
Assert.AreEqual(recipientAccount.iban, findAccount.iban);

// List all RecipientAccount
List<RecipientAccount> recipientAccounts = gateway.recipientAccount.findAll(recipient.id);
Assert.AreEqual(2, recipientAccounts.Count);
Assert.AreEqual(recipientAccounts[0].currency, "CAD");

// Delete a RecipientAccount
bool response = gateway.recipientAccount.delete(recipient.id, recipientAccount.id);
Assert.IsTrue(response);

// Confirm the RecipientAccount was deleted and only one account can be found.
recipientAccounts = gateway.recipientAccount.findAll(recipient.id);
Assert.AreEqual(1, recipientAccounts.Count);

// Cleanup - delete Recipient
bool delResult = gateway.recipient.Delete(recipient.id);
Assert.IsTrue(delResult);
}

[TestMethod]
public void TestMultipleDelete()
{
// Create first Recipient
string uuid = Guid.NewGuid().ToString();
Recipient recipient = new Recipient();
recipient.type = "individual";
Expand All @@ -200,6 +237,7 @@ public void TestMultipleDelete()

Assert.AreEqual("Tom", createdRecipient1.firstName);

// Create another Recipient
uuid = Guid.NewGuid().ToString();
recipient.email = "test.create.netsdk" + uuid + "@example.com";
recipient.firstName = "John";
Expand All @@ -208,6 +246,7 @@ public void TestMultipleDelete()

Assert.AreEqual("John", createdRecipient2.firstName);

// Delete both Recipients together
bool delResult = gateway.recipient.Delete(createdRecipient1.id, createdRecipient2.id);

Assert.IsTrue(delResult);
Expand Down
Loading

0 comments on commit 6c1e0d6

Please sign in to comment.