diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..8f41861 --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +ACCESS_KEY= +SECRET_KEY= \ No newline at end of file diff --git a/.gitignore b/.gitignore index 8753aeb..41afdc2 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,6 @@ nbproject .project .vscode .vscode/* -src/main/java/ca/paymentrails/paymentrails/index.java \ No newline at end of file +src/main/java/com/trolley/trolley/index.java +/.metadata/ +.env \ No newline at end of file diff --git a/README.md b/README.md index 4ddfdb6..633f794 100644 --- a/README.md +++ b/README.md @@ -20,19 +20,21 @@ Add this dependency to your project's POM: ```xml - ca.paymentrails - paymentrails - 1.0.2 + com.trolley + java-sdk + 1.0.1 ``` -The library is hosted at [https://github.com/paymentRails/java-sdk](https://github.com/paymentRails/java-sdk) +The library's source is hosted at [https://github.com/paymentRails/java-sdk](https://github.com/paymentRails/java-sdk) + +The library can be found at: [https://central.sonatype.com/artifact/com.trolley/java-sdk/1.0](https://central.sonatype.com/artifact/com.trolley/java-sdk/1.0) ## Getting Started ```java -import ca.paymentrails.paymentrails.*; -import ca.paymentrails.Exceptions.*; +import com.trolley.java-sdk.*; +import com.trolley.Exceptions.*; public class PaymentRailsExample { public static void main(String[] args) { @@ -51,7 +53,7 @@ public class PaymentRailsExample { ### Usage -Methods should all have Java Doc comments to help you understand their usage. As mentioned the [full API documentation](https://docs.trolley.com) +Methods should all have Java Doc comments to help you understand their usage. As mentioned the [full API documentation](http://docs.trolley.com) is the best source of information about the API. For more information please read the [Java API docs](https://github.com/PaymentRails/java-sdk/tree/master/docs) is available. The best starting point is: diff --git a/docs/classes/batchgateway.md b/docs/classes/batchgateway.md index b728a76..04f2fe4 100644 --- a/docs/classes/batchgateway.md +++ b/docs/classes/batchgateway.md @@ -3,21 +3,21 @@ # Class: BatchGateway Gateway class for batches -*__class__*: BatchGateway +_**class**_: BatchGateway ## Index ### Methods -* [create](BatchGateway.md#create) -* [find](BatchGateway.md#find) -* [generateQuote](BatchGateway.md#generatequote) -* [paymentList](BatchGateway.md#paymentlist) -* [delete](BatchGateway.md#delete) -* [search](BatchGateway.md#search) -* [processBatch](BatchGateway.md#processBatch) -* [summary](BatchGateway.md#summary) -* [update](BatchGateway.md#update) +- [create](BatchGateway.md#create) +- [find](BatchGateway.md#find) +- [generateQuote](BatchGateway.md#generatequote) +- [paymentList](BatchGateway.md#paymentlist) +- [delete](BatchGateway.md#delete) +- [search](BatchGateway.md#search) +- [processBatch](BatchGateway.md#processBatch) +- [summary](BatchGateway.md#summary) +- [update](BatchGateway.md#update) --- @@ -27,19 +27,19 @@ Gateway class for batches ### create -► **create**(batch: *`Batch`*): `Batch` +► **create**(batch: _`Batch`_): `Batch` -*Defined in [BatchGateway.java:95](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/BatchGateway.java#L95)* +_Defined in [BatchGateway.java:95](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/BatchGateway.java#L95)_ -Creates a batch with optional payments. This is the interface that is provide by the [Create Batch](https://docs.trolley.com/api/#create-a-batch) API +Creates a batch with optional payments. This is the interface that is provide by the [Create Batch](http://docs.trolley.com/api/#create-a-batch) API Batch batch = client.batch.create("{\"sourceCurrency\": \"USD\", \"description\":\"Docs Create\"}"); **Parameters:** -| Param | Type | Description | -| ------ | ------ | ------ | -| batch | `Batch` | - | +| Param | Type | Description | +| ----- | ------- | ----------- | +| batch | `Batch` | - | **Returns:** `Batch` @@ -49,9 +49,9 @@ Creates a batch with optional payments. This is the interface that is provide by ### find -► **find**(batchId: *`string`*): `Batch` +► **find**(batchId: _`string`_): `Batch` -*Defined in [BatchGateway.java:67](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/BatchGateway.java#L67)* +_Defined in [BatchGateway.java:67](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/BatchGateway.java#L67)_ Retrieves a batch based on the batch id @@ -71,9 +71,9 @@ Retrieves a batch based on the batch id ### generateQuote -► **generateQuote**(batchId: *`string`*): `Batch` +► **generateQuote**(batchId: _`string`_): `Batch` -*Defined in [BatchGateway.java:182](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/BatchGateway.java#L182)* +_Defined in [BatchGateway.java:182](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/BatchGateway.java#L182)_ Generate a FX quote for this batch @@ -91,9 +91,9 @@ Generate a FX quote for this batch ### paymentList -► **paymentList**(batchId: *`string`*, page?: *`number`*, pageSize?: *`number`*): `Payment`[] +► **paymentList**(batchId: _`string`_, page?: _`number`_, pageSize?: _`number`_): `Payment`[] -*Defined in [BatchGateway.java:166](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/BatchGateway.java#L166)* +_Defined in [BatchGateway.java:166](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/BatchGateway.java#L166)_ Return a paginated list of payments for this batch @@ -113,9 +113,9 @@ Return a paginated list of payments for this batch ### delete -► **delete**(batchId: *`string`*): `Boolean` +► **delete**(batchId: _`string`_): `Boolean` -*Defined in [BatchGateway.java:132](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/BatchGateway.java#L132)* +_Defined in [BatchGateway.java:132](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/BatchGateway.java#L132)_ Delete the given batch @@ -135,19 +135,19 @@ Delete the given batch ### search -► **search**(page?: *`number`*, pageSize?: *`number`*, term?: *`string`*): `Batch`[] +► **search**(page?: _`number`_, pageSize?: _`number`_, term?: _`string`_): `Batch`[] -*Defined in [BatchGateway.java:146](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/BatchGateway.java#L146)* +_Defined in [BatchGateway.java:146](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/BatchGateway.java#L146)_ Search for a batch matching the given term **Parameters:** -| Param | Type | Default value | Description | -| ------ | ------ | ------ | ------ | -| page | `number` | 1 | - | -| pageSize | `number` | 10 | - | -| term | `string` | "" | string search term | +| Param | Type | Default value | Description | +| -------- | -------- | ------------- | ------------------ | +| page | `number` | 1 | - | +| pageSize | `number` | 10 | - | +| term | `string` | "" | string search term | **Returns:** `Batch`[] @@ -157,9 +157,9 @@ Search for a batch matching the given term ### processBatch -► **processBatch**(batchId: *`string`*): `Batch` +► **processBatch**(batchId: _`string`_): `Batch` -*Defined in [BatchGateway.java:194](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/BatchGateway.java#L194)* +_Defined in [BatchGateway.java:194](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/BatchGateway.java#L194)_ Start processing this batch @@ -177,9 +177,9 @@ Start processing this batch ### summary -► **summary**(batchId: *`string`*): `String` +► **summary**(batchId: _`string`_): `String` -*Defined in [BatchGateway.java:206](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/BatchGateway.java#L206)* +_Defined in [BatchGateway.java:206](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/BatchGateway.java#L206)_ Get a transaction totaled summary for this batch @@ -193,4 +193,4 @@ Get a transaction totaled summary for this batch **Returns:** `String` ---- \ No newline at end of file +--- diff --git a/docs/classes/configuration.md b/docs/classes/configuration.md index 6ed5dbd..08c2dd6 100644 --- a/docs/classes/configuration.md +++ b/docs/classes/configuration.md @@ -6,9 +6,9 @@ ### Properties -* [apiBase](Configuration.md#apibase) -* [apiKey](Configuration.md#apikey) -* [apiSecret](Configuration.md#apisecret) +- [apiBase](Configuration.md#apibase) +- [apiKey](Configuration.md#apikey) +- [apiSecret](Configuration.md#apisecret) --- @@ -18,9 +18,9 @@ ### environment -**● environment**: *`string`* +**● enviroment**: _`string`_ -*Defined in [Configuration.java:35](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Configuration.java#L35)* +_Defined in [Configuration.java:35](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Configuration.java#L35)_ --- @@ -28,9 +28,9 @@ ### publicKey -**● publicKey**: *`string`* +**● publicKey**: _`string`_ -*Defined in [Configuration.java:33](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Configuration.java#L33)* +_Defined in [Configuration.java:33](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Configuration.java#L33)_ --- @@ -38,9 +38,9 @@ ### privateKey -**● privateKey**: *`string`* +**● privateKey**: _`string`_ -*Defined in [Configuration.java:34](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Configuration.java#L34)* +_Defined in [Configuration.java:34](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Configuration.java#L34)_ --- @@ -48,17 +48,17 @@ ### «Static» environment -► **environment**(environment: *"production"⎮"sandbox"⎮"integration"*): `void` +► **environment**(environment: _"production"⎮"sandbox"⎮"integration"_): `void` -*Defined in [Configuration.java:90](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Configuration.java#L90)* +_Defined in [Configuration.java:90](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Configuration.java#L90)_ Set the Trolley API environment that you're using **Parameters:** -| Param | Type | Description | -| ------ | ------ | ------ | -| environment | "production"⎮"sandbox"⎮"integration" | one of "production" or "sandbox" | +| Param | Type | Description | +| ----------- | ------------------------------------ | -------------------------------- | +| environment | "production"⎮"sandbox"⎮"integration" | one of "production" or "sandbox" | **Returns:** `void` diff --git a/docs/classes/gateway.md b/docs/classes/gateway.md index 9677a42..b72be36 100644 --- a/docs/classes/gateway.md +++ b/docs/classes/gateway.md @@ -6,12 +6,12 @@ ### Properties -* [balances](gateway.md#balances) -* [batch](gateway.md#batch) -* [config](gateway.md#config) -* [payment](gateway.md#payment) -* [recipient](gateway.md#recipient) -* [recipientAccount](gateway.md#recipientaccount) +- [balances](gateway.md#balances) +- [batch](gateway.md#batch) +- [config](gateway.md#config) +- [payment](gateway.md#payment) +- [recipient](gateway.md#recipient) +- [recipientAccount](gateway.md#recipientaccount) --- @@ -21,9 +21,9 @@ ### balances -**● balances**: *[BalancesGateway](balancesgateway.md)* +**● balances**: _[BalancesGateway](balancesgateway.md)_ -*Defined in [Gateway.md:15]* +_Defined in [Gateway.md:15]_ --- @@ -31,9 +31,9 @@ ### batch -**● batch**: *[BatchGateway](batchgateway.md)* +**● batch**: _[BatchGateway](batchgateway.md)_ -*Defined in [Gateway.java:13](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Gateway.java#L13)* +_Defined in [Gateway.java:13](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Gateway.java#L13)_ --- @@ -41,9 +41,9 @@ ### config -**● config**: *[Configuration](configuration.md)* +**● config**: _[Configuration](configuration.md)_ -*Defined in [Gateway.java:10](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Gateway.java#L10)* +_Defined in [Gateway.java:10](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Gateway.java#L10)_ --- @@ -51,9 +51,9 @@ ### payment -**● payment**: *[PaymentGateway](paymentgateway.md)* +**● payment**: _[PaymentGateway](paymentgateway.md)_ -*Defined in [Gateway.java:16](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Gateway.java#L16)* +_Defined in [Gateway.java:16](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Gateway.java#L16)_ --- @@ -61,9 +61,9 @@ ### recipient -**● recipient**: *[RecipientGateway](recipientgateway.md)* +**● recipient**: _[RecipientGateway](recipientgateway.md)_ -*Defined in [Gateway.java:12](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Gateway.java#L12)* +_Defined in [Gateway.java:12](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Gateway.java#L12)_ --- @@ -71,8 +71,8 @@ ### recipientAccount -**● recipientAccount**: *[RecipientAccountGateway](recipientaccountgateway.md)* +**● recipientAccount**: _[RecipientAccountGateway](recipientaccountgateway.md)_ -*Defined in [Gateway.java:14](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Gateway.java#L14)* +_Defined in [Gateway.java:14](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Gateway.java#L14)_ ---- \ No newline at end of file +--- diff --git a/docs/classes/paymentgateway.md b/docs/classes/paymentgateway.md index a225a73..7fb78b8 100644 --- a/docs/classes/paymentgateway.md +++ b/docs/classes/paymentgateway.md @@ -6,11 +6,11 @@ ### Methods -* [create](paymentgateway.md#create) -* [find](paymentgateway.md#find) -* [remove](paymentgateway.md#remove) -* [search](paymentgateway.md#search) -* [update](paymentgateway.md#update) +- [create](paymentgateway.md#create) +- [find](paymentgateway.md#find) +- [remove](paymentgateway.md#remove) +- [search](paymentgateway.md#search) +- [update](paymentgateway.md#update) --- @@ -20,9 +20,9 @@ ### create -► **create**(batchId: *`string`*, body: *`any`*): `Payment` +► **create**(batchId: _`string`_, body: _`any`_): `Payment` -*Defined in [PaymentGateway.java:55](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Gateway.java#L55)* +_Defined in [PaymentGateway.java:55](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Gateway.java#L55)_ Create a new payment in a batch @@ -43,9 +43,9 @@ Create a new payment in a batch ### find -► **find**(paymentId: *`string`*): `Payment` +► **find**(paymentId: _`string`_): `Payment` -*Defined in [PaymentGateway.java:34](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Gateway.java#L34)* +_Defined in [PaymentGateway.java:34](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Gateway.java#L34)_ Find a specific payment @@ -65,9 +65,9 @@ Find a specific payment ### delete -► **delete**(paymentId: *`string`*, batchId: *`string`*): `boolean` +► **delete**(paymentId: _`string`_, batchId: _`string`_): `boolean` -*Defined in [PaymentGateway.java:90](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Gateway.java#L90)* +_Defined in [PaymentGateway.java:90](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Gateway.java#L90)_ Delete a given payment -- Note you can only delete non processed payments @@ -88,9 +88,9 @@ Delete a given payment -- Note you can only delete non processed payments ### search -► **search**(batchId: *`string`*, page?: *`number`*, pageSize?: *`number`*, term?: *`string`*): `Payment`[] +► **search**(batchId: _`string`_, page?: _`number`_, pageSize?: _`number`_, term?: _`string`_): `Payment`[] -*Defined in [PaymentGateway.java:105](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Gateway.java#L105)* +_Defined in [PaymentGateway.java:105](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Gateway.java#L105)_ Search for payments in a given batch @@ -111,9 +111,9 @@ Search for payments in a given batch ### update -► **update**(paymentId: *`string`*, batchId: *`string`*, body: *`any`*): `boolean` +► **update**(paymentId: _`string`_, batchId: _`string`_, body: _`any`_): `boolean` -*Defined in [PaymentGateway.java:74](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Gateway.java#L74)* +_Defined in [PaymentGateway.java:74](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Gateway.java#L74)_ Update a given payment @@ -129,4 +129,4 @@ Update a given payment **Returns:** `boolean` ---- \ No newline at end of file +--- diff --git a/docs/classes/recipientaccountgateway.md b/docs/classes/recipientaccountgateway.md index 84cd0d1..7dfcd31 100644 --- a/docs/classes/recipientaccountgateway.md +++ b/docs/classes/recipientaccountgateway.md @@ -6,11 +6,11 @@ ### Methods -* [findAll](recipientaccountgateway.md#findAll) -* [create](recipientaccountgateway.md#create) -* [find](recipientaccountgateway.md#find) -* [remove](recipientaccountgateway.md#remove) -* [update](recipientaccountgateway.md#update) +- [findAll](recipientaccountgateway.md#findAll) +- [create](recipientaccountgateway.md#create) +- [find](recipientaccountgateway.md#find) +- [remove](recipientaccountgateway.md#remove) +- [update](recipientaccountgateway.md#update) --- @@ -20,9 +20,9 @@ ### all -► **all**(recipientId: *`string`*): `List`(recipientaccount.md)[]> +► **all**(recipientId: _`string`_): `List`(recipientaccount.md)[]> -*Defined in [RecipientAccountGateway.java:33](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/RecipientAccountGateway.java#L33)* +_Defined in [RecipientAccountGateway.java:33](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/RecipientAccountGateway.java#L33)_ Fetch all of the accounts for a given Trolley recipient @@ -43,13 +43,14 @@ Fetch all of the accounts for a given Trolley recipient ### create -► **create**(recipientId: *`string`*, body: *`RecipientAccount`*): `RecipientAccount`(recipientaccount.md)> +► **create**(recipientId: _`string`_, body: _`RecipientAccount`_): `RecipientAccount`(recipientaccount.md)> -*Defined in [RecipientAccountGateway.java:79](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/RecipientAccountGateway.java#L79)* +_Defined in [RecipientAccountGateway.java:79](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/RecipientAccountGateway.java#L79)_ Create a new recipient account RecipientAccount recipientAccount = client.recipientAccount.create("R-112e2c3x","{\"type\":\"bank-transfer\",\"primary\":\"true\",\"country\":\"CA\",\"currency\":\"CAD\",\"accountNum\":\"012345678\",\"bankId\":\"004\",\"branchId\":\"47261\",\"accountHolderName\":\"John Smith\"}"); + **Parameters:** | Param | Type | Description | @@ -65,9 +66,9 @@ Create a new recipient account ### find -► **find**(recipientId: *`string`*, accountId: *`string`*): `RecipientAccount`(recipientaccount.md)> +► **find**(recipientId: _`string`_, accountId: _`string`_): `RecipientAccount`(recipientaccount.md)> -*Defined in [RecipientAccountGateway.java:52](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/RecipientAccountGateway.java#L52)* +_Defined in [RecipientAccountGateway.java:52](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/RecipientAccountGateway.java#L52)_ Fetch a specific account for a given Trolley recipient @@ -88,9 +89,9 @@ RecipientAccount recipientAccount = client.recipientAccount.find("R-ad322121", " ### delete -► **delete**(recipientId: *`string`*, accountId: *`string`*): `boolean` +► **delete**(recipientId: _`string`_, accountId: _`string`_): `boolean` -*Defined in [RecipientAccountGateway.java:121](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/RecipientAccountGateway.java#L121)* +_Defined in [RecipientAccountGateway.java:121](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/RecipientAccountGateway.java#L121)_ Delete the given recipient account. This will only return success, otherwise it will throw an exception (e.g. NotFound) @@ -111,9 +112,9 @@ Delete the given recipient account. This will only return success, otherwise it ### update -► **update**(recipientId: *`string`*, accountId: *`string`*, body: *`RecipientAccount`*): `RecipientAccount`(recipientaccount.md)> +► **update**(recipientId: _`string`_, accountId: _`string`_, body: _`RecipientAccount`_): `RecipientAccount`(recipientaccount.md)> -*Defined in [RecipientAccountGateway.java:102](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/RecipientAccountGateway.java#L102)* +_Defined in [RecipientAccountGateway.java:102](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/RecipientAccountGateway.java#L102)_ Update a recipient account. Note: Updating an account will create a new account ID if it contains any property that isn't just "primary" @@ -129,4 +130,4 @@ Update a recipient account. Note: Updating an account will create a new account **Returns:** `RecipientAccount`(recipientaccount.md)> ---- \ No newline at end of file +--- diff --git a/docs/classes/recipientgateway.md b/docs/classes/recipientgateway.md index cfdbbdc..6e996e3 100644 --- a/docs/classes/recipientgateway.md +++ b/docs/classes/recipientgateway.md @@ -6,11 +6,11 @@ ### Methods -* [create](RecipientGateway.md#create) -* [find](RecipientGateway.md#find) -* [remove](RecipientGateway.md#remove) -* [search](RecipientGateway.md#search) -* [update](RecipientGateway.md#update) +- [create](RecipientGateway.md#create) +- [find](RecipientGateway.md#find) +- [remove](RecipientGateway.md#remove) +- [search](RecipientGateway.md#search) +- [update](RecipientGateway.md#update) --- @@ -20,9 +20,9 @@ ### create -► **create**(body: *[Recipient](../types/recipient.md)*): `Recipient` +► **create**(body: _[Recipient](../types/recipient.md)_): `Recipient` -*Defined in [RecipientGateway.java:82](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/RecipientGateway.java#L82)* +_Defined in [RecipientGateway.java:82](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/RecipientGateway.java#L82)_ Create a given recipient @@ -32,9 +32,9 @@ Create a given recipient **Parameters:** -| Param | Type | Description | -| ------ | ------ | ------ | -| body | [Recipient](../types/recipient.md) | The recipient information to create | +| Param | Type | Description | +| ----- | ---------------------------------- | ----------------------------------- | +| body | [Recipient](../types/recipient.md) | The recipient information to create | **Returns:** `Recipient` @@ -44,9 +44,9 @@ Create a given recipient ### find -► **find**(recipientId: *`string`*): `Recipient` +► **find**(recipientId: _`string`_): `Recipient` -*Defined in [RecipientGateway.java:58](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/RecipientGateway.java#L58)* +_Defined in [RecipientGateway.java:58](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/RecipientGateway.java#L58)_ Find a specific recipient by their Trolley recipient ID @@ -66,9 +66,9 @@ Recipient recipient = client.recipient.find(R-efr313md8cj); ### delete -► **delete**(recipientId: *`string`*): `boolean` +► **delete**(recipientId: _`string`_): `boolean` -*Defined in [RecipientGateway.java:115](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/RecipientGateway.java#L115)* +_Defined in [RecipientGateway.java:115](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/RecipientGateway.java#L115)_ Delete the given recipient. @@ -88,17 +88,17 @@ Delete the given recipient. ### search -► **search**(page: *`number`*, pageSize: *`number`*, term: *`string`*): `Recipient`[] +► **search**(page: _`number`_, pageSize: _`number`_, term: _`string`_): `Recipient`[] -*Defined in [RecipientGateway.java:123](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/RecipientGateway.java#L123)* +_Defined in [RecipientGateway.java:123](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/RecipientGateway.java#L123)_ **Parameters:** -| Param | Type | Description | -| ------ | ------ | ------ | -| page | `number` | - | -| pageSize | `number` | - | -| term | `string` | - | +| Param | Type | Description | +| -------- | -------- | ----------- | +| page | `number` | - | +| pageSize | `number` | - | +| term | `string` | - | **Returns:** `Recipient`[] @@ -108,9 +108,9 @@ Delete the given recipient. ### update -► **update**(body: *[Recipient](../types/recipient.md)*): `boolean` +► **update**(body: _[Recipient](../types/recipient.md)_): `boolean` -*Defined in [RecipientGateway.java:100](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/RecipientGateway.java#L100)* +_Defined in [RecipientGateway.java:100](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/RecipientGateway.java#L100)_ Update the given recipient @@ -118,10 +118,10 @@ Update the given recipient **Parameters:** -| Param | Type | Description | -| ------ | ------ | ------ | -| body | [Recipient](../types/recipient.md) | the changes to make to the recipient | +| Param | Type | Description | +| ----- | ---------------------------------- | ------------------------------------ | +| body | [Recipient](../types/recipient.md) | the changes to make to the recipient | **Returns:** `boolean` ---- \ No newline at end of file +--- diff --git a/docs/types/batch.md b/docs/types/batch.md index 54f8aa5..e22d941 100644 --- a/docs/types/batch.md +++ b/docs/types/batch.md @@ -2,7 +2,7 @@ # Types: Batch -*__type__*: Batch +_**type**_: Batch ## Properties @@ -10,9 +10,9 @@ ### description -**● description**: *`undefined`⎮`string`* +**● description**: _`undefined`⎮`string`_ -*Defined in [Batch.java:15](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Batch.java#L15)* +_Defined in [Batch.java:15](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Batch.java#L15)_ --- @@ -20,8 +20,8 @@ ### sourceCurrency -**● sourceCurrency**: *`undefined`⎮`string`* +**● sourceCurrency**: _`undefined`⎮`string`_ -*Defined in [Batch.java:14](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Batch.java#L14)* +_Defined in [Batch.java:14](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Batch.java#L14)_ ---- \ No newline at end of file +--- diff --git a/docs/types/configurationparams.md b/docs/types/configurationparams.md index 9f6b683..b2733b1 100644 --- a/docs/types/configurationparams.md +++ b/docs/types/configurationparams.md @@ -8,9 +8,9 @@ ### «Optional» environment -**● environment**: *"production"⎮"sandbox"⎮"integration"⎮"development"* +**● environment**: _"production"⎮"sandbox"⎮"integration"⎮"development"_ -*Defined in [Configuration.java:15](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Configuration.java#L15)* +_Defined in [Configuration.java:15](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Configuration.java#L15)_ The environment that you're using, most likely one of "production" or "sandbox" @@ -20,9 +20,9 @@ The environment that you're using, most likely one of "production" or "sandbox" ### public key -**● public key**: *`string`* +**● public key**: _`string`_ -*Defined in [Configuration.java:7](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Configuration.java#L7)* +_Defined in [Configuration.java:7](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Configuration.java#L7)_ The Trolley public key @@ -32,10 +32,10 @@ The Trolley public key ### private key -**● private key**: *`string`* +**● private key**: _`string`_ -*Defined in [Configuration.java:11](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Configuration.java#L11)* +_Defined in [Configuration.java:11](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Configuration.java#L11)_ The Trolley private key ---- \ No newline at end of file +--- diff --git a/docs/types/payment.md b/docs/types/payment.md index 7b64100..59af32c 100644 --- a/docs/types/payment.md +++ b/docs/types/payment.md @@ -2,7 +2,7 @@ # Types: Payment -*__type__*: Payment +_**type**_: Payment ## Properties @@ -10,9 +10,9 @@ ### «Optional» memo -**● memo**: *`undefined`⎮`string`* +**● memo**: _`undefined`⎮`string`_ -*Defined in [Payment.java:22](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Payment.java#L22)* +_Defined in [Payment.java:22](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Payment.java#L22)_ --- @@ -20,15 +20,15 @@ ### recipient -**● recipient**: *`object`* +**● recipient**: _`object`_ -*Defined in [Payment.java:23](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Payment.java#L23)* +_Defined in [Payment.java:23](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Payment.java#L23)_ #### Type declaration -«Optional» email: `undefined`⎮`string` -«Optional» id: `undefined`⎮`string` -«Optional» referenceId: `undefined`⎮`string` +«Optional» email: `undefined`⎮`string` +«Optional» id: `undefined`⎮`string` +«Optional» referenceId: `undefined`⎮`string` --- @@ -36,9 +36,9 @@ ### «Optional» sourceAmount -**● sourceAmount**: *`undefined`⎮`string`* +**● sourceAmount**: _`undefined`⎮`string`_ -*Defined in [Payment.java:19](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Payment.java#L19)* +_Defined in [Payment.java:19](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Payment.java#L19)_ --- @@ -46,9 +46,9 @@ ### «Optional» targetAmount -**● targetAmount**: *`undefined`⎮`string`* +**● targetAmount**: _`undefined`⎮`string`_ -*Defined in [Payment.java:20](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Payment.java#L20)* +_Defined in [Payment.java:20](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Payment.java#L20)_ --- @@ -56,8 +56,8 @@ ### «Optional» targetCurrency -**● targetCurrency**: *`undefined`⎮`string`* +**● targetCurrency**: _`undefined`⎮`string`_ -*Defined in [Payment.java:21](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Payment.java#L21)* +_Defined in [Payment.java:21](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Payment.java#L21)_ ---- \ No newline at end of file +--- diff --git a/docs/types/recipient.md b/docs/types/recipient.md index 7a7b5e2..02a8467 100644 --- a/docs/types/recipient.md +++ b/docs/types/recipient.md @@ -2,7 +2,7 @@ # Types: Recipient -*__type__*: Recipient +_**type**_: Recipient ## Properties @@ -10,9 +10,9 @@ ### «Optional» account -**● account**: *`any`* +**● account**: _`any`_ -*Defined in [Recipient.java:30](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Recipient.java#L29)* +_Defined in [Recipient.java:30](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Recipient.java#L29)_ --- @@ -20,9 +20,9 @@ ### «Optional» address -**● address**: *`undefined`⎮`object`* +**● address**: _`undefined`⎮`object`_ -*Defined in [Recipient.java:20](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Recipient.java#L20)* +_Defined in [Recipient.java:20](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Recipient.java#L20)_ --- @@ -30,9 +30,9 @@ ### «Optional» dob -**● dob**: *`undefined`⎮`string`* +**● dob**: _`undefined`⎮`string`_ -*Defined in [Recipient.java:15](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Recipient.java#L15)* +_Defined in [Recipient.java:15](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Recipient.java#L15)_ --- @@ -40,9 +40,9 @@ ### «Optional» email -**● email**: *`undefined`⎮`string`* +**● email**: _`undefined`⎮`string`_ -*Defined in [Recipient.java:10](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Recipient.java#L10)* +_Defined in [Recipient.java:10](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Recipient.java#L10)_ --- @@ -50,9 +50,9 @@ ### «Optional» firstName -**● firstName**: *`undefined`⎮`string`* +**● firstName**: _`undefined`⎮`string`_ -*Defined in [Recipient.java:12](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Recipient.java#L12)* +_Defined in [Recipient.java:12](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Recipient.java#L12)_ --- @@ -60,9 +60,9 @@ ### «Optional» governmentId -**● governmentId**: *`undefined`⎮`string`* +**● governmentId**: _`undefined`⎮`string`_ -*Defined in [Recipient.java:17](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Recipient.java#L17)* +_Defined in [Recipient.java:17](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Recipient.java#L17)_ --- @@ -70,9 +70,9 @@ ### «Optional» language -**● language**: *`undefined`⎮`string`* +**● language**: _`undefined`⎮`string`_ -*Defined in [Recipient.java:19](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Recipient.java#L19)* +_Defined in [Recipient.java:19](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Recipient.java#L19)_ --- @@ -80,9 +80,9 @@ ### «Optional» lastName -**● lastName**: *`undefined`⎮`string`* +**● lastName**: _`undefined`⎮`string`_ -*Defined in [Recipient.java:13](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Recipient.java#L13)* +_Defined in [Recipient.java:13](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Recipient.java#L13)_ --- @@ -90,9 +90,9 @@ ### «Optional» name -**● name**: *`undefined`⎮`string`* +**● name**: _`undefined`⎮`string`_ -*Defined in [Recipient.java:11](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Recipient.java#L11)* +_Defined in [Recipient.java:11](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Recipient.java#L11)_ --- @@ -100,9 +100,9 @@ ### «Optional» passport -**● passport**: *`undefined`⎮`string`* +**● passport**: _`undefined`⎮`string`_ -*Defined in [Recipient.java:18](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Recipient.java#L18)* +_Defined in [Recipient.java:18](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Recipient.java#L18)_ --- @@ -110,9 +110,9 @@ ### «Optional» referenceId -**● referenceId**: *`undefined`⎮`string`* +**● referenceId**: _`undefined`⎮`string`_ -*Defined in [Recipient.java:9](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Recipient.java#L9)* +_Defined in [Recipient.java:9](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Recipient.java#L9)_ --- @@ -120,9 +120,9 @@ ### «Optional» ssn -**● ssn**: *`undefined`⎮`string`* +**● ssn**: _`undefined`⎮`string`_ -*Defined in [Recipient.java:16](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Recipient.java#L16)* +_Defined in [Recipient.java:16](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Recipient.java#L16)_ --- @@ -130,8 +130,8 @@ ### «Optional» type -**● type**: *"individual"⎮"business"* +**● type**: _"individual"⎮"business"_ -*Defined in [Recipient.java:14](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/Recipient.java#L14)* +_Defined in [Recipient.java:14](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/Recipient.java#L14)_ ---- \ No newline at end of file +--- diff --git a/docs/types/recipientaccount.md b/docs/types/recipientaccount.md index 1fe3b7e..9977d12 100644 --- a/docs/types/recipientaccount.md +++ b/docs/types/recipientaccount.md @@ -2,7 +2,7 @@ # Types: RecipientAccount -*__type__*: RecipientAccount +_**type**_: RecipientAccount ## Properties @@ -10,18 +10,19 @@ ### «Optional» accountHolderName -**● accountHolderName**: *`undefined`⎮`string`* +**● accountHolderName**: _`undefined`⎮`string`_ -*Defined in [RecipientAccount.java:23](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/RecipientAccount.java#L23)* +_Defined in [RecipientAccount.java:23](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/RecipientAccount.java#L23)_ --- + ### «Optional» accountNum -**● accountNum**: *`undefined`⎮`string`* +**● accountNum**: _`undefined`⎮`string`_ -*Defined in [RecipientAccount.java:22](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/RecipientAccount.java#L22)* +_Defined in [RecipientAccount.java:22](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/RecipientAccount.java#L22)_ --- @@ -29,9 +30,9 @@ ### «Optional» bankAddress -**● bankAddress**: *`undefined`⎮`string`* +**● bankAddress**: _`undefined`⎮`string`_ -*Defined in [RecipientAccount.java:28](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/RecipientAccount.java#L28)* +_Defined in [RecipientAccount.java:28](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/RecipientAccount.java#L28)_ --- @@ -39,9 +40,9 @@ ### «Optional» bankCity -**● bankCity**: *`undefined`⎮`string`* +**● bankCity**: _`undefined`⎮`string`_ -*Defined in [RecipientAccount.java:29](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/RecipientAccount.java#L29)* +_Defined in [RecipientAccount.java:29](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/RecipientAccount.java#L29)_ --- @@ -49,9 +50,9 @@ ### «Optional» bankId -**● bankId**: *`undefined`⎮`string`* +**● bankId**: _`undefined`⎮`string`_ -*Defined in [RecipientAccount.java:26](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/RecipientAccount.java#L26)* +_Defined in [RecipientAccount.java:26](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/RecipientAccount.java#L26)_ --- @@ -59,9 +60,9 @@ ### «Optional» bankName -**● bankName**: *`undefined`⎮`string`* +**● bankName**: _`undefined`⎮`string`_ -*Defined in [RecipientAccount.java:27](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/RecipientAccount.java#L27)* +_Defined in [RecipientAccount.java:27](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/RecipientAccount.java#L27)_ --- @@ -69,9 +70,9 @@ ### «Optional» bankPostalCode -**● bankPostalCode**: *`undefined`⎮`string`* +**● bankPostalCode**: _`undefined`⎮`string`_ -*Defined in [RecipientAccount.java:31](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/RecipientAccount.java#L31)* +_Defined in [RecipientAccount.java:31](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/RecipientAccount.java#L31)_ --- @@ -79,9 +80,9 @@ ### «Optional» bankRegionCode -**● bankRegionCode**: *`undefined`⎮`string`* +**● bankRegionCode**: _`undefined`⎮`string`_ -*Defined in [RecipientAccount.java:30](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/RecipientAccount.java#L30)* +_Defined in [RecipientAccount.java:30](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/RecipientAccount.java#L30)_ --- @@ -89,9 +90,9 @@ ### «Optional» branchId -**● branchId**: *`undefined`⎮`string`* +**● branchId**: _`undefined`⎮`string`_ -*Defined in [RecipientAccount.java:25](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/RecipientAccount.java#L25)* +_Defined in [RecipientAccount.java:25](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/RecipientAccount.java#L25)_ --- @@ -99,9 +100,9 @@ ### «Optional» country -**● country**: *`undefined`⎮`string`* +**● country**: _`undefined`⎮`string`_ -*Defined in [RecipientAccount.java:19](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/RecipientAccount.java#L19)* +_Defined in [RecipientAccount.java:19](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/RecipientAccount.java#L19)_ --- @@ -109,9 +110,9 @@ ### currency -**● currency**: *`string`* = "" +**● currency**: _`string`_ = "" -*Defined in [RecipientAccount.java:11](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/RecipientAccount.java#L11)* +_Defined in [RecipientAccount.java:11](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/RecipientAccount.java#L11)_ --- @@ -119,9 +120,9 @@ ### «Optional» emailAddress -**● emailAddress**: *`undefined`⎮`string`* +**● emailAddress**: _`undefined`⎮`string`_ -*Defined in [RecipientAccount.java:16](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/RecipientAccount.java#L16)* +_Defined in [RecipientAccount.java:16](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/RecipientAccount.java#L16)_ --- @@ -129,9 +130,9 @@ ### «Optional» iban -**● iban**: *`undefined`⎮`string`* +**● iban**: _`undefined`⎮`string`_ -*Defined in [RecipientAccount.java:21](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/RecipientAccount.java#L21)* +_Defined in [RecipientAccount.java:21](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/RecipientAccount.java#L21)_ --- @@ -139,9 +140,9 @@ ### id -**● id**: *`string`* = "" +**● id**: _`string`_ = "" -*Defined in [RecipientAccount.java:9](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/RecipientAccount.java#L9)* +_Defined in [RecipientAccount.java:9](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/RecipientAccount.java#L9)_ --- @@ -149,9 +150,9 @@ ### primary -**● primary**: *`boolean`* = false +**● primary**: _`boolean`_ = false -*Defined in [RecipientAccount.java:10](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/RecipientAccount.java#L10)* +_Defined in [RecipientAccount.java:10](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/RecipientAccount.java#L10)_ --- @@ -159,9 +160,9 @@ ### «Optional» recipientFees -**● recipientFees**: *`undefined`⎮`string`* +**● recipientFees**: _`undefined`⎮`string`_ -*Defined in [RecipientAccount.java:13](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/RecipientAccount.java#L13)* +_Defined in [RecipientAccount.java:13](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/RecipientAccount.java#L13)_ --- @@ -169,9 +170,9 @@ ### «Optional» routeType -**● routeType**: *`undefined`⎮`string`* +**● routeType**: _`undefined`⎮`string`_ -*Defined in [RecipientAccount.java:12](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/RecipientAccount.java#L12)* +_Defined in [RecipientAccount.java:12](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/RecipientAccount.java#L12)_ --- @@ -179,9 +180,9 @@ ### «Optional» swiftBic -**● swiftBic**: *`string`⎮`null`* +**● swiftBic**: _`string`⎮`null`_ -*Defined in [RecipientAccount.java:24](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/RecipientAccount.java#L24)* +_Defined in [RecipientAccount.java:24](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/RecipientAccount.java#L24)_ --- @@ -189,8 +190,8 @@ ### «Optional» type -**● type**: *`undefined`⎮`string`* +**● type**: _`undefined`⎮`string`_ -*Defined in [RecipientAccount.java:20](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/ca/paymentrails/paymentrails/RecipientAccount.java#L20)* +_Defined in [RecipientAccount.java:20](https://github.com/PaymentRails/java-sdk/tree/master/src/main/java/com/trolley/trolley/RecipientAccount.java#L20)_ ---- \ No newline at end of file +--- diff --git a/pom.xml b/pom.xml index e26d126..5e3ea92 100644 --- a/pom.xml +++ b/pom.xml @@ -1,69 +1,181 @@ 4.0.0 - ca.paymentrails - paymentrails - 1.0.2 - Java SDK for Trolley + com.trolley + java-sdk + 1.1.0 + Java SDK for Trolley API jar Trolley Java SDK + https://github.com/PaymentRails/java-sdk + + + + The MIT License + https://raw.githubusercontent.com/ConvertAPI/convertapi-java/master/LICENSE.txt + repo + + + + + + aman.aalam + Aman Aalam + aman.alam@trolley.com + Trolley + https://www.trolley.com/ + + developer + + + + joshuapr + Joshua Cunningham + joshua@trolley.com + Trolley + https://www.trolley.com/ + + architect + developer + + + + + scm:git:git://github.com/PaymentRails/java-sdk.git + scm:git:git://github.com/PaymentRails/java-sdk.git + https://github.com/PaymentRails/java-sdk + HEAD + - UTF-8 + 1.8 1.8 - 1.6.6 - + + + + ossrh + https://s01.oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.7 + true + + ossrh + https://s01.oss.sonatype.org/ + true + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + -Xdoclint:all -Xdoclint:-missing + -Xdoclint:all -Xdoclint:-missing + + -Xdoclint:all + -Xdoclint:-missing + + + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.5 + + + sign-artifacts + verify + + sign + + + + --pinentry-mode + loopback + + + + + + + + + - org.apache.httpcomponents - httpclient - 4.5.3 + io.github.cdimascio + dotenv-java + 2.3.2 - junit - junit - 4.13.1 - test + org.apache.httpcomponents + httpclient + 4.5.13 + - org.hamcrest - hamcrest-core - 1.3 - test + com.fasterxml.jackson.core + jackson-annotations + 2.15.2 + - org.mockito - mockito-core - 1.10.19 + com.fasterxml.jackson.core + jackson-core + 2.15.2 + - org.powermock - powermock-module-junit4 - ${powermock.version} - test + com.fasterxml.jackson.core + jackson-databind + 2.12.7.1 + org.powermock powermock-api-mockito - ${powermock.version} + 1.6.6 test + + - com.fasterxml.jackson.core - jackson-databind - 2.9.10.1 + junit + junit + 4.13.2 - - com.fasterxml.jackson.core - jackson-annotations - LATEST - - - com.fasterxml.jackson.core - jackson-core - LATEST - - + \ No newline at end of file diff --git a/pom_old.xml b/pom_old.xml new file mode 100644 index 0000000..0e8dcc0 --- /dev/null +++ b/pom_old.xml @@ -0,0 +1,140 @@ + + + 4.0.0 + com.trolley + java-sdk + 1.0.1 + Java SDK for Trolley API + jar + Trolley Java SDK + + UTF-8 + 8 + 8 + 1.6.6 + + + + ossrh + https://s01.oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.7 + true + + ossrh + https://s01.oss.sonatype.org/ + true + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.5 + + + sign-artifacts + verify + + sign + + + + --pinentry-mode + loopback + + + + + + + + + + + + org.apache.httpcomponents + httpclient + 4.5.13 + + + junit + junit + 4.13.1 + test + + + + + org.powermock + powermock-module-junit4 + ${powermock.version} + test + + + org.powermock + powermock-api-mockito + ${powermock.version} + test + + + com.fasterxml.jackson.core + jackson-databind + 2.13.1 + + + com.fasterxml.jackson.core + jackson-annotations + LATEST + + + com.fasterxml.jackson.core + jackson-core + LATEST + + + \ No newline at end of file diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/src/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/src/main/java/ca/paymentrails/Exceptions/AuthenticationException.java b/src/main/java/ca/paymentrails/Exceptions/AuthenticationException.java deleted file mode 100644 index 1be01bc..0000000 --- a/src/main/java/ca/paymentrails/Exceptions/AuthenticationException.java +++ /dev/null @@ -1,13 +0,0 @@ -package ca.paymentrails.Exceptions; - -public class AuthenticationException extends Exception { - - public AuthenticationException() { - super(); - } - - public AuthenticationException(String message) { - super(message); - } - -} diff --git a/src/main/java/ca/paymentrails/Exceptions/AuthorizationException.java b/src/main/java/ca/paymentrails/Exceptions/AuthorizationException.java deleted file mode 100644 index 3a62261..0000000 --- a/src/main/java/ca/paymentrails/Exceptions/AuthorizationException.java +++ /dev/null @@ -1,13 +0,0 @@ -package ca.paymentrails.Exceptions; - -public class AuthorizationException extends Exception { - - public AuthorizationException() { - super(); - } - - public AuthorizationException(String message) { - super(message); - } - -} diff --git a/src/main/java/ca/paymentrails/Exceptions/DownForMaintenanceException.java b/src/main/java/ca/paymentrails/Exceptions/DownForMaintenanceException.java deleted file mode 100644 index 1934a08..0000000 --- a/src/main/java/ca/paymentrails/Exceptions/DownForMaintenanceException.java +++ /dev/null @@ -1,13 +0,0 @@ -package ca.paymentrails.Exceptions; - -public class DownForMaintenanceException extends Exception { - - public DownForMaintenanceException() { - super(); - } - - public DownForMaintenanceException(String message) { - super(message); - } - -} diff --git a/src/main/java/ca/paymentrails/Exceptions/InvalidFieldException.java b/src/main/java/ca/paymentrails/Exceptions/InvalidFieldException.java deleted file mode 100644 index 4acc61e..0000000 --- a/src/main/java/ca/paymentrails/Exceptions/InvalidFieldException.java +++ /dev/null @@ -1,14 +0,0 @@ - -package ca.paymentrails.Exceptions; - -public class InvalidFieldException extends Exception { - - public InvalidFieldException() { - super(); - } - - public InvalidFieldException(String message) { - super(message); - } - -} diff --git a/src/main/java/ca/paymentrails/Exceptions/InvalidServerConnectionException.java b/src/main/java/ca/paymentrails/Exceptions/InvalidServerConnectionException.java deleted file mode 100644 index a55bb44..0000000 --- a/src/main/java/ca/paymentrails/Exceptions/InvalidServerConnectionException.java +++ /dev/null @@ -1,13 +0,0 @@ -package ca.paymentrails.Exceptions; - -public class InvalidServerConnectionException extends Exception { - - public InvalidServerConnectionException() { - super(); - } - - public InvalidServerConnectionException(String message) { - super(message); - } - -} diff --git a/src/main/java/ca/paymentrails/Exceptions/InvalidStatusCodeException.java b/src/main/java/ca/paymentrails/Exceptions/InvalidStatusCodeException.java deleted file mode 100644 index 3525e12..0000000 --- a/src/main/java/ca/paymentrails/Exceptions/InvalidStatusCodeException.java +++ /dev/null @@ -1,13 +0,0 @@ -package ca.paymentrails.Exceptions; - -public class InvalidStatusCodeException extends Exception { - - public InvalidStatusCodeException() { - super(); - } - - public InvalidStatusCodeException(String message) { - super(message); - } - -} diff --git a/src/main/java/ca/paymentrails/Exceptions/MalformedException.java b/src/main/java/ca/paymentrails/Exceptions/MalformedException.java deleted file mode 100644 index 6e47650..0000000 --- a/src/main/java/ca/paymentrails/Exceptions/MalformedException.java +++ /dev/null @@ -1,13 +0,0 @@ -package ca.paymentrails.Exceptions; - -public class MalformedException extends Exception { - - public MalformedException() { - super(); - } - - public MalformedException(String message) { - super(message); - } - -} diff --git a/src/main/java/ca/paymentrails/Exceptions/NotFoundException.java b/src/main/java/ca/paymentrails/Exceptions/NotFoundException.java deleted file mode 100644 index 851a0b7..0000000 --- a/src/main/java/ca/paymentrails/Exceptions/NotFoundException.java +++ /dev/null @@ -1,13 +0,0 @@ -package ca.paymentrails.Exceptions; - -public class NotFoundException extends Exception { - - public NotFoundException() { - super(); - } - - public NotFoundException(String message) { - super(message); - } - -} diff --git a/src/main/java/ca/paymentrails/Exceptions/TooManyRequestsException.java b/src/main/java/ca/paymentrails/Exceptions/TooManyRequestsException.java deleted file mode 100644 index e74fede..0000000 --- a/src/main/java/ca/paymentrails/Exceptions/TooManyRequestsException.java +++ /dev/null @@ -1,13 +0,0 @@ -package ca.paymentrails.Exceptions; - -public class TooManyRequestsException extends Exception { - - public TooManyRequestsException() { - super(); - } - - public TooManyRequestsException(String message) { - super(message); - } - -} diff --git a/src/main/java/ca/paymentrails/Exceptions/UnexpectedException.java b/src/main/java/ca/paymentrails/Exceptions/UnexpectedException.java deleted file mode 100644 index 02ee809..0000000 --- a/src/main/java/ca/paymentrails/Exceptions/UnexpectedException.java +++ /dev/null @@ -1,13 +0,0 @@ -package ca.paymentrails.Exceptions; - -public class UnexpectedException extends Exception { - - public UnexpectedException() { - super(); - } - - public UnexpectedException(String message) { - super(message); - } - -} diff --git a/src/main/java/ca/paymentrails/paymentrails/Balances.java b/src/main/java/ca/paymentrails/paymentrails/Balances.java deleted file mode 100644 index d74480e..0000000 --- a/src/main/java/ca/paymentrails/paymentrails/Balances.java +++ /dev/null @@ -1,60 +0,0 @@ -package ca.paymentrails.paymentrails; - -public class Balances { - - public EUR EUR; - - public USD USD; - - public CAD CAD; - - public EUR getEUR() { - return EUR; - } - - public void setEUR(EUR EUR) { - this.EUR = EUR; - } - - public USD getUSD() { - return USD; - } - - public void setUSD(USD USD) { - this.USD = USD; - } - - public CAD getCAD() { - return CAD; - } - - public void setCAD(CAD CAD) { - this.CAD = CAD; - } - - /** - * Retrieves all account balances - * - * @return The response - * @throws ca.paymentrails.Exceptions.InvalidStatusCodeException - * @throws ca.paymentrails.Exceptions.InvalidFieldException - * @throws ca.paymentrails.Exceptions.InvalidConnectionException - */ - public static String find() throws Exception { - return find(""); - } - - /** - * Retrieves balance based on term - * - * @param term (paypal or paymentrails) - * @return The response - * @throws ca.paymentrails.Exceptions.InvalidStatusCodeException - * @throws ca.paymentrails.Exceptions.InvalidFieldException - * @throws ca.paymentrails.Exceptions.InvalidConnectionException - */ - public static String find(String term) throws Exception { - return Configuration.gateway().balances.find(term); - } - -} diff --git a/src/main/java/ca/paymentrails/paymentrails/BalancesGateway.java b/src/main/java/ca/paymentrails/paymentrails/BalancesGateway.java deleted file mode 100644 index eef1bab..0000000 --- a/src/main/java/ca/paymentrails/paymentrails/BalancesGateway.java +++ /dev/null @@ -1,20 +0,0 @@ -package ca.paymentrails.paymentrails; - -import ca.paymentrails.Exceptions.InvalidFieldException; - -public class BalancesGateway { - Client client; - - public BalancesGateway(Configuration config) { - this.client = new Client(config); - } - - public String find(String term) throws Exception { - if (term == null) { - throw new InvalidFieldException("Term cannot be null"); - } - String endPoint = "/v1/balances/" + term; - String response = this.client.get(endPoint); - return response; - } -} \ No newline at end of file diff --git a/src/main/java/ca/paymentrails/paymentrails/Batch.java b/src/main/java/ca/paymentrails/paymentrails/Batch.java deleted file mode 100644 index f50b375..0000000 --- a/src/main/java/ca/paymentrails/paymentrails/Batch.java +++ /dev/null @@ -1,258 +0,0 @@ -package ca.paymentrails.paymentrails; - -import java.util.List; - -public class Batch { - - private String id; - private String status; - private String amount; - private Integer totalPayments; - private String currency; - private String description; - private Object sentAt; - private Object completedAt; - private String createdAt; - private String updatedAt; - private Payments payments; - public String quoteExpiredAt; - - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public String getAmount() { - return amount; - } - - public void setAmount(String amount) { - this.amount = amount; - } - - public Integer getTotalPayments() { - return totalPayments; - } - - public void setTotalPayments(Integer totalPayments) { - this.totalPayments = totalPayments; - } - - public String getCurrency() { - return currency; - } - - public void setCurrency(String currency) { - this.currency = currency; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public Object getSentAt() { - return sentAt; - } - - public void setSentAt(Object sentAt) { - this.sentAt = sentAt; - } - - public Object getCompletedAt() { - return completedAt; - } - - public void setCompletedAt(Object completedAt) { - this.completedAt = completedAt; - } - - public String getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(String createdAt) { - this.createdAt = createdAt; - } - - public String getUpdatedAt() { - return updatedAt; - } - - public void setUpdatedAt(String updatedAt) { - this.updatedAt = updatedAt; - } - - public Payments getPayments() { - return payments; - } - - public void setPayments(Payments payments) { - this.payments = payments; - } - - /** - * Retrieves a batch based on the batch id given - * - * @param batch_id - * @return The response - * @throws ca.paymentrails.Exceptions.InvalidStatusCodeException - * @throws ca.paymentrails.Exceptions.InvalidFieldException - * @throws ca.paymentrails.Exceptions.InvalidConnectionException - */ - public static Batch find(String batch_id) throws Exception { - return Configuration.gateway().batch.find(batch_id); - } - - /** - * Updates a batch based on the batch id and body - * - * @param batch_id - * @param body - * @return The response - * @throws ca.paymentrails.Exceptions.InvalidStatusCodeException - * @throws ca.paymentrails.Exceptions.InvalidFieldException - * @throws ca.paymentrails.Exceptions.InvalidConnectionException - */ - public static boolean update(String batch_id, String body) throws Exception { - return Configuration.gateway().batch.update(batch_id, body); - } - - /** - * Deletes a batch based on batch id - * - * @param batch_id - * @return The response - * @throws ca.paymentrails.Exceptions.InvalidStatusCodeException - * @throws ca.paymentrails.Exceptions.InvalidFieldException - * @throws ca.paymentrails.Exceptions.InvalidConnectionException - */ - public static boolean delete(String batch_id) throws Exception { - return Configuration.gateway().batch.delete(batch_id); - } - - /** - * Creates a batch based on batch the body - * - * @param body - * @return The response - * @throws ca.paymentrails.Exceptions.InvalidStatusCodeException - * @throws ca.paymentrails.Exceptions.InvalidFieldException - * @throws ca.paymentrails.Exceptions.InvalidConnectionException - */ - public static Batch create(String body) throws Exception { - return Configuration.gateway().batch.create(body); - } - - /** - * Generate a quote for a batch - * - * @param batch_id - * @return The response - * @throws ca.paymentrails.Exceptions.InvalidStatusCodeException - * @throws ca.paymentrails.Exceptions.InvalidFieldException - * @throws ca.paymentrails.Exceptions.InvalidConnectionException - */ - public static String generateQuote(String batch_id) throws Exception { - return Configuration.gateway().batch.generateQuote(batch_id); - } - - /** - * Process a batch - * - * @param batch_id - * @return The response - * @throws ca.paymentrails.Exceptions.InvalidStatusCodeException - * @throws ca.paymentrails.Exceptions.InvalidFieldException - * @throws ca.paymentrails.Exceptions.InvalidConnectionException - */ - public static String processBatch(String batch_id) throws Exception { - return Configuration.gateway().batch.processBatch(batch_id); - } - - /** - * List all Batches based on the recipient id and (optional) a given - * wildcard, page amount and page size - * - * @param page - * @param pageSize - * @param message - * @return The response - * @throws ca.paymentrails.Exceptions.InvalidStatusCodeException - * @throws ca.paymentrails.Exceptions.InvalidConnectionException - * @throws ca.paymentrails.Exceptions.InvalidFieldException - */ - public static List query(int page, int pageSize, String message) throws Exception { - return Configuration.gateway().batch.query(page, pageSize, message); - - } - - /** - * List all batches based on the recipient id and a given wildcard - * - * @param message - * @return The response - * @throws ca.paymentrails.Exceptions.InvalidStatusCodeException - * @throws ca.paymentrails.Exceptions.InvalidConnectionException - * @throws ca.paymentrails.Exceptions.InvalidFieldException - */ - public static List query(String message) throws Exception { - return query(1, 10, message); - } - - /** - * List all batches - * - * @return The response - * @throws ca.paymentrails.Exceptions.InvalidStatusCodeException - * @throws ca.paymentrails.Exceptions.InvalidConnectionException - * @throws ca.paymentrails.Exceptions.InvalidFieldException - */ - public static List query() throws Exception { - return query(1, 10, ""); - } - - /** - * List all batches based on the recipient id and (optional) page amount and - * page size - * - * @param page - * @param pageNumber - * @return The response - * @throws ca.paymentrails.Exceptions.InvalidStatusCodeException - * @throws ca.paymentrails.Exceptions.InvalidConnectionException - * @throws ca.paymentrails.Exceptions.InvalidFieldException - */ - public static List query(int page, int pageNumber) throws Exception { - return query(page, pageNumber, ""); - } - - /** - * Retrieves summary of batch - * - * @param batch_id - * @return The response - * @throws ca.paymentrails.Exceptions.InvalidStatusCodeException - * @throws ca.paymentrails.Exceptions.InvalidFieldException - * @throws ca.paymentrails.Exceptions.InvalidConnectionException - */ - public static BatchSummary summary(String batch_id) throws Exception { - return Configuration.gateway().batch.summary(batch_id); - - } -} diff --git a/src/main/java/ca/paymentrails/paymentrails/BatchGateway.java b/src/main/java/ca/paymentrails/paymentrails/BatchGateway.java deleted file mode 100644 index ede97d2..0000000 --- a/src/main/java/ca/paymentrails/paymentrails/BatchGateway.java +++ /dev/null @@ -1,146 +0,0 @@ -package ca.paymentrails.paymentrails; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - -import ca.paymentrails.Exceptions.InvalidFieldException; - -public class BatchGateway { - Client client; - - public BatchGateway(Configuration config) { - this.client = new Client(config); - } - - public Batch find(String batch_id) throws Exception { - if (batch_id == null || batch_id.isEmpty()) { - throw new InvalidFieldException("Batch id cannot be null or empty."); - } - - String endPoint = "/v1/batches/" + batch_id; - String response = this.client.get(endPoint); - return batchFactory(response); - } - - public boolean update(String batch_id, String body) throws Exception { - if (batch_id == null || batch_id.isEmpty()) { - throw new InvalidFieldException("Batch id cannot be null or empty."); - } - if (body == null || body.isEmpty()) { - throw new InvalidFieldException("Body cannot be null or empty."); - } - - String endPoint = "/v1/batches/" + batch_id; - this.client.patch(endPoint, body); - return true; - } - - public boolean delete(String batch_id) throws Exception { - if (batch_id == null || batch_id.isEmpty()) { - throw new InvalidFieldException("Batch id cannot be null or empty."); - } - - String endPoint = "/v1/batches/" + batch_id; - this.client.delete(endPoint); - return true; - } - - public Batch create(String body) throws Exception { - if (body == null || body.isEmpty()) { - throw new InvalidFieldException("Body cannot be null or empty."); - } - - String endPoint = "/v1/batches/"; - String response = this.client.post(endPoint, body); - return batchFactory(response); - } - - public String generateQuote(String batch_id) throws Exception { - if (batch_id == null || batch_id.isEmpty()) { - throw new InvalidFieldException("Batch id cannot be null or empty."); - } - - String endPoint = "/v1/batches/" + batch_id + "/generate-quote"; - String response = this.client.post(endPoint); - return response; - } - - public String processBatch(String batch_id) throws Exception { - if (batch_id == null || batch_id.isEmpty()) { - throw new InvalidFieldException("Batch id cannot be null or empty."); - } - String endPoint = "/v1/batches/" + batch_id + "/start-processing"; - String response = this.client.post(endPoint); - return response; - } - - public List query(int page, int pageSize, String message) throws Exception { - if (page < 0) { - throw new InvalidFieldException("Page cannot be less than 0"); - } - if (pageSize < 0) { - throw new InvalidFieldException("Page size cannot be less than 0"); - } - if (message == null) { - throw new InvalidFieldException("Message cannot be null"); - } - String endPoint = "/v1/batches/?" + "&search=" + message + "&page=" + page + "&pageSize=" + pageSize; - String response = this.client.get(endPoint); - return batchListFactory(response); - } - - public List query(String message) throws Exception { - return query(1, 10, message); - } - - public List query() throws Exception { - return query(1, 10, ""); - } - - public List query(int page, int pageNumber) throws Exception { - return query(page, pageNumber, ""); - } - - public BatchSummary summary(String batch_id) throws Exception { - if (batch_id == null || batch_id.isEmpty()) { - throw new InvalidFieldException("Batch id cannot be null os empty"); - } - - String endPoint = "/v1/batches/" + batch_id + "/summary"; - String response = this.client.get(endPoint); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - JsonNode node = mapper.readTree(response); - BatchSummary batchSummary = mapper.readValue(node.get("batchSummary").traverse(), BatchSummary.class); - return batchSummary; - } - - private Batch batchFactory(String data) throws IOException { - ObjectMapper mapper = new ObjectMapper(); - JsonNode node = mapper.readTree(data); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - Batch batch = mapper.readValue(node.get("batch").traverse(), Batch.class); - return batch; - } - - private List batchListFactory(String data) throws IOException { - ObjectMapper mapper = new ObjectMapper(); - JsonNode node = mapper.readTree(data); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - Object batch = mapper.readValue(node.get("batches").traverse(), Object.class); - @SuppressWarnings("unchecked") - List batchs = (List) batch; - List batches = new ArrayList(); - for (int i = 0; i < batchs.size(); i++) { - Batch pojo = mapper.convertValue(batchs.get(i), Batch.class); - batches.add(pojo); - } - return batches; - } -} \ No newline at end of file diff --git a/src/main/java/ca/paymentrails/paymentrails/BatchSummary.java b/src/main/java/ca/paymentrails/paymentrails/BatchSummary.java deleted file mode 100644 index 76a392b..0000000 --- a/src/main/java/ca/paymentrails/paymentrails/BatchSummary.java +++ /dev/null @@ -1,8 +0,0 @@ -package ca.paymentrails.paymentrails; - -public class BatchSummary { - - public Total total; - public Detail detail; - -} \ No newline at end of file diff --git a/src/main/java/ca/paymentrails/paymentrails/Client.java b/src/main/java/ca/paymentrails/paymentrails/Client.java deleted file mode 100644 index 2985deb..0000000 --- a/src/main/java/ca/paymentrails/paymentrails/Client.java +++ /dev/null @@ -1,238 +0,0 @@ -package ca.paymentrails.paymentrails; - -import java.io.BufferedReader; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.URL; -import java.rmi.UnexpectedException; - -import javax.crypto.Mac; -import javax.crypto.spec.SecretKeySpec; - -import org.apache.http.HttpResponse; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpPatch; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.HttpClients; - -import ca.paymentrails.Exceptions.*; - -public class Client { - - private Configuration config; - - public Client(Configuration config) { - this.config = config; - } - - /** - * Factory Method to create an instance of Client - * - * @return Client - */ - public static Client create(Configuration config) { - return new Client(config); - } - - private String sendRequest(String method, String endPoint, String body) throws Exception { - String StringResponse = ""; - HttpURLConnection con; - try { - String url = this.config.getApiBase() + endPoint; - URL obj = new URL(url); - con = (HttpURLConnection) obj.openConnection(); - - int timeStamp = (int) (System.currentTimeMillis() / 1000L); - String authorizarion = generateAuthorization(timeStamp, method, endPoint, body); - - con.setRequestMethod(method); - - con.setRequestProperty("X-PR-Timestamp", timeStamp + ""); - con.setRequestProperty("Authorization", authorizarion); - con.setRequestProperty("Trolley-Source", "java-sdk_1.0.2"); - con.setRequestProperty("Content-Type", "application/json"); - if (method == "POST" && body != "") { - - con.setDoOutput(true); - try (DataOutputStream wr = new DataOutputStream(con.getOutputStream())) { - wr.writeBytes(body); - wr.flush(); - } - } - int responseCode = con.getResponseCode(); - - if (responseCode != 200) { - throwStatusCodeException(responseCode, con.getResponseMessage()); - } - StringBuffer response; - try (BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()))) { - String inputLine; - response = new StringBuffer(); - while ((inputLine = in.readLine()) != null) { - response.append(inputLine); - } - StringResponse = response.toString(); - } catch (IOException e) { - throw new UnexpectedException(StringResponse); - } - - } catch (IOException e) { - throw new UnexpectedException(StringResponse); - } - return StringResponse; - } - - private String sendRequest(String method, String endPoint) throws Exception { - return sendRequest(method, endPoint, ""); - } - - /** - * Makes an HTTP GET request to the API - * - * @param endPoint - * @return The response - * @throws Exception - */ - public String get(String endPoint) throws Exception { - return sendRequest("GET", endPoint); - } - - /** - * Makes an HTTP POST request to the API - * - * @param endPoint - * @param body - * @return The response - * @throws Exception - */ - public String post(String endPoint, String body) throws Exception { - return sendRequest("POST", endPoint, body); - } - - /** - * Makes an HTTP POST request to the API - * - * @param endPoint - * @return The response - * @throws Exception - */ - public String post(String endPoint) throws Exception { - return sendRequest("POST", endPoint); - } - /** - * Makes an HTTP PATCH request to the API - * - * @param endPoint - * @param body - * @return The response - * @throws ca.paymentrails.Exceptions.InvalidStatusCodeException - * @throws ca.paymentrails.Exceptions.InvalidConnectionException - */ - public String patch(String endPoint, String body) throws Exception { - String StringResponse = ""; - try { - - HttpClient httpclient = HttpClients.createDefault(); - HttpPatch httpPatch = new HttpPatch(this.config.getApiBase() + endPoint); - StringEntity params = new StringEntity(body); - - int timeStamp = (int) (System.currentTimeMillis() / 1000L); - String authorizarion = generateAuthorization(timeStamp, "PATCH", endPoint, body); - - params.setContentType("application/json"); - - httpPatch.setEntity(params); - httpPatch.addHeader("X-PR-Timestamp", timeStamp + ""); - httpPatch.addHeader("Trolley-Source", "java-sdk_1.0.2"); - httpPatch.addHeader("Authorization", authorizarion); - - HttpResponse response = httpclient.execute(httpPatch); - StringBuffer result = new StringBuffer(); - String line = ""; - - BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); - while ((line = rd.readLine()) != null) { - result.append(line); - } - - StringResponse = result.toString(); - - int responseCode = response.getStatusLine().getStatusCode(); - if (responseCode != 200) { - throwStatusCodeException(responseCode, StringResponse); - } - - } catch (IOException e) { - throw new UnexpectedException(StringResponse); - } - return StringResponse; - } - - /** - * Makes an HTTP DELETE request to the API - * - * @param endPoint - * @return The response - * @throws InvalidStatusCodeException - * @throws ca.paymentrails.Exceptions.InvalidConnectionException - */ - public String delete(String endPoint) throws Exception { - return sendRequest("DELETE", endPoint); - } - - private void throwStatusCodeException(int statusCode, String message) throws Exception { - switch (statusCode) { - case 400: - throw new MalformedException(message); - case 401: - throw new AuthenticationException(message); - case 403: - throw new AuthorizationException(message); - case 404: - throw new NotFoundException(statusCode + " " + message); - case 406: - throw new InvalidStatusCodeException(message); - case 429: - throw new TooManyRequestsException(message); - case 500: - throw new InvalidServerConnectionException(message); - case 503: - throw new DownForMaintenanceException(message); - default: - throw new ca.paymentrails.Exceptions.UnexpectedException(message); - } - } - - private String generateAuthorization(int timeStamp, String method, String endPoint, String body) { - String message = timeStamp + "\n" + method + "\n" + endPoint + "\n" + body + "\n"; - try { - String hash = hmacDigest(message, this.config.getPrivateKey(), "HmacSHA256"); - return "prsign " + this.config.getPublicKey() + ":" + hash; - } catch (Exception e) { - return "prsign 1:1"; - } - - } - - private String hmacDigest(String msg, String keyString, String algo) throws Exception { - String digest = null; - SecretKeySpec key = new SecretKeySpec((keyString).getBytes("UTF-8"), algo); - Mac mac = Mac.getInstance(algo); - mac.init(key); - - byte[] bytes = mac.doFinal(msg.getBytes("ASCII")); - - StringBuffer hash = new StringBuffer(); - for (int i = 0; i < bytes.length; i++) { - String hex = Integer.toHexString(0xFF & bytes[i]); - if (hex.length() == 1) { - hash.append('0'); - } - hash.append(hex); - } - digest = hash.toString(); - return digest; - } -} diff --git a/src/main/java/ca/paymentrails/paymentrails/Compliance.java b/src/main/java/ca/paymentrails/paymentrails/Compliance.java deleted file mode 100644 index 36e8ec3..0000000 --- a/src/main/java/ca/paymentrails/paymentrails/Compliance.java +++ /dev/null @@ -1,35 +0,0 @@ -package ca.paymentrails.paymentrails; - -import java.util.HashMap; -import java.util.Map; - -public class Compliance { - - private String status; - private Object checkedAt; - private Map additionalProperties = new HashMap(); - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public Object getCheckedAt() { - return checkedAt; - } - - public void setCheckedAt(Object checkedAt) { - this.checkedAt = checkedAt; - } - - public Map getAdditionalProperties() { - return this.additionalProperties; - } - - public void setAdditionalProperty(String name, Object value) { - this.additionalProperties.put(name, value); - } -} \ No newline at end of file diff --git a/src/main/java/ca/paymentrails/paymentrails/Configuration.java b/src/main/java/ca/paymentrails/paymentrails/Configuration.java deleted file mode 100644 index b84e250..0000000 --- a/src/main/java/ca/paymentrails/paymentrails/Configuration.java +++ /dev/null @@ -1,109 +0,0 @@ -package ca.paymentrails.paymentrails; - -public class Configuration { - - String apiBase = "https://api.trolley.com"; - String privateKey = ""; - String publicKey = ""; - - public Configuration() { - } - public Configuration(String publicKey, String privateKey){ - this.publicKey = publicKey; - this.privateKey = privateKey; - } - public Configuration(String publicKey, String privateKey, String apiBase) { - this.publicKey = publicKey; - this.privateKey = privateKey; - this.apiBase = setEnviroment(apiBase); - } - - /** - * Getter for the api base - * - * @return the api base - */ - public String getApiBase() { - return this.apiBase; - } - - /** - * Setter for the api base - * - * @param apiBase - */ - public void setApiBase(String apiBase) { - this.apiBase = apiBase; - } - - /** - * Getter for the public static api key - * - * @return publicKey - */ - public String getPublicKey() { - return this.publicKey; - } - - /** - * Setter for the public static key - * - * @param publicKey - */ - public void setPublicKey(String publicKey) { - this.publicKey = publicKey; - } - - /** - * Getter for the private key - * - * @param privateKey - */ - public String getPrivateKey() { - return this.privateKey; - } - - /** - * Setter for the private key - * - * @param privateKey - */ - public void setPrivateKey(String privatKey) { - this.privateKey = privatKey; - } - - public static Gateway gateway() { - return new Gateway(Configuration.instantiate()); - } - - public static Client client(Configuration config) { - return new Client(config); - } - - public static Configuration instantiate() { - return new Configuration(); - } - - /** - * Set the API enviroment - * - * @param enviroment - */ - public String setEnviroment(String enviroment) { - switch (enviroment) { - case "production": - case "PRODUCTION": - return "https://api.trolley.com"; - case "development": - case "DEVELOPMENT": - return "http://api.railz.io"; - case "integration": - case "INTEGRATION": - return "http://api.local.dev:3000"; - case "sandbox": - case "SANDBOX": - return "https://api.trolley.com"; - } - return "https://api.trolley.com"; - } -} \ No newline at end of file diff --git a/src/main/java/ca/paymentrails/paymentrails/EUR.java b/src/main/java/ca/paymentrails/paymentrails/EUR.java deleted file mode 100644 index 7478893..0000000 --- a/src/main/java/ca/paymentrails/paymentrails/EUR.java +++ /dev/null @@ -1,66 +0,0 @@ -package ca.paymentrails.paymentrails; - -public class EUR { - - private Boolean primary; - private String amount; - private String currency; - private String type; - private String accountNumber; - private Boolean display; - - public Boolean getPrimary() { - return primary; - } - - public void setPrimary(Boolean primary) { - this.primary = primary; - } - - public String getAmount() { - return amount; - } - - public void setAmount(String amount) { - this.amount = amount; - } - - public String getCurrency() { - return currency; - } - - public void setCurrency(String currency) { - this.currency = currency; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getAccountNumber() { - return accountNumber; - } - - public void setAccountNumber(String accountNumber) { - this.accountNumber = accountNumber; - } - - public Boolean getDisplay() { - return display; - } - - public void setDisplay(Boolean display) { - this.display = display; - } - - @Override - public String toString() { - return "ClassPojo [amount = " + amount + ", accountNumber = " + accountNumber + ", primary = " + primary - + ", display = " + display + ", type = " + type + ", currency = " + currency + "]"; - } - -} \ No newline at end of file diff --git a/src/main/java/ca/paymentrails/paymentrails/Meta.java b/src/main/java/ca/paymentrails/paymentrails/Meta.java deleted file mode 100644 index 08705b0..0000000 --- a/src/main/java/ca/paymentrails/paymentrails/Meta.java +++ /dev/null @@ -1,32 +0,0 @@ -package ca.paymentrails.paymentrails; - -public class Meta { - - private Integer page; - private Integer pages; - private Integer records; - - public Integer getPage() { - return page; - } - - public void setPage(Integer page) { - this.page = page; - } - - public Integer getPages() { - return pages; - } - - public void setPages(Integer pages) { - this.pages = pages; - } - - public Integer getRecords() { - return records; - } - - public void setRecords(Integer records) { - this.records = records; - } -} \ No newline at end of file diff --git a/src/main/java/ca/paymentrails/paymentrails/Payment.java b/src/main/java/ca/paymentrails/paymentrails/Payment.java deleted file mode 100644 index f6ba890..0000000 --- a/src/main/java/ca/paymentrails/paymentrails/Payment.java +++ /dev/null @@ -1,410 +0,0 @@ -package ca.paymentrails.paymentrails; - -import java.util.List; - -public class Payment { - - private String id; - private Recipient recipient; - private String status; - private Boolean isSupplyPayment; - private String returnedAmount; - - private String amount; - private String currency; - private String category; - private RecipientAccount account; - private List tags; - - private String sourceAmount; - private String sourceCurrency; - private String targetAmount; - private String targetCurrency; - private String exchangeRate; - private String fees; - private String recipientFees; - private String fxRate; - private String memo; - private String externalId; - private Object processedAt; - private String createdAt; - private String updatedAt; - private String merchantFees; - private Compliance compliance; - private String payoutMethod; - private String methodDisplay; - Object batch; - - String withholdingAmount; - String withholdingCurrency; - String equivalentWithholdingAmount; - String equivalentWithholdingCurrency; - - public void setEquivalentWithholdingCurrency(String equivalentWithholdingCurrency) { - this.equivalentWithholdingCurrency = equivalentWithholdingCurrency; - } - - public String getEquivalentWithholdingCurrency() { - return equivalentWithholdingCurrency; - } - - public void setEquivalentWithholdingAmount(String equivalentWithholdingAmount) { - this.equivalentWithholdingAmount = equivalentWithholdingAmount; - } - - public String getEquivalentWithholdingAmount() { - return equivalentWithholdingAmount; - } - - public void setWithholdingCurrency(String withholdingCurrency) { - this.withholdingCurrency = withholdingCurrency; - } - - public List getTags() { - return this.tags; - } - - public void setTags(List tags) { - this.tags = tags; - } - - public RecipientAccount getAccount() { - return account; - } - - public void setAccount(RecipientAccount account) { - this.account = account; - } - - public String getCategory() { - return category; - } - - public void setCategory(String category) { - this.category = category; - } - - public String getCurrency() { - return currency; - } - - public void setCurrency(String currency) { - this.currency = currency; - } - - public String getAmount() { - return amount; - } - - public void setAmount(String amount) { - this.amount = amount; - } - - public String getWithholdingCurrency() { - return withholdingCurrency; - } - - public void setWithholdingAmount(String withholdingAmount) { - this.withholdingAmount = withholdingAmount; - } - - public String getWithholdingAmount() { - return withholdingAmount; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public Recipient getRecipient() { - return recipient; - } - - public void setRecipient(Recipient recipient) { - this.recipient = recipient; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public Boolean getIsSupplyPayment() { - return isSupplyPayment; - } - - public void setIsSupplyPayment(Boolean isSupplyPayment) { - this.isSupplyPayment = isSupplyPayment; - } - - public String getReturnedAmount() { - return returnedAmount; - } - - public void setReturnedAmount(String returnedAmount) { - this.returnedAmount = returnedAmount; - } - - public String getSourceAmount() { - return sourceAmount; - } - - public void setSourceAmount(String sourceAmount) { - this.sourceAmount = sourceAmount; - } - - public String getSourceCurrency() { - return sourceCurrency; - } - - public void setSourceCurrency(String sourceCurrency) { - this.sourceCurrency = sourceCurrency; - } - - public String getTargetAmount() { - return targetAmount; - } - - public void setTargetAmount(String targetAmount) { - this.targetAmount = targetAmount; - } - - public String getTargetCurrency() { - return targetCurrency; - } - - public void setTargetCurrency(String targetCurrency) { - this.targetCurrency = targetCurrency; - } - - public String getExchangeRate() { - return exchangeRate; - } - - public void setExchangeRate(String exchangeRate) { - this.exchangeRate = exchangeRate; - } - - public String getFees() { - return fees; - } - - public void setFees(String fees) { - this.fees = fees; - } - - public String getRecipientFees() { - return recipientFees; - } - - public void setRecipientFees(String recipientFees) { - this.recipientFees = recipientFees; - } - - public String getFxRate() { - return fxRate; - } - - public void setFxRate(String fxRate) { - this.fxRate = fxRate; - } - - public String getMemo() { - return memo; - } - - public void setMemo(String memo) { - this.memo = memo; - } - - public String getExternalId() { - return externalId; - } - - public void setExternalId(String externalId) { - this.externalId = externalId; - } - - public Object getProcessedAt() { - return processedAt; - } - - public void setProcessedAt(Object processedAt) { - this.processedAt = processedAt; - } - - public String getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(String createdAt) { - this.createdAt = createdAt; - } - - public String getUpdatedAt() { - return updatedAt; - } - - public void setUpdatedAt(String updatedAt) { - this.updatedAt = updatedAt; - } - - public String getMerchantFees() { - return merchantFees; - } - - public void setMerchantFees(String merchantFees) { - this.merchantFees = merchantFees; - } - - public Compliance getCompliance() { - return compliance; - } - - public void setCompliance(Compliance compliance) { - this.compliance = compliance; - } - - public String getPayoutMethod() { - return payoutMethod; - } - - public void setPayoutMethod(String payoutMethod) { - this.payoutMethod = payoutMethod; - } - - public String getMethodDisplay() { - return methodDisplay; - } - - public void setMethodDisplay(String methodDisplay) { - this.methodDisplay = methodDisplay; - } - - /** - * Retrieves a batch based on the batch id - * - * @param payment_id - * @param batch_id - * @return The response - * @throws ca.paymentrails.Exceptions.InvalidStatusCodeException - * @throws ca.paymentrails.Exceptions.InvalidConnectionException - * @throws ca.paymentrails.Exceptions.InvalidFieldException - */ - public static Payment find(String payment_id, String batch_id) throws Exception { - return Configuration.gateway().payment.find(payment_id, batch_id); - } - - /** - * Creates a payment based on the body and batch id - * - * @param body - * @param batch_id - * @return The response - * @throws ca.paymentrails.Exceptions.InvalidStatusCodeException - * @throws ca.paymentrails.Exceptions.InvalidConnectionException - * @throws ca.paymentrails.Exceptions.InvalidFieldException - */ - public static Payment create(String body, String batch_id) throws Exception { - return Configuration.gateway().payment.create(body, batch_id); - } - - /** - * Updates a payment based on the payment id, body and batch id - * - * @param payment_id - * @param body - * @param batch_id - * @return The response - * @throws ca.paymentrails.Exceptions.InvalidStatusCodeException - * @throws ca.paymentrails.Exceptions.InvalidConnectionException - * @throws ca.paymentrails.Exceptions.InvalidFieldException - */ - public static boolean update(String payment_id, String body, String batch_id) throws Exception { - return Configuration.gateway().payment.update(payment_id, body, batch_id); - } - - /** - * Deletes a payment based on the payment id and batch id - * - * @param payment_id - * @param batch_id - * @return The response - * @throws ca.paymentrails.Exceptions.InvalidStatusCodeException - * @throws ca.paymentrails.Exceptions.InvalidConnectionException - * @throws ca.paymentrails.Exceptions.InvalidFieldException - */ - public static boolean delete(String payment_id, String batch_id) throws Exception { - return Configuration.gateway().payment.delete(payment_id, batch_id); - } - - /** - * List all payments based on the recipient id and (optional) a given - * wildcard, page amount and page size - * - * @param batch_id - * @param page - * @param pageSize - * @param message - * @return The response - * @throws ca.paymentrails.Exceptions.InvalidStatusCodeException - * @throws ca.paymentrails.Exceptions.InvalidConnectionException - * @throws ca.paymentrails.Exceptions.InvalidFieldException - */ - public static List query(String batch_id, int page, int pageSize, String message) throws Exception { - - return Configuration.gateway().payment.query(batch_id, page, pageSize, message); - - } - - /** - * List all payments based on the recipient id and a given wildcard - * - * @param batch_id - * @param message - * @return The response - * @throws ca.paymentrails.Exceptions.InvalidStatusCodeException - * @throws ca.paymentrails.Exceptions.InvalidConnectionException - * @throws ca.paymentrails.Exceptions.InvalidFieldException - */ - public static List query(String batch_id, String message) throws Exception { - return query(batch_id, 1, 10, message); - } - - /** - * List all payments - * - * @param batch_id - * @return The response - * @throws ca.paymentrails.Exceptions.InvalidStatusCodeException - * @throws ca.paymentrails.Exceptions.InvalidConnectionException - * @throws ca.paymentrails.Exceptions.InvalidFieldException - */ - public static List query(String batch_id) throws Exception { - return query(batch_id, 1, 10, ""); - } - - /** - * List all payments based on the recipient id and (optional) page amount - * and page size - * - * @param batch_id - * @param page - * @param pageSize - * @return The response - * @throws ca.paymentrails.Exceptions.InvalidStatusCodeException - * @throws ca.paymentrails.Exceptions.InvalidConnectionException - * @throws ca.paymentrails.Exceptions.InvalidFieldException - */ - public static List query(String batch_id, int page, int pageSize) throws Exception { - - return query(batch_id, page, pageSize, ""); - } -} diff --git a/src/main/java/ca/paymentrails/paymentrails/Payments.java b/src/main/java/ca/paymentrails/paymentrails/Payments.java deleted file mode 100644 index db032f9..0000000 --- a/src/main/java/ca/paymentrails/paymentrails/Payments.java +++ /dev/null @@ -1,26 +0,0 @@ -package ca.paymentrails.paymentrails; - -import java.util.List; - -public class Payments { - - private List payments = null; - private Meta meta; - - public List getPayments() { - return payments; - } - - public void setPayments(List payments) { - this.payments = payments; - } - - public Meta getMeta() { - return meta; - } - - public void setMeta(Meta meta) { - this.meta = meta; - } - -} \ No newline at end of file diff --git a/src/main/java/ca/paymentrails/paymentrails/Recipient.java b/src/main/java/ca/paymentrails/paymentrails/Recipient.java deleted file mode 100644 index 1747413..0000000 --- a/src/main/java/ca/paymentrails/paymentrails/Recipient.java +++ /dev/null @@ -1,438 +0,0 @@ -package ca.paymentrails.paymentrails; - -import java.util.List; - -public class Recipient { - - String id; - String routeType; - String routeMinimum; - String estimatedFees; - String referenceId; - String email; - String name; - String lastName; - String firstName; - String type; - String taxType; - String status; - String language; - String complianceStatus; - String dob; - String passport; - String updatedAt; - String createdAt; - String gravatarUrl; - String governmentId; - String ssn; - String primaryCurrency; - String placeOfBirth; - List tags; - String merchantId; - String payoutMethod; - public Object payout; - String emailAddress; - public Object inactiveReasons; - - Compliance compliance; - List accounts; - Address address; - - String taxForm; - String taxFormStatus; - String taxWithholdingPercentage = "0.0"; - - public String getTaxFormStatus() { - return this.taxFormStatus; - } - - public void setTaxFormStatus(String taxFormStatus) { - this.taxFormStatus = taxForm; - } - - public List getTags() { - return this.tags; - } - - public void setTags(List tags) { - this.tags = tags; - } - - public String getTaxWithholdingPercentage() { - return this.taxWithholdingPercentage; - } - - public void setTaxWithholdingPercentage(String taxWithholdingPercentage) { - this.taxWithholdingPercentage = taxWithholdingPercentage; - } - - public String getTaxForm() { - return this.taxForm; - } - - public void setTaxForm(String taxForm) { - this.taxForm = taxForm; - } - - public Object getInactiveReasons() { - return inactiveReasons; - } - - public void setInactiveReasons(Object inactiveReasons) { - this.inactiveReasons = inactiveReasons; - } - - public List getAccounts() { - return accounts; - } - - public void setAccounts(List accounts) { - this.accounts = accounts; - } - - public void setAddress(Address address) { - this.address = address; - } - - public Compliance getCompliance() { - return compliance; - } - - public void setCompliance(Compliance compliance) { - this.compliance = compliance; - } - - public String getLastName() { - return this.lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public String getRouteType() { - return this.routeType; - } - - public void setRouteType(String routeType) { - this.routeType = routeType; - } - - public String getRouteMinimum() { - return this.routeMinimum; - } - - public void setRouteMinimum(String routeMinimum) { - this.routeMinimum = routeMinimum; - } - - public String getEstimatedFees() { - return estimatedFees; - } - - public void setEstimatedFees(String estimatedFees) { - this.estimatedFees = estimatedFees; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getReferenceId() { - return referenceId; - } - - public void setReferenceId(String referenceId) { - this.referenceId = referenceId; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getTaxType() { - return taxType; - } - - public void setTaxType(String taxType) { - this.taxType = taxType; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public String getLanguage() { - return language; - } - - public void setLanguage(String language) { - this.language = language; - } - - public String getComplianceStatus() { - return complianceStatus; - } - - public void setComplianceStatus(String complianceStatus) { - this.complianceStatus = complianceStatus; - } - - public String getDob() { - return dob; - } - - public void setDob(String dob) { - this.dob = dob; - } - - public String getPassport() { - return passport; - } - - public void setPassport(String passport) { - this.passport = passport; - } - - public String getUpdatedAt() { - return updatedAt; - } - - public void setUpdatedAt(String updatedAt) { - this.updatedAt = updatedAt; - } - - public String getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(String createdAt) { - this.createdAt = createdAt; - } - - public String getGravatarUrl() { - return gravatarUrl; - } - - public void setGravatarUrl(String gravatarUrl) { - this.gravatarUrl = gravatarUrl; - } - - public String getGovernmentId() { - return governmentId; - } - - public void setGovernmentId(String governmentId) { - this.governmentId = governmentId; - } - - public String getSsn() { - return ssn; - } - - public void setSsn(String ssn) { - this.ssn = ssn; - } - - public String getPrimaryCurrency() { - return primaryCurrency; - } - - public void setPrimaryCurrency(String primaryCurrency) { - this.primaryCurrency = primaryCurrency; - } - - public String getPlaceOfBirth() { - return placeOfBirth; - } - - public void setPlaceOfBirth(String placeOfBirth) { - this.placeOfBirth = placeOfBirth; - } - - public String getMerchantId() { - return merchantId; - } - - public void setMerchantId(String merchantId) { - this.merchantId = merchantId; - } - - public String getPayoutMethod() { - return payoutMethod; - } - - public void setPayoutMethod(String payoutMethod) { - this.payoutMethod = payoutMethod; - } - - /** - * Retrieves a recipient based on the recipient id given - * - * @param recipient_id - * @return The response - * @throws Exception - - */ - - public static Recipient find(String recipient_id) throws Exception { - return Configuration.gateway().recipient.find(recipient_id); - } - - /** - * Retreives the recipient's logs based on the recipient id given - * - * @param recipient_id - * @return the response - * @throws Exception - */ - public static String findLogs(String recipient_id) throws Exception { - String response = Configuration.gateway().recipient.findLogs(recipient_id); - return response; - } - - /** - * Retreives the recipient's payments based on the recipient id given - * - * @param recipient_id - * @return the response - * @throws Exception - */ - public static List findPayments(String recipient_id) throws Exception { - return Configuration.gateway().recipient.findPayments(recipient_id); - - } - - /** - * Creates a recipient based on the body given to the client - * - * @param body - * @return The response - * @throws ca.paymentrails.Exceptions.InvalidStatusCodeException - * @throws ca.paymentrails.Exceptions.InvalidFieldException - * @throws ca.paymentrails.Exceptions.InvalidConnectionException - */ - public static Recipient create(String body) throws Exception { - return Configuration.gateway().recipient.create(body); - - } - - /** - * Updates a recipient based on the body given to the client - * - * @param recipient_id - * @param body - * @return The response - * @throws ca.paymentrails.Exceptions.InvalidStatusCodeException - * @throws ca.paymentrails.Exceptions.InvalidFieldException - * @throws ca.paymentrails.Exceptions.InvalidConnectionException - */ - public static boolean update(String recipient_id, String body) throws Exception { - return Configuration.gateway().recipient.update(recipient_id, body); - } - - /** - * Delete a recipient based on the recipient id - * - * @param recipient_id - * @return The response - * @throws ca.paymentrails.Exceptions.InvalidStatusCodeException - * @throws ca.paymentrails.Exceptions.InvalidFieldException - * @throws ca.paymentrails.Exceptions.InvalidConnectionException - */ - public static boolean delete(String recipient_id) throws Exception { - return Configuration.gateway().recipient.delete(recipient_id); - } - - /** - * List all recipients based on the recipient id and (optional) a given - * wildcard, page amount and page size - * - * @param page - * @param pageSize - * @param term - * @return The response - * @throws ca.paymentrails.Exceptions.InvalidStatusCodeException - * @throws ca.paymentrails.Exceptions.InvalidConnectionException - * @throws ca.paymentrails.Exceptions.InvalidFieldException - */ - public static List search(int page, int pageSize, String term) throws Exception { - return Configuration.gateway().recipient.search(page, pageSize, term); - } - - /** - * List all recipients based on the recipient id and a given wildcard - * - * @param message - * @return The response - * @throws ca.paymentrails.Exceptions.InvalidStatusCodeException - * @throws ca.paymentrails.Exceptions.InvalidConnectionException - * @throws ca.paymentrails.Exceptions.InvalidFieldException - */ - public static List search(String message) throws Exception { - return search(1, 10, message); - } - - /** - * - * @return The response - * @throws ca.paymentrails.Exceptions.InvalidStatusCodeException - * @throws ca.paymentrails.Exceptions.InvalidConnectionException - * @throws ca.paymentrails.Exceptions.InvalidFieldException - */ - public static List search() throws Exception { - return search(1, 10, ""); - } - - /** - * List all recipients based on the recipient id and (optional) page amount - * and page size - * - * @param page - * @param pageNumber - * @return The response - * @throws ca.paymentrails.Exceptions.InvalidStatusCodeException - * @throws ca.paymentrails.Exceptions.InvalidConnectionException - * @throws ca.paymentrails.Exceptions.InvalidFieldException - */ - public static List search(int page, int pageNumber) throws Exception { - return search(page, pageNumber, ""); - } - -} diff --git a/src/main/java/ca/paymentrails/paymentrails/RecipientAccount.java b/src/main/java/ca/paymentrails/paymentrails/RecipientAccount.java deleted file mode 100644 index e9147f3..0000000 --- a/src/main/java/ca/paymentrails/paymentrails/RecipientAccount.java +++ /dev/null @@ -1,232 +0,0 @@ -package ca.paymentrails.paymentrails; - -import java.util.List; - -public class RecipientAccount { - - String type; - Boolean primary; - String currency; - String id; - String recipientId; - String recipientAccountId; - String routeType; - String recipientFees; - String country; - String iban; - String accountNum; - String accountHolderName; - String swiftBic; - String branchId; - String bankId; - String bankName; - String bankAddress; - String bankCity; - String bankRegionCode; - String bankPostalCode; - String emailAddress; - String status; - String disabledAt; - - public String getEmailAddress(){ - return emailAddress; - } - public void setEmailAddress(String emailAddress){ - this.emailAddress = emailAddress; - } - - - public String getDisabledAt(){ - return disabledAt; - } - public void setDisabledAt(String disabledAt){ - this.disabledAt = disabledAt; - } - - public String getStatus(){ - return status; - } - public void setStatus(String status){ - this.status = status; - } - - public String getRecipientId(){ - return recipientId; - } - public void setRecipientId(String recipientId){ - this.recipientId = recipientId; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public Boolean getPrimary() { - return primary; - } - - public void setPrimary(Boolean primary) { - this.primary = primary; - } - - public String getCurrency() { - return currency; - } - - public void setCurrency(String currency) { - this.currency = currency; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getRecipientAccountId() { - return recipientAccountId; - } - - public void setRecipientAccountId(String recipientAccountId) { - this.recipientAccountId = recipientAccountId; - } - - public String getRouteType() { - return routeType; - } - - public void setRouteType(String routeType) { - this.routeType = routeType; - } - - public String getRecipientFees() { - return recipientFees; - } - - public void setRecipientFees(String recipientFees) { - this.recipientFees = recipientFees; - } - - public String getCountry() { - return country; - } - - public void setCountry(String country) { - this.country = country; - } - - public String getIban() { - return iban; - } - - public void setIban(String iban) { - this.iban = iban; - } - - public String getAccountNum() { - return accountNum; - } - - public void setAccountNum(String accountNum) { - this.accountNum = accountNum; - } - - public String getAccountHolderName() { - return accountHolderName; - } - - public void setAccountHolderName(String accountHolderName) { - this.accountHolderName = accountHolderName; - } - - public String getSwiftBic() { - return swiftBic; - } - - public void setSwiftBic(String swiftBic) { - this.swiftBic = swiftBic; - } - - public String getBranchId() { - return branchId; - } - - public void setBranchId(String branchId) { - this.branchId = branchId; - } - - public String getBankId() { - return bankId; - } - - public void setBankId(String bankId) { - this.bankId = bankId; - } - - public String getBankName() { - return bankName; - } - - public void setBankName(String bankName) { - this.bankName = bankName; - } - - public String getBankAddress() { - return bankAddress; - } - - public void setBankAddress(String bankAddress) { - this.bankAddress = bankAddress; - } - - public String getBankCity() { - return bankCity; - } - - public void setBankCity(String bankCity) { - this.bankCity = bankCity; - } - - public String getBankRegionCode() { - return bankRegionCode; - } - - public void setBankRegionCode(String bankRegionCode) { - this.bankRegionCode = bankRegionCode; - } - - public String getBankPostalCode() { - return bankPostalCode; - } - - public void setBankPostalCode(String bankPostalCode) { - this.bankPostalCode = bankPostalCode; - } - - public static List findAll(String recipient_id) throws Exception { - return Configuration.gateway().recipientAccount.findAll(recipient_id); - } - - public static RecipientAccount find(String recipient_id, String recipient_account_id) throws Exception { - return Configuration.gateway().recipientAccount.find(recipient_id, recipient_account_id); - } - - public static RecipientAccount create(String recipient_id, String body) throws Exception { - return Configuration.gateway().recipientAccount.create(recipient_id, body); - } - - public static RecipientAccount update(String recipient_id, String recipient_account_id, String body) throws Exception { - return Configuration.gateway().recipientAccount.update(recipient_id, recipient_account_id, body); - } - - public static boolean delete(String recipient_id, String recipient_account_id) throws Exception { - return Configuration.gateway().recipientAccount.delete(recipient_id, recipient_account_id); - } - -} \ No newline at end of file diff --git a/src/main/java/ca/paymentrails/paymentrails/RecipientAccountGateway.java b/src/main/java/ca/paymentrails/paymentrails/RecipientAccountGateway.java deleted file mode 100644 index 593ccb3..0000000 --- a/src/main/java/ca/paymentrails/paymentrails/RecipientAccountGateway.java +++ /dev/null @@ -1,97 +0,0 @@ -package ca.paymentrails.paymentrails; - -import ca.paymentrails.Exceptions.InvalidFieldException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import java.io.IOException; -import java.util.ArrayList; -import com.fasterxml.jackson.databind.DeserializationFeature; -import java.util.List; - -public class RecipientAccountGateway { - - Client client; - - public RecipientAccountGateway(Configuration config) { - this.client = new Client(config); - } - - public List findAll(String recipient_id) throws Exception { - if (recipient_id == null || recipient_id.isEmpty()) { - throw new InvalidFieldException("Recipient id cannot be null or empty."); - } - - String endPoint = "/v1/recipients/" + recipient_id + "/accounts"; - String response = this.client.get(endPoint); - return recipientAccountListFactory(response); - } - - public RecipientAccount find(String recipient_id, String recipient_account_id) throws Exception { - if (recipient_id == null || recipient_id.isEmpty()) { - throw new InvalidFieldException("Recipient id cannot be null or empty."); - } - - String endPoint = "/v1/recipients/" + recipient_id + "/accounts/" + recipient_account_id; - String response = this.client.get(endPoint); - return recipientAccountFactory(response); - } - - public RecipientAccount create(String recipient_id, String body) throws Exception { - if (recipient_id == null || recipient_id.isEmpty()) { - throw new InvalidFieldException("Recipient id cannot be null or empty."); - } - if (body == null || body.isEmpty()) { - throw new InvalidFieldException("Body cannot be null or empty"); - } - - String endPoint = "/v1/recipients/" + recipient_id + "/accounts"; - String response = this.client.post(endPoint, body); - return recipientAccountFactory(response); - } - - public RecipientAccount update(String recipient_id, String recipient_account_id, String body) throws Exception { - if (recipient_id == null || recipient_id.isEmpty()) { - throw new InvalidFieldException("Recipient id cannot be null or empty."); - } - if (body == null || body.isEmpty()) { - throw new InvalidFieldException("Body cannot be null or empty"); - } - - String endPoint = "/v1/recipients/" + recipient_id + "/accounts/" + recipient_account_id; - String response = this.client.patch(endPoint, body); - return recipientAccountFactory(response); - } - - public boolean delete(String recipient_id, String recipient_account_id) throws Exception { - if (recipient_id == null || recipient_id.isEmpty()) { - throw new InvalidFieldException("Recipient id cannot be null or empty."); - } - - String endPoint = "/v1/recipients/" + recipient_id + "/accounts/" + recipient_account_id; - this.client.delete(endPoint); - return true; - } - - private RecipientAccount recipientAccountFactory(String data) throws IOException { - ObjectMapper mapper = new ObjectMapper(); - JsonNode node = mapper.readTree(data); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - RecipientAccount recipientAccount = mapper.readValue(node.get("account").traverse(), RecipientAccount.class); - return recipientAccount; - } - - private List recipientAccountListFactory(String data) throws IOException { - ObjectMapper mapper = new ObjectMapper(); - JsonNode node = mapper.readTree(data); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - Object recipientAccount = mapper.readValue(node.get("accounts").traverse(), Object.class); - @SuppressWarnings("unchecked") - List recipAccounts = (List) recipientAccount; - List recipientAccounts = new ArrayList(); - for (int i = 0; i < recipAccounts.size(); i++) { - RecipientAccount pojo = mapper.convertValue(recipAccounts.get(i), RecipientAccount.class); - recipientAccounts.add(pojo); - } - return recipientAccounts; - } -} \ No newline at end of file diff --git a/src/main/java/ca/paymentrails/paymentrails/RecipientGateway.java b/src/main/java/ca/paymentrails/paymentrails/RecipientGateway.java deleted file mode 100644 index 0ded248..0000000 --- a/src/main/java/ca/paymentrails/paymentrails/RecipientGateway.java +++ /dev/null @@ -1,125 +0,0 @@ -package ca.paymentrails.paymentrails; - -import ca.paymentrails.Exceptions.InvalidFieldException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import com.fasterxml.jackson.databind.DeserializationFeature; - -public class RecipientGateway { - - Client client; - - public RecipientGateway(Configuration config) { - this.client = new Client(config); - } - - public Recipient find(String recipient_id) throws Exception { - if (recipient_id == null || recipient_id.isEmpty()) { - throw new InvalidFieldException("Recipient id cannot be null or empty."); - } - - String endPoint = "/v1/recipients/" + recipient_id; - String response = this.client.get(endPoint); - return recipientFactory(response); - } - - public String findLogs(String recipient_id) throws Exception { - String endPoint = "/v1/recipients/" + recipient_id + "/logs"; - String response = this.client.get(endPoint); - return response; - } - - public List findPayments(String recipient_id) throws Exception { - String endPoint = "/v1/recipients/" + recipient_id + "/payments"; - String response = this.client.get(endPoint); - ObjectMapper mapper = new ObjectMapper(); - JsonNode node = mapper.readTree(response); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - Object payment = mapper.readValue(node.get("payments").traverse(), Object.class); - @SuppressWarnings("unchecked") - List paymens = (List) payment; - List payments = new ArrayList(); - for (int i = 0; i < paymens.size(); i++) { - Payment pojo = mapper.convertValue(paymens.get(i), Payment.class); - payments.add(pojo); - } - - return payments; - } - - public Recipient create(String body) throws Exception { - if (body == null || body.isEmpty()) { - throw new InvalidFieldException("Body cannot be null or empty"); - } - String endPoint = "/v1/recipients/"; - String response = this.client.post(endPoint, body); - return recipientFactory(response); - } - - public boolean update(String recipient_id, String body) throws Exception { - if (recipient_id == null || recipient_id.isEmpty()) { - throw new InvalidFieldException("Recipient id cannot be null or empty."); - } - if (body == null || body.isEmpty()) { - throw new InvalidFieldException("Body cannot be null or empty"); - } - - String endPoint = "/v1/recipients/" + recipient_id; - this.client.patch(endPoint, body); - return true; - } - - public boolean delete(String recipient_id) throws Exception { - if (recipient_id == null || recipient_id.isEmpty()) { - throw new InvalidFieldException("Recipient id cannot be null or empty."); - } - - String endPoint = "/v1/recipients/" + recipient_id; - this.client.delete(endPoint); - return true; - } - - public List search(int page, int pageSize, String term) throws Exception { - if (page < 0) { - throw new InvalidFieldException("Page cannot be less than 0"); - } - if (pageSize < 0) { - throw new InvalidFieldException("Page size cannot be less than 0"); - } - if (term == null) { - throw new InvalidFieldException("Message cannot be null"); - } - - String endPoint = "/v1/recipients/?" + "&search=" + term + "&page=" + page + "&pageSize=" + pageSize; - String response = this.client.get(endPoint); - - return recipientListFactory(response); - } - - private Recipient recipientFactory(String data) throws IOException { - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - JsonNode node = mapper.readTree(data); - Recipient recipient = mapper.readValue(node.get("recipient").traverse(), Recipient.class); - return recipient; - } - - private List recipientListFactory(String data) throws IOException { - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - JsonNode node = mapper.readTree(data); - - Object recipient = mapper.readValue(node.get("recipients").traverse(), Object.class); - @SuppressWarnings("unchecked") - List recips = (List) recipient; - List recipients = new ArrayList(); - for (int i = 0; i < recips.size(); i++) { - Recipient pojo = mapper.convertValue(recips.get(i), Recipient.class); - recipients.add(pojo); - } - return recipients; - } -} \ No newline at end of file diff --git a/src/main/java/com/trolley/Exceptions/AuthenticationException.java b/src/main/java/com/trolley/Exceptions/AuthenticationException.java new file mode 100644 index 0000000..6432a11 --- /dev/null +++ b/src/main/java/com/trolley/Exceptions/AuthenticationException.java @@ -0,0 +1,11 @@ +package com.trolley.Exceptions; + +public class AuthenticationException extends Exception +{ + public AuthenticationException() { + } + + public AuthenticationException(final String message) { + super(message); + } +} diff --git a/src/main/java/com/trolley/Exceptions/AuthorizationException.java b/src/main/java/com/trolley/Exceptions/AuthorizationException.java new file mode 100644 index 0000000..9f24e24 --- /dev/null +++ b/src/main/java/com/trolley/Exceptions/AuthorizationException.java @@ -0,0 +1,11 @@ +package com.trolley.Exceptions; + +public class AuthorizationException extends Exception +{ + public AuthorizationException() { + } + + public AuthorizationException(final String message) { + super(message); + } +} diff --git a/src/main/java/com/trolley/Exceptions/DownForMaintenanceException.java b/src/main/java/com/trolley/Exceptions/DownForMaintenanceException.java new file mode 100644 index 0000000..f2d7aec --- /dev/null +++ b/src/main/java/com/trolley/Exceptions/DownForMaintenanceException.java @@ -0,0 +1,11 @@ +package com.trolley.Exceptions; + +public class DownForMaintenanceException extends Exception +{ + public DownForMaintenanceException() { + } + + public DownForMaintenanceException(final String message) { + super(message); + } +} diff --git a/src/main/java/com/trolley/Exceptions/InvalidFieldException.java b/src/main/java/com/trolley/Exceptions/InvalidFieldException.java new file mode 100644 index 0000000..4ec0e6c --- /dev/null +++ b/src/main/java/com/trolley/Exceptions/InvalidFieldException.java @@ -0,0 +1,12 @@ + +package com.trolley.Exceptions; + +public class InvalidFieldException extends Exception +{ + public InvalidFieldException() { + } + + public InvalidFieldException(final String message) { + super(message); + } +} diff --git a/src/main/java/com/trolley/Exceptions/InvalidServerConnectionException.java b/src/main/java/com/trolley/Exceptions/InvalidServerConnectionException.java new file mode 100644 index 0000000..d41bafb --- /dev/null +++ b/src/main/java/com/trolley/Exceptions/InvalidServerConnectionException.java @@ -0,0 +1,11 @@ +package com.trolley.Exceptions; + +public class InvalidServerConnectionException extends Exception +{ + public InvalidServerConnectionException() { + } + + public InvalidServerConnectionException(final String message) { + super(message); + } +} diff --git a/src/main/java/com/trolley/Exceptions/InvalidStatusCodeException.java b/src/main/java/com/trolley/Exceptions/InvalidStatusCodeException.java new file mode 100644 index 0000000..a089ce4 --- /dev/null +++ b/src/main/java/com/trolley/Exceptions/InvalidStatusCodeException.java @@ -0,0 +1,11 @@ +package com.trolley.Exceptions; + +public class InvalidStatusCodeException extends Exception +{ + public InvalidStatusCodeException() { + } + + public InvalidStatusCodeException(final String message) { + super(message); + } +} diff --git a/src/main/java/com/trolley/Exceptions/MalformedException.java b/src/main/java/com/trolley/Exceptions/MalformedException.java new file mode 100644 index 0000000..cf487f8 --- /dev/null +++ b/src/main/java/com/trolley/Exceptions/MalformedException.java @@ -0,0 +1,11 @@ +package com.trolley.Exceptions; + +public class MalformedException extends Exception +{ + public MalformedException() { + } + + public MalformedException(final String message) { + super(message); + } +} diff --git a/src/main/java/com/trolley/Exceptions/NotFoundException.java b/src/main/java/com/trolley/Exceptions/NotFoundException.java new file mode 100644 index 0000000..6b2b405 --- /dev/null +++ b/src/main/java/com/trolley/Exceptions/NotFoundException.java @@ -0,0 +1,11 @@ +package com.trolley.Exceptions; + +public class NotFoundException extends Exception +{ + public NotFoundException() { + } + + public NotFoundException(final String message) { + super(message); + } +} diff --git a/src/main/java/com/trolley/Exceptions/TooManyRequestsException.java b/src/main/java/com/trolley/Exceptions/TooManyRequestsException.java new file mode 100644 index 0000000..5ab979f --- /dev/null +++ b/src/main/java/com/trolley/Exceptions/TooManyRequestsException.java @@ -0,0 +1,11 @@ +package com.trolley.Exceptions; + +public class TooManyRequestsException extends Exception +{ + public TooManyRequestsException() { + } + + public TooManyRequestsException(final String message) { + super(message); + } +} diff --git a/src/main/java/com/trolley/Exceptions/UnexpectedException.java b/src/main/java/com/trolley/Exceptions/UnexpectedException.java new file mode 100644 index 0000000..7b839fb --- /dev/null +++ b/src/main/java/com/trolley/Exceptions/UnexpectedException.java @@ -0,0 +1,11 @@ +package com.trolley.Exceptions; + +public class UnexpectedException extends Exception +{ + public UnexpectedException() { + } + + public UnexpectedException(final String message) { + super(message); + } +} diff --git a/src/main/java/ca/paymentrails/paymentrails/Address.java b/src/main/java/com/trolley/trolley/Address.java similarity index 50% rename from src/main/java/ca/paymentrails/paymentrails/Address.java rename to src/main/java/com/trolley/trolley/Address.java index 2265b94..22fff04 100644 --- a/src/main/java/ca/paymentrails/paymentrails/Address.java +++ b/src/main/java/com/trolley/trolley/Address.java @@ -1,9 +1,10 @@ -package ca.paymentrails.paymentrails; +package com.trolley.trolley; import java.util.HashMap; import java.util.Map; -public class Address { +public class Address +{ private String street1; private String street2; private String city; @@ -12,77 +13,81 @@ public class Address { private String region; private String phone; private Boolean phoneValidated; - private Map additionalProperties = new HashMap(); - + private Map additionalProperties; + + public Address() { + this.additionalProperties = new HashMap(); + } + public String getStreet1() { - return street1; + return this.street1; } - - public void setStreet1(String street1) { + + public void setStreet1(final String street1) { this.street1 = street1; } - + public String getStreet2() { - return street2; + return this.street2; } - - public void setStreet2(String street2) { + + public void setStreet2(final String street2) { this.street2 = street2; } - + public String getCity() { - return city; + return this.city; } - - public void setCity(String city) { + + public void setCity(final String city) { this.city = city; } - + public String getPostalCode() { - return postalCode; + return this.postalCode; } - - public void setPostalCode(String postalCode) { + + public void setPostalCode(final String postalCode) { this.postalCode = postalCode; } - + public String getCountry() { - return country; + return this.country; } - - public void setCountry(String country) { + + public void setCountry(final String country) { this.country = country; } - + public String getRegion() { - return region; + return this.region; } - - public void setRegion(String region) { + + public void setRegion(final String region) { this.region = region; } - + public String getPhone() { - return phone; + return this.phone; } - - public void setPhone(String phone) { + + public void setPhone(final String phone) { this.phone = phone; } - + public Boolean getPhoneValidated() { - return phoneValidated; + return this.phoneValidated; } - - public void setPhoneValidated(Boolean phoneValidated) { + + public void setPhoneValidated(final Boolean phoneValidated) { this.phoneValidated = phoneValidated; } - + public Map getAdditionalProperties() { return this.additionalProperties; } - - public void setAdditionalProperty(String name, Object value) { + + public void setAdditionalProperty(final String name, final Object value) { this.additionalProperties.put(name, value); } -} \ No newline at end of file +} diff --git a/src/main/java/com/trolley/trolley/Balances.java b/src/main/java/com/trolley/trolley/Balances.java new file mode 100644 index 0000000..53afd8a --- /dev/null +++ b/src/main/java/com/trolley/trolley/Balances.java @@ -0,0 +1,40 @@ +package com.trolley.trolley; + +public class Balances +{ + public EUR EUR; + public USD USD; + public CAD CAD; + + public EUR getEUR() { + return this.EUR; + } + + public void setEUR(final EUR EUR) { + this.EUR = EUR; + } + + public USD getUSD() { + return this.USD; + } + + public void setUSD(final USD USD) { + this.USD = USD; + } + + public CAD getCAD() { + return this.CAD; + } + + public void setCAD(final CAD CAD) { + this.CAD = CAD; + } + + public static String find() throws Exception { + return find(""); + } + + public static String find(final String term) throws Exception { + return Configuration.gateway().balances.find(term); + } +} diff --git a/src/main/java/com/trolley/trolley/BalancesGateway.java b/src/main/java/com/trolley/trolley/BalancesGateway.java new file mode 100644 index 0000000..7127ebd --- /dev/null +++ b/src/main/java/com/trolley/trolley/BalancesGateway.java @@ -0,0 +1,21 @@ +package com.trolley.trolley; + +import com.trolley.Exceptions.InvalidFieldException; + +public class BalancesGateway +{ + Client client; + + public BalancesGateway(final Configuration config) { + this.client = new Client(config); + } + + public String find(final String term) throws Exception { + if (term == null) { + throw new InvalidFieldException("Term cannot be null"); + } + final String endPoint = "/v1/balances/" + term; + final String response = this.client.get(endPoint); + return response; + } +} diff --git a/src/main/java/ca/paymentrails/paymentrails/BankTransfer.java b/src/main/java/com/trolley/trolley/BankTransfer.java similarity index 69% rename from src/main/java/ca/paymentrails/paymentrails/BankTransfer.java rename to src/main/java/com/trolley/trolley/BankTransfer.java index 52b224d..4ff2b46 100644 --- a/src/main/java/ca/paymentrails/paymentrails/BankTransfer.java +++ b/src/main/java/com/trolley/trolley/BankTransfer.java @@ -1,10 +1,10 @@ -package ca.paymentrails.paymentrails; - -public class BankTransfer { +package com.trolley.trolley; +public class BankTransfer +{ public Integer count; public String totalFees; public String merchantFees; public String debitAmount; public String sendingAmount; -} \ No newline at end of file +} diff --git a/src/main/java/com/trolley/trolley/Batch.java b/src/main/java/com/trolley/trolley/Batch.java new file mode 100644 index 0000000..3478d1e --- /dev/null +++ b/src/main/java/com/trolley/trolley/Batch.java @@ -0,0 +1,157 @@ +package com.trolley.trolley; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonInclude; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Batch +{ + private String id; + private String status; + private String amount; + private Integer totalPayments; + private String currency; + private String description; + private Object sentAt; + private Object completedAt; + private String createdAt; + private String updatedAt; + private List payments; + public String quoteExpiredAt; + + public String getId() { + return this.id; + } + + public void setId(final String id) { + this.id = id; + } + + public String getStatus() { + return this.status; + } + + public void setStatus(final String status) { + this.status = status; + } + + public String getAmount() { + return this.amount; + } + + public void setAmount(final String amount) { + this.amount = amount; + } + + public Integer getTotalPayments() { + return this.totalPayments; + } + + public void setTotalPayments(final Integer totalPayments) { + this.totalPayments = totalPayments; + } + + public String getCurrency() { + return this.currency; + } + + public void setCurrency(final String currency) { + this.currency = currency; + } + + public String getDescription() { + return this.description; + } + + public void setDescription(final String description) { + this.description = description; + } + + public Object getSentAt() { + return this.sentAt; + } + + public void setSentAt(final Object sentAt) { + this.sentAt = sentAt; + } + + public Object getCompletedAt() { + return this.completedAt; + } + + public void setCompletedAt(final Object completedAt) { + this.completedAt = completedAt; + } + + public String getCreatedAt() { + return this.createdAt; + } + + public void setCreatedAt(final String createdAt) { + this.createdAt = createdAt; + } + + public String getUpdatedAt() { + return this.updatedAt; + } + + public void setUpdatedAt(final String updatedAt) { + this.updatedAt = updatedAt; + } + + public List getPayments() { + return this.payments; + } + + public void setPayments(final List payments) { + this.payments = payments; + } + + public static Batch find(final String batch_id) throws Exception { + return Configuration.gateway().batch.find(batch_id); + } + + public static boolean update(final String batch_id, final String body) throws Exception { + return Configuration.gateway().batch.update(batch_id, body); + } + + public static boolean delete(final String batch_id) throws Exception { + return Configuration.gateway().batch.delete(batch_id); + } + + public static Batch create(final String body) throws Exception { + return Configuration.gateway().batch.create(body); + } + + public static Batch create(final Batch body) throws Exception { + return Configuration.gateway().batch.create(body); + } + + public static String generateQuote(final String batch_id) throws Exception { + return Configuration.gateway().batch.generateQuote(batch_id); + } + + public static String processBatch(final String batch_id) throws Exception { + return Configuration.gateway().batch.processBatch(batch_id); + } + + public static List query(final int page, final int pageSize, final String message) throws Exception { + return Configuration.gateway().batch.query(page, pageSize, message); + } + + public static List query(final String message) throws Exception { + return query(1, 10, message); + } + + public static List query() throws Exception { + return query(1, 10, ""); + } + + public static List query(final int page, final int pageNumber) throws Exception { + return query(page, pageNumber, ""); + } + + public static BatchSummary summary(final String batch_id) throws Exception { + return Configuration.gateway().batch.summary(batch_id); + } +} diff --git a/src/main/java/com/trolley/trolley/BatchGateway.java b/src/main/java/com/trolley/trolley/BatchGateway.java new file mode 100644 index 0000000..a585cf3 --- /dev/null +++ b/src/main/java/com/trolley/trolley/BatchGateway.java @@ -0,0 +1,169 @@ +package com.trolley.trolley; + +import java.io.IOException; +import java.util.ArrayList; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.DeserializationFeature; +import java.util.List; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.trolley.Exceptions.InvalidFieldException; + +public class BatchGateway +{ + Client client; + + public BatchGateway(final Configuration config) { + this.client = new Client(config); + } + + public Batch find(final String batch_id) throws Exception { + if (batch_id == null || batch_id.isEmpty()) { + throw new InvalidFieldException("Batch id cannot be null or empty."); + } + final String endPoint = "/v1/batches/" + batch_id; + final String response = this.client.get(endPoint); + return this.batchFactory(response); + } + + public boolean update(final String batch_id, final String body) throws Exception { + if (batch_id == null || batch_id.isEmpty()) { + throw new InvalidFieldException("Batch id cannot be null or empty."); + } + if (body == null || body.isEmpty()) { + throw new InvalidFieldException("Body cannot be null or empty."); + } + final String endPoint = "/v1/batches/" + batch_id; + this.client.patch(endPoint, body); + return true; + } + + public boolean update(final String batch_id, final Batch batch) throws Exception { + if (batch_id == null || batch_id.isEmpty()) { + throw new InvalidFieldException("Batch id cannot be null or empty."); + } + if (batch == null) { + throw new InvalidFieldException("Body cannot be null or empty."); + } + final String jsonBatch = new ObjectMapper().writeValueAsString((Object)batch); + final String endPoint = "/v1/batches/" + batch_id; + this.client.patch(endPoint, jsonBatch); + return true; + } + + public boolean delete(final String batch_id) throws Exception { + if (batch_id == null || batch_id.isEmpty()) { + throw new InvalidFieldException("Batch id cannot be null or empty."); + } + final String endPoint = "/v1/batches/" + batch_id; + this.client.delete(endPoint); + return true; + } + + public Batch create(final String body) throws Exception { + if (body == null || body.isEmpty()) { + throw new InvalidFieldException("Body cannot be null or empty."); + } + final String endPoint = "/v1/batches/"; + final String response = this.client.post(endPoint, body); + return this.batchFactory(response); + } + + public Batch create(final Batch batch) throws Exception { + if (batch == null) { + throw new InvalidFieldException("Batch cannot be null."); + } + final String result = new ObjectMapper().writeValueAsString((Object)batch); + final String endPoint = "/v1/batches/"; + final String response = this.client.post(endPoint, result); + return this.batchFactory(response); + } + + public String generateQuote(final String batch_id) throws Exception { + if (batch_id == null || batch_id.isEmpty()) { + throw new InvalidFieldException("Batch id cannot be null or empty."); + } + final String endPoint = "/v1/batches/" + batch_id + "/generate-quote"; + final String response = this.client.post(endPoint); + return response; + } + + public String processBatch(final String batch_id) throws Exception { + if (batch_id == null || batch_id.isEmpty()) { + throw new InvalidFieldException("Batch id cannot be null or empty."); + } + final String endPoint = "/v1/batches/" + batch_id + "/start-processing"; + final String response = this.client.post(endPoint); + return response; + } + + public List query(final int page, final int pageSize, final String message) throws Exception { + if (page < 0) { + throw new InvalidFieldException("Page cannot be less than 0"); + } + if (pageSize < 0) { + throw new InvalidFieldException("Page size cannot be less than 0"); + } + if (message == null) { + throw new InvalidFieldException("Message cannot be null"); + } + final String endPoint = "/v1/batches/?&search=" + message + "&page=" + page + "&pageSize=" + pageSize; + final String response = this.client.get(endPoint); + return this.batchListFactory(response); + } + + public List query(final String message) throws Exception { + return this.query(1, 10, message); + } + + public List query() throws Exception { + return this.query(1, 10, ""); + } + + public List query(final int page, final int pageNumber) throws Exception { + return this.query(page, pageNumber, ""); + } + + public BatchSummary summary(final String batch_id) throws Exception { + if (batch_id == null || batch_id.isEmpty()) { + throw new InvalidFieldException("Batch id cannot be null os empty"); + } + final String endPoint = "/v1/batches/" + batch_id + "/summary"; + final String response = this.client.get(endPoint); + final ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + final JsonNode node = mapper.readTree(response); + final BatchSummary batchSummary = (BatchSummary)mapper.readValue(node.get("batchSummary").traverse(), (Class)BatchSummary.class); + return batchSummary; + } + + private Batch batchFactory(final String data) throws IOException { + final ObjectMapper mapper = new ObjectMapper(); + final JsonNode node = mapper.readTree(data); + mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + final Object payments = mapper.readValue(node.get("batch").get("payments").get("payments").traverse(), (Class)Object.class); + final List castPayments = (List)payments; + final List paymentList = new ArrayList(); + for (int i = 0; i < castPayments.size(); ++i) { + final Payment payment = (Payment)mapper.convertValue((Object)castPayments.get(i), (Class)Payment.class); + paymentList.add(payment); + } + final Batch batch = (Batch)mapper.readValue(node.get("batch").traverse(), (Class)Batch.class); + batch.setPayments(paymentList); + return batch; + } + + private List batchListFactory(final String data) throws IOException { + final ObjectMapper mapper = new ObjectMapper(); + final JsonNode node = mapper.readTree(data); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + final Object batch = mapper.readValue(node.get("batches").traverse(), (Class)Object.class); + final List batchs = (List)batch; + final List batches = new ArrayList(); + for (int i = 0; i < batchs.size(); ++i) { + final Batch pojo = (Batch)mapper.convertValue((Object)batchs.get(i), (Class)Batch.class); + batches.add(pojo); + } + return batches; + } +} diff --git a/src/main/java/com/trolley/trolley/BatchSummary.java b/src/main/java/com/trolley/trolley/BatchSummary.java new file mode 100644 index 0000000..2938941 --- /dev/null +++ b/src/main/java/com/trolley/trolley/BatchSummary.java @@ -0,0 +1,7 @@ +package com.trolley.trolley; + +public class BatchSummary +{ + public Total total; + public Detail detail; +} diff --git a/src/main/java/ca/paymentrails/paymentrails/CAD.java b/src/main/java/com/trolley/trolley/CAD.java similarity index 51% rename from src/main/java/ca/paymentrails/paymentrails/CAD.java rename to src/main/java/com/trolley/trolley/CAD.java index 46f43dd..31f7af7 100644 --- a/src/main/java/ca/paymentrails/paymentrails/CAD.java +++ b/src/main/java/com/trolley/trolley/CAD.java @@ -1,60 +1,59 @@ -package ca.paymentrails.paymentrails; - -public class CAD { +package com.trolley.trolley; +public class CAD +{ private Boolean primary; private String amount; private String currency; private String type; private String accountNumber; private Boolean display; - + public Boolean getPrimary() { - return primary; + return this.primary; } - - public void setPrimary(Boolean primary) { + + public void setPrimary(final Boolean primary) { this.primary = primary; } - + public String getAmount() { - return amount; + return this.amount; } - - public void setAmount(String amount) { + + public void setAmount(final String amount) { this.amount = amount; } - + public String getCurrency() { - return currency; + return this.currency; } - - public void setCurrency(String currency) { + + public void setCurrency(final String currency) { this.currency = currency; } - + public String getType() { - return type; + return this.type; } - - public void setType(String type) { + + public void setType(final String type) { this.type = type; } - + public String getAccountNumber() { - return accountNumber; + return this.accountNumber; } - - public void setAccountNumber(String accountNumber) { + + public void setAccountNumber(final String accountNumber) { this.accountNumber = accountNumber; } - + public Boolean getDisplay() { - return display; + return this.display; } - - public void setDisplay(Boolean display) { + + public void setDisplay(final Boolean display) { this.display = display; } - -} \ No newline at end of file +} diff --git a/src/main/java/com/trolley/trolley/Client.java b/src/main/java/com/trolley/trolley/Client.java new file mode 100644 index 0000000..3b0849f --- /dev/null +++ b/src/main/java/com/trolley/trolley/Client.java @@ -0,0 +1,227 @@ +package com.trolley.trolley; + +import javax.crypto.Mac; +import javax.crypto.spec.SecretKeySpec; +import com.trolley.Exceptions.DownForMaintenanceException; +import com.trolley.Exceptions.InvalidServerConnectionException; +import com.trolley.Exceptions.TooManyRequestsException; +import com.trolley.Exceptions.InvalidStatusCodeException; +import com.trolley.Exceptions.NotFoundException; +import com.trolley.Exceptions.AuthorizationException; +import com.trolley.Exceptions.AuthenticationException; +import com.trolley.Exceptions.MalformedException; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.HttpEntity; +import org.apache.http.entity.StringEntity; +import org.apache.http.client.methods.HttpPatch; +import org.apache.http.impl.client.HttpClients; +import java.io.IOException; +import java.io.InputStream; +import java.rmi.UnexpectedException; +import java.io.Reader; +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.io.DataOutputStream; +import java.net.HttpURLConnection; +import java.net.URL; + +public class Client +{ + private Configuration config; + private String trolleySourceString = "java-sdk_"+Version.MAJOR+"."+Version.MINOR+"."+Version.PATCH; + + public Client(final Configuration config) { + this.config = config; + } + + public static Client create(final Configuration config) { + return new Client(config); + } + + private String sendRequest(final String method, final String endPoint, final String body) throws Exception { + String StringResponse = ""; + try { + final String url = this.config.getApiBase() + endPoint; + final URL obj = new URL(url); + final HttpURLConnection con = (HttpURLConnection)obj.openConnection(); + final int timeStamp = (int)(System.currentTimeMillis() / 1000L); + final String authorizarion = this.generateAuthorization(timeStamp, method, endPoint, body); + con.setRequestMethod(method); + con.setRequestProperty("X-PR-Timestamp", timeStamp + ""); + con.setRequestProperty("Authorization", authorizarion); + con.setRequestProperty("Trolley-Source", trolleySourceString); + con.setRequestProperty("Content-Type", "application/json"); + if (method == "POST" && body != "") { + con.setDoOutput(true); + final DataOutputStream wr = new DataOutputStream(con.getOutputStream()); + try { + wr.writeBytes(body); + wr.flush(); + wr.close(); + } + catch (Throwable t) { + try { + wr.close(); + } + catch (Throwable exception) { + t.addSuppressed(exception); + } + throw t; + } + } + final int responseCode = con.getResponseCode(); + try { + InputStream is; + + if(responseCode >= 200 && responseCode < 400){ + is = con.getInputStream(); + }else{ + is = con.getErrorStream(); + } + final BufferedReader in = new BufferedReader(new InputStreamReader(is)); + try { + final StringBuffer response = new StringBuffer(); + String inputLine; + while ((inputLine = in.readLine()) != null) { + response.append(inputLine); + } + StringResponse = response.toString(); + in.close(); + }catch (Throwable t2) { + try { + in.close(); + }catch (Throwable exception2) { + t2.addSuppressed(exception2); + } + throw t2; + } + }catch (IOException e) { + throw new UnexpectedException(StringResponse, e); + } + + if (responseCode != 200) { + this.throwStatusCodeException(responseCode, StringResponse); + } + + } + catch (IOException e2) { + throw new UnexpectedException(StringResponse); + } + return StringResponse; + } + + private String sendRequest(final String method, final String endPoint) throws Exception { + return this.sendRequest(method, endPoint, ""); + } + + public String get(final String endPoint) throws Exception { + return this.sendRequest("GET", endPoint); + } + + public String post(final String endPoint, final String body) throws Exception { + return this.sendRequest("POST", endPoint, body); + } + + public String post(final String endPoint) throws Exception { + return this.sendRequest("POST", endPoint); + } + + public String patch(final String endPoint, final String body) throws Exception { + String StringResponse = ""; + try { + final HttpClient httpclient = (HttpClient)HttpClients.createDefault(); + final HttpPatch httpPatch = new HttpPatch(this.config.getApiBase() + endPoint); + final StringEntity params = new StringEntity(body); + final int timeStamp = (int)(System.currentTimeMillis() / 1000L); + final String authorizarion = this.generateAuthorization(timeStamp, "PATCH", endPoint, body); + params.setContentType("application/json"); + httpPatch.setEntity((HttpEntity)params); + httpPatch.addHeader("X-PR-Timestamp", timeStamp + ""); + httpPatch.addHeader("Authorization", authorizarion); + httpPatch.addHeader("Trolley-Source", trolleySourceString); + final HttpResponse response = httpclient.execute((HttpUriRequest)httpPatch); + final StringBuffer result = new StringBuffer(); + String line = ""; + final BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); + while ((line = rd.readLine()) != null) { + result.append(line); + } + StringResponse = result.toString(); + final int responseCode = response.getStatusLine().getStatusCode(); + if (responseCode != 200) { + this.throwStatusCodeException(responseCode, StringResponse); + } + } + catch (IOException e) { + throw new UnexpectedException(StringResponse); + } + return StringResponse; + } + + public String delete(final String endPoint) throws Exception { + return this.sendRequest("DELETE", endPoint); + } + + private void throwStatusCodeException(final int statusCode, final String message) throws Exception { + switch (statusCode) { + case 400: { + throw new MalformedException(message); + } + case 401: { + throw new AuthenticationException(message); + } + case 403: { + throw new AuthorizationException(message); + } + case 404: { + throw new NotFoundException(statusCode + " " + message); + } + case 406: { + throw new InvalidStatusCodeException(message); + } + case 429: { + throw new TooManyRequestsException(message); + } + case 500: { + throw new InvalidServerConnectionException(message); + } + case 503: { + throw new DownForMaintenanceException(message); + } + default: { + throw new com.trolley.Exceptions.UnexpectedException(message); + } + } + } + + private String generateAuthorization(final int timeStamp, final String method, final String endPoint, final String body) { + final String message = timeStamp + "\n" + method + "\n" + endPoint + "\n" + body + "\n"; + try { + final String hash = this.hmacDigest(message, this.config.getPrivateKey(), "HmacSHA256"); + return "prsign " + this.config.getPublicKey() + ":" + hash; + } + catch (Exception e) { + return "prsign 1:1"; + } + } + + private String hmacDigest(final String msg, final String keyString, final String algo) throws Exception { + String digest = null; + final SecretKeySpec key = new SecretKeySpec(keyString.getBytes("UTF-8"), algo); + final Mac mac = Mac.getInstance(algo); + mac.init(key); + final byte[] bytes = mac.doFinal(msg.getBytes("ASCII")); + final StringBuffer hash = new StringBuffer(); + for (int i = 0; i < bytes.length; ++i) { + final String hex = Integer.toHexString(0xFF & bytes[i]); + if (hex.length() == 1) { + hash.append('0'); + } + hash.append(hex); + } + digest = hash.toString(); + return digest; + } +} diff --git a/src/main/java/com/trolley/trolley/Compliance.java b/src/main/java/com/trolley/trolley/Compliance.java new file mode 100644 index 0000000..58a3293 --- /dev/null +++ b/src/main/java/com/trolley/trolley/Compliance.java @@ -0,0 +1,39 @@ +package com.trolley.trolley; + +import java.util.HashMap; +import java.util.Map; + +public class Compliance +{ + private String status; + private Object checkedAt; + private Map additionalProperties; + + public Compliance() { + this.additionalProperties = new HashMap(); + } + + public String getStatus() { + return this.status; + } + + public void setStatus(final String status) { + this.status = status; + } + + public Object getCheckedAt() { + return this.checkedAt; + } + + public void setCheckedAt(final Object checkedAt) { + this.checkedAt = checkedAt; + } + + public Map getAdditionalProperties() { + return this.additionalProperties; + } + + public void setAdditionalProperty(final String name, final Object value) { + this.additionalProperties.put(name, value); + } +} diff --git a/src/main/java/com/trolley/trolley/Configuration.java b/src/main/java/com/trolley/trolley/Configuration.java new file mode 100644 index 0000000..68071bb --- /dev/null +++ b/src/main/java/com/trolley/trolley/Configuration.java @@ -0,0 +1,91 @@ +package com.trolley.trolley; + +public class Configuration +{ + String apiBase = "https://api.trolley.com"; + String privateKey; + String publicKey; + + public Configuration() { + this.apiBase = "https://api.trolley.com"; + this.privateKey = ""; + this.publicKey = ""; + } + + public Configuration(final String publicKey, final String privateKey) { + this.apiBase = "https://api.trolley.com"; + this.privateKey = ""; + this.publicKey = ""; + this.publicKey = publicKey; + this.privateKey = privateKey; + } + + public Configuration(final String publicKey, final String privateKey, final String apiBase) { + this.apiBase = "https://api.trolley.com"; + this.privateKey = ""; + this.publicKey = ""; + this.publicKey = publicKey; + this.privateKey = privateKey; + this.apiBase = this.setEnviroment(apiBase); + } + + public String getApiBase() { + return this.apiBase; + } + + public void setApiBase(final String apiBase) { + this.apiBase = apiBase; + } + + public String getPublicKey() { + return this.publicKey; + } + + public void setPublicKey(final String publicKey) { + this.publicKey = publicKey; + } + + public String getPrivateKey() { + return this.privateKey; + } + + public void setPrivateKey(final String privatKey) { + this.privateKey = privatKey; + } + + public static Gateway gateway() { + return new Gateway(instantiate()); + } + + public static Client client(final Configuration config) { + return new Client(config); + } + + public static Configuration instantiate() { + return new Configuration(); + } + + public String setEnviroment(final String enviroment) { + switch (enviroment) { + case "production": + case "PRODUCTION": { + return "https://api.trolley.com"; + } + case "development": + case "DEVELOPMENT": { + return "http://api.railz.io"; + } + case "integration": + case "INTEGRATION": { + return "http://api.local.dev:3000"; + } + case "sandbox": + case "SANDBOX": { + return "https://api.trolley.com"; + } + default: { + return "https://api.trolley.com"; + } + } + } +} diff --git a/src/main/java/ca/paymentrails/paymentrails/Detail.java b/src/main/java/com/trolley/trolley/Detail.java similarity index 67% rename from src/main/java/ca/paymentrails/paymentrails/Detail.java rename to src/main/java/com/trolley/trolley/Detail.java index 807adcb..0fb6d71 100644 --- a/src/main/java/ca/paymentrails/paymentrails/Detail.java +++ b/src/main/java/com/trolley/trolley/Detail.java @@ -1,10 +1,9 @@ -package ca.paymentrails.paymentrails; +package com.trolley.trolley; import com.fasterxml.jackson.annotation.JsonProperty; -public class Detail { - +public class Detail +{ @JsonProperty("bank-transfer") public BankTransfer bankTransfer; - -} \ No newline at end of file +} diff --git a/src/main/java/com/trolley/trolley/EUR.java b/src/main/java/com/trolley/trolley/EUR.java new file mode 100644 index 0000000..3528ab9 --- /dev/null +++ b/src/main/java/com/trolley/trolley/EUR.java @@ -0,0 +1,64 @@ +package com.trolley.trolley; + +public class EUR +{ + private Boolean primary; + private String amount; + private String currency; + private String type; + private String accountNumber; + private Boolean display; + + public Boolean getPrimary() { + return this.primary; + } + + public void setPrimary(final Boolean primary) { + this.primary = primary; + } + + public String getAmount() { + return this.amount; + } + + public void setAmount(final String amount) { + this.amount = amount; + } + + public String getCurrency() { + return this.currency; + } + + public void setCurrency(final String currency) { + this.currency = currency; + } + + public String getType() { + return this.type; + } + + public void setType(final String type) { + this.type = type; + } + + public String getAccountNumber() { + return this.accountNumber; + } + + public void setAccountNumber(final String accountNumber) { + this.accountNumber = accountNumber; + } + + public Boolean getDisplay() { + return this.display; + } + + public void setDisplay(final Boolean display) { + this.display = display; + } + + @Override + public String toString() { + return "ClassPojo [amount = " + this.amount + ", accountNumber = " + this.accountNumber + ", primary = " + this.primary + ", display = " + this.display + ", type = " + this.type + ", currency = " + this.currency + "]"; + } +} diff --git a/src/main/java/ca/paymentrails/paymentrails/Gateway.java b/src/main/java/com/trolley/trolley/Gateway.java similarity index 59% rename from src/main/java/ca/paymentrails/paymentrails/Gateway.java rename to src/main/java/com/trolley/trolley/Gateway.java index b91d77f..e2e35fc 100644 --- a/src/main/java/ca/paymentrails/paymentrails/Gateway.java +++ b/src/main/java/com/trolley/trolley/Gateway.java @@ -1,7 +1,7 @@ -package ca.paymentrails.paymentrails; - -public class Gateway { +package com.trolley.trolley; +public class Gateway +{ public Configuration config; public RecipientGateway recipient; public Client client; @@ -9,8 +9,11 @@ public class Gateway { public RecipientAccountGateway recipientAccount; public BalancesGateway balances; public PaymentGateway payment; - - public Gateway(Configuration config) { + public InvoiceGateway invoice; + public InvoiceLineGateway invoiceLine; + public InvoicePaymentGateway invoicePayment; + + public Gateway(final Configuration config) { this.config = config; this.client = new Client(config); this.recipient = new RecipientGateway(config); @@ -18,6 +21,8 @@ public Gateway(Configuration config) { this.recipientAccount = new RecipientAccountGateway(config); this.balances = new BalancesGateway(config); this.payment = new PaymentGateway(config); - + this.invoice = new InvoiceGateway(config); + this.invoiceLine = new InvoiceLineGateway(config); + this.invoicePayment = new InvoicePaymentGateway(config); } -} \ No newline at end of file +} diff --git a/src/main/java/com/trolley/trolley/Invoice.java b/src/main/java/com/trolley/trolley/Invoice.java new file mode 100644 index 0000000..42da799 --- /dev/null +++ b/src/main/java/com/trolley/trolley/Invoice.java @@ -0,0 +1,337 @@ +package com.trolley.trolley; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.exc.StreamReadException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonValue; +import com.trolley.trolley.types.Amount; +import com.trolley.trolley.types.Invoices; +import com.trolley.trolley.types.Meta; + +public class Invoice +{ + private String id; + private String invoiceId; + private String invoiceNumber; + private String description; + private String status; + private String externalId; + private String invoiceDate; + private String dueDate; + private String createdAt; + private String updatedAt; + private Amount totalAmount; + private Amount paidAmount; + private Amount dueAmount; + private List tags; + private List lines; + private String recipientId; + + public static enum SearchBy { + INVOICE_ID("invoiceId"), + RECIPIENT_ID("recipientId"), + INVOICE_NUMBER("invoiceNumber"), + INVOICE_DATE("invoiceDate"), + EXTERNAL_ID("externalId"), + TAGS("tags"); + + private String key; + + SearchBy(String key) { + this.key = key; + } + + @JsonCreator + public static SearchBy fromString(String key) { + return key == null + ? null + : SearchBy.valueOf(key.toUpperCase(Locale.US)); + } + + @JsonValue + public String getKey() { + return key; + } + + public String toString(){ + return key.toLowerCase(Locale.US); + } + } + + public Invoice() { } + + /** + * @param recipientId + * @param invoiceNumber + * @param description + * @param externalId + * @param invoiceDate + * @param dueDate + * @param tags + * @param lines + */ + public Invoice(String recipientId, + String invoiceNumber, + String description, + String externalId, + String invoiceDate, + String dueDate, + List tags, + List lines) { + this.invoiceNumber = invoiceNumber; + this.description = description; + this.externalId = externalId; + this.invoiceDate = invoiceDate; + this.dueDate = dueDate; + this.tags = tags; + this.lines = lines; + this.recipientId = recipientId; + } + + private Invoice(String id, + String invoiceId, + String invoiceNumber, + String description, + String status, + String externalId, + String invoiceDate, + String dueDate, + String createdAt, + String updatedAt, + Amount totalAmount, + Amount paidAmount, + Amount dueAmount, + List tags, + List lines, + String recipientId) { + this.id = id; + this.invoiceId = invoiceId; // Only for Invoice.Update operation + this.invoiceNumber = invoiceNumber; + this.description = description; + this.status = status; + this.externalId = externalId; + this.invoiceDate = invoiceDate; + this.dueDate = dueDate; + this.createdAt = createdAt; + this.updatedAt = updatedAt; + this.totalAmount = totalAmount; + this.paidAmount = paidAmount; + this.dueAmount = dueAmount; + this.tags = tags; + this.lines = lines; + this.recipientId = recipientId; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + /** + * Sets the 'invoiceId' parameter for updating an invoice. + * Used only by InvoiceGateway class. + * May not have invoiceId set in most of the cases. + * see setId() for setting ID of this invoice. + * @param invoiceId + */ + public void setInvoiceId(String invoiceId) { + this.invoiceId = invoiceId; + } + + /** + * Getter for Jackson. This will not have any data in most of the cases. + * See getId() for getting ID of this invoice. + * @return + */ + public String getInvoiceId() { + return invoiceId; + } + + public String getInvoiceNumber() { + return invoiceNumber; + } + + public void setInvoiceNumber(String invoiceNumber) { + this.invoiceNumber = invoiceNumber; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getExternalId() { + return externalId; + } + + public void setExternalId(String externalId) { + this.externalId = externalId; + } + + public String getInvoiceDate() { + return invoiceDate; + } + + public void setInvoiceDate(String invoiceDate) { + this.invoiceDate = invoiceDate; + } + + public String getDueDate() { + return dueDate; + } + + public void setDueDate(String dueDate) { + this.dueDate = dueDate; + } + + public String getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(String createdAt) { + this.createdAt = createdAt; + } + + public String getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(String updatedAt) { + this.updatedAt = updatedAt; + } + + public Amount getTotalAmount() { + return totalAmount; + } + + public void setTotalAmount(Amount totalAmount) { + this.totalAmount = totalAmount; + } + + public Amount getPaidAmount() { + return paidAmount; + } + + public void setPaidAmount(Amount paidAmount) { + this.paidAmount = paidAmount; + } + + public Amount getDueAmount() { + return dueAmount; + } + + public void setDueAmount(Amount dueAmount) { + this.dueAmount = dueAmount; + } + + public List getTags() { + return tags; + } + + public void setTags(List tags) { + this.tags = tags; + } + + public List getLines() { + return lines; + } + + public void setLines(List lines) { + this.lines = lines; + } + + public String getRecipientId() { + return recipientId; + } + + public void setRecipientId(String recipientId) { + this.recipientId = recipientId; + } + + /** + * Factory method to generate Invoice object from a String representation of a valid Invoice JSON + * @param invoiceStr + * @return + * @throws JsonProcessingException + * @throws JsonMappingException + */ + public static Invoice invoiceFactory(final String invoiceStr) throws JsonMappingException, JsonProcessingException { + final ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + final JsonNode node = mapper.readTree(invoiceStr); + String invoiceId = node.get("invoice").get("id").asText(); + try{ + final Invoice invoice = (Invoice)mapper.readValue(node.get("invoice").traverse(), (Class)Invoice.class); + return invoice; + }catch(Exception e){ + e.printStackTrace(); + } + return new Invoice(invoiceId, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null); + } + + /** + * Factory method to create a List of Invoices + * @param invoicesStr + * @return + * @throws StreamReadException + * @throws IOException + */ + public static Invoices invoiceListFactory(final String invoicesStr) throws StreamReadException, IOException { + final ObjectMapper mapper = new ObjectMapper(); + final JsonNode node = mapper.readTree(invoicesStr); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + final Object invoice = mapper.readValue(node.get("invoices").traverse(), (Class)Object.class); + final List parsedInvoices = (List)invoice; + final List invoiceObjs = new ArrayList(); + + final Meta meta = (Meta)mapper.readValue(node.get("meta").traverse(), (Class)Meta.class); + + //Creating List object to return + for (Object singleInvoice : parsedInvoices) { + final Invoice pojo = (Invoice)mapper.convertValue((Object)singleInvoice, (Class)Invoice.class); + invoiceObjs.add(pojo); + } + + return new Invoices(invoiceObjs, meta); + } + + /** + * Invoice class' toString() method, returns a valid JSON String representation of this object + * @return String JSON String representation of this object + */ + public String toString(){ + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); + String jsonString = null; + try { + jsonString = objectMapper.writeValueAsString(this); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + return jsonString; + } +} diff --git a/src/main/java/com/trolley/trolley/InvoiceGateway.java b/src/main/java/com/trolley/trolley/InvoiceGateway.java new file mode 100644 index 0000000..7fd42cc --- /dev/null +++ b/src/main/java/com/trolley/trolley/InvoiceGateway.java @@ -0,0 +1,225 @@ +package com.trolley.trolley; +import java.util.ArrayList; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.trolley.Exceptions.InvalidFieldException; +import com.trolley.trolley.Invoice.SearchBy; +import com.trolley.trolley.types.Invoices; + +public class InvoiceGateway +{ + Client client; + + public InvoiceGateway(final Configuration config) { + this.client = new Client(config); + } + + /** + * Create a new invoice with data provided by the invoice object + * @param invoiceBody + * @return Invoice created invoice + * @throws Exception + */ + public Invoice create(final Invoice invoiceBody) throws Exception { + String body = invoiceBody.toString(); + + final String endPoint = "/v1/invoices/create/"; + final String response = this.client.post(endPoint, body); + return Invoice.invoiceFactory(response); + } + + /** + * Update the invoice represented by the given invoiceId with data found in + * invoiceBody object supplied. + * Only the fields that you send will be updated. + * @param invoiceId + * @param invoiceBody + * @return Invoice updated invoice + * @throws Exception + */ + public Invoice update(final String invoiceId, final Invoice invoiceBody) throws Exception { + invoiceBody.setInvoiceId(invoiceId); + String body = invoiceBody.toString(); + + final String endPoint = "/v1/invoices/update/"; + final String response = this.client.post(endPoint, body); + + return Invoice.invoiceFactory(response); + } + + /** + * Delete one invoice by its ID + * @param invoiceId + * @return boolean true if the delete operation was successful + * @throws Exception + */ + public boolean delete(final String invoiceId) throws Exception { + final String endPoint = "/v1/invoices/delete/"; + + ArrayList invoiceIds = new ArrayList() { + { + add(invoiceId); + } + }; + + final String body = "{\"invoiceIds\":" + +new ObjectMapper().writeValueAsString(invoiceIds) + +"}"; + + final String response = this.client.post(endPoint, body); + + final ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + final JsonNode node = mapper.readTree(response); + return node.get("ok").asBoolean(false); + } + + /** + * Delete multiple invoices whose ID is provided as a List + * @param invoiceIds + * @return boolean true if the delete operation was successful + * @throws Exception + */ + public boolean delete(final List invoiceIds) throws Exception { + final String endPoint = "/v1/invoices/delete/"; + + final String body = "{\"invoiceIds\":" + +new ObjectMapper() + .setSerializationInclusion(Include.NON_EMPTY) + .writeValueAsString(invoiceIds) + +"}"; + + final String response = this.client.post(endPoint, body); + + final ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + final JsonNode node = mapper.readTree(response); + return node.get("ok").asBoolean(false); + } + + /** + * Fetch an invoice by invoiceId + * @param invoiceId + * @return Invoice The invoice that was fetched + * @throws Exception + */ + public Invoice fetch(final String invoiceId) throws Exception { + final String endPoint = "/v1/invoices/get/"; + final String body = "{\"invoiceId\":\""+invoiceId+"\"}"; + final String response = this.client.post(endPoint, body); + return Invoice.invoiceFactory(response); + } + + /** + * Search invoices by multiple options such as by invoiceId, recipientId etc. + * Note: This method only returns the fist page, defaulting to 10 records per page. + * For pagination, look at {@code search(SearchBy searchBy, List paramsList, String param, int page, int pageSize)} below. + * + * Depending on what you want to search by, you'll either provide a {@code List} parameter, or a + * String parameter. Details about when to provide which parameter are given in the parameter + * list. + * These options correspond to our documentation. + * @param searchBy Enum of type Invoice.SearchBy denoting which field you want to search by + * @param paramsList {@code List} Required if 'searchBy' is either of these: 'invoiceId' + * 'recipientId', 'invoiceNumber', 'tags'. Set to 'null' otherwise. + * @param param String Required if 'searchBy' is either 'invoiceDate' or 'externalId'. Set to null otherwise. + * @return {@code List} + * @throws Exception + */ + + public List search(final SearchBy searchBy, + final List paramsList, + final String param) throws Exception { + + String body = ""; + + switch (searchBy){ + case INVOICE_ID: + case RECIPIENT_ID: + case INVOICE_NUMBER: + case TAGS: + if(null == paramsList){ + throw new InvalidFieldException("variable paramsList can not be null for the provided searchBy parameter. Refer to method's Javadoc for more details."); + } + body = "{\""+searchBy.name()+"\":" + +new ObjectMapper() + .setSerializationInclusion(Include.NON_EMPTY) + .writeValueAsString(paramsList) + +"}"; + break; + + case INVOICE_DATE: + case EXTERNAL_ID: + if(null == param){ + throw new InvalidFieldException("variable param can not be null for the provided searchBy parameter. Refer to method's Javadoc for more details."); + } + body = "{\""+searchBy.name()+"\":\""+param+"\"}"; + break; + } + final String endPoint = "/v1/invoices/search/"; + + final String response = this.client.post(endPoint, body); + + return Invoice.invoiceListFactory(response).getInvoices(); + } + + /** + * Search invoices by multiple options such as by invoiceId, recipientId etc. + * Note: This method supports pagination. + * Depending on what you want to search by, you'll either provide a {@code List} parameter, or a + * String parameter. Details about when to provide which parameter are given in the parameter + * list. + * These options correspond to our documentation. + * @param searchBy Enum of type Invoice.SearchBy denoting which field you want to search by + * @param paramsList {@code List} Required if 'searchBy' is either of these: 'invoiceId' + * 'recipientId', 'invoiceNumber', 'tags'. Set to 'null' otherwise. + * @param param String Required if 'searchBy' is either 'invoiceDate' or 'externalId'. Set to null otherwise. + * @return Invoices object that contains {@code List} that you can traverse through, and a Meta object with pagination information + * @throws Exception + */ + + public Invoices search(final SearchBy searchBy, + final List paramsList, + final String param, + final int page, + final int pageSize ) throws Exception { + + String body = ""; + + switch (searchBy){ + case INVOICE_ID: + case RECIPIENT_ID: + case INVOICE_NUMBER: + case TAGS: + if(null == paramsList){ + throw new InvalidFieldException("variable paramsList can not be null for the provided searchBy parameter. Refer to method's Javadoc for more details."); + } + body = "{\""+searchBy.name()+"\":" + +new ObjectMapper() + .setSerializationInclusion(Include.NON_EMPTY) + .writeValueAsString(paramsList) + +", \"page\":"+page + +", \"pageSize\":"+pageSize + +"}"; + break; + + case INVOICE_DATE: + case EXTERNAL_ID: + if(null == param){ + throw new InvalidFieldException("variable param can not be null for the provided searchBy parameter. Refer to method's Javadoc for more details."); + } + body = "{\""+searchBy.name()+"\":\""+param+"\"}"; + break; + } + final String endPoint = "/v1/invoices/search/"; + + final String response = this.client.post(endPoint, body); + return Invoice.invoiceListFactory(response); + + } + +} diff --git a/src/main/java/com/trolley/trolley/InvoiceLine.java b/src/main/java/com/trolley/trolley/InvoiceLine.java new file mode 100644 index 0000000..884ae9b --- /dev/null +++ b/src/main/java/com/trolley/trolley/InvoiceLine.java @@ -0,0 +1,286 @@ +package com.trolley.trolley; + +import java.io.IOException; +import java.util.List; +import java.util.Locale; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonValue; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.trolley.trolley.types.Amount; + +public class InvoiceLine +{ + private String id; + private String invoiceLineId; + private String status; + private String description; + private Amount unitAmount; + private String quantity; + private Amount discountAmount; + private Amount taxAmount; + private Amount totalAmount; + private Amount dueAmount; + private Amount paidAmount; + private String externalId; + private boolean taxReportable; + private List tags; + private InvoiceCategories category; + private boolean forceUsTaxActivity; + + public static enum InvoiceCategories{ + SERVICES("services"), + RENT("rent"), + ROYALTIES("royalties"), + ROYALTIES_FILM("royalties_film"), + PRIZES("prizes"), + EDUCATION("education"), + REFUNDS("refunds"); + + private String key; + + InvoiceCategories(String key) { + this.key = key; + } + + @JsonCreator + public static InvoiceCategories fromString(String key) { + return key == null + ? null + : InvoiceCategories.valueOf(key.toUpperCase(Locale.US)); + } + + @JsonValue + public String getKey() { + return key; + } + + public String toString(){ + return key.toLowerCase(Locale.US); + } + }; + + public InvoiceLine() {} + + /** + * @param unitAmount + * @param category + * @param description + * @param externalId + * @param taxReportable + * @param forceUsTaxActivity + * @param tags + * @param quantity + * @param discountAmount + * @param taxAmount + * @param dueAmount + * @param paidAmount + */ + public InvoiceLine( + Amount unitAmount, + InvoiceCategories category, + String description, + String externalId, + boolean taxReportable, + boolean forceUsTaxActivity, + List tags, + String quantity, + Amount discountAmount, + Amount taxAmount, + Amount dueAmount, + Amount paidAmount) { + this.description = description; + this.unitAmount = unitAmount; + this.quantity = quantity; + this.discountAmount = discountAmount; + this.taxAmount = taxAmount; + this.dueAmount = dueAmount; + this.paidAmount = paidAmount; + this.externalId = externalId; + this.taxReportable = taxReportable; + this.tags = tags; + this.category = category; + this.forceUsTaxActivity = forceUsTaxActivity; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + /** + * Get invoiceLineId for Update Invoice Line operation. + *

+ * NOTE: Only used for Update operation, may not be filled by other operations. + *

+ * See getId() for accessing InvoiceLineId from a response + * @return String invoiceLineId the id of the invoice line that needs to be updated + */ + public String getInvoiceLineId() { + return invoiceLineId; + } + + /** + * Set invoiceLineId for Update Invoice Line operation. + *

+ * NOTE: Only used for Update operation, may not be filled by other operations. + *

+ * See getId() for accessing InvoiceLineId from a response + * @param invoiceLineId the id of the invoice line that needs to be updated + */ + public void setInvoiceLineId(String invoiceLineId) { + this.invoiceLineId = invoiceLineId; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Amount getUnitAmount() { + return unitAmount; + } + + public void setUnitAmount(Amount unitAmount) { + this.unitAmount = unitAmount; + } + + public String getQuantity() { + return quantity; + } + + public void setQuantity(String quantity) { + this.quantity = quantity; + } + + public Amount getDiscountAmount() { + return discountAmount; + } + + public void setDiscountAmount(Amount discountAmount) { + this.discountAmount = discountAmount; + } + + public Amount getTaxAmount() { + return taxAmount; + } + + public void setTaxAmount(Amount taxAmount) { + this.taxAmount = taxAmount; + } + + public Amount getTotalAmount() { + return totalAmount; + } + + public void setTotalAmount(Amount totalAmount) { + this.totalAmount = totalAmount; + } + + public Amount getDueAmount() { + return dueAmount; + } + + public void setDueAmount(Amount dueAmount) { + this.dueAmount = dueAmount; + } + + public Amount getPaidAmount() { + return paidAmount; + } + + public void setPaidAmount(Amount paidAmount) { + this.paidAmount = paidAmount; + } + + public String getExternalId() { + return externalId; + } + + public void setExternalId(String externalId) { + this.externalId = externalId; + } + + public boolean isTaxReportable() { + return taxReportable; + } + + public void setTaxReportable(boolean taxReportable) { + this.taxReportable = taxReportable; + } + + public List getTags() { + return tags; + } + + public void setTags(List tags) { + this.tags = tags; + } + + public InvoiceCategories getCategory() { + return category; + } + + public void setCategory(InvoiceCategories category) { + this.category = category; + } + + public boolean isForceUsTaxActivity() { + return forceUsTaxActivity; + } + + public void setForceUsTaxActivity(boolean forceUsTaxActivity) { + this.forceUsTaxActivity = forceUsTaxActivity; + } + + /** + * Factory method to create Invoice object from the response that was returned.
+ *

+ * The API responds with the full Invoice object where the newly created line is added, + * so instead of returning the individual line item, the Invoice object is returned.
+ *

+ * + * @param invoiceLineResponse JSON String received in the response + * @return Invoice object containing all the lines, including the newly created one + * @throws JsonProcessingException + * @throws JsonMappingException + */ + public static Invoice invoiceLinesFactory(final String invoiceLineResponse) throws JsonMappingException, JsonProcessingException { + return Invoice.invoiceFactory(invoiceLineResponse); + } + + /** + * InvoiceLine class' toString() method, returns a valid JSON String representation of this object + * @return String JSON String representation of this object + */ + public String toString(){ + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); + String jsonString = null; + try { + jsonString = objectMapper.setSerializationInclusion(Include.NON_EMPTY).writeValueAsString(this); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + + return jsonString; + } +} diff --git a/src/main/java/com/trolley/trolley/InvoiceLineGateway.java b/src/main/java/com/trolley/trolley/InvoiceLineGateway.java new file mode 100644 index 0000000..05a40a9 --- /dev/null +++ b/src/main/java/com/trolley/trolley/InvoiceLineGateway.java @@ -0,0 +1,184 @@ +package com.trolley.trolley; +import java.util.ArrayList; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.trolley.Exceptions.InvalidFieldException; + +public class InvoiceLineGateway +{ + Client client; + + public InvoiceLineGateway(final Configuration config) { + this.client = new Client(config); + } + + /** + * Create a single Invoice Line and add it to the Invoice whose ID is supplied.
+ * + * @param invoiceId Id of the invoice where this line will be added + * @param invoiceLine InvoiceLine object which will be created + * @return Invoice object of the updated invoice containing the newly created line + * @throws Exception + */ + public Invoice create(final String invoiceId, final InvoiceLine invoiceLine) throws Exception { + final String endPoint = "/v1/invoices/create-lines/"; + ArrayList invoiceLines = new ArrayList() { + { + add(invoiceLine); + } + }; + + final String body = "{" + +"\"invoiceId\":\"" +invoiceId+"\"," + +"\"lines\":" +new ObjectMapper() + .setSerializationInclusion(Include.NON_EMPTY) + .writeValueAsString(invoiceLines) + +"}"; + + final String response = this.client.post(endPoint, body); + return InvoiceLine.invoiceLinesFactory(response); + } + + /** + * Create multiple Invoice Lines and adds them to the Invoice whose ID is supplied.
+ * @param invoiceId Id of the invoice where this line will be added + * @param invoiceLines {@code List} object represnting the lines which will be created + * @return Invoice object of the updated invoice containing these lines + * @throws Exception + */ + public Invoice create(final String invoiceId, final List invoiceLines) throws Exception { + final String endPoint = "/v1/invoices/create-lines/"; + + final String body = "{" + +"\"invoiceId\":\"" +invoiceId+"\"," + +"\"lines\":" +new ObjectMapper() + .setSerializationInclusion(Include.NON_EMPTY) + .writeValueAsString(invoiceLines) + +"}"; + + final String response = this.client.post(endPoint, body); + return InvoiceLine.invoiceLinesFactory(response); + } + + /** + * Update a single Invoice Line in an Invoice whose ID is supplied.
+ *

+ * NOTE: Make sure you set the {@code invoiceLineId} variable of the {@code invoiceLine} + * object supplied as parameter here. Not the {@code id}. + * + * @param invoiceId Id of the invoice where this line will be added + * @param invoiceLine InvoiceLine object which will be update + * @return Invoice object of the updated invoice containing the updated line + * @throws Exception + */ + public Invoice update(final String invoiceId, final InvoiceLine invoiceLine) throws Exception { + final String endPoint = "/v1/invoices/update-lines/"; + + if( null == invoiceLine.getInvoiceLineId() || + invoiceLine.getInvoiceLineId().length() == 0){ + throw new InvalidFieldException("invoiceLineId of invoiceLine object must be set to denote which invoiceLine needs to be updated. Did you set id variable instead? Refer to method's Javadoc for more details."); + } + + ArrayList invoiceLines = new ArrayList() { + { + add(invoiceLine); + } + }; + + final String body = "{" + +"\"invoiceId\":\"" +invoiceId+"\"," + +"\"lines\" :" +new ObjectMapper() + .setSerializationInclusion(Include.NON_EMPTY) + .writeValueAsString(invoiceLines) + +"}"; + + final String response = this.client.post(endPoint, body); + return InvoiceLine.invoiceLinesFactory(response); + } + + /** + * Update multiple Invoice Lines in an Invoice whose ID is supplied.
+ *

+ * NOTE: Make sure you set the {@code invoiceLineId} variable in all the objects supplied + * in the {@code invoiceLines} parameter. + * @param invoiceId Id of the invoice where this line will be added + * @param invoiceLines {@code List} object representing the lines which will be edited + * @return Invoice object of the updated invoice containing these lines + * @throws Exception + */ + public Invoice update(final String invoiceId, final List invoiceLines) throws Exception { + final String endPoint = "/v1/invoices/update-lines/"; + + for (InvoiceLine invoiceLine : invoiceLines) { + if( null == invoiceLine.getInvoiceLineId() || + invoiceLine.getInvoiceLineId().length() == 0){ + throw new InvalidFieldException("invoiceLineId of invoiceLine object must be set to denote which invoiceLine needs to be updated. Please confirm all of the items have this set correctly. Refer to method's Javadoc for more details."); + } + } + + final String body = "{" + +"\"invoiceId\":\"" +invoiceId+"\"," + +"\"lines\":" +new ObjectMapper() + .setSerializationInclusion(Include.NON_EMPTY) + .writeValueAsString(invoiceLines) + +"}"; + + final String response = this.client.post(endPoint, body); + return InvoiceLine.invoiceLinesFactory(response); + } + + /** + * Delete one invoice line by its ID + * @param invoiceId ID of the invoice from where this line needs to be deleted + * @param invoiceLineId ID of the invoice line which needs to be deleted + * @return boolean true if the delete operation was successful + * @throws Exception + */ + public boolean delete(final String invoiceId, final String invoiceLineId) throws Exception { + final String endPoint = "/v1/invoices/delete-lines/"; + + ArrayList invoiceLineIds = new ArrayList() { + { + add(invoiceLineId); + } + }; + + final String body = "{" + +"\"invoiceId\":\""+invoiceId+"\"," + +"\"invoiceLineIds\":"+new ObjectMapper().writeValueAsString(invoiceLineIds) + +"}"; + + final String response = this.client.post(endPoint, body); + + final ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + final JsonNode node = mapper.readTree(response); + return node.get("ok").asBoolean(false); + } + + /** + * Delete multiple invoices whose ID is provided as a List + * @param invoiceId + * @return boolean true if the delete operation was successful + * @throws Exception + */ + public boolean delete(final String invoiceId, final List invoiceLineIds) throws Exception { + final String endPoint = "/v1/invoices/delete-lines/"; + + final String body = "{" + +"\"invoiceId\":\"" +invoiceId+"\"," + +"\"invoiceLineIds\":" +new ObjectMapper().writeValueAsString(invoiceLineIds) + +"}"; + + final String response = this.client.post(endPoint, body); + + final ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + final JsonNode node = mapper.readTree(response); + return node.get("ok").asBoolean(false); + } +} diff --git a/src/main/java/com/trolley/trolley/InvoicePayment.java b/src/main/java/com/trolley/trolley/InvoicePayment.java new file mode 100644 index 0000000..61bc711 --- /dev/null +++ b/src/main/java/com/trolley/trolley/InvoicePayment.java @@ -0,0 +1,114 @@ +package com.trolley.trolley; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.exc.StreamReadException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.trolley.trolley.types.InvoicePaymentPart; +import com.trolley.trolley.types.InvoicePayments; +import com.trolley.trolley.types.Meta; + +public class InvoicePayment +{ + private String batchId; + private String paymentId; + private List invoicePayments; + + public InvoicePayment() {} + + public InvoicePayment(List invoicePayments) { + this.invoicePayments = invoicePayments; + } + + public String getBatchId() { + return batchId; + } + + public void setBatchId(String batchId) { + this.batchId = batchId; + } + + public String getPaymentId() { + return paymentId; + } + + public void setPaymentId(String paymentId) { + this.paymentId = paymentId; + } + + public List getInvoicePayments() { + return invoicePayments; + } + + public void setInvoicePayments(List invoicePayments) { + this.invoicePayments = invoicePayments; + } + + /** + * Factory method to create InvoicePayment object from the response that was returned. + * + * @param invoicePaymentResponse JSON String received in the response + * @return InvoicePayment object containing all the lines, including the newly created one + * @throws JsonProcessingException + * @throws JsonMappingException + */ + public static InvoicePayment invoicePaymentFactory(final String invoicePaymentResponse) throws JsonMappingException, JsonProcessingException { + final ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + final JsonNode node = mapper.readTree(invoicePaymentResponse); + String paymentId = node.get("invoicePayment").get("paymentId").asText(); + InvoicePayment invoicePayment; + try{ + invoicePayment = (InvoicePayment)mapper.readValue(node.get("invoicePayment").traverse(), (Class)InvoicePayment.class); + }catch(Exception e){ + e.printStackTrace(); + invoicePayment = new InvoicePayment(null); + invoicePayment.setPaymentId(paymentId); + } + return invoicePayment; + } + + public static InvoicePayments invoicePaymentsFactory(final String invoicePaymentResponse) throws StreamReadException, IOException{ + final ObjectMapper mapper = new ObjectMapper(); + final JsonNode node = mapper.readTree(invoicePaymentResponse); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + final Object invoicePayments = mapper.readValue(node.get("invoicePayments").traverse(), (Class)Object.class); + final List parsedInvoicePayments = (List)invoicePayments; + final ArrayList paymentPartsObjs = new ArrayList(); + + final Meta meta = (Meta)mapper.readValue(node.get("meta").traverse(), (Class)Meta.class); + + //Creating List object to return + for (Object invoicePayment : parsedInvoicePayments) { + final InvoicePaymentPart pojo = (InvoicePaymentPart)mapper.convertValue((Object)invoicePayment, (Class)InvoicePaymentPart.class); + paymentPartsObjs.add(pojo); + } + + return new InvoicePayments(paymentPartsObjs, meta); + } + + /** + * InvoicePayment class' toString() method, returns a valid JSON String representation of this object + * @return String JSON String representation of this object + */ + public String toString(){ + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY); + String jsonString = null; + try { + jsonString = objectMapper.setSerializationInclusion(Include.NON_EMPTY).writeValueAsString(this); + } catch (JsonProcessingException e) { + e.printStackTrace(); + } + + return jsonString; + } +} diff --git a/src/main/java/com/trolley/trolley/InvoicePaymentGateway.java b/src/main/java/com/trolley/trolley/InvoicePaymentGateway.java new file mode 100644 index 0000000..4a74414 --- /dev/null +++ b/src/main/java/com/trolley/trolley/InvoicePaymentGateway.java @@ -0,0 +1,197 @@ +package com.trolley.trolley; +import java.util.ArrayList; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.trolley.trolley.types.InvoicePaymentPart; +import com.trolley.trolley.types.InvoicePayments; + +public class InvoicePaymentGateway +{ + Client client; + + public InvoicePaymentGateway(final Configuration config) { + this.client = new Client(config); + } + + /** + * Create a payment against an invoice. + *

+ * NOTE: If you provide a batch id, this method will try to add the payment to it. If you provide a + * {@code null} or blank ({@code ""}) batch id, a new batch will be created. + * + * + * @param batchId (Optional) Id of the batch you want to add these payments too. + * @param payment InvoicePaymentPart object representing the Invoice payment that needs to be created + * @return InvoicePayment object of representing the created payment for the Invoice + * @throws Exception + */ + public InvoicePayment create(final String batchId, final InvoicePaymentPart payment) throws Exception { + final String endPoint = "/v1/invoices/payment/create/"; + + String body = ""; + + if(null != batchId && !batchId.isEmpty()){ + body = "{ \"batchId\": \"" + batchId + "\","; + }else{ + body = "{"; + } + ArrayList invoicePaymentParts = new ArrayList() { + { + add(payment); + } + }; + + body+= "\"ids\":" +new ObjectMapper() + .setSerializationInclusion(Include.NON_EMPTY) + .writeValueAsString(invoicePaymentParts) + +"}"; + final String response = this.client.post(endPoint, body); + return InvoicePayment.invoicePaymentFactory(response); + } + + /** + * Create a payment against multiple invoices. + *

+ * NOTE: If you provide a batch id, this method will try to add the payment to it. If you provide a + * {@code null} or blank ({@code ""}) batch id, a new batch will be created. + * + * @param batchId (Optional) Id of the batch you want to add these payments too. + * @param invoicePaymentParts A List of InvoicePaymentPart objects representing the Invoice payments that need to be created. + * @return InvoicePayment object of representing the created payment for the Invoice + * @throws Exception + */ + public InvoicePayment create(final String batchId, final List invoicePaymentParts) throws Exception { + final String endPoint = "/v1/invoices/payment/create/"; + + String body = ""; + + if(null != batchId && !batchId.isEmpty()){ + body = "{ \"batchId\": \"" + batchId + "\","; + }else{ + body = "{"; + } + + body+= "\"ids\":" +new ObjectMapper() + .setSerializationInclusion(Include.NON_EMPTY) + .writeValueAsString(invoicePaymentParts) + +"}"; + final String response = this.client.post(endPoint, body); + return InvoicePayment.invoicePaymentFactory(response); + } + + /** + * Update an Invoice Payment whose details are provided in invoicePaymentPart object. + *

+ * Refer to our docs for details + * about which parameters are required. + * @param invoicePaymentPart + * @return boolean true if the update was successful + * @throws Exception + */ + public boolean update(final InvoicePaymentPart invoicePaymentPart) throws Exception { + final String endPoint = "/v1/invoices/payment/update/"; + + final String body = new ObjectMapper() + .setSerializationInclusion(Include.NON_EMPTY) + .writeValueAsString(invoicePaymentPart); + + final String response = this.client.post(endPoint, body); + + final ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + final JsonNode node = mapper.readTree(response); + return node.get("ok").asBoolean(false); + } + + /** + * Search for invoice payments matching the list of paymentIds or invoiceIds provided. + *

+ * Either {@code paymentIds} or {@code invoiceIds} is required. + * @param paymentIds + * @param invoiceIds + * @return InvoicePayments object containing a list of found InvoicePaymentParts and Meta object for + * pagination information + * @throws Exception + */ + public InvoicePayments search(final List paymentIds, final List invoiceIds) throws Exception { + final String endPoint = "/v1/invoices/payment/search/"; + + String body = "{"; + if(null != paymentIds && !paymentIds.isEmpty()){ + body+= "\"paymentIds\":" + new ObjectMapper() + .setSerializationInclusion(Include.NON_EMPTY) + .writeValueAsString(paymentIds); + } + + if(null != invoiceIds && !invoiceIds.isEmpty()){ + if(null != paymentIds && !paymentIds.isEmpty()){ + body+=","; + } + body+="\"invoiceIds\":" + new ObjectMapper() + .setSerializationInclusion(Include.NON_EMPTY) + .writeValueAsString(invoiceIds); + } + + body+= "}"; + + final String response = this.client.post(endPoint, body); + + return InvoicePayment.invoicePaymentsFactory(response); + } + + /** + * Remove the association between a payment and an invoice line ID. + * @param paymentId payment id to delete + * @param invoiceLineId + * @return boolean true if the delete operation was successful + * @throws Exception + */ + public boolean delete(final String paymentId, final String invoiceLineId) throws Exception { + final String endPoint = "/v1/invoices/payment/delete/"; + + ArrayList invoiceLineIds = new ArrayList() { + { + add(invoiceLineId); + } + }; + + final String body = "{" + +"\"paymentId\":\""+paymentId+"\"," + +"\"invoiceLineIds\":"+new ObjectMapper().writeValueAsString(invoiceLineIds) + +"}"; + + final String response = this.client.post(endPoint, body); + + final ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + final JsonNode node = mapper.readTree(response); + return node.get("ok").asBoolean(false); + } + + /** + * Remove the association between a payment and multiple invoice line IDs. + * @param paymentId payment id to delete + * @param invoiceLineIds a {@code List} of invoiceLineIds + * @return + * @throws Exception + */ + public boolean delete(final String paymentId, final List invoiceLineIds) throws Exception { + final String endPoint = "/v1/invoices/payment/delete/"; + + final String body = "{" + +"\"paymentId\":\""+paymentId+"\"," + +"\"invoiceLineIds\":"+new ObjectMapper().writeValueAsString(invoiceLineIds) + +"}"; + + final String response = this.client.post(endPoint, body); + + final ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + final JsonNode node = mapper.readTree(response); + return node.get("ok").asBoolean(false); + } +} diff --git a/src/main/java/com/trolley/trolley/Payment.java b/src/main/java/com/trolley/trolley/Payment.java new file mode 100644 index 0000000..14123a8 --- /dev/null +++ b/src/main/java/com/trolley/trolley/Payment.java @@ -0,0 +1,321 @@ +package com.trolley.trolley; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonInclude; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Payment +{ + private String id; + private Recipient recipient; + private String status; + private Boolean isSupplyPayment; + private String returnedAmount; + private String amount; + private String currency; + private String category; + private RecipientAccount account; + private List tags; + private String sourceAmount; + private String sourceCurrency; + private String targetAmount; + private String targetCurrency; + private String exchangeRate; + private String fees; + private String recipientFees; + private String fxRate; + private String memo; + private String externalId; + private Object processedAt; + private String createdAt; + private String updatedAt; + private String merchantFees; + private Compliance compliance; + private String payoutMethod; + private String methodDisplay; + Object batch; + String withholdingAmount; + String withholdingCurrency; + String equivalentWithholdingAmount; + String equivalentWithholdingCurrency; + + public void setEquivalentWithholdingCurrency(final String equivalentWithholdingCurrency) { + this.equivalentWithholdingCurrency = equivalentWithholdingCurrency; + } + + public String getEquivalentWithholdingCurrency() { + return this.equivalentWithholdingCurrency; + } + + public void setEquivalentWithholdingAmount(final String equivalentWithholdingAmount) { + this.equivalentWithholdingAmount = equivalentWithholdingAmount; + } + + public String getEquivalentWithholdingAmount() { + return this.equivalentWithholdingAmount; + } + + public void setWithholdingCurrency(final String withholdingCurrency) { + this.withholdingCurrency = withholdingCurrency; + } + + public List getTags() { + return this.tags; + } + + public void setTags(final List tags) { + this.tags = tags; + } + + public RecipientAccount getAccount() { + return this.account; + } + + public void setAccount(final RecipientAccount account) { + this.account = account; + } + + public String getCategory() { + return this.category; + } + + public void setCategory(final String category) { + this.category = category; + } + + public String getCurrency() { + return this.currency; + } + + public void setCurrency(final String currency) { + this.currency = currency; + } + + public String getAmount() { + return this.amount; + } + + public void setAmount(final String amount) { + this.amount = amount; + } + + public String getWithholdingCurrency() { + return this.withholdingCurrency; + } + + public void setWithholdingAmount(final String withholdingAmount) { + this.withholdingAmount = withholdingAmount; + } + + public String getWithholdingAmount() { + return this.withholdingAmount; + } + + public String getId() { + return this.id; + } + + public void setId(final String id) { + this.id = id; + } + + public Recipient getRecipient() { + return this.recipient; + } + + public void setRecipient(final Recipient recipient) { + this.recipient = recipient; + } + + public String getStatus() { + return this.status; + } + + public void setStatus(final String status) { + this.status = status; + } + + public Boolean getIsSupplyPayment() { + return this.isSupplyPayment; + } + + public void setIsSupplyPayment(final Boolean isSupplyPayment) { + this.isSupplyPayment = isSupplyPayment; + } + + public String getReturnedAmount() { + return this.returnedAmount; + } + + public void setReturnedAmount(final String returnedAmount) { + this.returnedAmount = returnedAmount; + } + + public String getSourceAmount() { + return this.sourceAmount; + } + + public void setSourceAmount(final String sourceAmount) { + this.sourceAmount = sourceAmount; + } + + public String getSourceCurrency() { + return this.sourceCurrency; + } + + public void setSourceCurrency(final String sourceCurrency) { + this.sourceCurrency = sourceCurrency; + } + + public String getTargetAmount() { + return this.targetAmount; + } + + public void setTargetAmount(final String targetAmount) { + this.targetAmount = targetAmount; + } + + public String getTargetCurrency() { + return this.targetCurrency; + } + + public void setTargetCurrency(final String targetCurrency) { + this.targetCurrency = targetCurrency; + } + + public String getExchangeRate() { + return this.exchangeRate; + } + + public void setExchangeRate(final String exchangeRate) { + this.exchangeRate = exchangeRate; + } + + public String getFees() { + return this.fees; + } + + public void setFees(final String fees) { + this.fees = fees; + } + + public String getRecipientFees() { + return this.recipientFees; + } + + public void setRecipientFees(final String recipientFees) { + this.recipientFees = recipientFees; + } + + public String getFxRate() { + return this.fxRate; + } + + public void setFxRate(final String fxRate) { + this.fxRate = fxRate; + } + + public String getMemo() { + return this.memo; + } + + public void setMemo(final String memo) { + this.memo = memo; + } + + public String getExternalId() { + return this.externalId; + } + + public void setExternalId(final String externalId) { + this.externalId = externalId; + } + + public Object getProcessedAt() { + return this.processedAt; + } + + public void setProcessedAt(final Object processedAt) { + this.processedAt = processedAt; + } + + public String getCreatedAt() { + return this.createdAt; + } + + public void setCreatedAt(final String createdAt) { + this.createdAt = createdAt; + } + + public String getUpdatedAt() { + return this.updatedAt; + } + + public void setUpdatedAt(final String updatedAt) { + this.updatedAt = updatedAt; + } + + public String getMerchantFees() { + return this.merchantFees; + } + + public void setMerchantFees(final String merchantFees) { + this.merchantFees = merchantFees; + } + + public Compliance getCompliance() { + return this.compliance; + } + + public void setCompliance(final Compliance compliance) { + this.compliance = compliance; + } + + public String getPayoutMethod() { + return this.payoutMethod; + } + + public void setPayoutMethod(final String payoutMethod) { + this.payoutMethod = payoutMethod; + } + + public String getMethodDisplay() { + return this.methodDisplay; + } + + public void setMethodDisplay(final String methodDisplay) { + this.methodDisplay = methodDisplay; + } + + public static Payment find(final String payment_id, final String batch_id) throws Exception { + return Configuration.gateway().payment.find(payment_id, batch_id); + } + + public static Payment create(final String body, final String batch_id) throws Exception { + return Configuration.gateway().payment.create(body, batch_id); + } + + public static boolean update(final String payment_id, final String body, final String batch_id) throws Exception { + return Configuration.gateway().payment.update(payment_id, body, batch_id); + } + + public static boolean delete(final String payment_id, final String batch_id) throws Exception { + return Configuration.gateway().payment.delete(payment_id, batch_id); + } + + public static List query(final String batch_id, final int page, final int pageSize, final String message) throws Exception { + return Configuration.gateway().payment.query(batch_id, page, pageSize, message); + } + + public static List query(final String batch_id, final String message) throws Exception { + return query(batch_id, 1, 10, message); + } + + public static List query(final String batch_id) throws Exception { + return query(batch_id, 1, 10, ""); + } + + public static List query(final String batch_id, final int page, final int pageSize) throws Exception { + return query(batch_id, page, pageSize, ""); + } +} diff --git a/src/main/java/ca/paymentrails/paymentrails/PaymentGateway.java b/src/main/java/com/trolley/trolley/PaymentGateway.java similarity index 51% rename from src/main/java/ca/paymentrails/paymentrails/PaymentGateway.java rename to src/main/java/com/trolley/trolley/PaymentGateway.java index d8df8a7..6f07423 100644 --- a/src/main/java/ca/paymentrails/paymentrails/PaymentGateway.java +++ b/src/main/java/com/trolley/trolley/PaymentGateway.java @@ -1,48 +1,46 @@ -package ca.paymentrails.paymentrails; +package com.trolley.trolley; -import ca.paymentrails.Exceptions.InvalidFieldException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import java.io.IOException; import java.util.ArrayList; +import java.io.IOException; +import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; import java.util.List; +import com.trolley.Exceptions.InvalidFieldException; -public class PaymentGateway { +public class PaymentGateway +{ Client client; - - public PaymentGateway(Configuration config) { + + public PaymentGateway(final Configuration config) { this.client = new Client(config); } - - public Payment find(String payment_id, String batch_id) throws Exception { + + public Payment find(final String payment_id, final String batch_id) throws Exception { if (batch_id == null || batch_id.isEmpty()) { throw new InvalidFieldException("Batch id cannot be null or empty."); } if (payment_id == null || payment_id.isEmpty()) { throw new InvalidFieldException("Payment id cannot be null or empty."); } - - String endPoint = "/v1/batches/" + batch_id + "/payments/" + payment_id; - String response = this.client.get(endPoint); - return paymentFactory(response); + final String endPoint = "/v1/batches/" + batch_id + "/payments/" + payment_id; + final String response = this.client.get(endPoint); + return this.paymentFactory(response); } - - public Payment create(String body, String batch_id) throws Exception { + + public Payment create(final String body, final String batch_id) throws Exception { if (batch_id == null || batch_id.isEmpty()) { throw new InvalidFieldException("Batch id cannot be null or empty."); } if (body == null || body.isEmpty()) { throw new InvalidFieldException("Body cannot be null or empty."); } - - String endPoint = "/v1/batches/" + batch_id + "/payments"; - String response = this.client.post(endPoint, body); - - return paymentFactory(response); + final String endPoint = "/v1/batches/" + batch_id + "/payments"; + final String response = this.client.post(endPoint, body); + return this.paymentFactory(response); } - - public boolean update(String payment_id, String body, String batch_id) throws Exception { + + public boolean update(final String payment_id, final String body, final String batch_id) throws Exception { if (batch_id == null || batch_id.isEmpty()) { throw new InvalidFieldException("Batch id cannot be null or empty."); } @@ -52,27 +50,24 @@ public boolean update(String payment_id, String body, String batch_id) throws Ex if (body == null || body.isEmpty()) { throw new InvalidFieldException("Body cannot be null or empty."); } - - String endPoint = "/v1/batches/" + batch_id + "/payments/" + payment_id; + final String endPoint = "/v1/batches/" + batch_id + "/payments/" + payment_id; this.client.patch(endPoint, body); return true; } - - public boolean delete(String payment_id, String batch_id) throws Exception { + + public boolean delete(final String payment_id, final String batch_id) throws Exception { if (batch_id == null || batch_id.isEmpty()) { throw new InvalidFieldException("Batch id cannot be null or empty."); } if (payment_id == null || payment_id.isEmpty()) { throw new InvalidFieldException("Payment id cannot be null or empty."); } - - String endPoint = "/v1/batches/" + batch_id + "/payments/" + payment_id; + final String endPoint = "/v1/batches/" + batch_id + "/payments/" + payment_id; this.client.delete(endPoint); return true; } - - public List query(String batch_id, int page, int pageSize, String message) throws Exception { - + + public List query(final String batch_id, final int page, final int pageSize, final String message) throws Exception { if (batch_id == null || batch_id.isEmpty()) { throw new InvalidFieldException("Batch id cannot be null or empty."); } @@ -85,34 +80,30 @@ public List query(String batch_id, int page, int pageSize, String messa if (message == null) { throw new InvalidFieldException("Message cannot be null"); } - - String endPoint = "/v1/batches/" + batch_id + "/payments/?" + "&search=" + message + "&page=" + page - + "&pageSize=" + pageSize; - String response = this.client.get(endPoint); - return paymentListFactory(response); + final String endPoint = "/v1/batches/" + batch_id + "/payments/?&search=" + message + "&page=" + page + "&pageSize=" + pageSize; + final String response = this.client.get(endPoint); + return this.paymentListFactory(response); } - - private Payment paymentFactory(String data) throws IOException { - ObjectMapper mapper = new ObjectMapper(); + + private Payment paymentFactory(final String data) throws IOException { + final ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - JsonNode node = mapper.readTree(data); - Payment payment = mapper.readValue(node.get("payment").traverse(), Payment.class); + final JsonNode node = mapper.readTree(data); + final Payment payment = (Payment)mapper.readValue(node.get("payment").traverse(), (Class)Payment.class); return payment; } - - private List paymentListFactory(String data) throws IOException { - ObjectMapper mapper = new ObjectMapper(); - JsonNode node = mapper.readTree(data); + + private List paymentListFactory(final String data) throws IOException { + final ObjectMapper mapper = new ObjectMapper(); + final JsonNode node = mapper.readTree(data); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - Object payment = mapper.readValue(node.get("payments").traverse(), Object.class); - @SuppressWarnings("unchecked") - List paymens = (List) payment; - List payments = new ArrayList(); - for (int i = 0; i < paymens.size(); i++) { - Payment pojo = mapper.convertValue(paymens.get(i), Payment.class); + final Object payment = mapper.readValue(node.get("payments").traverse(), (Class)Object.class); + final List paymens = (List)payment; + final List payments = new ArrayList(); + for (int i = 0; i < paymens.size(); ++i) { + final Payment pojo = (Payment)mapper.convertValue((Object)paymens.get(i), (Class)Payment.class); payments.add(pojo); } - return payments; } -} \ No newline at end of file +} diff --git a/src/main/java/com/trolley/trolley/Payments.java b/src/main/java/com/trolley/trolley/Payments.java new file mode 100644 index 0000000..223f050 --- /dev/null +++ b/src/main/java/com/trolley/trolley/Payments.java @@ -0,0 +1,31 @@ +package com.trolley.trolley; + +import java.util.List; + +import com.trolley.trolley.types.Meta; + +public class Payments +{ + private List payments; + private Meta meta; + + public Payments() { + this.payments = null; + } + + public List getPayments() { + return this.payments; + } + + public void setPayments(final List payments) { + this.payments = payments; + } + + public Meta getMeta() { + return this.meta; + } + + public void setMeta(final Meta meta) { + this.meta = meta; + } +} diff --git a/src/main/java/com/trolley/trolley/Recipient.java b/src/main/java/com/trolley/trolley/Recipient.java new file mode 100644 index 0000000..fc077e5 --- /dev/null +++ b/src/main/java/com/trolley/trolley/Recipient.java @@ -0,0 +1,353 @@ +package com.trolley.trolley; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonInclude; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Recipient +{ + String id; + String routeType; + String routeMinimum; + String estimatedFees; + String referenceId; + String email; + String name; + String lastName; + String firstName; + String type; + String taxType; + String status; + String language; + String complianceStatus; + String dob; + String passport; + String updatedAt; + String createdAt; + String gravatarUrl; + String governmentId; + String ssn; + String primaryCurrency; + String placeOfBirth; + List tags; + String merchantId; + String payoutMethod; + public Object payout; + String emailAddress; + public Object inactiveReasons; + Compliance compliance; + List accounts; + Address address; + String taxForm; + String taxFormStatus; + String taxWithholdingPercentage; + + public Recipient() { + this.taxWithholdingPercentage = "0.0"; + } + + public String getTaxFormStatus() { + return this.taxFormStatus; + } + + public void setTaxFormStatus(final String taxFormStatus) { + this.taxFormStatus = this.taxForm; + } + + public List getTags() { + return this.tags; + } + + public void setTags(final List tags) { + this.tags = tags; + } + + public String getTaxWithholdingPercentage() { + return this.taxWithholdingPercentage; + } + + public void setTaxWithholdingPercentage(final String taxWithholdingPercentage) { + this.taxWithholdingPercentage = taxWithholdingPercentage; + } + + public String getTaxForm() { + return this.taxForm; + } + + public void setTaxForm(final String taxForm) { + this.taxForm = taxForm; + } + + public Object getInactiveReasons() { + return this.inactiveReasons; + } + + public void setInactiveReasons(final Object inactiveReasons) { + this.inactiveReasons = inactiveReasons; + } + + public List getAccounts() { + return this.accounts; + } + + public void setAccounts(final List accounts) { + this.accounts = accounts; + } + + public void setAddress(final Address address) { + this.address = address; + } + + public Address getAddress() { + return this.address; + } + + public Compliance getCompliance() { + return this.compliance; + } + + public void setCompliance(final Compliance compliance) { + this.compliance = compliance; + } + + public String getLastName() { + return this.lastName; + } + + public void setLastName(final String lastName) { + this.lastName = lastName; + } + + public String getRouteType() { + return this.routeType; + } + + public void setRouteType(final String routeType) { + this.routeType = routeType; + } + + public String getRouteMinimum() { + return this.routeMinimum; + } + + public void setRouteMinimum(String routeMinimum) { + this.routeMinimum = routeMinimum; + } + + public String getEstimatedFees() { + return this.estimatedFees; + } + + public void setEstimatedFees(final String estimatedFees) { + this.estimatedFees = estimatedFees; + } + + public String getId() { + return this.id; + } + + public void setId(final String id) { + this.id = id; + } + + public String getReferenceId() { + return this.referenceId; + } + + public void setReferenceId(final String referenceId) { + this.referenceId = referenceId; + } + + public String getEmail() { + return this.email; + } + + public void setEmail(final String email) { + this.email = email; + } + + public String getName() { + return this.name; + } + + public void setName(final String name) { + this.name = name; + } + + public String getFirstName() { + return this.firstName; + } + + public void setFirstName(final String firstName) { + this.firstName = firstName; + } + + public String getType() { + return this.type; + } + + public void setType(final String type) { + this.type = type; + } + + public String getTaxType() { + return this.taxType; + } + + public void setTaxType(final String taxType) { + this.taxType = taxType; + } + + public String getStatus() { + return this.status; + } + + public void setStatus(final String status) { + this.status = status; + } + + public String getLanguage() { + return this.language; + } + + public void setLanguage(final String language) { + this.language = language; + } + + public String getComplianceStatus() { + return this.complianceStatus; + } + + public void setComplianceStatus(final String complianceStatus) { + this.complianceStatus = complianceStatus; + } + + public String getDob() { + return this.dob; + } + + public void setDob(final String dob) { + this.dob = dob; + } + + public String getPassport() { + return this.passport; + } + + public void setPassport(final String passport) { + this.passport = passport; + } + + public String getUpdatedAt() { + return this.updatedAt; + } + + public void setUpdatedAt(final String updatedAt) { + this.updatedAt = updatedAt; + } + + public String getCreatedAt() { + return this.createdAt; + } + + public void setCreatedAt(final String createdAt) { + this.createdAt = createdAt; + } + + public String getGravatarUrl() { + return this.gravatarUrl; + } + + public void setGravatarUrl(final String gravatarUrl) { + this.gravatarUrl = gravatarUrl; + } + + public String getGovernmentId() { + return this.governmentId; + } + + public void setGovernmentId(final String governmentId) { + this.governmentId = governmentId; + } + + public String getSsn() { + return this.ssn; + } + + public void setSsn(final String ssn) { + this.ssn = ssn; + } + + public String getPrimaryCurrency() { + return this.primaryCurrency; + } + + public void setPrimaryCurrency(final String primaryCurrency) { + this.primaryCurrency = primaryCurrency; + } + + public String getPlaceOfBirth() { + return this.placeOfBirth; + } + + public void setPlaceOfBirth(final String placeOfBirth) { + this.placeOfBirth = placeOfBirth; + } + + public String getMerchantId() { + return this.merchantId; + } + + public void setMerchantId(final String merchantId) { + this.merchantId = merchantId; + } + + public String getPayoutMethod() { + return this.payoutMethod; + } + + public void setPayoutMethod(final String payoutMethod) { + this.payoutMethod = payoutMethod; + } + + public static Recipient find(final String recipient_id) throws Exception { + return Configuration.gateway().recipient.find(recipient_id); + } + + public static String findLogs(final String recipient_id) throws Exception { + final String response = Configuration.gateway().recipient.findLogs(recipient_id); + return response; + } + + public static List findPayments(final String recipient_id) throws Exception { + return Configuration.gateway().recipient.findPayments(recipient_id); + } + + public static Recipient create(final String body) throws Exception { + return Configuration.gateway().recipient.create(body); + } + + public static boolean update(final String recipient_id, final String body) throws Exception { + return Configuration.gateway().recipient.update(recipient_id, body); + } + + public static boolean delete(final String recipient_id) throws Exception { + return Configuration.gateway().recipient.delete(recipient_id); + } + + public static List search(final int page, final int pageSize, final String term) throws Exception { + return Configuration.gateway().recipient.search(page, pageSize, term); + } + + public static List search(final String message) throws Exception { + return search(1, 10, message); + } + + public static List search() throws Exception { + return search(1, 10, ""); + } + + public static List search(final int page, final int pageNumber) throws Exception { + return search(page, pageNumber, ""); + } +} diff --git a/src/main/java/com/trolley/trolley/RecipientAccount.java b/src/main/java/com/trolley/trolley/RecipientAccount.java new file mode 100644 index 0000000..e7d0648 --- /dev/null +++ b/src/main/java/com/trolley/trolley/RecipientAccount.java @@ -0,0 +1,237 @@ + +package com.trolley.trolley; + +import java.util.List; +import com.fasterxml.jackson.annotation.JsonInclude; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class RecipientAccount +{ + String type; + Boolean primary; + String currency; + String id; + String recipientId; + String recipientAccountId; + String routeType; + String recipientFees; + String country; + String iban; + String accountNum; + String accountHolderName; + String swiftBic; + String branchId; + String bankId; + String bankName; + String bankAddress; + String bankCity; + String bankRegionCode; + String bankPostalCode; + String emailAddress; + String status; + String disabledAt; + + public String getEmailAddress() { + return this.emailAddress; + } + + public void setEmailAddress(final String emailAddress) { + this.emailAddress = emailAddress; + } + + public String getDisabledAt() { + return this.disabledAt; + } + + public void setDisabledAt(final String disabledAt) { + this.disabledAt = disabledAt; + } + + public String getStatus() { + return this.status; + } + + public void setStatus(final String status) { + this.status = status; + } + + public String getRecipientId() { + return this.recipientId; + } + + public void setRecipientId(final String recipientId) { + this.recipientId = recipientId; + } + + public String getType() { + return this.type; + } + + public void setType(final String type) { + this.type = type; + } + + public Boolean getPrimary() { + return this.primary; + } + + public void setPrimary(final Boolean primary) { + this.primary = primary; + } + + public String getCurrency() { + return this.currency; + } + + public void setCurrency(final String currency) { + this.currency = currency; + } + + public String getId() { + return this.id; + } + + public void setId(final String id) { + this.id = id; + } + + public String getRecipientAccountId() { + return this.recipientAccountId; + } + + public void setRecipientAccountId(final String recipientAccountId) { + this.recipientAccountId = recipientAccountId; + } + + public String getRouteType() { + return this.routeType; + } + + public void setRouteType(final String routeType) { + this.routeType = routeType; + } + + public String getRecipientFees() { + return this.recipientFees; + } + + public void setRecipientFees(final String recipientFees) { + this.recipientFees = recipientFees; + } + + public String getCountry() { + return this.country; + } + + public void setCountry(final String country) { + this.country = country; + } + + public String getIban() { + return this.iban; + } + + public void setIban(final String iban) { + this.iban = iban; + } + + public String getAccountNum() { + return this.accountNum; + } + + public void setAccountNum(final String accountNum) { + this.accountNum = accountNum; + } + + public String getAccountHolderName() { + return this.accountHolderName; + } + + public void setAccountHolderName(final String accountHolderName) { + this.accountHolderName = accountHolderName; + } + + public String getSwiftBic() { + return this.swiftBic; + } + + public void setSwiftBic(final String swiftBic) { + this.swiftBic = swiftBic; + } + + public String getBranchId() { + return this.branchId; + } + + public void setBranchId(final String branchId) { + this.branchId = branchId; + } + + public String getBankId() { + return this.bankId; + } + + public void setBankId(final String bankId) { + this.bankId = bankId; + } + + public String getBankName() { + return this.bankName; + } + + public void setBankName(final String bankName) { + this.bankName = bankName; + } + + public String getBankAddress() { + return this.bankAddress; + } + + public void setBankAddress(final String bankAddress) { + this.bankAddress = bankAddress; + } + + public String getBankCity() { + return this.bankCity; + } + + public void setBankCity(final String bankCity) { + this.bankCity = bankCity; + } + + public String getBankRegionCode() { + return this.bankRegionCode; + } + + public void setBankRegionCode(final String bankRegionCode) { + this.bankRegionCode = bankRegionCode; + } + + public String getBankPostalCode() { + return this.bankPostalCode; + } + + public void setBankPostalCode(final String bankPostalCode) { + this.bankPostalCode = bankPostalCode; + } + + public static List findAll(final String recipient_id) throws Exception { + return Configuration.gateway().recipientAccount.findAll(recipient_id); + } + + public static RecipientAccount find(final String recipient_id, final String recipient_account_id) throws Exception { + return Configuration.gateway().recipientAccount.find(recipient_id, recipient_account_id); + } + + public static RecipientAccount create(final String recipient_id, final String body) throws Exception { + return Configuration.gateway().recipientAccount.create(recipient_id, body); + } + + public static RecipientAccount update(final String recipient_id, final String recipient_account_id, final String body) throws Exception { + return Configuration.gateway().recipientAccount.update(recipient_id, recipient_account_id, body); + } + + public static boolean delete(final String recipient_id, final String recipient_account_id) throws Exception { + return Configuration.gateway().recipientAccount.delete(recipient_id, recipient_account_id); + } +} diff --git a/src/main/java/com/trolley/trolley/RecipientAccountGateway.java b/src/main/java/com/trolley/trolley/RecipientAccountGateway.java new file mode 100644 index 0000000..1498645 --- /dev/null +++ b/src/main/java/com/trolley/trolley/RecipientAccountGateway.java @@ -0,0 +1,118 @@ + +package com.trolley.trolley; + +import java.util.ArrayList; +import java.io.IOException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.trolley.Exceptions.InvalidFieldException; +import java.util.List; + +public class RecipientAccountGateway +{ + Client client; + + public RecipientAccountGateway(final Configuration config) { + this.client = new Client(config); + } + + public List findAll(final String recipient_id) throws Exception { + if (recipient_id == null || recipient_id.isEmpty()) { + throw new InvalidFieldException("Recipient id cannot be null or empty."); + } + final String endPoint = "/v1/recipients/" + recipient_id + "/accounts"; + final String response = this.client.get(endPoint); + return this.recipientAccountListFactory(response); + } + + public RecipientAccount find(final String recipient_id, final String recipient_account_id) throws Exception { + if (recipient_id == null || recipient_id.isEmpty()) { + throw new InvalidFieldException("Recipient id cannot be null or empty."); + } + final String endPoint = "/v1/recipients/" + recipient_id + "/accounts/" + recipient_account_id; + final String response = this.client.get(endPoint); + return this.recipientAccountFactory(response); + } + + public RecipientAccount create(final String recipient_id, final String body) throws Exception { + if (recipient_id == null || recipient_id.isEmpty()) { + throw new InvalidFieldException("Recipient id cannot be null or empty."); + } + if (body == null || body.isEmpty()) { + throw new InvalidFieldException("Body cannot be null or empty"); + } + final String endPoint = "/v1/recipients/" + recipient_id + "/accounts"; + final String response = this.client.post(endPoint, body); + return this.recipientAccountFactory(response); + } + + public RecipientAccount create(final String recipient_id, final RecipientAccount account) throws Exception { + if (recipient_id == null || recipient_id.isEmpty()) { + throw new InvalidFieldException("Recipient id cannot be null or empty."); + } + if (account == null) { + throw new InvalidFieldException("Body cannot be null or empty"); + } + final String jsonAccount = new ObjectMapper().writeValueAsString((Object)account); + final String endPoint = "/v1/recipients/" + recipient_id + "/accounts"; + final String response = this.client.post(endPoint, jsonAccount); + return this.recipientAccountFactory(response); + } + + public RecipientAccount update(final String recipient_id, final String recipient_account_id, final String body) throws Exception { + if (recipient_id == null || recipient_id.isEmpty()) { + throw new InvalidFieldException("Recipient id cannot be null or empty."); + } + if (body == null || body.isEmpty()) { + throw new InvalidFieldException("Body cannot be null or empty"); + } + final String endPoint = "/v1/recipients/" + recipient_id + "/accounts/" + recipient_account_id; + final String response = this.client.patch(endPoint, body); + return this.recipientAccountFactory(response); + } + + public RecipientAccount update(final String recipient_id, final String recipient_account_id, final RecipientAccount account) throws Exception { + if (recipient_id == null || recipient_id.isEmpty()) { + throw new InvalidFieldException("Recipient id cannot be null or empty."); + } + if (account == null) { + throw new InvalidFieldException("Body cannot be null or empty"); + } + final String jsonAccount = new ObjectMapper().writeValueAsString((Object)account); + final String endPoint = "/v1/recipients/" + recipient_id + "/accounts/" + recipient_account_id; + final String response = this.client.patch(endPoint, jsonAccount); + return this.recipientAccountFactory(response); + } + + public boolean delete(final String recipient_id, final String recipient_account_id) throws Exception { + if (recipient_id == null || recipient_id.isEmpty()) { + throw new InvalidFieldException("Recipient id cannot be null or empty."); + } + final String endPoint = "/v1/recipients/" + recipient_id + "/accounts/" + recipient_account_id; + this.client.delete(endPoint); + return true; + } + + private RecipientAccount recipientAccountFactory(final String data) throws IOException { + final ObjectMapper mapper = new ObjectMapper(); + final JsonNode node = mapper.readTree(data); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + final RecipientAccount recipientAccount = (RecipientAccount)mapper.readValue(node.get("account").traverse(), (Class)RecipientAccount.class); + return recipientAccount; + } + + private List recipientAccountListFactory(final String data) throws IOException { + final ObjectMapper mapper = new ObjectMapper(); + final JsonNode node = mapper.readTree(data); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + final Object recipientAccount = mapper.readValue(node.get("accounts").traverse(), (Class)Object.class); + final List recipAccounts = (List)recipientAccount; + final List recipientAccounts = new ArrayList(); + for (int i = 0; i < recipAccounts.size(); ++i) { + final RecipientAccount pojo = (RecipientAccount)mapper.convertValue((Object)recipAccounts.get(i), (Class)RecipientAccount.class); + recipientAccounts.add(pojo); + } + return recipientAccounts; + } +} diff --git a/src/main/java/com/trolley/trolley/RecipientGateway.java b/src/main/java/com/trolley/trolley/RecipientGateway.java new file mode 100644 index 0000000..9da04a0 --- /dev/null +++ b/src/main/java/com/trolley/trolley/RecipientGateway.java @@ -0,0 +1,140 @@ + +package com.trolley.trolley; + +import java.io.IOException; +import com.fasterxml.jackson.databind.JsonNode; +import java.util.ArrayList; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.List; +import com.trolley.Exceptions.InvalidFieldException; + +public class RecipientGateway +{ + Client client; + + public RecipientGateway(final Configuration config) { + this.client = new Client(config); + } + + public Recipient find(final String recipient_id) throws Exception { + if (recipient_id == null || recipient_id.isEmpty()) { + throw new InvalidFieldException("Recipient id cannot be null or empty."); + } + final String endPoint = "/v1/recipients/" + recipient_id; + final String response = this.client.get(endPoint); + return this.recipientFactory(response); + } + + public String findLogs(final String recipient_id) throws Exception { + final String endPoint = "/v1/recipients/" + recipient_id + "/logs"; + final String response = this.client.get(endPoint); + return response; + } + + public List findPayments(final String recipient_id) throws Exception { + final String endPoint = "/v1/recipients/" + recipient_id + "/payments"; + final String response = this.client.get(endPoint); + final ObjectMapper mapper = new ObjectMapper(); + final JsonNode node = mapper.readTree(response); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + final Object payment = mapper.readValue(node.get("payments").traverse(), (Class)Object.class); + final List paymens = (List)payment; + final List payments = new ArrayList(); + for (int i = 0; i < paymens.size(); ++i) { + final Payment pojo = (Payment)mapper.convertValue((Object)paymens.get(i), (Class)Payment.class); + payments.add(pojo); + } + return payments; + } + + public Recipient create(final String body) throws Exception { + if (body == null || body.isEmpty()) { + throw new InvalidFieldException("Body cannot be null or empty"); + } + final String endPoint = "/v1/recipients/"; + final String response = this.client.post(endPoint, body); + return this.recipientFactory(response); + } + + public Recipient create(final Recipient recipient) throws Exception { + if (recipient == null) { + throw new InvalidFieldException("Body cannot be null or empty"); + } + final String jsonRecipient = new ObjectMapper().writeValueAsString((Object)recipient); + final String endPoint = "/v1/recipients/"; + final String response = this.client.post(endPoint, jsonRecipient); + return this.recipientFactory(response); + } + + public boolean update(final String recipient_id, final String body) throws Exception { + if (recipient_id == null || recipient_id.isEmpty()) { + throw new InvalidFieldException("Recipient id cannot be null or empty."); + } + if (body == null || body.isEmpty()) { + throw new InvalidFieldException("Body cannot be null or empty"); + } + final String endPoint = "/v1/recipients/" + recipient_id; + this.client.patch(endPoint, body); + return true; + } + + public boolean update(final String recipient_id, final Recipient recipient) throws Exception { + if (recipient_id == null || recipient_id.isEmpty()) { + throw new InvalidFieldException("Recipient id cannot be null or empty."); + } + if (recipient == null) { + throw new InvalidFieldException("Body cannot be null or empty"); + } + final String jsonRecipient = new ObjectMapper().writeValueAsString((Object)recipient); + final String endPoint = "/v1/recipients/" + recipient_id; + this.client.patch(endPoint, jsonRecipient); + return true; + } + + public boolean delete(final String recipient_id) throws Exception { + if (recipient_id == null || recipient_id.isEmpty()) { + throw new InvalidFieldException("Recipient id cannot be null or empty."); + } + final String endPoint = "/v1/recipients/" + recipient_id; + this.client.delete(endPoint); + return true; + } + + public List search(final int page, final int pageSize, final String term) throws Exception { + if (page < 0) { + throw new InvalidFieldException("Page cannot be less than 0"); + } + if (pageSize < 0) { + throw new InvalidFieldException("Page size cannot be less than 0"); + } + if (term == null) { + throw new InvalidFieldException("Message cannot be null"); + } + final String endPoint = "/v1/recipients/?&search=" + term + "&page=" + page + "&pageSize=" + pageSize; + final String response = this.client.get(endPoint); + return this.recipientListFactory(response); + } + + private Recipient recipientFactory(final String data) throws IOException { + final ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + final JsonNode node = mapper.readTree(data); + final Recipient recipient = (Recipient)mapper.readValue(node.get("recipient").traverse(), (Class)Recipient.class); + return recipient; + } + + private List recipientListFactory(final String data) throws IOException { + final ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + final JsonNode node = mapper.readTree(data); + final Object recipient = mapper.readValue(node.get("recipients").traverse(), (Class)Object.class); + final List recips = (List)recipient; + final List recipients = new ArrayList(); + for (int i = 0; i < recips.size(); ++i) { + final Recipient pojo = (Recipient)mapper.convertValue((Object)recips.get(i), (Class)Recipient.class); + recipients.add(pojo); + } + return recipients; + } +} diff --git a/src/main/java/ca/paymentrails/paymentrails/Total.java b/src/main/java/com/trolley/trolley/Total.java similarity index 71% rename from src/main/java/ca/paymentrails/paymentrails/Total.java rename to src/main/java/com/trolley/trolley/Total.java index ef7e67b..48aadc1 100644 --- a/src/main/java/ca/paymentrails/paymentrails/Total.java +++ b/src/main/java/com/trolley/trolley/Total.java @@ -1,10 +1,11 @@ -package ca.paymentrails.paymentrails; -public class Total { +package com.trolley.trolley; +public class Total +{ public Integer count; public String totalFees; public String merchantFees; public String debitAmount; public String sendingAmount; -} \ No newline at end of file +} diff --git a/src/main/java/ca/paymentrails/paymentrails/USD.java b/src/main/java/com/trolley/trolley/USD.java similarity index 51% rename from src/main/java/ca/paymentrails/paymentrails/USD.java rename to src/main/java/com/trolley/trolley/USD.java index 2976037..80cd1c3 100644 --- a/src/main/java/ca/paymentrails/paymentrails/USD.java +++ b/src/main/java/com/trolley/trolley/USD.java @@ -1,59 +1,60 @@ -package ca.paymentrails.paymentrails; -public class USD { +package com.trolley.trolley; +public class USD +{ private Boolean primary; private String amount; private String currency; private String type; private String accountNumber; private Boolean display; - + public Boolean getPrimary() { - return primary; + return this.primary; } - - public void setPrimary(Boolean primary) { + + public void setPrimary(final Boolean primary) { this.primary = primary; } - + public String getAmount() { - return amount; + return this.amount; } - - public void setAmount(String amount) { + + public void setAmount(final String amount) { this.amount = amount; } - + public String getCurrency() { - return currency; + return this.currency; } - - public void setCurrency(String currency) { + + public void setCurrency(final String currency) { this.currency = currency; } - + public String getType() { - return type; + return this.type; } - - public void setType(String type) { + + public void setType(final String type) { this.type = type; } - + public String getAccountNumber() { - return accountNumber; + return this.accountNumber; } - - public void setAccountNumber(String accountNumber) { + + public void setAccountNumber(final String accountNumber) { this.accountNumber = accountNumber; } - + public Boolean getDisplay() { - return display; + return this.display; } - - public void setDisplay(Boolean display) { + + public void setDisplay(final Boolean display) { this.display = display; } -} \ No newline at end of file +} diff --git a/src/main/java/com/trolley/trolley/Version.java b/src/main/java/com/trolley/trolley/Version.java new file mode 100644 index 0000000..dd9a28f --- /dev/null +++ b/src/main/java/com/trolley/trolley/Version.java @@ -0,0 +1,10 @@ +package com.trolley.trolley; + +/** + * Public class provide SemVer information + */ +public class Version { + public static int MAJOR = 1; + public static int MINOR = 1; + public static int PATCH = 0; +} diff --git a/src/main/java/com/trolley/trolley/types/Amount.java b/src/main/java/com/trolley/trolley/types/Amount.java new file mode 100644 index 0000000..0952e82 --- /dev/null +++ b/src/main/java/com/trolley/trolley/types/Amount.java @@ -0,0 +1,31 @@ +package com.trolley.trolley.types; + +public class Amount { + + private String value; + private String currency; + + public Amount(){ + } + + public Amount(String value, String currency){ + this.value = value; + this.currency = currency; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getCurrency() { + return currency; + } + + public void setCurrency(String currency) { + this.currency = currency; + } +} diff --git a/src/main/java/com/trolley/trolley/types/InvoicePaymentPart.java b/src/main/java/com/trolley/trolley/types/InvoicePaymentPart.java new file mode 100644 index 0000000..dfb76ab --- /dev/null +++ b/src/main/java/com/trolley/trolley/types/InvoicePaymentPart.java @@ -0,0 +1,50 @@ +package com.trolley.trolley.types; + +public class InvoicePaymentPart{ + private String invoiceId; + private String invoiceLineId; + private String paymentId; + private Amount amount; + + public InvoicePaymentPart() { + } + + public InvoicePaymentPart(String invoiceId, String invoiceLineId, String paymentId, Amount amount) { + this.invoiceId = invoiceId; + this.invoiceLineId = invoiceLineId; + this.paymentId = paymentId; + this.amount = amount; + } + + public String getInvoiceId() { + return invoiceId; + } + + public void setInvoiceId(String invoiceId) { + this.invoiceId = invoiceId; + } + + public String getInvoiceLineId() { + return invoiceLineId; + } + + public void setInvoiceLineId(String invoiceLineId) { + this.invoiceLineId = invoiceLineId; + } + + public String getPaymentId() { + return paymentId; + } + + public void setPaymentId(String paymentId) { + this.paymentId = paymentId; + } + + public Amount getAmount() { + return amount; + } + + public void setAmount(Amount amount) { + this.amount = amount; + } +} \ No newline at end of file diff --git a/src/main/java/com/trolley/trolley/types/InvoicePayments.java b/src/main/java/com/trolley/trolley/types/InvoicePayments.java new file mode 100644 index 0000000..b7eff2b --- /dev/null +++ b/src/main/java/com/trolley/trolley/types/InvoicePayments.java @@ -0,0 +1,30 @@ +package com.trolley.trolley.types; + +import java.util.List; + +public class InvoicePayments { + + private List invoicePaymentParts; + private Meta meta; + + public InvoicePayments(List invoicePaymentParts, Meta meta) { + this.invoicePaymentParts = invoicePaymentParts; + this.meta = meta; + } + + public List getInvoicePaymentParts() { + return this.invoicePaymentParts; + } + + public void setInvoicePaymentParts(final List invoicePaymentParts) { + this.invoicePaymentParts = invoicePaymentParts; + } + + public Meta getMeta() { + return this.meta; + } + + public void setMeta(final Meta meta) { + this.meta = meta; + } +} diff --git a/src/main/java/com/trolley/trolley/types/Invoices.java b/src/main/java/com/trolley/trolley/types/Invoices.java new file mode 100644 index 0000000..570f862 --- /dev/null +++ b/src/main/java/com/trolley/trolley/types/Invoices.java @@ -0,0 +1,32 @@ +package com.trolley.trolley.types; + +import java.util.List; + +import com.trolley.trolley.Invoice; + +public class Invoices { + + private List invoices; + private Meta meta; + + public Invoices(List invoices, Meta meta) { + this.invoices = invoices; + this.meta = meta; + } + + public List getInvoices() { + return this.invoices; + } + + public void setInvoices(final List invoices) { + this.invoices = invoices; + } + + public Meta getMeta() { + return this.meta; + } + + public void setMeta(final Meta meta) { + this.meta = meta; + } +} diff --git a/src/main/java/com/trolley/trolley/types/Meta.java b/src/main/java/com/trolley/trolley/types/Meta.java new file mode 100644 index 0000000..439c90f --- /dev/null +++ b/src/main/java/com/trolley/trolley/types/Meta.java @@ -0,0 +1,41 @@ +package com.trolley.trolley.types; + +public class Meta +{ + private int page; + private int pages; + private int records; + + public Meta() { + } + + public Meta(int page, int pages, int records) { + this.page = page; + this.pages = pages; + this.records = records; + } + + public int getPage() { + return this.page; + } + + public void setPage(final int page) { + this.page = page; + } + + public int getPages() { + return this.pages; + } + + public void setPages(final int pages) { + this.pages = pages; + } + + public int getRecords() { + return this.records; + } + + public void setRecords(final int records) { + this.records = records; + } +} diff --git a/src/test/java/ca/paymentrails/paymentrails/integration/BatchTest.java b/src/test/java/ca/paymentrails/paymentrails/integration/BatchTest.java deleted file mode 100644 index 302fa83..0000000 --- a/src/test/java/ca/paymentrails/paymentrails/integration/BatchTest.java +++ /dev/null @@ -1,144 +0,0 @@ - -package ca.paymentrails.paymentrails.integration; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.util.UUID; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.powermock.core.classloader.annotations.PrepareForTest; - -import ca.paymentrails.paymentrails.Batch; -import ca.paymentrails.paymentrails.BatchSummary; -import ca.paymentrails.paymentrails.Configuration; -import ca.paymentrails.paymentrails.Gateway; -import ca.paymentrails.paymentrails.Payment; -import ca.paymentrails.paymentrails.Recipient; - -@PrepareForTest(Recipient.class) -public class BatchTest { - - private static Configuration config; - - @BeforeClass - public static void setupConfig() { - final String ACCESS_KEY = "YourAccessKey"; - final String SECRET_KEY = "YourSecretKey"; - final String ENVIRONMENT = "production"; - - // RecipientTest recipientTest = new RecipientTest(); - config = new Configuration(ACCESS_KEY, SECRET_KEY, ENVIRONMENT); - } - - - private Recipient createRecipient() throws Exception { - Gateway client = new Gateway(config); - - UUID uuid = UUID.randomUUID(); - - String email = "\"create.recipient" + uuid.toString() + "@example.com\""; - String body = "{\"type\": \"individual\",\"firstName\": \"John\",\"lastName\": \"Smith\",\"email\":" + email - + ",\"address\":{\"street1\": \"123 Main St\",\"city\": \"San Francisco\",\"region\": \"CA\",\"postalCode\": \"94131\",\"country\": \"DE\",\"phone\" : \"18005551212\"}}"; - - Recipient recipient = client.recipient.create(body); - - body = "{\"type\": \"bank-transfer\", \"primary\": true, \"country\": \"DE\", \"currency\": \"EUR\", \"iban\": \"DE89 3704 0044 0532 0130 00\", \"accountHolderName\": \"John Smith\"}"; - - client.recipientAccount.create(recipient.getId(), body); - - return recipient; - } - - @Test - public void testCreate() throws Exception { - Gateway client = new Gateway(config); - - String body = "{\"sourceCurrency\": \"GBP\", \"description\":\"Integration Test Create\"}"; - Batch batch = client.batch.create(body); - assertEquals(batch.getCurrency(), "GBP"); - } - - @Test - public void testUpdate() throws Exception { - Gateway client = new Gateway(config); - - String body = "{\"sourceCurrency\": \"GBP\", \"description\":\"Integration Test Create\"}"; - Batch batch = client.batch.create(body); - assertEquals(batch.getCurrency(), "GBP"); - - body = "{\"description\" : \"Integration Update\"}"; - boolean response = client.batch.update(batch.getId(), body); - assertNotNull(response); - - Batch batch1 = client.batch.find(batch.getId()); - assertEquals(batch1.getDescription(), "Integration Update"); - - response = client.batch.delete(batch1.getId()); - assertNotNull(response); - } - - @Test - public void testCreateWithPayments() throws Exception { - Gateway client = new Gateway(config); - - Recipient recipientAlpha = createRecipient(); - - String body = "{\"payments\": [{\"recipient\": {\"id\": " + "\"" + recipientAlpha.getId() + "\"" - + "},\"amount\": \"10.00\", \"currency\": \"EUR\"}]}"; - Batch batch = client.batch.create(body); - - assertNotNull(batch); - assertNotNull(batch.getId()); - - Batch batch1 = client.batch.find(batch.getId()); - assertNotNull(batch1); - - assertEquals(1, batch1.getPayments().getPayments().size()); - } - - @Test - public void testPayments() throws Exception { - Gateway client = new Gateway(config); - - String body = "{\"sourceCurrency\": \"GBP\", \"description\":\"Integration Test Create\"}"; - Batch batch = client.batch.create(body); - assertEquals(batch.getCurrency(), "GBP"); - - Recipient recipient = createRecipient(); - body = "{\"sourceAmount\":\"10.00\", \"recipient\": {\"id\": " + "\"" + recipient.getId() + "\"" + "}}"; - Payment payment = client.payment.create(body, batch.getId()); - assertNotNull(payment); - assertNotNull(payment.getId()); - body = "{\"sourceAmount\":\"20.00\"}"; - boolean response = client.payment.update(payment.getId(), body, batch.getId()); - assertNotNull(response); - - response = client.payment.delete(payment.getId(), batch.getId()); - assertNotNull(response); - } - - @Test - public void testProcessing() throws Exception { - Gateway client = new Gateway(config); - - Recipient recipientAlpha = createRecipient(); - - String body = "{\"payments\": [{\"recipient\": {\"id\": " + "\"" + recipientAlpha.getId() + "\"" - + "},\"amount\": \"10.00\", \"currency\": \"EUR\"}]}"; - - Batch batch = client.batch.create(body); - assertNotNull(batch); - assertNotNull(batch.getId()); - - BatchSummary batchSummary = client.batch.summary(batch.getId()); - assertNotNull(batchSummary); - - String batch1 = client.batch.generateQuote(batch.getId()); - assertNotNull(batch1); - String batch2 = client.batch.processBatch(batch.getId()); - assertNotNull(batch2); - - } -} \ No newline at end of file diff --git a/src/test/java/ca/paymentrails/paymentrails/integration/RecipientTest.java b/src/test/java/ca/paymentrails/paymentrails/integration/RecipientTest.java deleted file mode 100644 index f9d770e..0000000 --- a/src/test/java/ca/paymentrails/paymentrails/integration/RecipientTest.java +++ /dev/null @@ -1,126 +0,0 @@ - -package ca.paymentrails.paymentrails.integration; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.powermock.core.classloader.annotations.PrepareForTest; - -import ca.paymentrails.paymentrails.Configuration; -import ca.paymentrails.paymentrails.Recipient; -import ca.paymentrails.paymentrails.RecipientAccount; -import ca.paymentrails.paymentrails.Gateway; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -@PrepareForTest(Recipient.class) -public class RecipientTest { - - // Testing order: alphabetical - - private static Configuration config; - - @BeforeClass - public static void setupConfig() { - final String ACCESS_KEY = "YourAccessKey"; - final String SECRET_KEY = "YourSecretKey"; - final String ENVIRONMENT = "production"; - - // RecipientTest recipientTest = new RecipientTest(); - config = new Configuration(ACCESS_KEY, SECRET_KEY, ENVIRONMENT); - } - - @Test - public void testCreateRecipient() throws Exception { - Gateway client = new Gateway(config); - - UUID uuid = UUID.randomUUID(); - - String body = "{\"type\": \"individual\",\"firstName\": \"Tom\",\"lastName\": \"Jones\",\"email\": \"test.create" - + uuid.toString() - + "@example.com\",\"address\":{\"street1\": \"123 Main St\",\"city\": \"San Francisco\",\"region\": \"CA\",\"postalCode\": \"94131\",\"country\": \"US\",\"phone\" : \"18005551212\"}}"; - Recipient recipient = client.recipient.create(body); - assertEquals(recipient.getFirstName(), "Tom"); - assertEquals(recipient.getLastName(), "Jones"); - assertEquals(recipient.getEmail(), "test.create" + uuid.toString() + "@example.com"); - assertNotNull(recipient.getId()); - } - - @Test - public void testLifecycle() throws Exception { - Gateway client = new Gateway(config); - - UUID uuid = UUID.randomUUID(); - - String body = "{\"type\": \"individual\",\"firstName\": \"Tom\",\"lastName\": \"Jones\",\"email\": \"test.create" - + uuid.toString() + "@example.com\"}"; - Recipient recipient = client.recipient.create(body); - assertEquals(recipient.getFirstName(), "Tom"); - assertEquals(recipient.getLastName(), "Jones"); - assertEquals(recipient.getEmail(), "test.create" + uuid.toString() + "@example.com"); - assertNotNull(recipient.getId()); - - body = "{\"firstName\": \"Bob\"}"; - boolean response = client.recipient.update(recipient.getId(), body); - assertNotNull(response); - - Recipient anotherRecipient = client.recipient.find(recipient.getId()); - assertEquals(anotherRecipient.getFirstName(), "Bob"); - - response = client.recipient.delete(recipient.getId()); - assertNotNull(response); - - Recipient anotherNewRecipient = client.recipient.find(recipient.getId()); - assertEquals("archived", anotherNewRecipient.getStatus()); - } - - @Test - public void testRecipientAccount() throws Exception { - Gateway client = new Gateway(config); - - UUID uuid = UUID.randomUUID(); - - String body = "{\"type\": \"individual\",\"firstName\": \"Tom\",\"lastName\": \"Jones\",\"email\": \"account.create" - + uuid.toString() + "@example.com\"}"; - Recipient recipient = client.recipient.create(body); - assertEquals(recipient.getFirstName(), "Tom"); - assertEquals(recipient.getLastName(), "Jones"); - assertEquals(recipient.getEmail(), "account.create" + uuid.toString() + "@example.com"); - assertNotNull(recipient.getId()); - - body = "{\"type\": \"bank-transfer\", \"primary\": true, \"country\": \"DE\", \"currency\": \"EUR\", \"iban\": \"DE89 3704 0044 0532 0130 00\", \"accountHolderName\": \"Tom Jones\"}"; - RecipientAccount recipientAccount = client.recipientAccount.create(recipient.getId(), body); - assertEquals("Tom Jones", recipientAccount.getAccountHolderName()); - - body = "{\"type\": \"bank-transfer\", \"primary\": true, \"country\": \"DE\", \"currency\": \"EUR\", \"iban\": \"DE89 3704 0044 0532 0130 00\", \"accountHolderName\": \"Tom Jones2\"}"; - RecipientAccount recipientAccount1 = client.recipientAccount.create(recipient.getId(), body); - assertEquals("Tom Jones2", recipientAccount1.getAccountHolderName()); - - RecipientAccount recipAccount = client.recipientAccount.find(recipient.getId(), recipientAccount.getId()); - assertEquals(recipAccount.getCountry(), recipientAccount.getCountry()); - - List recipientAccounts = client.recipientAccount.findAll(recipient.getId()); - assertEquals(2, recipientAccounts.size()); - - boolean response = client.recipientAccount.delete(recipient.getId(), recipientAccount1.getId()); - assertNotNull(response); - - List recipientAccounts1 = client.recipientAccount.findAll(recipient.getId()); - assertEquals(1, recipientAccounts1.size()); - } - - @Test - public void testRecipientRouteMinimum() throws Exception { - Gateway client = new Gateway(config); - ArrayList recipients = (ArrayList)client.recipient.search(1,20,""); - //Making sure routeMinimum is not null before asserting it's value - assertNotNull(recipients.get(0).getRouteMinimum()); - //Making sure routeMinium is set to a non-null value - assertTrue(Integer.parseInt(recipients.get(0).getRouteMinimum()) >= 0); - } -} \ No newline at end of file diff --git a/src/test/java/com/trolley/sdk/integration/BatchTest.java b/src/test/java/com/trolley/sdk/integration/BatchTest.java new file mode 100644 index 0000000..75b1b50 --- /dev/null +++ b/src/test/java/com/trolley/sdk/integration/BatchTest.java @@ -0,0 +1,185 @@ + +package com.trolley.sdk.integration; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import com.trolley.trolley.Batch; +import com.trolley.trolley.BatchSummary; +import com.trolley.trolley.Configuration; +import com.trolley.trolley.Gateway; +import com.trolley.trolley.Payment; +import com.trolley.trolley.Payments; +import com.trolley.trolley.Recipient; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.powermock.core.classloader.annotations.PrepareForTest; + +@PrepareForTest(Batch.class) +public class BatchTest { + + private static Configuration config; + private static TestHelper testHelper; + + @BeforeClass + public static void setupConfig() { + config = TestHelper.getConfig(); + testHelper = new TestHelper(); + } + + @Test + public void testCreate() throws Exception { + Gateway client = new Gateway(config); + + String body = "{\"sourceCurrency\": \"GBP\", \"description\":\"Integration Test Create\"}"; + Batch batch = client.batch.create(body); + assertEquals(batch.getCurrency(), "GBP"); + + //Cleanup + boolean deleteResult = client.batch.delete(batch.getId()); + assertTrue(deleteResult); + } + + @Test + public void testCreateObject() throws Exception { + Gateway client = new Gateway(config); + + Batch batchToCreate = new Batch(); + batchToCreate.setCurrency("GBP"); + batchToCreate.setDescription("Integration Test Create"); + + Batch createdBatch = client.batch.create(batchToCreate); + assertEquals(createdBatch.getCurrency(), "GBP"); + assertEquals(createdBatch.getDescription(), "Integration Test Create"); + + //Cleanup + boolean deleteResult = client.batch.delete(createdBatch.getId()); + assertTrue(deleteResult); + } + + @Test + public void testUpdate() throws Exception { + Gateway client = new Gateway(config); + + String body = "{\"sourceCurrency\": \"GBP\", \"description\":\"Integration Test Create\"}"; + Batch batch = client.batch.create(body); + assertEquals(batch.getCurrency(), "GBP"); + + body = "{\"description\" : \"Integration Update\"}"; + boolean response = client.batch.update(batch.getId(), body); + assertNotNull(response); + + Batch batch1 = client.batch.find(batch.getId()); + assertEquals(batch1.getDescription(), "Integration Update"); + + //Cleanup + response = client.batch.delete(batch1.getId()); + assertNotNull(response); + } + + @Test + public void testCreateWithPayments() throws Exception { + Gateway client = new Gateway(config); + + Recipient recipientAlpha = testHelper.createRecipient(); + Payment payment = new Payment(); + + payment.setAmount("15"); + payment.setCurrency("USD"); + payment.setRecipient(recipientAlpha); + + List paymentList = new ArrayList(); + paymentList.add(payment); + + Payments payments = new Payments(); + payments.setPayments(paymentList); + + Batch batchToCreate = new Batch(); + batchToCreate.setPayments(paymentList); + + Batch batch = client.batch.create(batchToCreate); + + assertNotNull(batch); + assertNotNull(batch.getId()); + + List batchPayments = batch.getPayments(); + assertEquals(1, batchPayments.size()); + + assertEquals("15.00", batchPayments.get(0).getAmount()); + assertEquals("USD", batchPayments.get(0).getCurrency()); + + //Cleanup + boolean recDelResult = testHelper.deleteRecipient(recipientAlpha); + assertTrue(recDelResult); + + boolean batchDelResult = client.batch.delete(batch.getId()); + assertTrue(batchDelResult); + } + + @Test + public void testPayments() throws Exception { + Gateway client = new Gateway(config); + + String body = "{\"sourceCurrency\": \"GBP\", \"description\":\"Integration Test Create\"}"; + Batch batch = client.batch.create(body); + assertEquals(batch.getCurrency(), "GBP"); + + Recipient recipient = testHelper.createRecipient(); + body = "{\"sourceAmount\":\"10.00\", \"recipient\": {\"id\": " + "\"" + recipient.getId() + "\"" + "}}"; + Payment payment = client.payment.create(body, batch.getId()); + assertNotNull(payment); + assertNotNull(payment.getId()); + body = "{\"sourceAmount\":\"20.00\"}"; + boolean response = client.payment.update(payment.getId(), body, batch.getId()); + assertNotNull(response); + + response = client.payment.delete(payment.getId(), batch.getId()); + assertNotNull(response); + + //Cleanup + boolean recDelResult = testHelper.deleteRecipient(recipient); + assertTrue(recDelResult); + + boolean batchDelResult = client.batch.delete(batch.getId()); + assertTrue(batchDelResult); + } + + @Test + public void testProcessing() throws Exception { + Gateway client = new Gateway(config); + + Recipient recipientAlpha = testHelper.createRecipient(); + + String body = "{\"payments\": [{\"recipient\": {\"id\": " + "\"" + recipientAlpha.getId() + "\"" + + "},\"amount\": \"10.00\", \"currency\": \"EUR\"}]}"; + + Batch batch = client.batch.create(body); + assertNotNull(batch); + assertNotNull(batch.getId()); + + BatchSummary batchSummary = client.batch.summary(batch.getId()); + assertNotNull(batchSummary); + + try{ + String batch1 = client.batch.generateQuote(batch.getId()); + assertNotNull(batch1); + + String batch2 = client.batch.processBatch(batch.getId()); + assertNotNull(batch2); + }catch(Exception e){ + e.printStackTrace(); + } + + //Cleanup + boolean recDelResult = testHelper.deleteRecipient(recipientAlpha); + assertTrue(recDelResult); + + boolean batchDelResult = client.batch.delete(batch.getId()); + assertTrue(batchDelResult); + } +} \ No newline at end of file diff --git a/src/test/java/com/trolley/sdk/integration/InvoiceTests.java b/src/test/java/com/trolley/sdk/integration/InvoiceTests.java new file mode 100644 index 0000000..500a7b5 --- /dev/null +++ b/src/test/java/com/trolley/sdk/integration/InvoiceTests.java @@ -0,0 +1,283 @@ + +package com.trolley.sdk.integration; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import com.trolley.trolley.Invoice; +import com.trolley.trolley.InvoiceLine; +import com.trolley.trolley.InvoicePayment; +import com.trolley.trolley.Configuration; +import com.trolley.trolley.Gateway; +import com.trolley.trolley.Recipient; +import com.trolley.trolley.types.Amount; +import com.trolley.trolley.types.InvoicePaymentPart; +import com.trolley.trolley.types.InvoicePayments; +import com.trolley.trolley.types.Invoices; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.powermock.core.classloader.annotations.PrepareForTest; + +@PrepareForTest(Invoice.class) +public class InvoiceTests { + + private static Configuration config; + private static TestHelper testHelper; + + @BeforeClass + public static void setupConfig() { + config = TestHelper.getConfig(); + testHelper = new TestHelper(); + } + + @Test + public void testInvoices() throws Exception { + Gateway client = new Gateway(config); + final Recipient recipient = testHelper.createRecipient(); + + InvoiceLine invoiceLine = new InvoiceLine(); + invoiceLine.setUnitAmount(new Amount("100", "USD")); + + ArrayList invoiceLines = new ArrayList(){ + { + add(invoiceLine); + } + }; + + // Create a new invoice + Invoice invoice = client.invoice.create(new Invoice( + recipient.getId(), + "invoice-123", + "test-invoice-create-java-sdk", + "ext-id-"+System.currentTimeMillis(), + null, + null, + null, + invoiceLines)); + assertEquals(invoice.getRecipientId(), recipient.getId()); + + //Update an Invoice + final Invoice updatedInvoice = client.invoice.update( + invoice.getId(), + new Invoice( + null, + "invoice-123", + "test-invoice-update-java-sdk", + null, + null, + null, + null, + null + )); + assertEquals(updatedInvoice.getDescription(),"test-invoice-update-java-sdk"); + assertEquals(updatedInvoice.getId(),invoice.getId()); + + //Fetch an Invoice + invoice = client.invoice.fetch(updatedInvoice.getId()); + assertEquals(updatedInvoice.getId(),invoice.getId()); + + //Search for Invoices by recipientId - preparing params + ArrayList recipientIds = new ArrayList(){ + { + add(recipient.getId()); + } + }; + + // Search for Invoices by recipientId with pagination + Invoices invoices = client.invoice.search(Invoice.SearchBy.RECIPIENT_ID, recipientIds, null,1,2); + List invoiceList = invoices.getInvoices(); + assertEquals(invoiceList.get(0).getRecipientId(),invoice.getRecipientId()); + assertTrue(invoices.getMeta().getPages()>1); + + //Cleanup - Delete Recipient + boolean recDelResult = testHelper.deleteRecipient(recipient); + assertTrue(recDelResult); + + //Delete an Invoice + boolean invoiceDelResult = client.invoice.delete(invoice.getId()); + assertTrue(invoiceDelResult); + } + + @Test + public void testInvoiceLines() throws Exception { + Gateway client = new Gateway(config); + + //Setup - create recipient + final Recipient recipient = testHelper.createRecipient(); + + //Setup - create Invoice + Invoice invoice = client.invoice.create(new Invoice( + recipient.getId(), + "invoice-123", + "test-invoice-create-java-sdk", + "ext-id-"+System.currentTimeMillis(), + null, + null, + null, + null)); + assertEquals(invoice.getRecipientId(), recipient.getId()); + + //Add a new Invoice Line to the Invoice just created + Invoice invoiceWithLines = client.invoiceLine.create(invoice.getId(), + new InvoiceLine( + new Amount("100", "USD"), + InvoiceLine.InvoiceCategories.SERVICES, + "Invoice Line from Java SDK", + "ILine-ExtId-"+System.currentTimeMillis(), + true, + true, + null, + "2", + new Amount("10", "USD"), + new Amount("5", "USD"), + null, + null)); + assertEquals(invoiceWithLines.getLines().get(0).getUnitAmount().getValue(), "100.00"); + + //Add multiple new Invoice Lines to the Invoice created + List invoiceLines = new ArrayList(); + for (int i=1 ; i<=3; i++){ + invoiceLines.add(new InvoiceLine( + new Amount("10"+i, "USD"), + InvoiceLine.InvoiceCategories.SERVICES, + "Invoice Line from Java SDK", + "ILine-ExtId-"+System.currentTimeMillis()+"-"+i, + true, + true, + null, + "2", + new Amount("1"+i, "USD"), + new Amount("5", "USD"), + null, + null)); + } + + invoiceWithLines = client.invoiceLine.create(invoice.getId(), + invoiceLines); + assertEquals(invoiceWithLines.getLines().size(),4); + + //Update an invoice line + InvoiceLine lineToUpdate = invoiceWithLines.getLines().get(0); + lineToUpdate.setInvoiceLineId(lineToUpdate.getId()); + lineToUpdate.setUnitAmount(new Amount("500","USD")); + invoiceWithLines = client.invoiceLine.update(invoice.getId(), + lineToUpdate); + assertEquals(invoiceWithLines.getLines().get(0).getUnitAmount().getValue(),"500.00"); + + //Update multiple invoice lines + ArrayList linesToUpdate = new ArrayList(); + for (InvoiceLine invoiceLine : invoiceWithLines.getLines()) { + invoiceLine.setInvoiceLineId(invoiceLine.getId()); + invoiceLine.setUnitAmount(new Amount("350","USD")); + linesToUpdate.add(invoiceLine); + } + invoiceWithLines = client.invoiceLine.update(invoice.getId(), + linesToUpdate); + assertEquals(invoiceWithLines.getLines().size(),4); + assertEquals(invoiceWithLines.getLines().get(3).getUnitAmount().getValue(),"350.00"); + + //Delete an invoice line + boolean delete = client.invoiceLine.delete(invoiceWithLines.getId(), invoiceWithLines.getLines().get(0).getId()); + assertTrue(delete); + + //Refreshing invoice object + invoiceWithLines = client.invoice.fetch(invoiceWithLines.getId()); + + //Delete multiple invoice lines + ArrayList lineIdsToDel = new ArrayList(); + for (InvoiceLine line : invoiceWithLines.getLines()) { + lineIdsToDel.add(line.getId()); + } + boolean deleteMultiple = client.invoiceLine.delete(invoiceWithLines.getId(), lineIdsToDel); + assertTrue(deleteMultiple); + + // Assert that all lines were deleted + invoiceWithLines = client.invoice.fetch(invoiceWithLines.getId()); + assertTrue(invoiceWithLines.getLines().size() == 0); + + //Cleanup - delete invoice + boolean invoiceDelResult = client.invoice.delete(invoice.getId()); + assertTrue(invoiceDelResult); + + //Cleanup - delete recipient + boolean recDelResult = testHelper.deleteRecipient(recipient); + assertTrue(recDelResult); + } + + @Test + public void testInvoicePayments() throws Exception { + Gateway client = new Gateway(config); + //Setup - Recipient + final Recipient recipient = testHelper.createRecipient(); + + //Setup - Invoice Line + InvoiceLine invoiceLine = new InvoiceLine(); + invoiceLine.setUnitAmount(new Amount("100", "USD")); + + ArrayList invoiceLines = new ArrayList(){ + { + add(invoiceLine); + } + }; + + //Setup - Invoice + Invoice invoice = client.invoice.create(new Invoice( + recipient.getId(), + "invoice-123", + "test-invoice-create-java-sdk", + "ext-id-"+System.currentTimeMillis(), + null, + null, + null, + invoiceLines)); + assertEquals(invoice.getRecipientId(), recipient.getId()); + + //Create a new Invoice Payment + InvoicePaymentPart paymentPart = new InvoicePaymentPart(); + paymentPart.setInvoiceId(invoice.getId()); + paymentPart.setInvoiceLineId(invoice.getLines().get(0).getId()); + paymentPart.setAmount(new Amount("50", "USD")); + + InvoicePayment invoicePayment = client.invoicePayment.create(null, paymentPart); + + assertTrue(invoicePayment.getInvoicePayments().size()>0); + + // Update an invoice payment + paymentPart = new InvoicePaymentPart(); + paymentPart.setInvoiceId(invoice.getId()); + paymentPart.setInvoiceLineId(invoice.getLines().get(0).getId()); + paymentPart.setPaymentId(invoicePayment.getPaymentId()); + paymentPart.setAmount(new Amount("10","USD")); + + boolean paymentUpdateResult = client.invoicePayment.update(paymentPart); + assertTrue(paymentUpdateResult); + + //Search an invoice payment + List paymentIds = new ArrayList(); + paymentIds.add(invoicePayment.getPaymentId()); + + List invoiceIds = new ArrayList(); + invoiceIds.add(invoice.getId()); + InvoicePayments invoicePayments = client.invoicePayment.search(null, invoiceIds); + assertTrue(invoicePayments.getMeta().getRecords()>0); + + //Delete an Invoice Payment + boolean deleteResult = client.invoicePayment.delete( + invoicePayment.getInvoicePayments().get(0).getPaymentId(), + invoicePayment.getInvoicePayments().get(0).getInvoiceLineId()); + assertTrue(deleteResult); + + //Cleanup - Delete Recipient + boolean recDelResult = testHelper.deleteRecipient(recipient); + assertTrue(recDelResult); + + //Delete an Invoice + boolean invoiceDelResult = client.invoice.delete(invoice.getId()); + assertTrue(invoiceDelResult); + } + +} \ No newline at end of file diff --git a/src/test/java/com/trolley/sdk/integration/RecipientTest.java b/src/test/java/com/trolley/sdk/integration/RecipientTest.java new file mode 100644 index 0000000..add2edf --- /dev/null +++ b/src/test/java/com/trolley/sdk/integration/RecipientTest.java @@ -0,0 +1,111 @@ +package com.trolley.sdk.integration; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.powermock.core.classloader.annotations.PrepareForTest; + +import com.trolley.trolley.Configuration; +import com.trolley.trolley.Gateway; +import com.trolley.trolley.Recipient; +import com.trolley.trolley.RecipientAccount; + +import java.util.ArrayList; +import java.util.List; + +@PrepareForTest(Recipient.class) +public class RecipientTest { + + private static Configuration config; + private static TestHelper testHelper; + + @BeforeClass + public static void setupConfig() { + config = TestHelper.getConfig(); + testHelper = new TestHelper(); + } + + @Test + public void testCreateRecipient() throws Exception { + Recipient recipient = testHelper.createRecipient(); + assertEquals(recipient.getFirstName(), "John"); + assertEquals(recipient.getLastName(), "Smith"); + assertNotNull(recipient.getId()); + + //Cleanup + boolean deleteResult = testHelper.deleteRecipient(recipient); + assertTrue(deleteResult); + } + + @Test + public void testLifecycle() throws Exception { + Gateway client = new Gateway(config); + + Recipient recipient = testHelper.createRecipient(); + assertEquals(recipient.getFirstName(), "John"); + assertEquals(recipient.getLastName(), "Smith"); + assertNotNull(recipient.getId()); + + String body = "{\"firstName\": \"Bob\"}"; + boolean response = client.recipient.update(recipient.getId(), body); + assertNotNull(response); + + Recipient anotherRecipient = client.recipient.find(recipient.getId()); + assertEquals(anotherRecipient.getFirstName(), "Bob"); + + response = client.recipient.delete(recipient.getId()); + assertNotNull(response); + + Recipient anotherNewRecipient = client.recipient.find(recipient.getId()); + assertEquals("archived", anotherNewRecipient.getStatus()); + } + + @Test + public void testAccount() throws Exception { + Gateway client = new Gateway(config); + + Recipient recipient = testHelper.createRecipient(); + assertEquals(recipient.getFirstName(), "John"); + assertEquals(recipient.getLastName(), "Smith"); + assertNotNull(recipient.getId()); + + String body = "{\"type\": \"bank-transfer\", \"primary\": true, \"country\": \"DE\", \"currency\": \"EUR\", \"iban\": \"DE89 3704 0044 0532 0130 00\", \"accountHolderName\": \"Tom Jones\"}"; + RecipientAccount recipientAccount = testHelper.createRecipientAccount(recipient, body); + assertEquals("Tom Jones", recipientAccount.getAccountHolderName()); + + body = "{\"type\": \"bank-transfer\", \"primary\": true, \"country\": \"DE\", \"currency\": \"EUR\", \"iban\": \"DE89 3704 0044 0532 0130 00\", \"accountHolderName\": \"Tom Jones2\"}"; + RecipientAccount recipientAccount1 = testHelper.createRecipientAccount(recipient, body); + assertEquals("Tom Jones2", recipientAccount1.getAccountHolderName()); + + RecipientAccount recAccFindResult = client.recipientAccount.find(recipient.getId(), recipientAccount.getId()); + assertEquals(recAccFindResult.getCountry(), recipientAccount.getCountry()); + + List recipientAccounts = client.recipientAccount.findAll(recipient.getId()); + assertEquals(2, recipientAccounts.size()); + + boolean response = client.recipientAccount.delete(recipient.getId(), recipientAccount1.getId()); + assertNotNull(response); + + List recipientAccounts1 = client.recipientAccount.findAll(recipient.getId()); + assertEquals(1, recipientAccounts1.size()); + + //Cleanup + boolean deleteResult = testHelper.deleteRecipient(recipient); + assertTrue(deleteResult); + } + + + @Test + public void testRecipientRouteMinimum() throws Exception { + Gateway client = new Gateway(config); + ArrayList recipients = (ArrayList)client.recipient.search(1,20,""); + //Making sure routeMinimum is not null before asserting it's value + assertNotNull(recipients.get(0).getRouteMinimum()); + //Making sure routeMinium is set to a non-null value + assertTrue(Integer.parseInt(recipients.get(0).getRouteMinimum()) >= 0); + } + +} \ No newline at end of file diff --git a/src/test/java/com/trolley/sdk/integration/TestHelper.java b/src/test/java/com/trolley/sdk/integration/TestHelper.java new file mode 100644 index 0000000..f722093 --- /dev/null +++ b/src/test/java/com/trolley/sdk/integration/TestHelper.java @@ -0,0 +1,85 @@ +package com.trolley.sdk.integration; + +import java.util.UUID; + +import com.trolley.trolley.Configuration; +import com.trolley.trolley.Gateway; +import com.trolley.trolley.Recipient; +import com.trolley.trolley.RecipientAccount; + +import io.github.cdimascio.dotenv.Dotenv; + +public class TestHelper { + + public static Configuration getConfig(){ + Dotenv dotenv = Dotenv.load(); + + return new Configuration( + dotenv.get("ACCESS_KEY"), + dotenv.get("SECRET_KEY"), + "production"); + + } + + /** + * Creates a new Recipient for all test classes to use. + * @return Recipient the object representing the new Recipient created + * @throws Exception + */ + public Recipient createRecipient() throws Exception { + Gateway client = new Gateway(getConfig()); + + UUID uuid = UUID.randomUUID(); + + String email = "\"create.recipient.java-sdk." + uuid.toString() + "@example.com\""; + String body = "{\"type\": \"individual\",\"firstName\": \"John\",\"lastName\": \"Smith\",\"email\":" + email + + ",\"address\":{\"street1\": \"123 Main St\",\"city\": \"San Francisco\",\"region\": \"CA\",\"postalCode\": \"94131\",\"country\": \"DE\",\"phone\" : \"18005551212\"}}"; + + Recipient recipient = client.recipient.create(body); + + return recipient; + } + + /** + * Creates a new RecipientAccount for a Recipient. + * @param Recipient recipient to take recipientId from + * @return RecipientAccount + * @throws Exception + */ + public RecipientAccount createRecipientAccount(Recipient recipient) throws Exception { + Gateway client = new Gateway(getConfig()); + + String body = "{\"type\": \"bank-transfer\", \"primary\": true, \"country\": \"DE\", \"currency\": \"EUR\", \"iban\": \"DE89 3704 0044 0532 0130 00\", \"accountHolderName\": \"John Smith\"}"; + + RecipientAccount recipientAcount = client.recipientAccount.create(recipient.getId(), body); + + return recipientAcount; + } + + /** + * Create a RecipientAccount with the provided body + * @param recipient + * @param body + * @return + * @throws Exception + */ + public RecipientAccount createRecipientAccount(Recipient recipient, String body) throws Exception { + Gateway client = new Gateway(getConfig()); + + RecipientAccount recipientAcount = client.recipientAccount.create(recipient.getId(), body); + + return recipientAcount; + } + + /** + * Deletes a recipient + * @param recipient Recipient object of the recipient which needs to be deleted + * @return boolean indicating whether the delete operation was successful + * @throws Exception + */ + public boolean deleteRecipient(Recipient recipient) throws Exception { + Gateway client = new Gateway(getConfig()); + + return client.recipient.delete(recipient.getId()); + } +}