From c8c26f26fe42882d55d37547b96628dea226267a Mon Sep 17 00:00:00 2001 From: Tim Messerschmidt Date: Sun, 10 Mar 2013 00:52:24 +0100 Subject: [PATCH 01/30] Added an enum for available payment methods --- .../main/java/com/paypal/api/payments/Payer.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Payer.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Payer.java index 2cfd969f..db1ed798 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Payer.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Payer.java @@ -9,8 +9,11 @@ * */ public class Payer extends Resource { - - + public enum PaymentMethod { + CREDIT_CARD, + PAYPAL + } + /** * */ @@ -46,6 +49,12 @@ public String getPaymentMethod() { public void setPaymentMethod(String paymentMethod) { this.paymentMethod = paymentMethod; } + /** + * Setter for paymentMethod; + */ + public void setPaymentMethod(PaymentMethod paymentMethod) { + this.paymentMethod = paymentMethod.toString().toLowerCase(); + } /** * Getter for payerInfo */ From 66ce0e22a239bf2b839114f6c0caf364ad9c7f3a Mon Sep 17 00:00:00 2001 From: lathavairamani Date: Thu, 14 Mar 2013 12:30:16 +0530 Subject: [PATCH 02/30] updated User-Agent header value --- .../main/java/com/paypal/core/rest/PayPalResource.java | 2 +- .../main/java/com/paypal/core/rest/RESTConfiguration.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/rest-api-sdk/src/main/java/com/paypal/core/rest/PayPalResource.java b/rest-api-sdk/src/main/java/com/paypal/core/rest/PayPalResource.java index 5aa381b9..c8cb21bc 100644 --- a/rest-api-sdk/src/main/java/com/paypal/core/rest/PayPalResource.java +++ b/rest-api-sdk/src/main/java/com/paypal/core/rest/PayPalResource.java @@ -24,7 +24,7 @@ public abstract class PayPalResource { /** * SDK ID used in User-Agent HTTP header */ - public static final String SDK_ID = "ID"; + public static final String SDK_ID = "rest-sdk-java"; /** * SDK Version used in User-Agent HTTP header diff --git a/rest-api-sdk/src/main/java/com/paypal/core/rest/RESTConfiguration.java b/rest-api-sdk/src/main/java/com/paypal/core/rest/RESTConfiguration.java index f6332a8b..c7237db6 100644 --- a/rest-api-sdk/src/main/java/com/paypal/core/rest/RESTConfiguration.java +++ b/rest-api-sdk/src/main/java/com/paypal/core/rest/RESTConfiguration.java @@ -32,12 +32,12 @@ public class RESTConfiguration { StringBuilder javaVersion = new StringBuilder("lang=Java"); if (System.getProperty("java.version") != null && System.getProperty("java.version").length() > 0) { - javaVersion.append(";V=") + javaVersion.append(";v=") .append(System.getProperty("java.version")); } if (System.getProperty("java.vm.name") != null && System.getProperty("java.vm.name").length() > 0) { - javaVersion.append(";b="); + javaVersion.append(";bit="); if (System.getProperty("java.vm.name").contains("Client")) { javaVersion.append("32"); } else { @@ -50,10 +50,10 @@ public class RESTConfiguration { StringBuilder osVersion = new StringBuilder(); if (System.getProperty("os.name") != null && System.getProperty("os.name").length() > 0) { - osVersion.append("OS="); + osVersion.append("os="); osVersion.append(System.getProperty("os.name").replace(' ', '_')); } else { - osVersion.append("OS="); + osVersion.append("os="); } if (System.getProperty("os.version") != null && System.getProperty("os.version").length() > 0) { From 734004a294576ee10348993aa95a621ff09f8c42 Mon Sep 17 00:00:00 2001 From: Prasanna Annamalai Date: Mon, 18 Mar 2013 10:14:29 +0530 Subject: [PATCH 03/30] Added travis config --- .travis.yml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..4d26d3ea --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: java +jdk: + - oraclejdk7 + - openjdk7 + - openjdk6 +notifications: + recipients: + - prannamalai.x.com@gmail.com + on_success: always \ No newline at end of file From 4a1c428794d69959cabb3390484b4e9ce4530b45 Mon Sep 17 00:00:00 2001 From: Prasanna Annamalai Date: Mon, 18 Mar 2013 10:28:13 +0530 Subject: [PATCH 04/30] changed the travis config --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4d26d3ea..b8f220b6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,4 +6,4 @@ jdk: notifications: recipients: - prannamalai.x.com@gmail.com - on_success: always \ No newline at end of file + on_success: change \ No newline at end of file From 223655379d14d6a360c83586a10dc9ba1afebe01 Mon Sep 17 00:00:00 2001 From: Prasanna Annamalai Date: Mon, 18 Mar 2013 10:55:13 +0530 Subject: [PATCH 05/30] modified readme with github markdown java syntax --- README.md | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index a2b6cb62..bb8791d9 100644 --- a/README.md +++ b/README.md @@ -31,40 +31,49 @@ To make an API call: -------------------- * Import stub classes into your code. For example, - import com.paypal.api.payments.* + ```java + import com.paypal.api.payments.* + ``` * Copy the configuration file `sdk_config.properties` in `rest-api-sample/src/test/resources` folder to your application `src/main/resources`. And load it as a classloader resource, - InputStream is = PaymentWithCreditCardServlet.class.getResourceAsStream("/sdk_config.properties"); + ```java + InputStream is = PaymentWithCreditCardServlet.class.getResourceAsStream("/sdk_config.properties"); + ``` * Or load config file from any custom location using absolute path with the below method calls as required, - - Payment.initConfig(new File("../sdk_config.properties")); - Or - Payment.initConfig(new InputStream(new File("../sdk_config.properties"))); - Or - Payment.initConfig(new Properties().load(new InputStream(new File("../sdk_config.properties")))); + ```java + Payment.initConfig(new File("../sdk_config.properties")); + Or + Payment.initConfig(new InputStream(new File("../sdk_config.properties"))); + Or + Payment.initConfig(new Properties().load(new InputStream(new File("../sdk_config.properties")))); + ``` * Create `accesstoken` from `clientID` and `clientSecret` using `OAuthTokenCredential` - String accessToken = new OAuthTokenCredential(clientID, clientSecret).getAccessToken(); + ```java + String accessToken = new OAuthTokenCredential(clientID, clientSecret).getAccessToken(); + ``` * Depending on the context of API calls, calling method may be static or non-static (For example, most `GET` http methods are created as `static` methods within the resource). In all API calls, we need to pass `accessToken` created above as argument as shown below, * If it is static, invoke it as a class method as like - Payment.get(accessToken, paymentID); + ```java + Payment.get(accessToken, paymentID); + ``` * If it is non-static, invoke it using resource object as like below. The API call takes a APIContext object in the place of AccessToken, APIContext object encapsulates Access Token and Request ID (used for idempotency). - APIContext apiContext = new APIContext(accessToken); - (OR) - APIContext apiContext = new APIContext(accessToken, requestId); - Payment payment = new Payment(); - payment.setIntent("sale"); - ... - ... - ... - payment.create(apiContext); + ```java + APIContext apiContext = new APIContext(accessToken); + (OR) + APIContext apiContext = new APIContext(accessToken, requestId); + Payment payment = new Payment(); + payment.setIntent("sale"); + ... + payment.create(apiContext); + ``` SDK Configuration: From 11355510a4b77e29083db509414bde3391344d9a Mon Sep 17 00:00:00 2001 From: Prasanna Annamalai Date: Mon, 18 Mar 2013 11:18:31 +0530 Subject: [PATCH 06/30] added maven compiler plugin options for source and target as 1.5 JDK --- rest-api-sdk/pom.xml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/rest-api-sdk/pom.xml b/rest-api-sdk/pom.xml index c02ea684..ab99fe80 100644 --- a/rest-api-sdk/pom.xml +++ b/rest-api-sdk/pom.xml @@ -46,6 +46,15 @@ + + org.apache.maven.plugins + maven-compiler-plugin + 3.0 + + 1.5 + 1.5 + + org.apache.maven.plugins maven-source-plugin From 9ad6a020197a9d9a16682185aa2ab9672ded0c35 Mon Sep 17 00:00:00 2001 From: Prasanna Annamalai Date: Mon, 18 Mar 2013 11:19:40 +0530 Subject: [PATCH 07/30] Added maven compile plugin for setting source and target opts --- rest-api-sample/pom.xml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/rest-api-sample/pom.xml b/rest-api-sample/pom.xml index 4750366e..f36b6f99 100644 --- a/rest-api-sample/pom.xml +++ b/rest-api-sample/pom.xml @@ -20,6 +20,15 @@ + + org.apache.maven.plugins + maven-compiler-plugin + 3.0 + + 1.5 + 1.5 + + org.mortbay.jetty maven-jetty-plugin From 55f539d5119c81f159c9fd2fb3a8aa0ff1ca8e98 Mon Sep 17 00:00:00 2001 From: Prasanna Annamalai Date: Mon, 18 Mar 2013 11:32:56 +0530 Subject: [PATCH 08/30] Added build status link to README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index bb8791d9..e6450f19 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +## PayPal REST API Java SDK [![Build Status](https://travis-ci.org/prannamalai/rest-api-sdk-java.png?branch=master)](https://travis-ci.org/prannamalai/rest-api-sdk-java) This repository contains java sdk and samples for REST API. Prerequisites: From c77770c30d00006cb990737ef9cd24ff6e4b0fdf Mon Sep 17 00:00:00 2001 From: Prasanna Annamalai Date: Mon, 18 Mar 2013 11:44:36 +0530 Subject: [PATCH 09/30] Modified README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e6450f19..a9eb0cd2 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ ## PayPal REST API Java SDK [![Build Status](https://travis-ci.org/prannamalai/rest-api-sdk-java.png?branch=master)](https://travis-ci.org/prannamalai/rest-api-sdk-java) -This repository contains java sdk and samples for REST API. +This repository contains Java SDK and samples for REST API. Prerequisites: --------------- From b650348130aefd3833773e2bcec1fddf2cab2b6b Mon Sep 17 00:00:00 2001 From: Prasanna Annamalai Date: Mon, 18 Mar 2013 11:49:18 +0530 Subject: [PATCH 10/30] modified repo name to match paypal --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a9eb0cd2..bd83dffd 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -## PayPal REST API Java SDK [![Build Status](https://travis-ci.org/prannamalai/rest-api-sdk-java.png?branch=master)](https://travis-ci.org/prannamalai/rest-api-sdk-java) +## PayPal REST API Java SDK [![Build Status](https://travis-ci.org/paypal/rest-api-sdk-java.png?branch=master)](https://travis-ci.org/paypal/rest-api-sdk-java) This repository contains Java SDK and samples for REST API. Prerequisites: From b492068855c601de770dd29c448545de2a31f955 Mon Sep 17 00:00:00 2001 From: Prasanna Annamalai Date: Mon, 18 Mar 2013 11:51:51 +0530 Subject: [PATCH 11/30] modified email to include PP email --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index b8f220b6..4be275b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,5 +5,5 @@ jdk: - openjdk6 notifications: recipients: - - prannamalai.x.com@gmail.com + - DL-PP-Platform-Java-SDK@ebay.com on_success: change \ No newline at end of file From 69dac32ce4c5398976dfd52561bf628fd8e0a358 Mon Sep 17 00:00:00 2001 From: Tim Messerschmidt Date: Thu, 21 Mar 2013 18:17:29 +0100 Subject: [PATCH 12/30] Added Intent as enumeration --- .../main/java/com/paypal/api/payments/Payment.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Payment.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Payment.java index 76e469de..b1b74715 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Payment.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Payment.java @@ -21,7 +21,9 @@ * */ public class Payment extends Resource { - + public enum Intent { + SALE + } /** * @@ -191,6 +193,14 @@ public String getIntent() { public void setIntent(String intent) { this.intent = intent; } + + /** + * Setter for intent; + */ + public void setIntent(Intent intent) { + this.intent = intent.toString().toLowerCase(); + } + /** * Getter for payer */ From 4b22f75a2795191235030312d9264ad164342eff Mon Sep 17 00:00:00 2001 From: Kumarvel Jayakumar Date: Tue, 23 Apr 2013 15:35:35 +0530 Subject: [PATCH 13/30] Updated stubs for dynamic config --- pom.xml | 2 +- rest-api-sample/pom.xml | 4 +- rest-api-sdk/pom.xml | 9 +- .../com/paypal/api/payments/CreditCard.java | 26 +- .../java/com/paypal/api/payments/Payer.java | 13 +- .../java/com/paypal/api/payments/Payment.java | 96 ++++++- .../java/com/paypal/api/payments/Refund.java | 26 +- .../java/com/paypal/api/payments/Sale.java | 26 +- .../java/com/paypal/core/rest/APIContext.java | 76 ----- .../java/com/paypal/core/rest/HttpMethod.java | 25 -- .../com/paypal/core/rest/JSONFormatter.java | 53 ---- .../core/rest/OAuthTokenCredential.java | 139 --------- .../paypal/core/rest/PayPalRESTException.java | 20 -- .../com/paypal/core/rest/PayPalResource.java | 268 ------------------ .../com/paypal/core/rest/QueryParameters.java | 157 ---------- .../paypal/core/rest/RESTConfiguration.java | 236 --------------- .../java/com/paypal/core/rest/RESTUtil.java | 125 -------- .../rest/OAuthTokenCredentialTestCase.java | 68 ----- .../core/rest/PayPalResourceTestCase.java | 57 ---- .../core/rest/RESTConfigurationTestCase.java | 82 ------ .../com/paypal/core/rest/RESTUtilTest.java | 61 ---- 21 files changed, 164 insertions(+), 1405 deletions(-) delete mode 100644 rest-api-sdk/src/main/java/com/paypal/core/rest/APIContext.java delete mode 100644 rest-api-sdk/src/main/java/com/paypal/core/rest/HttpMethod.java delete mode 100644 rest-api-sdk/src/main/java/com/paypal/core/rest/JSONFormatter.java delete mode 100644 rest-api-sdk/src/main/java/com/paypal/core/rest/OAuthTokenCredential.java delete mode 100644 rest-api-sdk/src/main/java/com/paypal/core/rest/PayPalRESTException.java delete mode 100644 rest-api-sdk/src/main/java/com/paypal/core/rest/PayPalResource.java delete mode 100644 rest-api-sdk/src/main/java/com/paypal/core/rest/QueryParameters.java delete mode 100644 rest-api-sdk/src/main/java/com/paypal/core/rest/RESTConfiguration.java delete mode 100644 rest-api-sdk/src/main/java/com/paypal/core/rest/RESTUtil.java delete mode 100644 rest-api-sdk/src/test/java/com/paypal/core/rest/OAuthTokenCredentialTestCase.java delete mode 100644 rest-api-sdk/src/test/java/com/paypal/core/rest/PayPalResourceTestCase.java delete mode 100644 rest-api-sdk/src/test/java/com/paypal/core/rest/RESTConfigurationTestCase.java delete mode 100644 rest-api-sdk/src/test/java/com/paypal/core/rest/RESTUtilTest.java diff --git a/pom.xml b/pom.xml index a3fde597..a6b02c98 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.paypal.sdk rest-api - 0.5.2 + 0.6.0 pom rest-api diff --git a/rest-api-sample/pom.xml b/rest-api-sample/pom.xml index f36b6f99..614915fe 100644 --- a/rest-api-sample/pom.xml +++ b/rest-api-sample/pom.xml @@ -3,14 +3,14 @@ 4.0.0 com.paypal.sdk rest-api-sample - 0.5.2 + 0.6.0 REST API SAMPLE war com.paypal.sdk rest-api-sdk - 0.5.2 + 0.6.0 log4j diff --git a/rest-api-sdk/pom.xml b/rest-api-sdk/pom.xml index ab99fe80..b2eee159 100644 --- a/rest-api-sdk/pom.xml +++ b/rest-api-sdk/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.paypal.sdk rest-api-sdk - 0.5.2 + 0.6.0 jar REST API SDK PayPal SDK for integrating with the REST APIs @@ -28,11 +28,6 @@ UTF-8 - - com.google.code.gson - gson - 2.2.2 - org.testng testng @@ -41,7 +36,7 @@ com.paypal.sdk paypal-core - 1.2 + 1.4 diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCard.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCard.java index 07f1e11d..cc485944 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCard.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCard.java @@ -359,7 +359,31 @@ public static CreditCard get(String accessToken, String creditCardId) throws Pay Object[] parameters = new Object[] { creditCardId }; String resourcePath = RESTUtil.formatURIPath(pattern, parameters); String payLoad = ""; - return PayPalResource.configureAndExecute(accessToken, HttpMethod.GET, resourcePath, payLoad, CreditCard.class); + APIContext apiContext = new APIContext(accessToken); + return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, CreditCard.class); + } + + /** + * Get call for CreditCard. + * @param apiContext + * {@link APIContext} to be used for the call. + * @param creditCardId + * @HttpMethod GET + * @URIpath v1/vault/credit-card/:creditCardId + * @return CreditCard + */ + public static CreditCard get(APIContext apiContext, String creditCardId) throws PayPalRESTException { + if ((creditCardId == null) || (creditCardId.length() <= 0)) { + throw new IllegalArgumentException("creditCardId cannot be null or empty"); + } + String pattern = "v1/vault/credit-card/{0}"; + Object[] parameters = new Object[] { creditCardId }; + String resourcePath = RESTUtil.formatURIPath(pattern, parameters); + String payLoad = ""; + if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { + throw new IllegalArgumentException("AccessToken cannot be null in APIContext"); + } + return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, CreditCard.class); } /** diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Payer.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Payer.java index db1ed798..2cfd969f 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Payer.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Payer.java @@ -9,11 +9,8 @@ * */ public class Payer extends Resource { - public enum PaymentMethod { - CREDIT_CARD, - PAYPAL - } - + + /** * */ @@ -49,12 +46,6 @@ public String getPaymentMethod() { public void setPaymentMethod(String paymentMethod) { this.paymentMethod = paymentMethod; } - /** - * Setter for paymentMethod; - */ - public void setPaymentMethod(PaymentMethod paymentMethod) { - this.paymentMethod = paymentMethod.toString().toLowerCase(); - } /** * Getter for payerInfo */ diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Payment.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Payment.java index b1b74715..53040d2f 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Payment.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Payment.java @@ -21,9 +21,7 @@ * */ public class Payment extends Resource { - public enum Intent { - SALE - } + /** * @@ -193,14 +191,6 @@ public String getIntent() { public void setIntent(String intent) { this.intent = intent; } - - /** - * Setter for intent; - */ - public void setIntent(Intent intent) { - this.intent = intent.toString().toLowerCase(); - } - /** * Getter for payer */ @@ -281,7 +271,39 @@ public static PaymentHistory get(String accessToken, Map contain Object[] parameters = new Object[] { containerMap }; String resourcePath = RESTUtil.formatURIPath(pattern, parameters); String payLoad = ""; - return PayPalResource.configureAndExecute(accessToken, HttpMethod.GET, resourcePath, payLoad, PaymentHistory.class); + APIContext apiContext = new APIContext(accessToken); + return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, PaymentHistory.class); + } + + /** + * Get call for Payment. + * @param apiContext + * {@link APIContext} to be used for the call. + * @param containerMap + * Map containing the query strings with the + * following values as keys: + * count, + * start_id, + * start_index, + * start_time, + * end_time, + * payee_id, + * sort_by, + * sort_order, + * All other keys in the map are ignored by the SDK + * @HttpMethod GET + * @URIpath v1/payments/payment?count=:count&start_id=:start_id&start_index=:start_index&start_time=:start_time&end_time=:end_time&payee_id=:payee_id&sort_by=:sort_by&sort_order=:sort_order + * @return PaymentHistory + */ + public static PaymentHistory get(APIContext apiContext, Map containerMap) throws PayPalRESTException { + String pattern = "v1/payments/payment?count={0}&start_id={1}&start_index={2}&start_time={3}&end_time={4}&payee_id={5}&sort_by={6}&sort_order={7}"; + Object[] parameters = new Object[] { containerMap }; + String resourcePath = RESTUtil.formatURIPath(pattern, parameters); + String payLoad = ""; + if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { + throw new IllegalArgumentException("AccessToken cannot be null in APIContext"); + } + return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, PaymentHistory.class); } @@ -300,7 +322,29 @@ public static PaymentHistory get(String accessToken, QueryParameters queryParame Object[] parameters = new Object[] { queryParameters }; String resourcePath = RESTUtil.formatURIPath(pattern, parameters); String payLoad = ""; - return PayPalResource.configureAndExecute(accessToken, HttpMethod.GET, resourcePath, payLoad, PaymentHistory.class); + APIContext apiContext = new APIContext(accessToken); + return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, PaymentHistory.class); + } + + /** + * Get call for Payment. + * @param apiContext + * {@link APIContext} to be used for the call. + * @param queryParameters + * Container for query strings + * @HttpMethod GET + * @URIpath v1/payments/payment?count=:count&start_id=:start_id&start_index=:start_index&start_time=:start_time&end_time=:end_time&payee_id=:payee_id&sort_by=:sort_by&sort_order=:sort_order + * @return PaymentHistory + */ + public static PaymentHistory get(APIContext apiContext, QueryParameters queryParameters) throws PayPalRESTException { + String pattern = "v1/payments/payment?count={0}&start_id={1}&start_index={2}&start_time={3}&end_time={4}&payee_id={5}&sort_by={6}&sort_order={7}"; + Object[] parameters = new Object[] { queryParameters }; + String resourcePath = RESTUtil.formatURIPath(pattern, parameters); + String payLoad = ""; + if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { + throw new IllegalArgumentException("AccessToken cannot be null in APIContext"); + } + return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, PaymentHistory.class); } /** @@ -347,7 +391,31 @@ public static Payment get(String accessToken, String paymentId) throws PayPalRES Object[] parameters = new Object[] { paymentId }; String resourcePath = RESTUtil.formatURIPath(pattern, parameters); String payLoad = ""; - return PayPalResource.configureAndExecute(accessToken, HttpMethod.GET, resourcePath, payLoad, Payment.class); + APIContext apiContext = new APIContext(accessToken); + return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, Payment.class); + } + + /** + * Get call for Payment. + * @param apiContext + * {@link APIContext} to be used for the call. + * @param paymentId + * @HttpMethod GET + * @URIpath v1/payments/payment/:paymentId + * @return Payment + */ + public static Payment get(APIContext apiContext, String paymentId) throws PayPalRESTException { + if ((paymentId == null) || (paymentId.length() <= 0)) { + throw new IllegalArgumentException("paymentId cannot be null or empty"); + } + String pattern = "v1/payments/payment/{0}"; + Object[] parameters = new Object[] { paymentId }; + String resourcePath = RESTUtil.formatURIPath(pattern, parameters); + String payLoad = ""; + if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { + throw new IllegalArgumentException("AccessToken cannot be null in APIContext"); + } + return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, Payment.class); } /** diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Refund.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Refund.java index b8aaf2a7..f085ad4c 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Refund.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Refund.java @@ -278,7 +278,31 @@ public static Refund get(String accessToken, String refundId) throws PayPalRESTE Object[] parameters = new Object[] { refundId }; String resourcePath = RESTUtil.formatURIPath(pattern, parameters); String payLoad = ""; - return PayPalResource.configureAndExecute(accessToken, HttpMethod.GET, resourcePath, payLoad, Refund.class); + APIContext apiContext = new APIContext(accessToken); + return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, Refund.class); + } + + /** + * Get call for Refund. + * @param apiContext + * {@link APIContext} to be used for the call. + * @param refundId + * @HttpMethod GET + * @URIpath v1/payments/refund/:refundId + * @return Refund + */ + public static Refund get(APIContext apiContext, String refundId) throws PayPalRESTException { + if ((refundId == null) || (refundId.length() <= 0)) { + throw new IllegalArgumentException("refundId cannot be null or empty"); + } + String pattern = "v1/payments/refund/{0}"; + Object[] parameters = new Object[] { refundId }; + String resourcePath = RESTUtil.formatURIPath(pattern, parameters); + String payLoad = ""; + if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { + throw new IllegalArgumentException("AccessToken cannot be null in APIContext"); + } + return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, Refund.class); } /** diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Sale.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Sale.java index 96c2a12e..0fbe2606 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Sale.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Sale.java @@ -224,7 +224,31 @@ public static Sale get(String accessToken, String saleId) throws PayPalRESTExcep Object[] parameters = new Object[] { saleId }; String resourcePath = RESTUtil.formatURIPath(pattern, parameters); String payLoad = ""; - return PayPalResource.configureAndExecute(accessToken, HttpMethod.GET, resourcePath, payLoad, Sale.class); + APIContext apiContext = new APIContext(accessToken); + return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, Sale.class); + } + + /** + * Get call for Sale. + * @param apiContext + * {@link APIContext} to be used for the call. + * @param saleId + * @HttpMethod GET + * @URIpath v1/payments/sale/:saleId + * @return Sale + */ + public static Sale get(APIContext apiContext, String saleId) throws PayPalRESTException { + if ((saleId == null) || (saleId.length() <= 0)) { + throw new IllegalArgumentException("saleId cannot be null or empty"); + } + String pattern = "v1/payments/sale/{0}"; + Object[] parameters = new Object[] { saleId }; + String resourcePath = RESTUtil.formatURIPath(pattern, parameters); + String payLoad = ""; + if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { + throw new IllegalArgumentException("AccessToken cannot be null in APIContext"); + } + return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, Sale.class); } /** diff --git a/rest-api-sdk/src/main/java/com/paypal/core/rest/APIContext.java b/rest-api-sdk/src/main/java/com/paypal/core/rest/APIContext.java deleted file mode 100644 index 115bf596..00000000 --- a/rest-api-sdk/src/main/java/com/paypal/core/rest/APIContext.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.paypal.core.rest; - -import java.util.UUID; - -/** - * APIContext holds wire-level parameters for the API call. - * AccessToken is treated as a mandatory parameter. RequestId is generated if - * not supplied - * - * @author kjayakumar - * - */ -public class APIContext { - - /** - * Access Token - */ - private String accessToken; - - /** - * Request Id - */ - private String requestId; - - /** - * APIContext - * - * @param accessToken - * AccessToken required for the call. - */ - public APIContext(String accessToken) { - if (accessToken == null || accessToken.length() <= 0) { - throw new IllegalArgumentException("AccessToken cannot be null"); - } - this.accessToken = accessToken; - } - - /** - * APIContext - * - * @param accessToken - * AccessToken required for the call. - * @param requestId - * Unique requestId required for the call. - */ - public APIContext(String accessToken, String requestId) { - this(accessToken); - if (requestId == null || requestId.length() <= 0) { - throw new IllegalArgumentException("RequestId cannot be null"); - } - this.requestId = requestId; - } - - /** - * Returns the Access Token - * - * @return Access Token - */ - public String getAccessToken() { - return accessToken; - } - - /** - * Returns the unique requestId set during creation, if not available - * returns a generated one - * - * @return requestId - */ - public String getRequestId() { - if (requestId == null || requestId.length() <= 0) { - requestId = UUID.randomUUID().toString(); - } - return requestId; - } - -} diff --git a/rest-api-sdk/src/main/java/com/paypal/core/rest/HttpMethod.java b/rest-api-sdk/src/main/java/com/paypal/core/rest/HttpMethod.java deleted file mode 100644 index 5d54ed2c..00000000 --- a/rest-api-sdk/src/main/java/com/paypal/core/rest/HttpMethod.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.paypal.core.rest; - -/** - * HttpMethod enums used for HTTP method verbs - * @author kjayakumar - * - */ -public enum HttpMethod { - - // Get Http Method - GET, - - // Post Http Method - POST, - - // Patch Http Method - PATCH, - - // Put Http Method - PUT, - - // Delete Http Method - DELETE; - -} diff --git a/rest-api-sdk/src/main/java/com/paypal/core/rest/JSONFormatter.java b/rest-api-sdk/src/main/java/com/paypal/core/rest/JSONFormatter.java deleted file mode 100644 index 7e85c59d..00000000 --- a/rest-api-sdk/src/main/java/com/paypal/core/rest/JSONFormatter.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.paypal.core.rest; - -import com.google.gson.FieldNamingPolicy; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - -/** - * JSONFormatter converts objects to JSON representation and vice-versa - * - * @author kjayakumar - * - */ -public class JSONFormatter { - - /** - * Gson - */ - public static final Gson GSON = new GsonBuilder() - .setPrettyPrinting() - .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) - .create(); - - /** - * Converts a Raw Type to JSON String - * - * @param - * Type to be converted - * @param t - * Object of the type - * @return JSON representation - */ - public static String toJSON(T t) { - return GSON.toJson(t); - } - - /** - * Converts a JSON String to object representation - * - * @param - * Type to be converted - * @param responseString - * JSON representation - * @param clazz - * Target class - * @return Object of the target type - */ - public static T fromJSON(String responseString, Class clazz) { - T t = null; - t = GSON.fromJson(responseString, clazz); - return t; - } - -} diff --git a/rest-api-sdk/src/main/java/com/paypal/core/rest/OAuthTokenCredential.java b/rest-api-sdk/src/main/java/com/paypal/core/rest/OAuthTokenCredential.java deleted file mode 100644 index dccac68f..00000000 --- a/rest-api-sdk/src/main/java/com/paypal/core/rest/OAuthTokenCredential.java +++ /dev/null @@ -1,139 +0,0 @@ -package com.paypal.core.rest; - -import java.io.UnsupportedEncodingException; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.codec.binary.Base64; - -import com.google.gson.JsonElement; -import com.google.gson.JsonParser; -import com.paypal.core.ConfigManager; -import com.paypal.core.ConnectionManager; -import com.paypal.core.Constants; -import com.paypal.core.HttpConfiguration; -import com.paypal.core.HttpConnection; -import com.paypal.core.credential.ICredential; - -public final class OAuthTokenCredential implements ICredential { - - private static final String OAUTH_TOKEN_PATH = "/v1/oauth2/token"; - - /** - * Client ID for OAuth - */ - private String clientID; - - /** - * Client Secret for OAuth - */ - private String clientSecret; - - /** - * Access Token that is generated - */ - private String accessToken; - - /** - * Application ID returned by OAuth servers - */ - private transient String appId; - - /** - * @param clientID - * Client ID for the OAuth - * @param clientSecret - * Client Secret for OAuth - */ - public OAuthTokenCredential(String clientID, String clientSecret) { - super(); - this.clientID = clientID; - this.clientSecret = clientSecret; - } - - /** - * Computes Access Token by placing a call to OAuth server - * using ClientID and ClientSecret. The token is appended - * to the token type. - * @return the accessToken - * @throws PayPalRESTException - */ - public String getAccessToken() throws PayPalRESTException { - if (accessToken == null) { - // Write Logic for passing in Detail to Identity Api Serv and - // computing the token - // Set the Value inside the accessToken and result - accessToken = generateAccessToken(); - } - return accessToken; - } - - private String generateAccessToken() throws PayPalRESTException { - String generatedToken = null; - String base64ClientID = generateBase64String(clientID + ":" + clientSecret); - generatedToken = generateOAuthToken(base64ClientID); - return generatedToken; - } - - /* - * Generate a Base64 encoded String from clientID & clientSecret - */ - private String generateBase64String(String clientID) - throws PayPalRESTException { - String base64ClientID = null; - byte[] encoded = null; - try { - encoded = Base64.encodeBase64(clientID.getBytes("UTF-8")); - base64ClientID = new String(encoded, "UTF-8"); - } catch (UnsupportedEncodingException e) { - throw new PayPalRESTException(e.getMessage(), e); - } - return base64ClientID; - } - - /* - * Generate OAuth type token from Base64Client ID - */ - private String generateOAuthToken(String base64ClientID) - throws PayPalRESTException { - HttpConnection connection = null; - HttpConfiguration httpConfiguration = null; - String generatedToken = null; - try { - connection = ConnectionManager.getInstance().getConnection(); - httpConfiguration = getOAuthHttpConfiguration(); - connection.createAndconfigureHttpConnection(httpConfiguration); - Map headers = new HashMap(); - headers.put("Authorization", "Basic " + base64ClientID); - headers.put(Constants.HTTP_ACCEPT_HEADER, "*/*"); - String postRequest = "grant_type=client_credentials"; - String jsonResponse = connection.execute("", postRequest, headers); - JsonParser parser = new JsonParser(); - JsonElement jsonElement = parser.parse(jsonResponse); - generatedToken = jsonElement.getAsJsonObject().get("token_type") - .getAsString() - + " " - + jsonElement.getAsJsonObject().get("access_token") - .getAsString(); - appId = jsonElement.getAsJsonObject().get("app_id").getAsString(); - } catch (Exception e) { - throw new PayPalRESTException(e.getMessage(), e); - } - return generatedToken; - } - - /* - * Get HttpConfiguration object for OAuth server - */ - private HttpConfiguration getOAuthHttpConfiguration() { - ConfigManager config = ConfigManager.getInstance(); - HttpConfiguration httpConfiguration = new HttpConfiguration(); - httpConfiguration.setHttpMethod("POST"); - String endPointUrl = config.getValue("service.EndPoint") + OAUTH_TOKEN_PATH; - httpConfiguration.setEndPointUrl(endPointUrl); - httpConfiguration.setGoogleAppEngine(Boolean.parseBoolean(config - .getValue(Constants.GOOGLE_APP_ENGINE))); - return httpConfiguration; - } - -} diff --git a/rest-api-sdk/src/main/java/com/paypal/core/rest/PayPalRESTException.java b/rest-api-sdk/src/main/java/com/paypal/core/rest/PayPalRESTException.java deleted file mode 100644 index 0a1dc130..00000000 --- a/rest-api-sdk/src/main/java/com/paypal/core/rest/PayPalRESTException.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.paypal.core.rest; - -/** - * PayPalException handles all exceptions related to REST services - */ -public class PayPalRESTException extends Exception { - - public PayPalRESTException(String message) { - super(message); - } - - public PayPalRESTException(String message, Throwable throwable) { - super(message, throwable); - } - - public PayPalRESTException(Throwable throwable) { - super(throwable); - } - -} diff --git a/rest-api-sdk/src/main/java/com/paypal/core/rest/PayPalResource.java b/rest-api-sdk/src/main/java/com/paypal/core/rest/PayPalResource.java deleted file mode 100644 index c8cb21bc..00000000 --- a/rest-api-sdk/src/main/java/com/paypal/core/rest/PayPalResource.java +++ /dev/null @@ -1,268 +0,0 @@ -package com.paypal.core.rest; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URISyntaxException; -import java.util.Map; -import java.util.Properties; - -import com.paypal.core.ConfigManager; -import com.paypal.core.ConnectionManager; -import com.paypal.core.HttpConfiguration; -import com.paypal.core.HttpConnection; -import com.paypal.core.LoggingManager; - -/** - * PayPalResource acts as a base class for REST enabled resources - */ -public abstract class PayPalResource { - - /** - * SDK ID used in User-Agent HTTP header - */ - public static final String SDK_ID = "rest-sdk-java"; - - /** - * SDK Version used in User-Agent HTTP header - */ - public static final String SDK_VERSION = "0.5.2"; - - /** - * Configuration enabled flag - */ - private static boolean configInitialized = false; - - /** - * Last request sent to Service - */ - private static final ThreadLocal LASTREQUEST = new ThreadLocal(); - - /** - * Last response returned form Service - */ - private static final ThreadLocal LASTRESPONSE = new ThreadLocal(); - - /** - * Initialize using InputStream(of a Properties file) - * - * @param is - * InputStream - * @throws PayPalRESTException - */ - public static void initConfig(InputStream is) throws PayPalRESTException { - try { - ConfigManager.getInstance().load(is); - configInitialized = true; - } catch (IOException ioe) { - LoggingManager.severe(PayPalResource.class, ioe.getMessage(), ioe); - throw new PayPalRESTException(ioe.getMessage(), ioe); - } - - } - - /** - * Initialize using a File(Properties file) - * - * @param file - * File object of a properties entity - * @throws PayPalRESTException - */ - public static void initConfig(File file) throws PayPalRESTException { - try { - if (!file.exists()) { - throw new FileNotFoundException("File doesn't exist: " - + file.getAbsolutePath()); - } - FileInputStream fis = new FileInputStream(file); - initConfig(fis); - configInitialized = true; - } catch (IOException ioe) { - LoggingManager.severe(PayPalResource.class, ioe.getMessage(), ioe); - throw new PayPalRESTException(ioe.getMessage(), ioe); - } - - } - - /** - * Initialize using Properties - * - * @param properties - * Properties object - */ - public static void initConfig(Properties properties) { - ConfigManager.getInstance().load(properties); - configInitialized = true; - } - - /** - * Initialize to default properties - * - * @throws PayPalRESTException - */ - private static void initializeToDefault() throws PayPalRESTException { - initConfig(PayPalResource.class.getClassLoader().getResourceAsStream( - "sdk_config.properties")); - } - - /** - * Returns the last request sent to the Service - * - * @return Last request sent to the server - */ - public static String getLastRequest() { - return LASTREQUEST.get(); - } - - /** - * Returns the last response returned by the Service - * - * @return Last response got from the Service - */ - public static String getLastResponse() { - return LASTRESPONSE.get(); - } - - /** - * Configures and executes REST call: Supports JSON - * - * @param - * Response Type for de-serialization - * @param accessToken - * AccessToken to be used for the call. - * @param httpMethod - * Http Method verb - * @param resource - * Resource URI path - * @param payLoad - * Payload to Service - * @param clazz - * {@link Class} object used in De-serialization - * @return - * @throws PayPalRESTException - */ - public static T configureAndExecute(String accessToken, - HttpMethod httpMethod, String resourcePath, String payLoad, - Class clazz) throws PayPalRESTException { - T t = null; - if (!configInitialized) { - initializeToDefault(); - } - RESTConfiguration restConfiguration = createRESTConfiguration( - httpMethod, resourcePath, accessToken, null); - - t = execute(restConfiguration, payLoad, resourcePath, clazz); - return t; - } - - /** - * Configures and executes REST call: Supports JSON - * - * @param - * Response Type for de-serialization - * @param apiContext - * {@link APIContext} to be used for the call. - * @param httpMethod - * Http Method verb - * @param resource - * Resource URI path - * @param payLoad - * Payload to Service - * @param clazz - * {@link Class} object used in De-serialization - * @return - * @throws PayPalRESTException - */ - public static T configureAndExecute(APIContext apiContext, - HttpMethod httpMethod, String resourcePath, String payLoad, - Class clazz) throws PayPalRESTException { - T t = null; - if (!configInitialized) { - initializeToDefault(); - } - RESTConfiguration restConfiguration = createRESTConfiguration( - httpMethod, resourcePath, apiContext.getAccessToken(), - apiContext.getRequestId()); - - t = execute(restConfiguration, payLoad, resourcePath, clazz); - return t; - } - - /** - * Creates a {@link RESTConfiguration} based on configuration - * - * @param httpMethod - * {@link HttpMethod} - * @param resourcePath - * Resource URI - * @param accessToken - * Access Token - * @param requestId - * Request Id - * @return - */ - private static RESTConfiguration createRESTConfiguration( - HttpMethod httpMethod, String resourcePath, String accessToken, - String requestId) { - RESTConfiguration restConfiguration = new RESTConfiguration(); - restConfiguration.setHttpMethod(httpMethod); - restConfiguration.setResourcePath(resourcePath); - restConfiguration.setRequestId(requestId); - restConfiguration.setAuthorizationToken(accessToken); - return restConfiguration; - } - - /** - * Execute the API call and return response - * - * @param - * Type of the return object - * @param restConfiguration - * {@link RESTConfiguration} - * @param payLoad - * Payload - * @param resourcePath - * Resource URI - * @param clazz - * Class of the return object - * @return API response type object - * @throws PayPalRESTException - */ - private static T execute(RESTConfiguration restConfiguration, - String payLoad, String resourcePath, Class clazz) - throws PayPalRESTException { - T t = null; - ConnectionManager connectionManager; - HttpConnection httpConnection; - HttpConfiguration httpConfig; - Map headers; - String responseString; - try { - - // REST Headers - headers = restConfiguration.getHeaders(); - - // HTTPConfiguration Object - httpConfig = restConfiguration.getHttpConfigurations(); - - // HttpConnection Initialization - connectionManager = ConnectionManager.getInstance(); - httpConnection = connectionManager.getConnection(httpConfig); - httpConnection.createAndconfigureHttpConnection(httpConfig); - - LASTREQUEST.set(payLoad); - responseString = httpConnection.execute(restConfiguration - .getBaseURL().toURI().resolve(resourcePath).toString(), - payLoad, headers); - LASTRESPONSE.set(responseString); - t = JSONFormatter.fromJSON(responseString, clazz); - } catch (Exception e) { - throw new PayPalRESTException(e.getMessage(), e); - } - return t; - } - -} diff --git a/rest-api-sdk/src/main/java/com/paypal/core/rest/QueryParameters.java b/rest-api-sdk/src/main/java/com/paypal/core/rest/QueryParameters.java deleted file mode 100644 index 1495c27c..00000000 --- a/rest-api-sdk/src/main/java/com/paypal/core/rest/QueryParameters.java +++ /dev/null @@ -1,157 +0,0 @@ -package com.paypal.core.rest; - -import java.util.HashMap; -import java.util.Map; - -import com.paypal.api.payments.PaymentHistory; - -/** - * QueryParameters holds query parameters used for retrieving - * {@link PaymentHistory} object. - * - * @author kjayakumar - * - */ -public class QueryParameters { - - /** - * Count - */ - private static final String COUNT = "count"; - - /** - * Start Id - */ - private static final String STARTID = "start_id"; - - /** - * Start Index - */ - private static final String STARTINDEX = "start_index"; - - /** - * Start Time - */ - private static final String STARTTIME = "start_time"; - - /** - * End Time - */ - private static final String ENDTIME = "end_time"; - - /** - * Payee Id - */ - private static final String PAYEEID = "payee_id"; - - /** - * Sort By - */ - private static final String SORTBY = "sort_by"; - - /** - * Sort Order - */ - private static final String SORTORDER = "sort_order"; - - // Map backing QueryParameters intended to processed - // by SDK library 'RESTUtil' - private Map containerMap; - - public QueryParameters() { - containerMap = new HashMap(); - } - - /** - * @return the containerMap - */ - Map getContainerMap() { - return containerMap; - } - - /** - * Set the count - * - * @param count - * Number of items to return. - */ - public void setCount(String count) { - containerMap.put(COUNT, count); - } - - /** - * Set the startId - * - * @param startId - * Resource ID that indicates the starting resource to return. - */ - public void setStartId(String startId) { - containerMap.put(STARTID, startId); - } - - /** - * Set the startIndex - * - * @param startIndex - * Start index of the resources to be returned. Typically used to - * jump to a specific position in the resource history based on - * its order. - */ - public void setStartIndex(String startIndex) { - containerMap.put(STARTINDEX, startIndex); - } - - /** - * Set the startTime - * - * @param startTime - * Resource creation time that indicates the start of a range of - * results. - */ - public void setStartTime(String startTime) { - containerMap.put(STARTTIME, startTime); - } - - /** - * Set the endTime - * - * @param endTime - * Resource creation time that indicates the end of a range of - * results. - */ - public void setEndTime(String endTime) { - containerMap.put(ENDTIME, endTime); - } - - /** - * Set the payeeId - * - * @param payeeId - * PayeeId - */ - public void setPayeeId(String payeeId) { - containerMap.put(PAYEEID, payeeId); - } - - /** - * Set the sortBy - * - * @param sortBy - * Sort based on create_time or update_time. - */ - public void setSortBy(String sortBy) { - containerMap.put(SORTBY, sortBy); - } - - /** - * Set the sortOrder - * - * @param sortOrder - * Sort based on order of results. Options include asc for - * ascending order or dec for descending order. - */ - public void setSortOrder(String sortOrder) { - containerMap.put(SORTORDER, sortOrder); - } - -} diff --git a/rest-api-sdk/src/main/java/com/paypal/core/rest/RESTConfiguration.java b/rest-api-sdk/src/main/java/com/paypal/core/rest/RESTConfiguration.java deleted file mode 100644 index c7237db6..00000000 --- a/rest-api-sdk/src/main/java/com/paypal/core/rest/RESTConfiguration.java +++ /dev/null @@ -1,236 +0,0 @@ -package com.paypal.core.rest; - -import java.net.MalformedURLException; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; - -import com.paypal.core.ConfigManager; -import com.paypal.core.Constants; -import com.paypal.core.HttpConfiguration; - -/** - * RESTConfiguration helps {@link PayPalResource} with state dependent utility - * methods - */ -public class RESTConfiguration { - - /** - * Java Version and bit header computed during construction - */ - private static final String JAVAHEADER; - - /** - * OS Version and bit header computed during construction - */ - private static final String OSHEADER; - - static { - - // Java Version computed statically - StringBuilder javaVersion = new StringBuilder("lang=Java"); - if (System.getProperty("java.version") != null - && System.getProperty("java.version").length() > 0) { - javaVersion.append(";v=") - .append(System.getProperty("java.version")); - } - if (System.getProperty("java.vm.name") != null - && System.getProperty("java.vm.name").length() > 0) { - javaVersion.append(";bit="); - if (System.getProperty("java.vm.name").contains("Client")) { - javaVersion.append("32"); - } else { - javaVersion.append("64"); - } - } - JAVAHEADER = javaVersion.toString(); - - // OS Version Header - StringBuilder osVersion = new StringBuilder(); - if (System.getProperty("os.name") != null - && System.getProperty("os.name").length() > 0) { - osVersion.append("os="); - osVersion.append(System.getProperty("os.name").replace(' ', '_')); - } else { - osVersion.append("os="); - } - if (System.getProperty("os.version") != null - && System.getProperty("os.version").length() > 0) { - osVersion.append(" " - + System.getProperty("os.version").replace(' ', '_')); - } - OSHEADER = osVersion.toString(); - } - - /** - * Base URL for the service - */ - private URL url; - - /** - * Authorization token - */ - private String authorizationToken; - - /** - * {@link HttpMethod} - */ - private HttpMethod httpMethod; - - /** - * Resource URI as defined in the WSDL - */ - private String resourcePath; - - /** - * Request Id - */ - private String requestId; - - /** - * Default Constructor - */ - public RESTConfiguration() { - - } - - /** - * @param authorizationToken - * the authorizationToken to set - */ - public void setAuthorizationToken(String authorizationToken) { - this.authorizationToken = authorizationToken; - } - - /** - * @param httpMethod - * the httpMethod to set - */ - public void setHttpMethod(HttpMethod httpMethod) { - this.httpMethod = httpMethod; - } - - /** - * @param resourcePath - * the resourcePath to set - */ - public void setResourcePath(String resourcePath) { - this.resourcePath = resourcePath; - } - - /** - * @param requestId - * the requestId to set - */ - public void setRequestId(String requestId) { - this.requestId = requestId; - } - - /** - * Returns HTTP headers as a {@link Map} - * - * @return {@link Map} of Http headers - */ - public Map getHeaders() { - Map headers = new HashMap(); - headers.put("Authorization", authorizationToken); - headers.put("User-Agent", formUserAgentHeader()); - if (requestId != null && requestId.length() > 0) { - headers.put("PayPal-Request-Id", requestId); - } - return headers; - } - - /** - * Returns a {@link HttpConfiguration} based on configuration - * - * @return {@link HttpConfiguration} - * @throws MalformedURLException - * @throws URISyntaxException - */ - public HttpConfiguration getHttpConfigurations() - throws MalformedURLException, URISyntaxException { - ConfigManager config = ConfigManager.getInstance(); - HttpConfiguration httpConfiguration = new HttpConfiguration(); - httpConfiguration.setHttpMethod(httpMethod.toString()); - httpConfiguration.setEndPointUrl(getBaseURL().toURI() - .resolve(resourcePath).toString()); - httpConfiguration.setContentType("application/json"); - httpConfiguration.setGoogleAppEngine(Boolean.parseBoolean(config - .getValue(Constants.GOOGLE_APP_ENGINE))); - if (Boolean.parseBoolean(config.getValue(Constants.USE_HTTP_PROXY))) { - httpConfiguration.setProxyPort(Integer.parseInt(config - .getValue(Constants.HTTP_PROXY_PORT))); - httpConfiguration.setProxyHost(config - .getValue(Constants.HTTP_PROXY_HOST)); - httpConfiguration.setProxyUserName(config - .getValue(Constants.HTTP_PROXY_USERNAME)); - httpConfiguration.setProxyPassword(config - .getValue(Constants.HTTP_PROXY_PASSWORD)); - } - httpConfiguration.setConnectionTimeout(Integer.parseInt(config - .getValue(Constants.HTTP_CONNECTION_TIMEOUT))); - httpConfiguration.setMaxRetry(Integer.parseInt(config - .getValue(Constants.HTTP_CONNECTION_RETRY))); - httpConfiguration.setReadTimeout(Integer.parseInt(config - .getValue(Constants.HTTP_CONNECTION_READ_TIMEOUT))); - httpConfiguration.setMaxHttpConnection(Integer.parseInt(config - .getValue(Constants.HTTP_CONNECTION_MAX_CONNECTION))); - httpConfiguration.setIpAddress(config - .getValue(Constants.DEVICE_IP_ADDRESS)); - return httpConfiguration; - } - - /** - * Returns the base URL configured in application resources - * - * @return Base {@link URL} - * @throws MalformedURLException - */ - public URL getBaseURL() throws MalformedURLException { - if (url == null) { - String urlString = ConfigManager.getInstance().getValue( - "service.EndPoint"); - if (!urlString.endsWith("/")) { - urlString += "/"; - } - url = new URL(urlString); - } - return url; - } - - /** - * @param urlString - * the url to set - */ - public void setUrl(String urlString) throws MalformedURLException { - if (urlString != null && urlString.length() > 0) { - if (!urlString.endsWith("/")) { - urlString += "/"; - } - this.url = new URL(urlString); - } else { - this.url = getBaseURL(); - } - } - - /* - * Form User-Agent HTTP header - */ - private String formUserAgentHeader() { - String header = null; - StringBuilder stringBuilder = new StringBuilder("PayPalSDK/" - + PayPalResource.SDK_ID + " " + PayPalResource.SDK_VERSION - + " "); - stringBuilder.append("(").append(JAVAHEADER); - String osVersion = OSHEADER; - if (osVersion.length() > 0) { - stringBuilder.append(";").append(osVersion); - } - stringBuilder.append(")"); - header = stringBuilder.toString(); - return header; - } - -} diff --git a/rest-api-sdk/src/main/java/com/paypal/core/rest/RESTUtil.java b/rest-api-sdk/src/main/java/com/paypal/core/rest/RESTUtil.java deleted file mode 100644 index 657ff504..00000000 --- a/rest-api-sdk/src/main/java/com/paypal/core/rest/RESTUtil.java +++ /dev/null @@ -1,125 +0,0 @@ -package com.paypal.core.rest; - -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -public class RESTUtil { - - /** - * Formats the URI path for REST calls. - * - * @param pattern - * URI pattern with place holders for replacement strings - * @param parameters - * Replacement objects - * @return Formatted URI path - */ - public static String formatURIPath(String pattern, Object[] parameters) { - String formattedPath = null; - - if (pattern != null) { - if (parameters != null && parameters.length == 1 - && parameters[0] instanceof QueryParameters) { - - // Form a object array using the passed QueryParameters - parameters = splitParameters(pattern, - ((QueryParameters) parameters[0]).getContainerMap()); - } else if (parameters != null && parameters.length == 1 - && parameters[0] instanceof Map) { - - // Form a object array using the passed Map - parameters = splitParameters(pattern, - ((Map) parameters[0])); - } - - // Perform a simple message formatting - String fString = MessageFormat.format(pattern, parameters); - - // Process the resultant string for removing nulls - formattedPath = removeNullsInQS(fString); - } - return formattedPath; - } - - /** - * Remove null parameters from query string - * - * @param fString - * Formatted String - * @return Nulls removed query string - */ - private static String removeNullsInQS(String fString) { - if (fString != null && fString.length() != 0) { - String[] parts = fString.split("\\?"); - - // Process the query string part - if (parts.length == 2) { - String queryString = parts[1]; - String[] querys = queryString.split("&"); - if (querys.length > 0) { - StringBuilder strBuilder = new StringBuilder(); - for (String query : querys) { - String[] valueSplit = query.split("="); - if (valueSplit.length == 2) { - if ("null".equalsIgnoreCase(valueSplit[1].trim())) { - continue; - } else if ("".equals(valueSplit[1].trim())) { - continue; - } else { - strBuilder.append(query).append("&"); - } - } else if (valueSplit.length < 2) { - continue; - } - } - fString = (!strBuilder.toString().endsWith("&")) ? strBuilder - .toString() : strBuilder.toString().substring(0, - strBuilder.toString().length() - 1); - } - - // append the query string delimiter - fString = (parts[0].trim() + "?") + fString; - } - } - return fString; - } - - /** - * Split the URI and form a Object array using the query string and values - * in the provided map. The return object array is populated only if the map - * contains valid value for the query name. The object array contains null - * values if there is no value found in the map - * - * @param pattern - * URI pattern - * @param containerMap - * Map containing the query name and value - * @return Object array - */ - private static Object[] splitParameters(String pattern, - Map containerMap) { - List objectList = new ArrayList(); - String[] query = pattern.split("\\?"); - if (query != null && query.length == 2 && query[1].contains("={")) { - String[] queries = query[1].split("&"); - if (queries != null) { - for (String q : queries) { - String[] params = q.split("="); - if (params != null && params.length == 2) { - String key = params[0].trim(); - if (containerMap.containsKey(key)) { - Object object = containerMap.get(key); - objectList.add(object); - } else { - objectList.add(null); - } - } - } - } - } - return objectList.toArray(); - } - -} diff --git a/rest-api-sdk/src/test/java/com/paypal/core/rest/OAuthTokenCredentialTestCase.java b/rest-api-sdk/src/test/java/com/paypal/core/rest/OAuthTokenCredentialTestCase.java deleted file mode 100644 index 1038c26d..00000000 --- a/rest-api-sdk/src/test/java/com/paypal/core/rest/OAuthTokenCredentialTestCase.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.paypal.core.rest; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; - -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; -import org.testng.log4testng.Logger; - -import com.paypal.api.payments.Payment; -import com.paypal.api.payments.PaymentTestCase; - -import com.paypal.core.ConfigManager; - -public class OAuthTokenCredentialTestCase { - - private static final Logger logger = Logger - .getLogger(PaymentTestCase.class); - - String clientID; - String clientSecret; - - @BeforeClass - public void beforeClass() { - // ##Load Configuration - // Load SDK configuration for - // the resource. - InputStream is = OAuthTokenCredentialTestCase.class - .getResourceAsStream("/sdk_config.properties"); - - try { - PayPalResource.initConfig(is); - } catch (PayPalRESTException e) { - logger.error(e.getMessage()); - } - clientID = ConfigManager.getInstance().getValue("clientID"); - clientSecret = ConfigManager.getInstance().getValue("clientSecret"); - } - - @Test(dependsOnMethods = { "testGetRefund" }) - public void testGetAccessToken() throws PayPalRESTException { - - OAuthTokenCredential merchantTokenCredential = new OAuthTokenCredential( - clientID, clientSecret); - - String accessToken = merchantTokenCredential.getAccessToken(); - logger.info("Generated Access Token = " + accessToken); - Assert.assertEquals(true, accessToken.length() > 0); - } - - @Test(dependsOnMethods = { "testGetAccessToken" }) - public void testErrorAccessToken() { - File testFile = new File(".", - "src/test/resources/error_sdk_config.properties"); - try { - Payment.initConfig(testFile); - clientID = ConfigManager.getInstance().getValue("clientID"); - clientSecret = ConfigManager.getInstance().getValue("clientSecret"); - OAuthTokenCredential merchantTokenCredential = new OAuthTokenCredential( - clientID, clientSecret); - String accessToken = merchantTokenCredential.getAccessToken(); - } catch (PayPalRESTException e) { - Assert.assertEquals(true, e.getCause() instanceof IOException); - } - } -} diff --git a/rest-api-sdk/src/test/java/com/paypal/core/rest/PayPalResourceTestCase.java b/rest-api-sdk/src/test/java/com/paypal/core/rest/PayPalResourceTestCase.java deleted file mode 100644 index 9b2057a3..00000000 --- a/rest-api-sdk/src/test/java/com/paypal/core/rest/PayPalResourceTestCase.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.paypal.core.rest; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.Properties; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.paypal.api.payments.Payment; -import com.paypal.core.rest.PayPalRESTException; - -public class PayPalResourceTestCase { - - @Test - public void testUnknownFileConfiguration() { - try { - Payment.initConfig(new File("unknown.properties")); - } catch (PayPalRESTException e) { - Assert.assertEquals(e.getCause().getClass().getSimpleName(), - "FileNotFoundException"); - } - } - - @Test - public void testInputStreamConfiguration() { - try { - File testFile = new File(".", - "src/test/resources/sdk_config.properties"); - FileInputStream fis = new FileInputStream(testFile); - Payment.initConfig(fis); - } catch (PayPalRESTException e) { - Assert.fail("[sdk_config.properties] stream loading failed"); - } catch (FileNotFoundException e) { - Assert.fail("[sdk_config.properties] file is not available"); - } - } - - @Test - public void testPropertiesConfiguration() { - try { - File testFile = new File(".", - "src/test/resources/sdk_config.properties"); - Properties props = new Properties(); - FileInputStream fis = new FileInputStream(testFile); - props.load(fis); - Payment.initConfig(props); - } catch (FileNotFoundException e) { - Assert.fail("[sdk_config.properties] file is not available"); - } catch (IOException e) { - Assert.fail("[sdk_config.properties] file is not loaded into properties"); - } - } - -} diff --git a/rest-api-sdk/src/test/java/com/paypal/core/rest/RESTConfigurationTestCase.java b/rest-api-sdk/src/test/java/com/paypal/core/rest/RESTConfigurationTestCase.java deleted file mode 100644 index dd640d86..00000000 --- a/rest-api-sdk/src/test/java/com/paypal/core/rest/RESTConfigurationTestCase.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.paypal.core.rest; - -import java.io.File; -import java.net.MalformedURLException; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.Map; - -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.paypal.api.payments.Payment; -import com.paypal.api.payments.Sale; - -public class RESTConfigurationTestCase { - - @Test(dependsOnMethods = { "testErrorAccessToken" }) - public void testRESTConfiguration() { - File testFile = new File(".", - "src/test/resources/error_sdk_config.properties"); - try { - Payment.initConfig(testFile); - RESTConfiguration restConfiguration = new RESTConfiguration(); - restConfiguration.setHttpMethod(HttpMethod.POST); - restConfiguration.setResourcePath("/a/b/c"); - restConfiguration.getHttpConfigurations(); - URL url = restConfiguration.getBaseURL(); - Assert.assertEquals(true, url.toString().endsWith("/")); - } catch (PayPalRESTException e) { - Assert.fail(); - } catch (MalformedURLException e) { - Assert.fail(); - } catch (URISyntaxException e) { - Assert.fail(); - } - } - - @Test(dependsOnMethods = { "testRESTConfiguration" }) - public void testRESTHeaderConfiguration() { - File testFile = new File(".", - "src/test/resources/error_sdk_config.properties"); - try { - Payment.initConfig(testFile); - RESTConfiguration restConfiguration = new RESTConfiguration(); - restConfiguration.setHttpMethod(HttpMethod.POST); - restConfiguration.setResourcePath("/a/b/c"); - restConfiguration.getHttpConfigurations(); - Map headers = restConfiguration.getHeaders(); - Assert.assertEquals(headers.size() != 0, true); - String header = headers.get("User-Agent"); - String[] hdrs = header.split("\\("); - hdrs = hdrs[1].split(";"); - Assert.assertEquals(hdrs.length == 4, true); - } catch (PayPalRESTException e) { - Assert.fail(); - } catch (MalformedURLException e) { - Assert.fail(); - } catch (URISyntaxException e) { - Assert.fail(); - } - } - - @Test(dependsOnMethods = { "testRESTHeaderConfiguration" }) - public void testRESTConfigurationURL() { - File testFile = new File(".", - "src/test/resources/error_sdk_config.properties"); - try { - Sale.initConfig(testFile); - RESTConfiguration restConfiguration = new RESTConfiguration(); - restConfiguration.setHttpMethod(HttpMethod.POST); - restConfiguration.setResourcePath("/a/b/c"); - String urlString = "https://sample.com"; - restConfiguration.setUrl(urlString); - URL returnURL = restConfiguration.getBaseURL(); - Assert.assertEquals(true, returnURL.toString().endsWith("/")); - } catch (PayPalRESTException e) { - Assert.fail(); - } catch (MalformedURLException e) { - Assert.fail(); - } - } -} diff --git a/rest-api-sdk/src/test/java/com/paypal/core/rest/RESTUtilTest.java b/rest-api-sdk/src/test/java/com/paypal/core/rest/RESTUtilTest.java deleted file mode 100644 index 1b392e7d..00000000 --- a/rest-api-sdk/src/test/java/com/paypal/core/rest/RESTUtilTest.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.paypal.core.rest; - -import org.testng.Assert; -import org.testng.annotations.Test; - -public class RESTUtilTest { - - @Test - public void testFormatURIPathForNull() { - String nullString = RESTUtil.formatURIPath(null, null); - Assert.assertNull(nullString); - } - - @Test - public void testFormatURIPathNoPattern() { - String pattern = "/a/b/c"; - String uriPath = RESTUtil.formatURIPath(pattern, null); - Assert.assertEquals(uriPath, pattern); - } - - @Test - public void testFormatURIPathNoQS() { - String pattern = "/a/b/{0}"; - Object[] parameters = new Object[] {"replace"}; - String uriPath = RESTUtil.formatURIPath(pattern, parameters); - Assert.assertEquals(uriPath, "/a/b/replace"); - } - - @Test - public void testFormatURIPath() { - String pattern = "/a/b/{0}?name={1}"; - Object[] parameters = new Object[] {"replace", "nameValue"}; - String uriPath = RESTUtil.formatURIPath(pattern, parameters); - Assert.assertEquals(uriPath, "/a/b/replace?name=nameValue"); - } - - @Test - public void testFormatURIPathWithNull() { - String pattern = "/a/b/{0}?name={1}&age={2}"; - Object[] parameters = new Object[] {"replace", "nameValue", null}; - String uriPath = RESTUtil.formatURIPath(pattern, parameters); - Assert.assertEquals(uriPath, "/a/b/replace?name=nameValue"); - } - - @Test - public void testFormatURIPathWithEmpty() { - String pattern = "/a/b/{0}?name={1}&age="; - Object[] parameters = new Object[] {"replace", "nameValue", null}; - String uriPath = RESTUtil.formatURIPath(pattern, parameters); - Assert.assertEquals(uriPath, "/a/b/replace?name=nameValue"); - } - - @Test - public void testFormatURIPathTwoQS() { - String pattern = "/a/b/{0}?name={1}&age={2}"; - Object[] parameters = new Object[] {"replace", "nameValue", "1"}; - String uriPath = RESTUtil.formatURIPath(pattern, parameters); - Assert.assertEquals(uriPath, "/a/b/replace?name=nameValue&age=1"); - } - -} From c0fadae47cc2a5c199b2041ebf53024b885304c2 Mon Sep 17 00:00:00 2001 From: Kumarvel Jayakumar Date: Wed, 24 Apr 2013 11:50:01 +0530 Subject: [PATCH 14/30] Updated Payment resource to include Intent enum --- .../java/com/paypal/api/payments/Payment.java | 246 +++++++++++------- 1 file changed, 149 insertions(+), 97 deletions(-) diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Payment.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Payment.java index 53040d2f..4cb518c3 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Payment.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Payment.java @@ -1,4 +1,5 @@ package com.paypal.api.payments; + import com.paypal.api.payments.Payer; import java.util.List; import com.paypal.api.payments.Transaction; @@ -22,50 +23,53 @@ */ public class Payment extends Resource { + public enum Intent { + SALE + } /** * - */ + */ private String id; /** * - */ + */ private String createTime; /** * - */ + */ private String updateTime; /** * - */ + */ private String state; /** * - */ + */ private String intent; /** * - */ + */ private Payer payer; /** * - */ + */ private List transactions; /** * - */ + */ private RedirectUrls redirectUrls; /** * - */ + */ private List links; /** @@ -85,7 +89,7 @@ public static String getLastRequest() { public static String getLastResponse() { return PayPalResource.getLastResponse(); } - + /** * Initialize using InputStream(of a Properties file) * @@ -117,14 +121,13 @@ public static void initConfig(File file) throws PayPalRESTException { public static void initConfig(Properties properties) { PayPalResource.initConfig(properties); } - /** * Constructor */ public Payment() { - } + } /** * Getter for id @@ -132,111 +135,126 @@ public Payment() { public String getId() { return id; } - + /** * Setter for id; */ public void setId(String id) { this.id = id; } + /** * Getter for createTime */ public String getCreateTime() { return createTime; } - + /** * Setter for createTime; */ public void setCreateTime(String createTime) { this.createTime = createTime; } + /** * Getter for updateTime */ public String getUpdateTime() { return updateTime; } - + /** * Setter for updateTime; */ public void setUpdateTime(String updateTime) { this.updateTime = updateTime; } + /** * Getter for state */ public String getState() { return state; } - + /** * Setter for state; */ public void setState(String state) { this.state = state; } + /** * Getter for intent */ public String getIntent() { return intent; } - + /** * Setter for intent; */ public void setIntent(String intent) { this.intent = intent; } + + /** + * Setter for intent; + */ + public void setIntent(Intent intent) { + this.intent = intent.toString().toLowerCase(); + } + /** * Getter for payer */ public Payer getPayer() { return payer; } - + /** * Setter for payer; */ public void setPayer(Payer payer) { this.payer = payer; } + /** * Getter for transactions */ public List getTransactions() { return transactions; } - + /** * Setter for transactions; */ public void setTransactions(List transactions) { this.transactions = transactions; } + /** * Getter for redirectUrls */ public RedirectUrls getRedirectUrls() { return redirectUrls; } - + /** * Setter for redirectUrls; */ public void setRedirectUrls(RedirectUrls redirectUrls) { this.redirectUrls = redirectUrls; } + /** * Getter for links */ public List getLinks() { return links; } - + /** * Setter for links; */ @@ -244,113 +262,129 @@ public void setLinks(List links) { this.links = links; } - - /** * Get call for Payment. + * * @param accessToken - * AccessToken used for the API call + * AccessToken used for the API call * @param containerMap - * Map containing the query strings with the - * following values as keys: - * count, - * start_id, - * start_index, - * start_time, - * end_time, - * payee_id, - * sort_by, - * sort_order, - * All other keys in the map are ignored by the SDK + * Map containing the query strings with the following values as + * keys: count, start_id, start_index, start_time, end_time, + * payee_id, sort_by, sort_order, All other keys in the map are + * ignored by the SDK * @HttpMethod GET - * @URIpath v1/payments/payment?count=:count&start_id=:start_id&start_index=:start_index&start_time=:start_time&end_time=:end_time&payee_id=:payee_id&sort_by=:sort_by&sort_order=:sort_order + * @URIpath + * v1/payments/payment?count=:count&start_id=:start_id&start_index=: + * start_index + * &start_time=:start_time&end_time=:end_time&payee_id=:payee_id + * &sort_by=:sort_by&sort_order=:sort_order * @return PaymentHistory */ - public static PaymentHistory get(String accessToken, Map containerMap) throws PayPalRESTException { + public static PaymentHistory get(String accessToken, + Map containerMap) throws PayPalRESTException { String pattern = "v1/payments/payment?count={0}&start_id={1}&start_index={2}&start_time={3}&end_time={4}&payee_id={5}&sort_by={6}&sort_order={7}"; Object[] parameters = new Object[] { containerMap }; String resourcePath = RESTUtil.formatURIPath(pattern, parameters); String payLoad = ""; APIContext apiContext = new APIContext(accessToken); - return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, PaymentHistory.class); + return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, + resourcePath, payLoad, PaymentHistory.class); } - + /** * Get call for Payment. + * * @param apiContext - * {@link APIContext} to be used for the call. + * {@link APIContext} to be used for the call. * @param containerMap - * Map containing the query strings with the - * following values as keys: - * count, - * start_id, - * start_index, - * start_time, - * end_time, - * payee_id, - * sort_by, - * sort_order, - * All other keys in the map are ignored by the SDK + * Map containing the query strings with the following values as + * keys: count, start_id, start_index, start_time, end_time, + * payee_id, sort_by, sort_order, All other keys in the map are + * ignored by the SDK * @HttpMethod GET - * @URIpath v1/payments/payment?count=:count&start_id=:start_id&start_index=:start_index&start_time=:start_time&end_time=:end_time&payee_id=:payee_id&sort_by=:sort_by&sort_order=:sort_order + * @URIpath + * v1/payments/payment?count=:count&start_id=:start_id&start_index=: + * start_index + * &start_time=:start_time&end_time=:end_time&payee_id=:payee_id + * &sort_by=:sort_by&sort_order=:sort_order * @return PaymentHistory */ - public static PaymentHistory get(APIContext apiContext, Map containerMap) throws PayPalRESTException { + public static PaymentHistory get(APIContext apiContext, + Map containerMap) throws PayPalRESTException { String pattern = "v1/payments/payment?count={0}&start_id={1}&start_index={2}&start_time={3}&end_time={4}&payee_id={5}&sort_by={6}&sort_order={7}"; Object[] parameters = new Object[] { containerMap }; String resourcePath = RESTUtil.formatURIPath(pattern, parameters); String payLoad = ""; - if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { - throw new IllegalArgumentException("AccessToken cannot be null in APIContext"); + if (apiContext.getAccessToken() == null + || apiContext.getAccessToken().trim().length() <= 0) { + throw new IllegalArgumentException( + "AccessToken cannot be null in APIContext"); } - return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, PaymentHistory.class); + return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, + resourcePath, payLoad, PaymentHistory.class); } - /** * Get call for Payment. + * * @param accessToken - * AccessToken used for the API call + * AccessToken used for the API call * @param queryParameters - * Container for query strings + * Container for query strings * @HttpMethod GET - * @URIpath v1/payments/payment?count=:count&start_id=:start_id&start_index=:start_index&start_time=:start_time&end_time=:end_time&payee_id=:payee_id&sort_by=:sort_by&sort_order=:sort_order + * @URIpath + * v1/payments/payment?count=:count&start_id=:start_id&start_index=: + * start_index + * &start_time=:start_time&end_time=:end_time&payee_id=:payee_id + * &sort_by=:sort_by&sort_order=:sort_order * @return PaymentHistory */ - public static PaymentHistory get(String accessToken, QueryParameters queryParameters) throws PayPalRESTException { + public static PaymentHistory get(String accessToken, + QueryParameters queryParameters) throws PayPalRESTException { String pattern = "v1/payments/payment?count={0}&start_id={1}&start_index={2}&start_time={3}&end_time={4}&payee_id={5}&sort_by={6}&sort_order={7}"; Object[] parameters = new Object[] { queryParameters }; String resourcePath = RESTUtil.formatURIPath(pattern, parameters); String payLoad = ""; APIContext apiContext = new APIContext(accessToken); - return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, PaymentHistory.class); + return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, + resourcePath, payLoad, PaymentHistory.class); } - + /** * Get call for Payment. + * * @param apiContext - * {@link APIContext} to be used for the call. + * {@link APIContext} to be used for the call. * @param queryParameters - * Container for query strings + * Container for query strings * @HttpMethod GET - * @URIpath v1/payments/payment?count=:count&start_id=:start_id&start_index=:start_index&start_time=:start_time&end_time=:end_time&payee_id=:payee_id&sort_by=:sort_by&sort_order=:sort_order + * @URIpath + * v1/payments/payment?count=:count&start_id=:start_id&start_index=: + * start_index + * &start_time=:start_time&end_time=:end_time&payee_id=:payee_id + * &sort_by=:sort_by&sort_order=:sort_order * @return PaymentHistory */ - public static PaymentHistory get(APIContext apiContext, QueryParameters queryParameters) throws PayPalRESTException { + public static PaymentHistory get(APIContext apiContext, + QueryParameters queryParameters) throws PayPalRESTException { String pattern = "v1/payments/payment?count={0}&start_id={1}&start_index={2}&start_time={3}&end_time={4}&payee_id={5}&sort_by={6}&sort_order={7}"; Object[] parameters = new Object[] { queryParameters }; String resourcePath = RESTUtil.formatURIPath(pattern, parameters); String payLoad = ""; - if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { - throw new IllegalArgumentException("AccessToken cannot be null in APIContext"); + if (apiContext.getAccessToken() == null + || apiContext.getAccessToken().trim().length() <= 0) { + throw new IllegalArgumentException( + "AccessToken cannot be null in APIContext"); } - return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, PaymentHistory.class); + return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, + resourcePath, payLoad, PaymentHistory.class); } /** * Create call for Payment. + * * @param accessToken - * AccessToken used for the API call + * AccessToken used for the API call * @HttpMethod POST * @URIpath v1/payments/payment * @return Payment @@ -359,91 +393,108 @@ public Payment create(String accessToken) throws PayPalRESTException { APIContext apiContext = new APIContext(accessToken); return create(apiContext); } - + /** * Create call for Payment. + * * @param apiContext - * APIContext used for the API call + * APIContext used for the API call * @HttpMethod POST * @URIpath v1/payments/payment * @return Payment */ public Payment create(APIContext apiContext) throws PayPalRESTException { String resourcePath = "v1/payments/payment"; - String payLoad = this.toJSON(); - return PayPalResource.configureAndExecute(apiContext, HttpMethod.POST, resourcePath, payLoad, Payment.class); + String payLoad = this.toJSON(); + return PayPalResource.configureAndExecute(apiContext, HttpMethod.POST, + resourcePath, payLoad, Payment.class); } /** * Get call for Payment. + * * @param accessToken - * AccessToken used for the API call + * AccessToken used for the API call * @param paymentId * @HttpMethod GET * @URIpath v1/payments/payment/:paymentId * @return Payment */ - public static Payment get(String accessToken, String paymentId) throws PayPalRESTException { + public static Payment get(String accessToken, String paymentId) + throws PayPalRESTException { if ((paymentId == null) || (paymentId.length() <= 0)) { - throw new IllegalArgumentException("paymentId cannot be null or empty"); + throw new IllegalArgumentException( + "paymentId cannot be null or empty"); } String pattern = "v1/payments/payment/{0}"; - Object[] parameters = new Object[] { paymentId }; + Object[] parameters = new Object[] { paymentId }; String resourcePath = RESTUtil.formatURIPath(pattern, parameters); String payLoad = ""; APIContext apiContext = new APIContext(accessToken); - return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, Payment.class); + return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, + resourcePath, payLoad, Payment.class); } - + /** * Get call for Payment. + * * @param apiContext - * {@link APIContext} to be used for the call. + * {@link APIContext} to be used for the call. * @param paymentId * @HttpMethod GET * @URIpath v1/payments/payment/:paymentId * @return Payment */ - public static Payment get(APIContext apiContext, String paymentId) throws PayPalRESTException { + public static Payment get(APIContext apiContext, String paymentId) + throws PayPalRESTException { if ((paymentId == null) || (paymentId.length() <= 0)) { - throw new IllegalArgumentException("paymentId cannot be null or empty"); + throw new IllegalArgumentException( + "paymentId cannot be null or empty"); } String pattern = "v1/payments/payment/{0}"; - Object[] parameters = new Object[] { paymentId }; + Object[] parameters = new Object[] { paymentId }; String resourcePath = RESTUtil.formatURIPath(pattern, parameters); String payLoad = ""; - if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { - throw new IllegalArgumentException("AccessToken cannot be null in APIContext"); + if (apiContext.getAccessToken() == null + || apiContext.getAccessToken().trim().length() <= 0) { + throw new IllegalArgumentException( + "AccessToken cannot be null in APIContext"); } - return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, Payment.class); + return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, + resourcePath, payLoad, Payment.class); } /** * Execute call for Payment. + * * @param accessToken - * AccessToken used for the API call + * AccessToken used for the API call * @param paymentExecution * @HttpMethod POST * @URIpath v1/payments/payment/:paymentId/execute * @return Payment */ - public Payment execute(String accessToken, PaymentExecution paymentExecution) throws PayPalRESTException { + public Payment execute(String accessToken, PaymentExecution paymentExecution) + throws PayPalRESTException { APIContext apiContext = new APIContext(accessToken); return execute(apiContext, paymentExecution); } - + /** * Execute call for Payment. + * * @param apiContext - * APIContext used for the API call + * APIContext used for the API call * @param paymentExecution * @HttpMethod POST * @URIpath v1/payments/payment/:paymentId/execute * @return Payment */ - public Payment execute(APIContext apiContext, PaymentExecution paymentExecution) throws PayPalRESTException { + public Payment execute(APIContext apiContext, + PaymentExecution paymentExecution) throws PayPalRESTException { if (paymentExecution == null) { - throw new IllegalArgumentException("paymentExecution cannot be null"); + throw new IllegalArgumentException( + "paymentExecution cannot be null"); } if (this.getId() == null) { throw new IllegalArgumentException("Id cannot be null"); @@ -451,8 +502,9 @@ public Payment execute(APIContext apiContext, PaymentExecution paymentExecution) String pattern = "v1/payments/payment/{0}/execute"; Object[] parameters = new Object[] { this.getId() }; String resourcePath = RESTUtil.formatURIPath(pattern, parameters); - String payLoad = paymentExecution.toJSON(); - return PayPalResource.configureAndExecute(apiContext, HttpMethod.POST, resourcePath, payLoad, Payment.class); + String payLoad = paymentExecution.toJSON(); + return PayPalResource.configureAndExecute(apiContext, HttpMethod.POST, + resourcePath, payLoad, Payment.class); } /** @@ -463,7 +515,7 @@ public Payment execute(APIContext apiContext, PaymentExecution paymentExecution) public String toJSON() { return JSONFormatter.toJSON(this); } - + @Override public String toString() { return toJSON(); From 5ee652aff4e957be824cb0251295cbfc6a0c56cd Mon Sep 17 00:00:00 2001 From: Kumarvel Jayakumar Date: Thu, 25 Apr 2013 11:36:29 +0530 Subject: [PATCH 15/30] Added additional test case for PaymentHistory class --- .../com/paypal/api/payments/PaymentTestCase.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/rest-api-sdk/src/test/java/com/paypal/api/payments/PaymentTestCase.java b/rest-api-sdk/src/test/java/com/paypal/api/payments/PaymentTestCase.java index c04f4842..5ef493a2 100644 --- a/rest-api-sdk/src/test/java/com/paypal/api/payments/PaymentTestCase.java +++ b/rest-api-sdk/src/test/java/com/paypal/api/payments/PaymentTestCase.java @@ -281,8 +281,21 @@ public void testGetPaymentHistoryAPI() throws PayPalRESTException { logger.info("Response = " + Payment.getLastResponse()); logger.info("Retrieved Payments count = " + paymentHistory.getCount()); } - + @Test(dependsOnMethods = { "testGetPaymentHistoryAPI" }) + public void testGetPaymentHistoryQueryParamsAPI() throws PayPalRESTException { + logger.info("**** Get Payment History ****"); + logger.info("Setting Access Token = " + TokenHolder.accessToken); + QueryParameters params = new QueryParameters(); + params.setCount("10"); + PaymentHistory paymentHistory = Payment.get(TokenHolder.accessToken, + params); + logger.info("Request = " + Payment.getLastRequest()); + logger.info("Response = " + Payment.getLastResponse()); + logger.info("Retrieved Payments count = " + paymentHistory.getCount()); + } + + @Test(dependsOnMethods = { "testGetPaymentHistoryQueryParamsAPI" }) public void testFailCreatePaymentAPI() { logger.info("**** Failing Create Payment ****"); logger.info("Setting Access Token = " + TokenHolder.accessToken); From b44ed1437b074061f48c6e56e5c6c1a947a3ba80 Mon Sep 17 00:00:00 2001 From: Kumarvel Jayakumar Date: Thu, 25 Apr 2013 12:14:05 +0530 Subject: [PATCH 16/30] Updated stubs for dynamic config --- .../com/paypal/api/payments/CreditCard.java | 3 + .../java/com/paypal/api/payments/Payment.java | 255 ++++++++---------- .../java/com/paypal/api/payments/Sale.java | 3 + 3 files changed, 112 insertions(+), 149 deletions(-) diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCard.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCard.java index cc485944..3a01711c 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCard.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCard.java @@ -337,6 +337,9 @@ public CreditCard create(String accessToken) throws PayPalRESTException { * @return CreditCard */ public CreditCard create(APIContext apiContext) throws PayPalRESTException { + if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { + throw new IllegalArgumentException("AccessToken cannot be null or empty"); + } String resourcePath = "v1/vault/credit-card"; String payLoad = this.toJSON(); return PayPalResource.configureAndExecute(apiContext, HttpMethod.POST, resourcePath, payLoad, CreditCard.class); diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Payment.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Payment.java index 4cb518c3..0c18a18b 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Payment.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Payment.java @@ -1,5 +1,4 @@ package com.paypal.api.payments; - import com.paypal.api.payments.Payer; import java.util.List; import com.paypal.api.payments.Transaction; @@ -23,53 +22,50 @@ */ public class Payment extends Resource { - public enum Intent { - SALE - } /** * - */ + */ private String id; /** * - */ + */ private String createTime; /** * - */ + */ private String updateTime; /** * - */ + */ private String state; /** * - */ + */ private String intent; /** * - */ + */ private Payer payer; /** * - */ + */ private List transactions; /** * - */ + */ private RedirectUrls redirectUrls; /** * - */ + */ private List links; /** @@ -89,7 +85,7 @@ public static String getLastRequest() { public static String getLastResponse() { return PayPalResource.getLastResponse(); } - + /** * Initialize using InputStream(of a Properties file) * @@ -121,13 +117,14 @@ public static void initConfig(File file) throws PayPalRESTException { public static void initConfig(Properties properties) { PayPalResource.initConfig(properties); } + /** * Constructor */ public Payment() { - } + } /** * Getter for id @@ -135,126 +132,111 @@ public Payment() { public String getId() { return id; } - + /** * Setter for id; */ public void setId(String id) { this.id = id; } - /** * Getter for createTime */ public String getCreateTime() { return createTime; } - + /** * Setter for createTime; */ public void setCreateTime(String createTime) { this.createTime = createTime; } - /** * Getter for updateTime */ public String getUpdateTime() { return updateTime; } - + /** * Setter for updateTime; */ public void setUpdateTime(String updateTime) { this.updateTime = updateTime; } - /** * Getter for state */ public String getState() { return state; } - + /** * Setter for state; */ public void setState(String state) { this.state = state; } - /** * Getter for intent */ public String getIntent() { return intent; } - + /** * Setter for intent; */ public void setIntent(String intent) { this.intent = intent; } - - /** - * Setter for intent; - */ - public void setIntent(Intent intent) { - this.intent = intent.toString().toLowerCase(); - } - /** * Getter for payer */ public Payer getPayer() { return payer; } - + /** * Setter for payer; */ public void setPayer(Payer payer) { this.payer = payer; } - /** * Getter for transactions */ public List getTransactions() { return transactions; } - + /** * Setter for transactions; */ public void setTransactions(List transactions) { this.transactions = transactions; } - /** * Getter for redirectUrls */ public RedirectUrls getRedirectUrls() { return redirectUrls; } - + /** * Setter for redirectUrls; */ public void setRedirectUrls(RedirectUrls redirectUrls) { this.redirectUrls = redirectUrls; } - /** * Getter for links */ public List getLinks() { return links; } - + /** * Setter for links; */ @@ -262,129 +244,116 @@ public void setLinks(List links) { this.links = links; } + + /** * Get call for Payment. - * * @param accessToken - * AccessToken used for the API call + * AccessToken used for the API call * @param containerMap - * Map containing the query strings with the following values as - * keys: count, start_id, start_index, start_time, end_time, - * payee_id, sort_by, sort_order, All other keys in the map are - * ignored by the SDK + * Map containing the query strings with the + * following values as keys: + * count, + * start_id, + * start_index, + * start_time, + * end_time, + * payee_id, + * sort_by, + * sort_order, + * All other keys in the map are ignored by the SDK * @HttpMethod GET - * @URIpath - * v1/payments/payment?count=:count&start_id=:start_id&start_index=: - * start_index - * &start_time=:start_time&end_time=:end_time&payee_id=:payee_id - * &sort_by=:sort_by&sort_order=:sort_order + * @URIpath v1/payments/payment?count=:count&start_id=:start_id&start_index=:start_index&start_time=:start_time&end_time=:end_time&payee_id=:payee_id&sort_by=:sort_by&sort_order=:sort_order * @return PaymentHistory */ - public static PaymentHistory get(String accessToken, - Map containerMap) throws PayPalRESTException { + public static PaymentHistory get(String accessToken, Map containerMap) throws PayPalRESTException { String pattern = "v1/payments/payment?count={0}&start_id={1}&start_index={2}&start_time={3}&end_time={4}&payee_id={5}&sort_by={6}&sort_order={7}"; Object[] parameters = new Object[] { containerMap }; String resourcePath = RESTUtil.formatURIPath(pattern, parameters); String payLoad = ""; APIContext apiContext = new APIContext(accessToken); - return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, - resourcePath, payLoad, PaymentHistory.class); + return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, PaymentHistory.class); } - + /** * Get call for Payment. - * * @param apiContext - * {@link APIContext} to be used for the call. + * {@link APIContext} to be used for the call. * @param containerMap - * Map containing the query strings with the following values as - * keys: count, start_id, start_index, start_time, end_time, - * payee_id, sort_by, sort_order, All other keys in the map are - * ignored by the SDK + * Map containing the query strings with the + * following values as keys: + * count, + * start_id, + * start_index, + * start_time, + * end_time, + * payee_id, + * sort_by, + * sort_order, + * All other keys in the map are ignored by the SDK * @HttpMethod GET - * @URIpath - * v1/payments/payment?count=:count&start_id=:start_id&start_index=: - * start_index - * &start_time=:start_time&end_time=:end_time&payee_id=:payee_id - * &sort_by=:sort_by&sort_order=:sort_order + * @URIpath v1/payments/payment?count=:count&start_id=:start_id&start_index=:start_index&start_time=:start_time&end_time=:end_time&payee_id=:payee_id&sort_by=:sort_by&sort_order=:sort_order * @return PaymentHistory */ - public static PaymentHistory get(APIContext apiContext, - Map containerMap) throws PayPalRESTException { + public static PaymentHistory get(APIContext apiContext, Map containerMap) throws PayPalRESTException { + if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { + throw new IllegalArgumentException("AccessToken cannot be null or empty"); + } String pattern = "v1/payments/payment?count={0}&start_id={1}&start_index={2}&start_time={3}&end_time={4}&payee_id={5}&sort_by={6}&sort_order={7}"; Object[] parameters = new Object[] { containerMap }; String resourcePath = RESTUtil.formatURIPath(pattern, parameters); String payLoad = ""; - if (apiContext.getAccessToken() == null - || apiContext.getAccessToken().trim().length() <= 0) { - throw new IllegalArgumentException( - "AccessToken cannot be null in APIContext"); + if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { + throw new IllegalArgumentException("AccessToken cannot be null in APIContext"); } - return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, - resourcePath, payLoad, PaymentHistory.class); + return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, PaymentHistory.class); } + /** * Get call for Payment. - * * @param accessToken - * AccessToken used for the API call + * AccessToken used for the API call * @param queryParameters - * Container for query strings + * Container for query strings * @HttpMethod GET - * @URIpath - * v1/payments/payment?count=:count&start_id=:start_id&start_index=: - * start_index - * &start_time=:start_time&end_time=:end_time&payee_id=:payee_id - * &sort_by=:sort_by&sort_order=:sort_order + * @URIpath v1/payments/payment?count=:count&start_id=:start_id&start_index=:start_index&start_time=:start_time&end_time=:end_time&payee_id=:payee_id&sort_by=:sort_by&sort_order=:sort_order * @return PaymentHistory */ - public static PaymentHistory get(String accessToken, - QueryParameters queryParameters) throws PayPalRESTException { + public static PaymentHistory get(String accessToken, QueryParameters queryParameters) throws PayPalRESTException { String pattern = "v1/payments/payment?count={0}&start_id={1}&start_index={2}&start_time={3}&end_time={4}&payee_id={5}&sort_by={6}&sort_order={7}"; Object[] parameters = new Object[] { queryParameters }; String resourcePath = RESTUtil.formatURIPath(pattern, parameters); String payLoad = ""; APIContext apiContext = new APIContext(accessToken); - return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, - resourcePath, payLoad, PaymentHistory.class); + return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, PaymentHistory.class); } - + /** * Get call for Payment. - * * @param apiContext - * {@link APIContext} to be used for the call. + * {@link APIContext} to be used for the call. * @param queryParameters - * Container for query strings + * Container for query strings * @HttpMethod GET - * @URIpath - * v1/payments/payment?count=:count&start_id=:start_id&start_index=: - * start_index - * &start_time=:start_time&end_time=:end_time&payee_id=:payee_id - * &sort_by=:sort_by&sort_order=:sort_order + * @URIpath v1/payments/payment?count=:count&start_id=:start_id&start_index=:start_index&start_time=:start_time&end_time=:end_time&payee_id=:payee_id&sort_by=:sort_by&sort_order=:sort_order * @return PaymentHistory */ - public static PaymentHistory get(APIContext apiContext, - QueryParameters queryParameters) throws PayPalRESTException { + public static PaymentHistory get(APIContext apiContext, QueryParameters queryParameters) throws PayPalRESTException { String pattern = "v1/payments/payment?count={0}&start_id={1}&start_index={2}&start_time={3}&end_time={4}&payee_id={5}&sort_by={6}&sort_order={7}"; Object[] parameters = new Object[] { queryParameters }; String resourcePath = RESTUtil.formatURIPath(pattern, parameters); String payLoad = ""; - if (apiContext.getAccessToken() == null - || apiContext.getAccessToken().trim().length() <= 0) { - throw new IllegalArgumentException( - "AccessToken cannot be null in APIContext"); + if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { + throw new IllegalArgumentException("AccessToken cannot be null in APIContext"); } - return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, - resourcePath, payLoad, PaymentHistory.class); + return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, PaymentHistory.class); } /** * Create call for Payment. - * * @param accessToken - * AccessToken used for the API call + * AccessToken used for the API call * @HttpMethod POST * @URIpath v1/payments/payment * @return Payment @@ -393,108 +362,97 @@ public Payment create(String accessToken) throws PayPalRESTException { APIContext apiContext = new APIContext(accessToken); return create(apiContext); } - + /** * Create call for Payment. - * * @param apiContext - * APIContext used for the API call + * APIContext used for the API call * @HttpMethod POST * @URIpath v1/payments/payment * @return Payment */ public Payment create(APIContext apiContext) throws PayPalRESTException { + if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { + throw new IllegalArgumentException("AccessToken cannot be null or empty"); + } String resourcePath = "v1/payments/payment"; - String payLoad = this.toJSON(); - return PayPalResource.configureAndExecute(apiContext, HttpMethod.POST, - resourcePath, payLoad, Payment.class); + String payLoad = this.toJSON(); + return PayPalResource.configureAndExecute(apiContext, HttpMethod.POST, resourcePath, payLoad, Payment.class); } /** * Get call for Payment. - * * @param accessToken - * AccessToken used for the API call + * AccessToken used for the API call * @param paymentId * @HttpMethod GET * @URIpath v1/payments/payment/:paymentId * @return Payment */ - public static Payment get(String accessToken, String paymentId) - throws PayPalRESTException { + public static Payment get(String accessToken, String paymentId) throws PayPalRESTException { if ((paymentId == null) || (paymentId.length() <= 0)) { - throw new IllegalArgumentException( - "paymentId cannot be null or empty"); + throw new IllegalArgumentException("paymentId cannot be null or empty"); } String pattern = "v1/payments/payment/{0}"; - Object[] parameters = new Object[] { paymentId }; + Object[] parameters = new Object[] { paymentId }; String resourcePath = RESTUtil.formatURIPath(pattern, parameters); String payLoad = ""; APIContext apiContext = new APIContext(accessToken); - return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, - resourcePath, payLoad, Payment.class); + return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, Payment.class); } - + /** * Get call for Payment. - * * @param apiContext - * {@link APIContext} to be used for the call. + * {@link APIContext} to be used for the call. * @param paymentId * @HttpMethod GET * @URIpath v1/payments/payment/:paymentId * @return Payment */ - public static Payment get(APIContext apiContext, String paymentId) - throws PayPalRESTException { + public static Payment get(APIContext apiContext, String paymentId) throws PayPalRESTException { if ((paymentId == null) || (paymentId.length() <= 0)) { - throw new IllegalArgumentException( - "paymentId cannot be null or empty"); + throw new IllegalArgumentException("paymentId cannot be null or empty"); } String pattern = "v1/payments/payment/{0}"; - Object[] parameters = new Object[] { paymentId }; + Object[] parameters = new Object[] { paymentId }; String resourcePath = RESTUtil.formatURIPath(pattern, parameters); String payLoad = ""; - if (apiContext.getAccessToken() == null - || apiContext.getAccessToken().trim().length() <= 0) { - throw new IllegalArgumentException( - "AccessToken cannot be null in APIContext"); + if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { + throw new IllegalArgumentException("AccessToken cannot be null in APIContext"); } - return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, - resourcePath, payLoad, Payment.class); + return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, Payment.class); } /** * Execute call for Payment. - * * @param accessToken - * AccessToken used for the API call + * AccessToken used for the API call * @param paymentExecution * @HttpMethod POST * @URIpath v1/payments/payment/:paymentId/execute * @return Payment */ - public Payment execute(String accessToken, PaymentExecution paymentExecution) - throws PayPalRESTException { + public Payment execute(String accessToken, PaymentExecution paymentExecution) throws PayPalRESTException { APIContext apiContext = new APIContext(accessToken); return execute(apiContext, paymentExecution); } - + /** * Execute call for Payment. - * * @param apiContext - * APIContext used for the API call + * APIContext used for the API call * @param paymentExecution * @HttpMethod POST * @URIpath v1/payments/payment/:paymentId/execute * @return Payment */ - public Payment execute(APIContext apiContext, - PaymentExecution paymentExecution) throws PayPalRESTException { + public Payment execute(APIContext apiContext, PaymentExecution paymentExecution) throws PayPalRESTException { + if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { + throw new IllegalArgumentException("AccessToken cannot be null or empty"); + } if (paymentExecution == null) { - throw new IllegalArgumentException( - "paymentExecution cannot be null"); + throw new IllegalArgumentException("paymentExecution cannot be null"); } if (this.getId() == null) { throw new IllegalArgumentException("Id cannot be null"); @@ -502,9 +460,8 @@ public Payment execute(APIContext apiContext, String pattern = "v1/payments/payment/{0}/execute"; Object[] parameters = new Object[] { this.getId() }; String resourcePath = RESTUtil.formatURIPath(pattern, parameters); - String payLoad = paymentExecution.toJSON(); - return PayPalResource.configureAndExecute(apiContext, HttpMethod.POST, - resourcePath, payLoad, Payment.class); + String payLoad = paymentExecution.toJSON(); + return PayPalResource.configureAndExecute(apiContext, HttpMethod.POST, resourcePath, payLoad, Payment.class); } /** @@ -515,7 +472,7 @@ public Payment execute(APIContext apiContext, public String toJSON() { return JSONFormatter.toJSON(this); } - + @Override public String toString() { return toJSON(); diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Sale.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Sale.java index 0fbe2606..19d0a17e 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Sale.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Sale.java @@ -275,6 +275,9 @@ public Refund refund(String accessToken, Refund refund) throws PayPalRESTExcepti * @return Refund */ public Refund refund(APIContext apiContext, Refund refund) throws PayPalRESTException { + if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { + throw new IllegalArgumentException("AccessToken cannot be null or empty"); + } if (refund == null) { throw new IllegalArgumentException("refund cannot be null"); } From 8d5e4bce8be4b46613357b014c2e34c44a316860 Mon Sep 17 00:00:00 2001 From: kumaravel-jayakumar Date: Thu, 25 Apr 2013 18:19:25 +0530 Subject: [PATCH 17/30] Update CHANGELOG.md Updated change log for rest-api-sdk-java version 0.6.0 --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33d10cd9..1fd790f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,3 +6,8 @@ V0.5.2 (March 07, 2013) * Initial Release +V0.6.0 (April 26, 2013) +----------------------- + + * Added dynamic configuration support for API calls + From 0a8ae81e6485ea922153cd3b7a60037193fae546 Mon Sep 17 00:00:00 2001 From: kumaravel jayakumar Date: Fri, 24 May 2013 16:50:08 +0530 Subject: [PATCH 18/30] Update stubs against new schema --- rest-api-sdk/pom.xml | 2 +- .../java/com/paypal/api/payments/Address.java | 199 ++++---- .../java/com/paypal/api/payments/Amount.java | 100 ++-- .../paypal/api/payments/Authorization.java | 322 +++++++++--- .../java/com/paypal/api/payments/Capture.java | 294 +++++++---- .../com/paypal/api/payments/CreditCard.java | 440 +++++++++------- .../api/payments/CreditCardHistory.java | 98 ++++ .../paypal/api/payments/CreditCardToken.java | 141 +++++- .../{AmountDetails.java => Details.java} | 112 +++-- .../api/payments/FundingInstrument.java | 68 +-- .../com/paypal/api/payments/HyperSchema.java | 158 ++++++ .../java/com/paypal/api/payments/Item.java | 142 +++--- .../com/paypal/api/payments/ItemList.java | 70 +-- .../java/com/paypal/api/payments/Link.java | 90 ---- .../java/com/paypal/api/payments/Links.java | 165 ++++++ .../java/com/paypal/api/payments/Payee.java | 97 ++-- .../java/com/paypal/api/payments/Payer.java | 99 ++-- .../com/paypal/api/payments/PayerInfo.java | 148 +++--- .../java/com/paypal/api/payments/Payment.java | 470 +++++++++--------- .../paypal/api/payments/PaymentExecution.java | 77 +-- .../paypal/api/payments/PaymentHistory.java | 92 ++-- .../com/paypal/api/payments/RedirectUrls.java | 66 +-- .../java/com/paypal/api/payments/Refund.java | 254 +++++----- ...Transaction.java => RelatedResources.java} | 114 +++-- .../com/paypal/api/payments/Resource.java | 35 -- .../java/com/paypal/api/payments/Sale.java | 238 +++++---- .../paypal/api/payments/ShippingAddress.java | 50 +- .../com/paypal/api/payments/Transaction.java | 147 ++++-- .../com/paypal/api/payments/Transactions.java | 64 +++ .../paypal/api/payments/AmountTestCase.java | 6 +- .../api/payments/AuthorizationTestCase.java | 4 +- .../paypal/api/payments/CaptureTestCase.java | 6 +- .../api/payments/CreditCardTestCase.java | 8 +- ...ailsTestCase.java => DetailsTestCase.java} | 12 +- .../{LinkTestCase.java => LinksTestCase.java} | 12 +- .../payments/PaymentExecutionTestCase.java | 8 +- .../api/payments/PaymentHistoryTestCase.java | 2 +- .../paypal/api/payments/PaymentTestCase.java | 130 ++--- .../paypal/api/payments/RefundTestCase.java | 4 +- ...ase.java => RelatedResourcesTestCase.java} | 12 +- .../paypal/api/payments/ResourceTestCase.java | 25 - .../com/paypal/api/payments/SaleTestCase.java | 6 +- .../api/payments/TransactionTestCase.java | 4 +- .../api/payments/TransactionsTestCase.java | 35 ++ .../src/test/resources/sdk_config.properties | 7 +- 45 files changed, 2788 insertions(+), 1845 deletions(-) create mode 100644 rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCardHistory.java rename rest-api-sdk/src/main/java/com/paypal/api/payments/{AmountDetails.java => Details.java} (53%) create mode 100644 rest-api-sdk/src/main/java/com/paypal/api/payments/HyperSchema.java delete mode 100644 rest-api-sdk/src/main/java/com/paypal/api/payments/Link.java create mode 100644 rest-api-sdk/src/main/java/com/paypal/api/payments/Links.java rename rest-api-sdk/src/main/java/com/paypal/api/payments/{SubTransaction.java => RelatedResources.java} (61%) delete mode 100644 rest-api-sdk/src/main/java/com/paypal/api/payments/Resource.java create mode 100644 rest-api-sdk/src/main/java/com/paypal/api/payments/Transactions.java rename rest-api-sdk/src/test/java/com/paypal/api/payments/{AmountDetailsTestCase.java => DetailsTestCase.java} (75%) rename rest-api-sdk/src/test/java/com/paypal/api/payments/{LinkTestCase.java => LinksTestCase.java} (76%) rename rest-api-sdk/src/test/java/com/paypal/api/payments/{SubTransactionTestCase.java => RelatedResourcesTestCase.java} (77%) delete mode 100644 rest-api-sdk/src/test/java/com/paypal/api/payments/ResourceTestCase.java create mode 100644 rest-api-sdk/src/test/java/com/paypal/api/payments/TransactionsTestCase.java diff --git a/rest-api-sdk/pom.xml b/rest-api-sdk/pom.xml index b2eee159..b0188de6 100644 --- a/rest-api-sdk/pom.xml +++ b/rest-api-sdk/pom.xml @@ -36,7 +36,7 @@ com.paypal.sdk paypal-core - 1.4 + 1.4.3 diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Address.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Address.java index 29974d5d..ac955fcd 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Address.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Address.java @@ -1,168 +1,194 @@ package com.paypal.api.payments; -import com.paypal.api.payments.Resource; -import com.paypal.core.rest.JSONFormatter; -/** - * - */ -public class Address extends Resource { +import com.paypal.core.rest.JSONFormatter; +import java.util.Map; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; +import com.paypal.core.rest.HttpMethod; +import com.paypal.core.rest.RESTUtil; +import com.paypal.core.rest.QueryParameters; +import com.paypal.core.rest.APIContext; +import java.io.File; +import java.io.InputStream; +import java.util.Properties; +public class Address { /** - * - */ + * Line 1 of the Address (eg. number, street, etc). + */ private String line1; - + /** - * - */ + * Optional line 2 of the Address (eg. suite, apt #, etc.). + */ private String line2; - + /** - * - */ + * City name. + */ private String city; - + /** - * - */ - private String state; - + * 2 letter country code. + */ + private String countryCode; + /** - * - */ + * Zip code or equivalent is usually required for countries that have them. For list of countries that do not have postal codes please refer to http://en.wikipedia.org/wiki/Postal_code. + */ private String postalCode; - + /** - * - */ - private String countryCode; - + * 2 letter code for US states, and the equivalent for other countries. + */ + private String state; + /** - * - */ - private String type; - + * Phone number in E.123 format. + */ + private String phone; + /** * */ - private String phone; - + private String type; + /** - * Constructor + * Default Constructor */ public Address() { - - } + } /** - * Getter for line1 + * Parameterized Constructor */ - public String getLine1() { - return line1; + public Address(String line1, String city, String countryCode, String state) { + this.line1 = line1; + this.city = city; + this.countryCode = countryCode; + this.state = state; } + /** - * Setter for line1; + * Setter for line1 */ public void setLine1(String line1) { this.line1 = line1; } + /** - * Getter for line2 + * Getter for line1 */ - public String getLine2() { - return line2; + public String getLine1() { + return this.line1; } - + + /** - * Setter for line2; + * @return the type */ - public void setLine2(String line2) { - this.line2 = line2; + public String getType() { + return type; } + /** - * Getter for city + * @param type the type to set */ - public String getCity() { - return city; + public void setType(String type) { + this.type = type; + } + + /** + * Setter for line2 + */ + public void setLine2(String line2) { + this.line2 = line2; } /** - * Setter for city; + * Getter for line2 */ - public void setCity(String city) { - this.city = city; + public String getLine2() { + return this.line2; } + + /** - * Getter for state + * Setter for city */ - public String getState() { - return state; + public void setCity(String city) { + this.city = city; } /** - * Setter for state; + * Getter for city */ - public void setState(String state) { - this.state = state; + public String getCity() { + return this.city; } + + /** - * Getter for postalCode + * Setter for countryCode */ - public String getPostalCode() { - return postalCode; + public void setCountryCode(String countryCode) { + this.countryCode = countryCode; } /** - * Setter for postalCode; + * Getter for countryCode */ - public void setPostalCode(String postalCode) { - this.postalCode = postalCode; + public String getCountryCode() { + return this.countryCode; } + + /** - * Getter for countryCode + * Setter for postalCode */ - public String getCountryCode() { - return countryCode; + public void setPostalCode(String postalCode) { + this.postalCode = postalCode; } /** - * Setter for countryCode; + * Getter for postalCode */ - public void setCountryCode(String countryCode) { - this.countryCode = countryCode; + public String getPostalCode() { + return this.postalCode; } + + /** - * Getter for type + * Setter for state */ - public String getType() { - return type; + public void setState(String state) { + this.state = state; } /** - * Setter for type; + * Getter for state */ - public void setType(String type) { - this.type = type; + public String getState() { + return this.state; } + + /** - * Getter for phone + * Setter for phone */ - public String getPhone() { - return phone; + public void setPhone(String phone) { + this.phone = phone; } /** - * Setter for phone; + * Getter for phone */ - public void setPhone(String phone) { - this.phone = phone; + public String getPhone() { + return this.phone; } - - - /** * Returns a JSON string corresponding to object state * @@ -171,10 +197,9 @@ public void setPhone(String phone) { public String toJSON() { return JSONFormatter.toJSON(this); } - + @Override public String toString() { return toJSON(); } - } \ No newline at end of file diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Amount.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Amount.java index b45f947f..5ae31563 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Amount.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Amount.java @@ -1,79 +1,94 @@ package com.paypal.api.payments; -import com.paypal.api.payments.AmountDetails; -import com.paypal.api.payments.Resource; -import com.paypal.core.rest.JSONFormatter; -/** - * - */ -public class Amount extends Resource { +import com.paypal.core.rest.JSONFormatter; +import com.paypal.api.payments.Details; +import java.util.Map; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; +import com.paypal.core.rest.HttpMethod; +import com.paypal.core.rest.RESTUtil; +import com.paypal.core.rest.QueryParameters; +import com.paypal.core.rest.APIContext; +import java.io.File; +import java.io.InputStream; +import java.util.Properties; +public class Amount { /** - * - */ - private String total; - - /** - * - */ + * 3 letter currency code + */ private String currency; - + /** - * - */ - private AmountDetails details; - + * Total amount charged from the Payer account (or card) to Payee. In case of a refund, this is the refunded amount to the original Payer from Payee account. + */ + private String total; + + /** + * Additional details of the payment amount. + */ + private Details details; + /** - * Constructor + * Default Constructor */ public Amount() { - - } + } /** - * Getter for total + * Parameterized Constructor */ - public String getTotal() { - return total; + public Amount(String currency, String total) { + this.currency = currency; + this.total = total; } + /** - * Setter for total; + * Setter for currency */ - public void setTotal(String total) { - this.total = total; + public void setCurrency(String currency) { + this.currency = currency; } + /** * Getter for currency */ public String getCurrency() { - return currency; + return this.currency; + } + + + /** + * Setter for total + */ + public void setTotal(String total) { + this.total = total; } /** - * Setter for currency; + * Getter for total */ - public void setCurrency(String currency) { - this.currency = currency; + public String getTotal() { + return this.total; } + + /** - * Getter for details + * Setter for details */ - public AmountDetails getDetails() { - return details; + public void setDetails(Details details) { + this.details = details; } /** - * Setter for details; + * Getter for details */ - public void setDetails(AmountDetails details) { - this.details = details; + public Details getDetails() { + return this.details; } - - - /** * Returns a JSON string corresponding to object state * @@ -82,10 +97,9 @@ public void setDetails(AmountDetails details) { public String toJSON() { return JSONFormatter.toJSON(this); } - + @Override public String toString() { return toJSON(); } - } \ No newline at end of file diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Authorization.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Authorization.java index c778523e..d889e992 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Authorization.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Authorization.java @@ -1,153 +1,344 @@ package com.paypal.api.payments; + +import com.paypal.core.rest.JSONFormatter; import com.paypal.api.payments.Amount; +import com.paypal.api.payments.Links; import java.util.List; -import com.paypal.api.payments.Link; -import com.paypal.api.payments.Resource; -import com.paypal.core.rest.JSONFormatter; - -/** - * - */ -public class Authorization extends Resource { +import java.util.Map; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; +import com.paypal.core.rest.HttpMethod; +import com.paypal.core.rest.RESTUtil; +import com.paypal.core.rest.QueryParameters; +import com.paypal.core.rest.APIContext; +import java.io.File; +import java.io.InputStream; +import java.util.Properties; +public class Authorization { /** - * - */ + * Identifier of the authorization transaction. + */ private String id; - + /** - * - */ + * Time the resource was created. + */ private String createTime; - + /** - * - */ + * Time the resource was last updated. + */ private String updateTime; - + /** - * - */ + * Amount being authorized for. + */ + private Amount amount; + + /** + * State of the authorization transaction. + */ private String state; + + /** + * ID of the Payment resource that this transaction is based on. + */ + private String parentPayment; + + /** + * Date/Time until which funds may be captured against this resource. + */ + private String validUntil; + + /** + * + */ + private List links; + + /** + * Returns the last request sent to the Service + * + * @return Last request sent to the server + */ + public static String getLastRequest() { + return PayPalResource.getLastRequest(); + } /** + * Returns the last response returned by the Service * - */ - private Amount amount; + * @return Last response got from the Service + */ + public static String getLastResponse() { + return PayPalResource.getLastResponse(); + } /** + * Initialize using InputStream(of a Properties file) * - */ - private String parentPayment; + * @param is + * InputStream + * @throws PayPalRESTException + */ + public static void initConfig(InputStream is) throws PayPalRESTException { + PayPalResource.initConfig(is); + } /** + * Initialize using a File(Properties file) * - */ - private List links; + * @param file + * File object of a properties entity + * @throws PayPalRESTException + */ + public static void initConfig(File file) throws PayPalRESTException { + PayPalResource.initConfig(file); + } /** - * Constructor + * Initialize using Properties + * + * @param properties + * Properties object + */ + public static void initConfig(Properties properties) { + PayPalResource.initConfig(properties); + } + /** + * Default Constructor */ public Authorization() { + } - } + /** + * Setter for id + */ + public void setId(String id) { + this.id = id; + } + /** * Getter for id */ public String getId() { - return id; + return this.id; } - + + /** - * Setter for id; + * Setter for createTime */ - public void setId(String id) { - this.id = id; + public void setCreateTime(String createTime) { + this.createTime = createTime; } + /** * Getter for createTime */ public String getCreateTime() { - return createTime; + return this.createTime; } - + + /** - * Setter for createTime; + * Setter for updateTime */ - public void setCreateTime(String createTime) { - this.createTime = createTime; + public void setUpdateTime(String updateTime) { + this.updateTime = updateTime; } + /** * Getter for updateTime */ public String getUpdateTime() { - return updateTime; + return this.updateTime; } - + + /** - * Setter for updateTime; + * Setter for amount */ - public void setUpdateTime(String updateTime) { - this.updateTime = updateTime; + public void setAmount(Amount amount) { + this.amount = amount; } + /** - * Getter for state + * Getter for amount */ - public String getState() { - return state; + public Amount getAmount() { + return this.amount; } - + + /** - * Setter for state; + * Setter for state */ public void setState(String state) { this.state = state; } + /** - * Getter for amount + * Getter for state */ - public Amount getAmount() { - return amount; + public String getState() { + return this.state; } - + + /** - * Setter for amount; + * Setter for parentPayment */ - public void setAmount(Amount amount) { - this.amount = amount; + public void setParentPayment(String parentPayment) { + this.parentPayment = parentPayment; } + /** * Getter for parentPayment */ public String getParentPayment() { - return parentPayment; + return this.parentPayment; + } + + + /** + * Setter for validUntil + */ + public void setValidUntil(String validUntil) { + this.validUntil = validUntil; } /** - * Setter for parentPayment; + * Getter for validUntil */ - public void setParentPayment(String parentPayment) { - this.parentPayment = parentPayment; + public String getValidUntil() { + return this.validUntil; } + + /** - * Getter for links + * Setter for links */ - public List getLinks() { - return links; + public void setLinks(List links) { + this.links = links; } /** - * Setter for links; + * Getter for links */ - public void setLinks(List links) { - this.links = links; + public List getLinks() { + return this.links; } + /** + * Obtain the Authorization transaction resource for the given identifier. + */ + public static Authorization get(String accessToken, String authorizationId) throws PayPalRESTException { + APIContext apiContext = new APIContext(accessToken); + return get(apiContext, authorizationId); + } + + /** + * Obtain the Authorization transaction resource for the given identifier. + */ + public static Authorization get(APIContext apiContext, String authorizationId) throws PayPalRESTException { + if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { + throw new IllegalArgumentException("AccessToken cannot be null or empty"); + } + if (authorizationId == null) { + throw new IllegalArgumentException("authorizationId cannot be null"); + } + Object[] parameters = new Object[] {authorizationId}; + String pattern = "v1/payments/authorization/{0}"; + String resourcePath = RESTUtil.formatURIPath(pattern, parameters); + String payLoad = ""; + return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, Authorization.class); + } + + /** + * Creates (and processes) a new Capture Transaction added as a related resource. + */ + public Capture capture(String accessToken, Capture capture) throws PayPalRESTException { + APIContext apiContext = new APIContext(accessToken); + return capture(apiContext, capture); + } + + /** + * Creates (and processes) a new Capture Transaction added as a related resource. + */ + public Capture capture(APIContext apiContext, Capture capture) throws PayPalRESTException { + if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { + throw new IllegalArgumentException("AccessToken cannot be null or empty"); + } + if (this.getId() == null) { + throw new IllegalArgumentException("Id cannot be null"); + } + if (capture == null) { + throw new IllegalArgumentException("capture cannot be null"); + } + Object[] parameters = new Object[] {this.getId()}; + String pattern = "v1/payments/authorization/{0}/capture"; + String resourcePath = RESTUtil.formatURIPath(pattern, parameters); + String payLoad = capture.toJSON(); + return PayPalResource.configureAndExecute(apiContext, HttpMethod.POST, resourcePath, payLoad, Capture.class); + } + + /** + * Voids (cancels) an Authorization. + */ + public Authorization doVoid(String accessToken) throws PayPalRESTException { + APIContext apiContext = new APIContext(accessToken); + return doVoid(apiContext); + } + + /** + * Voids (cancels) an Authorization. + */ + public Authorization doVoid(APIContext apiContext) throws PayPalRESTException { + if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { + throw new IllegalArgumentException("AccessToken cannot be null or empty"); + } + if (this.getId() == null) { + throw new IllegalArgumentException("Id cannot be null"); + } + Object[] parameters = new Object[] {this.getId()}; + String pattern = "v1/payments/authorization/{0}/void"; + String resourcePath = RESTUtil.formatURIPath(pattern, parameters); + String payLoad = ""; + return PayPalResource.configureAndExecute(apiContext, HttpMethod.POST, resourcePath, payLoad, Authorization.class); + } + + + /** + * Reauthorizes an expired Authorization. + */ + public Authorization reauthorize(String accessToken) throws PayPalRESTException { + APIContext apiContext = new APIContext(accessToken); + return reauthorize(apiContext); + } + + /** + * Reauthorizes an expired Authorization. + */ + public Authorization reauthorize(APIContext apiContext) throws PayPalRESTException { + if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { + throw new IllegalArgumentException("AccessToken cannot be null or empty"); + } + if (this.getId() == null) { + throw new IllegalArgumentException("Id cannot be null"); + } + Object[] parameters = new Object[] {this.getId()}; + String pattern = "v1/payments/authorization/{0}/reauthorize"; + String resourcePath = RESTUtil.formatURIPath(pattern, parameters); + String payLoad = this.toJSON(); + return PayPalResource.configureAndExecute(apiContext, HttpMethod.POST, resourcePath, payLoad, Authorization.class); + } + /** * Returns a JSON string corresponding to object state * @@ -156,10 +347,9 @@ public void setLinks(List links) { public String toJSON() { return JSONFormatter.toJSON(this); } - + @Override public String toString() { return toJSON(); } - } \ No newline at end of file diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Capture.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Capture.java index 953d56e0..2984cb20 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Capture.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Capture.java @@ -1,189 +1,312 @@ package com.paypal.api.payments; + +import com.paypal.core.rest.JSONFormatter; import com.paypal.api.payments.Amount; +import com.paypal.api.payments.Links; import java.util.List; -import com.paypal.api.payments.Link; -import com.paypal.api.payments.Resource; -import com.paypal.core.rest.JSONFormatter; - -/** - * - */ -public class Capture extends Resource { +import java.util.Map; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; +import com.paypal.core.rest.HttpMethod; +import com.paypal.core.rest.RESTUtil; +import com.paypal.core.rest.QueryParameters; +import com.paypal.core.rest.APIContext; +import java.io.File; +import java.io.InputStream; +import java.util.Properties; +public class Capture { /** - * - */ + * Identifier of the Capture transaction. + */ private String id; - + /** - * - */ + * Time the resource was created. + */ private String createTime; - + /** - * - */ + * Time the resource was last updated. + */ private String updateTime; - + /** - * - */ + * Amount being captured. If no amount is specified, amount is used from the authorization being captured. If amount is same as the amount that's authorized for, the state of the authorization changes to captured. If not, the state of the authorization changes to partially_captured. Alternatively, you could indicate a final capture by seting the is_final_capture flag to true. + */ + private Amount amount; + + /** + * whether this is a final capture for the given authorization or not. If it's final, all the remaining funds held by the authorization, will be released in the funding instrument. + */ + private Boolean isFinalCapture; + + /** + * State of the capture transaction. + */ private String state; - + + /** + * ID of the Payment resource that this transaction is based on. + */ + private String parentPayment; + + /** + * Additional information to add when capturing the funds. Eg. shipment tracking number + */ + private String description; + /** * - */ - private Amount amount; - + */ + private List links; + /** + * Returns the last request sent to the Service * - */ - private String parentPayment; + * @return Last request sent to the server + */ + public static String getLastRequest() { + return PayPalResource.getLastRequest(); + } /** + * Returns the last response returned by the Service * - */ - private String authorizationId; + * @return Last response got from the Service + */ + public static String getLastResponse() { + return PayPalResource.getLastResponse(); + } /** + * Initialize using InputStream(of a Properties file) * - */ - private String description; + * @param is + * InputStream + * @throws PayPalRESTException + */ + public static void initConfig(InputStream is) throws PayPalRESTException { + PayPalResource.initConfig(is); + } /** + * Initialize using a File(Properties file) * - */ - private List links; + * @param file + * File object of a properties entity + * @throws PayPalRESTException + */ + public static void initConfig(File file) throws PayPalRESTException { + PayPalResource.initConfig(file); + } /** - * Constructor + * Initialize using Properties + * + * @param properties + * Properties object + */ + public static void initConfig(Properties properties) { + PayPalResource.initConfig(properties); + } + /** + * Default Constructor */ public Capture() { + } - } + /** + * Setter for id + */ + public void setId(String id) { + this.id = id; + } + /** * Getter for id */ public String getId() { - return id; + return this.id; } - + + /** - * Setter for id; + * Setter for createTime */ - public void setId(String id) { - this.id = id; + public void setCreateTime(String createTime) { + this.createTime = createTime; } + /** * Getter for createTime */ public String getCreateTime() { - return createTime; + return this.createTime; } - + + /** - * Setter for createTime; + * Setter for updateTime */ - public void setCreateTime(String createTime) { - this.createTime = createTime; + public void setUpdateTime(String updateTime) { + this.updateTime = updateTime; } + /** * Getter for updateTime */ public String getUpdateTime() { - return updateTime; + return this.updateTime; + } + + + /** + * Setter for amount + */ + public void setAmount(Amount amount) { + this.amount = amount; } /** - * Setter for updateTime; + * Getter for amount */ - public void setUpdateTime(String updateTime) { - this.updateTime = updateTime; + public Amount getAmount() { + return this.amount; } + + /** - * Getter for state + * Setter for isFinalCapture */ - public String getState() { - return state; + public void setIsFinalCapture(Boolean isFinalCapture) { + this.isFinalCapture = isFinalCapture; } /** - * Setter for state; + * Getter for isFinalCapture + */ + public Boolean getIsFinalCapture() { + return this.isFinalCapture; + } + + + /** + * Setter for state */ public void setState(String state) { this.state = state; } + /** - * Getter for amount + * Getter for state */ - public Amount getAmount() { - return amount; + public String getState() { + return this.state; } - + + /** - * Setter for amount; + * Setter for parentPayment */ - public void setAmount(Amount amount) { - this.amount = amount; + public void setParentPayment(String parentPayment) { + this.parentPayment = parentPayment; } + /** * Getter for parentPayment */ public String getParentPayment() { - return parentPayment; + return this.parentPayment; + } + + + /** + * Setter for description + */ + public void setDescription(String description) { + this.description = description; } /** - * Setter for parentPayment; + * Getter for description */ - public void setParentPayment(String parentPayment) { - this.parentPayment = parentPayment; + public String getDescription() { + return this.description; } + + /** - * Getter for authorizationId + * Setter for links */ - public String getAuthorizationId() { - return authorizationId; + public void setLinks(List links) { + this.links = links; } /** - * Setter for authorizationId; + * Getter for links */ - public void setAuthorizationId(String authorizationId) { - this.authorizationId = authorizationId; + public List getLinks() { + return this.links; } + + /** - * Getter for description + * Obtain the Capture transaction resource for the given identifier. */ - public String getDescription() { - return description; + public static Capture get(String accessToken, String captureId) throws PayPalRESTException { + APIContext apiContext = new APIContext(accessToken); + return get(apiContext, captureId); } /** - * Setter for description; + * Obtain the Capture transaction resource for the given identifier. */ - public void setDescription(String description) { - this.description = description; + public static Capture get(APIContext apiContext, String captureId) throws PayPalRESTException { + if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { + throw new IllegalArgumentException("AccessToken cannot be null or empty"); + } + if (captureId == null) { + throw new IllegalArgumentException("captureId cannot be null"); + } + Object[] parameters = new Object[] {captureId}; + String pattern = "v1/payments/capture/{0}"; + String resourcePath = RESTUtil.formatURIPath(pattern, parameters); + String payLoad = ""; + return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, Capture.class); } + + /** - * Getter for links + * Creates (and processes) a new Refund Transaction added as a related resource. */ - public List getLinks() { - return links; + public Refund refund(String accessToken, Refund refund) throws PayPalRESTException { + APIContext apiContext = new APIContext(accessToken); + return refund(apiContext, refund); } /** - * Setter for links; + * Creates (and processes) a new Refund Transaction added as a related resource. */ - public void setLinks(List links) { - this.links = links; + public Refund refund(APIContext apiContext, Refund refund) throws PayPalRESTException { + if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { + throw new IllegalArgumentException("AccessToken cannot be null or empty"); + } + if (this.getId() == null) { + throw new IllegalArgumentException("Id cannot be null"); + } + if (refund == null) { + throw new IllegalArgumentException("refund cannot be null"); + } + Object[] parameters = new Object[] {this.getId()}; + String pattern = "v1/payments/capture/{0}/refund"; + String resourcePath = RESTUtil.formatURIPath(pattern, parameters); + String payLoad = refund.toJSON(); + return PayPalResource.configureAndExecute(apiContext, HttpMethod.POST, resourcePath, payLoad, Refund.class); } - - - - + /** * Returns a JSON string corresponding to object state * @@ -192,10 +315,9 @@ public void setLinks(List links) { public String toJSON() { return JSONFormatter.toJSON(this); } - + @Override public String toString() { return toJSON(); } - } \ No newline at end of file diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCard.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCard.java index 3a01711c..0799b89b 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCard.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCard.java @@ -1,89 +1,87 @@ package com.paypal.api.payments; + +import com.paypal.core.rest.JSONFormatter; import com.paypal.api.payments.Address; +import com.paypal.api.payments.Links; import java.util.List; -import com.paypal.api.payments.Link; -import com.paypal.api.payments.Resource; +import java.util.Map; +import com.paypal.core.rest.PayPalRESTException; import com.paypal.core.rest.PayPalResource; import com.paypal.core.rest.HttpMethod; -import com.paypal.core.rest.PayPalRESTException; import com.paypal.core.rest.RESTUtil; -import com.paypal.core.rest.JSONFormatter; +import com.paypal.core.rest.QueryParameters; import com.paypal.core.rest.APIContext; import java.io.File; import java.io.InputStream; import java.util.Properties; -/** - * - */ -public class CreditCard extends Resource { - +public class CreditCard { /** - * - */ + * ID of the credit card being saved for later use. + */ private String id; - - /** - * - */ - private String validUntil; - - /** - * - */ - private String state; - + /** - * - */ - private String payerId; - + * Card number. + */ + private String number; + /** - * - */ + * Type of the Card (eg. Visa, Mastercard, etc.). + */ private String type; - - /** - * - */ - private String number; - + /** - * - */ - private String expireMonth; - + * card expiry month with value 1 - 12. + */ + private int expireMonth; + /** - * - */ - private String expireYear; - + * 4 digit card expiry year + */ + private int expireYear; + /** - * - */ + * Card validation code. Only supported when making a Payment but not when saving a credit card for future use. + */ private String cvv2; - + /** - * - */ + * Card holder's first name. + */ private String firstName; - + /** - * - */ + * Card holder's last name. + */ private String lastName; - + /** - * - */ + * Billing Address associated with this card. + */ private Address billingAddress; - + + /** + * A unique identifier of the payer generated and provided by the facilitator. This is required when creating or using a tokenized funding instrument. + */ + private String payerId; + + /** + * State of the funding instrument. + */ + private String state; + + /** + * Date/Time until this resource can be used fund a payment. + */ + private String validUntil; + /** * - */ - private List links; - + */ + private List links; + /** * Returns the last request sent to the Service * @@ -101,7 +99,7 @@ public static String getLastRequest() { public static String getLastResponse() { return PayPalResource.getLastResponse(); } - + /** * Initialize using InputStream(of a Properties file) * @@ -133,195 +131,220 @@ public static void initConfig(File file) throws PayPalRESTException { public static void initConfig(Properties properties) { PayPalResource.initConfig(properties); } - - /** - * Constructor + * Default Constructor */ public CreditCard() { - - } + } /** - * Getter for id + * Parameterized Constructor */ - public String getId() { - return id; + public CreditCard(String number, String type, int expireMonth, int expireYear) { + this.number = number; + this.type = type; + this.expireMonth = expireMonth; + this.expireYear = expireYear; } + /** - * Setter for id; + * Setter for id */ public void setId(String id) { this.id = id; } + /** - * Getter for validUntil + * Getter for id */ - public String getValidUntil() { - return validUntil; + public String getId() { + return this.id; + } + + + /** + * Setter for number + */ + public void setNumber(String number) { + this.number = number; } /** - * Setter for validUntil; + * Getter for number */ - public void setValidUntil(String validUntil) { - this.validUntil = validUntil; + public String getNumber() { + return this.number; } + + /** - * Getter for state + * Setter for type */ - public String getState() { - return state; + public void setType(String type) { + this.type = type; } /** - * Setter for state; + * Getter for type */ - public void setState(String state) { - this.state = state; + public String getType() { + return this.type; } + + /** - * Getter for payerId + * Setter for expireMonth */ - public String getPayerId() { - return payerId; + public void setExpireMonth(int expireMonth) { + this.expireMonth = expireMonth; } /** - * Setter for payerId; + * Getter for expireMonth */ - public void setPayerId(String payerId) { - this.payerId = payerId; + public int getExpireMonth() { + return this.expireMonth; } + + /** - * Getter for type + * Setter for expireYear */ - public String getType() { - return type; + public void setExpireYear(int expireYear) { + this.expireYear = expireYear; } /** - * Setter for type; + * Getter for expireYear */ - public void setType(String type) { - this.type = type; + public int getExpireYear() { + return this.expireYear; } + + /** - * Getter for number + * Setter for cvv2 */ - public String getNumber() { - return number; + public void setCvv2(String cvv2) { + this.cvv2 = cvv2; } /** - * Setter for number; + * Getter for cvv2 */ - public void setNumber(String number) { - this.number = number; + public String getCvv2() { + return this.cvv2; } + + /** - * Getter for expireMonth + * Setter for firstName */ - public String getExpireMonth() { - return expireMonth; + public void setFirstName(String firstName) { + this.firstName = firstName; } /** - * Setter for expireMonth; + * Getter for firstName */ - public void setExpireMonth(String expireMonth) { - this.expireMonth = expireMonth; + public String getFirstName() { + return this.firstName; } + + /** - * Getter for expireYear + * Setter for lastName */ - public String getExpireYear() { - return expireYear; + public void setLastName(String lastName) { + this.lastName = lastName; } /** - * Setter for expireYear; + * Getter for lastName */ - public void setExpireYear(String expireYear) { - this.expireYear = expireYear; + public String getLastName() { + return this.lastName; } + + /** - * Getter for cvv2 + * Setter for billingAddress */ - public String getCvv2() { - return cvv2; + public void setBillingAddress(Address billingAddress) { + this.billingAddress = billingAddress; } /** - * Setter for cvv2; + * Getter for billingAddress */ - public void setCvv2(String cvv2) { - this.cvv2 = cvv2; + public Address getBillingAddress() { + return this.billingAddress; } + + /** - * Getter for firstName + * Setter for payerId */ - public String getFirstName() { - return firstName; + public void setPayerId(String payerId) { + this.payerId = payerId; } /** - * Setter for firstName; + * Getter for payerId */ - public void setFirstName(String firstName) { - this.firstName = firstName; + public String getPayerId() { + return this.payerId; } + + /** - * Getter for lastName + * Setter for state */ - public String getLastName() { - return lastName; + public void setState(String state) { + this.state = state; } /** - * Setter for lastName; + * Getter for state */ - public void setLastName(String lastName) { - this.lastName = lastName; + public String getState() { + return this.state; } + + /** - * Getter for billingAddress + * Setter for validUntil */ - public Address getBillingAddress() { - return billingAddress; + public void setValidUntil(String validUntil) { + this.validUntil = validUntil; } /** - * Setter for billingAddress; + * Getter for validUntil */ - public void setBillingAddress(Address billingAddress) { - this.billingAddress = billingAddress; + public String getValidUntil() { + return this.validUntil; } + + /** - * Getter for links + * Setter for links */ - public List getLinks() { - return links; + public void setLinks(List links) { + this.links = links; } /** - * Setter for links; + * Getter for links */ - public void setLinks(List links) { - this.links = links; + public List getLinks() { + return this.links; } - - /** - * Create call for CreditCard. - * @param accessToken - * AccessToken used for the API call - * @HttpMethod POST - * @URIpath v1/vault/credit-card - * @return CreditCard + * Creates a new Credit Card Resource (aka Tokenize). */ public CreditCard create(String accessToken) throws PayPalRESTException { APIContext apiContext = new APIContext(accessToken); @@ -329,66 +352,124 @@ public CreditCard create(String accessToken) throws PayPalRESTException { } /** - * Create call for CreditCard. - * @param apiContext - * APIContext used for the API call - * @HttpMethod POST - * @URIpath v1/vault/credit-card - * @return CreditCard + * Creates a new Credit Card Resource (aka Tokenize). */ public CreditCard create(APIContext apiContext) throws PayPalRESTException { if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { throw new IllegalArgumentException("AccessToken cannot be null or empty"); } String resourcePath = "v1/vault/credit-card"; - String payLoad = this.toJSON(); + String payLoad = this.toJSON(); return PayPalResource.configureAndExecute(apiContext, HttpMethod.POST, resourcePath, payLoad, CreditCard.class); } + /** - * Get call for CreditCard. - * @param accessToken - * AccessToken used for the API call - * @param creditCardId - * @HttpMethod GET - * @URIpath v1/vault/credit-card/:creditCardId - * @return CreditCard + * Obtain the Credit Card resource for the given identifier. */ public static CreditCard get(String accessToken, String creditCardId) throws PayPalRESTException { - if ((creditCardId == null) || (creditCardId.length() <= 0)) { - throw new IllegalArgumentException("creditCardId cannot be null or empty"); + APIContext apiContext = new APIContext(accessToken); + return get(apiContext, creditCardId); + } + + /** + * Obtain the Credit Card resource for the given identifier. + */ + public static CreditCard get(APIContext apiContext, String creditCardId) throws PayPalRESTException { + if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { + throw new IllegalArgumentException("AccessToken cannot be null or empty"); + } + if (creditCardId == null) { + throw new IllegalArgumentException("creditCardId cannot be null"); } + Object[] parameters = new Object[] {creditCardId}; String pattern = "v1/vault/credit-card/{0}"; - Object[] parameters = new Object[] { creditCardId }; String resourcePath = RESTUtil.formatURIPath(pattern, parameters); String payLoad = ""; - APIContext apiContext = new APIContext(accessToken); return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, CreditCard.class); } + /** - * Get call for CreditCard. - * @param apiContext - * {@link APIContext} to be used for the call. - * @param creditCardId - * @HttpMethod GET - * @URIpath v1/vault/credit-card/:creditCardId - * @return CreditCard + * Delete the Credit Card resource for the given identifier. */ - public static CreditCard get(APIContext apiContext, String creditCardId) throws PayPalRESTException { - if ((creditCardId == null) || (creditCardId.length() <= 0)) { - throw new IllegalArgumentException("creditCardId cannot be null or empty"); + public void delete(String accessToken) throws PayPalRESTException { + APIContext apiContext = new APIContext(accessToken); + delete(apiContext); + return; + } + + /** + * Delete the Credit Card resource for the given identifier. + */ + public void delete(APIContext apiContext) throws PayPalRESTException { + if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { + throw new IllegalArgumentException("AccessToken cannot be null or empty"); } + if (this.getId() == null) { + throw new IllegalArgumentException("Id cannot be null"); + } + apiContext.setMaskRequestId(true); + Object[] parameters = new Object[] {this.getId()}; String pattern = "v1/vault/credit-card/{0}"; - Object[] parameters = new Object[] { creditCardId }; String resourcePath = RESTUtil.formatURIPath(pattern, parameters); String payLoad = ""; + PayPalResource.configureAndExecute(apiContext, HttpMethod.DELETE, resourcePath, payLoad, null); + return; + } + + + /** + * Update information in a previously saved card. Only the modified fields need to be passed in the request. + */ + public CreditCard update(String accessToken) throws PayPalRESTException { + APIContext apiContext = new APIContext(accessToken); + return update(apiContext); + } + + /** + * Update information in a previously saved card. Only the modified fields need to be passed in the request. + */ + public CreditCard update(APIContext apiContext) throws PayPalRESTException { if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { - throw new IllegalArgumentException("AccessToken cannot be null in APIContext"); + throw new IllegalArgumentException("AccessToken cannot be null or empty"); } - return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, CreditCard.class); + if (this.getId() == null) { + throw new IllegalArgumentException("Id cannot be null"); + } + Object[] parameters = new Object[] {this.getId()}; + String pattern = "v1/vault/credit-card/{0}"; + String resourcePath = RESTUtil.formatURIPath(pattern, parameters); + String payLoad = this.toJSON(); + return PayPalResource.configureAndExecute(apiContext, HttpMethod.PATCH, resourcePath, payLoad, CreditCard.class); } + + /** + * Retrieves a list of Credit Card resources. + */ + public static CreditCardHistory list(String accessToken, Map containerMap) throws PayPalRESTException { + APIContext apiContext = new APIContext(accessToken); + return list(apiContext, containerMap); + } + + /** + * Retrieves a list of Credit Card resources. + */ + public static CreditCardHistory list(APIContext apiContext, Map containerMap) throws PayPalRESTException { + if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { + throw new IllegalArgumentException("AccessToken cannot be null or empty"); + } + if (containerMap == null) { + throw new IllegalArgumentException("containerMap cannot be null"); + } + Object[] parameters = new Object[] {containerMap}; + String pattern = "v1/vault/credit-card?count={0}&start_id={1}&start_index={2}&start_time={3}&end_time={4}&payer_id={5}"; + String resourcePath = RESTUtil.formatURIPath(pattern, parameters); + String payLoad = ""; + return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, CreditCardHistory.class); + } + /** * Returns a JSON string corresponding to object state * @@ -397,10 +478,9 @@ public static CreditCard get(APIContext apiContext, String creditCardId) throws public String toJSON() { return JSONFormatter.toJSON(this); } - + @Override public String toString() { return toJSON(); } - } \ No newline at end of file diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCardHistory.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCardHistory.java new file mode 100644 index 00000000..c1624898 --- /dev/null +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCardHistory.java @@ -0,0 +1,98 @@ +package com.paypal.api.payments; + +import com.paypal.core.rest.JSONFormatter; +import com.paypal.api.payments.CreditCard; +import java.util.List; +import java.util.Map; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; +import com.paypal.core.rest.HttpMethod; +import com.paypal.core.rest.RESTUtil; +import com.paypal.core.rest.QueryParameters; +import com.paypal.core.rest.APIContext; +import java.io.File; +import java.io.InputStream; +import java.util.Properties; + +public class CreditCardHistory { + + /** + * A list of credit card resources + */ + private List creditCards; + + /** + * Number of items returned in each range of results. Note that the last results range could have fewer items than the requested number of items. + */ + private int count; + + /** + * Identifier of the next element to get the next range of results. + */ + private String nextId; + + /** + * Default Constructor + */ + public CreditCardHistory() { + } + + + /** + * Setter for creditCards + */ + public void setCreditCards(List creditCards) { + this.creditCards = creditCards; + } + + /** + * Getter for creditCards + */ + public List getCreditCards() { + return this.creditCards; + } + + + /** + * Setter for count + */ + public void setCount(int count) { + this.count = count; + } + + /** + * Getter for count + */ + public int getCount() { + return this.count; + } + + + /** + * Setter for nextId + */ + public void setNextId(String nextId) { + this.nextId = nextId; + } + + /** + * Getter for nextId + */ + public String getNextId() { + return this.nextId; + } + + /** + * Returns a JSON string corresponding to object state + * + * @return JSON representation + */ + public String toJSON() { + return JSONFormatter.toJSON(this); + } + + @Override + public String toString() { + return toJSON(); + } +} \ No newline at end of file diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCardToken.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCardToken.java index 3fb650de..6b9438e0 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCardToken.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCardToken.java @@ -1,60 +1,152 @@ package com.paypal.api.payments; -import com.paypal.api.payments.Resource; -import com.paypal.core.rest.JSONFormatter; -/** - * - */ -public class CreditCardToken extends Resource { +import com.paypal.core.rest.JSONFormatter; +import java.util.Map; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; +import com.paypal.core.rest.HttpMethod; +import com.paypal.core.rest.RESTUtil; +import com.paypal.core.rest.QueryParameters; +import com.paypal.core.rest.APIContext; +import java.io.File; +import java.io.InputStream; +import java.util.Properties; +public class CreditCardToken { /** - * - */ + * ID of a previously saved Credit Card resource using /vault/credit-card API. + */ private String creditCardId; - + /** - * - */ + * The unique identifier of the payer used when saving this credit card using /vault/credit-card API. + */ private String payerId; - + + /** + * Last 4 digits of the card number from the saved card. + */ + private String last4; + + /** + * Type of the Card (eg. visa, mastercard, etc.) from the saved card. Please note that the values are always in lowercase and not meant to be used directly for display. + */ + private String type; + + /** + * card expiry month from the saved card with value 1 - 12 + */ + private int expireMonth; + /** - * Constructor + * 4 digit card expiry year from the saved card + */ + private int expireYear; + + /** + * Default Constructor */ public CreditCardToken() { - - } + } /** - * Getter for creditCardId + * Parameterized Constructor */ - public String getCreditCardId() { - return creditCardId; + public CreditCardToken(String creditCardId) { + this.creditCardId = creditCardId; } + /** - * Setter for creditCardId; + * Setter for creditCardId */ public void setCreditCardId(String creditCardId) { this.creditCardId = creditCardId; } + + /** + * Getter for creditCardId + */ + public String getCreditCardId() { + return this.creditCardId; + } + + + /** + * Setter for payerId + */ + public void setPayerId(String payerId) { + this.payerId = payerId; + } + /** * Getter for payerId */ public String getPayerId() { - return payerId; + return this.payerId; + } + + + /** + * Setter for last4 + */ + public void setLast4(String last4) { + this.last4 = last4; } /** - * Setter for payerId; + * Getter for last4 */ - public void setPayerId(String payerId) { - this.payerId = payerId; + public String getLast4() { + return this.last4; + } + + + /** + * Setter for type + */ + public void setType(String type) { + this.type = type; + } + + /** + * Getter for type + */ + public String getType() { + return this.type; } + /** + * Setter for expireMonth + */ + public void setExpireMonth(int expireMonth) { + this.expireMonth = expireMonth; + } + + /** + * Getter for expireMonth + */ + public int getExpireMonth() { + return this.expireMonth; + } + /** + * Setter for expireYear + */ + public void setExpireYear(int expireYear) { + this.expireYear = expireYear; + } + + /** + * Getter for expireYear + */ + public int getExpireYear() { + return this.expireYear; + } + /** * Returns a JSON string corresponding to object state * @@ -63,10 +155,9 @@ public void setPayerId(String payerId) { public String toJSON() { return JSONFormatter.toJSON(this); } - + @Override public String toString() { return toJSON(); } - } \ No newline at end of file diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/AmountDetails.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Details.java similarity index 53% rename from rest-api-sdk/src/main/java/com/paypal/api/payments/AmountDetails.java rename to rest-api-sdk/src/main/java/com/paypal/api/payments/Details.java index 09bdd688..fc20d97f 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/AmountDetails.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Details.java @@ -1,96 +1,105 @@ package com.paypal.api.payments; -import com.paypal.api.payments.Resource; -import com.paypal.core.rest.JSONFormatter; -/** - * - */ -public class AmountDetails extends Resource { +import com.paypal.core.rest.JSONFormatter; +import java.util.Map; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; +import com.paypal.core.rest.HttpMethod; +import com.paypal.core.rest.RESTUtil; +import com.paypal.core.rest.QueryParameters; +import com.paypal.core.rest.APIContext; +import java.io.File; +import java.io.InputStream; +import java.util.Properties; +public class Details { /** - * - */ + * Amount being charged for shipping. + */ + private String shipping; + + /** + * Sub-total (amount) of items being paid for. + */ private String subtotal; - + /** - * - */ + * Amount being charged as tax. + */ private String tax; - - /** - * - */ - private String shipping; - + /** - * - */ + * Fee charged by PayPal. In case of a refund, this is the fee amount refunded to the original receipient of the payment. + */ private String fee; - + /** - * Constructor + * Default Constructor */ - public AmountDetails() { + public Details() { + } - } /** - * Getter for subtotal + * Setter for shipping */ - public String getSubtotal() { - return subtotal; + public void setShipping(String shipping) { + this.shipping = shipping; } /** - * Setter for subtotal; + * Getter for shipping */ - public void setSubtotal(String subtotal) { - this.subtotal = subtotal; + public String getShipping() { + return this.shipping; } + + /** - * Getter for tax + * Setter for subtotal */ - public String getTax() { - return tax; + public void setSubtotal(String subtotal) { + this.subtotal = subtotal; } /** - * Setter for tax; + * Getter for subtotal */ - public void setTax(String tax) { - this.tax = tax; + public String getSubtotal() { + return this.subtotal; } + + /** - * Getter for shipping + * Setter for tax */ - public String getShipping() { - return shipping; + public void setTax(String tax) { + this.tax = tax; } /** - * Setter for shipping; + * Getter for tax */ - public void setShipping(String shipping) { - this.shipping = shipping; + public String getTax() { + return this.tax; } + + /** - * Getter for fee + * Setter for fee */ - public String getFee() { - return fee; + public void setFee(String fee) { + this.fee = fee; } /** - * Setter for fee; + * Getter for fee */ - public void setFee(String fee) { - this.fee = fee; + public String getFee() { + return this.fee; } - - - /** * Returns a JSON string corresponding to object state * @@ -99,10 +108,9 @@ public void setFee(String fee) { public String toJSON() { return JSONFormatter.toJSON(this); } - + @Override public String toString() { return toJSON(); } - } \ No newline at end of file diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/FundingInstrument.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/FundingInstrument.java index ff51b45b..ecffca4f 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/FundingInstrument.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/FundingInstrument.java @@ -1,62 +1,67 @@ package com.paypal.api.payments; + +import com.paypal.core.rest.JSONFormatter; import com.paypal.api.payments.CreditCard; import com.paypal.api.payments.CreditCardToken; -import com.paypal.api.payments.Resource; -import com.paypal.core.rest.JSONFormatter; - -/** - * - */ -public class FundingInstrument extends Resource { +import java.util.Map; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; +import com.paypal.core.rest.HttpMethod; +import com.paypal.core.rest.RESTUtil; +import com.paypal.core.rest.QueryParameters; +import com.paypal.core.rest.APIContext; +import java.io.File; +import java.io.InputStream; +import java.util.Properties; +public class FundingInstrument { /** - * - */ + * Credit Card information. + */ private CreditCard creditCard; - + /** - * - */ + * Credit Card information. + */ private CreditCardToken creditCardToken; - + /** - * Constructor + * Default Constructor */ public FundingInstrument() { + } - } /** - * Getter for creditCard + * Setter for creditCard */ - public CreditCard getCreditCard() { - return creditCard; + public void setCreditCard(CreditCard creditCard) { + this.creditCard = creditCard; } /** - * Setter for creditCard; + * Getter for creditCard */ - public void setCreditCard(CreditCard creditCard) { - this.creditCard = creditCard; + public CreditCard getCreditCard() { + return this.creditCard; } + + /** - * Getter for creditCardToken + * Setter for creditCardToken */ - public CreditCardToken getCreditCardToken() { - return creditCardToken; + public void setCreditCardToken(CreditCardToken creditCardToken) { + this.creditCardToken = creditCardToken; } /** - * Setter for creditCardToken; + * Getter for creditCardToken */ - public void setCreditCardToken(CreditCardToken creditCardToken) { - this.creditCardToken = creditCardToken; + public CreditCardToken getCreditCardToken() { + return this.creditCardToken; } - - - /** * Returns a JSON string corresponding to object state * @@ -65,10 +70,9 @@ public void setCreditCardToken(CreditCardToken creditCardToken) { public String toJSON() { return JSONFormatter.toJSON(this); } - + @Override public String toString() { return toJSON(); } - } \ No newline at end of file diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/HyperSchema.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/HyperSchema.java new file mode 100644 index 00000000..f9c3f1ff --- /dev/null +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/HyperSchema.java @@ -0,0 +1,158 @@ +package com.paypal.api.payments; + +import com.paypal.core.rest.JSONFormatter; +import com.paypal.api.payments.Links; +import java.util.List; +import java.util.Map; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; +import com.paypal.core.rest.HttpMethod; +import com.paypal.core.rest.RESTUtil; +import com.paypal.core.rest.QueryParameters; +import com.paypal.core.rest.APIContext; +import java.io.File; +import java.io.InputStream; +import java.util.Properties; + +public class HyperSchema { + + /** + * + */ + private List links; + + /** + * + */ + private String fragmentResolution; + + /** + * + */ + private Boolean readonly; + + /** + * + */ + private String contentEncoding; + + /** + * + */ + private String pathStart; + + /** + * + */ + private String mediaType; + + /** + * Default Constructor + */ + public HyperSchema() { + } + + + /** + * Setter for links + */ + public void setLinks(List links) { + this.links = links; + } + + /** + * Getter for links + */ + public List getLinks() { + return this.links; + } + + + /** + * Setter for fragmentResolution + */ + public void setFragmentResolution(String fragmentResolution) { + this.fragmentResolution = fragmentResolution; + } + + /** + * Getter for fragmentResolution + */ + public String getFragmentResolution() { + return this.fragmentResolution; + } + + + /** + * Setter for readonly + */ + public void setReadonly(Boolean readonly) { + this.readonly = readonly; + } + + /** + * Getter for readonly + */ + public Boolean getReadonly() { + return this.readonly; + } + + + /** + * Setter for contentEncoding + */ + public void setContentEncoding(String contentEncoding) { + this.contentEncoding = contentEncoding; + } + + /** + * Getter for contentEncoding + */ + public String getContentEncoding() { + return this.contentEncoding; + } + + + /** + * Setter for pathStart + */ + public void setPathStart(String pathStart) { + this.pathStart = pathStart; + } + + /** + * Getter for pathStart + */ + public String getPathStart() { + return this.pathStart; + } + + + /** + * Setter for mediaType + */ + public void setMediaType(String mediaType) { + this.mediaType = mediaType; + } + + /** + * Getter for mediaType + */ + public String getMediaType() { + return this.mediaType; + } + + /** + * Returns a JSON string corresponding to object state + * + * @return JSON representation + */ + public String toJSON() { + return JSONFormatter.toJSON(this); + } + + @Override + public String toString() { + return toJSON(); + } +} \ No newline at end of file diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Item.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Item.java index 7054c0b3..30510674 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Item.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Item.java @@ -1,114 +1,135 @@ package com.paypal.api.payments; -import com.paypal.api.payments.Resource; -import com.paypal.core.rest.JSONFormatter; -/** - * - */ -public class Item extends Resource { +import com.paypal.core.rest.JSONFormatter; +import java.util.Map; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; +import com.paypal.core.rest.HttpMethod; +import com.paypal.core.rest.RESTUtil; +import com.paypal.core.rest.QueryParameters; +import com.paypal.core.rest.APIContext; +import java.io.File; +import java.io.InputStream; +import java.util.Properties; +public class Item { /** - * - */ - private String name; - + * Number of items. + */ + private String quantity; + /** - * - */ - private String sku; - + * Name of the item. + */ + private String name; + /** - * - */ + * Cost of the item. + */ private String price; - + /** - * - */ + * 3-letter Currency Code + */ private String currency; - + /** - * - */ - private String quantity; - + * Number or code to identify the item in your catalog/records. + */ + private String sku; + /** - * Constructor + * Default Constructor */ public Item() { - - } + } /** - * Getter for name + * Parameterized Constructor */ - public String getName() { - return name; + public Item(String quantity, String name, String price, String currency) { + this.quantity = quantity; + this.name = name; + this.price = price; + this.currency = currency; } + /** - * Setter for name; + * Setter for quantity */ - public void setName(String name) { - this.name = name; + public void setQuantity(String quantity) { + this.quantity = quantity; } + /** - * Getter for sku + * Getter for quantity */ - public String getSku() { - return sku; + public String getQuantity() { + return this.quantity; } - + + /** - * Setter for sku; + * Setter for name */ - public void setSku(String sku) { - this.sku = sku; + public void setName(String name) { + this.name = name; } + /** - * Getter for price + * Getter for name */ - public String getPrice() { - return price; + public String getName() { + return this.name; } - + + /** - * Setter for price; + * Setter for price */ public void setPrice(String price) { this.price = price; } + /** - * Getter for currency + * Getter for price */ - public String getCurrency() { - return currency; + public String getPrice() { + return this.price; } - + + /** - * Setter for currency; + * Setter for currency */ public void setCurrency(String currency) { this.currency = currency; } + /** - * Getter for quantity + * Getter for currency */ - public String getQuantity() { - return quantity; + public String getCurrency() { + return this.currency; + } + + + /** + * Setter for sku + */ + public void setSku(String sku) { + this.sku = sku; } /** - * Setter for quantity; + * Getter for sku */ - public void setQuantity(String quantity) { - this.quantity = quantity; + public String getSku() { + return this.sku; } - - - /** * Returns a JSON string corresponding to object state * @@ -117,10 +138,9 @@ public void setQuantity(String quantity) { public String toJSON() { return JSONFormatter.toJSON(this); } - + @Override public String toString() { return toJSON(); } - } \ No newline at end of file diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/ItemList.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/ItemList.java index a7a4c318..f3adebea 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/ItemList.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/ItemList.java @@ -1,63 +1,68 @@ package com.paypal.api.payments; -import java.util.List; + +import com.paypal.core.rest.JSONFormatter; import com.paypal.api.payments.Item; +import java.util.List; import com.paypal.api.payments.ShippingAddress; -import com.paypal.api.payments.Resource; -import com.paypal.core.rest.JSONFormatter; - -/** - * - */ -public class ItemList extends Resource { +import java.util.Map; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; +import com.paypal.core.rest.HttpMethod; +import com.paypal.core.rest.RESTUtil; +import com.paypal.core.rest.QueryParameters; +import com.paypal.core.rest.APIContext; +import java.io.File; +import java.io.InputStream; +import java.util.Properties; +public class ItemList { /** - * - */ + * List of items. + */ private List items; - + /** - * - */ + * Shipping address. + */ private ShippingAddress shippingAddress; - + /** - * Constructor + * Default Constructor */ public ItemList() { + } - } /** - * Getter for items + * Setter for items */ - public List getItems() { - return items; + public void setItems(List items) { + this.items = items; } /** - * Setter for items; + * Getter for items */ - public void setItems(List items) { - this.items = items; + public List getItems() { + return this.items; } + + /** - * Getter for shippingAddress + * Setter for shippingAddress */ - public ShippingAddress getShippingAddress() { - return shippingAddress; + public void setShippingAddress(ShippingAddress shippingAddress) { + this.shippingAddress = shippingAddress; } /** - * Setter for shippingAddress; + * Getter for shippingAddress */ - public void setShippingAddress(ShippingAddress shippingAddress) { - this.shippingAddress = shippingAddress; + public ShippingAddress getShippingAddress() { + return this.shippingAddress; } - - - /** * Returns a JSON string corresponding to object state * @@ -66,10 +71,9 @@ public void setShippingAddress(ShippingAddress shippingAddress) { public String toJSON() { return JSONFormatter.toJSON(this); } - + @Override public String toString() { return toJSON(); } - } \ No newline at end of file diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Link.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Link.java deleted file mode 100644 index 30ec946d..00000000 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Link.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.paypal.api.payments; -import com.paypal.api.payments.Resource; -import com.paypal.core.rest.JSONFormatter; - -/** - * - */ -public class Link extends Resource { - - - /** - * - */ - private String href; - - /** - * - */ - private String rel; - - /** - * - */ - private String method; - - /** - * Constructor - */ - public Link() { - - } - - /** - * Getter for href - */ - public String getHref() { - return href; - } - - /** - * Setter for href; - */ - public void setHref(String href) { - this.href = href; - } - /** - * Getter for rel - */ - public String getRel() { - return rel; - } - - /** - * Setter for rel; - */ - public void setRel(String rel) { - this.rel = rel; - } - /** - * Getter for method - */ - public String getMethod() { - return method; - } - - /** - * Setter for method; - */ - public void setMethod(String method) { - this.method = method; - } - - - - - /** - * Returns a JSON string corresponding to object state - * - * @return JSON representation - */ - public String toJSON() { - return JSONFormatter.toJSON(this); - } - - @Override - public String toString() { - return toJSON(); - } - -} \ No newline at end of file diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Links.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Links.java new file mode 100644 index 00000000..2dbd9394 --- /dev/null +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Links.java @@ -0,0 +1,165 @@ +package com.paypal.api.payments; + +import com.paypal.core.rest.JSONFormatter; +import com.paypal.api.payments.HyperSchema; +import java.util.Map; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; +import com.paypal.core.rest.HttpMethod; +import com.paypal.core.rest.RESTUtil; +import com.paypal.core.rest.QueryParameters; +import com.paypal.core.rest.APIContext; +import java.io.File; +import java.io.InputStream; +import java.util.Properties; + +public class Links { + + /** + * + */ + private String href; + + /** + * + */ + private String rel; + + /** + * + */ + private HyperSchema targetSchema; + + /** + * + */ + private String method; + + /** + * + */ + private String enctype; + + /** + * + */ + private HyperSchema schema; + + /** + * Default Constructor + */ + public Links() { + } + + /** + * Parameterized Constructor + */ + public Links(String href, String rel) { + this.href = href; + this.rel = rel; + } + + + /** + * Setter for href + */ + public void setHref(String href) { + this.href = href; + } + + /** + * Getter for href + */ + public String getHref() { + return this.href; + } + + + /** + * Setter for rel + */ + public void setRel(String rel) { + this.rel = rel; + } + + /** + * Getter for rel + */ + public String getRel() { + return this.rel; + } + + + /** + * Setter for targetSchema + */ + public void setTargetSchema(HyperSchema targetSchema) { + this.targetSchema = targetSchema; + } + + /** + * Getter for targetSchema + */ + public HyperSchema getTargetSchema() { + return this.targetSchema; + } + + + /** + * Setter for method + */ + public void setMethod(String method) { + this.method = method; + } + + /** + * Getter for method + */ + public String getMethod() { + return this.method; + } + + + /** + * Setter for enctype + */ + public void setEnctype(String enctype) { + this.enctype = enctype; + } + + /** + * Getter for enctype + */ + public String getEnctype() { + return this.enctype; + } + + + /** + * Setter for schema + */ + public void setSchema(HyperSchema schema) { + this.schema = schema; + } + + /** + * Getter for schema + */ + public HyperSchema getSchema() { + return this.schema; + } + + /** + * Returns a JSON string corresponding to object state + * + * @return JSON representation + */ + public String toJSON() { + return JSONFormatter.toJSON(this); + } + + @Override + public String toString() { + return toJSON(); + } +} \ No newline at end of file diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Payee.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Payee.java index e7822202..48fba9ac 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Payee.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Payee.java @@ -1,77 +1,93 @@ package com.paypal.api.payments; -import com.paypal.api.payments.Resource; -import com.paypal.core.rest.JSONFormatter; - -/** - * - */ -public class Payee extends Resource { +import com.paypal.core.rest.JSONFormatter; +import java.util.Map; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; +import com.paypal.core.rest.HttpMethod; +import com.paypal.core.rest.RESTUtil; +import com.paypal.core.rest.QueryParameters; +import com.paypal.core.rest.APIContext; +import java.io.File; +import java.io.InputStream; +import java.util.Properties; - /** - * - */ - private String merchantId; +public class Payee { /** - * - */ + * Email Address associated with the Payee's PayPal Account. If the provided email address is not associated with any PayPal Account, the payee can only receiver PayPal Wallet Payments. Direct Credit Card Payments will be denied due to card compliance requirements. + */ private String email; - + /** - * - */ + * Encrypted PayPal Account identifier for the Payee. + */ + private String merchantId; + + /** + * Phone number (in E.123 format) associated with the Payee's PayPal Account. If the provided phont number is not associated with any PayPal Account, the payee can only receiver PayPal Wallet Payments. Direct Credit Card Payments will be denied due to card compliance requirements. + */ private String phone; - + /** - * Constructor + * Default Constructor */ public Payee() { - - } + } /** - * Getter for merchantId + * Parameterized Constructor */ - public String getMerchantId() { - return merchantId; + public Payee(String email, String merchantId, String phone) { + this.email = email; + this.merchantId = merchantId; + this.phone = phone; } + /** - * Setter for merchantId; + * Setter for email */ - public void setMerchantId(String merchantId) { - this.merchantId = merchantId; + public void setEmail(String email) { + this.email = email; } + /** * Getter for email */ public String getEmail() { - return email; + return this.email; } - + + /** - * Setter for email; + * Setter for merchantId */ - public void setEmail(String email) { - this.email = email; + public void setMerchantId(String merchantId) { + this.merchantId = merchantId; } + /** - * Getter for phone + * Getter for merchantId */ - public String getPhone() { - return phone; + public String getMerchantId() { + return this.merchantId; } - + + /** - * Setter for phone; + * Setter for phone */ public void setPhone(String phone) { this.phone = phone; } - - - + + /** + * Getter for phone + */ + public String getPhone() { + return this.phone; + } /** * Returns a JSON string corresponding to object state @@ -81,10 +97,9 @@ public void setPhone(String phone) { public String toJSON() { return JSONFormatter.toJSON(this); } - + @Override public String toString() { return toJSON(); } - } \ No newline at end of file diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Payer.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Payer.java index 2cfd969f..7e2cabef 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Payer.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Payer.java @@ -1,81 +1,95 @@ package com.paypal.api.payments; -import com.paypal.api.payments.PayerInfo; -import java.util.List; -import com.paypal.api.payments.FundingInstrument; -import com.paypal.api.payments.Resource; -import com.paypal.core.rest.JSONFormatter; -/** - * - */ -public class Payer extends Resource { +import com.paypal.core.rest.JSONFormatter; +import com.paypal.api.payments.FundingInstrument; +import java.util.List; +import com.paypal.api.payments.PayerInfo; +import java.util.Map; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; +import com.paypal.core.rest.HttpMethod; +import com.paypal.core.rest.RESTUtil; +import com.paypal.core.rest.QueryParameters; +import com.paypal.core.rest.APIContext; +import java.io.File; +import java.io.InputStream; +import java.util.Properties; +public class Payer { /** - * - */ + * Payment method being used - PayPal Wallet payment or Direct Credit card. + */ private String paymentMethod; - - /** - * - */ - private PayerInfo payerInfo; - + /** - * - */ + * List of funding instruments from where the funds of the current payment come from. Typically a credit card. + */ private List fundingInstruments; - + /** - * Constructor + * Information related to the Payer. In case of PayPal Wallet payment, this information will be filled in by PayPal after the user approves the payment using their PayPal Wallet. + */ + private PayerInfo payerInfo; + + /** + * Default Constructor */ public Payer() { - - } + } /** - * Getter for paymentMethod + * Parameterized Constructor */ - public String getPaymentMethod() { - return paymentMethod; + public Payer(String paymentMethod) { + this.paymentMethod = paymentMethod; } + /** - * Setter for paymentMethod; + * Setter for paymentMethod */ public void setPaymentMethod(String paymentMethod) { this.paymentMethod = paymentMethod; } + /** - * Getter for payerInfo + * Getter for paymentMethod */ - public PayerInfo getPayerInfo() { - return payerInfo; + public String getPaymentMethod() { + return this.paymentMethod; } - + + /** - * Setter for payerInfo; + * Setter for fundingInstruments */ - public void setPayerInfo(PayerInfo payerInfo) { - this.payerInfo = payerInfo; + public void setFundingInstruments(List fundingInstruments) { + this.fundingInstruments = fundingInstruments; } + /** * Getter for fundingInstruments */ public List getFundingInstruments() { - return fundingInstruments; + return this.fundingInstruments; + } + + + /** + * Setter for payerInfo + */ + public void setPayerInfo(PayerInfo payerInfo) { + this.payerInfo = payerInfo; } /** - * Setter for fundingInstruments; + * Getter for payerInfo */ - public void setFundingInstruments(List fundingInstruments) { - this.fundingInstruments = fundingInstruments; + public PayerInfo getPayerInfo() { + return this.payerInfo; } - - - /** * Returns a JSON string corresponding to object state * @@ -84,10 +98,9 @@ public void setFundingInstruments(List fundingInstruments) { public String toJSON() { return JSONFormatter.toJSON(this); } - + @Override public String toString() { return toJSON(); } - } \ No newline at end of file diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/PayerInfo.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/PayerInfo.java index 95ff3524..463dd571 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/PayerInfo.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/PayerInfo.java @@ -1,133 +1,146 @@ package com.paypal.api.payments; -import com.paypal.api.payments.Address; -import com.paypal.api.payments.Resource; -import com.paypal.core.rest.JSONFormatter; -/** - * - */ -public class PayerInfo extends Resource { +import com.paypal.core.rest.JSONFormatter; +import com.paypal.api.payments.Address; +import java.util.Map; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; +import com.paypal.core.rest.HttpMethod; +import com.paypal.core.rest.RESTUtil; +import com.paypal.core.rest.QueryParameters; +import com.paypal.core.rest.APIContext; +import java.io.File; +import java.io.InputStream; +import java.util.Properties; +public class PayerInfo { /** - * - */ + * Email address representing the Payer. + */ private String email; - + /** - * - */ + * First Name of the Payer from their PayPal Account. + */ private String firstName; - + /** - * - */ + * Last Name of the Payer from their PayPal Account. + */ private String lastName; - + /** - * - */ + * PayPal assigned Payer ID. + */ private String payerId; - - /** - * - */ - private Address shippingAddress; - + /** - * - */ + * Phone number representing the Payer. + */ private String phone; - + /** - * Constructor + * Shipping address of the Payer from their PayPal Account. */ - public PayerInfo() { - - } - + private Address shippingAddress; + /** - * Getter for email + * Default Constructor */ - public String getEmail() { - return email; + public PayerInfo() { } - + + /** - * Setter for email; + * Setter for email */ public void setEmail(String email) { this.email = email; } + /** - * Getter for firstName + * Getter for email */ - public String getFirstName() { - return firstName; + public String getEmail() { + return this.email; } - + + /** - * Setter for firstName; + * Setter for firstName */ public void setFirstName(String firstName) { this.firstName = firstName; } + /** - * Getter for lastName + * Getter for firstName */ - public String getLastName() { - return lastName; + public String getFirstName() { + return this.firstName; } - + + /** - * Setter for lastName; + * Setter for lastName */ public void setLastName(String lastName) { this.lastName = lastName; } + /** - * Getter for payerId + * Getter for lastName */ - public String getPayerId() { - return payerId; + public String getLastName() { + return this.lastName; } - + + /** - * Setter for payerId; + * Setter for payerId */ public void setPayerId(String payerId) { this.payerId = payerId; } + /** - * Getter for shippingAddress + * Getter for payerId */ - public Address getShippingAddress() { - return shippingAddress; + public String getPayerId() { + return this.payerId; } - + + /** - * Setter for shippingAddress; + * Setter for phone */ - public void setShippingAddress(Address shippingAddress) { - this.shippingAddress = shippingAddress; + public void setPhone(String phone) { + this.phone = phone; } + /** * Getter for phone */ public String getPhone() { - return phone; + return this.phone; + } + + + /** + * Setter for shippingAddress + */ + public void setShippingAddress(Address shippingAddress) { + this.shippingAddress = shippingAddress; } /** - * Setter for phone; + * Getter for shippingAddress */ - public void setPhone(String phone) { - this.phone = phone; + public Address getShippingAddress() { + return this.shippingAddress; } - - - /** * Returns a JSON string corresponding to object state * @@ -136,10 +149,9 @@ public void setPhone(String phone) { public String toJSON() { return JSONFormatter.toJSON(this); } - + @Override public String toString() { return toJSON(); } - } \ No newline at end of file diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Payment.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Payment.java index 0c18a18b..e4ef2e9e 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Payment.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Payment.java @@ -1,73 +1,64 @@ package com.paypal.api.payments; + +import com.paypal.core.rest.JSONFormatter; import com.paypal.api.payments.Payer; -import java.util.List; import com.paypal.api.payments.Transaction; +import java.util.List; import com.paypal.api.payments.RedirectUrls; -import com.paypal.api.payments.Link; -import com.paypal.api.payments.Resource; +import com.paypal.api.payments.Links; +import java.util.Map; +import com.paypal.core.rest.PayPalRESTException; import com.paypal.core.rest.PayPalResource; import com.paypal.core.rest.HttpMethod; -import com.paypal.core.rest.PayPalRESTException; import com.paypal.core.rest.RESTUtil; import com.paypal.core.rest.QueryParameters; -import com.paypal.core.rest.JSONFormatter; import com.paypal.core.rest.APIContext; import java.io.File; import java.io.InputStream; import java.util.Properties; -import java.util.Map; - -/** - * - */ -public class Payment extends Resource { +public class Payment { /** - * - */ + * Identifier of the payment resource created. + */ private String id; - + /** - * - */ + * Time the resource was created. + */ private String createTime; - - /** - * - */ - private String updateTime; - - /** - * - */ - private String state; - + /** - * - */ + * Intent of the payment - Sale or Authorization or Order. + */ private String intent; - + /** - * - */ + * Source of the funds for this payment represented by a PayPal account or a direct credit card. + */ private Payer payer; - + /** - * - */ + * A payment can have more than one transaction, with each transaction establishing a contract between the payer and a payee + */ private List transactions; - + /** - * - */ + * state of the payment + */ + private String state; + + /** + * Redirect urls required only when using payment_method as PayPal - the only settings supported are return and cancel urls. + */ private RedirectUrls redirectUrls; - + /** * - */ - private List links; - + */ + private List links; + /** * Returns the last request sent to the Service * @@ -85,7 +76,7 @@ public static String getLastRequest() { public static String getLastResponse() { return PayPalResource.getLastResponse(); } - + /** * Initialize using InputStream(of a Properties file) * @@ -117,139 +108,220 @@ public static void initConfig(File file) throws PayPalRESTException { public static void initConfig(Properties properties) { PayPalResource.initConfig(properties); } - - /** - * Constructor + * Default Constructor */ public Payment() { - - } + } /** - * Getter for id + * Parameterized Constructor */ - public String getId() { - return id; + public Payment(String intent, Payer payer, List transactions) { + this.intent = intent; + this.payer = payer; + this.transactions = transactions; } + /** - * Setter for id; + * Setter for id */ public void setId(String id) { this.id = id; } + + /** + * Getter for id + */ + public String getId() { + return this.id; + } + + + /** + * Setter for createTime + */ + public void setCreateTime(String createTime) { + this.createTime = createTime; + } + /** * Getter for createTime */ public String getCreateTime() { - return createTime; + return this.createTime; + } + + + /** + * Setter for intent + */ + public void setIntent(String intent) { + this.intent = intent; } /** - * Setter for createTime; + * Getter for intent */ - public void setCreateTime(String createTime) { - this.createTime = createTime; + public String getIntent() { + return this.intent; } + + /** - * Getter for updateTime + * Setter for payer */ - public String getUpdateTime() { - return updateTime; + public void setPayer(Payer payer) { + this.payer = payer; } /** - * Setter for updateTime; + * Getter for payer */ - public void setUpdateTime(String updateTime) { - this.updateTime = updateTime; + public Payer getPayer() { + return this.payer; } + + /** - * Getter for state + * Setter for transactions */ - public String getState() { - return state; + public void setTransactions(List transactions) { + this.transactions = transactions; } /** - * Setter for state; + * Getter for transactions + */ + public List getTransactions() { + return this.transactions; + } + + + /** + * Setter for state */ public void setState(String state) { this.state = state; } + /** - * Getter for intent + * Getter for state */ - public String getIntent() { - return intent; + public String getState() { + return this.state; + } + + + /** + * Setter for redirectUrls + */ + public void setRedirectUrls(RedirectUrls redirectUrls) { + this.redirectUrls = redirectUrls; } /** - * Setter for intent; + * Getter for redirectUrls */ - public void setIntent(String intent) { - this.intent = intent; + public RedirectUrls getRedirectUrls() { + return this.redirectUrls; } + + /** - * Getter for payer + * Setter for links */ - public Payer getPayer() { - return payer; + public void setLinks(List links) { + this.links = links; } /** - * Setter for payer; + * Getter for links */ - public void setPayer(Payer payer) { - this.payer = payer; + public List getLinks() { + return this.links; } + + /** - * Getter for transactions + * Creates (and processes) a new Payment Resource. */ - public List getTransactions() { - return transactions; + public Payment create(String accessToken) throws PayPalRESTException { + APIContext apiContext = new APIContext(accessToken); + return create(apiContext); } /** - * Setter for transactions; + * Creates (and processes) a new Payment Resource. */ - public void setTransactions(List transactions) { - this.transactions = transactions; + public Payment create(APIContext apiContext) throws PayPalRESTException { + if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { + throw new IllegalArgumentException("AccessToken cannot be null or empty"); + } + String resourcePath = "v1/payments/payment"; + String payLoad = this.toJSON(); + return PayPalResource.configureAndExecute(apiContext, HttpMethod.POST, resourcePath, payLoad, Payment.class); } + + /** - * Getter for redirectUrls + * Obtain the Payment resource for the given identifier. */ - public RedirectUrls getRedirectUrls() { - return redirectUrls; + public static Payment get(String accessToken, String paymentId) throws PayPalRESTException { + APIContext apiContext = new APIContext(accessToken); + return get(apiContext, paymentId); } /** - * Setter for redirectUrls; + * Obtain the Payment resource for the given identifier. */ - public void setRedirectUrls(RedirectUrls redirectUrls) { - this.redirectUrls = redirectUrls; + public static Payment get(APIContext apiContext, String paymentId) throws PayPalRESTException { + if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { + throw new IllegalArgumentException("AccessToken cannot be null or empty"); + } + if (paymentId == null) { + throw new IllegalArgumentException("paymentId cannot be null"); + } + Object[] parameters = new Object[] {paymentId}; + String pattern = "v1/payments/payment/{0}"; + String resourcePath = RESTUtil.formatURIPath(pattern, parameters); + String payLoad = ""; + return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, Payment.class); } + + /** - * Getter for links + * Executes the payment (after approved by the Payer) associated with this resource when the payment method is PayPal. */ - public List getLinks() { - return links; + public Payment execute(String accessToken, PaymentExecution paymentExecution) throws PayPalRESTException { + APIContext apiContext = new APIContext(accessToken); + return execute(apiContext, paymentExecution); } /** - * Setter for links; + * Executes the payment (after approved by the Payer) associated with this resource when the payment method is PayPal. */ - public void setLinks(List links) { - this.links = links; + public Payment execute(APIContext apiContext, PaymentExecution paymentExecution) throws PayPalRESTException { + if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { + throw new IllegalArgumentException("AccessToken cannot be null or empty"); + } + if (this.getId() == null) { + throw new IllegalArgumentException("Id cannot be null"); + } + if (paymentExecution == null) { + throw new IllegalArgumentException("paymentExecution cannot be null"); + } + Object[] parameters = new Object[] {this.getId()}; + String pattern = "v1/payments/payment/{0}/execute"; + String resourcePath = RESTUtil.formatURIPath(pattern, parameters); + String payLoad = paymentExecution.toJSON(); + return PayPalResource.configureAndExecute(apiContext, HttpMethod.POST, resourcePath, payLoad, Payment.class); } - - + /** - * Get call for Payment. - * @param accessToken - * AccessToken used for the API call + * Retrieves a list of Payment resources. * @param containerMap * Map containing the query strings with the * following values as keys: @@ -262,23 +334,14 @@ public void setLinks(List links) { * sort_by, * sort_order, * All other keys in the map are ignored by the SDK - * @HttpMethod GET - * @URIpath v1/payments/payment?count=:count&start_id=:start_id&start_index=:start_index&start_time=:start_time&end_time=:end_time&payee_id=:payee_id&sort_by=:sort_by&sort_order=:sort_order - * @return PaymentHistory */ - public static PaymentHistory get(String accessToken, Map containerMap) throws PayPalRESTException { - String pattern = "v1/payments/payment?count={0}&start_id={1}&start_index={2}&start_time={3}&end_time={4}&payee_id={5}&sort_by={6}&sort_order={7}"; - Object[] parameters = new Object[] { containerMap }; - String resourcePath = RESTUtil.formatURIPath(pattern, parameters); - String payLoad = ""; + public static PaymentHistory list(String accessToken, Map containerMap) throws PayPalRESTException { APIContext apiContext = new APIContext(accessToken); - return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, PaymentHistory.class); + return list(apiContext, containerMap); } /** - * Get call for Payment. - * @param apiContext - * {@link APIContext} to be used for the call. + * Retrieves a list of Payment resources. * @param containerMap * Map containing the query strings with the * following values as keys: @@ -291,179 +354,129 @@ public static PaymentHistory get(String accessToken, Map contain * sort_by, * sort_order, * All other keys in the map are ignored by the SDK - * @HttpMethod GET - * @URIpath v1/payments/payment?count=:count&start_id=:start_id&start_index=:start_index&start_time=:start_time&end_time=:end_time&payee_id=:payee_id&sort_by=:sort_by&sort_order=:sort_order - * @return PaymentHistory */ - public static PaymentHistory get(APIContext apiContext, Map containerMap) throws PayPalRESTException { + public static PaymentHistory list(APIContext apiContext, Map containerMap) throws PayPalRESTException { if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { throw new IllegalArgumentException("AccessToken cannot be null or empty"); } + if (containerMap == null) { + throw new IllegalArgumentException("containerMap cannot be null"); + } + Object[] parameters = new Object[] {containerMap}; String pattern = "v1/payments/payment?count={0}&start_id={1}&start_index={2}&start_time={3}&end_time={4}&payee_id={5}&sort_by={6}&sort_order={7}"; - Object[] parameters = new Object[] { containerMap }; String resourcePath = RESTUtil.formatURIPath(pattern, parameters); String payLoad = ""; - if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { - throw new IllegalArgumentException("AccessToken cannot be null in APIContext"); - } return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, PaymentHistory.class); } - /** * Get call for Payment. + * @deprecated * @param accessToken * AccessToken used for the API call - * @param queryParameters - * Container for query strings + * @param containerMap + * Map containing the query strings with the + * following values as keys: + * count, + * start_id, + * start_index, + * start_time, + * end_time, + * payee_id, + * sort_by, + * sort_order, + * All other keys in the map are ignored by the SDK * @HttpMethod GET * @URIpath v1/payments/payment?count=:count&start_id=:start_id&start_index=:start_index&start_time=:start_time&end_time=:end_time&payee_id=:payee_id&sort_by=:sort_by&sort_order=:sort_order * @return PaymentHistory */ - public static PaymentHistory get(String accessToken, QueryParameters queryParameters) throws PayPalRESTException { - String pattern = "v1/payments/payment?count={0}&start_id={1}&start_index={2}&start_time={3}&end_time={4}&payee_id={5}&sort_by={6}&sort_order={7}"; - Object[] parameters = new Object[] { queryParameters }; - String resourcePath = RESTUtil.formatURIPath(pattern, parameters); - String payLoad = ""; - APIContext apiContext = new APIContext(accessToken); - return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, PaymentHistory.class); + public static PaymentHistory get(String accessToken, Map containerMap) throws PayPalRESTException { + return list(accessToken, containerMap); } /** * Get call for Payment. + * @deprecated * @param apiContext * {@link APIContext} to be used for the call. - * @param queryParameters - * Container for query strings + * @param containerMap + * Map containing the query strings with the + * following values as keys: + * count, + * start_id, + * start_index, + * start_time, + * end_time, + * payee_id, + * sort_by, + * sort_order, + * All other keys in the map are ignored by the SDK * @HttpMethod GET * @URIpath v1/payments/payment?count=:count&start_id=:start_id&start_index=:start_index&start_time=:start_time&end_time=:end_time&payee_id=:payee_id&sort_by=:sort_by&sort_order=:sort_order * @return PaymentHistory */ - public static PaymentHistory get(APIContext apiContext, QueryParameters queryParameters) throws PayPalRESTException { - String pattern = "v1/payments/payment?count={0}&start_id={1}&start_index={2}&start_time={3}&end_time={4}&payee_id={5}&sort_by={6}&sort_order={7}"; - Object[] parameters = new Object[] { queryParameters }; - String resourcePath = RESTUtil.formatURIPath(pattern, parameters); - String payLoad = ""; - if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { - throw new IllegalArgumentException("AccessToken cannot be null in APIContext"); - } - return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, PaymentHistory.class); - } - - /** - * Create call for Payment. - * @param accessToken - * AccessToken used for the API call - * @HttpMethod POST - * @URIpath v1/payments/payment - * @return Payment - */ - public Payment create(String accessToken) throws PayPalRESTException { - APIContext apiContext = new APIContext(accessToken); - return create(apiContext); + public static PaymentHistory get(APIContext apiContext, Map containerMap) throws PayPalRESTException { + return list(apiContext, containerMap); } - /** - * Create call for Payment. - * @param apiContext - * APIContext used for the API call - * @HttpMethod POST - * @URIpath v1/payments/payment - * @return Payment - */ - public Payment create(APIContext apiContext) throws PayPalRESTException { - if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { - throw new IllegalArgumentException("AccessToken cannot be null or empty"); - } - String resourcePath = "v1/payments/payment"; - String payLoad = this.toJSON(); - return PayPalResource.configureAndExecute(apiContext, HttpMethod.POST, resourcePath, payLoad, Payment.class); - } /** * Get call for Payment. + * @deprecated * @param accessToken * AccessToken used for the API call - * @param paymentId + * @param queryParameters + * Container for query strings * @HttpMethod GET - * @URIpath v1/payments/payment/:paymentId - * @return Payment + * @URIpath v1/payments/payment?count=:count&start_id=:start_id&start_index=:start_index&start_time=:start_time&end_time=:end_time&payee_id=:payee_id&sort_by=:sort_by&sort_order=:sort_order + * @return PaymentHistory */ - public static Payment get(String accessToken, String paymentId) throws PayPalRESTException { - if ((paymentId == null) || (paymentId.length() <= 0)) { - throw new IllegalArgumentException("paymentId cannot be null or empty"); - } - String pattern = "v1/payments/payment/{0}"; - Object[] parameters = new Object[] { paymentId }; - String resourcePath = RESTUtil.formatURIPath(pattern, parameters); - String payLoad = ""; - APIContext apiContext = new APIContext(accessToken); - return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, Payment.class); + public static PaymentHistory get(String accessToken, QueryParameters queryParameters) throws PayPalRESTException { + return list(accessToken, queryParameters); } /** * Get call for Payment. + * @deprecated * @param apiContext * {@link APIContext} to be used for the call. - * @param paymentId + * @param queryParameters + * Container for query strings * @HttpMethod GET - * @URIpath v1/payments/payment/:paymentId - * @return Payment + * @URIpath v1/payments/payment?count=:count&start_id=:start_id&start_index=:start_index&start_time=:start_time&end_time=:end_time&payee_id=:payee_id&sort_by=:sort_by&sort_order=:sort_order + * @return PaymentHistory */ - public static Payment get(APIContext apiContext, String paymentId) throws PayPalRESTException { - if ((paymentId == null) || (paymentId.length() <= 0)) { - throw new IllegalArgumentException("paymentId cannot be null or empty"); - } - String pattern = "v1/payments/payment/{0}"; - Object[] parameters = new Object[] { paymentId }; - String resourcePath = RESTUtil.formatURIPath(pattern, parameters); - String payLoad = ""; - if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { - throw new IllegalArgumentException("AccessToken cannot be null in APIContext"); - } - return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, Payment.class); + public static PaymentHistory get(APIContext apiContext, QueryParameters queryParameters) throws PayPalRESTException { + return list(apiContext, queryParameters); } - + /** - * Execute call for Payment. - * @param accessToken - * AccessToken used for the API call - * @param paymentExecution - * @HttpMethod POST - * @URIpath v1/payments/payment/:paymentId/execute - * @return Payment + * Retrieves a list of Payment resources. + * @deprecated */ - public Payment execute(String accessToken, PaymentExecution paymentExecution) throws PayPalRESTException { + public static PaymentHistory list(String accessToken, QueryParameters queryParameters) throws PayPalRESTException { APIContext apiContext = new APIContext(accessToken); - return execute(apiContext, paymentExecution); + return list(apiContext, queryParameters); } /** - * Execute call for Payment. - * @param apiContext - * APIContext used for the API call - * @param paymentExecution - * @HttpMethod POST - * @URIpath v1/payments/payment/:paymentId/execute - * @return Payment + * Retrieves a list of Payment resources. + * @deprecated */ - public Payment execute(APIContext apiContext, PaymentExecution paymentExecution) throws PayPalRESTException { + public static PaymentHistory list(APIContext apiContext, QueryParameters queryParameters) throws PayPalRESTException { if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { throw new IllegalArgumentException("AccessToken cannot be null or empty"); } - if (paymentExecution == null) { - throw new IllegalArgumentException("paymentExecution cannot be null"); - } - if (this.getId() == null) { - throw new IllegalArgumentException("Id cannot be null"); + if (queryParameters == null) { + throw new IllegalArgumentException("queryParameters cannot be null"); } - String pattern = "v1/payments/payment/{0}/execute"; - Object[] parameters = new Object[] { this.getId() }; + Object[] parameters = new Object[] {queryParameters}; + String pattern = "v1/payments/payment?count={0}&start_id={1}&start_index={2}&start_time={3}&end_time={4}&payee_id={5}&sort_by={6}&sort_order={7}"; String resourcePath = RESTUtil.formatURIPath(pattern, parameters); - String payLoad = paymentExecution.toJSON(); - return PayPalResource.configureAndExecute(apiContext, HttpMethod.POST, resourcePath, payLoad, Payment.class); + String payLoad = ""; + return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, PaymentHistory.class); } - + /** * Returns a JSON string corresponding to object state * @@ -472,10 +485,9 @@ public Payment execute(APIContext apiContext, PaymentExecution paymentExecution) public String toJSON() { return JSONFormatter.toJSON(this); } - + @Override public String toString() { return toJSON(); } - } \ No newline at end of file diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/PaymentExecution.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/PaymentExecution.java index e42b3b3b..4ae76dd7 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/PaymentExecution.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/PaymentExecution.java @@ -1,61 +1,73 @@ package com.paypal.api.payments; -import java.util.List; -import com.paypal.api.payments.Amount; -import com.paypal.api.payments.Resource; -import com.paypal.core.rest.JSONFormatter; -/** - * - */ -public class PaymentExecution extends Resource { +import com.paypal.core.rest.JSONFormatter; +import com.paypal.api.payments.Transactions; +import java.util.List; +import java.util.Map; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; +import com.paypal.core.rest.HttpMethod; +import com.paypal.core.rest.RESTUtil; +import com.paypal.core.rest.QueryParameters; +import com.paypal.core.rest.APIContext; +import java.io.File; +import java.io.InputStream; +import java.util.Properties; +public class PaymentExecution { /** - * - */ + * PayPal assigned Payer ID returned in the approval return url. + */ private String payerId; - + /** - * - */ - private List transactions; - + * If the amount needs to be updated after obtaining the PayPal Payer info (eg. shipping address), it can be updated using this element. + */ + private List transactions; + /** - * Constructor + * Default Constructor */ public PaymentExecution() { - - } + } /** - * Getter for payerId + * Parameterized Constructor */ - public String getPayerId() { - return payerId; + public PaymentExecution(String payerId) { + this.payerId = payerId; } + /** - * Setter for payerId; + * Setter for payerId */ public void setPayerId(String payerId) { this.payerId = payerId; } + /** - * Getter for transactions + * Getter for payerId */ - public List getTransactions() { - return transactions; + public String getPayerId() { + return this.payerId; } - + + /** - * Setter for transactions; + * Setter for transactions */ - public void setTransactions(List transactions) { + public void setTransactions(List transactions) { this.transactions = transactions; } - - - + + /** + * Getter for transactions + */ + public List getTransactions() { + return this.transactions; + } /** * Returns a JSON string corresponding to object state @@ -65,10 +77,9 @@ public void setTransactions(List transactions) { public String toJSON() { return JSONFormatter.toJSON(this); } - + @Override public String toString() { return toJSON(); } - } \ No newline at end of file diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/PaymentHistory.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/PaymentHistory.java index 94e08fa2..e36d323b 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/PaymentHistory.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/PaymentHistory.java @@ -1,80 +1,87 @@ package com.paypal.api.payments; -import java.util.List; -import com.paypal.api.payments.Payment; -import com.paypal.api.payments.Resource; -import com.paypal.core.rest.JSONFormatter; -/** - * - */ -public class PaymentHistory extends Resource { +import com.paypal.core.rest.JSONFormatter; +import com.paypal.api.payments.Payment; +import java.util.List; +import java.util.Map; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; +import com.paypal.core.rest.HttpMethod; +import com.paypal.core.rest.RESTUtil; +import com.paypal.core.rest.QueryParameters; +import com.paypal.core.rest.APIContext; +import java.io.File; +import java.io.InputStream; +import java.util.Properties; +public class PaymentHistory { /** - * - */ + * A list of Payment resources + */ private List payments; - + /** - * - */ - private Integer count; - + * Number of items returned in each range of results. Note that the last results range could have fewer items than the requested number of items. + */ + private int count; + /** - * - */ + * Identifier of the next element to get the next range of results. + */ private String nextId; - + /** - * Constructor + * Default Constructor */ public PaymentHistory() { + } - } /** - * Getter for payments + * Setter for payments */ - public List getPayments() { - return payments; + public void setPayments(List payments) { + this.payments = payments; } /** - * Setter for payments; + * Getter for payments */ - public void setPayments(List payments) { - this.payments = payments; + public List getPayments() { + return this.payments; } + + /** - * Getter for count + * Setter for count */ - public Integer getCount() { - return count; + public void setCount(int count) { + this.count = count; } /** - * Setter for count; + * Getter for count */ - public void setCount(Integer count) { - this.count = count; + public int getCount() { + return this.count; } + + /** - * Getter for nextId + * Setter for nextId */ - public String getNextId() { - return nextId; + public void setNextId(String nextId) { + this.nextId = nextId; } /** - * Setter for nextId; + * Getter for nextId */ - public void setNextId(String nextId) { - this.nextId = nextId; + public String getNextId() { + return this.nextId; } - - - /** * Returns a JSON string corresponding to object state * @@ -83,10 +90,9 @@ public void setNextId(String nextId) { public String toJSON() { return JSONFormatter.toJSON(this); } - + @Override public String toString() { return toJSON(); } - } \ No newline at end of file diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/RedirectUrls.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/RedirectUrls.java index 5ba3cae9..255b9e0e 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/RedirectUrls.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/RedirectUrls.java @@ -1,60 +1,65 @@ package com.paypal.api.payments; -import com.paypal.api.payments.Resource; -import com.paypal.core.rest.JSONFormatter; -/** - * - */ -public class RedirectUrls extends Resource { +import com.paypal.core.rest.JSONFormatter; +import java.util.Map; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; +import com.paypal.core.rest.HttpMethod; +import com.paypal.core.rest.RESTUtil; +import com.paypal.core.rest.QueryParameters; +import com.paypal.core.rest.APIContext; +import java.io.File; +import java.io.InputStream; +import java.util.Properties; +public class RedirectUrls { /** - * - */ + * Url where the payer would be redirected to after approving the payment. + */ private String returnUrl; - + /** - * - */ + * Url where the payer would be redirected to after canceling the payment. + */ private String cancelUrl; - + /** - * Constructor + * Default Constructor */ public RedirectUrls() { + } - } /** - * Getter for returnUrl + * Setter for returnUrl */ - public String getReturnUrl() { - return returnUrl; + public void setReturnUrl(String returnUrl) { + this.returnUrl = returnUrl; } /** - * Setter for returnUrl; + * Getter for returnUrl */ - public void setReturnUrl(String returnUrl) { - this.returnUrl = returnUrl; + public String getReturnUrl() { + return this.returnUrl; } + + /** - * Getter for cancelUrl + * Setter for cancelUrl */ - public String getCancelUrl() { - return cancelUrl; + public void setCancelUrl(String cancelUrl) { + this.cancelUrl = cancelUrl; } /** - * Setter for cancelUrl; + * Getter for cancelUrl */ - public void setCancelUrl(String cancelUrl) { - this.cancelUrl = cancelUrl; + public String getCancelUrl() { + return this.cancelUrl; } - - - /** * Returns a JSON string corresponding to object state * @@ -63,10 +68,9 @@ public void setCancelUrl(String cancelUrl) { public String toJSON() { return JSONFormatter.toJSON(this); } - + @Override public String toString() { return toJSON(); } - } \ No newline at end of file diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Refund.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Refund.java index f085ad4c..e93ad19a 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Refund.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Refund.java @@ -1,74 +1,67 @@ package com.paypal.api.payments; + +import com.paypal.core.rest.JSONFormatter; import com.paypal.api.payments.Amount; +import com.paypal.api.payments.Links; import java.util.List; -import com.paypal.api.payments.Link; -import com.paypal.api.payments.Resource; +import java.util.Map; +import com.paypal.core.rest.PayPalRESTException; import com.paypal.core.rest.PayPalResource; import com.paypal.core.rest.HttpMethod; -import com.paypal.core.rest.PayPalRESTException; import com.paypal.core.rest.RESTUtil; -import com.paypal.core.rest.JSONFormatter; +import com.paypal.core.rest.QueryParameters; import com.paypal.core.rest.APIContext; import java.io.File; import java.io.InputStream; import java.util.Properties; -/** - * - */ -public class Refund extends Resource { - +public class Refund { /** - * - */ + * Identifier of the refund transaction. + */ private String id; - + /** - * - */ + * Time the resource was created. + */ private String createTime; - + /** - * - */ - private String updateTime; - + * Details including both refunded amount (to Payer) and refunded fee (to Payee).If amount is not specified, it's assumed to be full refund. + */ + private Amount amount; + /** - * - */ + * State of the refund transaction. + */ private String state; - - /** - * - */ - private Amount amount; - + /** - * - */ + * ID of the Sale transaction being refunded. + */ private String saleId; - + /** - * - */ + * ID of the Capture transaction being refunded. + */ private String captureId; - + /** - * - */ + * ID of the Payment resource that this transaction is based on. + */ private String parentPayment; - + /** - * - */ + * Description of what is being refunded for. + */ private String description; - + /** * - */ - private List links; - + */ + private List links; + /** * Returns the last request sent to the Service * @@ -86,7 +79,7 @@ public static String getLastRequest() { public static String getLastResponse() { return PayPalResource.getLastResponse(); } - + /** * Initialize using InputStream(of a Properties file) * @@ -118,193 +111,173 @@ public static void initConfig(File file) throws PayPalRESTException { public static void initConfig(Properties properties) { PayPalResource.initConfig(properties); } - - /** - * Constructor + * Default Constructor */ public Refund() { + } - } /** - * Getter for id - */ - public String getId() { - return id; - } - - /** - * Setter for id; + * Setter for id */ public void setId(String id) { this.id = id; } + /** - * Getter for createTime + * Getter for id */ - public String getCreateTime() { - return createTime; + public String getId() { + return this.id; } - + + /** - * Setter for createTime; + * Setter for createTime */ public void setCreateTime(String createTime) { this.createTime = createTime; } + /** - * Getter for updateTime + * Getter for createTime */ - public String getUpdateTime() { - return updateTime; + public String getCreateTime() { + return this.createTime; } - + + /** - * Setter for updateTime; + * Setter for amount */ - public void setUpdateTime(String updateTime) { - this.updateTime = updateTime; + public void setAmount(Amount amount) { + this.amount = amount; } + /** - * Getter for state + * Getter for amount */ - public String getState() { - return state; + public Amount getAmount() { + return this.amount; } - + + /** - * Setter for state; + * Setter for state */ public void setState(String state) { this.state = state; } + /** - * Getter for amount + * Getter for state */ - public Amount getAmount() { - return amount; + public String getState() { + return this.state; } - + + /** - * Setter for amount; + * Setter for saleId */ - public void setAmount(Amount amount) { - this.amount = amount; + public void setSaleId(String saleId) { + this.saleId = saleId; } + /** * Getter for saleId */ public String getSaleId() { - return saleId; + return this.saleId; } - + + /** - * Setter for saleId; + * Setter for captureId */ - public void setSaleId(String saleId) { - this.saleId = saleId; + public void setCaptureId(String captureId) { + this.captureId = captureId; } + /** * Getter for captureId */ public String getCaptureId() { - return captureId; + return this.captureId; } - + + /** - * Setter for captureId; + * Setter for parentPayment */ - public void setCaptureId(String captureId) { - this.captureId = captureId; + public void setParentPayment(String parentPayment) { + this.parentPayment = parentPayment; } + /** * Getter for parentPayment */ public String getParentPayment() { - return parentPayment; + return this.parentPayment; } - + + /** - * Setter for parentPayment; + * Setter for description */ - public void setParentPayment(String parentPayment) { - this.parentPayment = parentPayment; + public void setDescription(String description) { + this.description = description; } + /** * Getter for description */ public String getDescription() { - return description; - } - - /** - * Setter for description; - */ - public void setDescription(String description) { - this.description = description; + return this.description; } + + /** - * Getter for links + * Setter for links */ - public List getLinks() { - return links; + public void setLinks(List links) { + this.links = links; } /** - * Setter for links; + * Getter for links */ - public void setLinks(List links) { - this.links = links; + public List getLinks() { + return this.links; } - - /** - * Get call for Refund. - * @param accessToken - * AccessToken used for the API call - * @param refundId - * @HttpMethod GET - * @URIpath v1/payments/refund/:refundId - * @return Refund + * Obtain the Refund transaction resource for the given identifier. */ public static Refund get(String accessToken, String refundId) throws PayPalRESTException { - if ((refundId == null) || (refundId.length() <= 0)) { - throw new IllegalArgumentException("refundId cannot be null or empty"); - } - String pattern = "v1/payments/refund/{0}"; - Object[] parameters = new Object[] { refundId }; - String resourcePath = RESTUtil.formatURIPath(pattern, parameters); - String payLoad = ""; APIContext apiContext = new APIContext(accessToken); - return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, Refund.class); + return get(apiContext, refundId); } /** - * Get call for Refund. - * @param apiContext - * {@link APIContext} to be used for the call. - * @param refundId - * @HttpMethod GET - * @URIpath v1/payments/refund/:refundId - * @return Refund + * Obtain the Refund transaction resource for the given identifier. */ public static Refund get(APIContext apiContext, String refundId) throws PayPalRESTException { - if ((refundId == null) || (refundId.length() <= 0)) { - throw new IllegalArgumentException("refundId cannot be null or empty"); + if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { + throw new IllegalArgumentException("AccessToken cannot be null or empty"); + } + if (refundId == null) { + throw new IllegalArgumentException("refundId cannot be null"); } + Object[] parameters = new Object[] {refundId}; String pattern = "v1/payments/refund/{0}"; - Object[] parameters = new Object[] { refundId }; String resourcePath = RESTUtil.formatURIPath(pattern, parameters); String payLoad = ""; - if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { - throw new IllegalArgumentException("AccessToken cannot be null in APIContext"); - } return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, Refund.class); } - + /** * Returns a JSON string corresponding to object state * @@ -313,10 +286,9 @@ public static Refund get(APIContext apiContext, String refundId) throws PayPalRE public String toJSON() { return JSONFormatter.toJSON(this); } - + @Override public String toString() { return toJSON(); } - } \ No newline at end of file diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/SubTransaction.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/RelatedResources.java similarity index 61% rename from rest-api-sdk/src/main/java/com/paypal/api/payments/SubTransaction.java rename to rest-api-sdk/src/main/java/com/paypal/api/payments/RelatedResources.java index 5528d7cc..4c86a6d3 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/SubTransaction.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/RelatedResources.java @@ -1,100 +1,109 @@ package com.paypal.api.payments; + +import com.paypal.core.rest.JSONFormatter; import com.paypal.api.payments.Sale; import com.paypal.api.payments.Authorization; -import com.paypal.api.payments.Refund; import com.paypal.api.payments.Capture; -import com.paypal.api.payments.Resource; -import com.paypal.core.rest.JSONFormatter; - -/** - * - */ -public class SubTransaction extends Resource { +import com.paypal.api.payments.Refund; +import java.util.Map; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; +import com.paypal.core.rest.HttpMethod; +import com.paypal.core.rest.RESTUtil; +import com.paypal.core.rest.QueryParameters; +import com.paypal.core.rest.APIContext; +import java.io.File; +import java.io.InputStream; +import java.util.Properties; +public class RelatedResources { /** - * - */ + * A sale transaction + */ private Sale sale; - + /** - * - */ + * An authorization transaction + */ private Authorization authorization; - - /** - * - */ - private Refund refund; - + /** - * - */ + * A capture transaction + */ private Capture capture; - + /** - * Constructor + * A refund transaction */ - public SubTransaction() { - - } - + private Refund refund; + /** - * Getter for sale + * Default Constructor */ - public Sale getSale() { - return sale; + public RelatedResources() { } - + + /** - * Setter for sale; + * Setter for sale */ public void setSale(Sale sale) { this.sale = sale; } + /** - * Getter for authorization + * Getter for sale */ - public Authorization getAuthorization() { - return authorization; + public Sale getSale() { + return this.sale; } - + + /** - * Setter for authorization; + * Setter for authorization */ public void setAuthorization(Authorization authorization) { this.authorization = authorization; } + /** - * Getter for refund + * Getter for authorization */ - public Refund getRefund() { - return refund; + public Authorization getAuthorization() { + return this.authorization; } - + + /** - * Setter for refund; + * Setter for capture */ - public void setRefund(Refund refund) { - this.refund = refund; + public void setCapture(Capture capture) { + this.capture = capture; } + /** * Getter for capture */ public Capture getCapture() { - return capture; + return this.capture; + } + + + /** + * Setter for refund + */ + public void setRefund(Refund refund) { + this.refund = refund; } /** - * Setter for capture; + * Getter for refund */ - public void setCapture(Capture capture) { - this.capture = capture; + public Refund getRefund() { + return this.refund; } - - - /** * Returns a JSON string corresponding to object state * @@ -103,10 +112,9 @@ public void setCapture(Capture capture) { public String toJSON() { return JSONFormatter.toJSON(this); } - + @Override public String toString() { return toJSON(); } - } \ No newline at end of file diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Resource.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Resource.java deleted file mode 100644 index e9cc1d02..00000000 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Resource.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.paypal.api.payments; -import com.paypal.core.rest.JSONFormatter; - -/** - * - */ -public class Resource{ - - - /** - * Constructor - */ - public Resource() { - - } - - - - - - /** - * Returns a JSON string corresponding to object state - * - * @return JSON representation - */ - public String toJSON() { - return JSONFormatter.toJSON(this); - } - - @Override - public String toString() { - return toJSON(); - } - -} \ No newline at end of file diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Sale.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Sale.java index 19d0a17e..0f521130 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Sale.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Sale.java @@ -1,59 +1,57 @@ package com.paypal.api.payments; + +import com.paypal.core.rest.JSONFormatter; import com.paypal.api.payments.Amount; +import com.paypal.api.payments.Links; import java.util.List; -import com.paypal.api.payments.Link; -import com.paypal.api.payments.Resource; +import java.util.Map; +import com.paypal.core.rest.PayPalRESTException; import com.paypal.core.rest.PayPalResource; import com.paypal.core.rest.HttpMethod; -import com.paypal.core.rest.PayPalRESTException; import com.paypal.core.rest.RESTUtil; -import com.paypal.core.rest.JSONFormatter; +import com.paypal.core.rest.QueryParameters; import com.paypal.core.rest.APIContext; import java.io.File; import java.io.InputStream; import java.util.Properties; -/** - * - */ -public class Sale extends Resource { - +public class Sale { /** - * - */ + * Identifier of the authorization transaction. + */ private String id; - + /** - * - */ + * Time the resource was created. + */ private String createTime; - + /** - * - */ + * Time the resource was last updated. + */ private String updateTime; - - /** - * - */ - private String state; - + /** - * - */ + * Amount being collected. + */ private Amount amount; - + /** - * - */ + * State of the sale transaction. + */ + private String state; + + /** + * ID of the Payment resource that this transaction is based on. + */ private String parentPayment; - + /** * - */ - private List links; - + */ + private List links; + /** * Returns the last request sent to the Service * @@ -71,7 +69,7 @@ public static String getLastRequest() { public static String getLastResponse() { return PayPalResource.getLastResponse(); } - + /** * Initialize using InputStream(of a Properties file) * @@ -103,162 +101,155 @@ public static void initConfig(File file) throws PayPalRESTException { public static void initConfig(Properties properties) { PayPalResource.initConfig(properties); } - - /** - * Constructor + * Default Constructor */ public Sale() { - - } + } /** - * Getter for id + * Parameterized Constructor */ - public String getId() { - return id; + public Sale(Amount amount, String state, String parentPayment) { + this.amount = amount; + this.state = state; + this.parentPayment = parentPayment; } + /** - * Setter for id; + * Setter for id */ public void setId(String id) { this.id = id; } + /** - * Getter for createTime + * Getter for id */ - public String getCreateTime() { - return createTime; + public String getId() { + return this.id; } - + + /** - * Setter for createTime; + * Setter for createTime */ public void setCreateTime(String createTime) { this.createTime = createTime; } + /** - * Getter for updateTime + * Getter for createTime */ - public String getUpdateTime() { - return updateTime; + public String getCreateTime() { + return this.createTime; } - + + /** - * Setter for updateTime; + * Setter for updateTime */ public void setUpdateTime(String updateTime) { this.updateTime = updateTime; } + /** - * Getter for state + * Getter for updateTime */ - public String getState() { - return state; + public String getUpdateTime() { + return this.updateTime; } - + + /** - * Setter for state; + * Setter for amount */ - public void setState(String state) { - this.state = state; + public void setAmount(Amount amount) { + this.amount = amount; } + /** * Getter for amount */ public Amount getAmount() { - return amount; + return this.amount; } - + + /** - * Setter for amount; + * Setter for state */ - public void setAmount(Amount amount) { - this.amount = amount; + public void setState(String state) { + this.state = state; } + /** - * Getter for parentPayment + * Getter for state */ - public String getParentPayment() { - return parentPayment; + public String getState() { + return this.state; } - + + /** - * Setter for parentPayment; + * Setter for parentPayment */ public void setParentPayment(String parentPayment) { this.parentPayment = parentPayment; } + /** - * Getter for links + * Getter for parentPayment + */ + public String getParentPayment() { + return this.parentPayment; + } + + + /** + * Setter for links */ - public List getLinks() { - return links; + public void setLinks(List links) { + this.links = links; } /** - * Setter for links; + * Getter for links */ - public void setLinks(List links) { - this.links = links; + public List getLinks() { + return this.links; } - - /** - * Get call for Sale. - * @param accessToken - * AccessToken used for the API call - * @param saleId - * @HttpMethod GET - * @URIpath v1/payments/sale/:saleId - * @return Sale + * Obtain the Sale transaction resource for the given identifier. */ public static Sale get(String accessToken, String saleId) throws PayPalRESTException { - if ((saleId == null) || (saleId.length() <= 0)) { - throw new IllegalArgumentException("saleId cannot be null or empty"); - } - String pattern = "v1/payments/sale/{0}"; - Object[] parameters = new Object[] { saleId }; - String resourcePath = RESTUtil.formatURIPath(pattern, parameters); - String payLoad = ""; APIContext apiContext = new APIContext(accessToken); - return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, Sale.class); + return get(apiContext, saleId); } /** - * Get call for Sale. - * @param apiContext - * {@link APIContext} to be used for the call. - * @param saleId - * @HttpMethod GET - * @URIpath v1/payments/sale/:saleId - * @return Sale + * Obtain the Sale transaction resource for the given identifier. */ public static Sale get(APIContext apiContext, String saleId) throws PayPalRESTException { - if ((saleId == null) || (saleId.length() <= 0)) { - throw new IllegalArgumentException("saleId cannot be null or empty"); + if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { + throw new IllegalArgumentException("AccessToken cannot be null or empty"); + } + if (saleId == null) { + throw new IllegalArgumentException("saleId cannot be null"); } + Object[] parameters = new Object[] {saleId}; String pattern = "v1/payments/sale/{0}"; - Object[] parameters = new Object[] { saleId }; String resourcePath = RESTUtil.formatURIPath(pattern, parameters); String payLoad = ""; - if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { - throw new IllegalArgumentException("AccessToken cannot be null in APIContext"); - } return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, Sale.class); } + /** - * Refund call for Sale. - * @param accessToken - * AccessToken used for the API call - * @param refund - * @HttpMethod POST - * @URIpath v1/payments/sale/:saleId/refund - * @return Refund + * Creates (and processes) a new Refund Transaction added as a related resource. */ public Refund refund(String accessToken, Refund refund) throws PayPalRESTException { APIContext apiContext = new APIContext(accessToken); @@ -266,31 +257,25 @@ public Refund refund(String accessToken, Refund refund) throws PayPalRESTExcepti } /** - * Refund call for Sale. - * @param apiContext - * APIContext used for the API call - * @param refund - * @HttpMethod POST - * @URIpath v1/payments/sale/:saleId/refund - * @return Refund + * Creates (and processes) a new Refund Transaction added as a related resource. */ public Refund refund(APIContext apiContext, Refund refund) throws PayPalRESTException { if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { throw new IllegalArgumentException("AccessToken cannot be null or empty"); } - if (refund == null) { - throw new IllegalArgumentException("refund cannot be null"); - } if (this.getId() == null) { throw new IllegalArgumentException("Id cannot be null"); } + if (refund == null) { + throw new IllegalArgumentException("refund cannot be null"); + } + Object[] parameters = new Object[] {this.getId()}; String pattern = "v1/payments/sale/{0}/refund"; - Object[] parameters = new Object[] { this.getId() }; String resourcePath = RESTUtil.formatURIPath(pattern, parameters); - String payLoad = refund.toJSON(); + String payLoad = refund.toJSON(); return PayPalResource.configureAndExecute(apiContext, HttpMethod.POST, resourcePath, payLoad, Refund.class); } - + /** * Returns a JSON string corresponding to object state * @@ -299,10 +284,9 @@ public Refund refund(APIContext apiContext, Refund refund) throws PayPalRESTExce public String toJSON() { return JSONFormatter.toJSON(this); } - + @Override public String toString() { return toJSON(); } - } \ No newline at end of file diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/ShippingAddress.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/ShippingAddress.java index bf874b67..322b5b70 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/ShippingAddress.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/ShippingAddress.java @@ -1,41 +1,52 @@ package com.paypal.api.payments; -import com.paypal.api.payments.Address; + import com.paypal.core.rest.JSONFormatter; +import java.util.Map; +import com.paypal.api.payments.Address; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; +import com.paypal.core.rest.HttpMethod; +import com.paypal.core.rest.RESTUtil; +import com.paypal.core.rest.QueryParameters; +import com.paypal.core.rest.APIContext; +import java.io.File; +import java.io.InputStream; +import java.util.Properties; -/** - * - */ public class ShippingAddress extends Address { - /** - * - */ + * Name of the recipient at this address. + */ private String recipientName; - + /** - * Constructor + * Default Constructor */ public ShippingAddress() { - - } + } /** - * Getter for recipientName + * Parameterized Constructor */ - public String getRecipientName() { - return recipientName; + public ShippingAddress(String recipientName) { + this.recipientName = recipientName; } + /** - * Setter for recipientName; + * Setter for recipientName */ public void setRecipientName(String recipientName) { this.recipientName = recipientName; } - - - + + /** + * Getter for recipientName + */ + public String getRecipientName() { + return this.recipientName; + } /** * Returns a JSON string corresponding to object state @@ -45,10 +56,9 @@ public void setRecipientName(String recipientName) { public String toJSON() { return JSONFormatter.toJSON(this); } - + @Override public String toString() { return toJSON(); } - } \ No newline at end of file diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Transaction.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Transaction.java index 92357740..a2dc0ab0 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Transaction.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Transaction.java @@ -1,118 +1,156 @@ package com.paypal.api.payments; + +import com.paypal.core.rest.JSONFormatter; import com.paypal.api.payments.Amount; import com.paypal.api.payments.Payee; import com.paypal.api.payments.ItemList; +import com.paypal.api.payments.RelatedResources; import java.util.List; -import com.paypal.api.payments.SubTransaction; -import com.paypal.api.payments.Resource; -import com.paypal.core.rest.JSONFormatter; - -/** - * - */ -public class Transaction extends Resource { +import java.util.Map; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; +import com.paypal.core.rest.HttpMethod; +import com.paypal.core.rest.RESTUtil; +import com.paypal.core.rest.QueryParameters; +import com.paypal.core.rest.APIContext; +import java.io.File; +import java.io.InputStream; +import java.util.Properties; +public class Transaction { /** - * - */ + * Amount being collected. + */ private Amount amount; - + /** - * - */ + * Recepient of the funds in this transaction. + */ private Payee payee; - + /** - * - */ + * Description of what is being paid for. + */ private String description; - + /** - * - */ + * List of items being paid for. + */ private ItemList itemList; - + /** - * - */ - private List relatedResources; - + * List of financial transactions (Sale, Authorization, Capture, Refund) related to the payment. + */ + private List relatedResources; + + /** + * Additional transactions for complex payment (Parallel and Chained) scenarios. + */ + private List transactions; + /** - * Constructor + * Default Constructor */ public Transaction() { - - } + } /** - * Getter for amount + * Parameterized Constructor */ - public Amount getAmount() { - return amount; + public Transaction(Amount amount) { + this.amount = amount; } + /** - * Setter for amount; + * Setter for amount */ public void setAmount(Amount amount) { this.amount = amount; } + /** - * Getter for payee + * Getter for amount */ - public Payee getPayee() { - return payee; + public Amount getAmount() { + return this.amount; } - + + /** - * Setter for payee; + * Setter for payee */ public void setPayee(Payee payee) { this.payee = payee; } + /** - * Getter for description + * Getter for payee */ - public String getDescription() { - return description; + public Payee getPayee() { + return this.payee; } - + + /** - * Setter for description; + * Setter for description */ public void setDescription(String description) { this.description = description; } + /** - * Getter for itemList + * Getter for description */ - public ItemList getItemList() { - return itemList; + public String getDescription() { + return this.description; } - + + /** - * Setter for itemList; + * Setter for itemList */ public void setItemList(ItemList itemList) { this.itemList = itemList; } + /** - * Getter for relatedResources + * Getter for itemList */ - public List getRelatedResources() { - return relatedResources; + public ItemList getItemList() { + return this.itemList; } - + + /** - * Setter for relatedResources; + * Setter for relatedResources */ - public void setRelatedResources(List relatedResources) { + public void setRelatedResources(List relatedResources) { this.relatedResources = relatedResources; } + + /** + * Getter for relatedResources + */ + public List getRelatedResources() { + return this.relatedResources; + } - + /** + * Setter for transactions + */ + public void setTransactions(List transactions) { + this.transactions = transactions; + } + + /** + * Getter for transactions + */ + public List getTransactions() { + return this.transactions; + } /** * Returns a JSON string corresponding to object state @@ -122,10 +160,9 @@ public void setRelatedResources(List relatedResources) { public String toJSON() { return JSONFormatter.toJSON(this); } - + @Override public String toString() { return toJSON(); } - } \ No newline at end of file diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Transactions.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Transactions.java new file mode 100644 index 00000000..d836fd2a --- /dev/null +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Transactions.java @@ -0,0 +1,64 @@ +package com.paypal.api.payments; + +import com.paypal.core.rest.JSONFormatter; +import com.paypal.api.payments.Amount; +import java.util.Map; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; +import com.paypal.core.rest.HttpMethod; +import com.paypal.core.rest.RESTUtil; +import com.paypal.core.rest.QueryParameters; +import com.paypal.core.rest.APIContext; +import java.io.File; +import java.io.InputStream; +import java.util.Properties; + +public class Transactions { + + /** + * Amount being collected. + */ + private Amount amount; + + /** + * Default Constructor + */ + public Transactions() { + } + + /** + * Parameterized Constructor + */ + public Transactions(Amount amount) { + this.amount = amount; + } + + + /** + * Setter for amount + */ + public void setAmount(Amount amount) { + this.amount = amount; + } + + /** + * Getter for amount + */ + public Amount getAmount() { + return this.amount; + } + + /** + * Returns a JSON string corresponding to object state + * + * @return JSON representation + */ + public String toJSON() { + return JSONFormatter.toJSON(this); + } + + @Override + public String toString() { + return toJSON(); + } +} \ No newline at end of file diff --git a/rest-api-sdk/src/test/java/com/paypal/api/payments/AmountTestCase.java b/rest-api-sdk/src/test/java/com/paypal/api/payments/AmountTestCase.java index e1f80749..78daa2e5 100644 --- a/rest-api-sdk/src/test/java/com/paypal/api/payments/AmountTestCase.java +++ b/rest-api-sdk/src/test/java/com/paypal/api/payments/AmountTestCase.java @@ -7,8 +7,8 @@ public class AmountTestCase { public static final String CURRENCY = "USD"; - public static final AmountDetails AMOUNTDETAILS = AmountDetailsTestCase - .createAmountDetails(); + public static final Details AMOUNTDETAILS = DetailsTestCase + .createDetails(); public static Amount createAmount(String total) { Amount amount = new Amount(); @@ -24,7 +24,7 @@ public void testConstruction() { Assert.assertEquals(amount.getTotal(), "1000.00"); Assert.assertEquals(amount.getCurrency(), CURRENCY); Assert.assertEquals(amount.getDetails().getFee(), - AmountDetailsTestCase.FEE); + DetailsTestCase.FEE); } @Test diff --git a/rest-api-sdk/src/test/java/com/paypal/api/payments/AuthorizationTestCase.java b/rest-api-sdk/src/test/java/com/paypal/api/payments/AuthorizationTestCase.java index b184c7c2..f2a390bd 100644 --- a/rest-api-sdk/src/test/java/com/paypal/api/payments/AuthorizationTestCase.java +++ b/rest-api-sdk/src/test/java/com/paypal/api/payments/AuthorizationTestCase.java @@ -19,8 +19,8 @@ public class AuthorizationTestCase { public static final String CREATEDTIME = "2013-01-17T18:12:02.347Z"; public static Authorization createAuthorization() { - List links = new ArrayList(); - links.add(LinkTestCase.createLink()); + List links = new ArrayList(); + links.add(LinksTestCase.createLinks()); Authorization authorization = new Authorization(); authorization.setId(ID); authorization.setParentPayment(PARENTPAYMENT); diff --git a/rest-api-sdk/src/test/java/com/paypal/api/payments/CaptureTestCase.java b/rest-api-sdk/src/test/java/com/paypal/api/payments/CaptureTestCase.java index 75f1ae4d..83e54c9a 100644 --- a/rest-api-sdk/src/test/java/com/paypal/api/payments/CaptureTestCase.java +++ b/rest-api-sdk/src/test/java/com/paypal/api/payments/CaptureTestCase.java @@ -23,10 +23,9 @@ public class CaptureTestCase { public static final String CREATEDTIME = "2013-01-17T18:12:02.347Z"; public static Capture createCapture() { - List links = new ArrayList(); - links.add(LinkTestCase.createLink()); + List links = new ArrayList(); + links.add(LinksTestCase.createLinks()); Capture capture = new Capture(); - capture.setAuthorizationId(AUTHID); capture.setDescription(DESCRIPTION); capture.setId(ID); capture.setParentPayment(PARENTPAYMENT); @@ -41,7 +40,6 @@ public static Capture createCapture() { public void testConstruction() { Capture capture = createCapture(); Assert.assertEquals(capture.getId(), ID); - Assert.assertEquals(capture.getAuthorizationId(), AUTHID); Assert.assertEquals(capture.getDescription(), DESCRIPTION); Assert.assertEquals(capture.getParentPayment(), PARENTPAYMENT); Assert.assertEquals(capture.getState(), STATE); diff --git a/rest-api-sdk/src/test/java/com/paypal/api/payments/CreditCardTestCase.java b/rest-api-sdk/src/test/java/com/paypal/api/payments/CreditCardTestCase.java index 8bdb5f4e..f67c1ace 100644 --- a/rest-api-sdk/src/test/java/com/paypal/api/payments/CreditCardTestCase.java +++ b/rest-api-sdk/src/test/java/com/paypal/api/payments/CreditCardTestCase.java @@ -32,9 +32,9 @@ public class CreditCardTestCase { public static final String LASTNAME = "Shopper"; - public static final String EXPMONTH = "11"; + public static final int EXPMONTH = 11; - public static final String EXPYEAR = "2018"; + public static final int EXPYEAR = 2018; public static final String CVV2 = "874"; @@ -89,8 +89,8 @@ public static CreditCard createDummyCreditCard() { creditCard.setPayerId(PAYERID); creditCard.setState(STATE); creditCard.setValidUntil(VALIDUNTIL); - List links = new ArrayList(); - links.add(LinkTestCase.createLink()); + List links = new ArrayList(); + links.add(LinksTestCase.createLinks()); creditCard.setLinks(links); return creditCard; } diff --git a/rest-api-sdk/src/test/java/com/paypal/api/payments/AmountDetailsTestCase.java b/rest-api-sdk/src/test/java/com/paypal/api/payments/DetailsTestCase.java similarity index 75% rename from rest-api-sdk/src/test/java/com/paypal/api/payments/AmountDetailsTestCase.java rename to rest-api-sdk/src/test/java/com/paypal/api/payments/DetailsTestCase.java index bf43989e..4028e2f1 100644 --- a/rest-api-sdk/src/test/java/com/paypal/api/payments/AmountDetailsTestCase.java +++ b/rest-api-sdk/src/test/java/com/paypal/api/payments/DetailsTestCase.java @@ -3,7 +3,7 @@ import org.testng.Assert; import org.testng.annotations.Test; -public class AmountDetailsTestCase { +public class DetailsTestCase { public static final String FEE = "100.00"; @@ -13,8 +13,8 @@ public class AmountDetailsTestCase { public static final String TAX = "20.00"; - public static AmountDetails createAmountDetails() { - AmountDetails amountDetails = new AmountDetails(); + public static Details createDetails() { + Details amountDetails = new Details(); amountDetails.setFee(FEE); amountDetails.setShipping(SHIPPING); amountDetails.setSubtotal(SUBTOTAL); @@ -24,7 +24,7 @@ public static AmountDetails createAmountDetails() { @Test public void testConstruction() { - AmountDetails amountDetails = createAmountDetails(); + Details amountDetails = createDetails(); Assert.assertEquals(amountDetails.getFee(), FEE); Assert.assertEquals(amountDetails.getShipping(), SHIPPING); Assert.assertEquals(amountDetails.getSubtotal(), SUBTOTAL); @@ -33,13 +33,13 @@ public void testConstruction() { @Test public void testTOJSON() { - AmountDetails amountDetails = createAmountDetails(); + Details amountDetails = createDetails(); Assert.assertEquals(amountDetails.toJSON().length() == 0, false); } @Test public void testTOString() { - AmountDetails amountDetails = createAmountDetails(); + Details amountDetails = createDetails(); Assert.assertEquals(amountDetails.toString().length() == 0, false); } diff --git a/rest-api-sdk/src/test/java/com/paypal/api/payments/LinkTestCase.java b/rest-api-sdk/src/test/java/com/paypal/api/payments/LinksTestCase.java similarity index 76% rename from rest-api-sdk/src/test/java/com/paypal/api/payments/LinkTestCase.java rename to rest-api-sdk/src/test/java/com/paypal/api/payments/LinksTestCase.java index d6375fe2..1efd3105 100644 --- a/rest-api-sdk/src/test/java/com/paypal/api/payments/LinkTestCase.java +++ b/rest-api-sdk/src/test/java/com/paypal/api/payments/LinksTestCase.java @@ -3,7 +3,7 @@ import org.testng.Assert; import org.testng.annotations.Test; -public class LinkTestCase { +public class LinksTestCase { public static final String HREF = "http://sample.com"; @@ -11,8 +11,8 @@ public class LinkTestCase { public static final String REL = "authorize"; - public static Link createLink() { - Link link = new Link(); + public static Links createLinks() { + Links link = new Links(); link.setHref(HREF); link.setMethod(METHOD); link.setRel(REL); @@ -21,7 +21,7 @@ public static Link createLink() { @Test public void testConstruction() { - Link link = LinkTestCase.createLink(); + Links link = LinksTestCase.createLinks(); Assert.assertEquals(link.getHref(), HREF); Assert.assertEquals(link.getRel(), REL); Assert.assertEquals(link.getMethod(), METHOD); @@ -29,13 +29,13 @@ public void testConstruction() { @Test public void testTOJSON() { - Link link = LinkTestCase.createLink(); + Links link = LinksTestCase.createLinks(); Assert.assertEquals(link.toJSON().length() == 0, false); } @Test public void testTOString() { - Link link = LinkTestCase.createLink(); + Links link = LinksTestCase.createLinks(); Assert.assertEquals(link.toString().length() == 0, false); } diff --git a/rest-api-sdk/src/test/java/com/paypal/api/payments/PaymentExecutionTestCase.java b/rest-api-sdk/src/test/java/com/paypal/api/payments/PaymentExecutionTestCase.java index 50fb1b51..e856c4e3 100644 --- a/rest-api-sdk/src/test/java/com/paypal/api/payments/PaymentExecutionTestCase.java +++ b/rest-api-sdk/src/test/java/com/paypal/api/payments/PaymentExecutionTestCase.java @@ -9,8 +9,8 @@ public class PaymentExecutionTestCase { public static PaymentExecution createPaymentExecution(){ - List transactions = new ArrayList(); - transactions.add(AmountTestCase.createAmount("100.00")); + List transactions = new ArrayList(); + transactions.add(TransactionsTestCase.createTransactions()); PaymentExecution pae=new PaymentExecution(); pae.setPayerId(PayerInfoTestCase.PAYERID); pae.setTransactions(transactions); @@ -21,8 +21,8 @@ public static PaymentExecution createPaymentExecution(){ public void testConstruction(){ PaymentExecution pae = createPaymentExecution(); Assert.assertEquals(pae.getPayerId(), PayerInfoTestCase.PAYERID); - Assert.assertEquals(pae.getTransactions().get(0).getTotal(),"100.00"); - Assert.assertEquals(pae.getTransactions().get(0).getCurrency(),AmountTestCase.CURRENCY); + Assert.assertEquals(pae.getTransactions().get(0).getAmount().getTotal(),"100.00"); + Assert.assertEquals(pae.getTransactions().get(0).getAmount().getCurrency(),AmountTestCase.CURRENCY); } diff --git a/rest-api-sdk/src/test/java/com/paypal/api/payments/PaymentHistoryTestCase.java b/rest-api-sdk/src/test/java/com/paypal/api/payments/PaymentHistoryTestCase.java index 551bfb55..a8d4e32b 100644 --- a/rest-api-sdk/src/test/java/com/paypal/api/payments/PaymentHistoryTestCase.java +++ b/rest-api-sdk/src/test/java/com/paypal/api/payments/PaymentHistoryTestCase.java @@ -26,7 +26,7 @@ public static PaymentHistory createPaymentHistory() { public void testConstruction() { PaymentHistory paymentHistory = PaymentHistoryTestCase .createPaymentHistory(); - Assert.assertEquals(paymentHistory.getCount(), COUNT); + Assert.assertEquals(paymentHistory.getCount(), COUNT.intValue()); Assert.assertEquals(paymentHistory.getNextId(), NEXTID); Assert.assertEquals(paymentHistory.getPayments().size(), 1); } diff --git a/rest-api-sdk/src/test/java/com/paypal/api/payments/PaymentTestCase.java b/rest-api-sdk/src/test/java/com/paypal/api/payments/PaymentTestCase.java index 5ef493a2..c0d9e5b8 100644 --- a/rest-api-sdk/src/test/java/com/paypal/api/payments/PaymentTestCase.java +++ b/rest-api-sdk/src/test/java/com/paypal/api/payments/PaymentTestCase.java @@ -19,6 +19,7 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.paypal.core.ConfigManager; +import com.paypal.core.rest.APIContext; import com.paypal.core.rest.OAuthTokenCredential; import com.paypal.core.rest.PayPalRESTException; import com.paypal.core.rest.QueryParameters; @@ -62,8 +63,8 @@ public static Payment createCallPayment() { CreditCard creditCard = new CreditCard(); creditCard.setBillingAddress(billingAddress); creditCard.setCvv2("874"); - creditCard.setExpireMonth("11"); - creditCard.setExpireYear("2018"); + creditCard.setExpireMonth(11); + creditCard.setExpireYear(2018); creditCard.setFirstName("Joe"); creditCard.setLastName("Shopper"); creditCard.setNumber("4417119669820331"); @@ -108,14 +109,14 @@ public static Payment createPayment() { CreditCard creditCard = new CreditCard(); creditCard.setBillingAddress(billingAddress); creditCard.setCvv2("874"); - creditCard.setExpireMonth("11"); - creditCard.setExpireYear("2018"); + creditCard.setExpireMonth(11); + creditCard.setExpireYear(2018); creditCard.setFirstName("Joe"); creditCard.setLastName("Shopper"); creditCard.setNumber("4111111111111111"); creditCard.setType("visa"); - AmountDetails amountDetails = new AmountDetails(); + Details amountDetails = new Details(); amountDetails.setShipping("10"); amountDetails.setSubtotal("75"); amountDetails.setTax("15"); @@ -145,8 +146,8 @@ public static Payment createPayment() { payer.setFundingInstruments(fundingInstrumentList); payer.setPaymentMethod("credit_card"); - List links = new ArrayList(); - links.add(LinkTestCase.createLink()); + List links = new ArrayList(); + links.add(LinksTestCase.createLinks()); RedirectUrls redirectUrls = RedirectUrlsTestCase.createRedirectUrls(); @@ -162,7 +163,7 @@ public static Payment createPayment() { } public static Payment createPaymentForExecution() { - AmountDetails amountDetails = new AmountDetails(); + Details amountDetails = new Details(); amountDetails.setShipping("10"); amountDetails.setSubtotal("75"); amountDetails.setTax("15"); @@ -240,99 +241,30 @@ public void testCreatePaymentAPI() throws PayPalRESTException { .get("id").getAsString(); } - @Test(dependsOnMethods = { "testCreatePaymentAPI" }) - public void testGetPaymentAPI() throws PayPalRESTException { - logger.info("**** Get Payment ****"); - logger.info("Setting Access Token = " + TokenHolder.accessToken); - payment = Payment.get(TokenHolder.accessToken, createdPaymentID); - logger.info("Request = " + Payment.getLastRequest()); - logger.info("Response = " + Payment.getLastResponse()); - logger.info("Retrieved Payment status = " + payment.getState()); - } - - @Test(enabled = false, dependsOnMethods = { "testGetPaymentAPI" }) - public void testExecutePayment() throws PayPalRESTException, IOException { - logger.info("**** Execute Payment ****"); - Payment exPayment = createPaymentForExecution(); - exPayment = exPayment.create(TokenHolder.accessToken); - logger.info("Create Payment Response: " + exPayment); - logger.info("Payer ID:"); - InputStreamReader converter = new InputStreamReader(System.in); - BufferedReader in = new BufferedReader(converter); - String payerId = in.readLine(); - PaymentExecution paymentExecution = new PaymentExecution(); - paymentExecution.setPayerId(payerId); - exPayment = exPayment - .execute(TokenHolder.accessToken, paymentExecution); - logger.info("Request = " + Payment.getLastRequest()); - logger.info("Response = " + Payment.getLastResponse()); - logger.info("Retrieved Payment status = " + exPayment.getState()); - } - - @Test(dependsOnMethods = { "testGetPaymentAPI" }) - public void testGetPaymentHistoryAPI() throws PayPalRESTException { - logger.info("**** Get Payment History ****"); - logger.info("Setting Access Token = " + TokenHolder.accessToken); - Map containerMap = new HashMap(); - containerMap.put("count", "10"); - PaymentHistory paymentHistory = Payment.get(TokenHolder.accessToken, - containerMap); - logger.info("Request = " + Payment.getLastRequest()); - logger.info("Response = " + Payment.getLastResponse()); - logger.info("Retrieved Payments count = " + paymentHistory.getCount()); - } - @Test(dependsOnMethods = { "testGetPaymentHistoryAPI" }) - public void testGetPaymentHistoryQueryParamsAPI() throws PayPalRESTException { - logger.info("**** Get Payment History ****"); - logger.info("Setting Access Token = " + TokenHolder.accessToken); - QueryParameters params = new QueryParameters(); - params.setCount("10"); - PaymentHistory paymentHistory = Payment.get(TokenHolder.accessToken, - params); - logger.info("Request = " + Payment.getLastRequest()); - logger.info("Response = " + Payment.getLastResponse()); - logger.info("Retrieved Payments count = " + paymentHistory.getCount()); - } - - @Test(dependsOnMethods = { "testGetPaymentHistoryQueryParamsAPI" }) - public void testFailCreatePaymentAPI() { - logger.info("**** Failing Create Payment ****"); - logger.info("Setting Access Token = " + TokenHolder.accessToken); - Payment payment = new Payment(); - try { - Payment createdPayment = payment.create(TokenHolder.accessToken); - } catch (PayPalRESTException e) { - Assert.assertEquals(e.getCause().getClass().getSimpleName(), - "HttpErrorException"); - } - } - - @Test(dependsOnMethods = { "testFailCreatePaymentAPI" }) - public void testFailGetPaymentAPI() { - logger.info("**** Failing Get Payment ****"); - logger.info("Setting Access Token = " + TokenHolder.accessToken); - try { - Payment createdPayment = Payment.get(TokenHolder.accessToken, - (String) null); - } catch (IllegalArgumentException e) { - Assert.assertTrue(e != null, - "Illegal Argument Exception not thrown for null arguments"); - } catch (PayPalRESTException e) { - Assert.fail(); - } - } - - @Test - public void testTOJSON() { - Payment payment = createPayment(); - Assert.assertEquals(payment.toJSON().length() == 0, false); - } + @Test(dependsOnMethods = { "testCreatePaymentAPI" }) + public void testA() throws PayPalRESTException { + logger.info("**** Create CreditCard ****"); + logger.info("Generated Access Token = " + TokenHolder.accessToken); - @Test - public void testTOString() { - Payment payment = createPayment(); - Assert.assertEquals(payment.toString().length() == 0, false); + CreditCard creditCard = new CreditCard(); + creditCard.setExpireMonth(11); + creditCard.setExpireYear(2018); + creditCard.setNumber("4417119669820331"); + creditCard.setType("visa"); + CreditCard responseCreditCard = creditCard.create(TokenHolder.accessToken); + logger.info("Request = " + CreditCard.getLastRequest()); + logger.info("Response = " + CreditCard.getLastResponse()); + logger.info("Credit Card created with ID = " + responseCreditCard.getId()); + Assert.assertEquals(true, + "ok".equalsIgnoreCase(responseCreditCard.getState())); + logger.info("Created Credit Card status = " + + responseCreditCard.getState()); + String createdCreditCardId = responseCreditCard.getId(); + + System.out.println("CC: " + responseCreditCard); + + responseCreditCard.delete(TokenHolder.accessToken); } } diff --git a/rest-api-sdk/src/test/java/com/paypal/api/payments/RefundTestCase.java b/rest-api-sdk/src/test/java/com/paypal/api/payments/RefundTestCase.java index cc772eeb..3d8d88a3 100644 --- a/rest-api-sdk/src/test/java/com/paypal/api/payments/RefundTestCase.java +++ b/rest-api-sdk/src/test/java/com/paypal/api/payments/RefundTestCase.java @@ -43,8 +43,8 @@ public void beforeClass() throws PayPalRESTException { } public static Refund createRefund() { - List links = new ArrayList(); - links.add(LinkTestCase.createLink()); + List links = new ArrayList(); + links.add(LinksTestCase.createLinks()); Refund refund = new Refund(); refund.setCaptureId(CAPTUREID); refund.setDescription(DESCRIPTION); diff --git a/rest-api-sdk/src/test/java/com/paypal/api/payments/SubTransactionTestCase.java b/rest-api-sdk/src/test/java/com/paypal/api/payments/RelatedResourcesTestCase.java similarity index 77% rename from rest-api-sdk/src/test/java/com/paypal/api/payments/SubTransactionTestCase.java rename to rest-api-sdk/src/test/java/com/paypal/api/payments/RelatedResourcesTestCase.java index ca4304ae..e7466f5e 100644 --- a/rest-api-sdk/src/test/java/com/paypal/api/payments/SubTransactionTestCase.java +++ b/rest-api-sdk/src/test/java/com/paypal/api/payments/RelatedResourcesTestCase.java @@ -3,7 +3,7 @@ import org.testng.Assert; import org.testng.annotations.Test; -public class SubTransactionTestCase { +public class RelatedResourcesTestCase { public static final Sale SALE = SaleTestCase.createSale(); @@ -14,8 +14,8 @@ public class SubTransactionTestCase { public static final Capture CAPTURE = CaptureTestCase.createCapture(); - public static SubTransaction createSubTransaction() { - SubTransaction subTransaction = new SubTransaction(); + public static RelatedResources createRelatedResources() { + RelatedResources subTransaction = new RelatedResources(); subTransaction.setAuthorization(AUTHORIZATION); subTransaction.setCapture(CAPTURE); subTransaction.setRefund(REFUND); @@ -25,7 +25,7 @@ public static SubTransaction createSubTransaction() { @Test public void testConstruction() { - SubTransaction subTransaction = createSubTransaction(); + RelatedResources subTransaction = createRelatedResources(); Assert.assertEquals(subTransaction.getAuthorization().getId(), AuthorizationTestCase.ID); Assert.assertEquals(subTransaction.getSale().getId(), SaleTestCase.ID); @@ -37,13 +37,13 @@ public void testConstruction() { @Test public void testTOJSON() { - SubTransaction subTransaction = createSubTransaction(); + RelatedResources subTransaction = createRelatedResources(); Assert.assertEquals(subTransaction.toJSON().length() == 0, false); } @Test public void testTOString() { - SubTransaction subTransaction = createSubTransaction(); + RelatedResources subTransaction = createRelatedResources(); Assert.assertEquals(subTransaction.toString().length() == 0, false); } diff --git a/rest-api-sdk/src/test/java/com/paypal/api/payments/ResourceTestCase.java b/rest-api-sdk/src/test/java/com/paypal/api/payments/ResourceTestCase.java deleted file mode 100644 index a1084822..00000000 --- a/rest-api-sdk/src/test/java/com/paypal/api/payments/ResourceTestCase.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.paypal.api.payments; - -import org.testng.Assert; -import org.testng.annotations.Test; - -public class ResourceTestCase { - - public static Resource createResource() { - Resource resource = new Resource(); - return resource; - } - - @Test - public void testTOJSON() { - Resource resource = ResourceTestCase.createResource(); - Assert.assertEquals(resource.toJSON().length() == 0, false); - } - - @Test - public void testTOString() { - Resource resource = ResourceTestCase.createResource(); - Assert.assertEquals(resource.toString().length() == 0, false); - } - -} diff --git a/rest-api-sdk/src/test/java/com/paypal/api/payments/SaleTestCase.java b/rest-api-sdk/src/test/java/com/paypal/api/payments/SaleTestCase.java index 809dc57d..99b4104b 100644 --- a/rest-api-sdk/src/test/java/com/paypal/api/payments/SaleTestCase.java +++ b/rest-api-sdk/src/test/java/com/paypal/api/payments/SaleTestCase.java @@ -39,8 +39,8 @@ public void beforeClass() throws PayPalRESTException { } public static Sale createSale() { - List links = new ArrayList(); - links.add(LinkTestCase.createLink()); + List links = new ArrayList(); + links.add(LinksTestCase.createLinks()); Sale sale = new Sale(); sale.setAmount(AMOUNT); sale.setId(ID); @@ -71,7 +71,7 @@ public void testSaleRefundAPI() throws PayPalRESTException { Payment createdPayment = payment.create(TokenHolder.accessToken); List transactions = createdPayment.getTransactions(); - List subTransactions = transactions.get(0) + List subTransactions = transactions.get(0) .getRelatedResources(); String id = subTransactions.get(0).getSale().getId(); this.SALE_ID = id; diff --git a/rest-api-sdk/src/test/java/com/paypal/api/payments/TransactionTestCase.java b/rest-api-sdk/src/test/java/com/paypal/api/payments/TransactionTestCase.java index 8ef42ee2..a34ea747 100644 --- a/rest-api-sdk/src/test/java/com/paypal/api/payments/TransactionTestCase.java +++ b/rest-api-sdk/src/test/java/com/paypal/api/payments/TransactionTestCase.java @@ -16,8 +16,8 @@ public class TransactionTestCase { public static Transaction createTransaction() { ItemList itemList = ItemListTestCase.createItemList(); - List relResources = new ArrayList(); - relResources.add(SubTransactionTestCase.createSubTransaction()); + List relResources = new ArrayList(); + relResources.add(RelatedResourcesTestCase.createRelatedResources()); Transaction transaction = new Transaction(); transaction.setAmount(AMOUNT); transaction.setPayee(PAYEE); diff --git a/rest-api-sdk/src/test/java/com/paypal/api/payments/TransactionsTestCase.java b/rest-api-sdk/src/test/java/com/paypal/api/payments/TransactionsTestCase.java new file mode 100644 index 00000000..32113423 --- /dev/null +++ b/rest-api-sdk/src/test/java/com/paypal/api/payments/TransactionsTestCase.java @@ -0,0 +1,35 @@ +package com.paypal.api.payments; + +import org.testng.Assert; +import org.testng.annotations.Test; + +public class TransactionsTestCase { + + public static final Amount AMOUNT = AmountTestCase.createAmount("100.00"); + + public static Transactions createTransactions() { + Transactions transactions = new Transactions(); + transactions.setAmount(AMOUNT); + return transactions; + } + + @Test + public void testConstruction() { + Transactions transactions = TransactionsTestCase.createTransactions(); + Assert.assertEquals(transactions.getAmount().getTotal(), "100.00"); + + } + + @Test + public void testTOJSON() { + Transactions transactions = TransactionsTestCase.createTransactions(); + Assert.assertEquals(transactions.toJSON().length() == 0, false); + } + + @Test + public void testTOString() { + Transactions transactions = TransactionsTestCase.createTransactions(); + Assert.assertEquals(transactions.toString().length() == 0, false); + } + +} diff --git a/rest-api-sdk/src/test/resources/sdk_config.properties b/rest-api-sdk/src/test/resources/sdk_config.properties index e9092491..c06c9502 100644 --- a/rest-api-sdk/src/test/resources/sdk_config.properties +++ b/rest-api-sdk/src/test/resources/sdk_config.properties @@ -16,10 +16,11 @@ http.ProxyPassword=null http.GoogleAppEngine = false # Service Configuration -service.EndPoint=https://api.sandbox.paypal.com +service.EndPoint=http://localhost/restapi +oauth.EndPoint=http://localhost/ # Live EndPoint # service.EndPoint=https://api.paypal.com # Credentials -clientID=EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM -clientSecret=EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM +clientID=AcJxCBCGPWRox3Y85YSr67vxDiho6QTnrFp8fBEpcM4ZdLSK1Ex4daY6pNNb +clientSecret=EPgxwRDLQiY12i1GI1-JV_XWD-uXNEysx3NAEEcrBv2AjCuqbVvdyu3XtYy9 From e2382352297219247f1eed16abc5d1197b775edd Mon Sep 17 00:00:00 2001 From: kumaravel jayakumar Date: Tue, 28 May 2013 10:06:18 +0530 Subject: [PATCH 19/30] Updated stubs: Removed reAuthorize method for Authorization class --- .../java/com/paypal/api/payments/Address.java | 40 +++----- .../java/com/paypal/api/payments/Amount.java | 9 +- .../paypal/api/payments/Authorization.java | 50 ++++------ .../java/com/paypal/api/payments/Capture.java | 44 ++++----- .../com/paypal/api/payments/CreditCard.java | 95 ++++++------------- .../api/payments/CreditCardHistory.java | 9 +- .../paypal/api/payments/CreditCardToken.java | 18 ++-- .../java/com/paypal/api/payments/Details.java | 12 ++- .../api/payments/FundingInstrument.java | 6 +- .../com/paypal/api/payments/HyperSchema.java | 18 ++-- .../java/com/paypal/api/payments/Item.java | 15 ++- .../com/paypal/api/payments/ItemList.java | 6 +- .../java/com/paypal/api/payments/Links.java | 18 ++-- .../java/com/paypal/api/payments/Payee.java | 9 +- .../java/com/paypal/api/payments/Payer.java | 9 +- .../com/paypal/api/payments/PayerInfo.java | 18 ++-- .../java/com/paypal/api/payments/Payment.java | 45 +++++++-- .../paypal/api/payments/PaymentExecution.java | 6 +- .../paypal/api/payments/PaymentHistory.java | 9 +- .../com/paypal/api/payments/RedirectUrls.java | 6 +- .../java/com/paypal/api/payments/Refund.java | 44 ++++----- .../paypal/api/payments/RelatedResources.java | 12 ++- .../java/com/paypal/api/payments/Sale.java | 21 ++-- .../paypal/api/payments/ShippingAddress.java | 3 +- .../com/paypal/api/payments/Transaction.java | 18 ++-- .../com/paypal/api/payments/Transactions.java | 3 +- 26 files changed, 277 insertions(+), 266 deletions(-) diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Address.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Address.java index ac955fcd..fe8b55bf 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Address.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Address.java @@ -49,11 +49,6 @@ public class Address { */ private String phone; - /** - * - */ - private String type; - /** * Default Constructor */ @@ -74,8 +69,9 @@ public Address(String line1, String city, String countryCode, String state) { /** * Setter for line1 */ - public void setLine1(String line1) { + public Address setLine1(String line1) { this.line1 = line1; + return this; } /** @@ -86,25 +82,12 @@ public String getLine1() { } - /** - * @return the type - */ - public String getType() { - return type; - } - - /** - * @param type the type to set - */ - public void setType(String type) { - this.type = type; - } - /** * Setter for line2 */ - public void setLine2(String line2) { + public Address setLine2(String line2) { this.line2 = line2; + return this; } /** @@ -118,8 +101,9 @@ public String getLine2() { /** * Setter for city */ - public void setCity(String city) { + public Address setCity(String city) { this.city = city; + return this; } /** @@ -133,8 +117,9 @@ public String getCity() { /** * Setter for countryCode */ - public void setCountryCode(String countryCode) { + public Address setCountryCode(String countryCode) { this.countryCode = countryCode; + return this; } /** @@ -148,8 +133,9 @@ public String getCountryCode() { /** * Setter for postalCode */ - public void setPostalCode(String postalCode) { + public Address setPostalCode(String postalCode) { this.postalCode = postalCode; + return this; } /** @@ -163,8 +149,9 @@ public String getPostalCode() { /** * Setter for state */ - public void setState(String state) { + public Address setState(String state) { this.state = state; + return this; } /** @@ -178,8 +165,9 @@ public String getState() { /** * Setter for phone */ - public void setPhone(String phone) { + public Address setPhone(String phone) { this.phone = phone; + return this; } /** diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Amount.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Amount.java index 5ae31563..4dc3ed3d 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Amount.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Amount.java @@ -48,8 +48,9 @@ public Amount(String currency, String total) { /** * Setter for currency */ - public void setCurrency(String currency) { + public Amount setCurrency(String currency) { this.currency = currency; + return this; } /** @@ -63,8 +64,9 @@ public String getCurrency() { /** * Setter for total */ - public void setTotal(String total) { + public Amount setTotal(String total) { this.total = total; + return this; } /** @@ -78,8 +80,9 @@ public String getTotal() { /** * Setter for details */ - public void setDetails(Details details) { + public Amount setDetails(Details details) { this.details = details; + return this; } /** diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Authorization.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Authorization.java index d889e992..6b7e5ff5 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Authorization.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Authorization.java @@ -116,8 +116,9 @@ public Authorization() { /** * Setter for id */ - public void setId(String id) { + public Authorization setId(String id) { this.id = id; + return this; } /** @@ -131,8 +132,9 @@ public String getId() { /** * Setter for createTime */ - public void setCreateTime(String createTime) { + public Authorization setCreateTime(String createTime) { this.createTime = createTime; + return this; } /** @@ -146,8 +148,9 @@ public String getCreateTime() { /** * Setter for updateTime */ - public void setUpdateTime(String updateTime) { + public Authorization setUpdateTime(String updateTime) { this.updateTime = updateTime; + return this; } /** @@ -161,8 +164,9 @@ public String getUpdateTime() { /** * Setter for amount */ - public void setAmount(Amount amount) { + public Authorization setAmount(Amount amount) { this.amount = amount; + return this; } /** @@ -176,8 +180,9 @@ public Amount getAmount() { /** * Setter for state */ - public void setState(String state) { + public Authorization setState(String state) { this.state = state; + return this; } /** @@ -191,8 +196,9 @@ public String getState() { /** * Setter for parentPayment */ - public void setParentPayment(String parentPayment) { + public Authorization setParentPayment(String parentPayment) { this.parentPayment = parentPayment; + return this; } /** @@ -206,8 +212,9 @@ public String getParentPayment() { /** * Setter for validUntil */ - public void setValidUntil(String validUntil) { + public Authorization setValidUntil(String validUntil) { this.validUntil = validUntil; + return this; } /** @@ -221,8 +228,9 @@ public String getValidUntil() { /** * Setter for links */ - public void setLinks(List links) { + public Authorization setLinks(List links) { this.links = links; + return this; } /** @@ -313,32 +321,6 @@ public Authorization doVoid(APIContext apiContext) throws PayPalRESTException { return PayPalResource.configureAndExecute(apiContext, HttpMethod.POST, resourcePath, payLoad, Authorization.class); } - - /** - * Reauthorizes an expired Authorization. - */ - public Authorization reauthorize(String accessToken) throws PayPalRESTException { - APIContext apiContext = new APIContext(accessToken); - return reauthorize(apiContext); - } - - /** - * Reauthorizes an expired Authorization. - */ - public Authorization reauthorize(APIContext apiContext) throws PayPalRESTException { - if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { - throw new IllegalArgumentException("AccessToken cannot be null or empty"); - } - if (this.getId() == null) { - throw new IllegalArgumentException("Id cannot be null"); - } - Object[] parameters = new Object[] {this.getId()}; - String pattern = "v1/payments/authorization/{0}/reauthorize"; - String resourcePath = RESTUtil.formatURIPath(pattern, parameters); - String payLoad = this.toJSON(); - return PayPalResource.configureAndExecute(apiContext, HttpMethod.POST, resourcePath, payLoad, Authorization.class); - } - /** * Returns a JSON string corresponding to object state * diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Capture.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Capture.java index 2984cb20..1eaa3e61 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Capture.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Capture.java @@ -52,11 +52,6 @@ public class Capture { */ private String parentPayment; - /** - * Additional information to add when capturing the funds. Eg. shipment tracking number - */ - private String description; - /** * */ @@ -121,8 +116,9 @@ public Capture() { /** * Setter for id */ - public void setId(String id) { + public Capture setId(String id) { this.id = id; + return this; } /** @@ -136,8 +132,9 @@ public String getId() { /** * Setter for createTime */ - public void setCreateTime(String createTime) { + public Capture setCreateTime(String createTime) { this.createTime = createTime; + return this; } /** @@ -151,8 +148,9 @@ public String getCreateTime() { /** * Setter for updateTime */ - public void setUpdateTime(String updateTime) { + public Capture setUpdateTime(String updateTime) { this.updateTime = updateTime; + return this; } /** @@ -166,8 +164,9 @@ public String getUpdateTime() { /** * Setter for amount */ - public void setAmount(Amount amount) { + public Capture setAmount(Amount amount) { this.amount = amount; + return this; } /** @@ -181,8 +180,9 @@ public Amount getAmount() { /** * Setter for isFinalCapture */ - public void setIsFinalCapture(Boolean isFinalCapture) { + public Capture setIsFinalCapture(Boolean isFinalCapture) { this.isFinalCapture = isFinalCapture; + return this; } /** @@ -196,8 +196,9 @@ public Boolean getIsFinalCapture() { /** * Setter for state */ - public void setState(String state) { + public Capture setState(String state) { this.state = state; + return this; } /** @@ -211,8 +212,9 @@ public String getState() { /** * Setter for parentPayment */ - public void setParentPayment(String parentPayment) { + public Capture setParentPayment(String parentPayment) { this.parentPayment = parentPayment; + return this; } /** @@ -223,26 +225,12 @@ public String getParentPayment() { } - /** - * Setter for description - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * Getter for description - */ - public String getDescription() { - return this.description; - } - - /** * Setter for links */ - public void setLinks(List links) { + public Capture setLinks(List links) { this.links = links; + return this; } /** diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCard.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCard.java index 0799b89b..88e33b9e 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCard.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCard.java @@ -151,8 +151,9 @@ public CreditCard(String number, String type, int expireMonth, int expireYear) { /** * Setter for id */ - public void setId(String id) { + public CreditCard setId(String id) { this.id = id; + return this; } /** @@ -166,8 +167,9 @@ public String getId() { /** * Setter for number */ - public void setNumber(String number) { + public CreditCard setNumber(String number) { this.number = number; + return this; } /** @@ -181,8 +183,9 @@ public String getNumber() { /** * Setter for type */ - public void setType(String type) { + public CreditCard setType(String type) { this.type = type; + return this; } /** @@ -196,8 +199,9 @@ public String getType() { /** * Setter for expireMonth */ - public void setExpireMonth(int expireMonth) { + public CreditCard setExpireMonth(int expireMonth) { this.expireMonth = expireMonth; + return this; } /** @@ -211,8 +215,9 @@ public int getExpireMonth() { /** * Setter for expireYear */ - public void setExpireYear(int expireYear) { + public CreditCard setExpireYear(int expireYear) { this.expireYear = expireYear; + return this; } /** @@ -226,8 +231,9 @@ public int getExpireYear() { /** * Setter for cvv2 */ - public void setCvv2(String cvv2) { + public CreditCard setCvv2(String cvv2) { this.cvv2 = cvv2; + return this; } /** @@ -241,8 +247,9 @@ public String getCvv2() { /** * Setter for firstName */ - public void setFirstName(String firstName) { + public CreditCard setFirstName(String firstName) { this.firstName = firstName; + return this; } /** @@ -256,8 +263,9 @@ public String getFirstName() { /** * Setter for lastName */ - public void setLastName(String lastName) { + public CreditCard setLastName(String lastName) { this.lastName = lastName; + return this; } /** @@ -271,8 +279,9 @@ public String getLastName() { /** * Setter for billingAddress */ - public void setBillingAddress(Address billingAddress) { + public CreditCard setBillingAddress(Address billingAddress) { this.billingAddress = billingAddress; + return this; } /** @@ -286,8 +295,9 @@ public Address getBillingAddress() { /** * Setter for payerId */ - public void setPayerId(String payerId) { + public CreditCard setPayerId(String payerId) { this.payerId = payerId; + return this; } /** @@ -301,8 +311,9 @@ public String getPayerId() { /** * Setter for state */ - public void setState(String state) { + public CreditCard setState(String state) { this.state = state; + return this; } /** @@ -316,8 +327,9 @@ public String getState() { /** * Setter for validUntil */ - public void setValidUntil(String validUntil) { + public CreditCard setValidUntil(String validUntil) { this.validUntil = validUntil; + return this; } /** @@ -331,8 +343,9 @@ public String getValidUntil() { /** * Setter for links */ - public void setLinks(List links) { + public CreditCard setLinks(List links) { this.links = links; + return this; } /** @@ -391,7 +404,7 @@ public static CreditCard get(APIContext apiContext, String creditCardId) throws /** - * Delete the Credit Card resource for the given identifier. + * Delete the Credit Card resource for the given identifier. Returns 204 No Content when the card is deleted successfully. */ public void delete(String accessToken) throws PayPalRESTException { APIContext apiContext = new APIContext(accessToken); @@ -400,7 +413,7 @@ public void delete(String accessToken) throws PayPalRESTException { } /** - * Delete the Credit Card resource for the given identifier. + * Delete the Credit Card resource for the given identifier. Returns 204 No Content when the card is deleted successfully. */ public void delete(APIContext apiContext) throws PayPalRESTException { if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { @@ -418,58 +431,6 @@ public void delete(APIContext apiContext) throws PayPalRESTException { return; } - - /** - * Update information in a previously saved card. Only the modified fields need to be passed in the request. - */ - public CreditCard update(String accessToken) throws PayPalRESTException { - APIContext apiContext = new APIContext(accessToken); - return update(apiContext); - } - - /** - * Update information in a previously saved card. Only the modified fields need to be passed in the request. - */ - public CreditCard update(APIContext apiContext) throws PayPalRESTException { - if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { - throw new IllegalArgumentException("AccessToken cannot be null or empty"); - } - if (this.getId() == null) { - throw new IllegalArgumentException("Id cannot be null"); - } - Object[] parameters = new Object[] {this.getId()}; - String pattern = "v1/vault/credit-card/{0}"; - String resourcePath = RESTUtil.formatURIPath(pattern, parameters); - String payLoad = this.toJSON(); - return PayPalResource.configureAndExecute(apiContext, HttpMethod.PATCH, resourcePath, payLoad, CreditCard.class); - } - - - /** - * Retrieves a list of Credit Card resources. - */ - public static CreditCardHistory list(String accessToken, Map containerMap) throws PayPalRESTException { - APIContext apiContext = new APIContext(accessToken); - return list(apiContext, containerMap); - } - - /** - * Retrieves a list of Credit Card resources. - */ - public static CreditCardHistory list(APIContext apiContext, Map containerMap) throws PayPalRESTException { - if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) { - throw new IllegalArgumentException("AccessToken cannot be null or empty"); - } - if (containerMap == null) { - throw new IllegalArgumentException("containerMap cannot be null"); - } - Object[] parameters = new Object[] {containerMap}; - String pattern = "v1/vault/credit-card?count={0}&start_id={1}&start_index={2}&start_time={3}&end_time={4}&payer_id={5}"; - String resourcePath = RESTUtil.formatURIPath(pattern, parameters); - String payLoad = ""; - return PayPalResource.configureAndExecute(apiContext, HttpMethod.GET, resourcePath, payLoad, CreditCardHistory.class); - } - /** * Returns a JSON string corresponding to object state * diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCardHistory.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCardHistory.java index c1624898..ff2088dd 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCardHistory.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCardHistory.java @@ -41,8 +41,9 @@ public CreditCardHistory() { /** * Setter for creditCards */ - public void setCreditCards(List creditCards) { + public CreditCardHistory setCreditCards(List creditCards) { this.creditCards = creditCards; + return this; } /** @@ -56,8 +57,9 @@ public List getCreditCards() { /** * Setter for count */ - public void setCount(int count) { + public CreditCardHistory setCount(int count) { this.count = count; + return this; } /** @@ -71,8 +73,9 @@ public int getCount() { /** * Setter for nextId */ - public void setNextId(String nextId) { + public CreditCardHistory setNextId(String nextId) { this.nextId = nextId; + return this; } /** diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCardToken.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCardToken.java index 6b9438e0..c3c02aa3 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCardToken.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/CreditCardToken.java @@ -61,8 +61,9 @@ public CreditCardToken(String creditCardId) { /** * Setter for creditCardId */ - public void setCreditCardId(String creditCardId) { + public CreditCardToken setCreditCardId(String creditCardId) { this.creditCardId = creditCardId; + return this; } /** @@ -76,8 +77,9 @@ public String getCreditCardId() { /** * Setter for payerId */ - public void setPayerId(String payerId) { + public CreditCardToken setPayerId(String payerId) { this.payerId = payerId; + return this; } /** @@ -91,8 +93,9 @@ public String getPayerId() { /** * Setter for last4 */ - public void setLast4(String last4) { + public CreditCardToken setLast4(String last4) { this.last4 = last4; + return this; } /** @@ -106,8 +109,9 @@ public String getLast4() { /** * Setter for type */ - public void setType(String type) { + public CreditCardToken setType(String type) { this.type = type; + return this; } /** @@ -121,8 +125,9 @@ public String getType() { /** * Setter for expireMonth */ - public void setExpireMonth(int expireMonth) { + public CreditCardToken setExpireMonth(int expireMonth) { this.expireMonth = expireMonth; + return this; } /** @@ -136,8 +141,9 @@ public int getExpireMonth() { /** * Setter for expireYear */ - public void setExpireYear(int expireYear) { + public CreditCardToken setExpireYear(int expireYear) { this.expireYear = expireYear; + return this; } /** diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Details.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Details.java index fc20d97f..ccf077c6 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Details.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Details.java @@ -44,8 +44,9 @@ public Details() { /** * Setter for shipping */ - public void setShipping(String shipping) { + public Details setShipping(String shipping) { this.shipping = shipping; + return this; } /** @@ -59,8 +60,9 @@ public String getShipping() { /** * Setter for subtotal */ - public void setSubtotal(String subtotal) { + public Details setSubtotal(String subtotal) { this.subtotal = subtotal; + return this; } /** @@ -74,8 +76,9 @@ public String getSubtotal() { /** * Setter for tax */ - public void setTax(String tax) { + public Details setTax(String tax) { this.tax = tax; + return this; } /** @@ -89,8 +92,9 @@ public String getTax() { /** * Setter for fee */ - public void setFee(String fee) { + public Details setFee(String fee) { this.fee = fee; + return this; } /** diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/FundingInstrument.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/FundingInstrument.java index ecffca4f..40c33d2e 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/FundingInstrument.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/FundingInstrument.java @@ -36,8 +36,9 @@ public FundingInstrument() { /** * Setter for creditCard */ - public void setCreditCard(CreditCard creditCard) { + public FundingInstrument setCreditCard(CreditCard creditCard) { this.creditCard = creditCard; + return this; } /** @@ -51,8 +52,9 @@ public CreditCard getCreditCard() { /** * Setter for creditCardToken */ - public void setCreditCardToken(CreditCardToken creditCardToken) { + public FundingInstrument setCreditCardToken(CreditCardToken creditCardToken) { this.creditCardToken = creditCardToken; + return this; } /** diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/HyperSchema.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/HyperSchema.java index f9c3f1ff..78105023 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/HyperSchema.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/HyperSchema.java @@ -56,8 +56,9 @@ public HyperSchema() { /** * Setter for links */ - public void setLinks(List links) { + public HyperSchema setLinks(List links) { this.links = links; + return this; } /** @@ -71,8 +72,9 @@ public List getLinks() { /** * Setter for fragmentResolution */ - public void setFragmentResolution(String fragmentResolution) { + public HyperSchema setFragmentResolution(String fragmentResolution) { this.fragmentResolution = fragmentResolution; + return this; } /** @@ -86,8 +88,9 @@ public String getFragmentResolution() { /** * Setter for readonly */ - public void setReadonly(Boolean readonly) { + public HyperSchema setReadonly(Boolean readonly) { this.readonly = readonly; + return this; } /** @@ -101,8 +104,9 @@ public Boolean getReadonly() { /** * Setter for contentEncoding */ - public void setContentEncoding(String contentEncoding) { + public HyperSchema setContentEncoding(String contentEncoding) { this.contentEncoding = contentEncoding; + return this; } /** @@ -116,8 +120,9 @@ public String getContentEncoding() { /** * Setter for pathStart */ - public void setPathStart(String pathStart) { + public HyperSchema setPathStart(String pathStart) { this.pathStart = pathStart; + return this; } /** @@ -131,8 +136,9 @@ public String getPathStart() { /** * Setter for mediaType */ - public void setMediaType(String mediaType) { + public HyperSchema setMediaType(String mediaType) { this.mediaType = mediaType; + return this; } /** diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Item.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Item.java index 30510674..d08a6f1e 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Item.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Item.java @@ -59,8 +59,9 @@ public Item(String quantity, String name, String price, String currency) { /** * Setter for quantity */ - public void setQuantity(String quantity) { + public Item setQuantity(String quantity) { this.quantity = quantity; + return this; } /** @@ -74,8 +75,9 @@ public String getQuantity() { /** * Setter for name */ - public void setName(String name) { + public Item setName(String name) { this.name = name; + return this; } /** @@ -89,8 +91,9 @@ public String getName() { /** * Setter for price */ - public void setPrice(String price) { + public Item setPrice(String price) { this.price = price; + return this; } /** @@ -104,8 +107,9 @@ public String getPrice() { /** * Setter for currency */ - public void setCurrency(String currency) { + public Item setCurrency(String currency) { this.currency = currency; + return this; } /** @@ -119,8 +123,9 @@ public String getCurrency() { /** * Setter for sku */ - public void setSku(String sku) { + public Item setSku(String sku) { this.sku = sku; + return this; } /** diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/ItemList.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/ItemList.java index f3adebea..819af479 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/ItemList.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/ItemList.java @@ -37,8 +37,9 @@ public ItemList() { /** * Setter for items */ - public void setItems(List items) { + public ItemList setItems(List items) { this.items = items; + return this; } /** @@ -52,8 +53,9 @@ public List getItems() { /** * Setter for shippingAddress */ - public void setShippingAddress(ShippingAddress shippingAddress) { + public ItemList setShippingAddress(ShippingAddress shippingAddress) { this.shippingAddress = shippingAddress; + return this; } /** diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Links.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Links.java index 2dbd9394..3d909aa5 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Links.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Links.java @@ -63,8 +63,9 @@ public Links(String href, String rel) { /** * Setter for href */ - public void setHref(String href) { + public Links setHref(String href) { this.href = href; + return this; } /** @@ -78,8 +79,9 @@ public String getHref() { /** * Setter for rel */ - public void setRel(String rel) { + public Links setRel(String rel) { this.rel = rel; + return this; } /** @@ -93,8 +95,9 @@ public String getRel() { /** * Setter for targetSchema */ - public void setTargetSchema(HyperSchema targetSchema) { + public Links setTargetSchema(HyperSchema targetSchema) { this.targetSchema = targetSchema; + return this; } /** @@ -108,8 +111,9 @@ public HyperSchema getTargetSchema() { /** * Setter for method */ - public void setMethod(String method) { + public Links setMethod(String method) { this.method = method; + return this; } /** @@ -123,8 +127,9 @@ public String getMethod() { /** * Setter for enctype */ - public void setEnctype(String enctype) { + public Links setEnctype(String enctype) { this.enctype = enctype; + return this; } /** @@ -138,8 +143,9 @@ public String getEnctype() { /** * Setter for schema */ - public void setSchema(HyperSchema schema) { + public Links setSchema(HyperSchema schema) { this.schema = schema; + return this; } /** diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Payee.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Payee.java index 48fba9ac..b1865812 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Payee.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Payee.java @@ -48,8 +48,9 @@ public Payee(String email, String merchantId, String phone) { /** * Setter for email */ - public void setEmail(String email) { + public Payee setEmail(String email) { this.email = email; + return this; } /** @@ -63,8 +64,9 @@ public String getEmail() { /** * Setter for merchantId */ - public void setMerchantId(String merchantId) { + public Payee setMerchantId(String merchantId) { this.merchantId = merchantId; + return this; } /** @@ -78,8 +80,9 @@ public String getMerchantId() { /** * Setter for phone */ - public void setPhone(String phone) { + public Payee setPhone(String phone) { this.phone = phone; + return this; } /** diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Payer.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Payer.java index 7e2cabef..a006bd50 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Payer.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Payer.java @@ -49,8 +49,9 @@ public Payer(String paymentMethod) { /** * Setter for paymentMethod */ - public void setPaymentMethod(String paymentMethod) { + public Payer setPaymentMethod(String paymentMethod) { this.paymentMethod = paymentMethod; + return this; } /** @@ -64,8 +65,9 @@ public String getPaymentMethod() { /** * Setter for fundingInstruments */ - public void setFundingInstruments(List fundingInstruments) { + public Payer setFundingInstruments(List fundingInstruments) { this.fundingInstruments = fundingInstruments; + return this; } /** @@ -79,8 +81,9 @@ public List getFundingInstruments() { /** * Setter for payerInfo */ - public void setPayerInfo(PayerInfo payerInfo) { + public Payer setPayerInfo(PayerInfo payerInfo) { this.payerInfo = payerInfo; + return this; } /** diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/PayerInfo.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/PayerInfo.java index 463dd571..caf525a9 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/PayerInfo.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/PayerInfo.java @@ -55,8 +55,9 @@ public PayerInfo() { /** * Setter for email */ - public void setEmail(String email) { + public PayerInfo setEmail(String email) { this.email = email; + return this; } /** @@ -70,8 +71,9 @@ public String getEmail() { /** * Setter for firstName */ - public void setFirstName(String firstName) { + public PayerInfo setFirstName(String firstName) { this.firstName = firstName; + return this; } /** @@ -85,8 +87,9 @@ public String getFirstName() { /** * Setter for lastName */ - public void setLastName(String lastName) { + public PayerInfo setLastName(String lastName) { this.lastName = lastName; + return this; } /** @@ -100,8 +103,9 @@ public String getLastName() { /** * Setter for payerId */ - public void setPayerId(String payerId) { + public PayerInfo setPayerId(String payerId) { this.payerId = payerId; + return this; } /** @@ -115,8 +119,9 @@ public String getPayerId() { /** * Setter for phone */ - public void setPhone(String phone) { + public PayerInfo setPhone(String phone) { this.phone = phone; + return this; } /** @@ -130,8 +135,9 @@ public String getPhone() { /** * Setter for shippingAddress */ - public void setShippingAddress(Address shippingAddress) { + public PayerInfo setShippingAddress(Address shippingAddress) { this.shippingAddress = shippingAddress; + return this; } /** diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Payment.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Payment.java index e4ef2e9e..89ea9456 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Payment.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Payment.java @@ -29,6 +29,11 @@ public class Payment { */ private String createTime; + /** + * Time the resource was last updated. + */ + private String updateTime; + /** * Intent of the payment - Sale or Authorization or Order. */ @@ -127,8 +132,9 @@ public Payment(String intent, Payer payer, List transactions) { /** * Setter for id */ - public void setId(String id) { + public Payment setId(String id) { this.id = id; + return this; } /** @@ -142,8 +148,9 @@ public String getId() { /** * Setter for createTime */ - public void setCreateTime(String createTime) { + public Payment setCreateTime(String createTime) { this.createTime = createTime; + return this; } /** @@ -154,11 +161,28 @@ public String getCreateTime() { } + /** + * Setter for updateTime + */ + public Payment setUpdateTime(String updateTime) { + this.updateTime = updateTime; + return this; + } + + /** + * Getter for updateTime + */ + public String getUpdateTime() { + return this.updateTime; + } + + /** * Setter for intent */ - public void setIntent(String intent) { + public Payment setIntent(String intent) { this.intent = intent; + return this; } /** @@ -172,8 +196,9 @@ public String getIntent() { /** * Setter for payer */ - public void setPayer(Payer payer) { + public Payment setPayer(Payer payer) { this.payer = payer; + return this; } /** @@ -187,8 +212,9 @@ public Payer getPayer() { /** * Setter for transactions */ - public void setTransactions(List transactions) { + public Payment setTransactions(List transactions) { this.transactions = transactions; + return this; } /** @@ -202,8 +228,9 @@ public List getTransactions() { /** * Setter for state */ - public void setState(String state) { + public Payment setState(String state) { this.state = state; + return this; } /** @@ -217,8 +244,9 @@ public String getState() { /** * Setter for redirectUrls */ - public void setRedirectUrls(RedirectUrls redirectUrls) { + public Payment setRedirectUrls(RedirectUrls redirectUrls) { this.redirectUrls = redirectUrls; + return this; } /** @@ -232,8 +260,9 @@ public RedirectUrls getRedirectUrls() { /** * Setter for links */ - public void setLinks(List links) { + public Payment setLinks(List links) { this.links = links; + return this; } /** diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/PaymentExecution.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/PaymentExecution.java index 4ae76dd7..57052af7 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/PaymentExecution.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/PaymentExecution.java @@ -43,8 +43,9 @@ public PaymentExecution(String payerId) { /** * Setter for payerId */ - public void setPayerId(String payerId) { + public PaymentExecution setPayerId(String payerId) { this.payerId = payerId; + return this; } /** @@ -58,8 +59,9 @@ public String getPayerId() { /** * Setter for transactions */ - public void setTransactions(List transactions) { + public PaymentExecution setTransactions(List transactions) { this.transactions = transactions; + return this; } /** diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/PaymentHistory.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/PaymentHistory.java index e36d323b..1f5e969c 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/PaymentHistory.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/PaymentHistory.java @@ -41,8 +41,9 @@ public PaymentHistory() { /** * Setter for payments */ - public void setPayments(List payments) { + public PaymentHistory setPayments(List payments) { this.payments = payments; + return this; } /** @@ -56,8 +57,9 @@ public List getPayments() { /** * Setter for count */ - public void setCount(int count) { + public PaymentHistory setCount(int count) { this.count = count; + return this; } /** @@ -71,8 +73,9 @@ public int getCount() { /** * Setter for nextId */ - public void setNextId(String nextId) { + public PaymentHistory setNextId(String nextId) { this.nextId = nextId; + return this; } /** diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/RedirectUrls.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/RedirectUrls.java index 255b9e0e..58b01770 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/RedirectUrls.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/RedirectUrls.java @@ -34,8 +34,9 @@ public RedirectUrls() { /** * Setter for returnUrl */ - public void setReturnUrl(String returnUrl) { + public RedirectUrls setReturnUrl(String returnUrl) { this.returnUrl = returnUrl; + return this; } /** @@ -49,8 +50,9 @@ public String getReturnUrl() { /** * Setter for cancelUrl */ - public void setCancelUrl(String cancelUrl) { + public RedirectUrls setCancelUrl(String cancelUrl) { this.cancelUrl = cancelUrl; + return this; } /** diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Refund.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Refund.java index e93ad19a..a4649f84 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Refund.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Refund.java @@ -52,11 +52,6 @@ public class Refund { */ private String parentPayment; - /** - * Description of what is being refunded for. - */ - private String description; - /** * */ @@ -121,8 +116,9 @@ public Refund() { /** * Setter for id */ - public void setId(String id) { + public Refund setId(String id) { this.id = id; + return this; } /** @@ -136,8 +132,9 @@ public String getId() { /** * Setter for createTime */ - public void setCreateTime(String createTime) { + public Refund setCreateTime(String createTime) { this.createTime = createTime; + return this; } /** @@ -151,8 +148,9 @@ public String getCreateTime() { /** * Setter for amount */ - public void setAmount(Amount amount) { + public Refund setAmount(Amount amount) { this.amount = amount; + return this; } /** @@ -166,8 +164,9 @@ public Amount getAmount() { /** * Setter for state */ - public void setState(String state) { + public Refund setState(String state) { this.state = state; + return this; } /** @@ -181,8 +180,9 @@ public String getState() { /** * Setter for saleId */ - public void setSaleId(String saleId) { + public Refund setSaleId(String saleId) { this.saleId = saleId; + return this; } /** @@ -196,8 +196,9 @@ public String getSaleId() { /** * Setter for captureId */ - public void setCaptureId(String captureId) { + public Refund setCaptureId(String captureId) { this.captureId = captureId; + return this; } /** @@ -211,8 +212,9 @@ public String getCaptureId() { /** * Setter for parentPayment */ - public void setParentPayment(String parentPayment) { + public Refund setParentPayment(String parentPayment) { this.parentPayment = parentPayment; + return this; } /** @@ -223,26 +225,12 @@ public String getParentPayment() { } - /** - * Setter for description - */ - public void setDescription(String description) { - this.description = description; - } - - /** - * Getter for description - */ - public String getDescription() { - return this.description; - } - - /** * Setter for links */ - public void setLinks(List links) { + public Refund setLinks(List links) { this.links = links; + return this; } /** diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/RelatedResources.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/RelatedResources.java index 4c86a6d3..8006cbdf 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/RelatedResources.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/RelatedResources.java @@ -48,8 +48,9 @@ public RelatedResources() { /** * Setter for sale */ - public void setSale(Sale sale) { + public RelatedResources setSale(Sale sale) { this.sale = sale; + return this; } /** @@ -63,8 +64,9 @@ public Sale getSale() { /** * Setter for authorization */ - public void setAuthorization(Authorization authorization) { + public RelatedResources setAuthorization(Authorization authorization) { this.authorization = authorization; + return this; } /** @@ -78,8 +80,9 @@ public Authorization getAuthorization() { /** * Setter for capture */ - public void setCapture(Capture capture) { + public RelatedResources setCapture(Capture capture) { this.capture = capture; + return this; } /** @@ -93,8 +96,9 @@ public Capture getCapture() { /** * Setter for refund */ - public void setRefund(Refund refund) { + public RelatedResources setRefund(Refund refund) { this.refund = refund; + return this; } /** diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Sale.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Sale.java index 0f521130..8e362117 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Sale.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Sale.java @@ -120,8 +120,9 @@ public Sale(Amount amount, String state, String parentPayment) { /** * Setter for id */ - public void setId(String id) { + public Sale setId(String id) { this.id = id; + return this; } /** @@ -135,8 +136,9 @@ public String getId() { /** * Setter for createTime */ - public void setCreateTime(String createTime) { + public Sale setCreateTime(String createTime) { this.createTime = createTime; + return this; } /** @@ -150,8 +152,9 @@ public String getCreateTime() { /** * Setter for updateTime */ - public void setUpdateTime(String updateTime) { + public Sale setUpdateTime(String updateTime) { this.updateTime = updateTime; + return this; } /** @@ -165,8 +168,9 @@ public String getUpdateTime() { /** * Setter for amount */ - public void setAmount(Amount amount) { + public Sale setAmount(Amount amount) { this.amount = amount; + return this; } /** @@ -180,8 +184,9 @@ public Amount getAmount() { /** * Setter for state */ - public void setState(String state) { + public Sale setState(String state) { this.state = state; + return this; } /** @@ -195,8 +200,9 @@ public String getState() { /** * Setter for parentPayment */ - public void setParentPayment(String parentPayment) { + public Sale setParentPayment(String parentPayment) { this.parentPayment = parentPayment; + return this; } /** @@ -210,8 +216,9 @@ public String getParentPayment() { /** * Setter for links */ - public void setLinks(List links) { + public Sale setLinks(List links) { this.links = links; + return this; } /** diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/ShippingAddress.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/ShippingAddress.java index 322b5b70..1ff3e802 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/ShippingAddress.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/ShippingAddress.java @@ -37,8 +37,9 @@ public ShippingAddress(String recipientName) { /** * Setter for recipientName */ - public void setRecipientName(String recipientName) { + public ShippingAddress setRecipientName(String recipientName) { this.recipientName = recipientName; + return this; } /** diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Transaction.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Transaction.java index a2dc0ab0..2f41c9a3 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Transaction.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Transaction.java @@ -66,8 +66,9 @@ public Transaction(Amount amount) { /** * Setter for amount */ - public void setAmount(Amount amount) { + public Transaction setAmount(Amount amount) { this.amount = amount; + return this; } /** @@ -81,8 +82,9 @@ public Amount getAmount() { /** * Setter for payee */ - public void setPayee(Payee payee) { + public Transaction setPayee(Payee payee) { this.payee = payee; + return this; } /** @@ -96,8 +98,9 @@ public Payee getPayee() { /** * Setter for description */ - public void setDescription(String description) { + public Transaction setDescription(String description) { this.description = description; + return this; } /** @@ -111,8 +114,9 @@ public String getDescription() { /** * Setter for itemList */ - public void setItemList(ItemList itemList) { + public Transaction setItemList(ItemList itemList) { this.itemList = itemList; + return this; } /** @@ -126,8 +130,9 @@ public ItemList getItemList() { /** * Setter for relatedResources */ - public void setRelatedResources(List relatedResources) { + public Transaction setRelatedResources(List relatedResources) { this.relatedResources = relatedResources; + return this; } /** @@ -141,8 +146,9 @@ public List getRelatedResources() { /** * Setter for transactions */ - public void setTransactions(List transactions) { + public Transaction setTransactions(List transactions) { this.transactions = transactions; + return this; } /** diff --git a/rest-api-sdk/src/main/java/com/paypal/api/payments/Transactions.java b/rest-api-sdk/src/main/java/com/paypal/api/payments/Transactions.java index d836fd2a..f1badb49 100644 --- a/rest-api-sdk/src/main/java/com/paypal/api/payments/Transactions.java +++ b/rest-api-sdk/src/main/java/com/paypal/api/payments/Transactions.java @@ -37,8 +37,9 @@ public Transactions(Amount amount) { /** * Setter for amount */ - public void setAmount(Amount amount) { + public Transactions setAmount(Amount amount) { this.amount = amount; + return this; } /** From 51f0064c48a61afd8d5d3e61b776af8104e6ef4f Mon Sep 17 00:00:00 2001 From: kumaravel jayakumar Date: Tue, 28 May 2013 10:09:04 +0530 Subject: [PATCH 20/30] Updated negative testcases --- .../paypal/api/payments/AddressTestCase.java | 8 - .../api/payments/AuthorizationTestCase.java | 124 ++++++++++++++++ .../paypal/api/payments/CaptureTestCase.java | 112 +++++++++++++- .../api/payments/CreditCardTestCase.java | 25 ++-- .../paypal/api/payments/PaymentTestCase.java | 140 +++++++++++++----- .../paypal/api/payments/RefundTestCase.java | 4 - 6 files changed, 342 insertions(+), 71 deletions(-) diff --git a/rest-api-sdk/src/test/java/com/paypal/api/payments/AddressTestCase.java b/rest-api-sdk/src/test/java/com/paypal/api/payments/AddressTestCase.java index a8ebbe28..10d95632 100644 --- a/rest-api-sdk/src/test/java/com/paypal/api/payments/AddressTestCase.java +++ b/rest-api-sdk/src/test/java/com/paypal/api/payments/AddressTestCase.java @@ -5,8 +5,6 @@ public class AddressTestCase { -// public static final String RECIPIENTSNAME = "TestUser"; - public static final String CITY = "Niagara Falls"; public static final String COUNTRYCODE = "US"; @@ -21,11 +19,8 @@ public class AddressTestCase { public static final String STATE = "NY"; - public static final String TYPE = "Business"; - public static Address createAddress() { Address billingAddress = new Address(); -// billingAddress.setRecipientName(RECIPIENTSNAME); billingAddress.setCity(CITY); billingAddress.setCountryCode(COUNTRYCODE); billingAddress.setLine1(LINE1); @@ -33,14 +28,12 @@ public static Address createAddress() { billingAddress.setPostalCode(POSTALCODE); billingAddress.setPhone(PHONE); billingAddress.setState(STATE); - billingAddress.setType(TYPE); return billingAddress; } @Test public void testConstruction() { Address address = createAddress(); -// Assert.assertEquals(address.getRecipientName(), RECIPIENTSNAME); Assert.assertEquals(address.getCity(), CITY); Assert.assertEquals(address.getCountryCode(), COUNTRYCODE); Assert.assertEquals(address.getLine1(), LINE1); @@ -48,7 +41,6 @@ public void testConstruction() { Assert.assertEquals(address.getPostalCode(), POSTALCODE); Assert.assertEquals(address.getPhone(), PHONE); Assert.assertEquals(address.getState(), STATE); - Assert.assertEquals(address.getType(), TYPE); } @Test diff --git a/rest-api-sdk/src/test/java/com/paypal/api/payments/AuthorizationTestCase.java b/rest-api-sdk/src/test/java/com/paypal/api/payments/AuthorizationTestCase.java index f2a390bd..c9de8d20 100644 --- a/rest-api-sdk/src/test/java/com/paypal/api/payments/AuthorizationTestCase.java +++ b/rest-api-sdk/src/test/java/com/paypal/api/payments/AuthorizationTestCase.java @@ -1,13 +1,22 @@ package com.paypal.api.payments; +import java.io.File; import java.util.ArrayList; import java.util.List; import org.testng.Assert; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import org.testng.log4testng.Logger; + +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; public class AuthorizationTestCase { + private static final Logger logger = Logger + .getLogger(AuthorizationTestCase.class); + public static final String ID = "12345"; public static final String PARENTPAYMENT = "12345"; @@ -18,6 +27,17 @@ public class AuthorizationTestCase { public static final String CREATEDTIME = "2013-01-17T18:12:02.347Z"; + public String authorizationId = null; + + public Authorization authorization = null; + + @BeforeClass + public void beforeClass() throws PayPalRESTException { + File testFile = new File(".", + "src/test/resources/sdk_config.properties"); + PayPalResource.initConfig(testFile); + } + public static Authorization createAuthorization() { List links = new ArrayList(); links.add(LinksTestCase.createLinks()); @@ -43,6 +63,68 @@ public void testConstruction() { AmountTestCase.CURRENCY); } + @Test(dependsOnMethods = { "testGetRefundForNull" }) + public void testGetAuthorization() throws PayPalRESTException { + logger.info("**** Authorize Payment ****"); + Payment payment = getPaymentAgainstAuthorization(); + Payment authPayment = payment.create(TokenHolder.accessToken); + logger.info("Authorization Payment created with ID = " + + authPayment.getId()); + authorizationId = authPayment.getTransactions().get(0) + .getRelatedResources().get(0).getAuthorization().getId(); + logger.info("Retrieving Authorization using id = " + authorizationId); + authorization = Authorization.get(TokenHolder.accessToken, + authorizationId); + logger.info("Request = " + Authorization.getLastRequest()); + logger.info("Response = " + Authorization.getLastResponse()); + logger.info("Authorization State: " + authorization.getState()); + } + + @Test(dependsOnMethods = { "testGetAuthorization" }) + public void testAuthorizationCapture() throws PayPalRESTException { + logger.info("**** Capture Authorization ****"); + Capture capture = new Capture(); + Amount amount = new Amount(); + amount.setCurrency("USD").setTotal("1"); + capture.setAmount(amount); + capture.setIsFinalCapture(true); + Capture responsecapture = authorization.capture( + TokenHolder.accessToken, capture); + logger.info("Request = " + Authorization.getLastRequest()); + logger.info("Response = " + Authorization.getLastResponse()); + logger.info("Returned Capture state: " + responsecapture.getState()); + } + + @Test(dependsOnMethods = { "testAuthorizationCapture" }) + public void testAuthorizationVoid() throws PayPalRESTException { + logger.info("**** Void Authorization ****"); + Authorization auth = getAuthorization(); + Authorization responseAuthorization = auth + .doVoid(TokenHolder.accessToken); + logger.info("Request = " + Authorization.getLastRequest()); + logger.info("Response = " + Authorization.getLastResponse()); + logger.info("Returned Authorization state: " + + responseAuthorization.getState()); + } + + @Test(expectedExceptions = { IllegalArgumentException.class }) + public void testAuthorizationNullAccessToken() throws PayPalRESTException { + logger.info("**** Get Authorization (Null Access Token) ****"); + Authorization auth = Authorization.get((String) null, "123"); + } + + @Test(expectedExceptions = { IllegalArgumentException.class }) + public void testAuthorizationNullAuthId() throws PayPalRESTException { + logger.info("**** Get Authorization (Null Auth ID) ****"); + Authorization auth = Authorization.get(TokenHolder.accessToken, null); + } + + @Test(expectedExceptions = { IllegalArgumentException.class }) + public void testAuthorizationNullCapture() throws PayPalRESTException { + logger.info("**** Capture Authorization (Null Capture) ****"); + Capture responsecapture = getAuthorization().capture(TokenHolder.accessToken, null); + } + @Test public void testTOJSON() { Authorization authorization = createAuthorization(); @@ -55,4 +137,46 @@ public void testTOString() { Assert.assertEquals(authorization.toString().length() == 0, false); } + private Payment getPaymentAgainstAuthorization() { + Payment payment = new Payment(); + Details details = new Details(); + details.setShipping("10"); + details.setSubtotal("75"); + details.setTax("15"); + + Amount amount = new Amount(); + amount.setCurrency("USD"); + amount.setTotal("100"); + amount.setDetails(details); + + Transaction transaction = new Transaction(); + transaction.setAmount(amount); + transaction + .setDescription("This is the payment authorization description."); + List transactions = new ArrayList(); + transactions.add(transaction); + + FundingInstrument fundingInstrument = new FundingInstrument(); + fundingInstrument.setCreditCard(CreditCardTestCase.createCreditCard()); + List fundingInstruments = new ArrayList(); + fundingInstruments.add(fundingInstrument); + + Payer payer = new Payer(); + payer.setPaymentMethod("credit_card"); + payer.setFundingInstruments(fundingInstruments); + + payment.setIntent("authorize"); + payment.setPayer(payer); + payment.setTransactions(transactions); + return payment; + } + + private Authorization getAuthorization() throws PayPalRESTException { + Payment payment = getPaymentAgainstAuthorization(); + Payment authPayment = payment.create(TokenHolder.accessToken); + Authorization authorization = authPayment.getTransactions().get(0) + .getRelatedResources().get(0).getAuthorization(); + return authorization; + } + } diff --git a/rest-api-sdk/src/test/java/com/paypal/api/payments/CaptureTestCase.java b/rest-api-sdk/src/test/java/com/paypal/api/payments/CaptureTestCase.java index 83e54c9a..08b07910 100644 --- a/rest-api-sdk/src/test/java/com/paypal/api/payments/CaptureTestCase.java +++ b/rest-api-sdk/src/test/java/com/paypal/api/payments/CaptureTestCase.java @@ -1,16 +1,23 @@ package com.paypal.api.payments; +import java.io.File; import java.util.ArrayList; import java.util.List; import org.testng.Assert; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import org.testng.log4testng.Logger; + +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; public class CaptureTestCase { - public static final String AUTHID = "12345"; + private static final Logger logger = Logger + .getLogger(CaptureTestCase.class); - public static final String DESCRIPTION = "sample description"; + public static final String AUTHID = "12345"; public static final String ID = "12345"; @@ -21,12 +28,20 @@ public class CaptureTestCase { public static final Amount AMOUNT = AmountTestCase.createAmount("120.00"); public static final String CREATEDTIME = "2013-01-17T18:12:02.347Z"; + + private Capture retrievedCapture = null; + + @BeforeClass + public void beforeClass() throws PayPalRESTException { + File testFile = new File(".", + "src/test/resources/sdk_config.properties"); + PayPalResource.initConfig(testFile); + } public static Capture createCapture() { List links = new ArrayList(); links.add(LinksTestCase.createLinks()); Capture capture = new Capture(); - capture.setDescription(DESCRIPTION); capture.setId(ID); capture.setParentPayment(PARENTPAYMENT); capture.setState(STATE); @@ -40,7 +55,6 @@ public static Capture createCapture() { public void testConstruction() { Capture capture = createCapture(); Assert.assertEquals(capture.getId(), ID); - Assert.assertEquals(capture.getDescription(), DESCRIPTION); Assert.assertEquals(capture.getParentPayment(), PARENTPAYMENT); Assert.assertEquals(capture.getState(), STATE); Assert.assertEquals(capture.getAmount().getCurrency(), @@ -49,6 +63,67 @@ public void testConstruction() { Assert.assertEquals(capture.getLinks().size(), 1); } + @Test(dependsOnMethods = { "testAuthorizationVoid" }) + public void testGetCapture() throws PayPalRESTException { + logger.info("**** Get Capture ****"); + Payment payment = getPaymentAgainstAuthorization(); + Payment authPayment = payment.create(TokenHolder.accessToken); + String authorizationId = authPayment.getTransactions().get(0) + .getRelatedResources().get(0).getAuthorization().getId(); + Authorization authorization = Authorization.get(TokenHolder.accessToken, + authorizationId); + Capture capture = new Capture(); + Amount amount = new Amount(); + amount.setCurrency("USD").setTotal("1"); + capture.setAmount(amount).setIsFinalCapture(true); + Capture responsecapture = authorization.capture( + TokenHolder.accessToken, capture); + logger.info("Generated Capture Id = " + responsecapture.getId()); + retrievedCapture = Capture.get(TokenHolder.accessToken, responsecapture.getId()); + logger.info("Request = " + Capture.getLastRequest()); + logger.info("Response = " + Capture.getLastResponse()); + logger.info("Retrieved Capture State: " + retrievedCapture.getState()); + } + + @Test(dependsOnMethods = { "testGetCapture" }) + public void testRefundCapture() throws PayPalRESTException { + logger.info("**** Refund Capture ****"); + Refund refund = new Refund(); + Amount amount = new Amount(); + amount.setCurrency("USD").setTotal("1"); + refund.setAmount(amount); + Refund responseRefund = retrievedCapture.refund(TokenHolder.accessToken, refund); + logger.info("Request = " + Capture.getLastRequest()); + logger.info("Response = " + Capture.getLastResponse()); + logger.info("Refund State: " + responseRefund.getState()); + } + + @Test(expectedExceptions = { IllegalArgumentException.class }) + public void testGetCaptureNullCaptureId() throws PayPalRESTException { + logger.info("**** Get Capture (Null Capture Id) ****"); + Capture capture = Capture.get(TokenHolder.accessToken, null); + } + + @Test(expectedExceptions = { IllegalArgumentException.class }) + public void testCaptureNullRefund() throws PayPalRESTException { + logger.info("**** Get Capture (Null Refund) ****"); + Payment payment = getPaymentAgainstAuthorization(); + Payment authPayment = payment.create(TokenHolder.accessToken); + String authorizationId = authPayment.getTransactions().get(0) + .getRelatedResources().get(0).getAuthorization().getId(); + Authorization authorization = Authorization.get(TokenHolder.accessToken, + authorizationId); + Capture capture = new Capture(); + Amount amount = new Amount(); + amount.setCurrency("USD").setTotal("1"); + capture.setAmount(amount).setIsFinalCapture(true); + Capture responsecapture = authorization.capture( + TokenHolder.accessToken, capture); + logger.info("Generated Capture Id = " + responsecapture.getId()); + Capture rCapture = Capture.get(TokenHolder.accessToken, responsecapture.getId()); + rCapture.refund(TokenHolder.accessToken, null); + } + @Test public void testTOJSON() { Capture capture = createCapture(); @@ -61,4 +136,33 @@ public void testTOString() { Assert.assertEquals(capture.toString().length() == 0, false); } + private Payment getPaymentAgainstAuthorization() { + Payment payment = new Payment(); + Details details = new Details().setShipping("10").setSubtotal("75").setTax("15"); + + Amount amount = new Amount(); + amount.setCurrency("USD").setTotal("100").setDetails(details); + + Transaction transaction = new Transaction(); + transaction.setAmount(amount); + transaction + .setDescription("This is the payment authorization description."); + List transactions = new ArrayList(); + transactions.add(transaction); + + FundingInstrument fundingInstrument = new FundingInstrument(); + fundingInstrument.setCreditCard(CreditCardTestCase.createCreditCard()); + List fundingInstruments = new ArrayList(); + fundingInstruments.add(fundingInstrument); + + Payer payer = new Payer(); + payer.setPaymentMethod("credit_card"); + payer.setFundingInstruments(fundingInstruments); + + payment.setIntent("authorize"); + payment.setPayer(payer); + payment.setTransactions(transactions); + return payment; + } + } diff --git a/rest-api-sdk/src/test/java/com/paypal/api/payments/CreditCardTestCase.java b/rest-api-sdk/src/test/java/com/paypal/api/payments/CreditCardTestCase.java index f67c1ace..da55bc66 100644 --- a/rest-api-sdk/src/test/java/com/paypal/api/payments/CreditCardTestCase.java +++ b/rest-api-sdk/src/test/java/com/paypal/api/payments/CreditCardTestCase.java @@ -58,19 +58,11 @@ public void beforeClass() throws PayPalRESTException { public static CreditCard createCreditCard() { CreditCard creditCard = new CreditCard(); - creditCard.setBillingAddress(BILLINGADDRESS); - creditCard.setExpireMonth(EXPMONTH); - creditCard.setExpireYear(EXPYEAR); - creditCard.setFirstName(FIRSTNAME); - creditCard.setLastName(LASTNAME); - creditCard.setNumber(NUMBER); - creditCard.setType(TYPE); - creditCard.setCvv2(CVV2); - creditCard.setBillingAddress(BILLINGADDRESS); - creditCard.setId(ID); - creditCard.setPayerId(PAYERID); - creditCard.setState(STATE); - creditCard.setValidUntil(VALIDUNTIL); + creditCard.setBillingAddress(BILLINGADDRESS).setExpireMonth(EXPMONTH) + .setExpireYear(EXPYEAR).setFirstName(FIRSTNAME) + .setLastName(LASTNAME).setNumber(NUMBER).setType(TYPE) + .setCvv2(CVV2).setBillingAddress(BILLINGADDRESS).setId(ID) + .setPayerId(PAYERID).setState(STATE).setValidUntil(VALIDUNTIL); return creditCard; } @@ -140,7 +132,8 @@ public void getCreditCard() throws PayPalRESTException { logger.info("**** Get CreditCard ****"); logger.info("Generated Access Token = " + TokenHolder.accessToken); - CreditCard retrievedCreditCard = CreditCard.get(TokenHolder.accessToken, createdCreditCardId); + CreditCard retrievedCreditCard = CreditCard.get( + TokenHolder.accessToken, createdCreditCardId); logger.info("Request = " + CreditCard.getLastRequest()); logger.info("Response = " + CreditCard.getLastResponse()); Assert.assertEquals( @@ -167,7 +160,7 @@ public void getCreditCardForNull() { Assert.fail(); } } - + @Test public void testCreditCardUnknownFileConfiguration() { try { @@ -191,7 +184,7 @@ public void testCreditCardInputStreamConfiguration() { Assert.fail("[sdk_config.properties] file is not available"); } } - + @Test public void testCreditCardPropertiesConfiguration() { try { diff --git a/rest-api-sdk/src/test/java/com/paypal/api/payments/PaymentTestCase.java b/rest-api-sdk/src/test/java/com/paypal/api/payments/PaymentTestCase.java index c0d9e5b8..9e8065bb 100644 --- a/rest-api-sdk/src/test/java/com/paypal/api/payments/PaymentTestCase.java +++ b/rest-api-sdk/src/test/java/com/paypal/api/payments/PaymentTestCase.java @@ -19,7 +19,6 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.paypal.core.ConfigManager; -import com.paypal.core.rest.APIContext; import com.paypal.core.rest.OAuthTokenCredential; import com.paypal.core.rest.PayPalRESTException; import com.paypal.core.rest.QueryParameters; @@ -70,15 +69,9 @@ public static Payment createCallPayment() { creditCard.setNumber("4417119669820331"); creditCard.setType("visa"); - // AmountDetails amountDetails = new AmountDetails(); - // amountDetails.setShipping("10"); - // amountDetails.setSubtotal("75"); - // amountDetails.setTax("15"); - Amount amount = new Amount(); amount.setCurrency("USD"); amount.setTotal("7"); - // amount.setDetails(amountDetails); Transaction transaction = new Transaction(); transaction.setAmount(amount); @@ -116,15 +109,15 @@ public static Payment createPayment() { creditCard.setNumber("4111111111111111"); creditCard.setType("visa"); - Details amountDetails = new Details(); - amountDetails.setShipping("10"); - amountDetails.setSubtotal("75"); - amountDetails.setTax("15"); + Details details = new Details(); + details.setShipping("10"); + details.setSubtotal("75"); + details.setTax("15"); Amount amount = new Amount(); amount.setCurrency("USD"); amount.setTotal("100"); - amount.setDetails(amountDetails); + amount.setDetails(details); Payee payee = new Payee(); payee.setMerchantId("NMXBYHSEL4FEY"); @@ -163,15 +156,15 @@ public static Payment createPayment() { } public static Payment createPaymentForExecution() { - Details amountDetails = new Details(); - amountDetails.setShipping("10"); - amountDetails.setSubtotal("75"); - amountDetails.setTax("15"); + Details details = new Details(); + details.setShipping("10"); + details.setSubtotal("75"); + details.setTax("15"); Amount amount = new Amount(); amount.setCurrency("USD"); amount.setTotal("100"); - amount.setDetails(amountDetails); + amount.setDetails(details); RedirectUrls redirectUrls = new RedirectUrls(); redirectUrls.setCancelUrl("http://www.hawaii.com"); @@ -241,30 +234,99 @@ public void testCreatePaymentAPI() throws PayPalRESTException { .get("id").getAsString(); } - @Test(dependsOnMethods = { "testCreatePaymentAPI" }) - public void testA() throws PayPalRESTException { - logger.info("**** Create CreditCard ****"); - logger.info("Generated Access Token = " + TokenHolder.accessToken); + public void testGetPaymentAPI() throws PayPalRESTException { + logger.info("**** Get Payment ****"); + logger.info("Setting Access Token = " + TokenHolder.accessToken); + payment = Payment.get(TokenHolder.accessToken, createdPaymentID); + logger.info("Request = " + Payment.getLastRequest()); + logger.info("Response = " + Payment.getLastResponse()); + logger.info("Retrieved Payment status = " + payment.getState()); + } - CreditCard creditCard = new CreditCard(); - creditCard.setExpireMonth(11); - creditCard.setExpireYear(2018); - creditCard.setNumber("4417119669820331"); - creditCard.setType("visa"); - CreditCard responseCreditCard = creditCard.create(TokenHolder.accessToken); - logger.info("Request = " + CreditCard.getLastRequest()); - logger.info("Response = " + CreditCard.getLastResponse()); - logger.info("Credit Card created with ID = " + responseCreditCard.getId()); - Assert.assertEquals(true, - "ok".equalsIgnoreCase(responseCreditCard.getState())); - logger.info("Created Credit Card status = " - + responseCreditCard.getState()); - String createdCreditCardId = responseCreditCard.getId(); - - System.out.println("CC: " + responseCreditCard); - - responseCreditCard.delete(TokenHolder.accessToken); + @Test(enabled = false, dependsOnMethods = { "testGetPaymentAPI" }) + public void testExecutePayment() throws PayPalRESTException, IOException { + logger.info("**** Execute Payment ****"); + Payment exPayment = createPaymentForExecution(); + exPayment = exPayment.create(TokenHolder.accessToken); + logger.info("Create Payment Response: " + exPayment); + logger.info("Payer ID:"); + InputStreamReader converter = new InputStreamReader(System.in); + BufferedReader in = new BufferedReader(converter); + String payerId = in.readLine(); + PaymentExecution paymentExecution = new PaymentExecution(); + paymentExecution.setPayerId(payerId); + exPayment = exPayment + .execute(TokenHolder.accessToken, paymentExecution); + logger.info("Request = " + Payment.getLastRequest()); + logger.info("Response = " + Payment.getLastResponse()); + logger.info("Retrieved Payment status = " + exPayment.getState()); + } + + @Test(dependsOnMethods = { "testGetPaymentAPI" }) + public void testGetPaymentHistoryAPI() throws PayPalRESTException { + logger.info("**** Get Payment History ****"); + logger.info("Setting Access Token = " + TokenHolder.accessToken); + Map containerMap = new HashMap(); + containerMap.put("count", "10"); + PaymentHistory paymentHistory = Payment.get(TokenHolder.accessToken, + containerMap); + logger.info("Request = " + Payment.getLastRequest()); + logger.info("Response = " + Payment.getLastResponse()); + logger.info("Retrieved Payments count = " + paymentHistory.getCount()); + } + + @Test(dependsOnMethods = { "testGetPaymentHistoryAPI" }) + public void testGetPaymentHistoryQueryParamsAPI() throws PayPalRESTException { + logger.info("**** Get Payment History ****"); + logger.info("Setting Access Token = " + TokenHolder.accessToken); + QueryParameters params = new QueryParameters(); + params.setCount("10"); + PaymentHistory paymentHistory = Payment.get(TokenHolder.accessToken, + params); + logger.info("Request = " + Payment.getLastRequest()); + logger.info("Response = " + Payment.getLastResponse()); + logger.info("Retrieved Payments count = " + paymentHistory.getCount()); + } + + @Test(dependsOnMethods = { "testGetPaymentHistoryQueryParamsAPI" }) + public void testFailCreatePaymentAPI() { + logger.info("**** Failing Create Payment ****"); + logger.info("Setting Access Token = " + TokenHolder.accessToken); + Payment payment = new Payment(); + try { + Payment createdPayment = payment.create(TokenHolder.accessToken); + } catch (PayPalRESTException e) { + Assert.assertEquals(e.getCause().getClass().getSimpleName(), + "HttpErrorException"); + } + } + + @Test(dependsOnMethods = { "testFailCreatePaymentAPI" }) + public void testFailGetPaymentAPI() { + logger.info("**** Failing Get Payment ****"); + logger.info("Setting Access Token = " + TokenHolder.accessToken); + try { + Payment createdPayment = Payment.get(TokenHolder.accessToken, + (String) null); + } catch (IllegalArgumentException e) { + Assert.assertTrue(e != null, + "Illegal Argument Exception not thrown for null arguments"); + } catch (PayPalRESTException e) { + Assert.fail(); + } + } + + @Test + public void testTOJSON() { + Payment payment = createPayment(); + Assert.assertEquals(payment.toJSON().length() == 0, false); + } + + @Test + public void testTOString() { + Payment payment = createPayment(); + Assert.assertEquals(payment.toString().length() == 0, false); } } diff --git a/rest-api-sdk/src/test/java/com/paypal/api/payments/RefundTestCase.java b/rest-api-sdk/src/test/java/com/paypal/api/payments/RefundTestCase.java index 3d8d88a3..17060f0b 100644 --- a/rest-api-sdk/src/test/java/com/paypal/api/payments/RefundTestCase.java +++ b/rest-api-sdk/src/test/java/com/paypal/api/payments/RefundTestCase.java @@ -21,8 +21,6 @@ public class RefundTestCase { public static final String CAPTUREID = "12345"; - public static final String DESCRIPTION = "sample description"; - public static final String ID = "12345"; public static final String PARENTPAYMENT = "12345"; @@ -47,7 +45,6 @@ public static Refund createRefund() { links.add(LinksTestCase.createLinks()); Refund refund = new Refund(); refund.setCaptureId(CAPTUREID); - refund.setDescription(DESCRIPTION); refund.setId(ID); refund.setParentPayment(PARENTPAYMENT); refund.setSaleId(SALEID); @@ -63,7 +60,6 @@ public void testConstruction() { Refund refund = createRefund(); Assert.assertEquals(refund.getId(), ID); Assert.assertEquals(refund.getCaptureId(), CAPTUREID); - Assert.assertEquals(refund.getDescription(), DESCRIPTION); Assert.assertEquals(refund.getParentPayment(), PARENTPAYMENT); Assert.assertEquals(refund.getSaleId(), SALEID); Assert.assertEquals(refund.getState(), STATE); From 04b28066167315f2d737e8ca875d63c5d41fa27d Mon Sep 17 00:00:00 2001 From: kumaravel jayakumar Date: Tue, 28 May 2013 13:38:03 +0530 Subject: [PATCH 21/30] Updated samples and testcases for new stubs --- .../servlet/AuthorizationCaptureServlet.java | 217 +++++++++++++++ .../servlet/CreateCreditCardServlet.java | 4 +- .../servlet/GetAuthorizationServlet.java | 205 +++++++++++++++ .../payments/servlet/GetCaptureServlet.java | 234 +++++++++++++++++ .../payments/servlet/GetPaymentServlet.java | 2 +- .../servlet/PaymentWithCreditCardServlet.java | 16 +- .../servlet/PaymentWithPayPalServlet.java | 63 +++-- .../servlet/PaymentWithSavedCardServlet.java | 12 +- .../servlet/RefundCaptureServlet.java | 246 ++++++++++++++++++ .../servlet/VoidAuthorizationServlet.java | 200 ++++++++++++++ .../src/main/webapp/WEB-INF/web.xml | 209 +++++++++------ rest-api-sample/src/main/webapp/index.html | 52 ++++ 12 files changed, 1336 insertions(+), 124 deletions(-) create mode 100644 rest-api-sample/src/main/java/com/paypal/api/payments/servlet/AuthorizationCaptureServlet.java create mode 100644 rest-api-sample/src/main/java/com/paypal/api/payments/servlet/GetAuthorizationServlet.java create mode 100644 rest-api-sample/src/main/java/com/paypal/api/payments/servlet/GetCaptureServlet.java create mode 100644 rest-api-sample/src/main/java/com/paypal/api/payments/servlet/RefundCaptureServlet.java create mode 100644 rest-api-sample/src/main/java/com/paypal/api/payments/servlet/VoidAuthorizationServlet.java diff --git a/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/AuthorizationCaptureServlet.java b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/AuthorizationCaptureServlet.java new file mode 100644 index 00000000..9b65adf8 --- /dev/null +++ b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/AuthorizationCaptureServlet.java @@ -0,0 +1,217 @@ +package com.paypal.api.payments.servlet; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; + +import com.paypal.api.payments.Address; +import com.paypal.api.payments.Amount; +import com.paypal.api.payments.Authorization; +import com.paypal.api.payments.Capture; +import com.paypal.api.payments.CreditCard; +import com.paypal.api.payments.Details; +import com.paypal.api.payments.FundingInstrument; +import com.paypal.api.payments.Payer; +import com.paypal.api.payments.Payment; +import com.paypal.api.payments.Transaction; +import com.paypal.api.payments.util.GenerateAccessToken; +import com.paypal.core.rest.APIContext; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; + +public class AuthorizationCaptureServlet extends HttpServlet { + + private static final long serialVersionUID = 1L; + + private static final Logger LOGGER = Logger + .getLogger(AuthorizationCaptureServlet.class); + + public void init(ServletConfig servletConfig) throws ServletException { + // ##Load Configuration + // Load SDK configuration for + // the resource. This intialization code can be + // done as Init Servlet. + InputStream is = AuthorizationCaptureServlet.class + .getResourceAsStream("/sdk_config.properties"); + try { + PayPalResource.initConfig(is); + } catch (PayPalRESTException e) { + LOGGER.fatal(e.getMessage()); + } + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + doPost(req, resp); + } + + // ##AuthorizationCapture + // Sample showing to do a Capture using Authorization + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + // ###AccessToken + // Retrieve the access token from + // OAuthTokenCredential by passing in + // ClientID and ClientSecret + APIContext apiContext = null; + String accessToken = null; + try { + accessToken = GenerateAccessToken.getAccessToken(); + + // ### Api Context + // Pass in a `ApiContext` object to authenticate + // the call and to send a unique request id + // (that ensures idempotency). The SDK generates + // a request id if you do not pass one explicitly. + apiContext = new APIContext(accessToken); + // Use this variant if you want to pass in a request id + // that is meaningful in your application, ideally + // a order id. + /* + * String requestId = Long.toString(System.nanoTime(); APIContext + * apiContext = new APIContext(accessToken, requestId )); + */ + + // ###Authorization + // Retrieve a Authorization object + // by making a Payment with intent + // as 'authorize' + Authorization authorization = getAuthorization(apiContext); + + // ###Amount + // Let's you specify a capture amount. + Amount amount = new Amount(); + amount.setCurrency("USD"); + amount.setTotal("4.54"); + + // ###Capture + Capture capture = new Capture(); + capture.setAmount(amount); + + // ##IsFinalCapture + // If set to true, all remaining + // funds held by the authorization + // will be released in the funding + // instrument. Default is ‘false’. + capture.setIsFinalCapture(true); + + // Capture by POSTing to + // URI v1/payments/authorization/{authorization_id}/capture + Capture responseCapture = authorization.capture(apiContext, capture); + + req.setAttribute("response", Authorization.getLastResponse()); + LOGGER.info("Capture id = " + responseCapture.getId() + + " and status = " + responseCapture.getState()); + } catch (PayPalRESTException e) { + req.setAttribute("error", e.getMessage()); + } + req.setAttribute("request", Authorization.getLastRequest()); + req.getRequestDispatcher("response.jsp").forward(req, resp); + } + + private Authorization getAuthorization(APIContext apiContext) + throws PayPalRESTException { + + // ###Details + // Let's you specify details of a payment amount. + Details details = new Details(); + details.setShipping("0.03"); + details.setSubtotal("107.41"); + details.setTax("0.03"); + + // ###Amount + // Let's you specify a payment amount. + Amount amount = new Amount(); + amount.setCurrency("USD"); + amount.setTotal("107.47"); + amount.setDetails(details); + + // ###Transaction + // A transaction defines the contract of a + // payment - what is the payment for and who + // is fulfilling it. Transaction is created with + // a `Payee` and `Amount` types + Transaction transaction = new Transaction(); + transaction.setAmount(amount); + transaction + .setDescription("This is the payment transaction description."); + + // The Payment creation API requires a list of + // Transaction; add the created `Transaction` + // to a List + List transactions = new ArrayList(); + transactions.add(transaction); + + // ###Address + // Base Address object used as shipping or billing + // address in a payment. [Optional] + Address billingAddress = new Address(); + billingAddress.setCity("Johnstown"); + billingAddress.setCountryCode("US"); + billingAddress.setLine1("52 N Main ST"); + billingAddress.setPostalCode("43210"); + billingAddress.setState("OH"); + + // ###CreditCard + // A resource representing a credit card that can be + // used to fund a payment. + CreditCard creditCard = new CreditCard(); + creditCard.setBillingAddress(billingAddress); + creditCard.setCvv2("874"); + creditCard.setExpireMonth(11); + creditCard.setExpireYear(2018); + creditCard.setFirstName("Joe"); + creditCard.setLastName("Shopper"); + creditCard.setNumber("4417119669820331"); + creditCard.setType("visa"); + + // ###FundingInstrument + // A resource representing a Payeer's funding instrument. + // Use a Payer ID (A unique identifier of the payer generated + // and provided by the facilitator. This is required when + // creating or using a tokenized funding instrument) + // and the `CreditCardDetails` + FundingInstrument fundingInstrument = new FundingInstrument(); + fundingInstrument.setCreditCard(creditCard); + + // The Payment creation API requires a list of + // FundingInstrument; add the created `FundingInstrument` + // to a List + List fundingInstruments = new ArrayList(); + fundingInstruments.add(fundingInstrument); + + // ###Payer + // A resource representing a Payer that funds a payment + // Use the List of `FundingInstrument` and the Payment Method + // as 'credit_card' + Payer payer = new Payer(); + payer.setFundingInstruments(fundingInstruments); + payer.setPaymentMethod("credit_card"); + + // ###Payment + // A Payment Resource; create one using + // the above types and intent as 'authorize' + Payment payment = new Payment(); + payment.setIntent("authorize"); + payment.setPayer(payer); + payment.setTransactions(transactions); + + Payment responsePayment = payment.create(apiContext); + return responsePayment.getTransactions().get(0) + .getRelatedResources().get(0).getAuthorization(); + } + +} diff --git a/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/CreateCreditCardServlet.java b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/CreateCreditCardServlet.java index 0da959b3..8027586e 100644 --- a/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/CreateCreditCardServlet.java +++ b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/CreateCreditCardServlet.java @@ -63,8 +63,8 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) // A resource representing a credit card that can be // used to fund a payment. CreditCard creditCard = new CreditCard(); - creditCard.setExpireMonth("11"); - creditCard.setExpireYear("2018"); + creditCard.setExpireMonth(11); + creditCard.setExpireYear(2018); creditCard.setNumber("4417119669820331"); creditCard.setType("visa"); diff --git a/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/GetAuthorizationServlet.java b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/GetAuthorizationServlet.java new file mode 100644 index 00000000..cc21e580 --- /dev/null +++ b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/GetAuthorizationServlet.java @@ -0,0 +1,205 @@ +package com.paypal.api.payments.servlet; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; + +import com.paypal.api.payments.Address; +import com.paypal.api.payments.Amount; +import com.paypal.api.payments.Authorization; +import com.paypal.api.payments.CreditCard; +import com.paypal.api.payments.Details; +import com.paypal.api.payments.FundingInstrument; +import com.paypal.api.payments.Payer; +import com.paypal.api.payments.Payment; +import com.paypal.api.payments.Transaction; +import com.paypal.api.payments.util.GenerateAccessToken; +import com.paypal.core.rest.APIContext; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; + +public class GetAuthorizationServlet extends HttpServlet { + + private static final long serialVersionUID = 1L; + + private static final Logger LOGGER = Logger + .getLogger(GetAuthorizationServlet.class); + + public void init(ServletConfig servletConfig) throws ServletException { + // ##Load Configuration + // Load SDK configuration for + // the resource. This intialization code can be + // done as Init Servlet. + InputStream is = GetAuthorizationServlet.class + .getResourceAsStream("/sdk_config.properties"); + try { + PayPalResource.initConfig(is); + } catch (PayPalRESTException e) { + LOGGER.fatal(e.getMessage()); + } + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + doPost(req, resp); + } + + // ##GetAuthorization + // Sample showing to do a Get Authorization + // using Authorization Id + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + // ###AccessToken + // Retrieve the access token from + // OAuthTokenCredential by passing in + // ClientID and ClientSecret + APIContext apiContext = null; + String accessToken = null; + try { + accessToken = GenerateAccessToken.getAccessToken(); + + // ### Api Context + // Pass in a `ApiContext` object to authenticate + // the call and to send a unique request id + // (that ensures idempotency). The SDK generates + // a request id if you do not pass one explicitly. + apiContext = new APIContext(accessToken); + // Use this variant if you want to pass in a request id + // that is meaningful in your application, ideally + // a order id. + /* + * String requestId = Long.toString(System.nanoTime(); APIContext + * apiContext = new APIContext(accessToken, requestId )); + */ + + // ###Authorization + // Retrieve an Authorization Id + // by making a Payment with intent + // as 'authorize' and parsing through + // the Payment object + String authorizationId = getAuthorizationID(apiContext); + + // Get Authorization by sending + // a GET request with authorization Id + // to the + // URI v1/payments/authorization/{id} + Authorization authorization = Authorization.get(apiContext, + authorizationId); + + req.setAttribute("response", Authorization.getLastResponse()); + LOGGER.info("Authorization id = " + authorization.getId() + + " and status = " + authorization.getState()); + } catch (PayPalRESTException e) { + req.setAttribute("error", e.getMessage()); + } + req.getRequestDispatcher("response.jsp").forward(req, resp); + } + + private String getAuthorizationID(APIContext apiContext) + throws PayPalRESTException { + String authorizationID = null; + + // ###Details + // Let's you specify details of a payment amount. + Details details = new Details(); + details.setShipping("0.03"); + details.setSubtotal("107.41"); + details.setTax("0.03"); + + // ###Amount + // Let's you specify a payment amount. + Amount amount = new Amount(); + amount.setCurrency("USD"); + amount.setTotal("107.47"); + amount.setDetails(details); + + // ###Transaction + // A transaction defines the contract of a + // payment - what is the payment for and who + // is fulfilling it. Transaction is created with + // a `Payee` and `Amount` types + Transaction transaction = new Transaction(); + transaction.setAmount(amount); + transaction + .setDescription("This is the payment transaction description."); + + // The Payment creation API requires a list of + // Transaction; add the created `Transaction` + // to a List + List transactions = new ArrayList(); + transactions.add(transaction); + + // ###Address + // Base Address object used as shipping or billing + // address in a payment. [Optional] + Address billingAddress = new Address(); + billingAddress.setCity("Johnstown"); + billingAddress.setCountryCode("US"); + billingAddress.setLine1("52 N Main ST"); + billingAddress.setPostalCode("43210"); + billingAddress.setState("OH"); + + // ###CreditCard + // A resource representing a credit card that can be + // used to fund a payment. + CreditCard creditCard = new CreditCard(); + creditCard.setBillingAddress(billingAddress); + creditCard.setCvv2("874"); + creditCard.setExpireMonth(11); + creditCard.setExpireYear(2018); + creditCard.setFirstName("Joe"); + creditCard.setLastName("Shopper"); + creditCard.setNumber("4417119669820331"); + creditCard.setType("visa"); + + // ###FundingInstrument + // A resource representing a Payeer's funding instrument. + // Use a Payer ID (A unique identifier of the payer generated + // and provided by the facilitator. This is required when + // creating or using a tokenized funding instrument) + // and the `CreditCardDetails` + FundingInstrument fundingInstrument = new FundingInstrument(); + fundingInstrument.setCreditCard(creditCard); + + // The Payment creation API requires a list of + // FundingInstrument; add the created `FundingInstrument` + // to a List + List fundingInstruments = new ArrayList(); + fundingInstruments.add(fundingInstrument); + + // ###Payer + // A resource representing a Payer that funds a payment + // Use the List of `FundingInstrument` and the Payment Method + // as 'credit_card' + Payer payer = new Payer(); + payer.setFundingInstruments(fundingInstruments); + payer.setPaymentMethod("credit_card"); + + // ###Payment + // A Payment Resource; create one using + // the above types and intent as 'authorize' + Payment payment = new Payment(); + payment.setIntent("authorize"); + payment.setPayer(payer); + payment.setTransactions(transactions); + + Payment responsePayment = payment.create(apiContext); + + // Retrieve the authorization Id + authorizationID = responsePayment.getTransactions().get(0) + .getRelatedResources().get(0).getAuthorization().getId(); + return authorizationID; + } + +} diff --git a/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/GetCaptureServlet.java b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/GetCaptureServlet.java new file mode 100644 index 00000000..11f420c0 --- /dev/null +++ b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/GetCaptureServlet.java @@ -0,0 +1,234 @@ +package com.paypal.api.payments.servlet; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; + +import com.paypal.api.payments.Address; +import com.paypal.api.payments.Amount; +import com.paypal.api.payments.Authorization; +import com.paypal.api.payments.Capture; +import com.paypal.api.payments.CreditCard; +import com.paypal.api.payments.Details; +import com.paypal.api.payments.FundingInstrument; +import com.paypal.api.payments.Payer; +import com.paypal.api.payments.Payment; +import com.paypal.api.payments.Transaction; +import com.paypal.api.payments.util.GenerateAccessToken; +import com.paypal.core.rest.APIContext; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; + +public class GetCaptureServlet extends HttpServlet { + + private static final long serialVersionUID = 1L; + + private static final Logger LOGGER = Logger + .getLogger(GetAuthorizationServlet.class); + + public void init(ServletConfig servletConfig) throws ServletException { + // ##Load Configuration + // Load SDK configuration for + // the resource. This intialization code can be + // done as Init Servlet. + InputStream is = GetCaptureServlet.class + .getResourceAsStream("/sdk_config.properties"); + try { + PayPalResource.initConfig(is); + } catch (PayPalRESTException e) { + LOGGER.fatal(e.getMessage()); + } + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + doPost(req, resp); + } + + // ##GetCapture + // Sample showing to Get a Capture using + // CaptureId + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + // ###AccessToken + // Retrieve the access token from + // OAuthTokenCredential by passing in + // ClientID and ClientSecret + APIContext apiContext = null; + String accessToken = null; + try { + accessToken = GenerateAccessToken.getAccessToken(); + + // ### Api Context + // Pass in a `ApiContext` object to authenticate + // the call and to send a unique request id + // (that ensures idempotency). The SDK generates + // a request id if you do not pass one explicitly. + apiContext = new APIContext(accessToken); + // Use this variant if you want to pass in a request id + // that is meaningful in your application, ideally + // a order id. + /* + * String requestId = Long.toString(System.nanoTime(); APIContext + * apiContext = new APIContext(accessToken, requestId )); + */ + + // ###Authorization + // Retrieve a Authorization object + // by making a Payment with intent + // as 'authorize' + Authorization authorization = getAuthorization(apiContext); + + /// ###Capture + // Create a Capture object + // by doing a capture on + // Authorization object + // and retrieve the Id + String captureId = getCaptureId(apiContext, authorization); + + // Retrieve the Capture object by + // doing a GET call to + // URI v1/payments/capture/{capture_id} + Capture capture = Capture.get(apiContext, captureId); + + req.setAttribute("response", Capture.getLastResponse()); + LOGGER.info("Capture id = " + capture.getId() + + " and status = " + capture.getState()); + + } catch (PayPalRESTException e) { + req.setAttribute("error", e.getMessage()); + } + req.getRequestDispatcher("response.jsp").forward(req, resp); + } + + private String getCaptureId(APIContext apiContext, Authorization authorization) throws PayPalRESTException{ + String captureId = null; + + // ###Amount + // Let's you specify a capture amount. + Amount amount = new Amount(); + amount.setCurrency("USD"); + amount.setTotal("4.54"); + + // ###Capture + Capture capture = new Capture(); + capture.setAmount(amount); + + // ##IsFinalCapture + // If set to true, all remaining + // funds held by the authorization + // will be released in the funding + // instrument. Default is ‘false’. + capture.setIsFinalCapture(true); + + // Capture by POSTing to + // URI v1/payments/authorization/{authorization_id}/capture + Capture responseCapture = authorization.capture(apiContext, capture); + captureId = responseCapture.getId(); + + return captureId; + } + + private Authorization getAuthorization(APIContext apiContext) + throws PayPalRESTException { + + // ###Details + // Let's you specify details of a payment amount. + Details details = new Details(); + details.setShipping("0.03"); + details.setSubtotal("107.41"); + details.setTax("0.03"); + + // ###Amount + // Let's you specify a payment amount. + Amount amount = new Amount(); + amount.setCurrency("USD"); + amount.setTotal("107.47"); + amount.setDetails(details); + + // ###Transaction + // A transaction defines the contract of a + // payment - what is the payment for and who + // is fulfilling it. Transaction is created with + // a `Payee` and `Amount` types + Transaction transaction = new Transaction(); + transaction.setAmount(amount); + transaction + .setDescription("This is the payment transaction description."); + + // The Payment creation API requires a list of + // Transaction; add the created `Transaction` + // to a List + List transactions = new ArrayList(); + transactions.add(transaction); + + // ###Address + // Base Address object used as shipping or billing + // address in a payment. [Optional] + Address billingAddress = new Address(); + billingAddress.setCity("Johnstown"); + billingAddress.setCountryCode("US"); + billingAddress.setLine1("52 N Main ST"); + billingAddress.setPostalCode("43210"); + billingAddress.setState("OH"); + + // ###CreditCard + // A resource representing a credit card that can be + // used to fund a payment. + CreditCard creditCard = new CreditCard(); + creditCard.setBillingAddress(billingAddress); + creditCard.setCvv2("874"); + creditCard.setExpireMonth(11); + creditCard.setExpireYear(2018); + creditCard.setFirstName("Joe"); + creditCard.setLastName("Shopper"); + creditCard.setNumber("4417119669820331"); + creditCard.setType("visa"); + + // ###FundingInstrument + // A resource representing a Payeer's funding instrument. + // Use a Payer ID (A unique identifier of the payer generated + // and provided by the facilitator. This is required when + // creating or using a tokenized funding instrument) + // and the `CreditCardDetails` + FundingInstrument fundingInstrument = new FundingInstrument(); + fundingInstrument.setCreditCard(creditCard); + + // The Payment creation API requires a list of + // FundingInstrument; add the created `FundingInstrument` + // to a List + List fundingInstruments = new ArrayList(); + fundingInstruments.add(fundingInstrument); + + // ###Payer + // A resource representing a Payer that funds a payment + // Use the List of `FundingInstrument` and the Payment Method + // as 'credit_card' + Payer payer = new Payer(); + payer.setFundingInstruments(fundingInstruments); + payer.setPaymentMethod("credit_card"); + + // ###Payment + // A Payment Resource; create one using + // the above types and intent as 'authorize' + Payment payment = new Payment(); + payment.setIntent("authorize"); + payment.setPayer(payer); + payment.setTransactions(transactions); + + Payment responsePayment = payment.create(apiContext); + return responsePayment.getTransactions().get(0).getRelatedResources() + .get(0).getAuthorization(); + } +} diff --git a/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/GetPaymentServlet.java b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/GetPaymentServlet.java index 982533f7..c274274e 100644 --- a/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/GetPaymentServlet.java +++ b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/GetPaymentServlet.java @@ -53,7 +53,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) } - // ##GetPaymentByPaymentId + // ##GetPayment // Call the method with a valid Payment ID @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) diff --git a/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/PaymentWithCreditCardServlet.java b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/PaymentWithCreditCardServlet.java index 63d9e1c3..464ad5b2 100644 --- a/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/PaymentWithCreditCardServlet.java +++ b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/PaymentWithCreditCardServlet.java @@ -71,19 +71,19 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) CreditCard creditCard = new CreditCard(); creditCard.setBillingAddress(billingAddress); creditCard.setCvv2("874"); - creditCard.setExpireMonth("11"); - creditCard.setExpireYear("2018"); + creditCard.setExpireMonth(11); + creditCard.setExpireYear(2018); creditCard.setFirstName("Joe"); creditCard.setLastName("Shopper"); creditCard.setNumber("4417119669820331"); creditCard.setType("visa"); - // ###AmountDetails + // ###Details // Let's you specify details of a payment amount. - AmountDetails amountDetails = new AmountDetails(); - amountDetails.setShipping("1"); - amountDetails.setSubtotal("5"); - amountDetails.setTax("1"); + Details details = new Details(); + details.setShipping("1"); + details.setSubtotal("5"); + details.setTax("1"); // ###Amount // Let's you specify a payment amount. @@ -91,7 +91,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) amount.setCurrency("USD"); // Total must be equal to sum of shipping, tax and subtotal. amount.setTotal("7"); - amount.setDetails(amountDetails); + amount.setDetails(details); // ###Transaction // A transaction defines the contract of a diff --git a/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/PaymentWithPayPalServlet.java b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/PaymentWithPayPalServlet.java index 839a0abf..5f3ebcc7 100644 --- a/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/PaymentWithPayPalServlet.java +++ b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/PaymentWithPayPalServlet.java @@ -6,16 +6,33 @@ import java.io.IOException; import java.io.InputStream; -import java.util.*; - -import javax.servlet.*; -import javax.servlet.http.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; -import com.paypal.api.payments.*; -import com.paypal.api.payments.util.*; -import com.paypal.core.rest.*; +import com.paypal.api.payments.Amount; +import com.paypal.api.payments.Details; +import com.paypal.api.payments.Links; +import com.paypal.api.payments.Payer; +import com.paypal.api.payments.Payment; +import com.paypal.api.payments.PaymentExecution; +import com.paypal.api.payments.RedirectUrls; +import com.paypal.api.payments.Transaction; +import com.paypal.api.payments.util.GenerateAccessToken; +import com.paypal.core.rest.APIContext; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; /** * @author lvairamani @@ -65,17 +82,17 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) accessToken = GenerateAccessToken.getAccessToken(); // ### Api Context - // Pass in a `ApiContext` object to authenticate - // the call and to send a unique request id + // Pass in a `ApiContext` object to authenticate + // the call and to send a unique request id // (that ensures idempotency). The SDK generates - // a request id if you do not pass one explicitly. + // a request id if you do not pass one explicitly. apiContext = new APIContext(accessToken); - // Use this variant if you want to pass in a request id - // that is meaningful in your application, ideally + // Use this variant if you want to pass in a request id + // that is meaningful in your application, ideally // a order id. - /* - * String requestId = Long.toString(System.nanoTime(); - * APIContext apiContext = new APIContext(accessToken, requestId )); + /* + * String requestId = Long.toString(System.nanoTime(); APIContext + * apiContext = new APIContext(accessToken, requestId )); */ } catch (PayPalRESTException e) { req.setAttribute("error", e.getMessage()); @@ -96,12 +113,12 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) } } else { - // ###AmountDetails + // ###Details // Let's you specify details of a payment amount. - AmountDetails amountDetails = new AmountDetails(); - amountDetails.setShipping("1"); - amountDetails.setSubtotal("5"); - amountDetails.setTax("1"); + Details details = new Details(); + details.setShipping("1"); + details.setSubtotal("5"); + details.setTax("1"); // ###Amount // Let's you specify a payment amount. @@ -109,7 +126,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) amount.setCurrency("USD"); // Total must be equal to sum of shipping, tax and subtotal. amount.setTotal("7"); - amount.setDetails(amountDetails); + amount.setDetails(details); // ###Transaction // A transaction defines the contract of a @@ -162,9 +179,9 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) + createdPayment.getId() + " and status = " + createdPayment.getState()); // ###Payment Approval Url - Iterator links = createdPayment.getLinks().iterator(); + Iterator links = createdPayment.getLinks().iterator(); while (links.hasNext()) { - Link link = links.next(); + Links link = links.next(); if (link.getRel().equalsIgnoreCase("approval_url")) { req.setAttribute("redirectURL", link.getHref()); } diff --git a/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/PaymentWithSavedCardServlet.java b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/PaymentWithSavedCardServlet.java index 10b0f7b6..b066d4cb 100644 --- a/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/PaymentWithSavedCardServlet.java +++ b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/PaymentWithSavedCardServlet.java @@ -63,12 +63,12 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) CreditCardToken creditCardToken = new CreditCardToken(); creditCardToken.setCreditCardId("CARD-5BT058015C739554AKE2GCEI"); - // ###AmountDetails + // ###Details // Let's you specify details of a payment amount. - AmountDetails amountDetails = new AmountDetails(); - amountDetails.setShipping("1"); - amountDetails.setSubtotal("5"); - amountDetails.setTax("1"); + Details details = new Details(); + details.setShipping("1"); + details.setSubtotal("5"); + details.setTax("1"); // ###Amount // Let's you specify a payment amount. @@ -76,7 +76,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) amount.setCurrency("USD"); // Total must be equal to the sum of shipping, tax and subtotal. amount.setTotal("7"); - amount.setDetails(amountDetails); + amount.setDetails(details); // ###Transaction // A transaction defines the contract of a diff --git a/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/RefundCaptureServlet.java b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/RefundCaptureServlet.java new file mode 100644 index 00000000..a2638a3b --- /dev/null +++ b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/RefundCaptureServlet.java @@ -0,0 +1,246 @@ +package com.paypal.api.payments.servlet; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; + +import com.paypal.api.payments.Address; +import com.paypal.api.payments.Amount; +import com.paypal.api.payments.Authorization; +import com.paypal.api.payments.Capture; +import com.paypal.api.payments.CreditCard; +import com.paypal.api.payments.Details; +import com.paypal.api.payments.FundingInstrument; +import com.paypal.api.payments.Payer; +import com.paypal.api.payments.Payment; +import com.paypal.api.payments.Refund; +import com.paypal.api.payments.Transaction; +import com.paypal.api.payments.util.GenerateAccessToken; +import com.paypal.core.rest.APIContext; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; + +public class RefundCaptureServlet extends HttpServlet { + + private static final long serialVersionUID = 1L; + + private static final Logger LOGGER = Logger + .getLogger(GetAuthorizationServlet.class); + + public void init(ServletConfig servletConfig) throws ServletException { + // ##Load Configuration + // Load SDK configuration for + // the resource. This intialization code can be + // done as Init Servlet. + InputStream is = RefundCaptureServlet.class + .getResourceAsStream("/sdk_config.properties"); + try { + PayPalResource.initConfig(is); + } catch (PayPalRESTException e) { + LOGGER.fatal(e.getMessage()); + } + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + doPost(req, resp); + } + + // ##GetCapture + // Sample showing to Get a Capture using + // CaptureId + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + // ###AccessToken + // Retrieve the access token from + // OAuthTokenCredential by passing in + // ClientID and ClientSecret + APIContext apiContext = null; + String accessToken = null; + try { + accessToken = GenerateAccessToken.getAccessToken(); + + // ### Api Context + // Pass in a `ApiContext` object to authenticate + // the call and to send a unique request id + // (that ensures idempotency). The SDK generates + // a request id if you do not pass one explicitly. + apiContext = new APIContext(accessToken); + // Use this variant if you want to pass in a request id + // that is meaningful in your application, ideally + // a order id. + /* + * String requestId = Long.toString(System.nanoTime(); APIContext + * apiContext = new APIContext(accessToken, requestId )); + */ + + // ###Authorization + // Retrieve a Authorization object + // by making a Payment with intent + // as 'authorize' + Authorization authorization = getAuthorization(apiContext); + + /// ###Capture + // Create a Capture object + // by doing a capture on + // Authorization object + // and retrieve the Id + Capture capture = getCapture(apiContext, authorization); + + /// ###Refund + /// Create a Refund object + Refund refund = new Refund(); + + // ###Amount + // Let's you specify a capture amount. + Amount amount = new Amount(); + amount.setCurrency("USD").setTotal("1"); + + refund.setAmount(amount); + + // Create new APIContext for + // Refund + apiContext = new APIContext(accessToken); + // Do a Refund by + // POSTing to + // URI v1/payments/capture/{capture_id}/refund + Refund responseRefund = capture.refund(apiContext, refund); + + req.setAttribute("response", Capture.getLastResponse()); + LOGGER.info("Refund id = " + responseRefund.getId() + + " and status = " + responseRefund.getState()); + + } catch (PayPalRESTException e) { + req.setAttribute("error", e.getMessage()); + } + req.setAttribute("request", Capture.getLastRequest()); + req.getRequestDispatcher("response.jsp").forward(req, resp); + } + + private Capture getCapture(APIContext apiContext, Authorization authorization) throws PayPalRESTException{ + // ###Amount + // Let's you specify a capture amount. + Amount amount = new Amount(); + amount.setCurrency("USD"); + amount.setTotal("4.54"); + + // ###Capture + Capture capture = new Capture(); + capture.setAmount(amount); + + // ##IsFinalCapture + // If set to true, all remaining + // funds held by the authorization + // will be released in the funding + // instrument. Default is ‘false’. + capture.setIsFinalCapture(true); + + // Capture by POSTing to + // URI v1/payments/authorization/{authorization_id}/capture + Capture responseCapture = authorization.capture(apiContext, capture); + return responseCapture; + } + + private Authorization getAuthorization(APIContext apiContext) + throws PayPalRESTException { + + // ###Details + // Let's you specify details of a payment amount. + Details details = new Details(); + details.setShipping("0.03"); + details.setSubtotal("107.41"); + details.setTax("0.03"); + + // ###Amount + // Let's you specify a payment amount. + Amount amount = new Amount(); + amount.setCurrency("USD"); + amount.setTotal("107.47"); + amount.setDetails(details); + + // ###Transaction + // A transaction defines the contract of a + // payment - what is the payment for and who + // is fulfilling it. Transaction is created with + // a `Payee` and `Amount` types + Transaction transaction = new Transaction(); + transaction.setAmount(amount); + transaction + .setDescription("This is the payment transaction description."); + + // The Payment creation API requires a list of + // Transaction; add the created `Transaction` + // to a List + List transactions = new ArrayList(); + transactions.add(transaction); + + // ###Address + // Base Address object used as shipping or billing + // address in a payment. [Optional] + Address billingAddress = new Address(); + billingAddress.setCity("Johnstown"); + billingAddress.setCountryCode("US"); + billingAddress.setLine1("52 N Main ST"); + billingAddress.setPostalCode("43210"); + billingAddress.setState("OH"); + + // ###CreditCard + // A resource representing a credit card that can be + // used to fund a payment. + CreditCard creditCard = new CreditCard(); + creditCard.setBillingAddress(billingAddress); + creditCard.setCvv2("874"); + creditCard.setExpireMonth(11); + creditCard.setExpireYear(2018); + creditCard.setFirstName("Joe"); + creditCard.setLastName("Shopper"); + creditCard.setNumber("4417119669820331"); + creditCard.setType("visa"); + + // ###FundingInstrument + // A resource representing a Payeer's funding instrument. + // Use a Payer ID (A unique identifier of the payer generated + // and provided by the facilitator. This is required when + // creating or using a tokenized funding instrument) + // and the `CreditCardDetails` + FundingInstrument fundingInstrument = new FundingInstrument(); + fundingInstrument.setCreditCard(creditCard); + + // The Payment creation API requires a list of + // FundingInstrument; add the created `FundingInstrument` + // to a List + List fundingInstruments = new ArrayList(); + fundingInstruments.add(fundingInstrument); + + // ###Payer + // A resource representing a Payer that funds a payment + // Use the List of `FundingInstrument` and the Payment Method + // as 'credit_card' + Payer payer = new Payer(); + payer.setFundingInstruments(fundingInstruments); + payer.setPaymentMethod("credit_card"); + + // ###Payment + // A Payment Resource; create one using + // the above types and intent as 'authorize' + Payment payment = new Payment(); + payment.setIntent("authorize"); + payment.setPayer(payer); + payment.setTransactions(transactions); + + Payment responsePayment = payment.create(apiContext); + return responsePayment.getTransactions().get(0).getRelatedResources() + .get(0).getAuthorization(); + } +} diff --git a/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/VoidAuthorizationServlet.java b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/VoidAuthorizationServlet.java new file mode 100644 index 00000000..b4f94e63 --- /dev/null +++ b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/VoidAuthorizationServlet.java @@ -0,0 +1,200 @@ +package com.paypal.api.payments.servlet; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; + +import com.paypal.api.payments.Address; +import com.paypal.api.payments.Amount; +import com.paypal.api.payments.Authorization; +import com.paypal.api.payments.CreditCard; +import com.paypal.api.payments.Details; +import com.paypal.api.payments.FundingInstrument; +import com.paypal.api.payments.Payer; +import com.paypal.api.payments.Payment; +import com.paypal.api.payments.Transaction; +import com.paypal.api.payments.util.GenerateAccessToken; +import com.paypal.core.rest.APIContext; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; + +public class VoidAuthorizationServlet extends HttpServlet { + + private static final long serialVersionUID = 1L; + + private static final Logger LOGGER = Logger + .getLogger(VoidAuthorizationServlet.class); + Map map = new HashMap(); + + public void init(ServletConfig servletConfig) throws ServletException { + // ##Load Configuration + // Load SDK configuration for + // the resource. This intialization code can be + // done as Init Servlet. + InputStream is = VoidAuthorizationServlet.class + .getResourceAsStream("/sdk_config.properties"); + try { + PayPalResource.initConfig(is); + } catch (PayPalRESTException e) { + LOGGER.fatal(e.getMessage()); + } + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + doPost(req, resp); + } + + // ##VoidAuthorization + // Sample showing how to void an Authorization + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + // ###AccessToken + // Retrieve the access token from + // OAuthTokenCredential by passing in + // ClientID and ClientSecret + APIContext apiContext = null; + String accessToken = null; + try { + accessToken = GenerateAccessToken.getAccessToken(); + + // ### Api Context + // Pass in a `ApiContext` object to authenticate + // the call and to send a unique request id + // (that ensures idempotency). The SDK generates + // a request id if you do not pass one explicitly. + apiContext = new APIContext(accessToken); + // Use this variant if you want to pass in a request id + // that is meaningful in your application, ideally + // a order id. + /* + * String requestId = Long.toString(System.nanoTime(); APIContext + * apiContext = new APIContext(accessToken, requestId )); + */ + + // ###Authorization + // Retrieve a Authorization object + // by making a Payment with intent + // as 'authorize' + Authorization authorization = getAuthorization(apiContext); + + // Void an Authorization + // by POSTing to + // URI v1/payments/authorization/{authorization_id}/void + Authorization returnAuthorization = authorization.doVoid(apiContext); + + req.setAttribute("response", Authorization.getLastResponse()); + LOGGER.info("Authorization id = " + returnAuthorization.getId() + + " and status = " + returnAuthorization.getState()); + } catch (PayPalRESTException e) { + req.setAttribute("error", e.getMessage()); + } + req.getRequestDispatcher("response.jsp").forward(req, resp); + } + + private Authorization getAuthorization(APIContext apiContext) + throws PayPalRESTException { + + // ###Details + // Let's you specify details of a payment amount. + Details details = new Details(); + details.setShipping("0.03"); + details.setSubtotal("107.41"); + details.setTax("0.03"); + + // ###Amount + // Let's you specify a payment amount. + Amount amount = new Amount(); + amount.setCurrency("USD"); + amount.setTotal("107.47"); + amount.setDetails(details); + + // ###Transaction + // A transaction defines the contract of a + // payment - what is the payment for and who + // is fulfilling it. Transaction is created with + // a `Payee` and `Amount` types + Transaction transaction = new Transaction(); + transaction.setAmount(amount); + transaction + .setDescription("This is the payment transaction description."); + + // The Payment creation API requires a list of + // Transaction; add the created `Transaction` + // to a List + List transactions = new ArrayList(); + transactions.add(transaction); + + // ###Address + // Base Address object used as shipping or billing + // address in a payment. [Optional] + Address billingAddress = new Address(); + billingAddress.setCity("Johnstown"); + billingAddress.setCountryCode("US"); + billingAddress.setLine1("52 N Main ST"); + billingAddress.setPostalCode("43210"); + billingAddress.setState("OH"); + + // ###CreditCard + // A resource representing a credit card that can be + // used to fund a payment. + CreditCard creditCard = new CreditCard(); + creditCard.setBillingAddress(billingAddress); + creditCard.setCvv2("874"); + creditCard.setExpireMonth(11); + creditCard.setExpireYear(2018); + creditCard.setFirstName("Joe"); + creditCard.setLastName("Shopper"); + creditCard.setNumber("4417119669820331"); + creditCard.setType("visa"); + + // ###FundingInstrument + // A resource representing a Payeer's funding instrument. + // Use a Payer ID (A unique identifier of the payer generated + // and provided by the facilitator. This is required when + // creating or using a tokenized funding instrument) + // and the `CreditCardDetails` + FundingInstrument fundingInstrument = new FundingInstrument(); + fundingInstrument.setCreditCard(creditCard); + + // The Payment creation API requires a list of + // FundingInstrument; add the created `FundingInstrument` + // to a List + List fundingInstruments = new ArrayList(); + fundingInstruments.add(fundingInstrument); + + // ###Payer + // A resource representing a Payer that funds a payment + // Use the List of `FundingInstrument` and the Payment Method + // as 'credit_card' + Payer payer = new Payer(); + payer.setFundingInstruments(fundingInstruments); + payer.setPaymentMethod("credit_card"); + + // ###Payment + // A Payment Resource; create one using + // the above types and intent as 'authorize' + Payment payment = new Payment(); + payment.setIntent("authorize"); + payment.setPayer(payer); + payment.setTransactions(transactions); + + Payment responsePayment = payment.create(apiContext); + return responsePayment.getTransactions().get(0) + .getRelatedResources().get(0).getAuthorization(); + } + +} diff --git a/rest-api-sample/src/main/webapp/WEB-INF/web.xml b/rest-api-sample/src/main/webapp/WEB-INF/web.xml index 9d3900f3..629e9c56 100644 --- a/rest-api-sample/src/main/webapp/WEB-INF/web.xml +++ b/rest-api-sample/src/main/webapp/WEB-INF/web.xml @@ -1,85 +1,126 @@ - - OAuth2TokenGenerator - - - 30 - - - - index.html - - - PaymentWithCreditCardServlet - com.paypal.api.payments.servlet.PaymentWithCreditCardServlet - - - PaymentWithCreditCardServlet - /paymentwithcreditcard - - - PaymentWithPayPalServlet - com.paypal.api.payments.servlet.PaymentWithPayPalServlet - - - PaymentWithPayPalServlet - /paymentwithpaypal - - - PaymentWithSavedCardServlet - com.paypal.api.payments.servlet.PaymentWithSavedCardServlet - - - PaymentWithSavedCardServlet - /paymentwithsavedcard - - - GetPaymentServlet - com.paypal.api.payments.servlet.GetPaymentServlet - - - GetPaymentServlet - /getpayment - - - GetPaymentHistoryServlet - com.paypal.api.payments.servlet.GetPaymentHistoryServlet - - - GetPaymentHistoryServlet - /getpaymenthistory - - - GetSaleServlet - com.paypal.api.payments.servlet.GetSaleServlet - - - GetSaleServlet - /getsale - - - SaleRefundServlet - com.paypal.api.payments.servlet.SaleRefundServlet - - - SaleRefundServlet - /salerefund - - - CreateCreditCardServlet - com.paypal.api.payments.servlet.CreateCreditCardServlet - - - CreateCreditCardServlet - /createcreditcard - - - GetCreditCardServlet - com.paypal.api.payments.servlet.GetCreditCardServlet - - - GetCreditCardServlet - /getcreditcard - - - + + OAuth2TokenGenerator + + 30 + + + index.html + + + GetAuthorizationServlet + com.paypal.api.payments.servlet.GetAuthorizationServlet + + + AuthorizationCaptureServlet + com.paypal.api.payments.servlet.AuthorizationCaptureServlet + + + VoidAuthorizationServlet + com.paypal.api.payments.servlet.VoidAuthorizationServlet + + + GetCaptureServlet + com.paypal.api.payments.servlet.GetCaptureServlet + + + RefundCaptureServlet + com.paypal.api.payments.servlet.RefundCaptureServlet + + + PaymentWithCreditCardServlet + com.paypal.api.payments.servlet.PaymentWithCreditCardServlet + + + PaymentWithCreditCardServlet + /paymentwithcreditcard + + + PaymentWithPayPalServlet + com.paypal.api.payments.servlet.PaymentWithPayPalServlet + + + PaymentWithPayPalServlet + /paymentwithpaypal + + + PaymentWithSavedCardServlet + com.paypal.api.payments.servlet.PaymentWithSavedCardServlet + + + + GetAuthorizationServlet + /getauthorizationservlet + + + AuthorizationCaptureServlet + /authorizationcaptureservlet + + + VoidAuthorizationServlet + /voidauthorizationservlet + + + GetCaptureServlet + /getcaptureservlet + + + RefundCaptureServlet + /refundcaptureservlet + + + PaymentWithSavedCardServlet + /paymentwithsavedcard + + + GetPaymentServlet + com.paypal.api.payments.servlet.GetPaymentServlet + + + GetPaymentServlet + /getpayment + + + GetPaymentHistoryServlet + com.paypal.api.payments.servlet.GetPaymentHistoryServlet + + + GetPaymentHistoryServlet + /getpaymenthistory + + + GetSaleServlet + com.paypal.api.payments.servlet.GetSaleServlet + + + GetSaleServlet + /getsale + + + SaleRefundServlet + com.paypal.api.payments.servlet.SaleRefundServlet + + + SaleRefundServlet + /salerefund + + + CreateCreditCardServlet + com.paypal.api.payments.servlet.CreateCreditCardServlet + + + CreateCreditCardServlet + /createcreditcard + + + GetCreditCardServlet + com.paypal.api.payments.servlet.GetCreditCardServlet + + + GetCreditCardServlet + /getcreditcard + + + diff --git a/rest-api-sample/src/main/webapp/index.html b/rest-api-sample/src/main/webapp/index.html index a6404061..88a9d36b 100644 --- a/rest-api-sample/src/main/webapp/index.html +++ b/rest-api-sample/src/main/webapp/index.html @@ -114,6 +114,58 @@

PayPal REST API Samples

Source + + + + Get Authorization + + Execute + + Source + + + Capture Authorization + + Execute + + Source + + + Void Authorization + + Execute + + Source + + + Get Capture + + Execute + + Source + + + Refund Capture + + Execute + + Source + From 21e35205af37da501e7870b940f25dbe9e10f039 Mon Sep 17 00:00:00 2001 From: kumaravel jayakumar Date: Tue, 28 May 2013 18:56:14 +0530 Subject: [PATCH 22/30] Added missing assert statment for testcases --- .../paypal/api/payments/AuthorizationTestCase.java | 4 ++++ .../com/paypal/api/payments/CaptureTestCase.java | 1 + .../com/paypal/api/payments/CreditCardTestCase.java | 12 ++++++++++++ 3 files changed, 17 insertions(+) diff --git a/rest-api-sdk/src/test/java/com/paypal/api/payments/AuthorizationTestCase.java b/rest-api-sdk/src/test/java/com/paypal/api/payments/AuthorizationTestCase.java index c9de8d20..f06df4d5 100644 --- a/rest-api-sdk/src/test/java/com/paypal/api/payments/AuthorizationTestCase.java +++ b/rest-api-sdk/src/test/java/com/paypal/api/payments/AuthorizationTestCase.java @@ -75,6 +75,8 @@ public void testGetAuthorization() throws PayPalRESTException { logger.info("Retrieving Authorization using id = " + authorizationId); authorization = Authorization.get(TokenHolder.accessToken, authorizationId); + Assert.assertEquals(authorization.getId(), authPayment.getTransactions().get(0) + .getRelatedResources().get(0).getAuthorization().getId()); logger.info("Request = " + Authorization.getLastRequest()); logger.info("Response = " + Authorization.getLastResponse()); logger.info("Authorization State: " + authorization.getState()); @@ -90,6 +92,7 @@ public void testAuthorizationCapture() throws PayPalRESTException { capture.setIsFinalCapture(true); Capture responsecapture = authorization.capture( TokenHolder.accessToken, capture); + Assert.assertEquals(responsecapture.getState(), "completed"); logger.info("Request = " + Authorization.getLastRequest()); logger.info("Response = " + Authorization.getLastResponse()); logger.info("Returned Capture state: " + responsecapture.getState()); @@ -101,6 +104,7 @@ public void testAuthorizationVoid() throws PayPalRESTException { Authorization auth = getAuthorization(); Authorization responseAuthorization = auth .doVoid(TokenHolder.accessToken); + Assert.assertEquals(responseAuthorization.getState(), "voided"); logger.info("Request = " + Authorization.getLastRequest()); logger.info("Response = " + Authorization.getLastResponse()); logger.info("Returned Authorization state: " diff --git a/rest-api-sdk/src/test/java/com/paypal/api/payments/CaptureTestCase.java b/rest-api-sdk/src/test/java/com/paypal/api/payments/CaptureTestCase.java index 08b07910..127f2b56 100644 --- a/rest-api-sdk/src/test/java/com/paypal/api/payments/CaptureTestCase.java +++ b/rest-api-sdk/src/test/java/com/paypal/api/payments/CaptureTestCase.java @@ -93,6 +93,7 @@ public void testRefundCapture() throws PayPalRESTException { amount.setCurrency("USD").setTotal("1"); refund.setAmount(amount); Refund responseRefund = retrievedCapture.refund(TokenHolder.accessToken, refund); + Assert.assertEquals("completed", responseRefund.getState()); logger.info("Request = " + Capture.getLastRequest()); logger.info("Response = " + Capture.getLastResponse()); logger.info("Refund State: " + responseRefund.getState()); diff --git a/rest-api-sdk/src/test/java/com/paypal/api/payments/CreditCardTestCase.java b/rest-api-sdk/src/test/java/com/paypal/api/payments/CreditCardTestCase.java index da55bc66..d37e26d8 100644 --- a/rest-api-sdk/src/test/java/com/paypal/api/payments/CreditCardTestCase.java +++ b/rest-api-sdk/src/test/java/com/paypal/api/payments/CreditCardTestCase.java @@ -144,6 +144,18 @@ public void getCreditCard() throws PayPalRESTException { + retrievedCreditCard.getState()); } + + @Test(dependsOnMethods = { "getCreditCard" }) + public void deleteCreditCard() throws PayPalRESTException { + logger.info("**** Delete CreditCard ****"); + logger.info("Generated Access Token = " + TokenHolder.accessToken); + + CreditCard retrievedCreditCard = CreditCard.get( + TokenHolder.accessToken, createdCreditCardId); + retrievedCreditCard.delete(TokenHolder.accessToken); + logger.info("Request = " + CreditCard.getLastRequest()); + logger.info("Response = " + CreditCard.getLastResponse()); + } @Test(dependsOnMethods = { "getCreditCard" }) public void getCreditCardForNull() { From 4543e3a629a3720b6f5cc2ecce0679fbc2cd689c Mon Sep 17 00:00:00 2001 From: kumaravel jayakumar Date: Wed, 29 May 2013 15:54:41 +0530 Subject: [PATCH 23/30] Set request body for VoidAuthorizationServlet --- .../paypal/api/payments/servlet/VoidAuthorizationServlet.java | 1 + 1 file changed, 1 insertion(+) diff --git a/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/VoidAuthorizationServlet.java b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/VoidAuthorizationServlet.java index b4f94e63..28abe145 100644 --- a/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/VoidAuthorizationServlet.java +++ b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/VoidAuthorizationServlet.java @@ -102,6 +102,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) } catch (PayPalRESTException e) { req.setAttribute("error", e.getMessage()); } + req.setAttribute("request", Authorization.getLastRequest()); req.getRequestDispatcher("response.jsp").forward(req, resp); } From dbeb9393f0fab66ecfbb7c69467d7bdecd5d2a5f Mon Sep 17 00:00:00 2001 From: kumaravel jayakumar Date: Wed, 29 May 2013 15:57:10 +0530 Subject: [PATCH 24/30] Reverted sandbox credentials in sdk_config.properties --- rest-api-sdk/src/test/resources/sdk_config.properties | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/rest-api-sdk/src/test/resources/sdk_config.properties b/rest-api-sdk/src/test/resources/sdk_config.properties index c06c9502..e9092491 100644 --- a/rest-api-sdk/src/test/resources/sdk_config.properties +++ b/rest-api-sdk/src/test/resources/sdk_config.properties @@ -16,11 +16,10 @@ http.ProxyPassword=null http.GoogleAppEngine = false # Service Configuration -service.EndPoint=http://localhost/restapi -oauth.EndPoint=http://localhost/ +service.EndPoint=https://api.sandbox.paypal.com # Live EndPoint # service.EndPoint=https://api.paypal.com # Credentials -clientID=AcJxCBCGPWRox3Y85YSr67vxDiho6QTnrFp8fBEpcM4ZdLSK1Ex4daY6pNNb -clientSecret=EPgxwRDLQiY12i1GI1-JV_XWD-uXNEysx3NAEEcrBv2AjCuqbVvdyu3XtYy9 +clientID=EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM +clientSecret=EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM From 5df047a95d315960684912ee3e2c2eb2f33ddaeb Mon Sep 17 00:00:00 2001 From: kumaravel jayakumar Date: Thu, 30 May 2013 14:20:44 +0530 Subject: [PATCH 25/30] Updated testcases for Authorization and Capture --- .../api/payments/AuthorizationTestCase.java | 34 +++++++----- .../paypal/api/payments/CaptureTestCase.java | 54 ++++++++++++------- 2 files changed, 55 insertions(+), 33 deletions(-) diff --git a/rest-api-sdk/src/test/java/com/paypal/api/payments/AuthorizationTestCase.java b/rest-api-sdk/src/test/java/com/paypal/api/payments/AuthorizationTestCase.java index f06df4d5..bb9345e9 100644 --- a/rest-api-sdk/src/test/java/com/paypal/api/payments/AuthorizationTestCase.java +++ b/rest-api-sdk/src/test/java/com/paypal/api/payments/AuthorizationTestCase.java @@ -9,6 +9,8 @@ import org.testng.annotations.Test; import org.testng.log4testng.Logger; +import com.paypal.core.ConfigManager; +import com.paypal.core.rest.OAuthTokenCredential; import com.paypal.core.rest.PayPalRESTException; import com.paypal.core.rest.PayPalResource; @@ -128,7 +130,7 @@ public void testAuthorizationNullCapture() throws PayPalRESTException { logger.info("**** Capture Authorization (Null Capture) ****"); Capture responsecapture = getAuthorization().capture(TokenHolder.accessToken, null); } - + @Test public void testTOJSON() { Authorization authorization = createAuthorization(); @@ -142,33 +144,39 @@ public void testTOString() { } private Payment getPaymentAgainstAuthorization() { - Payment payment = new Payment(); - Details details = new Details(); - details.setShipping("10"); - details.setSubtotal("75"); - details.setTax("15"); + Address billingAddress = AddressTestCase.createAddress(); + + CreditCard creditCard = new CreditCard(); + creditCard.setBillingAddress(billingAddress); + creditCard.setCvv2("874"); + creditCard.setExpireMonth(11); + creditCard.setExpireYear(2018); + creditCard.setFirstName("Joe"); + creditCard.setLastName("Shopper"); + creditCard.setNumber("4417119669820331"); + creditCard.setType("visa"); Amount amount = new Amount(); amount.setCurrency("USD"); - amount.setTotal("100"); - amount.setDetails(details); + amount.setTotal("7"); Transaction transaction = new Transaction(); transaction.setAmount(amount); transaction - .setDescription("This is the payment authorization description."); + .setDescription("This is the payment transaction description."); List transactions = new ArrayList(); transactions.add(transaction); FundingInstrument fundingInstrument = new FundingInstrument(); - fundingInstrument.setCreditCard(CreditCardTestCase.createCreditCard()); - List fundingInstruments = new ArrayList(); - fundingInstruments.add(fundingInstrument); + fundingInstrument.setCreditCard(creditCard); + List fundingInstrumentList = new ArrayList(); + fundingInstrumentList.add(fundingInstrument); Payer payer = new Payer(); + payer.setFundingInstruments(fundingInstrumentList); payer.setPaymentMethod("credit_card"); - payer.setFundingInstruments(fundingInstruments); + Payment payment = new Payment(); payment.setIntent("authorize"); payment.setPayer(payer); payment.setTransactions(transactions); diff --git a/rest-api-sdk/src/test/java/com/paypal/api/payments/CaptureTestCase.java b/rest-api-sdk/src/test/java/com/paypal/api/payments/CaptureTestCase.java index 127f2b56..a0b94d02 100644 --- a/rest-api-sdk/src/test/java/com/paypal/api/payments/CaptureTestCase.java +++ b/rest-api-sdk/src/test/java/com/paypal/api/payments/CaptureTestCase.java @@ -28,7 +28,7 @@ public class CaptureTestCase { public static final Amount AMOUNT = AmountTestCase.createAmount("120.00"); public static final String CREATEDTIME = "2013-01-17T18:12:02.347Z"; - + private Capture retrievedCapture = null; @BeforeClass @@ -70,8 +70,8 @@ public void testGetCapture() throws PayPalRESTException { Payment authPayment = payment.create(TokenHolder.accessToken); String authorizationId = authPayment.getTransactions().get(0) .getRelatedResources().get(0).getAuthorization().getId(); - Authorization authorization = Authorization.get(TokenHolder.accessToken, - authorizationId); + Authorization authorization = Authorization.get( + TokenHolder.accessToken, authorizationId); Capture capture = new Capture(); Amount amount = new Amount(); amount.setCurrency("USD").setTotal("1"); @@ -79,12 +79,13 @@ public void testGetCapture() throws PayPalRESTException { Capture responsecapture = authorization.capture( TokenHolder.accessToken, capture); logger.info("Generated Capture Id = " + responsecapture.getId()); - retrievedCapture = Capture.get(TokenHolder.accessToken, responsecapture.getId()); + retrievedCapture = Capture.get(TokenHolder.accessToken, + responsecapture.getId()); logger.info("Request = " + Capture.getLastRequest()); logger.info("Response = " + Capture.getLastResponse()); logger.info("Retrieved Capture State: " + retrievedCapture.getState()); } - + @Test(dependsOnMethods = { "testGetCapture" }) public void testRefundCapture() throws PayPalRESTException { logger.info("**** Refund Capture ****"); @@ -92,19 +93,20 @@ public void testRefundCapture() throws PayPalRESTException { Amount amount = new Amount(); amount.setCurrency("USD").setTotal("1"); refund.setAmount(amount); - Refund responseRefund = retrievedCapture.refund(TokenHolder.accessToken, refund); + Refund responseRefund = retrievedCapture.refund( + TokenHolder.accessToken, refund); Assert.assertEquals("completed", responseRefund.getState()); logger.info("Request = " + Capture.getLastRequest()); logger.info("Response = " + Capture.getLastResponse()); logger.info("Refund State: " + responseRefund.getState()); } - + @Test(expectedExceptions = { IllegalArgumentException.class }) public void testGetCaptureNullCaptureId() throws PayPalRESTException { logger.info("**** Get Capture (Null Capture Id) ****"); Capture capture = Capture.get(TokenHolder.accessToken, null); } - + @Test(expectedExceptions = { IllegalArgumentException.class }) public void testCaptureNullRefund() throws PayPalRESTException { logger.info("**** Get Capture (Null Refund) ****"); @@ -112,8 +114,8 @@ public void testCaptureNullRefund() throws PayPalRESTException { Payment authPayment = payment.create(TokenHolder.accessToken); String authorizationId = authPayment.getTransactions().get(0) .getRelatedResources().get(0).getAuthorization().getId(); - Authorization authorization = Authorization.get(TokenHolder.accessToken, - authorizationId); + Authorization authorization = Authorization.get( + TokenHolder.accessToken, authorizationId); Capture capture = new Capture(); Amount amount = new Amount(); amount.setCurrency("USD").setTotal("1"); @@ -121,10 +123,11 @@ public void testCaptureNullRefund() throws PayPalRESTException { Capture responsecapture = authorization.capture( TokenHolder.accessToken, capture); logger.info("Generated Capture Id = " + responsecapture.getId()); - Capture rCapture = Capture.get(TokenHolder.accessToken, responsecapture.getId()); + Capture rCapture = Capture.get(TokenHolder.accessToken, + responsecapture.getId()); rCapture.refund(TokenHolder.accessToken, null); } - + @Test public void testTOJSON() { Capture capture = createCapture(); @@ -138,28 +141,39 @@ public void testTOString() { } private Payment getPaymentAgainstAuthorization() { - Payment payment = new Payment(); - Details details = new Details().setShipping("10").setSubtotal("75").setTax("15"); + Address billingAddress = AddressTestCase.createAddress(); + + CreditCard creditCard = new CreditCard(); + creditCard.setBillingAddress(billingAddress); + creditCard.setCvv2("874"); + creditCard.setExpireMonth(11); + creditCard.setExpireYear(2018); + creditCard.setFirstName("Joe"); + creditCard.setLastName("Shopper"); + creditCard.setNumber("4417119669820331"); + creditCard.setType("visa"); Amount amount = new Amount(); - amount.setCurrency("USD").setTotal("100").setDetails(details); + amount.setCurrency("USD"); + amount.setTotal("7"); Transaction transaction = new Transaction(); transaction.setAmount(amount); transaction - .setDescription("This is the payment authorization description."); + .setDescription("This is the payment transaction description."); List transactions = new ArrayList(); transactions.add(transaction); FundingInstrument fundingInstrument = new FundingInstrument(); - fundingInstrument.setCreditCard(CreditCardTestCase.createCreditCard()); - List fundingInstruments = new ArrayList(); - fundingInstruments.add(fundingInstrument); + fundingInstrument.setCreditCard(creditCard); + List fundingInstrumentList = new ArrayList(); + fundingInstrumentList.add(fundingInstrument); Payer payer = new Payer(); + payer.setFundingInstruments(fundingInstrumentList); payer.setPaymentMethod("credit_card"); - payer.setFundingInstruments(fundingInstruments); + Payment payment = new Payment(); payment.setIntent("authorize"); payment.setPayer(payer); payment.setTransactions(transactions); From b3cf904b6cd46327a938de10cf497c0034341a0c Mon Sep 17 00:00:00 2001 From: kumaravel jayakumar Date: Thu, 30 May 2013 15:30:14 +0530 Subject: [PATCH 26/30] Updated Samples Markdown comments Updated pom file version to 0.7.0 Updated samples html files --- pom.xml | 2 +- rest-api-sample/pom.xml | 4 +- .../servlet/AuthorizationCaptureServlet.java | 7 +- .../servlet/GetAuthorizationServlet.java | 7 +- .../payments/servlet/GetCaptureServlet.java | 7 +- .../servlet/RefundCaptureServlet.java | 12 +- .../servlet/VoidAuthorizationServlet.java | 6 +- rest-api-sample/src/main/webapp/index.html | 10 +- .../source/AuthorizationCaptureServlet.html | 186 ++++ .../source/CreateCreditCardServlet.html | 4 +- .../source/GetAuthorizationServlet.html | 172 ++++ .../main/webapp/source/GetCaptureServlet.html | 196 ++++ .../main/webapp/source/GetPaymentServlet.html | 2 +- .../source/PaymentWithCreditCardServlet.html | 16 +- .../source/PaymentWithPayPalServlet.html | 61 +- .../source/PaymentWithSavedCardServlet.html | 12 +- .../webapp/source/RefundCaptureServlet.html | 204 +++++ .../source/VoidAuthorizationServlet.html | 175 ++++ .../src/main/webapp/source/assets/behavior.js | 838 ++++++++++++++++-- rest-api-sdk/pom.xml | 2 +- 20 files changed, 1805 insertions(+), 118 deletions(-) create mode 100644 rest-api-sample/src/main/webapp/source/AuthorizationCaptureServlet.html create mode 100644 rest-api-sample/src/main/webapp/source/GetAuthorizationServlet.html create mode 100644 rest-api-sample/src/main/webapp/source/GetCaptureServlet.html create mode 100644 rest-api-sample/src/main/webapp/source/RefundCaptureServlet.html create mode 100644 rest-api-sample/src/main/webapp/source/VoidAuthorizationServlet.html diff --git a/pom.xml b/pom.xml index a6b02c98..1e1e08b0 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.paypal.sdk rest-api - 0.6.0 + 0.7.0 pom rest-api diff --git a/rest-api-sample/pom.xml b/rest-api-sample/pom.xml index 614915fe..86766661 100644 --- a/rest-api-sample/pom.xml +++ b/rest-api-sample/pom.xml @@ -3,14 +3,14 @@ 4.0.0 com.paypal.sdk rest-api-sample - 0.6.0 + 0.7.0 REST API SAMPLE war com.paypal.sdk rest-api-sdk - 0.6.0 + 0.7.0 log4j diff --git a/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/AuthorizationCaptureServlet.java b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/AuthorizationCaptureServlet.java index 9b65adf8..80396f9b 100644 --- a/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/AuthorizationCaptureServlet.java +++ b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/AuthorizationCaptureServlet.java @@ -1,3 +1,7 @@ +// #AuthorizationCapture Sample +// This sample code demonstrate how you +// do a Capture on an Authorization +// API used: /v1/payments/authorization/{authorization_id}/capture package com.paypal.api.payments.servlet; import java.io.IOException; @@ -58,7 +62,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) } // ##AuthorizationCapture - // Sample showing to do a Capture using Authorization + // Sample showing how to do a Capture using Authorization @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { @@ -98,6 +102,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) amount.setTotal("4.54"); // ###Capture + // A capture transaction Capture capture = new Capture(); capture.setAmount(amount); diff --git a/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/GetAuthorizationServlet.java b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/GetAuthorizationServlet.java index cc21e580..a9a05a5d 100644 --- a/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/GetAuthorizationServlet.java +++ b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/GetAuthorizationServlet.java @@ -1,3 +1,8 @@ +// #GetAuthorization Sample +// This sample code demonstrate how you +// can retrieve the details of a Authorization +// resource +// API used: /v1/payments/authorization/{id} package com.paypal.api.payments.servlet; import java.io.IOException; @@ -55,7 +60,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) } // ##GetAuthorization - // Sample showing to do a Get Authorization + // Sample showing how to do a Get Authorization // using Authorization Id @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) diff --git a/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/GetCaptureServlet.java b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/GetCaptureServlet.java index 11f420c0..b1b652e8 100644 --- a/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/GetCaptureServlet.java +++ b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/GetCaptureServlet.java @@ -1,3 +1,8 @@ +// #GetCapture Sample +// This sample code demonstrate how you +// can retrieve the details of a Capture +// resource +// API used: /v1/payments/capture/{capture_id} package com.paypal.api.payments.servlet; import java.io.IOException; @@ -56,7 +61,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) } // ##GetCapture - // Sample showing to Get a Capture using + // Sample showing how to Get a Capture using // CaptureId @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) diff --git a/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/RefundCaptureServlet.java b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/RefundCaptureServlet.java index a2638a3b..23d64c7a 100644 --- a/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/RefundCaptureServlet.java +++ b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/RefundCaptureServlet.java @@ -1,3 +1,8 @@ +// #RefundCapture Sample +// This sample code demonstrate how you +// can do a Refund on a Capture +// resource +// API used: /v1/payments/capture/{capture_id}/refund package com.paypal.api.payments.servlet; import java.io.IOException; @@ -56,9 +61,9 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) doPost(req, resp); } - // ##GetCapture - // Sample showing to Get a Capture using - // CaptureId + // ##RefundCapture + // Sample showing to how to do a Refund on + // a Capture @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { @@ -95,7 +100,6 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) // Create a Capture object // by doing a capture on // Authorization object - // and retrieve the Id Capture capture = getCapture(apiContext, authorization); /// ###Refund diff --git a/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/VoidAuthorizationServlet.java b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/VoidAuthorizationServlet.java index 28abe145..55670b37 100644 --- a/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/VoidAuthorizationServlet.java +++ b/rest-api-sample/src/main/java/com/paypal/api/payments/servlet/VoidAuthorizationServlet.java @@ -1,3 +1,8 @@ +// #VoidAuthorization Sample +// This sample code demonstrate how you +// can do a Void on a Authorization +// resource +// API used: /v1/payments/authorization/{authorization_id}/void package com.paypal.api.payments.servlet; import java.io.IOException; @@ -102,7 +107,6 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) } catch (PayPalRESTException e) { req.setAttribute("error", e.getMessage()); } - req.setAttribute("request", Authorization.getLastRequest()); req.getRequestDispatcher("response.jsp").forward(req, resp); } diff --git a/rest-api-sample/src/main/webapp/index.html b/rest-api-sample/src/main/webapp/index.html index 88a9d36b..a574677c 100644 --- a/rest-api-sample/src/main/webapp/index.html +++ b/rest-api-sample/src/main/webapp/index.html @@ -123,7 +123,7 @@

PayPal REST API Samples

getauthorizationservlet" class="execute imagelink">Execute - Source @@ -133,7 +133,7 @@

PayPal REST API Samples

authorizationcaptureservlet" class="execute imagelink">Execute - Source @@ -143,7 +143,7 @@

PayPal REST API Samples

voidauthorizationservlet" class="execute imagelink">Execute - Source @@ -153,7 +153,7 @@

PayPal REST API Samples

getcaptureservlet" class="execute imagelink">Execute - Source @@ -163,7 +163,7 @@

PayPal REST API Samples

refundcaptureservlet" class="execute imagelink">Execute - Source diff --git a/rest-api-sample/src/main/webapp/source/AuthorizationCaptureServlet.html b/rest-api-sample/src/main/webapp/source/AuthorizationCaptureServlet.html new file mode 100644 index 00000000..21ef0bab --- /dev/null +++ b/rest-api-sample/src/main/webapp/source/AuthorizationCaptureServlet.html @@ -0,0 +1,186 @@ +AuthorizationCaptureServletBack

AuthorizationCapture Sample

+ +

This sample code demonstrate how you +do a Capture on an Authorization +API used: /v1/payments/authorization/{authorization_id}/capture

package com.paypal.api.payments.servlet; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; + +import com.paypal.api.payments.Address; +import com.paypal.api.payments.Amount; +import com.paypal.api.payments.Authorization; +import com.paypal.api.payments.Capture; +import com.paypal.api.payments.CreditCard; +import com.paypal.api.payments.Details; +import com.paypal.api.payments.FundingInstrument; +import com.paypal.api.payments.Payer; +import com.paypal.api.payments.Payment; +import com.paypal.api.payments.Transaction; +import com.paypal.api.payments.util.GenerateAccessToken; +import com.paypal.core.rest.APIContext; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; + +public class AuthorizationCaptureServlet extends HttpServlet { + + private static final long serialVersionUID = 1L; + + private static final Logger LOGGER = Logger + .getLogger(AuthorizationCaptureServlet.class); + + public void init(ServletConfig servletConfig) throws ServletException {

Load Configuration

+ +

Load SDK configuration for +the resource. This intialization code can be +done as Init Servlet.

InputStream is = AuthorizationCaptureServlet.class + .getResourceAsStream("/sdk_config.properties"); + try { + PayPalResource.initConfig(is); + } catch (PayPalRESTException e) { + LOGGER.fatal(e.getMessage()); + } + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + doPost(req, resp); + }

AuthorizationCapture

+ +

Sample showing how to do a Capture using Authorization

@Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException {

AccessToken

+ +

Retrieve the access token from +OAuthTokenCredential by passing in +ClientID and ClientSecret

APIContext apiContext = null; + String accessToken = null; + try { + accessToken = GenerateAccessToken.getAccessToken();

Api Context

+ +

Pass in a ApiContext object to authenticate +the call and to send a unique request id +(that ensures idempotency). The SDK generates +a request id if you do not pass one explicitly.

apiContext = new APIContext(accessToken);

Use this variant if you want to pass in a request id +that is meaningful in your application, ideally +a order id.

/* + * String requestId = Long.toString(System.nanoTime(); APIContext + * apiContext = new APIContext(accessToken, requestId )); + */

Authorization

+ +

Retrieve a Authorization object +by making a Payment with intent +as 'authorize'

Authorization authorization = getAuthorization(apiContext);

Amount

+ +

Let's you specify a capture amount.

Amount amount = new Amount(); + amount.setCurrency("USD"); + amount.setTotal("4.54");

Capture

+ +

A capture transaction

Capture capture = new Capture(); + capture.setAmount(amount); +

IsFinalCapture

+ +

If set to true, all remaining +funds held by the authorization +will be released in the funding +instrument. Default is �false�.

capture.setIsFinalCapture(true);

Capture by POSTing to +URI v1/payments/authorization/{authorization_id}/capture

Capture responseCapture = authorization.capture(apiContext, capture); + + req.setAttribute("response", Authorization.getLastResponse()); + LOGGER.info("Capture id = " + responseCapture.getId() + + " and status = " + responseCapture.getState()); + } catch (PayPalRESTException e) { + req.setAttribute("error", e.getMessage()); + } + req.setAttribute("request", Authorization.getLastRequest()); + req.getRequestDispatcher("response.jsp").forward(req, resp); + } + + private Authorization getAuthorization(APIContext apiContext) + throws PayPalRESTException {

Details

+ +

Let's you specify details of a payment amount.

Details details = new Details(); + details.setShipping("0.03"); + details.setSubtotal("107.41"); + details.setTax("0.03");

Amount

+ +

Let's you specify a payment amount.

Amount amount = new Amount(); + amount.setCurrency("USD"); + amount.setTotal("107.47"); + amount.setDetails(details);

Transaction

+ +

A transaction defines the contract of a +payment - what is the payment for and who +is fulfilling it. Transaction is created with +a Payee and Amount types

Transaction transaction = new Transaction(); + transaction.setAmount(amount); + transaction + .setDescription("This is the payment transaction description."); +

The Payment creation API requires a list of +Transaction; add the created Transaction +to a List

List<Transaction> transactions = new ArrayList<Transaction>(); + transactions.add(transaction);

Address

+ +

Base Address object used as shipping or billing +address in a payment. [Optional]

Address billingAddress = new Address(); + billingAddress.setCity("Johnstown"); + billingAddress.setCountryCode("US"); + billingAddress.setLine1("52 N Main ST"); + billingAddress.setPostalCode("43210"); + billingAddress.setState("OH");

CreditCard

+ +

A resource representing a credit card that can be +used to fund a payment.

CreditCard creditCard = new CreditCard(); + creditCard.setBillingAddress(billingAddress); + creditCard.setCvv2("874"); + creditCard.setExpireMonth(11); + creditCard.setExpireYear(2018); + creditCard.setFirstName("Joe"); + creditCard.setLastName("Shopper"); + creditCard.setNumber("4417119669820331"); + creditCard.setType("visa"); +

FundingInstrument

+ +

A resource representing a Payeer's funding instrument. +Use a Payer ID (A unique identifier of the payer generated +and provided by the facilitator. This is required when +creating or using a tokenized funding instrument) +and the CreditCardDetails

FundingInstrument fundingInstrument = new FundingInstrument(); + fundingInstrument.setCreditCard(creditCard); +

The Payment creation API requires a list of +FundingInstrument; add the created FundingInstrument +to a List

List<FundingInstrument> fundingInstruments = new ArrayList<FundingInstrument>(); + fundingInstruments.add(fundingInstrument); +

Payer

+ +

A resource representing a Payer that funds a payment +Use the List of FundingInstrument and the Payment Method +as 'credit_card'

Payer payer = new Payer(); + payer.setFundingInstruments(fundingInstruments); + payer.setPaymentMethod("credit_card");

Payment

+ +

A Payment Resource; create one using +the above types and intent as 'authorize'

Payment payment = new Payment(); + payment.setIntent("authorize"); + payment.setPayer(payer); + payment.setTransactions(transactions); + + Payment responsePayment = payment.create(apiContext); + return responsePayment.getTransactions().get(0) + .getRelatedResources().get(0).getAuthorization(); + } + +}
\ No newline at end of file diff --git a/rest-api-sample/src/main/webapp/source/CreateCreditCardServlet.html b/rest-api-sample/src/main/webapp/source/CreateCreditCardServlet.html index e3c96d5c..afb47f0c 100644 --- a/rest-api-sample/src/main/webapp/source/CreateCreditCardServlet.html +++ b/rest-api-sample/src/main/webapp/source/CreateCreditCardServlet.html @@ -59,8 +59,8 @@

A resource representing a credit card that can be used to fund a payment.

CreditCard creditCard = new CreditCard(); - creditCard.setExpireMonth("11"); - creditCard.setExpireYear("2018"); + creditCard.setExpireMonth(11); + creditCard.setExpireYear(2018); creditCard.setNumber("4417119669820331"); creditCard.setType("visa"); diff --git a/rest-api-sample/src/main/webapp/source/GetAuthorizationServlet.html b/rest-api-sample/src/main/webapp/source/GetAuthorizationServlet.html new file mode 100644 index 00000000..1aa52bd6 --- /dev/null +++ b/rest-api-sample/src/main/webapp/source/GetAuthorizationServlet.html @@ -0,0 +1,172 @@ +GetAuthorizationServletBack

GetAuthorization Sample

+ +

This sample code demonstrate how you +can retrieve the details of a Authorization +resource +API used: /v1/payments/authorization/{id}

package com.paypal.api.payments.servlet; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; + +import com.paypal.api.payments.Address; +import com.paypal.api.payments.Amount; +import com.paypal.api.payments.Authorization; +import com.paypal.api.payments.CreditCard; +import com.paypal.api.payments.Details; +import com.paypal.api.payments.FundingInstrument; +import com.paypal.api.payments.Payer; +import com.paypal.api.payments.Payment; +import com.paypal.api.payments.Transaction; +import com.paypal.api.payments.util.GenerateAccessToken; +import com.paypal.core.rest.APIContext; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; + +public class GetAuthorizationServlet extends HttpServlet { + + private static final long serialVersionUID = 1L; + + private static final Logger LOGGER = Logger + .getLogger(GetAuthorizationServlet.class); + + public void init(ServletConfig servletConfig) throws ServletException {

Load Configuration

+ +

Load SDK configuration for +the resource. This intialization code can be +done as Init Servlet.

InputStream is = GetAuthorizationServlet.class + .getResourceAsStream("/sdk_config.properties"); + try { + PayPalResource.initConfig(is); + } catch (PayPalRESTException e) { + LOGGER.fatal(e.getMessage()); + } + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + doPost(req, resp); + }

GetAuthorization

+ +

Sample showing how to do a Get Authorization +using Authorization Id

@Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException {

AccessToken

+ +

Retrieve the access token from +OAuthTokenCredential by passing in +ClientID and ClientSecret

APIContext apiContext = null; + String accessToken = null; + try { + accessToken = GenerateAccessToken.getAccessToken();

Api Context

+ +

Pass in a ApiContext object to authenticate +the call and to send a unique request id +(that ensures idempotency). The SDK generates +a request id if you do not pass one explicitly.

apiContext = new APIContext(accessToken);

Use this variant if you want to pass in a request id +that is meaningful in your application, ideally +a order id.

/* + * String requestId = Long.toString(System.nanoTime(); APIContext + * apiContext = new APIContext(accessToken, requestId )); + */

Authorization

+ +

Retrieve an Authorization Id +by making a Payment with intent +as 'authorize' and parsing through +the Payment object

String authorizationId = getAuthorizationID(apiContext);

Get Authorization by sending +a GET request with authorization Id +to the +URI v1/payments/authorization/{id}

Authorization authorization = Authorization.get(apiContext, + authorizationId); + + req.setAttribute("response", Authorization.getLastResponse()); + LOGGER.info("Authorization id = " + authorization.getId() + + " and status = " + authorization.getState()); + } catch (PayPalRESTException e) { + req.setAttribute("error", e.getMessage()); + } + req.getRequestDispatcher("response.jsp").forward(req, resp); + } + + private String getAuthorizationID(APIContext apiContext) + throws PayPalRESTException { + String authorizationID = null;

Details

+ +

Let's you specify details of a payment amount.

Details details = new Details(); + details.setShipping("0.03"); + details.setSubtotal("107.41"); + details.setTax("0.03");

Amount

+ +

Let's you specify a payment amount.

Amount amount = new Amount(); + amount.setCurrency("USD"); + amount.setTotal("107.47"); + amount.setDetails(details);

Transaction

+ +

A transaction defines the contract of a +payment - what is the payment for and who +is fulfilling it. Transaction is created with +a Payee and Amount types

Transaction transaction = new Transaction(); + transaction.setAmount(amount); + transaction + .setDescription("This is the payment transaction description.");

The Payment creation API requires a list of +Transaction; add the created Transaction +to a List

List<Transaction> transactions = new ArrayList<Transaction>(); + transactions.add(transaction);

Address

+ +

Base Address object used as shipping or billing +address in a payment. [Optional]

Address billingAddress = new Address(); + billingAddress.setCity("Johnstown"); + billingAddress.setCountryCode("US"); + billingAddress.setLine1("52 N Main ST"); + billingAddress.setPostalCode("43210"); + billingAddress.setState("OH");

CreditCard

+ +

A resource representing a credit card that can be +used to fund a payment.

CreditCard creditCard = new CreditCard(); + creditCard.setBillingAddress(billingAddress); + creditCard.setCvv2("874"); + creditCard.setExpireMonth(11); + creditCard.setExpireYear(2018); + creditCard.setFirstName("Joe"); + creditCard.setLastName("Shopper"); + creditCard.setNumber("4417119669820331"); + creditCard.setType("visa");

FundingInstrument

+ +

A resource representing a Payeer's funding instrument. +Use a Payer ID (A unique identifier of the payer generated +and provided by the facilitator. This is required when +creating or using a tokenized funding instrument) +and the CreditCardDetails

FundingInstrument fundingInstrument = new FundingInstrument(); + fundingInstrument.setCreditCard(creditCard);

The Payment creation API requires a list of +FundingInstrument; add the created FundingInstrument +to a List

List<FundingInstrument> fundingInstruments = new ArrayList<FundingInstrument>(); + fundingInstruments.add(fundingInstrument);

Payer

+ +

A resource representing a Payer that funds a payment +Use the List of FundingInstrument and the Payment Method +as 'credit_card'

Payer payer = new Payer(); + payer.setFundingInstruments(fundingInstruments); + payer.setPaymentMethod("credit_card");

Payment

+ +

A Payment Resource; create one using +the above types and intent as 'authorize'

Payment payment = new Payment(); + payment.setIntent("authorize"); + payment.setPayer(payer); + payment.setTransactions(transactions); + + Payment responsePayment = payment.create(apiContext);

Retrieve the authorization Id

authorizationID = responsePayment.getTransactions().get(0) + .getRelatedResources().get(0).getAuthorization().getId(); + return authorizationID; + } + +}
\ No newline at end of file diff --git a/rest-api-sample/src/main/webapp/source/GetCaptureServlet.html b/rest-api-sample/src/main/webapp/source/GetCaptureServlet.html new file mode 100644 index 00000000..77f37540 --- /dev/null +++ b/rest-api-sample/src/main/webapp/source/GetCaptureServlet.html @@ -0,0 +1,196 @@ +GetCaptureServletBack

GetCapture Sample

+ +

This sample code demonstrate how you +can retrieve the details of a Capture +resource +API used: /v1/payments/capture/{capture_id}

package com.paypal.api.payments.servlet; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; + +import com.paypal.api.payments.Address; +import com.paypal.api.payments.Amount; +import com.paypal.api.payments.Authorization; +import com.paypal.api.payments.Capture; +import com.paypal.api.payments.CreditCard; +import com.paypal.api.payments.Details; +import com.paypal.api.payments.FundingInstrument; +import com.paypal.api.payments.Payer; +import com.paypal.api.payments.Payment; +import com.paypal.api.payments.Transaction; +import com.paypal.api.payments.util.GenerateAccessToken; +import com.paypal.core.rest.APIContext; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; + +public class GetCaptureServlet extends HttpServlet { + + private static final long serialVersionUID = 1L; + + private static final Logger LOGGER = Logger + .getLogger(GetAuthorizationServlet.class); + + public void init(ServletConfig servletConfig) throws ServletException {

Load Configuration

+ +

Load SDK configuration for +the resource. This intialization code can be +done as Init Servlet.

InputStream is = GetCaptureServlet.class + .getResourceAsStream("/sdk_config.properties"); + try { + PayPalResource.initConfig(is); + } catch (PayPalRESTException e) { + LOGGER.fatal(e.getMessage()); + } + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + doPost(req, resp); + } +

GetCapture

+ +

Sample showing how to Get a Capture using +CaptureId

@Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException {

AccessToken

+ +

Retrieve the access token from +OAuthTokenCredential by passing in +ClientID and ClientSecret

APIContext apiContext = null; + String accessToken = null; + try { + accessToken = GenerateAccessToken.getAccessToken();

Api Context

+ +

Pass in a ApiContext object to authenticate +the call and to send a unique request id +(that ensures idempotency). The SDK generates +a request id if you do not pass one explicitly.

apiContext = new APIContext(accessToken);

Use this variant if you want to pass in a request id +that is meaningful in your application, ideally +a order id.

/* + * String requestId = Long.toString(System.nanoTime(); APIContext + * apiContext = new APIContext(accessToken, requestId )); + */

Authorization

+ +

Retrieve a Authorization object +by making a Payment with intent +as 'authorize'

Authorization authorization = getAuthorization(apiContext); + + /// ###Capture

Create a Capture object +by doing a capture on +Authorization object +and retrieve the Id

String captureId = getCaptureId(apiContext, authorization); +

Retrieve the Capture object by +doing a GET call to +URI v1/payments/capture/{capture_id}

Capture capture = Capture.get(apiContext, captureId); + + req.setAttribute("response", Capture.getLastResponse()); + LOGGER.info("Capture id = " + capture.getId() + + " and status = " + capture.getState()); + + } catch (PayPalRESTException e) { + req.setAttribute("error", e.getMessage()); + } + req.getRequestDispatcher("response.jsp").forward(req, resp); + } + + private String getCaptureId(APIContext apiContext, Authorization authorization) throws PayPalRESTException{ + String captureId = null; +

Amount

+ +

Let's you specify a capture amount.

Amount amount = new Amount(); + amount.setCurrency("USD"); + amount.setTotal("4.54");

Capture

Capture capture = new Capture(); + capture.setAmount(amount); +

IsFinalCapture

+ +

If set to true, all remaining +funds held by the authorization +will be released in the funding +instrument. Default is �false�.

capture.setIsFinalCapture(true);

Capture by POSTing to +URI v1/payments/authorization/{authorization_id}/capture

Capture responseCapture = authorization.capture(apiContext, capture); + captureId = responseCapture.getId(); + + return captureId; + } + + private Authorization getAuthorization(APIContext apiContext) + throws PayPalRESTException {

Details

+ +

Let's you specify details of a payment amount.

Details details = new Details(); + details.setShipping("0.03"); + details.setSubtotal("107.41"); + details.setTax("0.03");

Amount

+ +

Let's you specify a payment amount.

Amount amount = new Amount(); + amount.setCurrency("USD"); + amount.setTotal("107.47"); + amount.setDetails(details);

Transaction

+ +

A transaction defines the contract of a +payment - what is the payment for and who +is fulfilling it. Transaction is created with +a Payee and Amount types

Transaction transaction = new Transaction(); + transaction.setAmount(amount); + transaction + .setDescription("This is the payment transaction description.");

The Payment creation API requires a list of +Transaction; add the created Transaction +to a List

List<Transaction> transactions = new ArrayList<Transaction>(); + transactions.add(transaction);

Address

+ +

Base Address object used as shipping or billing +address in a payment. [Optional]

Address billingAddress = new Address(); + billingAddress.setCity("Johnstown"); + billingAddress.setCountryCode("US"); + billingAddress.setLine1("52 N Main ST"); + billingAddress.setPostalCode("43210"); + billingAddress.setState("OH");

CreditCard

+ +

A resource representing a credit card that can be +used to fund a payment.

CreditCard creditCard = new CreditCard(); + creditCard.setBillingAddress(billingAddress); + creditCard.setCvv2("874"); + creditCard.setExpireMonth(11); + creditCard.setExpireYear(2018); + creditCard.setFirstName("Joe"); + creditCard.setLastName("Shopper"); + creditCard.setNumber("4417119669820331"); + creditCard.setType("visa");

FundingInstrument

+ +

A resource representing a Payeer's funding instrument. +Use a Payer ID (A unique identifier of the payer generated +and provided by the facilitator. This is required when +creating or using a tokenized funding instrument) +and the CreditCardDetails

FundingInstrument fundingInstrument = new FundingInstrument(); + fundingInstrument.setCreditCard(creditCard);

The Payment creation API requires a list of +FundingInstrument; add the created FundingInstrument +to a List

List<FundingInstrument> fundingInstruments = new ArrayList<FundingInstrument>(); + fundingInstruments.add(fundingInstrument);

Payer

+ +

A resource representing a Payer that funds a payment +Use the List of FundingInstrument and the Payment Method +as 'credit_card'

Payer payer = new Payer(); + payer.setFundingInstruments(fundingInstruments); + payer.setPaymentMethod("credit_card");

Payment

+ +

A Payment Resource; create one using +the above types and intent as 'authorize'

Payment payment = new Payment(); + payment.setIntent("authorize"); + payment.setPayer(payer); + payment.setTransactions(transactions); + + Payment responsePayment = payment.create(apiContext); + return responsePayment.getTransactions().get(0).getRelatedResources() + .get(0).getAuthorization(); + } +}
\ No newline at end of file diff --git a/rest-api-sample/src/main/webapp/source/GetPaymentServlet.html b/rest-api-sample/src/main/webapp/source/GetPaymentServlet.html index 05984cc5..89bf9b33 100644 --- a/rest-api-sample/src/main/webapp/source/GetPaymentServlet.html +++ b/rest-api-sample/src/main/webapp/source/GetPaymentServlet.html @@ -50,7 +50,7 @@ throws ServletException, IOException { doPost(req, resp); - }

GetPaymentByPaymentId

+ }

GetPayment

Call the method with a valid Payment ID

@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) diff --git a/rest-api-sample/src/main/webapp/source/PaymentWithCreditCardServlet.html b/rest-api-sample/src/main/webapp/source/PaymentWithCreditCardServlet.html index 66626a44..62085834 100644 --- a/rest-api-sample/src/main/webapp/source/PaymentWithCreditCardServlet.html +++ b/rest-api-sample/src/main/webapp/source/PaymentWithCreditCardServlet.html @@ -64,21 +64,21 @@ used to fund a payment.

CreditCard creditCard = new CreditCard(); creditCard.setBillingAddress(billingAddress); creditCard.setCvv2("874"); - creditCard.setExpireMonth("11"); - creditCard.setExpireYear("2018"); + creditCard.setExpireMonth(11); + creditCard.setExpireYear(2018); creditCard.setFirstName("Joe"); creditCard.setLastName("Shopper"); creditCard.setNumber("4417119669820331"); - creditCard.setType("visa");

AmountDetails

+ creditCard.setType("visa");

Details

-

Let's you specify details of a payment amount.

AmountDetails amountDetails = new AmountDetails(); - amountDetails.setShipping("1"); - amountDetails.setSubtotal("5"); - amountDetails.setTax("1");

Amount

+

Let's you specify details of a payment amount.

Details details = new Details(); + details.setShipping("1"); + details.setSubtotal("5"); + details.setTax("1");

Amount

Let's you specify a payment amount.

Amount amount = new Amount(); amount.setCurrency("USD");

Total must be equal to sum of shipping, tax and subtotal.

amount.setTotal("7"); - amount.setDetails(amountDetails);

Transaction

+ amount.setDetails(details);

Transaction

A transaction defines the contract of a payment - what is the payment for and who diff --git a/rest-api-sample/src/main/webapp/source/PaymentWithPayPalServlet.html b/rest-api-sample/src/main/webapp/source/PaymentWithPayPalServlet.html index c45e9725..8b428a7a 100644 --- a/rest-api-sample/src/main/webapp/source/PaymentWithPayPalServlet.html +++ b/rest-api-sample/src/main/webapp/source/PaymentWithPayPalServlet.html @@ -6,16 +6,33 @@ import java.io.IOException; import java.io.InputStream; -import java.util.*; - -import javax.servlet.*; -import javax.servlet.http.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; -import com.paypal.api.payments.*; -import com.paypal.api.payments.util.*; -import com.paypal.core.rest.*; +import com.paypal.api.payments.Amount; +import com.paypal.api.payments.Details; +import com.paypal.api.payments.Links; +import com.paypal.api.payments.Payer; +import com.paypal.api.payments.Payment; +import com.paypal.api.payments.PaymentExecution; +import com.paypal.api.payments.RedirectUrls; +import com.paypal.api.payments.Transaction; +import com.paypal.api.payments.util.GenerateAccessToken; +import com.paypal.core.rest.APIContext; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; /** * @author lvairamani @@ -60,14 +77,14 @@ try { accessToken = GenerateAccessToken.getAccessToken();

Api Context

-

Pass in a ApiContext object to authenticate -the call and to send a unique request id +

Pass in a ApiContext object to authenticate +the call and to send a unique request id (that ensures idempotency). The SDK generates -a request id if you do not pass one explicitly.

apiContext = new APIContext(accessToken);

Use this variant if you want to pass in a request id
-that is meaningful in your application, ideally -a order id.

/* - * String requestId = Long.toString(System.nanoTime(); - * APIContext apiContext = new APIContext(accessToken, requestId )); +a request id if you do not pass one explicitly.

apiContext = new APIContext(accessToken);

Use this variant if you want to pass in a request id +that is meaningful in your application, ideally +a order id.

/* + * String requestId = Long.toString(System.nanoTime(); APIContext + * apiContext = new APIContext(accessToken, requestId )); */ } catch (PayPalRESTException e) { req.setAttribute("error", e.getMessage()); @@ -86,16 +103,16 @@ } catch (PayPalRESTException e) { req.setAttribute("error", e.getMessage()); } - } else {

AmountDetails

+ } else {

Details

-

Let's you specify details of a payment amount.

AmountDetails amountDetails = new AmountDetails(); - amountDetails.setShipping("1"); - amountDetails.setSubtotal("5"); - amountDetails.setTax("1");

Amount

+

Let's you specify details of a payment amount.

Details details = new Details(); + details.setShipping("1"); + details.setSubtotal("5"); + details.setTax("1");

Amount

Let's you specify a payment amount.

Amount amount = new Amount(); amount.setCurrency("USD");

Total must be equal to sum of shipping, tax and subtotal.

amount.setTotal("7"); - amount.setDetails(amountDetails);

Transaction

+ amount.setDetails(details);

Transaction

A transaction defines the contract of a payment - what is the payment for and who @@ -131,9 +148,9 @@ Payment createdPayment = payment.create(apiContext); LOGGER.info("Created payment with id = " + createdPayment.getId() + " and status = " - + createdPayment.getState());

Payment Approval Url

Iterator<Link> links = createdPayment.getLinks().iterator(); + + createdPayment.getState());

Payment Approval Url

Iterator<Links> links = createdPayment.getLinks().iterator(); while (links.hasNext()) { - Link link = links.next(); + Links link = links.next(); if (link.getRel().equalsIgnoreCase("approval_url")) { req.setAttribute("redirectURL", link.getHref()); } diff --git a/rest-api-sample/src/main/webapp/source/PaymentWithSavedCardServlet.html b/rest-api-sample/src/main/webapp/source/PaymentWithSavedCardServlet.html index 32dd0882..484680ee 100644 --- a/rest-api-sample/src/main/webapp/source/PaymentWithSavedCardServlet.html +++ b/rest-api-sample/src/main/webapp/source/PaymentWithSavedCardServlet.html @@ -56,16 +56,16 @@

A resource representing a credit card that can be used to fund a payment.

CreditCardToken creditCardToken = new CreditCardToken(); - creditCardToken.setCreditCardId("CARD-5BT058015C739554AKE2GCEI");

AmountDetails

+ creditCardToken.setCreditCardId("CARD-5BT058015C739554AKE2GCEI");

Details

-

Let's you specify details of a payment amount.

AmountDetails amountDetails = new AmountDetails(); - amountDetails.setShipping("1"); - amountDetails.setSubtotal("5"); - amountDetails.setTax("1");

Amount

+

Let's you specify details of a payment amount.

Details details = new Details(); + details.setShipping("1"); + details.setSubtotal("5"); + details.setTax("1");

Amount

Let's you specify a payment amount.

Amount amount = new Amount(); amount.setCurrency("USD");

Total must be equal to the sum of shipping, tax and subtotal.

amount.setTotal("7"); - amount.setDetails(amountDetails);

Transaction

+ amount.setDetails(details);

Transaction

A transaction defines the contract of a payment - what is the payment for and who diff --git a/rest-api-sample/src/main/webapp/source/RefundCaptureServlet.html b/rest-api-sample/src/main/webapp/source/RefundCaptureServlet.html new file mode 100644 index 00000000..624d1b1d --- /dev/null +++ b/rest-api-sample/src/main/webapp/source/RefundCaptureServlet.html @@ -0,0 +1,204 @@ +RefundCaptureServletBack

RefundCapture Sample

+ +

This sample code demonstrate how you +can do a Refund on a Capture +resource +API used: /v1/payments/capture/{capture_id}/refund

package com.paypal.api.payments.servlet; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; + +import com.paypal.api.payments.Address; +import com.paypal.api.payments.Amount; +import com.paypal.api.payments.Authorization; +import com.paypal.api.payments.Capture; +import com.paypal.api.payments.CreditCard; +import com.paypal.api.payments.Details; +import com.paypal.api.payments.FundingInstrument; +import com.paypal.api.payments.Payer; +import com.paypal.api.payments.Payment; +import com.paypal.api.payments.Refund; +import com.paypal.api.payments.Transaction; +import com.paypal.api.payments.util.GenerateAccessToken; +import com.paypal.core.rest.APIContext; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; + +public class RefundCaptureServlet extends HttpServlet { + + private static final long serialVersionUID = 1L; + + private static final Logger LOGGER = Logger + .getLogger(GetAuthorizationServlet.class); + + public void init(ServletConfig servletConfig) throws ServletException {

Load Configuration

+ +

Load SDK configuration for +the resource. This intialization code can be +done as Init Servlet.

InputStream is = RefundCaptureServlet.class + .getResourceAsStream("/sdk_config.properties"); + try { + PayPalResource.initConfig(is); + } catch (PayPalRESTException e) { + LOGGER.fatal(e.getMessage()); + } + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + doPost(req, resp); + } +

RefundCapture

+ +

Sample showing to how to do a Refund on +a Capture

@Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException {

AccessToken

+ +

Retrieve the access token from +OAuthTokenCredential by passing in +ClientID and ClientSecret

APIContext apiContext = null; + String accessToken = null; + try { + accessToken = GenerateAccessToken.getAccessToken();

Api Context

+ +

Pass in a ApiContext object to authenticate +the call and to send a unique request id +(that ensures idempotency). The SDK generates +a request id if you do not pass one explicitly.

apiContext = new APIContext(accessToken);

Use this variant if you want to pass in a request id +that is meaningful in your application, ideally +a order id.

/* + * String requestId = Long.toString(System.nanoTime(); APIContext + * apiContext = new APIContext(accessToken, requestId )); + */

Authorization

+ +

Retrieve a Authorization object +by making a Payment with intent +as 'authorize'

Authorization authorization = getAuthorization(apiContext); + + /// ###Capture

Create a Capture object +by doing a capture on +Authorization object

Capture capture = getCapture(apiContext, authorization); + + /// ###Refund + /// Create a Refund object + Refund refund = new Refund(); +

Amount

+ +

Let's you specify a capture amount.

Amount amount = new Amount(); + amount.setCurrency("USD").setTotal("1"); + + refund.setAmount(amount); +

Create new APIContext for +Refund

apiContext = new APIContext(accessToken);

Do a Refund by +POSTing to +URI v1/payments/capture/{capture_id}/refund

Refund responseRefund = capture.refund(apiContext, refund); + + req.setAttribute("response", Capture.getLastResponse()); + LOGGER.info("Refund id = " + responseRefund.getId() + + " and status = " + responseRefund.getState()); + + } catch (PayPalRESTException e) { + req.setAttribute("error", e.getMessage()); + } + req.setAttribute("request", Capture.getLastRequest()); + req.getRequestDispatcher("response.jsp").forward(req, resp); + } + + private Capture getCapture(APIContext apiContext, Authorization authorization) throws PayPalRESTException{

Amount

+ +

Let's you specify a capture amount.

Amount amount = new Amount(); + amount.setCurrency("USD"); + amount.setTotal("4.54");

Capture

Capture capture = new Capture(); + capture.setAmount(amount); +

IsFinalCapture

+ +

If set to true, all remaining +funds held by the authorization +will be released in the funding +instrument. Default is �false�.

capture.setIsFinalCapture(true);

Capture by POSTing to +URI v1/payments/authorization/{authorization_id}/capture

Capture responseCapture = authorization.capture(apiContext, capture); + return responseCapture; + } + + private Authorization getAuthorization(APIContext apiContext) + throws PayPalRESTException {

Details

+ +

Let's you specify details of a payment amount.

Details details = new Details(); + details.setShipping("0.03"); + details.setSubtotal("107.41"); + details.setTax("0.03");

Amount

+ +

Let's you specify a payment amount.

Amount amount = new Amount(); + amount.setCurrency("USD"); + amount.setTotal("107.47"); + amount.setDetails(details);

Transaction

+ +

A transaction defines the contract of a +payment - what is the payment for and who +is fulfilling it. Transaction is created with +a Payee and Amount types

Transaction transaction = new Transaction(); + transaction.setAmount(amount); + transaction + .setDescription("This is the payment transaction description.");

The Payment creation API requires a list of +Transaction; add the created Transaction +to a List

List<Transaction> transactions = new ArrayList<Transaction>(); + transactions.add(transaction);

Address

+ +

Base Address object used as shipping or billing +address in a payment. [Optional]

Address billingAddress = new Address(); + billingAddress.setCity("Johnstown"); + billingAddress.setCountryCode("US"); + billingAddress.setLine1("52 N Main ST"); + billingAddress.setPostalCode("43210"); + billingAddress.setState("OH");

CreditCard

+ +

A resource representing a credit card that can be +used to fund a payment.

CreditCard creditCard = new CreditCard(); + creditCard.setBillingAddress(billingAddress); + creditCard.setCvv2("874"); + creditCard.setExpireMonth(11); + creditCard.setExpireYear(2018); + creditCard.setFirstName("Joe"); + creditCard.setLastName("Shopper"); + creditCard.setNumber("4417119669820331"); + creditCard.setType("visa");

FundingInstrument

+ +

A resource representing a Payeer's funding instrument. +Use a Payer ID (A unique identifier of the payer generated +and provided by the facilitator. This is required when +creating or using a tokenized funding instrument) +and the CreditCardDetails

FundingInstrument fundingInstrument = new FundingInstrument(); + fundingInstrument.setCreditCard(creditCard);

The Payment creation API requires a list of +FundingInstrument; add the created FundingInstrument +to a List

List<FundingInstrument> fundingInstruments = new ArrayList<FundingInstrument>(); + fundingInstruments.add(fundingInstrument);

Payer

+ +

A resource representing a Payer that funds a payment +Use the List of FundingInstrument and the Payment Method +as 'credit_card'

Payer payer = new Payer(); + payer.setFundingInstruments(fundingInstruments); + payer.setPaymentMethod("credit_card");

Payment

+ +

A Payment Resource; create one using +the above types and intent as 'authorize'

Payment payment = new Payment(); + payment.setIntent("authorize"); + payment.setPayer(payer); + payment.setTransactions(transactions); + + Payment responsePayment = payment.create(apiContext); + return responsePayment.getTransactions().get(0).getRelatedResources() + .get(0).getAuthorization(); + } +}
\ No newline at end of file diff --git a/rest-api-sample/src/main/webapp/source/VoidAuthorizationServlet.html b/rest-api-sample/src/main/webapp/source/VoidAuthorizationServlet.html new file mode 100644 index 00000000..17288666 --- /dev/null +++ b/rest-api-sample/src/main/webapp/source/VoidAuthorizationServlet.html @@ -0,0 +1,175 @@ +VoidAuthorizationServletBack

VoidAuthorization Sample

+ +

This sample code demonstrate how you +can do a Void on a Authorization +resource +API used: /v1/payments/authorization/{authorization_id}/void

package com.paypal.api.payments.servlet; + +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; + +import com.paypal.api.payments.Address; +import com.paypal.api.payments.Amount; +import com.paypal.api.payments.Authorization; +import com.paypal.api.payments.CreditCard; +import com.paypal.api.payments.Details; +import com.paypal.api.payments.FundingInstrument; +import com.paypal.api.payments.Payer; +import com.paypal.api.payments.Payment; +import com.paypal.api.payments.Transaction; +import com.paypal.api.payments.util.GenerateAccessToken; +import com.paypal.core.rest.APIContext; +import com.paypal.core.rest.PayPalRESTException; +import com.paypal.core.rest.PayPalResource; + +public class VoidAuthorizationServlet extends HttpServlet { + + private static final long serialVersionUID = 1L; + + private static final Logger LOGGER = Logger + .getLogger(VoidAuthorizationServlet.class); + Map<String, String> map = new HashMap<String, String>(); + + public void init(ServletConfig servletConfig) throws ServletException {

Load Configuration

+ +

Load SDK configuration for +the resource. This intialization code can be +done as Init Servlet.

InputStream is = VoidAuthorizationServlet.class + .getResourceAsStream("/sdk_config.properties"); + try { + PayPalResource.initConfig(is); + } catch (PayPalRESTException e) { + LOGGER.fatal(e.getMessage()); + } + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + doPost(req, resp); + } +

VoidAuthorization

+ +

Sample showing how to void an Authorization

@Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException {

AccessToken

+ +

Retrieve the access token from +OAuthTokenCredential by passing in +ClientID and ClientSecret

APIContext apiContext = null; + String accessToken = null; + try { + accessToken = GenerateAccessToken.getAccessToken();

Api Context

+ +

Pass in a ApiContext object to authenticate +the call and to send a unique request id +(that ensures idempotency). The SDK generates +a request id if you do not pass one explicitly.

apiContext = new APIContext(accessToken);

Use this variant if you want to pass in a request id +that is meaningful in your application, ideally +a order id.

/* + * String requestId = Long.toString(System.nanoTime(); APIContext + * apiContext = new APIContext(accessToken, requestId )); + */

Authorization

+ +

Retrieve a Authorization object +by making a Payment with intent +as 'authorize'

Authorization authorization = getAuthorization(apiContext);

Void an Authorization +by POSTing to +URI v1/payments/authorization/{authorization_id}/void

Authorization returnAuthorization = authorization.doVoid(apiContext); + + req.setAttribute("response", Authorization.getLastResponse()); + LOGGER.info("Authorization id = " + returnAuthorization.getId() + + " and status = " + returnAuthorization.getState()); + } catch (PayPalRESTException e) { + req.setAttribute("error", e.getMessage()); + } + req.getRequestDispatcher("response.jsp").forward(req, resp); + } + + private Authorization getAuthorization(APIContext apiContext) + throws PayPalRESTException {

Details

+ +

Let's you specify details of a payment amount.

Details details = new Details(); + details.setShipping("0.03"); + details.setSubtotal("107.41"); + details.setTax("0.03");

Amount

+ +

Let's you specify a payment amount.

Amount amount = new Amount(); + amount.setCurrency("USD"); + amount.setTotal("107.47"); + amount.setDetails(details);

Transaction

+ +

A transaction defines the contract of a +payment - what is the payment for and who +is fulfilling it. Transaction is created with +a Payee and Amount types

Transaction transaction = new Transaction(); + transaction.setAmount(amount); + transaction + .setDescription("This is the payment transaction description."); +

The Payment creation API requires a list of +Transaction; add the created Transaction +to a List

List<Transaction> transactions = new ArrayList<Transaction>(); + transactions.add(transaction);

Address

+ +

Base Address object used as shipping or billing +address in a payment. [Optional]

Address billingAddress = new Address(); + billingAddress.setCity("Johnstown"); + billingAddress.setCountryCode("US"); + billingAddress.setLine1("52 N Main ST"); + billingAddress.setPostalCode("43210"); + billingAddress.setState("OH");

CreditCard

+ +

A resource representing a credit card that can be +used to fund a payment.

CreditCard creditCard = new CreditCard(); + creditCard.setBillingAddress(billingAddress); + creditCard.setCvv2("874"); + creditCard.setExpireMonth(11); + creditCard.setExpireYear(2018); + creditCard.setFirstName("Joe"); + creditCard.setLastName("Shopper"); + creditCard.setNumber("4417119669820331"); + creditCard.setType("visa"); +

FundingInstrument

+ +

A resource representing a Payeer's funding instrument. +Use a Payer ID (A unique identifier of the payer generated +and provided by the facilitator. This is required when +creating or using a tokenized funding instrument) +and the CreditCardDetails

FundingInstrument fundingInstrument = new FundingInstrument(); + fundingInstrument.setCreditCard(creditCard); +

The Payment creation API requires a list of +FundingInstrument; add the created FundingInstrument +to a List

List<FundingInstrument> fundingInstruments = new ArrayList<FundingInstrument>(); + fundingInstruments.add(fundingInstrument); +

Payer

+ +

A resource representing a Payer that funds a payment +Use the List of FundingInstrument and the Payment Method +as 'credit_card'

Payer payer = new Payer(); + payer.setFundingInstruments(fundingInstruments); + payer.setPaymentMethod("credit_card");

Payment

+ +

A Payment Resource; create one using +the above types and intent as 'authorize'

Payment payment = new Payment(); + payment.setIntent("authorize"); + payment.setPayer(payer); + payment.setTransactions(transactions); + + Payment responsePayment = payment.create(apiContext); + return responsePayment.getTransactions().get(0) + .getRelatedResources().get(0).getAuthorization(); + } + +}
\ No newline at end of file diff --git a/rest-api-sample/src/main/webapp/source/assets/behavior.js b/rest-api-sample/src/main/webapp/source/assets/behavior.js index 72a35a89..9f0ab493 100644 --- a/rest-api-sample/src/main/webapp/source/assets/behavior.js +++ b/rest-api-sample/src/main/webapp/source/assets/behavior.js @@ -6,6 +6,158 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 tableOfContents = [ { + "type": "file", + "data": { + "language": { + "nameMatchers": [".java"], + "pygmentsLexer": "java", + "singleLineComment": ["//"], + "name": "Java" + }, + "sourcePath": "c:\\repos\\git-paypal\\groc\\sample-code\\AuthorizationCaptureServlet.java", + "projectPath": "AuthorizationCaptureServlet.java", + "targetPath": "AuthorizationCaptureServlet", + "title": "AuthorizationCaptureServlet" + }, + "depth": 1, + "outline": [ + { + "type": "heading", + "data": { + "level": 2, + "title": "Load Configuration", + "slug": "load-configuration" + }, + "depth": 2 + }, { + "type": "heading", + "data": { + "level": 2, + "title": "AuthorizationCapture", + "slug": "authorizationcapture" + }, + "depth": 2, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "AccessToken", + "slug": "accesstoken" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Api Context", + "slug": "api-context" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Authorization", + "slug": "authorization" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Amount", + "slug": "amount" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Capture", + "slug": "capture" + }, + "depth": 3 + } + ] + }, { + "type": "heading", + "data": { + "level": 2, + "title": "IsFinalCapture", + "slug": "isfinalcapture" + }, + "depth": 2, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Details", + "slug": "details" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Amount", + "slug": "amount" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Transaction", + "slug": "transaction" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Address", + "slug": "address" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "CreditCard", + "slug": "creditcard" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "FundingInstrument", + "slug": "fundinginstrument" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Payer", + "slug": "payer" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Payment", + "slug": "payment" + }, + "depth": 3 + } + ] + } + ] + }, { "type": "file", "data": { "language": { @@ -74,6 +226,283 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 ] } ] + }, { + "type": "file", + "data": { + "language": { + "nameMatchers": [".java"], + "pygmentsLexer": "java", + "singleLineComment": ["//"], + "name": "Java" + }, + "sourcePath": "c:\\repos\\git-paypal\\groc\\sample-code\\GetAuthorizationServlet.java", + "projectPath": "GetAuthorizationServlet.java", + "targetPath": "GetAuthorizationServlet", + "title": "GetAuthorizationServlet" + }, + "depth": 1, + "outline": [ + { + "type": "heading", + "data": { + "level": 2, + "title": "Load Configuration", + "slug": "load-configuration" + }, + "depth": 2 + }, { + "type": "heading", + "data": { + "level": 2, + "title": "GetAuthorization", + "slug": "getauthorization" + }, + "depth": 2, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "AccessToken", + "slug": "accesstoken" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Api Context", + "slug": "api-context" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Authorization", + "slug": "authorization" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Details", + "slug": "details" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Amount", + "slug": "amount" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Transaction", + "slug": "transaction" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Address", + "slug": "address" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "CreditCard", + "slug": "creditcard" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "FundingInstrument", + "slug": "fundinginstrument" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Payer", + "slug": "payer" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Payment", + "slug": "payment" + }, + "depth": 3 + } + ] + } + ] + }, { + "type": "file", + "data": { + "language": { + "nameMatchers": [".java"], + "pygmentsLexer": "java", + "singleLineComment": ["//"], + "name": "Java" + }, + "sourcePath": "c:\\repos\\git-paypal\\groc\\sample-code\\GetCaptureServlet.java", + "projectPath": "GetCaptureServlet.java", + "targetPath": "GetCaptureServlet", + "title": "GetCaptureServlet" + }, + "depth": 1, + "outline": [ + { + "type": "heading", + "data": { + "level": 2, + "title": "Load Configuration", + "slug": "load-configuration" + }, + "depth": 2 + }, { + "type": "heading", + "data": { + "level": 2, + "title": "GetCapture", + "slug": "getcapture" + }, + "depth": 2, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "AccessToken", + "slug": "accesstoken" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Api Context", + "slug": "api-context" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Authorization", + "slug": "authorization" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Amount", + "slug": "amount" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Capture", + "slug": "capture" + }, + "depth": 3 + } + ] + }, { + "type": "heading", + "data": { + "level": 2, + "title": "IsFinalCapture", + "slug": "isfinalcapture" + }, + "depth": 2, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Details", + "slug": "details" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Amount", + "slug": "amount" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Transaction", + "slug": "transaction" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Address", + "slug": "address" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "CreditCard", + "slug": "creditcard" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "FundingInstrument", + "slug": "fundinginstrument" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Payer", + "slug": "payer" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Payment", + "slug": "payment" + }, + "depth": 3 + } + ] + } + ] }, { "type": "file", "data": { @@ -192,8 +621,8 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "type": "heading", "data": { "level": 2, - "title": "GetPaymentByPaymentId", - "slug": "getpaymentbypaymentid" + "title": "GetPayment", + "slug": "getpayment" }, "depth": 2, "children": [ @@ -263,10 +692,127 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "singleLineComment": ["//"], "name": "Java" }, - "sourcePath": "c:\\repos\\git-paypal\\groc\\sample-code\\PaymentWithCreditCardServlet.java", - "projectPath": "PaymentWithCreditCardServlet.java", - "targetPath": "PaymentWithCreditCardServlet", - "title": "PaymentWithCreditCardServlet" + "sourcePath": "c:\\repos\\git-paypal\\groc\\sample-code\\PaymentWithCreditCardServlet.java", + "projectPath": "PaymentWithCreditCardServlet.java", + "targetPath": "PaymentWithCreditCardServlet", + "title": "PaymentWithCreditCardServlet" + }, + "depth": 1, + "outline": [ + { + "type": "heading", + "data": { + "level": 2, + "title": "Load Configuration", + "slug": "load-configuration" + }, + "depth": 2 + }, { + "type": "heading", + "data": { + "level": 2, + "title": "Create", + "slug": "create" + }, + "depth": 2, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Address", + "slug": "address" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "CreditCard", + "slug": "creditcard" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Details", + "slug": "details" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Amount", + "slug": "amount" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Transaction", + "slug": "transaction" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "FundingInstrument", + "slug": "fundinginstrument" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Payer", + "slug": "payer" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Payment", + "slug": "payment" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "AccessToken", + "slug": "accesstoken" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Api Context", + "slug": "api-context" + }, + "depth": 3 + } + ] + } + ] + }, { + "type": "file", + "data": { + "language": { + "nameMatchers": [".java"], + "pygmentsLexer": "java", + "singleLineComment": ["//"], + "name": "Java" + }, + "sourcePath": "c:\\repos\\git-paypal\\groc\\sample-code\\PaymentWithPayPalServlet.java", + "projectPath": "PaymentWithPayPalServlet.java", + "targetPath": "PaymentWithPayPalServlet", + "title": "PaymentWithPayPalServlet" }, "depth": 1, "outline": [ @@ -291,24 +837,24 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "type": "heading", "data": { "level": 3, - "title": "Address", - "slug": "address" + "title": "AccessToken", + "slug": "accesstoken" }, "depth": 3 }, { "type": "heading", "data": { "level": 3, - "title": "CreditCard", - "slug": "creditcard" + "title": "Api Context", + "slug": "api-context" }, "depth": 3 }, { "type": "heading", "data": { "level": 3, - "title": "AmountDetails", - "slug": "amountdetails" + "title": "Details", + "slug": "details" }, "depth": 3 }, { @@ -327,14 +873,6 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "slug": "transaction" }, "depth": 3 - }, { - "type": "heading", - "data": { - "level": 3, - "title": "FundingInstrument", - "slug": "fundinginstrument" - }, - "depth": 3 }, { "type": "heading", "data": { @@ -355,16 +893,16 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "type": "heading", "data": { "level": 3, - "title": "AccessToken", - "slug": "accesstoken" + "title": "Redirect URLs", + "slug": "redirect-urls" }, "depth": 3 }, { "type": "heading", "data": { "level": 3, - "title": "Api Context", - "slug": "api-context" + "title": "Payment Approval Url", + "slug": "payment-approval-url" }, "depth": 3 } @@ -380,10 +918,10 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "singleLineComment": ["//"], "name": "Java" }, - "sourcePath": "c:\\repos\\git-paypal\\groc\\sample-code\\PaymentWithPayPalServlet.java", - "projectPath": "PaymentWithPayPalServlet.java", - "targetPath": "PaymentWithPayPalServlet", - "title": "PaymentWithPayPalServlet" + "sourcePath": "c:\\repos\\git-paypal\\groc\\sample-code\\PaymentWithSavedCardServlet.java", + "projectPath": "PaymentWithSavedCardServlet.java", + "targetPath": "PaymentWithSavedCardServlet", + "title": "PaymentWithSavedCardServlet" }, "depth": 1, "outline": [ @@ -408,40 +946,40 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "type": "heading", "data": { "level": 3, - "title": "AccessToken", - "slug": "accesstoken" + "title": "CreditCard", + "slug": "creditcard" }, "depth": 3 }, { "type": "heading", "data": { "level": 3, - "title": "Api Context", - "slug": "api-context" + "title": "Details", + "slug": "details" }, "depth": 3 }, { "type": "heading", "data": { "level": 3, - "title": "AmountDetails", - "slug": "amountdetails" + "title": "Amount", + "slug": "amount" }, "depth": 3 }, { "type": "heading", "data": { "level": 3, - "title": "Amount", - "slug": "amount" + "title": "Transaction", + "slug": "transaction" }, "depth": 3 }, { "type": "heading", "data": { "level": 3, - "title": "Transaction", - "slug": "transaction" + "title": "FundingInstrument", + "slug": "fundinginstrument" }, "depth": 3 }, { @@ -464,16 +1002,16 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "type": "heading", "data": { "level": 3, - "title": "Redirect URLs", - "slug": "redirect-urls" + "title": "AccessToken", + "slug": "accesstoken" }, "depth": 3 }, { "type": "heading", "data": { "level": 3, - "title": "Payment Approval Url", - "slug": "payment-approval-url" + "title": "APIContext", + "slug": "apicontext" }, "depth": 3 } @@ -489,10 +1027,10 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "singleLineComment": ["//"], "name": "Java" }, - "sourcePath": "c:\\repos\\git-paypal\\groc\\sample-code\\PaymentWithSavedCardServlet.java", - "projectPath": "PaymentWithSavedCardServlet.java", - "targetPath": "PaymentWithSavedCardServlet", - "title": "PaymentWithSavedCardServlet" + "sourcePath": "c:\\repos\\git-paypal\\groc\\sample-code\\RefundCaptureServlet.java", + "projectPath": "RefundCaptureServlet.java", + "targetPath": "RefundCaptureServlet", + "title": "RefundCaptureServlet" }, "depth": 1, "outline": [ @@ -508,8 +1046,8 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "type": "heading", "data": { "level": 2, - "title": "Create", - "slug": "create" + "title": "RefundCapture", + "slug": "refundcapture" }, "depth": 2, "children": [ @@ -517,16 +1055,67 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "type": "heading", "data": { "level": 3, - "title": "CreditCard", - "slug": "creditcard" + "title": "AccessToken", + "slug": "accesstoken" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Api Context", + "slug": "api-context" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Authorization", + "slug": "authorization" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Amount", + "slug": "amount" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Amount", + "slug": "amount" }, "depth": 3 }, { "type": "heading", "data": { "level": 3, - "title": "AmountDetails", - "slug": "amountdetails" + "title": "Capture", + "slug": "capture" + }, + "depth": 3 + } + ] + }, { + "type": "heading", + "data": { + "level": 2, + "title": "IsFinalCapture", + "slug": "isfinalcapture" + }, + "depth": 2, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "Details", + "slug": "details" }, "depth": 3 }, { @@ -549,40 +1138,40 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 "type": "heading", "data": { "level": 3, - "title": "FundingInstrument", - "slug": "fundinginstrument" + "title": "Address", + "slug": "address" }, "depth": 3 }, { "type": "heading", "data": { "level": 3, - "title": "Payer", - "slug": "payer" + "title": "CreditCard", + "slug": "creditcard" }, "depth": 3 }, { "type": "heading", "data": { "level": 3, - "title": "Payment", - "slug": "payment" + "title": "FundingInstrument", + "slug": "fundinginstrument" }, "depth": 3 }, { "type": "heading", "data": { "level": 3, - "title": "AccessToken", - "slug": "accesstoken" + "title": "Payer", + "slug": "payer" }, "depth": 3 }, { "type": "heading", "data": { "level": 3, - "title": "APIContext", - "slug": "apicontext" + "title": "Payment", + "slug": "payment" }, "depth": 3 } @@ -666,6 +1255,131 @@ f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3 ] } ] + }, { + "type": "file", + "data": { + "language": { + "nameMatchers": [".java"], + "pygmentsLexer": "java", + "singleLineComment": ["//"], + "name": "Java" + }, + "sourcePath": "c:\\repos\\git-paypal\\groc\\sample-code\\VoidAuthorizationServlet.java", + "projectPath": "VoidAuthorizationServlet.java", + "targetPath": "VoidAuthorizationServlet", + "title": "VoidAuthorizationServlet" + }, + "depth": 1, + "outline": [ + { + "type": "heading", + "data": { + "level": 2, + "title": "Load Configuration", + "slug": "load-configuration" + }, + "depth": 2 + }, { + "type": "heading", + "data": { + "level": 2, + "title": "VoidAuthorization", + "slug": "voidauthorization" + }, + "depth": 2, + "children": [ + { + "type": "heading", + "data": { + "level": 3, + "title": "AccessToken", + "slug": "accesstoken" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Api Context", + "slug": "api-context" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Authorization", + "slug": "authorization" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Details", + "slug": "details" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Amount", + "slug": "amount" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Transaction", + "slug": "transaction" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Address", + "slug": "address" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "CreditCard", + "slug": "creditcard" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "FundingInstrument", + "slug": "fundinginstrument" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Payer", + "slug": "payer" + }, + "depth": 3 + }, { + "type": "heading", + "data": { + "level": 3, + "title": "Payment", + "slug": "payment" + }, + "depth": 3 + } + ] + } + ] } ]; diff --git a/rest-api-sdk/pom.xml b/rest-api-sdk/pom.xml index b0188de6..3c93c581 100644 --- a/rest-api-sdk/pom.xml +++ b/rest-api-sdk/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.paypal.sdk rest-api-sdk - 0.6.0 + 0.7.0 jar REST API SDK PayPal SDK for integrating with the REST APIs From 2ca4e5bbe70f59e7cb1e97d41677a769c25e3573 Mon Sep 17 00:00:00 2001 From: Prasanna Annamalai Date: Thu, 30 May 2013 16:01:18 +0530 Subject: [PATCH 27/30] Updated version number [ci skip] --- CHANGELOG.md | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fd790f6..c8f7680b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,13 +1,16 @@ CHANGELOG ========= - -V0.5.2 (March 07, 2013) +V0.7.0 (May 30, 2013) ----------------------- - - * Initial Release + * Added support for Auth and Capture APIs + * Types Modified to match the API Spec V0.6.0 (April 26, 2013) ----------------------- - * Added dynamic configuration support for API calls +V0.5.2 (March 07, 2013) +----------------------- + * Initial Release + + From e7da7f7d72ce9d470301c60a52a329ea8205c7ad Mon Sep 17 00:00:00 2001 From: Prasanna Annamalai Date: Thu, 30 May 2013 16:07:41 +0530 Subject: [PATCH 28/30] Updated README [ci skip] --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bd83dffd..18f4313f 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ SDK Integration: com.paypal.sdk rest-api-sdk - 0.5.2 + 0.7.0 From 4bc5eb2b033b24f95ff5078037f5be381c1e338e Mon Sep 17 00:00:00 2001 From: Prasanna Annamalai Date: Wed, 5 Jun 2013 13:58:57 +0530 Subject: [PATCH 29/30] changed testng scope to test --- rest-api-sdk/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/rest-api-sdk/pom.xml b/rest-api-sdk/pom.xml index 3c93c581..a604452a 100644 --- a/rest-api-sdk/pom.xml +++ b/rest-api-sdk/pom.xml @@ -32,6 +32,7 @@ org.testng testng 6.3.1 + test com.paypal.sdk From 8549cc69039aca0152f63c0dc21bdd2c6a350731 Mon Sep 17 00:00:00 2001 From: aydiv Date: Thu, 18 Jul 2013 17:07:22 +0530 Subject: [PATCH 30/30] pom.xml changes for jenkins/cobertura integration --- rest-api-sdk/pom.xml | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/rest-api-sdk/pom.xml b/rest-api-sdk/pom.xml index a604452a..fd1df0bf 100644 --- a/rest-api-sdk/pom.xml +++ b/rest-api-sdk/pom.xml @@ -94,6 +94,12 @@ coverage + + + + env.BUILD_NUMBER + + net.sourceforge.cobertura @@ -101,7 +107,7 @@ 1.9.4.1 - + org.codehaus.mojo @@ -113,9 +119,17 @@ xml + + + package + + cobertura + + + - +