diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..ab40d21 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,6 @@ +*Issue #, if available:* + +*Description of changes:* + + +By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. diff --git a/CHANGES.txt b/CHANGES.txt index eeb86ef..fa74f04 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,6 +1,58 @@ -Version 3.3.2 - March 2018 +Version 3.7.1 - July 2022 +- Fixed security vulnerabilities in dependencies. + +Version 3.7.0 - March 2021 +- Fixed following two security risks : +1. Deprecated setSecretKey(String) method & enabled setSecretKey(char[]) in Config & PayConfig +2. Buyer Access token is passed as HTTP header instead of query parameter in URL for GetUserInfo API +- Note: Consumers of previous SDK versions strongly recommended to update data type of secret key from string to char[] as of this SDK Version 3.7.0. Please check the link : https://www.techiedelight.com/why-character-array-preferred-over-string-storing-passwords/ to know why char array is preferred over string for string. + +Version 3.6.5 - January 2021 +- Added additional attribute (expectImmediateAuthorization) to ConfirmOrderReference. This value can be set to true or false (Boolean). See Amazon Pay Strong Customer Authentication (SCA) Upgrade Integration Guide for more information. + +Version 3.6.4 - September 2020 +- getPaymentDetails was throwing NPE instead of AmazonServiceException in certain situations +- Remediate weakly configured XML processor in PayLogUtil class + +Version 3.6.3 - February 2020 +- Fix Refund operation so that the ProviderCreditList is handled properly +- Add ProviderCreditList support to the AuthorizeOnBillingAgreement operation + +Version 3.6.2 - August 2019 +- Fix SetBillingAgreementDetails NPE for US and JP regions + +Version 3.6.1 - August 2019 +- Strong Customer Authentication (SCA) implementation bug fix + +Version 3.6.0 - August 2019 +- Added additional attributes (successUrl, failureUrl) to ConfirmBillingAgreement and (subscriptionAmount, billingAgreementType) to SetBillingAgreement Details + See Amazon Pay Strong Customer Authentication (SCA) Upgrade Integration Guide for more information + +Version 3.5.1 - May 2019 +- PaymentAuthenticationStatus getter added for GetOrderReferenceDetails, SetOrderReferenceDetails, and SetOrderAttributes API calls +- StaticToken getter added for GetOrderReferenceDetails + +Version 3.5.0 - February 2019 +- ConfirmOrderReference API has four new request parameters: + SuccessUrl, FailureUrl, AuthorizationAmount, and AuthorizationCurrencyCode + For usage instructions, please consult the + Amazon Pay Strong Customer Authentication (SCA) Upgrade Integration Guide + +Version 3.4.1 - October 2018 +- Updated XMLInputFactory.newFactory() to XMLInputFactory.newInstance() in generateErrorException method (now consistent with 3.0.1 release). +- Add parameter SupplementaryData to SetOrderAttributes and SetOrderReferenceDetails API calls. Only use this field at the specific direction of Amazon Pay. +- Force InputStreamReader to use UTF-8 encoding for request responses, overriding any local environment setting. +- ErrorResponse object collects both "RequestID" (returned from Throttled calls) and "RequestId" (everywhere else) in the XML instead so that it is accessible via getRequestId(). +- AuthorizeOnBillingAgreement can now properly set the sellerNote and platformId fields + +Version 3.4.0 - April 2018 +- Add support for GetMerchantAccountStatus API +- Solution Providers can now override the Seller ID on a per-request basis instead of having to instantiate a new Client object for each request. +- Fixed pay.amazon.com links to online API documentaton in Client.java + +Version 3.3.5 - March 2018 - Maven Central Release -- Documentation changes to satisfy Maven central release +- JavaDoc changes to satisfy Maven central release Version 3.3.1 - January 2018 - Fix the SDK version number in all files diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..3b64466 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,4 @@ +## Code of Conduct +This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). +For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact +opensource-codeofconduct@amazon.com with any additional questions or comments. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..ef506f1 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,61 @@ +# Contributing Guidelines + +Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional +documentation, we greatly value feedback and contributions from our community. + +Please read through this document before submitting any issues or pull requests to ensure we have all the necessary +information to effectively respond to your bug report or contribution. + + +## Reporting Bugs/Feature Requests + +We welcome you to use the GitHub issue tracker to report bugs or suggest features. + +When filing an issue, please check [existing open](https://github.com/amzn/amazon-pay-sdk-java/issues), or [recently closed](https://github.com/amzn/amazon-pay-sdk-java/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aclosed%20), issues to make sure somebody else hasn't already +reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: + +* A reproducible test case or series of steps +* The version of our code being used +* Any modifications you've made relevant to the bug +* Anything unusual about your environment or deployment + + +## Contributing via Pull Requests +Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: + +1. You are working against the latest source on the *master* branch. +2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already. +3. You open an issue to discuss any significant work - we would hate for your time to be wasted. + +To send us a pull request, please: + +1. Fork the repository. +2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change. +3. Ensure local tests pass. +4. Commit to your fork using clear commit messages. +5. Send us a pull request, answering any default questions in the pull request interface. +6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. + +GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and +[creating a pull request](https://help.github.com/articles/creating-a-pull-request/). + + +## Finding contributions to work on +Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels ((enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any ['help wanted'](https://github.com/amzn/amazon-pay-sdk-java/labels/help%20wanted) issues is a great place to start. + + +## Code of Conduct +This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). +For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact +opensource-codeofconduct@amazon.com with any additional questions or comments. + + +## Security issue notifications +If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue. + + +## Licensing + +See the [LICENSE](https://github.com/amzn/amazon-pay-sdk-java/blob/master/LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution. + +We may ask you to sign a [Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement) for larger changes. diff --git a/README.md b/README.md index e860cf0..3d2e88f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ -[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.amazon.pay/amazon-pay-java-sdk/badge.svg)] -(https://maven-badges.herokuapp.com/maven-central/com.amazon.pay/amazon-pay-java-sdk) +[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.amazon.pay/amazon-pay-java-sdk/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.amazon.pay/amazon-pay-java-sdk) + +> **Important:** This SDK has been deprecated. Amazon Pay will continue to support this version but it will not be updated with new features. New integrations should use [Amazon Pay API SDK (Java)](https://github.com/amzn/amazon-pay-api-sdk-java) & refer this [documentation](https://developer.amazon.com/docs/amazon-pay/intro.html) for more details. ### Amazon Pay Java SDK @@ -9,7 +10,7 @@ * Java 1.6 or higher *(including JCE Java Cryptography Extension)* * Apache Commons Logging 1.2 *(or JCL-over-SLF4J drop in replacement)* * Apache Commons Codec 1.10 -* Google Gson 2.2.2 or higher *(for GetUserInfo and IPN handling only)* +* Google Gson 2.8.9 or higher *(for GetUserInfo and IPN handling only)* Amazon Pay API Integration @@ -26,7 +27,7 @@ import com.amazon.pay.impl.PayConfig; ```java String merchantId = "YOUR_MERCHANT_ID"; String accessKey = "YOUR_ACCESS_KEY"; -String secretKey = "YOUR_SECRET_Key"; +char[] secretKey = getSecretKey() // Replace with your implementation Config config = new PayConfig() .withSellerId(merchantId) @@ -420,7 +421,7 @@ XMLGregorianCalendar endTime = ListOrderReferenceRequest listOrderReferenceRequest = new ListOrderReferenceRequest("YOUR_SELLER_ORDER_ID", "SellerOrderId"); // optional parameters -listOrderReferenceRequest.setMwsAuthToken("YOUR_MWS_AUTH_TOKEN"); +listOrderReferenceRequest.setMWSAuthToken("YOUR_MWS_AUTH_TOKEN"); listOrderReferenceRequest.setStartTime(startTime); listOrderReferenceRequest.setEndTime(endTime); listOrderReferenceRequest.setPageSize(5); @@ -436,8 +437,42 @@ This API returns a list of the continued orders from the previous call (ListOrde ```java ListOrderReferenceByNextTokenRequest listOrderReferenceByNextTokenRequest = new ListOrderReferenceByNextTokenRequest(nextPageToken); //nextPageToken is derived from the ListOrderReference response explained above //optional parameters -listOrderReferenceByNextTokenRequest.setMwsAuthToken("YOUR_MWS_AUTH_TOKEN"); +listOrderReferenceByNextTokenRequest.setMWSAuthToken("YOUR_MWS_AUTH_TOKEN"); ListOrderReferenceByNextTokenResponseData response = client.listOrderReferenceByNextToken(listOrderReferenceByNextTokenRequest); ``` + +### Get Merchant Account Status API +The GetMerchantAccountStatus operation is used to query the status of a particular merchant account and to retrieve information if the account is active or inactive. + +```java +import com.amazon.pay.response.model.AccountStatus; +import com.amazon.pay.response.parser.GetMerchantAccountStatusResponseData; +import com.amazon.pay.request.GetMerchantAccountStatusRequest; +... + +// To check the status of your merchant account +final GetMerchantAccountStatusResponseData response = client.getMerchantAccountStatus(); +final AccountStatus accountStatus = response.getAccountStatus(); + +if (accountStatus.equals(AccountStatus.ACTIVE)) { + System.out.println("Merchant account is enabled"); +} else if (accountStatus.equals(AccountStatus.INACTIVE)) { + System.out.println("Merchant account is disabled"); +} + +// Or using MWS delegation to check on the status of another merchant account +final GetMerchantAccountStatusRequest request = new GetMerchantAccountStatusRequest(); +request.setSellerId("REPLACE_WITH_OTHER_MERCHANT_ID"); +request.setMWSAuthToken("REPLACE_WITH_MWS_AUTH_TOKEN"); + +final GetMerchantAccountStatusResponseData resp = client.getMerchantAccountStatus(request); +final AccountStatus status = resp.getAccountStatus(); + +if (status.equals(AccountStatus.ACTIVE)) { + System.out.println("Child merchant account is enabled"); +} else if (status.equals(AccountStatus.INACTIVE)) { + System.out.println("Child merchant account is disabled"); +} +``` diff --git a/dist/amazon-pay-3.3.0.jar b/dist/amazon-pay-3.3.0.jar deleted file mode 100644 index e7f3950..0000000 Binary files a/dist/amazon-pay-3.3.0.jar and /dev/null differ diff --git a/dist/amazon-pay-3.3.1.jar b/dist/amazon-pay-3.3.1.jar deleted file mode 100644 index 08f614c..0000000 Binary files a/dist/amazon-pay-3.3.1.jar and /dev/null differ diff --git a/dist/amazon-pay-3.7.0.jar b/dist/amazon-pay-3.7.0.jar new file mode 100644 index 0000000..33ce7dc Binary files /dev/null and b/dist/amazon-pay-3.7.0.jar differ diff --git a/pom.xml b/pom.xml index 7a1c50f..2d20884 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.amazon.pay amazon-pay-java-sdk jar - 3.3.2 + 3.7.1 commons-codec @@ -14,7 +14,7 @@ com.google.code.gson gson - 2.2.2 + 2.8.9 org.json @@ -42,11 +42,11 @@ ossrh - https://oss.sonatype.org/content/repositories/snapshots + https://aws.oss.sonatype.org/content/repositories/snapshots ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ + https://aws.oss.sonatype.org/service/local/staging/deploy/maven2/ @@ -54,65 +54,71 @@ oss-parent 7 - - - release - target - - - org.apache.maven.plugins - maven-compiler-plugin - 3.6.0 - - 1.6 - 1.6 - 1.6 - UTF-8 - - - - org.apache.maven.plugins - maven-source-plugin - 2.2.1 - - - attach-sources - - jar-no-fork - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.9.1 - - - attach-javadocs - - jar - - - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.6 - - - sign-artifacts - verify - - sign - - - - - + target + src + tst - - + + + release + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.0 + + 1.6 + 1.6 + 1.6 + UTF-8 + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + package + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + + attach-javadocs + package + + jar + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + sign-artifacts + verify + + sign + + + + + + + + diff --git a/src/com/amazon/pay/Client.java b/src/com/amazon/pay/Client.java index c687401..cabd8d4 100644 --- a/src/com/amazon/pay/Client.java +++ b/src/com/amazon/pay/Client.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2016-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ import com.amazon.pay.request.GetAuthorizationDetailsRequest; import com.amazon.pay.request.GetBillingAgreementDetailsRequest; import com.amazon.pay.request.GetCaptureDetailsRequest; +import com.amazon.pay.request.GetMerchantAccountStatusRequest; import com.amazon.pay.request.GetOrderReferenceDetailsRequest; import com.amazon.pay.request.GetProviderCreditDetailsRequest; import com.amazon.pay.request.GetProviderCreditReversalDetailsRequest; @@ -56,6 +57,7 @@ import com.amazon.pay.response.parser.GetCaptureDetailsResponseData; import com.amazon.pay.response.parser.GetOrderReferenceDetailsResponseData; import com.amazon.pay.response.parser.GetPaymentDetails; +import com.amazon.pay.response.parser.GetMerchantAccountStatusResponseData; import com.amazon.pay.response.parser.GetProviderCreditDetailsResponseData; import com.amazon.pay.response.parser.GetProviderCreditReversalDetailsResponseData; import com.amazon.pay.response.parser.GetRefundDetailsResponseData; @@ -80,7 +82,7 @@ public interface Client { * Capture operation after you call this operation. An authorization is only * valid for a particular time period, which is specified in the response of * the operation. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201752010 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/authorize.html * * @param authorizeRequest Container for the necessary * parameters to execute the Authorize service API on @@ -101,7 +103,7 @@ public interface Client { * you must either set the CaptureNow request parameter to true, or call the * Capture operation after you call this operation. An authorization is only valid for * a particular time period, which is specified in the response of the operation. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201751940 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/authorizeonbillingagreement.html * * @param authorizeOnBillingAgreementRequest Container for the necessary * parameters to execute the AuthorizeOnBillingAgreement service API on @@ -121,7 +123,7 @@ public interface Client { * You can cancel an Order Reference object only if there are no Completed, Closed, or Pending * captures against it. If you cancel an order reference, all authorizations associated with * this order reference are also closed. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201751990 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/cancelorderreference.html * * @param request Container for the necessary * parameters to execute the CancelOrderReference service API on @@ -141,7 +143,7 @@ public interface Client { * To successfully capture a payment, you must call this operation on an Authorization object * before it expires, as specified by the ExpirationTimestamp returned in response of the Authorize operation call. * You must specify a capture amount, and the amount cannot exceed the original amount that was authorized. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201752040 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/capture.html * * @param request Container for the necessary * parameters to execute the Capture service API on @@ -176,7 +178,7 @@ public interface Client { /** * Call the CloseAuthorization operation to close an authorization after the * total amount of the authorization has been captured. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201752070 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/closeauthorization.html * * @param request Container for the necessary * parameters to execute the CloseAuthorization service API on @@ -196,7 +198,7 @@ public interface Client { * indicate that you want to terminate the billing agreement with the buyer and that you * do not expect to create any new order references or authorizations on this billing agreement. * All open authorizations on the billing agreement can still be used to capture funds. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201751950 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/closebillingagreement.html * * @param closeBillingAgreementRequest Container for the necessary * parameters to execute the CloseBillingAgreement service API on @@ -216,7 +218,7 @@ public interface Client { * has been fulfilled (fully or partially) and that you do not expect to create any new * authorizations on this order reference. You can still capture funds against open * authorizations on the order reference. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201752000 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/closeorderreference.html * * @param closeOrderReferenceRequest Container for the necessary * parameters to execute the CloseOrderReference service API on @@ -236,7 +238,7 @@ public interface Client { * indicating that all required information has been set on the billing agreement. * On successful completion of the ConfirmBillingAgreement call, the billing agreement * moves to the Open state. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201751710 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/confirmbillingagreement.html * * @param confirmBillingAgreementRequest Container for the necessary * parameters to execute the ConfirmBillingAgreement service API on @@ -256,7 +258,7 @@ public interface Client { * constraints and all required information has been set on the order reference. * After you call this operation, the order reference is set to the Open state and * you can submit authorizations against the order reference. - * Documentation; https://pay.amazon.com/documentation/apireference/201751630#201751980 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/confirmorderreference.html * * @param request Container for the necessary * parameters to execute the ConfirmOrderReference service API on @@ -269,14 +271,12 @@ public interface Client { * If an error response is returned by Amazon Pay indicating * either a problem with the data in the request, or a server side issue. */ - ConfirmOrderReferenceResponseData confirmOrderReference( - ConfirmOrderReferenceRequest request) throws AmazonServiceException; + ConfirmOrderReferenceResponseData confirmOrderReference(ConfirmOrderReferenceRequest request) throws AmazonServiceException; /** * The CreateOrderReferenceForId operation is used to create an Order Reference object from * the object represented by the Id and IdType request parameters. - * - * Documentation: https://pay.amazon.com/developer/documentation/apireference/201751670 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/createorderreferenceforid.html * * @param createOrderReferenceForIdRequest Container for the necessary * parameters to execute the GetOrderReferenceDetails service API on @@ -298,7 +298,7 @@ CreateOrderReferenceForIdResponseData createOrderReferenceForId( * and to retrieve information about the total amount captured on the authorization. * If you received a Pending status when you called the Authorize operation, * you can call this operation to get the current status. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201752030 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/getauthorizationdetails.html * * @param request Container for the necessary * parameters to execute the GetAuthorizationDetails service API on @@ -316,7 +316,7 @@ CreateOrderReferenceForIdResponseData createOrderReferenceForId( /** * The GetBillingAgreementDetails operation returns details about the Billing * Agreement object and its current state. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201751690 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/getbillingagreementdetails.html * * @param getBillingAgreementDetailsRequest Container for the necessary * parameters to execute the GetBillingAgreementDetails service API on @@ -336,7 +336,7 @@ CreateOrderReferenceForIdResponseData createOrderReferenceForId( * To successfully capture a payment, you must call this operation on an Authorization object * before it expires, as specified by the ExpirationTimestamp returned in response of the Authorize operation call. * You must specify a capture amount, and the amount cannot exceed the original amount that was authorized. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201752060 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/getcapturedetails.html * * @param request Container for the necessary * parameters to execute the GetCaptureDetails service API on @@ -354,7 +354,7 @@ CreateOrderReferenceForIdResponseData createOrderReferenceForId( /** * The GetOrderReferenceDetails operation returns details about the * Order Reference object and its current state. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201751970 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/getorderreferencedetails.html * * @param getOrderReferenceDetailsRequest Container for the necessary * parameters to execute the GetOrderReferenceDetails service API on @@ -439,7 +439,7 @@ CreateOrderReferenceForIdResponseData createOrderReferenceForId( * Call the GetRefundDetails operation to query the status of a particular refund. * If you received a Pending status when you called the Refund operation, * you can call this operation to get the current status. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201752100 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/getrefunddetails.html * * @param getRefundDetailsRequest Container for the necessary * parameters to execute the GetRefundDetails service API on @@ -457,7 +457,7 @@ CreateOrderReferenceForIdResponseData createOrderReferenceForId( /** * The GetServiceStatus operation returns the operational status of the Pay with Amazon API * section of Amazon Marketplace Web Service (Amazon MWS). - * Documentation: https://pay.amazon.com/developer/documentation/apireference/201752110 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/getservicestatus.html * * @return The response from the GetServiceStatus service API, as * returned by Amazon Pay @@ -486,7 +486,7 @@ CreateOrderReferenceForIdResponseData createOrderReferenceForId( /** * Call the Refund operation to refund a previously captured amount. You call the * GetRefundDetails operation to query the status of a refund. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201752080 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/refund.html * * @param refundRequest Container for the necessary * parameters to execute the Refund service API on @@ -520,7 +520,7 @@ CreateOrderReferenceForIdResponseData createOrderReferenceForId( /** * Call the SetBillingAgreementDetails operation to specify billing agreement * details such as a description of the agreement and other information about the merchant. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201751700 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/setbillingagreementdetails.html * * @param setBillingAgreementDetailsRequest Container for the necessary * parameters to execute the SetBillingAgreementDetails service API on @@ -539,7 +539,7 @@ CreateOrderReferenceForIdResponseData createOrderReferenceForId( * Call the SetOrderReferenceDetails operation to specify order details * such as the amount of the order, * a description of the order, and other order attributes. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201751960 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/setorderreferencedetails.html * * @param setOrderReferenceDetailsRequest Container for the necessary * parameters to execute the SetOrderReferenceDetails service API on @@ -559,7 +559,7 @@ CreateOrderReferenceForIdResponseData createOrderReferenceForId( * Open state (that is, after a successful call to the ConfirmBillingAgreement operation). * This operation validates the status of the billing agreement and the validity of the * payment method associated with the billing agreement. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201751720 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/validatebillingagreement.html * * @param validateBillingAgreementRequest Container for the necessary * parameters to execute the ValidateBillingAgreement service API on @@ -626,6 +626,7 @@ public ListOrderReferenceByNextTokenResponseData listOrderReferenceByNextToken( /** * The SetOrderAttributes operation is used to set order attributes even after * the order has been confirmed. + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/setorderattributes.html * * @param setOrderAttributesRequest Container for the necessary * parameters to execute the SetOrderAttributes service API on @@ -642,4 +643,39 @@ public SetOrderAttributesResponseData setOrderAttributes( SetOrderAttributesRequest setOrderAttributesRequest) throws AmazonServiceException; + /** + * The GetMerchantAccountStatus operation is used to query the status of a particular + * merchant account and to retrieve information if the account is active or inactive. + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/getmerchantaccountstatus.html + * + * @param getMerchantAccountStatusRequest Container for the optional + * parameters to execute the GetMerchantAccountStatus service API on + * Amazon Pay. + * + * @return The response from the GetMerchantAccountStatus service API, as + * returned by Amazon Pay. + * + * @throws AmazonServiceException + * If an error response is returned by Amazon Pay indicating + * either a problem with the data in the request, or a server side issue. + */ + public GetMerchantAccountStatusResponseData getMerchantAccountStatus( + GetMerchantAccountStatusRequest getMerchantAccountStatusRequest) + throws AmazonServiceException; + + /** + * The GetMerchantAccountStatus operation is used to query the status of a particular + * merchant account and to retrieve information if the account is active or inactive. + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/getmerchantaccountstatus.html + * + * @return The response from the GetMerchantAccountStatus service API, as + * returned by Amazon Pay. + * + * @throws AmazonServiceException + * If an error response is returned by Amazon Pay indicating + * either a problem with the data in the request, or a server side issue. + */ + public GetMerchantAccountStatusResponseData getMerchantAccountStatus() + throws AmazonServiceException; + } diff --git a/src/com/amazon/pay/Config.java b/src/com/amazon/pay/Config.java index bdb5db1..c6b4a6f 100644 --- a/src/com/amazon/pay/Config.java +++ b/src/com/amazon/pay/Config.java @@ -74,7 +74,7 @@ public interface Config { /** * @return Returns SecretKey from PayConfig */ - String getSecretKey(); + char[] getSecretKey(); /** * @return Returns the MerchantId/SellerId from PayConfig @@ -138,9 +138,16 @@ public interface Config { void setRegion(Region region); /** + * @deprecated(since = "3.7.0") This method is deprecated, instead use setSecretKey(char[] secretAccessKey) * @param secretAccessKey Sets SecretKey in PayConfig */ + @Deprecated void setSecretKey(String secretAccessKey); + + /** + * @param secretAccessKey Sets SecretKey in PayConfig + */ + void setSecretKey(char[] secretAccessKey); /** * @param sellerId Sets MerchantId/SellerId in PayConfig diff --git a/src/com/amazon/pay/exceptions/AmazonClientException.java b/src/com/amazon/pay/exceptions/AmazonClientException.java index 6fbb932..e2f6e59 100644 --- a/src/com/amazon/pay/exceptions/AmazonClientException.java +++ b/src/com/amazon/pay/exceptions/AmazonClientException.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. diff --git a/src/com/amazon/pay/exceptions/AmazonServiceException.java b/src/com/amazon/pay/exceptions/AmazonServiceException.java index 7444e95..3d14673 100644 --- a/src/com/amazon/pay/exceptions/AmazonServiceException.java +++ b/src/com/amazon/pay/exceptions/AmazonServiceException.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. diff --git a/src/com/amazon/pay/impl/PayClient.java b/src/com/amazon/pay/impl/PayClient.java index 40a0db0..11c273f 100755 --- a/src/com/amazon/pay/impl/PayClient.java +++ b/src/com/amazon/pay/impl/PayClient.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -33,6 +33,7 @@ import com.amazon.pay.request.GetBillingAgreementDetailsRequest; import com.amazon.pay.request.GetCaptureDetailsRequest; import com.amazon.pay.request.GetOrderReferenceDetailsRequest; +import com.amazon.pay.request.GetMerchantAccountStatusRequest; import com.amazon.pay.request.GetProviderCreditDetailsRequest; import com.amazon.pay.request.GetProviderCreditReversalDetailsRequest; import com.amazon.pay.request.GetRefundDetailsRequest; @@ -65,6 +66,7 @@ import com.amazon.pay.response.parser.GetBillingAgreementDetailsResponseData; import com.amazon.pay.response.parser.GetCaptureDetailsResponseData; import com.amazon.pay.response.parser.GetOrderReferenceDetailsResponseData; +import com.amazon.pay.response.parser.GetMerchantAccountStatusResponseData; import com.amazon.pay.response.parser.GetPaymentDetails; import com.amazon.pay.response.parser.GetProviderCreditDetailsResponseData; import com.amazon.pay.response.parser.GetProviderCreditReversalDetailsResponseData; @@ -116,7 +118,7 @@ public PayClient(Config config) { /** * The GetServiceStatus operation returns the operational status of the Amazon Pay API * section of Amazon Marketplace Web Service (Amazon MWS). - * Documentation: https://pay.amazon.com/developer/documentation/apireference/201752110 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/getservicestatus.html * * @return The response from the GetServiceStatus service API, as * returned by Amazon Pay @@ -140,8 +142,7 @@ public GetServiceStatusResponseData getServiceStatus() /** * The CreateOrderReferenceForId operation is used to create an Order Reference object from * the object represented by the Id and IdType request parameters. - * - * Documentation: https://pay.amazon.com/developer/documentation/apireference/201751670 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/createorderreferenceforid.html * * @param createOrderReferenceForIdRequest Container for the necessary * parameters to execute the GetOrderReferenceDetails service API on @@ -171,7 +172,7 @@ public CreateOrderReferenceForIdResponseData createOrderReferenceForId( /** * The GetOrderReferenceDetails operation returns details about the * Order Reference object and its current state. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201751970 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/getorderreferencedetails.html * * @param getOrderReferenceDetailsRequest Container for the necessary * parameters to execute the GetOrderReferenceDetails service API on @@ -234,40 +235,42 @@ public GetPaymentDetails getPaymentDetails( throws AmazonServiceException { GetPaymentDetails paymentDetails = new GetPaymentDetails(); - GetOrderReferenceDetailsRequest getOrderReferenceDetailsRequest = - new GetOrderReferenceDetailsRequest(orderReferenceID) - .setMWSAuthToken(MWSAuthToken); - OrderReferenceDetails orderReferenceResponse = getOrderReferenceDetails(getOrderReferenceDetailsRequest).getDetails(); + final GetOrderReferenceDetailsRequest getOrderReferenceDetailsRequest = + new GetOrderReferenceDetailsRequest(orderReferenceID).setMWSAuthToken(MWSAuthToken); + final OrderReferenceDetails orderReferenceResponse = getOrderReferenceDetails(getOrderReferenceDetailsRequest).getDetails(); paymentDetails.putOrderReferenceDetails(orderReferenceID, orderReferenceResponse); - List amazon_authorization_id = orderReferenceResponse.getIdList().getMember(); - - for (String authorizeID : amazon_authorization_id) { - GetAuthorizationDetailsRequest getAuthDetailsRequest = - new GetAuthorizationDetailsRequest(authorizeID) - .setMWSAuthToken(MWSAuthToken); - AuthorizationDetails responseAuthorize = getAuthorizationDetails(getAuthDetailsRequest).getDetails(); - paymentDetails.putAuthorizationDetails(authorizeID, responseAuthorize); - - List amazon_capture_id = responseAuthorize.getIdList().getMember(); - - for (String captureID : amazon_capture_id) { - GetCaptureDetailsRequest getCaptureDetailsRequest = - new GetCaptureDetailsRequest(captureID) - .setMWSAuthToken(MWSAuthToken); - CaptureDetails responseCapture = getCaptureDetails(getCaptureDetailsRequest).getDetails(); - paymentDetails.putCaptureDetails(captureID, responseCapture); - - List amazon_refund_id = responseCapture.getIdList().getMember(); - - for (String refundID : amazon_refund_id) { - GetRefundDetailsRequest getRefundDetailsRequest = - new GetRefundDetailsRequest(refundID) - .setMWSAuthToken(MWSAuthToken); - RefundDetails responseRefund = getRefundDetails(getRefundDetailsRequest).getDetails(); - paymentDetails.putRefundDetails(refundID, responseRefund); + if (orderReferenceResponse.getIdList() != null) { + final List amazonAuthorizations = orderReferenceResponse.getIdList().getMember(); + + for (String authorizeId : amazonAuthorizations) { + final GetAuthorizationDetailsRequest getAuthDetailsRequest = + new GetAuthorizationDetailsRequest(authorizeId).setMWSAuthToken(MWSAuthToken); + final AuthorizationDetails responseAuthorize = getAuthorizationDetails(getAuthDetailsRequest).getDetails(); + paymentDetails.putAuthorizationDetails(authorizeId, responseAuthorize); + + if (responseAuthorize.getIdList() != null) { + final List amazonCaptures = responseAuthorize.getIdList().getMember(); + + for (String captureId : amazonCaptures) { + final GetCaptureDetailsRequest getCaptureDetailsRequest = + new GetCaptureDetailsRequest(captureId).setMWSAuthToken(MWSAuthToken); + final CaptureDetails responseCapture = getCaptureDetails(getCaptureDetailsRequest).getDetails(); + paymentDetails.putCaptureDetails(captureId, responseCapture); + + if (responseCapture.getIdList() != null) { + final List amazonRefunds = responseCapture.getIdList().getMember(); + + for (String refundId : amazonRefunds) { + final GetRefundDetailsRequest getRefundDetailsRequest = + new GetRefundDetailsRequest(refundId).setMWSAuthToken(MWSAuthToken); + final RefundDetails responseRefund = getRefundDetails(getRefundDetailsRequest).getDetails(); + paymentDetails.putRefundDetails(refundId, responseRefund); + } } - } + } + } + } } return paymentDetails; @@ -278,7 +281,7 @@ public GetPaymentDetails getPaymentDetails( * Call the SetOrderReferenceDetails operation to specify order details * such as the amount of the order, * a description of the order, and other order attributes. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201751960 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/setorderreferencedetails.html * * @param setOrderReferenceDetailsRequest Container for the necessary * parameters to execute the SetOrderReferenceDetails service API on @@ -309,7 +312,7 @@ public SetOrderReferenceDetailsResponseData setOrderReferenceDetails(SetOrderRef * Capture operation after you call this operation. An authorization is only * valid for a particular time period, which is specified in the response of * the operation. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201752010 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/authorize.html * * * @param authorizeRequest Container for the necessary @@ -340,7 +343,7 @@ public AuthorizeResponseData authorize(AuthorizeRequest authorizeRequest) throws * and to retrieve information about the total amount captured on the authorization. * If you received a Pending status when you called the Authorize operation, * you can call this operation to get the current status. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201752030 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/getauthorizationdetails.html * * * @param request Container for the necessary @@ -371,7 +374,7 @@ public GetAuthorizationDetailsResponseData getAuthorizationDetails(GetAuthorizat * To successfully capture a payment, you must call this operation on an Authorization object * before it expires, as specified by the ExpirationTimestamp returned in response of the Authorize operation call. * You must specify a capture amount, and the amount cannot exceed the original amount that was authorized. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201752040 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/capture.html * * * @param request Container for the necessary @@ -402,7 +405,7 @@ public CaptureResponseData capture(CaptureRequest request) throws AmazonServiceE * To successfully capture a payment, you must call this operation on an Authorization object * before it expires, as specified by the ExpirationTimestamp returned in response of the Authorize operation call. * You must specify a capture amount, and the amount cannot exceed the original amount that was authorized. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201752060 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/getcapturedetails.html * * * @param request Container for the necessary @@ -435,7 +438,7 @@ public GetCaptureDetailsResponseData getCaptureDetails(GetCaptureDetailsRequest * constraints and all required information has been set on the order reference. * After you call this operation, the order reference is set to the Open state and * you can submit authorizations against the order reference. - * Documentation; https://pay.amazon.com/documentation/apireference/201751630#201751980 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/confirmorderreference.html * * * @param request Container for the necessary @@ -464,7 +467,7 @@ public ConfirmOrderReferenceResponseData confirmOrderReference(ConfirmOrderRefe /** * Call the CloseAuthorization operation to close an authorization after the * total amount of the authorization has been captured. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201752070 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/closeauthorization.html * * * @param request Container for the necessary @@ -498,7 +501,7 @@ public CloseAuthorizationResponseData closeAuthorization(CloseAuthorizationReque * You can cancel an Order Reference object only if there are no Completed, Closed, or Pending * captures against it. If you cancel an order reference, all authorizations associated with * this order reference are also closed. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201751990 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/cancelorderreference.html * * * @param request Container for the necessary @@ -529,7 +532,7 @@ public CancelOrderReferenceResponseData cancelOrderReference(CancelOrderReferenc * has been fulfilled (fully or partially) and that you do not expect to create any new * authorizations on this order reference. You can still capture funds against open * authorizations on the order reference. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201752000 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/closeorderreference.html * * * @param closeOrderReferenceRequest Container for the necessary @@ -560,7 +563,7 @@ public CloseOrderReferenceResponseData closeOrderReference(CloseOrderReferenceRe /** * Call the Refund operation to refund a previously captured amount. You call the * GetRefundDetails operation to query the status of a refund. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201752080 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/refund.html * * * @param refundRequest Container for the necessary @@ -592,7 +595,7 @@ public RefundResponseData refund(RefundRequest refundRequest) throws AmazonServi * Call the GetRefundDetails operation to query the status of a particular refund. * If you received a Pending status when you called the Refund operation, * you can call this operation to get the current status. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201752100 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/getrefunddetails.html * * * @param getRefundDetailsRequest Container for the necessary @@ -621,7 +624,7 @@ public GetRefundDetailsResponseData getRefundDetails(GetRefundDetailsRequest get /** * The GetBillingAgreementDetails operation returns details about the Billing * Agreement object and its current state. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201751690 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/getbillingagreementdetails.html * * * @param getBillingAgreementDetailsRequest Container for the necessary @@ -651,7 +654,7 @@ public GetBillingAgreementDetailsResponseData getBillingAgreementDetails(GetBill /** * Call the SetBillingAgreementDetails operation to specify billing agreement * details such as a description of the agreement and other information about the merchant. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201751700 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/setbillingagreementdetails.html * * * @param setBillingAgreementDetailsRequest Container for the necessary @@ -684,7 +687,7 @@ public SetBillingAgreementDetailsResponseData setBillingAgreementDetails(SetBill * Open state (that is, after a successful call to the ConfirmBillingAgreement operation). * This operation validates the status of the billing agreement and the validity of the * payment method associated with the billing agreement. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201751720 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/validatebillingagreement.html * * * @param validateBillingAgreementRequest Container for the necessary @@ -716,7 +719,7 @@ public ValidateBillingAgreementResponseData validateBillingAgreement(ValidateBil * indicating that all required information has been set on the billing agreement. * On successful completion of the ConfirmBillingAgreement call, the billing agreement * moves to the Open state. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201751710 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/confirmbillingagreement.html * * * @param confirmBillingAgreementRequest Container for the necessary @@ -749,7 +752,7 @@ public ConfirmBillingAgreementResponseData confirmBillingAgreement(ConfirmBillin * you must either set the CaptureNow request parameter to true, or call the * Capture operation after you call this operation. An authorization is only valid for * a particular time period, which is specified in the response of the operation. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201751940 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/authorizeonbillingagreement.html * * * @param authorizeOnBillingAgreementRequest Container for the necessary @@ -780,7 +783,7 @@ public AuthorizeOnBillingAgreementResponseData authorizeOnBillingAgreement(Autho * indicate that you want to terminate the billing agreement with the buyer and that you * do not expect to create any new order references or authorizations on this billing agreement. * All open authorizations on the billing agreement can still be used to capture funds. - * Documentation: https://pay.amazon.com/documentation/apireference/201751630#201751950 + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/closebillingagreement.html * * * @param closeBillingAgreementRequest Container for the necessary @@ -913,7 +916,7 @@ public ReverseProviderCreditResponseData reverseProviderCredit(ReverseProviderC @Override public User getUserInfo(String accessToken , String clientId) throws AmazonServiceException, IOException { - final String decodedAccessToken = URLDecoder.decode(accessToken, "UTF-8"); + final String decodedAccessToken = URLDecoder.decode(accessToken, ServiceConstants.UTF_8); String profileEndpoint; if (payConfig.getOverrideProfileURL() != null) { @@ -927,11 +930,12 @@ public User getUserInfo(String accessToken , String clientId) throws AmazonServi } Map headerValues = new HashMap(); - ResponseData response = Util.httpSendRequest("GET" , profileEndpoint + "/auth/o2/tokeninfo?access_token=" + decodedAccessToken, null, headerValues, null); + headerValues.put(ServiceConstants.X_AMZ_ACCESS_TOKEN, decodedAccessToken); + ResponseData response = Util.httpSendRequest(ServiceConstants.GET, profileEndpoint + ServiceConstants.AUTH_O2_TOKENINFO_URI, null, headerValues, null); Map m = Util.convertJsonToObject(response.toXML(), Map.class); - if (m.containsKey("error")) { - throw new AmazonServiceException("Retrieving User Info Failed. "+(String)m.get("error_description")); + if (m.containsKey(ServiceConstants.ERROR)) { + throw new AmazonServiceException("Retrieving User Info Failed. " + (String)m.get(ServiceConstants.ERROR_DESCRIPTION)); } if (clientId == null || !clientId.equals(m.get("aud"))) { @@ -939,11 +943,10 @@ public User getUserInfo(String accessToken , String clientId) throws AmazonServi throw new AmazonClientException("Access token does not belong to clientId: " + clientId); } - headerValues.put("Authorization", "bearer " + decodedAccessToken); - response = Util.httpSendRequest("GET" , profileEndpoint + "/user/profile", null, headerValues); + response = Util.httpSendRequest(ServiceConstants.GET , profileEndpoint + ServiceConstants.USER_PROFILE_URI, null, headerValues); m = Util.convertJsonToObject(response.toXML() , Map.class); - if (m.containsKey("error")) { - throw new AmazonServiceException("Retrieving User Info Failed. " + (String)m.get("error_description")); + if (m.containsKey(ServiceConstants.ERROR)) { + throw new AmazonServiceException("Retrieving User Info Failed. " + (String)m.get(ServiceConstants.ERROR_DESCRIPTION)); } final User user = Util.convertJsonToObject(response.toXML() , User.class); @@ -1067,7 +1070,6 @@ private GetAuthorizationDetailsResponseData chargeORO(ChargeRequest chargeReques .setProviderCredit(chargeRequest.getProviderCredit()) .setSellerAuthorizationNote(chargeRequest.getSellerNote()) .setSoftDescriptor(chargeRequest.getSoftDescriptor()) - .setProviderCredit(chargeRequest.getProviderCredit()) ).getDetails().getAmazonAuthorizationId(); authDetails = getAuthorizationDetails(new GetAuthorizationDetailsRequest(authId).setMWSAuthToken(mwsAuthToken)); } else { @@ -1129,6 +1131,7 @@ public ListOrderReferenceByNextTokenResponseData listOrderReferenceByNextToken( /** * The SetOrderAttributes operation is used to set order attributes even after * the order has been confirmed. + * Documentation: https://developer.amazon.com/docs/amazon-pay-api/setorderattributes.html * * @param setOrderAttributesRequest Container for the necessary * parameters to execute the SetOrderAttributes service API on @@ -1136,7 +1139,7 @@ public ListOrderReferenceByNextTokenResponseData listOrderReferenceByNextToken( * * @return The response from the SetOrderAttributes service API, as * returned by Amazon Pay. - * + * * @throws AmazonServiceException * If an error response is returned by Amazon Pay indicating * either a problem with the data in the request, or a server side issue. @@ -1150,6 +1153,49 @@ public SetOrderAttributesResponseData setOrderAttributes( return Parser.setOrderAttributes(rawResponse); } + /** + * The GetMerchantAccountStatus operation is used to query the status of a particular + * merchant account and to retrieve information if the account is active or inactive. + * + * @param getMerchantAccountStatusRequest Container for the optional + * parameters to execute the GetMerchantAccountStatus service API on + * Amazon Pay. + * + * @return The response from the GetMerchantAccountStatus service API, as + * returned by Amazon Pay. + * + * @throws AmazonServiceException + * If an error response is returned by Amazon Pay indicating + * either a problem with the data in the request, or a server side issue. + */ + @Override + public GetMerchantAccountStatusResponseData getMerchantAccountStatus( + GetMerchantAccountStatusRequest getMerchantAccountStatusRequest) + throws AmazonServiceException { + final ResponseData rawResponse = sendRequest(helper.getPostURL( + getMerchantAccountStatusRequest)); + return Parser.getMerchantAccountStatus(rawResponse); + } + + /** + * The GetMerchantAccountStatus operation is used to query the status of a particular + * merchant account and to retrieve information if the account is active or inactive. + * + * @return The response from the GetMerchantAccountStatus service API, as + * returned by Amazon Pay. + * + * @throws AmazonServiceException + * If an error response is returned by Amazon Pay indicating + * either a problem with the data in the request, or a server side issue. + */ + @Override + public GetMerchantAccountStatusResponseData getMerchantAccountStatus() + throws AmazonServiceException { + final ResponseData rawResponse = sendRequest(helper.getPostURL( + new GetMerchantAccountStatusRequest())); + return Parser.getMerchantAccountStatus(rawResponse); + } + private ResponseData sendRequest(String httpPostRequest) { ResponseData response = null; @@ -1173,7 +1219,7 @@ private ResponseData sendRequest(String httpPostRequest) { response = postRequest(httpPostRequest); statusCode = response.getStatusCode(); } - }catch (IOException e) { + } catch (IOException e) { throw new AmazonClientException("Encountered IOException: ", e); } catch (InterruptedException ex) { throw new AmazonClientException("Encountered InterruptedException:", ex); diff --git a/src/com/amazon/pay/impl/PayConfig.java b/src/com/amazon/pay/impl/PayConfig.java index 6209a5a..c843e04 100644 --- a/src/com/amazon/pay/impl/PayConfig.java +++ b/src/com/amazon/pay/impl/PayConfig.java @@ -26,7 +26,7 @@ public class PayConfig implements Config { private String accessKey; - private String secretKey; + private char[] secretKey; private String merchantId; private Region region; private Environment environment; @@ -143,27 +143,46 @@ public PayConfig withAccessKey(String accessKey) { * */ @Override - public String getSecretKey() { + public char[] getSecretKey() { return secretKey; } /** - * + * @deprecated(since = "3.7.0") This method is deprecated, instead use setSecretKey(char[] secretKey) * @param secretKey - Sets SecretKey in PayConfig */ @Override + @Deprecated public void setSecretKey(String secretKey) { - this.secretKey = secretKey; + this.secretKey = secretKey.toCharArray(); } + + /** + * @param secretKey - Sets SecretKey in PayConfig + */ + @Override + public void setSecretKey(char[] secretKey) { + this.secretKey = secretKey; + } /** - * + * @deprecated(since = "3.7.0") This method is deprecated, instead use withSecretKey(char[] privateKey) * @param secretKey - Sets SecretKey in PayConfig * @return Returns updated PayConfig object */ + @Deprecated public PayConfig withSecretKey(String secretKey) { + this.secretKey = secretKey.toCharArray(); + return this; + } + + /** + * @param secretKey - Sets SecretKey in PayConfig + * @return Returns updated PayConfig object + */ + public PayConfig withSecretKey(char[] secretKey) { this.secretKey = secretKey; return this; } @@ -605,7 +624,7 @@ private PayConfig loadConfigurationFromProperties(Properties prop) { this.setAccessKey(prop.getProperty(property)); break; case SECRET_KEY: - this.setSecretKey(prop.getProperty(property)); + this.setSecretKey(prop.getProperty(property).toCharArray()); break; case MERCHANT_ID: this.setSellerId(prop.getProperty(property)); @@ -681,7 +700,7 @@ private PayConfig loadConfigurationFromProperties(Properties prop) { private boolean checkIfRequriedPropertiesExist() { if (this.accessKey == null) generateException(Key.ACCESS_KEY); - else if (this.secretKey == null) + else if (this.secretKey == null || this.secretKey.length == 0) generateException(Key.SECRET_KEY); else if (this.merchantId == null) generateException(Key.MERCHANT_ID); @@ -711,7 +730,6 @@ private void generateException(Key propertyKey) { public String toString() { return "PayConfig{" + "accessKeyId=" + accessKey + - ", secretAccessKey=" + secretKey + ", sellerId=" + merchantId + ", region=" + region + ", environment=" + environment + diff --git a/src/com/amazon/pay/impl/PayLogUtil.java b/src/com/amazon/pay/impl/PayLogUtil.java index 2a80f85..9c20fcd 100644 --- a/src/com/amazon/pay/impl/PayLogUtil.java +++ b/src/com/amazon/pay/impl/PayLogUtil.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -24,7 +24,10 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.*; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; @@ -56,9 +59,9 @@ public void logMessage(String message) { * @return sanitized data not containing SellerNote, SellerAuthorizationNote, SellerCaptureNote, SellerRefundNote, Buyer, PhysicalDestination, * BillingAddress, AuthorizationBillingAddress */ - public String sanitizeString(String responseData) { + public String sanitizeString(final String responseData) { - List restrictedDataList = new ArrayList() {{ + final List restrictedDataList = new ArrayList() {{ add("SellerNote"); add("SellerAuthorizationNote"); add("SellerCaptureNote"); @@ -66,50 +69,68 @@ public String sanitizeString(String responseData) { add("Buyer"); add("PhysicalDestination"); add("BillingAddress"); - add("AuthorizationBillingAddress");}}; + add("AuthorizationBillingAddress"); + }}; - String sanitizedData; - sanitizedData = getSanitizedData(responseData,restrictedDataList); + final String sanitizedData = getSanitizedData(responseData, restrictedDataList); return sanitizedData; } /** - * * @param data - data to be sanitized. * @param removedata - List of strings to be removed from the data object. * @return - an XML not containing 'removedata' lists of strings. * - * @throws TransformerFactoryConfigurationError - Thrown when a problem with configuration with the Transformer Factories exists. This error will typically be thrown when the class of a transformation factory specified in the system properties cannot be found or instantiated. + * @throws AmazonClientException - upon issue sanitizing data */ - public String getSanitizedData(String data, List removedata) throws AmazonClientException{ - - try{ - DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - InputSource is = new InputSource(); + public String getSanitizedData(final String data, final List removedata) throws AmazonClientException { + + try { + final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + + // settings for XXE: External Entity Prevention + // see https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/XML_External_Entity_Prevention_Cheat_Sheet.md + dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + dbf.setFeature("http://xml.org/sax/features/external-general-entities", false); + dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false); + dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); + dbf.setXIncludeAware(false); + dbf.setExpandEntityReferences(false); + + final DocumentBuilder db = dbf.newDocumentBuilder(); + final InputSource is = new InputSource(); is.setCharacterStream(new StringReader(data)); - Document doc = db.parse(is); + final Document doc = db.parse(is); - NodeList list = doc.getElementsByTagName("*"); + final NodeList list = doc.getElementsByTagName("*"); for (int i = 0; i < list.getLength(); i++) { //Get Node - Node node = (Node) list.item(i); + final Node node = (Node) list.item(i); - for(Iterator j = removedata.iterator(); j.hasNext(); ) { - String item = j.next(); + final Iterator j = removedata.iterator(); + while (j.hasNext()) { + final String item = j.next(); if (node.getNodeName().equalsIgnoreCase(item)) { node.setTextContent("*** Removed ***"); } } } - StringWriter sw = new StringWriter(); - Transformer serializer = TransformerFactory.newInstance().newTransformer(); - serializer.transform(new DOMSource(list.item(0)), new StreamResult(sw)); + final TransformerFactory tf = TransformerFactory.newInstance(); - String result = sw.toString(); + // settings for XXE: External Entity Prevention + // XMLConstants we need were introduced in Java 7, but we need to maintain backward compatibility + // with Java 6 in this SDK, so we reference them as their native strings + tf.setAttribute("http://javax.xml.XMLConstants/property/accessExternalDTD", ""); // XMLConstants.ACCESS_EXTERNAL_DTD + tf.setAttribute("http://javax.xml.XMLConstants/property/accessExternalStylesheet", ""); // XMLConstants.ACCESS_EXTERNAL_STYLESHEET + + final Transformer serializer = tf.newTransformer(); + final StringWriter sw = new StringWriter(); + serializer.transform(new DOMSource(list.item(0)), new StreamResult(sw)); + final String result = sw.toString(); return result; } catch (ParserConfigurationException e) { throw new AmazonClientException("Encountered UnsupportedEncodingException:", e); diff --git a/src/com/amazon/pay/impl/Util.java b/src/com/amazon/pay/impl/Util.java index 5d51d45..7c00ae9 100644 --- a/src/com/amazon/pay/impl/Util.java +++ b/src/com/amazon/pay/impl/Util.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2016-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -30,9 +30,13 @@ import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; +import java.nio.ByteBuffer; +import java.nio.CharBuffer; +import java.nio.charset.Charset; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.text.SimpleDateFormat; +import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.Iterator; @@ -63,17 +67,19 @@ public class Util { * (invalid encoding, wrong length, uninitialized, etc). * * @throws NoSuchAlgorithmException This exception is thrown when a - * particular cryptographic algorithm is requested but is not available in the environment. + * particular cryptographic algorithm is requested but is not + * available in the environment. * * @throws UnsupportedEncodingException The Character Encoding is not supported. * * @return signatureBase64 base64 encoded signature using specified secret key */ - public static String getSignature(String stringToSign, String secretKey) throws IllegalStateException, InvalidKeyException, NoSuchAlgorithmException, UnsupportedEncodingException { - Mac mac = Mac.getInstance("HmacSHA256"); - mac.init(new SecretKeySpec(secretKey.getBytes("UTF-8"), "HmacSHA256")); - byte[] signature = mac.doFinal(stringToSign.getBytes("UTF-8")); - String signatureBase64 = new String(Base64.encodeBase64(signature), "UTF-8"); + public static String getSignature(String stringToSign, char[] secretKey) throws IllegalStateException, InvalidKeyException, NoSuchAlgorithmException, UnsupportedEncodingException { + final ByteBuffer byteBuffer = Charset.forName(ServiceConstants.UTF_8).encode(CharBuffer.wrap(secretKey)); + final Mac mac = Mac.getInstance(ServiceConstants.HMAC_SHA256); + mac.init(new SecretKeySpec(Arrays.copyOf(byteBuffer.array(), byteBuffer.limit()), ServiceConstants.HMAC_SHA256)); + final byte[] signature = mac.doFinal(stringToSign.getBytes(ServiceConstants.UTF_8)); + final String signatureBase64 = new String(Base64.encodeBase64(signature), ServiceConstants.UTF_8); return signatureBase64; } @@ -106,6 +112,9 @@ public static ResponseData httpSendRequest(String method, String url, String url URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); + con.setConnectTimeout(ServiceConstants.HTTP_CONNECT_TIMEOUT); + con.setReadTimeout(ServiceConstants.HTTP_READ_TIMEOUT); + if (headers != null && !headers.isEmpty()) { for (String key : headers.keySet()) { con.setRequestProperty(key, headers.get(key)); @@ -123,9 +132,9 @@ public static ResponseData httpSendRequest(String method, String url, String url BufferedReader in; if (responseCode != 200) { - in = new BufferedReader(new InputStreamReader(con.getErrorStream())); + in = new BufferedReader(new InputStreamReader(con.getErrorStream(), "UTF-8")); } else { - in = new BufferedReader(new InputStreamReader(con.getInputStream())); + in = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8")); } String inputLine; StringBuffer response = new StringBuffer(); @@ -155,6 +164,9 @@ public static ResponseData httpSendRequest(String method, String url, String url public static ResponseData httpSendRequest(String method, String url, String urlParameters, Map headers, PayConfig config) throws IOException { Map headerMap = new HashMap(); + if (headers != null) { + headerMap.putAll(headers); + } if (config != null) { diff --git a/src/com/amazon/pay/impl/ipn/NotificationFactory.java b/src/com/amazon/pay/impl/ipn/NotificationFactory.java index 8fa5dc2..8aeac1b 100644 --- a/src/com/amazon/pay/impl/ipn/NotificationFactory.java +++ b/src/com/amazon/pay/impl/ipn/NotificationFactory.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. diff --git a/src/com/amazon/pay/impl/ipn/NotificationVerification.java b/src/com/amazon/pay/impl/ipn/NotificationVerification.java index bf8dd8f..29fb42f 100644 --- a/src/com/amazon/pay/impl/ipn/NotificationVerification.java +++ b/src/com/amazon/pay/impl/ipn/NotificationVerification.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. diff --git a/src/com/amazon/pay/request/AuthorizeOnBillingAgreementRequest.java b/src/com/amazon/pay/request/AuthorizeOnBillingAgreementRequest.java index d198ace..65c196f 100644 --- a/src/com/amazon/pay/request/AuthorizeOnBillingAgreementRequest.java +++ b/src/com/amazon/pay/request/AuthorizeOnBillingAgreementRequest.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2016-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -14,14 +14,21 @@ */ package com.amazon.pay.request; +import com.amazon.pay.response.model.ProviderCredit; import com.amazon.pay.types.CurrencyCode; import java.io.Serializable; +import java.util.List; /** * For more information documentation, see * https://pay.amazon.com/documentation/apireference/201751630#201751940 */ -public class AuthorizeOnBillingAgreementRequest implements Serializable { +public class AuthorizeOnBillingAgreementRequest extends DelegateRequest implements Serializable { + + @Override + protected AuthorizeOnBillingAgreementRequest getThis() { + return this; + } //required parameters private final String amazonBillingAgreementId; @@ -37,11 +44,11 @@ public class AuthorizeOnBillingAgreementRequest implements Serializable { private String platformId; private String sellerNote; private Boolean inheritShippingAddress; - private String sellerOrderId; private String storeName; + private String supplementaryData; private String customInformation; - private String mwsAuthToken; + private List providerCredit; /** * Constructs request for AuthorizeOnBillingAgreement operation @@ -55,7 +62,7 @@ public class AuthorizeOnBillingAgreementRequest implements Serializable { * The identifier for this authorization transaction that you specify. * This identifier must be unique for all your authorization transactions. * @param authorizationAmount - * Represents the amount to be authorized. + * Represents the amount to be authorized * */ public AuthorizeOnBillingAgreementRequest(final String amazonBillingAgreementId, final String authorizationReferenceId, final String authorizationAmount) { @@ -67,7 +74,8 @@ public AuthorizeOnBillingAgreementRequest(final String amazonBillingAgreementId, /** * @param authorizationCurrencyCode three-digit currency code * - * @return Returns a reference to this object so that methods can be chained together. + * @return Returns a reference to this object so that methods + * can be chained together. */ public AuthorizeOnBillingAgreementRequest setAuthorizationCurrencyCode(final CurrencyCode authorizationCurrencyCode){ this.authorizationCurrencyCode = authorizationCurrencyCode; @@ -76,9 +84,11 @@ public AuthorizeOnBillingAgreementRequest setAuthorizationCurrencyCode(final Cur } /** - * @param sellerAuthorizationNote description for the transaction that is displayed in emails to the buyer. + * @param sellerAuthorizationNote description for the transaction that is + * displayed in emails to the buyer. * - * @return Returns a reference to this object so that methods can be chained together. + * @return Returns a reference to this object so that methods can be + * chained together. */ public AuthorizeOnBillingAgreementRequest setSellerAuthorizationNote(final String sellerAuthorizationNote){ this.sellerAuthorizationNote = sellerAuthorizationNote; @@ -86,8 +96,9 @@ public AuthorizeOnBillingAgreementRequest setSellerAuthorizationNote(final Strin } /** - * @param TransactionTimeout The number of minutes after which the authorization will automatically be - * closed and you will not be able to capture funds against the authorization. + * @param TransactionTimeout The number of minutes after which the authorization + * will automatically be closed and you will not be + * able to capture funds against the authorization. * * @return Returns a reference to this object so that methods can be chained together. */ @@ -110,10 +121,11 @@ public AuthorizeOnBillingAgreementRequest setCaptureNow(final boolean CaptureNow } /** - * @param softDescriptor The description to be shown on the buyer's payment instrument statement - * if CaptureNow is set to true. + * @param softDescriptor The description to be shown on the buyer's payment + * instrument statement if CaptureNow is set to true. * - * @return Returns a reference to this object so that methods can be chained together. + * @return Returns a reference to this object so that methods can be chained + * together. */ public AuthorizeOnBillingAgreementRequest setSoftDescriptor(final String softDescriptor) { this.softDescriptor = softDescriptor; @@ -121,9 +133,11 @@ public AuthorizeOnBillingAgreementRequest setSoftDescriptor(final String softDes } /** - * @param sellerNote Represents a description of the order that is displayed in emails to the buyer. + * @param sellerNote Represents a description of the order that is displayed + * in emails to the buyer. * - * @return Returns a reference to this object so that methods can be chained together. + * @return Returns a reference to this object so that methods can be chained + * together. */ public AuthorizeOnBillingAgreementRequest setSellerNote(final String sellerNote) { this.sellerNote = sellerNote; @@ -131,9 +145,10 @@ public AuthorizeOnBillingAgreementRequest setSellerNote(final String sellerNote) } /** - * @param platformId Represents the SellerId of the Solution Provider that developed the platform. - * This value should only be provided by Solution Providers. It should - * not be provided by merchants creating their own custom integration. + * @param platformId Represents the SellerId of the Solution Provider that + * developed the platform. This value should only be provided + * by Solution Providers. It should not be provided by merchants + * creating their own custom integration. * * @return Returns a reference to this object so that methods can be chained together. */ @@ -145,10 +160,12 @@ public AuthorizeOnBillingAgreementRequest setPlatformId(final String platformId) /** * * - * @param sellerOrderId The merchant-specified identifier of this order. This is displayed to the - * buyer in their emails and transaction history on the Amazon Pay website. + * @param sellerOrderId The merchant-specified identifier of this order. + * This is displayed to the buyer in their emails and + * transaction history on the Amazon Pay website. * - * @return Returns a reference to this object so that methods can be chained together. + * @return Returns a reference to this object so that methods can be chained + * together. */ public AuthorizeOnBillingAgreementRequest setSellerOrderId(final String sellerOrderId) { this.sellerOrderId = sellerOrderId; @@ -167,7 +184,21 @@ public AuthorizeOnBillingAgreementRequest setStoreName(final String storeName) { } /** - * @param customInformation Sets any additional information that you want to include with this order reference. + * Set the trusted authorization supplementary data. + * Use only as directed by Amazon Pay. + * + * @param supplementaryData Trusted authorization supplementary data (JSON string) + * + * @return Request object + */ + public AuthorizeOnBillingAgreementRequest setSupplementaryData(final String supplementaryData) { + this.supplementaryData = supplementaryData; + return this; + } + + /** + * @param customInformation Sets any additional information that you want to include + * with this order reference. * * @return Returns a reference to this object so that methods can be chained together. */ @@ -200,18 +231,6 @@ public AuthorizeOnBillingAgreementRequest setInheritShippingAddress(final String Boolean.parseBoolean(inheritShippingAddress)); } - /** - * @param mwsAuthToken Sets MWSAuthToken parameter in request. MWSAuthToken is required only - * for third-party solution providers and marketplaces. Do not specify - * this parameter for merchants creating their own custom integration. - * - * @return Returns a reference to this object so that methods can be chained together. - */ - public AuthorizeOnBillingAgreementRequest setMWSAuthToken(final String mwsAuthToken) { - this.mwsAuthToken = mwsAuthToken; - return this; - } - /** * The billing agreement identifier. This value is * retrieved from the Amazon Button, AddressBook, or @@ -338,6 +357,15 @@ public String getStoreName() { return storeName; } + /** + * Returns the trusted authorization supplementary data. + * + * @return supplementaryData as a JSON string + */ + public String getSupplementaryData() { + return supplementaryData; + } + /** * Sets any additional information that you want to include with this order reference. * @@ -348,14 +376,25 @@ public String getCustomInformation() { } /** - * Returns MWSAuthToken + * Applicable for third-party solution providers only. * - * @return Returns mwsAuthToken status from request + * @return ProviderCredit associated with this operation */ - public String getMwsAuthToken() { - return mwsAuthToken; + public List getProviderCredit() { + return providerCredit; } + /** + * Applicable for third-party solution providers only. + * + * @param providerCreditList associated with this operation + * + * @return Returns a reference to this object so that methods can be chained together. + */ + public AuthorizeOnBillingAgreementRequest setProviderCredit(List providerCreditList) { + this.providerCredit = providerCreditList; + return this; + } /** * Returns a string representation of this object; useful for testing and @@ -381,8 +420,10 @@ public String toString() { + ", inheritShippingAddress=" + inheritShippingAddress + ", sellerOrderId=" + sellerOrderId + ", storeName=" + storeName + + ", supplementaryData=" + supplementaryData + ", customInformation=" + customInformation - + ", mwsAuthToken=" + mwsAuthToken + '}'; + + ", providerCredit=" + providerCredit + + ", mwsAuthToken=" + getMwsAuthToken() + '}'; } } diff --git a/src/com/amazon/pay/request/AuthorizeRequest.java b/src/com/amazon/pay/request/AuthorizeRequest.java index 840e58a..e5c4a04 100644 --- a/src/com/amazon/pay/request/AuthorizeRequest.java +++ b/src/com/amazon/pay/request/AuthorizeRequest.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -24,20 +24,24 @@ * For more information documentation, see * https://pay.amazon.com/documentation/ */ -public class AuthorizeRequest implements Serializable { +public class AuthorizeRequest extends DelegateRequest implements Serializable { + + @Override + protected AuthorizeRequest getThis() { + return this; + } //required parameters private String amazonOrderReferenceId; private String authorizationReferenceId; private String authorizationAmount; - //optonal parameters + //optional parameters private CurrencyCode authorizationCurrencyCode; private String sellerAuthorizationNote; private String transactionTimeout; private Boolean captureNow; private String softDescriptor; - private String mwsAuthToken; private List providerCredit; /* @@ -211,27 +215,6 @@ public String getSoftDescriptor() { return softDescriptor; } - /** - * @return mwsAuthToken - */ - public String getMwsAuthToken() { - return mwsAuthToken; - } - - /** - * Applicable for third-party solution providers only. - * - * @param mwsAuthToken Sets MWSAuthToken parameter in request. MWSAuthToken is required - * only for third-party solution providers and marketplaces. Do not - * specify this parameter for merchants creating their own custom integration. - * - * @return The MWSAuthToken - */ - public AuthorizeRequest setMWSAuthToken(String mwsAuthToken) { - this.mwsAuthToken = mwsAuthToken; - return this; - } - /** * Applicable for third-party solution providers only. * @@ -263,11 +246,17 @@ public AuthorizeRequest setProviderCredit(List providerCreditLis */ @Override public String toString() { - return "AuthorizeRequest{" + "amazonOrderReferenceId=" + amazonOrderReferenceId + ", authorizationReferenceId=" - + authorizationReferenceId + ", authorizationAmount=" + authorizationAmount + ", authorizationCurrencyCode=" - + authorizationCurrencyCode + ", sellerAuthorizationNote=" + sellerAuthorizationNote + ", transactionTimeout=" - + transactionTimeout + ", captureNow=" + captureNow + ", softDescriptor=" + softDescriptor + ", mwsAuthToken=" - + mwsAuthToken + ", providerCredit=" + providerCredit + '}'; + return "AuthorizeRequest{" + + "amazonOrderReferenceId=" + amazonOrderReferenceId + + ", authorizationReferenceId=" + authorizationReferenceId + + ", authorizationAmount=" + authorizationAmount + + ", authorizationCurrencyCode=" + authorizationCurrencyCode + + ", sellerAuthorizationNote=" + sellerAuthorizationNote + + ", transactionTimeout=" + transactionTimeout + + ", captureNow=" + captureNow + + ", softDescriptor=" + softDescriptor + + ", mwsAuthToken=" + getMwsAuthToken() + + ", providerCredit=" + providerCredit + '}'; } } diff --git a/src/com/amazon/pay/request/CancelOrderReferenceRequest.java b/src/com/amazon/pay/request/CancelOrderReferenceRequest.java index 4375983..3019ed3 100644 --- a/src/com/amazon/pay/request/CancelOrderReferenceRequest.java +++ b/src/com/amazon/pay/request/CancelOrderReferenceRequest.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -20,22 +20,26 @@ * For more information documentation, see * https://pay.amazon.com/documentation/ */ -public class CancelOrderReferenceRequest implements Serializable{ +public class CancelOrderReferenceRequest extends DelegateRequest implements Serializable{ + + @Override + protected CancelOrderReferenceRequest getThis() { + return this; + } //required parameters private final String amazonOrderReferenceId; //optional parameters private String cancelationReason; - private String mwsAuthToken; /* * @param amazonOrderReferenceId - * The order reference identifier. This value is retrieved - * from the Amazon Button widget after the buyer has successfully + * The order reference identifier. This value is retrieved + * from the Amazon Button widget after the buyer has successfully * authenticated with Amazon. - * - * @return CancelOrderReferenceeRequest + * + * @return CancelOrderReferenceRequest * Container holding authorize operation parameters */ public CancelOrderReferenceRequest(String amazonOrderReferenceId) { @@ -43,10 +47,10 @@ public CancelOrderReferenceRequest(String amazonOrderReferenceId) { } /** - * Optional parameter + * Optional parameter * - * @param cancelationReason Describes the reason for the cancelation. This is for - * informational purposes only and is never displayed to the customer. + * @param cancelationReason Describes the reason for the cancelation. This is for + * informational purposes only and is never displayed to the customer. * The value can be retrieved in future GetOrderReferenceDetails calls. * Maximum: 1024 characters * @@ -58,19 +62,7 @@ public CancelOrderReferenceRequest setCancelReason(String cancelationReason) { } /** - * Applicable for third-party solution providers only. - * - * @param mwsAuthToken Sets MWSAuthToken - * - * @return Returns a reference to this object so that methods can be chained together. - */ - public CancelOrderReferenceRequest setMWSAuthToken(String mwsAuthToken) { - this.mwsAuthToken = mwsAuthToken; - return this; - } - - /** - * Represents the order reference identifier. + * Represents the order reference identifier. * * @return Returns AmazonOrderReferenceId from request */ @@ -78,25 +70,16 @@ public String getAmazonOrderReferenceId() { return amazonOrderReferenceId; } - /* - * Describes the reason for the cancelation. This is for - * informational purposes only and is never displayed to the customer. - * The value can be retrieved in future GetOrderReferenceDetails calls. - * Maximum: 1024 characters - - * @return Returns cancelationReason from request - */ - public String getCancelationReason() { - return cancelationReason; - } - /** - * Applicable for third-party solution providers only. + * Describes the reason for the cancelation. This is for + * informational purposes only and is never displayed to the customer. + * The value can be retrieved in future GetOrderReferenceDetails calls. + * Maximum: 1024 characters * - * @return Returns mwsAuthToken from request + * @return Returns cancelationReason from request */ - public String getMwsAuthToken() { - return mwsAuthToken; + public String getCancelationReason() { + return cancelationReason; } /** @@ -109,10 +92,10 @@ public String getMwsAuthToken() { */ @Override public String toString() { - return "CancelOrderReferenceRequest{" + "amazonOrderReferenceId=" + amazonOrderReferenceId + ", cancelationReason=" - + cancelationReason + ", mwsAuthToken=" + mwsAuthToken + '}'; + return "CancelOrderReferenceRequest{" + + "amazonOrderReferenceId=" + amazonOrderReferenceId + + ", cancelationReason=" + cancelationReason + + ", mwsAuthToken=" + getMwsAuthToken() + '}'; } - - } diff --git a/src/com/amazon/pay/request/CaptureRequest.java b/src/com/amazon/pay/request/CaptureRequest.java index 67a88c7..cfa2dd1 100644 --- a/src/com/amazon/pay/request/CaptureRequest.java +++ b/src/com/amazon/pay/request/CaptureRequest.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -15,16 +15,21 @@ package com.amazon.pay.request; import com.amazon.pay.types.CurrencyCode; -import java.util.*; import com.amazon.pay.response.model.ProviderCredit; import java.io.Serializable; +import java.util.List; /** * For more information documentation, see * https://pay.amazon.com/documentation/ */ -public class CaptureRequest implements Serializable { +public class CaptureRequest extends DelegateRequest implements Serializable { + + @Override + protected CaptureRequest getThis() { + return this; + } //required parameters private String amazonAuthorizationId; @@ -35,7 +40,6 @@ public class CaptureRequest implements Serializable { //optional parameters private String sellerCaptureNote; private String softDescriptor; - private String mwsAuthToken; private List providerCredit; /* @@ -91,20 +95,6 @@ public CaptureRequest setSoftDescriptor(String softDescriptor) { return this; } - /** - * Applicable for third-party solution providers only. - * - * @param mwsAuthToken Sets MWSAuthToken parameter in request. MWSAuthToken is required - * only for third-party solution providers and marketplaces. Do not - * specify this parameter for merchants creating their own custom integration. - * - * @return Returns a reference to this object so that methods can be chained together. - */ - public CaptureRequest setMWSAuthToken(String mwsAuthToken) { - this.mwsAuthToken = mwsAuthToken; - return this; - } - /** * Applicable for third-party solution providers only. * @@ -174,15 +164,6 @@ public String getSoftDescriptor() { return softDescriptor; } - /** - * Applicable for third-party solution providers only - * - * @return mwsAuthToken for Capture operation - */ - public String getMwsAuthToken() { - return mwsAuthToken; - } - /** * Applicable for third-party solution providers only. * @@ -202,11 +183,15 @@ public List getProviderCredit() { */ @Override public String toString() { - return "CaptureRequest{" + "amazonAuthorizationId=" + amazonAuthorizationId + ", captureReferenceId=" + captureReferenceId + ", captureAmount=" - + captureAmount + ", captureCurrencyCode=" + captureCurrencyCode + ", sellerCaptureNote=" + sellerCaptureNote + ", softDescriptor=" - + softDescriptor + ", mwsAuthToken=" + mwsAuthToken + ", providerCredit=" + providerCredit + '}'; + return "CaptureRequest{" + + "amazonAuthorizationId=" + amazonAuthorizationId + + ", captureReferenceId=" + captureReferenceId + + ", captureAmount=" + captureAmount + + ", captureCurrencyCode=" + captureCurrencyCode + + ", sellerCaptureNote=" + sellerCaptureNote + + ", softDescriptor=" + softDescriptor + + ", mwsAuthToken=" + getMwsAuthToken() + + ", providerCredit=" + providerCredit + '}'; } - - } diff --git a/src/com/amazon/pay/request/ChargeRequest.java b/src/com/amazon/pay/request/ChargeRequest.java index 19c286b..793d373 100644 --- a/src/com/amazon/pay/request/ChargeRequest.java +++ b/src/com/amazon/pay/request/ChargeRequest.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -27,7 +27,12 @@ * https://pay.amazon.com/documentation/ */ -public class ChargeRequest implements Serializable { +public class ChargeRequest extends DelegateRequest implements Serializable { + + @Override + protected ChargeRequest getThis() { + return this; + } //required parameters private String amazonReferenceId; @@ -45,7 +50,6 @@ public class ChargeRequest implements Serializable { //optional parameters private String sellerNote; private String softDescriptor; - private String mwsAuthToken; private Boolean inheritShippingAddress; @@ -313,18 +317,6 @@ public ChargeRequest withProviderCreditDetails(final List provid } - /** - * Sets the mwsAuthToken in ChargeRequest - * - * @param mwsAuthToken Sets the mwsAuthToken in ChargeRequest - * - * @return Returns a reference to this object so that methods can be chained together. - */ - public ChargeRequest withMWSAuthToken(final String mwsAuthToken) { - this.mwsAuthToken = mwsAuthToken; - return this; - } - /** * The identifier for this Amazon Pay transaction that you specify. * @@ -442,15 +434,6 @@ public String getSoftDescriptor() { return softDescriptor; } - /** - * The MWSAuthToken set in the request - * - * @return MWSAuthToken specified in request - */ - public String getMwsAuthToken() { - return mwsAuthToken; - } - /** * The ProviderCredit set in the request * @@ -484,7 +467,7 @@ public String toString() { + ", platformId=" + platformId + ", sellerNote=" + sellerNote + ", softDescriptor=" + softDescriptor - + ", mwsAuthToken=" + mwsAuthToken + + ", mwsAuthToken=" + getMwsAuthToken() + ", inheritShippingAddress=" + inheritShippingAddress + ", providerCredit=" + providerCredit + '}'; } diff --git a/src/com/amazon/pay/request/CloseAuthorizationRequest.java b/src/com/amazon/pay/request/CloseAuthorizationRequest.java index cc79bd3..3fcc428 100644 --- a/src/com/amazon/pay/request/CloseAuthorizationRequest.java +++ b/src/com/amazon/pay/request/CloseAuthorizationRequest.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -22,19 +22,23 @@ * For more information documentation, see * https://pay.amazon.com/documentation/ */ -public class CloseAuthorizationRequest implements Serializable{ +public class CloseAuthorizationRequest extends DelegateRequest implements Serializable { + + @Override + protected CloseAuthorizationRequest getThis() { + return this; + } //required parameters private String amazonAuthorizationId; //optional parameters private String closureReason; - private String mwsAuthToken; /** * * @param amazonAuthorizationId - * The authorization identifier that was generated by Amazon + * The authorization identifier that was generated by Amazon * in the earlier call to Authorize. * */ @@ -55,21 +59,7 @@ public CloseAuthorizationRequest setClosureReason(String closureReason) { } /** - * Applicable for third-party solution providers only. - * - * @param mwsAuthToken Sets MWSAuthToken parameter in request. MWSAuthToken is required - * only for third-party solution providers and marketplaces. Do not - * specify this parameter for merchants creating their own custom integration. - * - * @return MWSAuthToken - */ - public CloseAuthorizationRequest setMWSAuthToken(String mwsAuthToken) { - this.mwsAuthToken = mwsAuthToken; - return this; - } - - /** - * The authorization identifier that was generated by Amazon + * The authorization identifier that was generated by Amazon * in the earlier call to Authorize. * * @return AmazonAuthorizationId specified in request @@ -87,15 +77,6 @@ public String getClosureReason() { return closureReason; } - /** - * Applicable for third-party solution providers only. - * - * @return MWSAuthToken specified in request - */ - public String getMwsAuthToken() { - return mwsAuthToken; - } - /** * Returns a string representation of this object; useful for testing and * debugging. @@ -106,9 +87,10 @@ public String getMwsAuthToken() { */ @Override public String toString() { - return "CloseAuthorizationRequest{" + "amazonAuthorizationId=" + amazonAuthorizationId + ", closureReason=" + closureReason + ", mwsAuthToken=" - + mwsAuthToken + '}'; + return "CloseAuthorizationRequest{" + + "amazonAuthorizationId=" + amazonAuthorizationId + + ", closureReason=" + closureReason + + ", mwsAuthToken=" + getMwsAuthToken() + '}'; } - } diff --git a/src/com/amazon/pay/request/CloseBillingAgreementRequest.java b/src/com/amazon/pay/request/CloseBillingAgreementRequest.java index ea009e1..b959a41 100644 --- a/src/com/amazon/pay/request/CloseBillingAgreementRequest.java +++ b/src/com/amazon/pay/request/CloseBillingAgreementRequest.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -22,19 +22,23 @@ * For more information documentation, see * https://pay.amazon.com/documentation/ */ -public class CloseBillingAgreementRequest implements Serializable{ +public class CloseBillingAgreementRequest extends DelegateRequest implements Serializable { + + @Override + protected CloseBillingAgreementRequest getThis() { + return this; + } //required parameters private String amazonBillingAgreementId; //optional parameters private String closureReason; - private String mwsAuthToken; /** * * @param amazonBillingAgreementId - * The billing agreement identifier. This value is retrieved + * The billing agreement identifier. This value is retrieved * from the Amazon Button, AddressBook, or Wallet widgets. */ public CloseBillingAgreementRequest(String amazonBillingAgreementId) { @@ -53,22 +57,9 @@ public CloseBillingAgreementRequest setClosureReason(String closureReason) { } /** - * Applicable for third-party solution providers only. - * @param mwsAuthToken Sets MWSAuthToken parameter in request. MWSAuthToken is required - * only for third-party solution providers and marketplaces. Do not - * specify this parameter for merchants creating their own custom integration. - * - * @return The MWSAuthToken - */ - public CloseBillingAgreementRequest setMWSAuthToken(String mwsAuthToken) { - this.mwsAuthToken = mwsAuthToken; - return this; - } - - /** - * The billing agreement identifier. This value is retrieved + * The billing agreement identifier. This value is retrieved * from the Amazon Button, AddressBook, or Wallet widgets. - * @return AmazonBillingAgreementId specified in request + * @return AmazonBillingAgreementId specified in request */ public String getAmazonBillingAgreementId() { return amazonBillingAgreementId; @@ -82,14 +73,6 @@ public String getClosureReason() { return closureReason; } - /** - * - * @return MWSAuthToken specified in request - */ - public String getMwsAuthToken() { - return mwsAuthToken; - } - /** * Returns a string representation of this object; useful for testing and * debugging. @@ -100,9 +83,10 @@ public String getMwsAuthToken() { */ @Override public String toString() { - return "CloseBillingAgreementRequest{" + "amazonBillingAgreementId=" + amazonBillingAgreementId + ", closureReason=" - + closureReason + ", mwsAuthToken=" + mwsAuthToken + '}'; + return "CloseBillingAgreementRequest{" + + "amazonBillingAgreementId=" + amazonBillingAgreementId + + ", closureReason=" + closureReason + + ", mwsAuthToken=" + getMwsAuthToken() + '}'; } - } diff --git a/src/com/amazon/pay/request/CloseOrderReferenceRequest.java b/src/com/amazon/pay/request/CloseOrderReferenceRequest.java index cf90b9f..3b97108 100644 --- a/src/com/amazon/pay/request/CloseOrderReferenceRequest.java +++ b/src/com/amazon/pay/request/CloseOrderReferenceRequest.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -16,20 +16,23 @@ import java.io.Serializable; - /** * Container for the parameters to the CloseOrderReference operation. * For more information documentation, see * https://pay.amazon.com/documentation/ */ -public class CloseOrderReferenceRequest implements Serializable{ +public class CloseOrderReferenceRequest extends DelegateRequest implements Serializable { + + @Override + protected CloseOrderReferenceRequest getThis() { + return this; + } //required parameters private String amazonOrderReferenceId; //optional parameters private String closureReason; - private String mwsAuthToken; /** * @param amazonOrderReferenceId @@ -50,18 +53,6 @@ public CloseOrderReferenceRequest setClosureReason(String closureReason) { return this; } - /** - * @param mwsAuthToken Sets MWSAuthToken parameter in request. MWSAuthToken is required - * only for third-party solution providers and marketplaces. Do not - * specify this parameter for merchants creating their own custom integration. - * - * @return The MWSAuthToken - */ - public CloseOrderReferenceRequest setMWSAuthToken(String mwsAuthToken) { - this.mwsAuthToken = mwsAuthToken; - return this; - } - /** * The ID of the order reference for which the details are being requested. * @@ -79,16 +70,6 @@ public String getClosureReason() { return closureReason; } - /** - * Represents the MWSAuthToken parameter in request. MWSAuthToken is required only for third-party solution providers - * and marketplaces. Do not specify this parameter for merchants creating their own custom integration. - - * @return MWSAuthToken - */ - public String getMwsAuthToken() { - return mwsAuthToken; - } - /** * Returns a string representation of this object; useful for testing and * debugging. @@ -99,9 +80,10 @@ public String getMwsAuthToken() { */ @Override public String toString() { - return "CloseOrderReferenceRequest{" + "amazonOrderReferenceId=" + amazonOrderReferenceId + ", closureReason=" + closureReason + ", mwsAuthToken=" - + mwsAuthToken + '}'; + return "CloseOrderReferenceRequest{" + + "amazonOrderReferenceId=" + amazonOrderReferenceId + + ", closureReason=" + closureReason + + ", mwsAuthToken=" + getMwsAuthToken() + '}'; } - } diff --git a/src/com/amazon/pay/request/ConfirmBillingAgreementRequest.java b/src/com/amazon/pay/request/ConfirmBillingAgreementRequest.java index be34e5e..7263af4 100644 --- a/src/com/amazon/pay/request/ConfirmBillingAgreementRequest.java +++ b/src/com/amazon/pay/request/ConfirmBillingAgreementRequest.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2016-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -22,13 +22,19 @@ * For more information documentation, see * https://pay.amazon.com/documentation/ */ -public class ConfirmBillingAgreementRequest implements Serializable{ +public class ConfirmBillingAgreementRequest extends DelegateRequest implements Serializable { + + @Override + protected ConfirmBillingAgreementRequest getThis() { + return this; + } //required parameters private String amazonBillingAgreementId; //optional parameters - private String mwsAuthToken; + private String successUrl; + private String failureUrl; /** * @@ -40,33 +46,52 @@ public ConfirmBillingAgreementRequest(String amazonBillingAgreementId) { } /** - * Applicable for third-party solution providers only - * @param mwsAuthToken Sets MWSAuthToken parameter in request. MWSAuthToken is required - * only for third-party solution providers and marketplaces. Do not - * specify this parameter for merchants creating their own custom integration. + * The billing agreement identifier. + * + * @return Returns AmazonBillingAgreementId from request + */ + public String getAmazonBillingAgreementId() { + return amazonBillingAgreementId; + } + + /** + * Sets the URL where AmazonPay need to return after buyer successfully authenticate a transaction. + * @param successUrl After Successful authentication AmazonPay redirects + * to the SuccessUrl provided by the merchant * - * @return The MWSAuthToken + * @return Success Url */ - public ConfirmBillingAgreementRequest setMWSAuthToken(String mwsAuthToken) { - this.mwsAuthToken = mwsAuthToken; + public ConfirmBillingAgreementRequest setSuccessUrl(String successUrl) { + this.successUrl = successUrl; return this; } /** - * The billing agreement identifier. + * Sets the URL where AmazonPay need to return after buyer fails to authenticate a transaction. + * @param failureUrl If the buyer failed to provide correct Authentication AmazonPay redirects + * to FailureUrl provided by the merchant. * - * @return Returns AmazonBillingAgreementId from request + * @return Failure Url */ - public String getAmazonBillingAgreementId() { - return amazonBillingAgreementId; + public ConfirmBillingAgreementRequest setFailureUrl(String failureUrl) { + this.failureUrl = failureUrl; + return this; } /** - * Applicable for third-party solution providers only - * @return Returns mwsAuthToken from request + * + * @return successUrl */ - public String getMwsAuthToken() { - return mwsAuthToken; + public String getSuccessUrl() { + return successUrl; + } + + /** + * + * @return failureUrl + */ + public String getFailureUrl() { + return failureUrl; } /** @@ -79,8 +104,11 @@ public String getMwsAuthToken() { */ @Override public String toString() { - return "ConfirmBillingAgreementRequest{" + "amazonBillingAgreementId=" + amazonBillingAgreementId + ", mwsAuthToken=" + mwsAuthToken + '}'; + return "ConfirmBillingAgreementRequest{" + + "amazonBillingAgreementId=" + amazonBillingAgreementId + + ", successUrl=" + successUrl + + ", failureUrl=" + failureUrl + + ", mwsAuthToken=" + getMwsAuthToken() + '}'; } - } diff --git a/src/com/amazon/pay/request/ConfirmOrderReferenceRequest.java b/src/com/amazon/pay/request/ConfirmOrderReferenceRequest.java index e975be8..6dfb20c 100644 --- a/src/com/amazon/pay/request/ConfirmOrderReferenceRequest.java +++ b/src/com/amazon/pay/request/ConfirmOrderReferenceRequest.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2016-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -14,6 +14,7 @@ */ package com.amazon.pay.request; +import com.amazon.pay.types.CurrencyCode; import java.io.Serializable; /** @@ -22,49 +23,152 @@ * For more information documentation, see * https://pay.amazon.com/documentation/ */ -public class ConfirmOrderReferenceRequest implements Serializable{ +public class ConfirmOrderReferenceRequest extends DelegateRequest implements Serializable { + + @Override + protected ConfirmOrderReferenceRequest getThis() { + return this; + } //required parameters private String amazonOrderReferenceId; //optional parameters - private String mwsAuthToken; + private String successUrl; + private String failureUrl; + private String authorizationAmount; + private CurrencyCode authorizationCurrencyCode; + private Boolean expectImmediateAuthorization; /** - * + * Constructor requires an order reference identifier. * @param amazonOrderReferenceId The order reference identifier. */ - public ConfirmOrderReferenceRequest(String amazonOrderReferenceId){ + public ConfirmOrderReferenceRequest(String amazonOrderReferenceId) { this.amazonOrderReferenceId = amazonOrderReferenceId; } /** + * The order reference identifier. * - * @param mwsAuthToken Sets MWSAuthToken parameter in request. MWSAuthToken is required - * only for third-party solution providers and marketplaces. Do not - * specify this parameter for merchants creating their own custom integration. + * @return AmazonOrderReferenceId + */ + public String getAmazonOrderReferenceId() { + return amazonOrderReferenceId; + } + + /** + * @param currencyCode + * Three-digit currency code. In ISO 4217 format. * - * @return The MWSAuthToken + * @return ConfirmOrderReferenceRequest + * Container holding Confirm Order Reference operation parameters */ - public ConfirmOrderReferenceRequest setMWSAuthToken(String mwsAuthToken) { - this.mwsAuthToken = mwsAuthToken; + public ConfirmOrderReferenceRequest setAuthorizationCurrencyCode(final CurrencyCode currencyCode) { + this.authorizationCurrencyCode = currencyCode; return this; } /** + * Represents currency code for Confirm Order Reference request * - * @return AmazonOrderReferenceId + * @return CurrencyCode + * Enum representing three-character currency code (ISO 4217) */ - public String getAmazonOrderReferenceId() { - return amazonOrderReferenceId; + public CurrencyCode getAuthorizationCurrencyCode() { + return authorizationCurrencyCode; + } + + /** + * @param authorizationAmount + * The amount to authorize during MFA completion. + * Use this parameter if you want to set a payment + * amount that is different than the OrderTotal + * provided in the SetOrderReferenceDetails + * operation call. + * + * If this parameter is not set, the amount authorized + * during MFA will be equal to the OrderTotal. + * + * @return ConfirmOrderReferenceRequest + * Container holding Confirm Order Reference operation parameters + */ + public ConfirmOrderReferenceRequest setAuthorizationAmount(final String authorizationAmount) { + this.authorizationAmount = authorizationAmount; + return this; } /** + * Represents the amount to be authorized during MFA completion. * - * @return MWSAuthToken + * @return String */ - public String getMwsAuthToken() { - return mwsAuthToken; + public String getAuthorizationAmount() { + return authorizationAmount; + } + + /** + * @param successUrl + * The buyer is redirected to this URL if the MFA is successful. + * + * @return ConfirmOrderReferenceRequest + * Container holding Confirm Order Reference operation parameters + */ + public ConfirmOrderReferenceRequest setSuccessUrl(final String successUrl) { + this.successUrl = successUrl; + return this; + } + + /** + * Represents the URL buyer is redirected to when MFA is successful. + * + * @return String + */ + public String getSuccessUrl() { + return successUrl; + } + + /** + * @param failureUrl + * The buyer is redirected to this URL if the MFA is not successful. + * + * @return ConfirmOrderReferenceRequest + * Container holding Confirm Order Reference operation parameters + */ + public ConfirmOrderReferenceRequest setFailureUrl(final String failureUrl) { + this.failureUrl = failureUrl; + return this; + } + + /** + * Represents the URL buyer is redirected to when MFA is not successful. + * + * @return String + */ + public String getFailureUrl() { + return failureUrl; + } + + /** + * The ExpectImmediateAuthorization set in the request + * + * @return Boolean + */ + public Boolean isExpectImmediateAuthorization() { + return expectImmediateAuthorization; + } + + /** + * Sets the ExpectImmediateAuthorization in ConfirmOrderReference + * + * @param expectImmediateAuthorization Sets the expectImmediateAuthorization in ConfirmOrderReference + * + * @return ConfirmOrderReferenceRequest + * Container holding Confirm Order Reference operation parameters + */ + public ConfirmOrderReferenceRequest setExpectImmediateAuthorization(Boolean expectImmediateAuthorization) { + this.expectImmediateAuthorization = expectImmediateAuthorization; + return this; } /** @@ -77,7 +181,14 @@ public String getMwsAuthToken() { */ @Override public String toString() { - return "ConfirmOrderReferenceRequest{" + "amazonOrderReferenceId=" + amazonOrderReferenceId + ", mwsAuthToken=" + mwsAuthToken + '}'; + return "ConfirmOrderReferenceRequest{" + + "amazonOrderReferenceId=" + amazonOrderReferenceId + + ", authorizationAmount=" + authorizationAmount + + ", authorizationCurrencyCode=" + authorizationCurrencyCode + + ", successUrl=" + successUrl + + ", failureUrl=" + failureUrl + + ", mwsAuthToken=" + getMwsAuthToken() + + ", expectImmediateAuthorize=" + isExpectImmediateAuthorization() +'}'; } } diff --git a/src/com/amazon/pay/request/CreateOrderReferenceForIdRequest.java b/src/com/amazon/pay/request/CreateOrderReferenceForIdRequest.java index 9974af9..294a81f 100644 --- a/src/com/amazon/pay/request/CreateOrderReferenceForIdRequest.java +++ b/src/com/amazon/pay/request/CreateOrderReferenceForIdRequest.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -23,20 +23,25 @@ * For more information documentation, see * https://pay.amazon.com/documentation/ */ -public class CreateOrderReferenceForIdRequest implements Serializable { +public class CreateOrderReferenceForIdRequest extends DelegateRequest implements Serializable { + + @Override + protected CreateOrderReferenceForIdRequest getThis() { + return this; + } //required parameters private String id; private AmazonReferenceIdType idType; //optonal parameters - private String mwsAuthToken; private Boolean inheritShippingAddress; private Boolean confirmNow; private CurrencyCode orderTotalCurrencyCode; private String sellerNote; private String sellerOrderId; private String storeName; + private String supplementaryData; private String customInformation; //conditionally required @@ -92,30 +97,6 @@ public AmazonReferenceIdType getIdType() { return idType; } - /** - * Represents the authorization of a specific developer by a specific Amazon seller. - * Required For web applications and third-party developer authorizations only. - * - * @param mwsAuthToken - * The authorization token that you received when you registered for Amazon MWS. - * @return CreateOrderReferenceForIdRequest - * Container holding CreateOrderReferenceForId operation parameters - */ - public CreateOrderReferenceForIdRequest setMWSAuthToken(final String mwsAuthToken) { - this.mwsAuthToken = mwsAuthToken; - return this; - } - - /** - * Represents the authorization of a specific developer by a specific Amazon seller. - * Required For web applications and third-party developer authorizations only. - * - * @return MWSAuthToken - */ - public String getMwsAuthToken() { - return mwsAuthToken; - } - /** * Specifies whether to inherit the shipping address details from * the object represented by the Id request parameter. @@ -316,6 +297,28 @@ public String getStoreName() { return storeName; } + /** + * Set the trusted authorization supplementary data. + * Use only as directed by Amazon Pay. + * + * @param supplementaryData Trusted authorization supplementary data (JSON string) + * + * @return Request object + */ + public CreateOrderReferenceForIdRequest setSupplementaryData(final String supplementaryData) { + this.supplementaryData = supplementaryData; + return this; + } + + /** + * Returns the trusted authorization supplementary data. + * + * @return supplementaryData as a JSON string + */ + public String getSupplementaryData() { + return supplementaryData; + } + /** * Any additional information that you want to include with this order reference. * @param customInformation @@ -361,6 +364,7 @@ public String toString() { ", sellerNote=" + sellerNote + ", sellerOrderId=" + sellerOrderId + ", storeName=" + storeName + + ", supplementaryData=" + supplementaryData + ", customInformation=" + customInformation + "}"; } diff --git a/src/com/amazon/pay/request/DelegateRequest.java b/src/com/amazon/pay/request/DelegateRequest.java new file mode 100644 index 0000000..5112228 --- /dev/null +++ b/src/com/amazon/pay/request/DelegateRequest.java @@ -0,0 +1,80 @@ +/** + * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package com.amazon.pay.request; + +public abstract class DelegateRequest> { + + private String mwsAuthToken; + private String sellerId; + + protected abstract T getThis(); + + /** + * Returns the MWS Auth Token + * + * @return mwsAuthToken + */ + public String getMwsAuthToken() { + return mwsAuthToken; + } + + /** + * @param mwsAuthToken Sets MWSAuthToken parameter in request. MWSAuthToken is required + * only for third-party solution providers and marketplaces. Do not + * specify this parameter for merchants creating their own custom integration. + * + * @return The subclass object + */ + public T setMWSAuthToken(String mwsAuthToken) { + this.mwsAuthToken = mwsAuthToken; + return getThis(); + } + + /** + * @param mwsAuthToken Sets MWSAuthToken parameter in request. MWSAuthToken is required + * only for third-party solution providers and marketplaces. Do not + * specify this parameter for merchants creating their own custom integration. + * Does same thing as setMWSAuthToken. + * + * @return The subclass object + */ + public T withMWSAuthToken(String mwsAuthToken) { + this.mwsAuthToken = mwsAuthToken; + return getThis(); + } + + /** + * Returns the request-specific sellerId + * + * @return sellerId + */ + public String getSellerId() { + return sellerId; + } + + /** + * @param sellerId Sets request-specific merchant ID in order to override any merchant ID + * supplied from the Config object. This is useful for third-party solution + * providers that deal with hundreds or thousands of merchant ID's at the + * same time and do not want to contruct a new Config object for each request. + * + * @return The subclass object + */ + public T setSellerId(String sellerId) { + this.sellerId = sellerId; + return getThis(); + } + +} diff --git a/src/com/amazon/pay/request/GetAuthorizationDetailsRequest.java b/src/com/amazon/pay/request/GetAuthorizationDetailsRequest.java index 7f17dbf..00cc983 100644 --- a/src/com/amazon/pay/request/GetAuthorizationDetailsRequest.java +++ b/src/com/amazon/pay/request/GetAuthorizationDetailsRequest.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -22,36 +22,26 @@ * For more information documentation, see * https://pay.amazon.com/documentation/ */ -public class GetAuthorizationDetailsRequest implements Serializable{ +public class GetAuthorizationDetailsRequest extends DelegateRequest implements Serializable { + + @Override + protected GetAuthorizationDetailsRequest getThis() { + return this; + } //required parameters private String amazonAuthorizationId; - //optional parameters - private String mwsAuthToken; - /** * * @param amazonAuthorizationId - * The authorization identifier that was generated + * The authorization identifier that was generated * by Amazon in the earlier call to Authorize. */ public GetAuthorizationDetailsRequest(String amazonAuthorizationId) { this.amazonAuthorizationId = amazonAuthorizationId; } - /** - * @param mwsAuthToken Sets MWSAuthToken parameter in request. MWSAuthToken is required - * only for third-party solution providers and marketplaces. Do not - * specify this parameter for merchants creating their own custom integration. - * - * @return The MWSAuthToken - */ - public GetAuthorizationDetailsRequest setMWSAuthToken(String mwsAuthToken) { - this.mwsAuthToken = mwsAuthToken; - return this; - } - /** * @return AmazonAuthorizationId */ @@ -59,13 +49,6 @@ public String getAmazonAuthorizationId() { return amazonAuthorizationId; } - /** - * @return MWSAuthToken - */ - public String getMwsAuthToken() { - return mwsAuthToken; - } - /** * Returns a string representation of this object; useful for testing and * debugging. @@ -76,9 +59,9 @@ public String getMwsAuthToken() { */ @Override public String toString() { - return "GetAuthorizationDetailsRequest{" + "amazonAuthorizationId=" + amazonAuthorizationId + ", mwsAuthToken=" + mwsAuthToken + '}'; + return "GetAuthorizationDetailsRequest{" + + "amazonAuthorizationId=" + amazonAuthorizationId + + ", mwsAuthToken=" + getMwsAuthToken() + '}'; } - - } diff --git a/src/com/amazon/pay/request/GetBillingAgreementDetailsRequest.java b/src/com/amazon/pay/request/GetBillingAgreementDetailsRequest.java index 9c50f66..fb3f70b 100644 --- a/src/com/amazon/pay/request/GetBillingAgreementDetailsRequest.java +++ b/src/com/amazon/pay/request/GetBillingAgreementDetailsRequest.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -23,43 +23,34 @@ * For more information documentation, see * https://pay.amazon.com/documentation/ */ -public class GetBillingAgreementDetailsRequest implements Serializable{ +public class GetBillingAgreementDetailsRequest extends DelegateRequest implements Serializable { + + @Override + protected GetBillingAgreementDetailsRequest getThis() { + return this; + } //required parameters private String amazonBillingAgreementId; //optional parameters private String addressConsentToken; - private String mwsAuthToken; /** * * @param amazonBillingAgreementId - * The billing agreement identifier. This value is retrieved + * The billing agreement identifier. This value is retrieved * from the Amazon Button, AddressBook, or Wallet widgets. */ public GetBillingAgreementDetailsRequest(String amazonBillingAgreementId) { this.amazonBillingAgreementId = amazonBillingAgreementId; } - /** - * - * @param mwsAuthToken Sets MWSAuthToken parameter in request. MWSAuthToken is required - * only for third-party solution providers and marketplaces. Do not - * specify this parameter for merchants creating their own custom integration. - * - * @return The MWSAuthToken - */ - public GetBillingAgreementDetailsRequest setMWSAuthToken(String mwsAuthToken) { - this.mwsAuthToken = mwsAuthToken; - return this; - } - /** * * @param addressConsentToken - * The buyer address consent token. You must provide a valid - * AddressConsentToken if you want to get the full shipping address before + * The buyer address consent token. You must provide a valid + * AddressConsentToken if you want to get the full shipping address before * the billing agreement is confirmed. * @return AddressConsentToken */ @@ -84,14 +75,6 @@ public String getAddressConsentToken() { return addressConsentToken; } - /** - * - * @return MWSAuthToken - */ - public String getMwsAuthToken() { - return mwsAuthToken; - } - /** * Returns a string representation of this object; useful for testing and * debugging. @@ -102,9 +85,10 @@ public String getMwsAuthToken() { */ @Override public String toString() { - return "GetBillingAgreementDetailsRequest{" + "amazonBillingAgreementId=" + amazonBillingAgreementId + ", addressConsentToken=" - + addressConsentToken + ", mwsAuthToken=" + mwsAuthToken + '}'; + return "GetBillingAgreementDetailsRequest{" + + "amazonBillingAgreementId=" + amazonBillingAgreementId + + ", addressConsentToken=" + addressConsentToken + + ", mwsAuthToken=" + getMwsAuthToken() + '}'; } - } diff --git a/src/com/amazon/pay/request/GetCaptureDetailsRequest.java b/src/com/amazon/pay/request/GetCaptureDetailsRequest.java index 0cbfbd7..379f506 100644 --- a/src/com/amazon/pay/request/GetCaptureDetailsRequest.java +++ b/src/com/amazon/pay/request/GetCaptureDetailsRequest.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -22,10 +22,14 @@ * For more information documentation, see * https://pay.amazon.com/documentation/ */ -public class GetCaptureDetailsRequest implements Serializable{ +public class GetCaptureDetailsRequest extends DelegateRequest implements Serializable { + + @Override + protected GetCaptureDetailsRequest getThis() { + return this; + } private String amazonCaptureId; - private String mwsAuthToken; /** * @param amazonCaptureId The capture identifier that was generated by Amazon @@ -35,20 +39,6 @@ public GetCaptureDetailsRequest(String amazonCaptureId) { this.amazonCaptureId = amazonCaptureId; } - /** - * Set the value of mwsAuthToken - * - * @param mwsAuthToken Sets MWSAuthToken parameter in request. MWSAuthToken is required - * only for third-party solution providers and marketplaces. Do not - * specify this parameter for merchants creating their own custom integration. - * - * @return The MWSAuthToken - */ - public GetCaptureDetailsRequest setMWSAuthToken(String mwsAuthToken) { - this.mwsAuthToken = mwsAuthToken; - return this; - } - /** * *@return return the value of AmazonCaptureId @@ -57,14 +47,6 @@ public String getAmazonCaptureId() { return amazonCaptureId; } - /** - * - * @return mwsAuthToken Get the value of mwsAuthToken - */ - public String getMwsAuthToken() { - return mwsAuthToken; - } - /** * Returns a string representation of this object; useful for testing and * debugging. @@ -75,7 +57,9 @@ public String getMwsAuthToken() { */ @Override public String toString() { - return "GetCaptureDetailsRequest{" + "amazonCaptureId=" + amazonCaptureId + ", mwsAuthToken=" + mwsAuthToken + '}'; + return "GetCaptureDetailsRequest{" + + "amazonCaptureId=" + amazonCaptureId + + ", mwsAuthToken=" + getMwsAuthToken() + '}'; } } diff --git a/src/com/amazon/pay/request/GetMerchantAccountStatusRequest.java b/src/com/amazon/pay/request/GetMerchantAccountStatusRequest.java new file mode 100644 index 0000000..e8ae595 --- /dev/null +++ b/src/com/amazon/pay/request/GetMerchantAccountStatusRequest.java @@ -0,0 +1,46 @@ +/** + * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package com.amazon.pay.request; + +import java.io.Serializable; + +/** + * Container for the parameters to the GetMerchantAccountStatusRequest operation. + * For more information documentation, see + * https://pay.amazon.com/documentation/ + */ +public class GetMerchantAccountStatusRequest extends DelegateRequest implements Serializable { + + @Override + protected GetMerchantAccountStatusRequest getThis() { + return this; + } + + /** + * Returns a string representation of this object; useful for testing and + * debugging. + * + * @return A string representation of this object. + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "GetMerchantAccountStatusRequest{" + + "sellerId=" + getSellerId() + + ", mwsAuthToken=" + getMwsAuthToken() + '}'; + } + +} diff --git a/src/com/amazon/pay/request/GetOrderReferenceDetailsRequest.java b/src/com/amazon/pay/request/GetOrderReferenceDetailsRequest.java index 5a3a871..2583054 100644 --- a/src/com/amazon/pay/request/GetOrderReferenceDetailsRequest.java +++ b/src/com/amazon/pay/request/GetOrderReferenceDetailsRequest.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -23,19 +23,23 @@ * For more information documentation, see * https://pay.amazon.com/documentation/ */ -public class GetOrderReferenceDetailsRequest implements Serializable { +public class GetOrderReferenceDetailsRequest extends DelegateRequest implements Serializable { + + @Override + protected GetOrderReferenceDetailsRequest getThis() { + return this; + } private String amazonOrderReferenceId; private String accessToken; - private String mwsAuthToken; @Deprecated private String addressConsentToken; /** * - * @param amazonOrderReferenceId The order reference identifier. - * This value is retrieved from the Amazon Button widget + * @param amazonOrderReferenceId The order reference identifier. + * This value is retrieved from the Amazon Button widget * after the buyer has successfully authenticated with Amazon. */ public GetOrderReferenceDetailsRequest(String amazonOrderReferenceId) { @@ -44,8 +48,8 @@ public GetOrderReferenceDetailsRequest(String amazonOrderReferenceId) { /** * - * @param addressConsentToken The buyer address consent token. This value is retrieved - * from the Amazon Button widget after the buyer has + * @param addressConsentToken The buyer address consent token. This value is retrieved + * from the Amazon Button widget after the buyer has * successfully authenticated with Amazon. * * @return AddressConsentToken @@ -86,21 +90,6 @@ public String getAccessToken() { return this.accessToken; } - - /** - * Sets MWSAuthToken parameter in request. MWSAuthToken is required only for third-party solution providers - * and marketplaces. Do not specify this parameter for merchants creating their own custom integration. - * - * @param mwsAuthToken new value of mwsAuthToken - * - * @return The MWSAuthToken - */ - public GetOrderReferenceDetailsRequest setMWSAuthToken(String mwsAuthToken) { - this.mwsAuthToken = mwsAuthToken; - return this; - } - - /** * * @return AmazonOrderReferenceId @@ -109,14 +98,6 @@ public String getAmazonOrderReferenceId() { return amazonOrderReferenceId; } - /** - * - * @return MWSAuthToken - */ - public String getMwsAuthToken() { - return mwsAuthToken; - } - /** * Returns a string representation of this object; useful for testing and * debugging. @@ -130,6 +111,6 @@ public String toString() { return "GetOrderReferenceDetailsRequest{" + "amazonOrderReferenceId=" + amazonOrderReferenceId + ", accessToken=" + accessToken - + ", mwsAuthToken=" + mwsAuthToken + '}'; + + ", mwsAuthToken=" + getMwsAuthToken() + '}'; } } diff --git a/src/com/amazon/pay/request/GetProviderCreditDetailsRequest.java b/src/com/amazon/pay/request/GetProviderCreditDetailsRequest.java index 5daee0d..05a876a 100644 --- a/src/com/amazon/pay/request/GetProviderCreditDetailsRequest.java +++ b/src/com/amazon/pay/request/GetProviderCreditDetailsRequest.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -23,17 +23,19 @@ * https://pay.amazon.com/documentation/ * */ -public class GetProviderCreditDetailsRequest implements Serializable{ - +public class GetProviderCreditDetailsRequest extends DelegateRequest implements Serializable { + + @Override + protected GetProviderCreditDetailsRequest getThis() { + return this; + } + //required parameters private String amazonProviderCreditId; private String sellerId; - - //optional parameters - private String mwsAuthToken; /** - * + * * @param amazonProviderCreditId Provide Amazon Provider Credit ID in the request * * @param sellerId Provide the Seller ID in the request @@ -43,18 +45,6 @@ public GetProviderCreditDetailsRequest(String amazonProviderCreditId , String se this.sellerId = sellerId; } - /** - * @param mwsAuthToken Sets MWSAuthToken parameter in request. MWSAuthToken is required - * only for third-party solution providers and marketplaces. Do not - * specify this parameter for merchants creating their own custom integration. - * - * @return The MWSAuthToken - */ - public GetProviderCreditDetailsRequest setMwsAuthToken(String mwsAuthToken) { - this.mwsAuthToken = mwsAuthToken; - return this; - } - /** * @return amazonProviderCreditId */ @@ -69,13 +59,6 @@ public String getSellerId() { return sellerId; } - /** - * @return mwsAuthToken - */ - public String getMwsAuthToken() { - return mwsAuthToken; - } - /** * Returns a string representation of this object; useful for testing and * debugging. @@ -86,9 +69,10 @@ public String getMwsAuthToken() { */ @Override public String toString() { - return "GetProviderCreditDetailsRequest{" + "amazonProviderCreditId=" + amazonProviderCreditId + ", sellerId=" + sellerId + ", mwsAuthToken=" - + mwsAuthToken + '}'; + return "GetProviderCreditDetailsRequest{" + + "amazonProviderCreditId=" + amazonProviderCreditId + + ", sellerId=" + sellerId + + ", mwsAuthToken=" + getMwsAuthToken() + '}'; } - - + } diff --git a/src/com/amazon/pay/request/GetProviderCreditReversalDetailsRequest.java b/src/com/amazon/pay/request/GetProviderCreditReversalDetailsRequest.java index e62885f..9aad01b 100644 --- a/src/com/amazon/pay/request/GetProviderCreditReversalDetailsRequest.java +++ b/src/com/amazon/pay/request/GetProviderCreditReversalDetailsRequest.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -23,62 +23,35 @@ * https://pay.amazon.com/documentation/ * */ -public class GetProviderCreditReversalDetailsRequest implements Serializable{ - +public class GetProviderCreditReversalDetailsRequest extends DelegateRequest implements Serializable { + + @Override + protected GetProviderCreditReversalDetailsRequest getThis() { + return this; + } + //required parameters private final String amazonProviderCreditReversalId; - private final String sellerId; - - //optional parameters - private String mwsAuthToken; - + /** * * @param amazonProviderCreditReversalId Provide Amazon Provider Credit ID in the request * * @param sellerId Provide the Seller ID in the request */ - public GetProviderCreditReversalDetailsRequest(String amazonProviderCreditReversalId , String sellerId) { + public GetProviderCreditReversalDetailsRequest(String amazonProviderCreditReversalId, String sellerId) { this.amazonProviderCreditReversalId = amazonProviderCreditReversalId; - this.sellerId = sellerId; + setSellerId(sellerId); } /** - * @param mwsAuthToken Sets MWSAuthToken parameter in request. MWSAuthToken is required - * only for third-party solution providers and marketplaces. Do not - * specify this parameter for merchants creating their own custom integration. * - * @return The MWSAuthToken - */ - public GetProviderCreditReversalDetailsRequest setMwsAuthToken(String mwsAuthToken) { - this.mwsAuthToken = mwsAuthToken; - return this; - } - - /** - * * @return amazonProviderCreditReversalId */ public String getAmazonProviderCreditReversalId() { return amazonProviderCreditReversalId; } - /** - * - * @return sellerId - */ - public String getSellerId() { - return sellerId; - } - - /** - * - * @return mwsAuthToken - */ - public String getMwsAuthToken() { - return mwsAuthToken; - } - /** * Returns a string representation of this object; useful for testing and * debugging. @@ -89,9 +62,10 @@ public String getMwsAuthToken() { */ @Override public String toString() { - return "GetProviderCreditReversalDetailsRequest{" + "amazonProviderCreditReversalId=" + amazonProviderCreditReversalId + ", sellerId=" - + sellerId + ", mwsAuthToken=" + mwsAuthToken + '}'; + return "GetProviderCreditReversalDetailsRequest{" + + "amazonProviderCreditReversalId=" + amazonProviderCreditReversalId + + ", sellerId=" + getSellerId() + + ", mwsAuthToken=" + getMwsAuthToken() + '}'; } - } diff --git a/src/com/amazon/pay/request/GetRefundDetailsRequest.java b/src/com/amazon/pay/request/GetRefundDetailsRequest.java index d8468d5..91f98c7 100644 --- a/src/com/amazon/pay/request/GetRefundDetailsRequest.java +++ b/src/com/amazon/pay/request/GetRefundDetailsRequest.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -21,10 +21,14 @@ * For more information documentation, see * https://pay.amazon.com/documentation/ */ -public class GetRefundDetailsRequest implements Serializable{ +public class GetRefundDetailsRequest extends DelegateRequest implements Serializable { + + @Override + protected GetRefundDetailsRequest getThis() { + return this; + } private String amazonRefundId; - private String mwsAuthToken; /** * @@ -34,18 +38,6 @@ public GetRefundDetailsRequest(String amazonRefundId) { this.amazonRefundId = amazonRefundId; } - /** - * @param mwsAuthToken Sets MWSAuthToken parameter in request. MWSAuthToken is required - * only for third-party solution providers and marketplaces. Do not - * specify this parameter for merchants creating their own custom integration. - * - * @return The MWSAuthToken - */ - public GetRefundDetailsRequest setMWSAuthToken(String mwsAuthToken) { - this.mwsAuthToken = mwsAuthToken; - return this; - } - /** * * @return amazonRefundId @@ -54,14 +46,6 @@ public String getAmazonRefundId() { return amazonRefundId; } - /** - * - * @return mwsAuthToken - */ - public String getMwsAuthToken() { - return mwsAuthToken; - } - /** * Returns a string representation of this object; useful for testing and * debugging. @@ -72,9 +56,9 @@ public String getMwsAuthToken() { */ @Override public String toString() { - return "GetRefundDetailsRequest{" + "amazonRefundId=" + amazonRefundId + ", mwsAuthToken=" + mwsAuthToken + '}'; + return "GetRefundDetailsRequest{" + + "amazonRefundId=" + amazonRefundId + + ", mwsAuthToken=" + getMwsAuthToken() + '}'; } - - } diff --git a/src/com/amazon/pay/request/ListOrderReferenceByNextTokenRequest.java b/src/com/amazon/pay/request/ListOrderReferenceByNextTokenRequest.java index 06b93d7..0607491 100644 --- a/src/com/amazon/pay/request/ListOrderReferenceByNextTokenRequest.java +++ b/src/com/amazon/pay/request/ListOrderReferenceByNextTokenRequest.java @@ -1,5 +1,5 @@ /** - * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -19,7 +19,13 @@ /** * Container for the parameters to the ListOrderReferenceByNextToken operation. */ -public class ListOrderReferenceByNextTokenRequest extends SetMWSAuthToken implements Serializable { +public class ListOrderReferenceByNextTokenRequest extends DelegateRequest implements Serializable { + + @Override + protected ListOrderReferenceByNextTokenRequest getThis() { + return this; + } + //required parameters private String nextPageToken; diff --git a/src/com/amazon/pay/request/ListOrderReferenceRequest.java b/src/com/amazon/pay/request/ListOrderReferenceRequest.java index 71a8a4b..987eaf4 100644 --- a/src/com/amazon/pay/request/ListOrderReferenceRequest.java +++ b/src/com/amazon/pay/request/ListOrderReferenceRequest.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -14,7 +14,6 @@ */ package com.amazon.pay.request; - import com.amazon.pay.types.OrderReferenceStatus; import com.amazon.pay.types.SortOrder; @@ -25,7 +24,12 @@ /** * Container for the parameters to the ListOrderReference operation. */ -public class ListOrderReferenceRequest extends SetMWSAuthToken implements Serializable { +public class ListOrderReferenceRequest extends DelegateRequest implements Serializable { + + @Override + protected ListOrderReferenceRequest getThis() { + return this; + } // required parameters private String queryId; diff --git a/src/com/amazon/pay/request/RefundRequest.java b/src/com/amazon/pay/request/RefundRequest.java index 1bd938d..b05a04c 100644 --- a/src/com/amazon/pay/request/RefundRequest.java +++ b/src/com/amazon/pay/request/RefundRequest.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -24,7 +24,12 @@ * For more information documentation, see * https://pay.amazon.com/documentation/ */ -public class RefundRequest implements Serializable { +public class RefundRequest extends DelegateRequest implements Serializable { + + @Override + protected RefundRequest getThis() { + return this; + } //required parameters private String amazonCaptureId; @@ -35,10 +40,8 @@ public class RefundRequest implements Serializable { //optional parameters private String sellerRefundNote; private String softDescriptor; - private String mwsAuthToken; private List providerCredit; - /** * @param captureId The capture identifier that was generated by Amazon in the earlier call to Capture. * @param refundReferenceId The identifier for this refund transaction that you specify. @@ -84,17 +87,6 @@ public RefundRequest setSoftDescriptor(String softDescriptor) { return this; } - /** - * @param mwsAuthToken Sets MWSAuthToken. Applicable for third-party - * solution providers only. - * - * @return the MWSAuthToken - */ - public RefundRequest setMWSAuthToken(String mwsAuthToken) { - this.mwsAuthToken = mwsAuthToken; - return this; - } - /** * @return amazonCaptureId The capture identifier that was generated by * Amazon in the earlier call to Capture. @@ -141,13 +133,6 @@ public String getSoftDescriptor() { return softDescriptor; } - /** - * @return mwsAuthToken Applicable for third-party solution providers only. - */ - public String getMwsAuthToken() { - return mwsAuthToken; - } - /** * @return ProviderCredit associated with Refund operation */ @@ -176,9 +161,15 @@ public RefundRequest setProviderCredit(List providerCreditList) */ @Override public String toString() { - return "RefundRequest{" + "amazonCaptureId=" + amazonCaptureId + ", refundReferenceId=" + refundReferenceId + ", refundAmount=" - + refundAmount + ", refundCurrencyCode=" + refundCurrencyCode + ", sellerRefundNote=" + sellerRefundNote + ", softDescriptor=" - + softDescriptor + ", mwsAuthToken=" + mwsAuthToken + ", providerCredit=" + providerCredit + '}'; + return "RefundRequest{" + + "amazonCaptureId=" + amazonCaptureId + + ", refundReferenceId=" + refundReferenceId + + ", refundAmount=" + refundAmount + + ", refundCurrencyCode=" + refundCurrencyCode + + ", sellerRefundNote=" + sellerRefundNote + + ", softDescriptor=" + softDescriptor + + ", mwsAuthToken=" + getMwsAuthToken() + + ", providerCredit=" + providerCredit + '}'; } } diff --git a/src/com/amazon/pay/request/RequestHelper.java b/src/com/amazon/pay/request/RequestHelper.java index f1eae65..644599b 100644 --- a/src/com/amazon/pay/request/RequestHelper.java +++ b/src/com/amazon/pay/request/RequestHelper.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2016-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -44,10 +44,18 @@ public RequestHelper(PayConfig payConfig) { this.payUtil = new PayLogUtil(); } - - private Map addClientParameters(Map params) { + private Map addClientParameters(Map params, DelegateRequest request) { try { - params.put(ServiceConstants.SELLER_ID, payConfig.getSellerId()); + if ((request != null) && (request.getMwsAuthToken() != null)) { + params.put(ServiceConstants.MWS_AUTH_TOKEN, request.getMwsAuthToken()); + } + + if ((request != null) && (request.getSellerId() != null)) { + params.put(ServiceConstants.SELLER_ID, request.getSellerId()); + } else { + params.put(ServiceConstants.SELLER_ID, payConfig.getSellerId()); + } + params.put(ServiceConstants.AWSACCESSKEYID, payConfig.getAccessKey()); params.put(ServiceConstants.SIGNATUREVERSION, "2"); params.put(ServiceConstants.SIGNATUREMETHOD, "HmacSHA256"); @@ -105,10 +113,7 @@ public String getPostURL(GetOrderReferenceDetailsRequest request) { if (request.getAccessToken() != null) { parameters.put(ServiceConstants.ACCESS_TOKEN, request.getAccessToken()); } - if (request.getMwsAuthToken() != null) { - parameters.put(ServiceConstants.MWS_AUTH_TOKEN, request.getMwsAuthToken()); - } - addClientParameters(parameters); + addClientParameters(parameters, request); return Util.convertParameterMapToString(parameters); } @@ -139,16 +144,16 @@ public String getPostURL(SetOrderReferenceDetailsRequest request) { if (request.getStoreName() != null) { parameters.put(ServiceConstants.STORE_NAME, request.getStoreName()); } + if (request.getSupplementaryData() != null) { + parameters.put(ServiceConstants.SUPPLEMENTARY_DATA, request.getSupplementaryData()); + } if (request.getCustomInformation() != null) { parameters.put(ServiceConstants.CUSTOM_INFORMATION, request.getCustomInformation()); } - if (request.getMwsAuthToken() != null) { - parameters.put(ServiceConstants.MWS_AUTH_TOKEN, request.getMwsAuthToken()); - } if (request.getRequestPaymentAuthorization() != null) { parameters.put(ServiceConstants.REQUEST_PAYMENT_AUTHORIZATION, Boolean.toString(request.getRequestPaymentAuthorization())); } - addClientParameters(parameters); + addClientParameters(parameters, request); return Util.convertParameterMapToString(parameters); } @@ -182,13 +187,10 @@ public String getPostURL(AuthorizeRequest request) { if (request.getSoftDescriptor() != null) { parameters.put(ServiceConstants.SOFT_DESCRIPTOR, request.getSoftDescriptor()); } - if (request.getMwsAuthToken() != null) { - parameters.put(ServiceConstants.MWS_AUTH_TOKEN, request.getMwsAuthToken()); - } if (request.getProviderCredit() != null) { addProviderCreditToParamMap(request.getProviderCredit(), parameters); } - addClientParameters(parameters); + addClientParameters(parameters, request); return Util.convertParameterMapToString(parameters); } @@ -198,10 +200,7 @@ public String getPostURL(GetAuthorizationDetailsRequest request) { if (request.getAmazonAuthorizationId() != null) { parameters.put(ServiceConstants.AMAZON_AUTHORIZATION_ID, request.getAmazonAuthorizationId()); } - if (request.getMwsAuthToken() != null) { - parameters.put(ServiceConstants.MWS_AUTH_TOKEN, request.getMwsAuthToken()); - } - addClientParameters(parameters); + addClientParameters(parameters, request); return Util.convertParameterMapToString(parameters); } @@ -230,13 +229,10 @@ public String getPostURL(CaptureRequest request) { if (request.getSoftDescriptor() != null) { parameters.put( ServiceConstants.SOFT_DESCRIPTOR, request.getSoftDescriptor()); } - if (request.getMwsAuthToken() != null) { - parameters.put( ServiceConstants.MWS_AUTH_TOKEN, request.getMwsAuthToken()); - } if (request.getProviderCredit() != null) { addProviderCreditToParamMap(request.getProviderCredit(), parameters); } - addClientParameters(parameters); + addClientParameters(parameters, request); return Util.convertParameterMapToString(parameters); } @@ -246,10 +242,7 @@ public String getPostURL(GetCaptureDetailsRequest request) { if (request.getAmazonCaptureId() != null) { parameters.put(ServiceConstants.AMAZON_CAPTURE_ID, request.getAmazonCaptureId()); } - if (request.getMwsAuthToken() != null) { - parameters.put(ServiceConstants.MWS_AUTH_TOKEN, request.getMwsAuthToken()); - } - addClientParameters(parameters); + addClientParameters(parameters, request); return Util.convertParameterMapToString(parameters); } @@ -259,10 +252,25 @@ public String getPostURL(ConfirmOrderReferenceRequest request) { if (request.getAmazonOrderReferenceId() != null) { parameters.put(ServiceConstants.AMAZON_ORDER_REFERENCE_ID, request.getAmazonOrderReferenceId()); } - if (request.getMwsAuthToken() != null) { - parameters.put(ServiceConstants.MWS_AUTH_TOKEN, request.getMwsAuthToken()); + if (request.getSuccessUrl() != null) { + parameters.put(ServiceConstants.SUCCESS_URL, request.getSuccessUrl()); + } + if (request.getFailureUrl() != null) { + parameters.put(ServiceConstants.FAILURE_URL, request.getFailureUrl()); } - addClientParameters(parameters); + + if (request.getAuthorizationAmount() != null) { + parameters.put(ServiceConstants.AUTHORIZATION_AMOUNT, request.getAuthorizationAmount()); + + if (request.getAuthorizationCurrencyCode() == null) { + request.setAuthorizationCurrencyCode(payConfig.getCurrencyCode()); + } + parameters.put(ServiceConstants.AUTHORIZATION_CURRENCEYCODE, request.getAuthorizationCurrencyCode().toString()); + } + if (request.isExpectImmediateAuthorization() != null) { + parameters.put(ServiceConstants.EXPECT_IMMEDIATE_AUTHORIZATION, request.isExpectImmediateAuthorization().toString()); + } + addClientParameters(parameters, request); return Util.convertParameterMapToString(parameters); } @@ -275,10 +283,7 @@ public String getPostURL(CancelOrderReferenceRequest request) { if (request.getCancelationReason() != null) { parameters.put(ServiceConstants.CANCELATION_REASON, request.getCancelationReason()); } - if (request.getMwsAuthToken() != null) { - parameters.put(ServiceConstants.MWS_AUTH_TOKEN, request.getMwsAuthToken()); - } - addClientParameters(parameters); + addClientParameters(parameters, request); return Util.convertParameterMapToString(parameters); } @@ -291,10 +296,7 @@ public String getPostURL(CloseOrderReferenceRequest request) { if (request.getClosureReason() != null) { parameters.put(ServiceConstants.CLOSURE_REASON, request.getClosureReason()); } - if (request.getMwsAuthToken() != null) { - parameters.put(ServiceConstants.MWS_AUTH_TOKEN, request.getMwsAuthToken()); - } - addClientParameters(parameters); + addClientParameters(parameters, request); return Util.convertParameterMapToString(parameters); } @@ -307,19 +309,16 @@ public String getPostURL(CloseAuthorizationRequest request) { if (request.getClosureReason() != null) { parameters.put(ServiceConstants.CLOSURE_REASON, request.getClosureReason()); } - if (request.getMwsAuthToken() != null) { - parameters.put(ServiceConstants.MWS_AUTH_TOKEN, request.getMwsAuthToken()); - } - addClientParameters(parameters); + addClientParameters(parameters, request); return Util.convertParameterMapToString(parameters); } public String getPostURL(RefundRequest request) { Map parameters = new TreeMap(); parameters.put(ServiceConstants.ACTION, ServiceConstants.REFUND); - if (request.getRefundCurrencyCode() == null) + if (request.getRefundCurrencyCode() == null) { request.setRefundCurrencyCode(payConfig.getCurrencyCode()); - + } if (request.getAmazonCaptureId() != null) { parameters.put(ServiceConstants.AMAZON_CAPTURE_ID, request.getAmazonCaptureId()); } @@ -338,50 +337,40 @@ public String getPostURL(RefundRequest request) { if (request.getSoftDescriptor() != null) { parameters.put(ServiceConstants.SOFT_DESCRIPTOR, request.getSoftDescriptor()); } - if (request.getMwsAuthToken() != null) { - parameters.put(ServiceConstants.MWS_AUTH_TOKEN, request.getMwsAuthToken()); - } if (request.getProviderCredit() != null) { - addProviderCreditToParamMap(request.getProviderCredit(), parameters); + addProviderCreditReversalToParamMap(request.getProviderCredit(), parameters); } - addClientParameters(parameters); + addClientParameters(parameters, request); return Util.convertParameterMapToString(parameters); } public String getPostURL(GetRefundDetailsRequest request) { Map parameters = new TreeMap(); parameters.put(ServiceConstants.ACTION, ServiceConstants.GET_REFUND_DETAILS); - if (request.getAmazonRefundId() != null) + if (request.getAmazonRefundId() != null) { parameters.put(ServiceConstants.AMAZON_REFUND_ID, request.getAmazonRefundId()); - if (request.getMwsAuthToken() != null) - parameters.put(ServiceConstants.MWS_AUTH_TOKEN, request.getMwsAuthToken()); - addClientParameters(parameters); + } + addClientParameters(parameters, request); return Util.convertParameterMapToString(parameters); } public String getPostURL(GetProviderCreditDetailsRequest request) { Map parameters = new TreeMap(); parameters.put(ServiceConstants.ACTION, ServiceConstants.GET_PROVIDER_CREDIT_DETAILS); - if (request.getAmazonProviderCreditId() != null) + if (request.getAmazonProviderCreditId() != null) { parameters.put(ServiceConstants.AMAZON_PROVIDER_CREDIT_ID, request.getAmazonProviderCreditId()); - if (request.getSellerId() != null) - parameters.put(ServiceConstants.SELLER_ID, request.getSellerId()); - if (request.getMwsAuthToken() != null) - parameters.put(ServiceConstants.MWS_AUTH_TOKEN, request.getMwsAuthToken()); - addClientParameters(parameters); + } + addClientParameters(parameters, request); return Util.convertParameterMapToString(parameters); } public String getPostURL(GetProviderCreditReversalDetailsRequest request) { Map parameters = new TreeMap(); parameters.put(ServiceConstants.ACTION, ServiceConstants.GET_REVERSE_PROVIDER_CREDIT_DETAILS); - if (request.getAmazonProviderCreditReversalId() != null) + if (request.getAmazonProviderCreditReversalId() != null) { parameters.put(ServiceConstants.AMAZON_PROVIDER_CREDIT_REVERSAL_ID, request.getAmazonProviderCreditReversalId()); - if (request.getSellerId() != null) - parameters.put(ServiceConstants.SELLER_ID, request.getSellerId()); - if (request.getMwsAuthToken() != null) - parameters.put(ServiceConstants.MWS_AUTH_TOKEN, request.getMwsAuthToken()); - addClientParameters(parameters); + } + addClientParameters(parameters, request); return Util.convertParameterMapToString(parameters); } @@ -396,15 +385,11 @@ public String getPostURL(ReverseProviderCreditRequest request) { parameters.put(ServiceConstants.CREDIT_REVERSAL_REFERENCE_ID, request.getCreditReversalReferenceId()); if (request.getCreditReversalAmount() != null) parameters.put(ServiceConstants.CREDIT_REVERSAL_AMOUNT, request.getCreditReversalAmount()); - if (request.getSellerId() != null) - parameters.put(ServiceConstants.SELLER_ID, request.getSellerId()); if (request.getCreditReversalAmountCurrencyCode() != null) parameters.put(ServiceConstants.CREDIT_REVERSAL_AMOUNT_CURRENCY_CODE, request.getCreditReversalAmountCurrencyCode().toString()); if (request.getCreditReversalNote() != null) parameters.put(ServiceConstants.CREDIT_REVERSAL_NOTE, request.getCreditReversalNote()); - if (request.getMwsAuthToken() != null) - parameters.put(ServiceConstants.MWS_AUTH_TOKEN,request.getMwsAuthToken()); - addClientParameters(parameters); + addClientParameters(parameters, request); return Util.convertParameterMapToString(parameters); } @@ -413,11 +398,9 @@ public String getPostURL(GetBillingAgreementDetailsRequest request) { parameters.put(ServiceConstants.ACTION, ServiceConstants.GET_BILLING_AGREEMENT_DETAILS); if (request.getAmazonBillingAgreementId() != null) parameters.put(ServiceConstants.AMAZON_BILLING_AGREEMENT_ID, request.getAmazonBillingAgreementId()); - if (request.getMwsAuthToken() != null) - parameters.put(ServiceConstants.MWS_AUTH_TOKEN, request.getMwsAuthToken()); if (request.getAddressConsentToken() != null) parameters.put(ServiceConstants.ADDRESS_CONSENT_TOKEN , request.getAddressConsentToken()); - addClientParameters(parameters); + addClientParameters(parameters, request); return Util.convertParameterMapToString(parameters); } @@ -426,19 +409,26 @@ public String getPostURL(SetBillingAgreementDetailsRequest request) { parameters.put(ServiceConstants.ACTION, ServiceConstants.SET_BILLING_AGREEMENT_DETAILS); if (request.getAmazonBillingAgreementId() != null) parameters.put(ServiceConstants.AMAZON_BILLING_AGREEMENT_ID, request.getAmazonBillingAgreementId()); - if (request.getMwsAuthToken() != null) - parameters.put(ServiceConstants.MWS_AUTH_TOKEN, request.getMwsAuthToken()); if (request.getPlatformId() != null) parameters.put(ServiceConstants.BILLING_AGREEMENT_PLATFORM_ID, request.getPlatformId()); if (request.getSellerNote() != null) parameters.put(ServiceConstants.BILLING_AGREEMENT_SELLER_NOTE, request.getSellerNote()); if (request.getAmazonBillingAgreementId() != null) parameters.put(ServiceConstants.BILLING_AGREEMENT_SELLER_BILLING_AGREEMENT_ID, request.getSellerBillingAgreementId()); - if (request.getStoreName()!= null) + if (request.getStoreName() != null) parameters.put(ServiceConstants.BILLING_AGREEMENT_SELLER_STORE_NAME, request.getStoreName()); if (request.getCustomInformation() != null) parameters.put(ServiceConstants.BILLING_AGREEMENT_SELLER_CUSTOM_INFORMATION, request.getCustomInformation()); - addClientParameters(parameters); + if (request.getBillingAgreementType() != null) + parameters.put(ServiceConstants.BILLING_AGREEMENT_TYPE, request.getBillingAgreementType().toString()); + if (request.getSubscriptionAmount() != null) { + if (request.getSubscriptionAmount().getCurrencyCode() != null) + parameters.put(ServiceConstants.BILLING_AGREEMENT_SUBSCRIPTION_AMOUNT_CURRENCY_CODE, request.getSubscriptionAmount().getCurrencyCode()); + if (request.getSubscriptionAmount().getAmount() != null) + parameters.put(ServiceConstants.BILLING_AGREEMENT_SUBSCRIPTION_AMOUNT_AMOUNT, request.getSubscriptionAmount().getAmount()); + } + addClientParameters(parameters, request); + return Util.convertParameterMapToString(parameters); } @@ -447,9 +437,11 @@ public String getPostURL(ConfirmBillingAgreementRequest request) { parameters.put(ServiceConstants.ACTION, ServiceConstants.CONFIRM_BILLING_AGREEMENT_DETAILS); if (request.getAmazonBillingAgreementId() != null) parameters.put(ServiceConstants.AMAZON_BILLING_AGREEMENT_ID, request.getAmazonBillingAgreementId()); - if (request.getMwsAuthToken() != null) - parameters.put(ServiceConstants.MWS_AUTH_TOKEN, request.getMwsAuthToken()); - addClientParameters(parameters); + if (request.getSuccessUrl() != null) + parameters.put(ServiceConstants.SUCCESS_URL, request.getSuccessUrl()); + if (request.getFailureUrl() != null) + parameters.put(ServiceConstants.FAILURE_URL, request.getFailureUrl()); + addClientParameters(parameters, request); return Util.convertParameterMapToString(parameters); } @@ -460,9 +452,7 @@ public String getPostURL(CloseBillingAgreementRequest request) { parameters.put(ServiceConstants.AMAZON_BILLING_AGREEMENT_ID, request.getAmazonBillingAgreementId()); if (request.getClosureReason() != null) parameters.put(ServiceConstants.CLOSURE_REASON, request.getClosureReason()); - if (request.getMwsAuthToken() != null) - parameters.put(ServiceConstants.MWS_AUTH_TOKEN, request.getMwsAuthToken()); - addClientParameters(parameters); + addClientParameters(parameters, request); return Util.convertParameterMapToString(parameters); } @@ -473,13 +463,13 @@ public String getPostURL(AuthorizeOnBillingAgreementRequest request) { request.setAuthorizationCurrencyCode(payConfig.getCurrencyCode()); if (request.getAmazonBillingAgreementId() != null) parameters.put(ServiceConstants.AMAZON_BILLING_AGREEMENT_ID, request.getAmazonBillingAgreementId()); - if (request.getAuthorizationReferenceId() != null) + if (request.getAuthorizationReferenceId() != null) parameters.put(ServiceConstants.AUTHORIZATION_REFERENCE_ID, request.getAuthorizationReferenceId()); - if (request.getAuthorizationAmount() != null) + if (request.getAuthorizationAmount() != null) parameters.put(ServiceConstants.AUTHORIZATION_AMOUNT, request.getAuthorizationAmount()); - if (request.getAuthorizationCurrencyCode() != null) + if (request.getAuthorizationCurrencyCode() != null) parameters.put(ServiceConstants.AUTHORIZATION_CURRENCEYCODE, request.getAuthorizationCurrencyCode().toString()); - if (request.getSellerAuthorizationNote() != null) + if (request.getSellerAuthorizationNote() != null) parameters.put(ServiceConstants.SELLER_AUTHORIZATION_NOTE, request.getSellerAuthorizationNote()); if (request.getTransactionTimeout() != null) parameters.put(ServiceConstants.TRANSACTION_TIMEOUT, request.getTransactionTimeout()); @@ -488,20 +478,22 @@ public String getPostURL(AuthorizeOnBillingAgreementRequest request) { if (request.getSoftDescriptor() != null) parameters.put(ServiceConstants.SOFT_DESCRIPTOR, request.getSoftDescriptor()); if (request.getSellerNote() != null) - parameters.put(ServiceConstants.SELLER_NOTE, request.getSellerNote()); + parameters.put(ServiceConstants.BA_SELLER_NOTE, request.getSellerNote()); if (request.getPlatformId() != null) - parameters.put(ServiceConstants.PLATFORM_ID, request.getPlatformId()); + parameters.put(ServiceConstants.BA_PLATFORM_ID, request.getPlatformId()); if (request.getSellerOrderId() != null) parameters.put(ServiceConstants.BA_SELLER_ORDER_ID, request.getSellerOrderId()); if (request.getStoreName() != null) parameters.put(ServiceConstants.BA_STORE_NAME, request.getStoreName()); + if (request.getSupplementaryData() != null) + parameters.put(ServiceConstants.BA_SUPPLEMENTARY_DATA, request.getSupplementaryData()); if (request.getCustomInformation() != null) parameters.put(ServiceConstants.BA_CUSTOM_INFORMATION, request.getCustomInformation()); if (request.getInheritShippingAddress() != null) parameters.put(ServiceConstants.INHERIT_SHIPPING_ADDRESS, Boolean.toString(request.getInheritShippingAddress())); - if (request.getMwsAuthToken() != null) - parameters.put(ServiceConstants.MWS_AUTH_TOKEN, request.getMwsAuthToken()); - addClientParameters(parameters); + if (request.getProviderCredit() != null) + addProviderCreditToParamMap(request.getProviderCredit(), parameters); + addClientParameters(parameters, request); return Util.convertParameterMapToString(parameters); } @@ -510,9 +502,7 @@ public String getPostURL(ValidateBillingAgreementRequest request) { parameters.put(ServiceConstants.ACTION, ServiceConstants.VALIDATE_BILLING_AGREEMENT_DETAILS); if (request.getAmazonBillingAgreementId() != null) parameters.put(ServiceConstants.AMAZON_BILLING_AGREEMENT_ID, request.getAmazonBillingAgreementId()); - if (request.getMwsAuthToken() != null) - parameters.put(ServiceConstants.MWS_AUTH_TOKEN, request.getMwsAuthToken()); - addClientParameters(parameters); + addClientParameters(parameters, request); return Util.convertParameterMapToString(parameters); } @@ -549,19 +539,19 @@ public String getPostURL(CreateOrderReferenceForIdRequest request) { parameters.put(ServiceConstants.SELLER_ORDER_ID, request.getSellerOrderId()); if (request.getStoreName() != null) parameters.put(ServiceConstants.STORE_NAME, request.getStoreName()); + if (request.getSupplementaryData() != null) + parameters.put(ServiceConstants.SUPPLEMENTARY_DATA, request.getSupplementaryData()); if (request.getCustomInformation() != null) parameters.put(ServiceConstants.CUSTOM_INFORMATION, request.getCustomInformation()); - if (request.getMwsAuthToken() != null) - parameters.put(ServiceConstants.MWS_AUTH_TOKEN, request.getMwsAuthToken()); - addClientParameters(parameters); + addClientParameters(parameters, request); return Util.convertParameterMapToString(parameters); } public String getPostURLGetServiceStatus() { final Map parameters = new TreeMap(); parameters.put(ServiceConstants.ACTION, ServiceConstants.GET_SERVICE_STATUS); - addClientParameters(parameters); + addClientParameters(parameters, null); return Util.convertParameterMapToString(parameters); } @@ -603,10 +593,8 @@ public String getPostURL(ListOrderReferenceRequest request){ count++; } } - if (request.getMwsAuthToken() != null) - parameters.put(ServiceConstants.MWS_AUTH_TOKEN, request.getMwsAuthToken()); - addClientParameters(parameters); + addClientParameters(parameters, request); return Util.convertParameterMapToString(parameters); } @@ -616,10 +604,8 @@ public String getPostURL(ListOrderReferenceByNextTokenRequest request){ if (request.getNextPageToken() != null) parameters.put(ServiceConstants.NEXT_PAGE_TOKEN, request.getNextPageToken()); - if (request.getMwsAuthToken() != null) - parameters.put(ServiceConstants.MWS_AUTH_TOKEN, request.getMwsAuthToken()); - addClientParameters(parameters); + addClientParameters(parameters, request); return Util.convertParameterMapToString(parameters); } @@ -641,6 +627,8 @@ public String getPostURL(SetOrderAttributesRequest request){ parameters.put(ServiceConstants.ORDER_ATTRIBUTES_SELLER_ORDER_ID, request.getSellerOrderId()); if (request.getStoreName() != null) parameters.put(ServiceConstants.ORDER_ATTRIBUTES_STORE_NAME, request.getStoreName()); + if (request.getSupplementaryData() != null) + parameters.put(ServiceConstants.ORDER_ATTRIBUTES_SUPPLEMENTARY_DATA, request.getSupplementaryData()); if (request.getPlatformId() != null) parameters.put(ServiceConstants.ORDER_ATTRIBUTES_PLATFORM_ID, request.getPlatformId()); if (request.getCustomInformation() != null) @@ -657,10 +645,16 @@ public String getPostURL(SetOrderAttributesRequest request){ count++; } } - if (request.getMwsAuthToken() != null) - parameters.put(ServiceConstants.MWS_AUTH_TOKEN, request.getMwsAuthToken()); - addClientParameters(parameters); + addClientParameters(parameters, request); + return Util.convertParameterMapToString(parameters); + } + + public String getPostURL(GetMerchantAccountStatusRequest request){ + final Map parameters = new TreeMap(); + parameters.put(ServiceConstants.ACTION, ServiceConstants.GET_MERCHANT_ACCOUNT_STATUS); + + addClientParameters(parameters, request); return Util.convertParameterMapToString(parameters); } @@ -672,7 +666,7 @@ private void addProviderCreditToParamMap(List providerCreditList if (member.getProviderId() != null) { parameters.put("ProviderCreditList" + "." + "member" + "." + memberListIndex + "." + "ProviderId", member.getProviderId()); } - Price creditAmount = member.getCreditAmount(); + final Price creditAmount = member.getCreditAmount(); if (creditAmount != null) { parameters.put("ProviderCreditList" + "." + "member" + "." + memberListIndex + "." + "CreditAmount" + "." + "Amount", creditAmount.getAmount()); parameters.put("ProviderCreditList" + "." + "member" + "." + memberListIndex + "." + "CreditAmount" + "." + "CurrencyCode", creditAmount.getCurrencyCode()); @@ -683,4 +677,23 @@ private void addProviderCreditToParamMap(List providerCreditList } } + private void addProviderCreditReversalToParamMap(List providerCreditList, Map parameters) { + if (providerCreditList != null) { + int memberListIndex = 1; + for (ProviderCredit member : providerCreditList) { + if (member != null) { + if (member.getProviderId() != null) { + parameters.put("ProviderCreditReversalList" + "." + "member" + "." + memberListIndex + "." + "ProviderId", member.getProviderId()); + } + final Price creditAmount = member.getCreditAmount(); + if (creditAmount != null) { + parameters.put("ProviderCreditReversalList" + "." + "member" + "." + memberListIndex + "." + "CreditReversalAmount" + "." + "Amount", creditAmount.getAmount()); + parameters.put("ProviderCreditReversalList" + "." + "member" + "." + memberListIndex + "." + "CreditReversalAmount" + "." + "CurrencyCode", creditAmount.getCurrencyCode()); + } + memberListIndex++; + } + } + } + } + } diff --git a/src/com/amazon/pay/request/ReverseProviderCreditRequest.java b/src/com/amazon/pay/request/ReverseProviderCreditRequest.java index 5bab2de..1bdd4ec 100644 --- a/src/com/amazon/pay/request/ReverseProviderCreditRequest.java +++ b/src/com/amazon/pay/request/ReverseProviderCreditRequest.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -24,19 +24,22 @@ * https://pay.amazon.com/documentation/ * */ -public class ReverseProviderCreditRequest implements Serializable{ - +public class ReverseProviderCreditRequest extends DelegateRequest implements Serializable { + + @Override + protected ReverseProviderCreditRequest getThis() { + return this; + } + //required parameters private String amazonProviderCreditId; private String creditReversalReferenceId; private String creditReversalAmount; private CurrencyCode creditReversalAmountCurrencyCode; - private String sellerId; - + //optional parameters private String creditReversalNote ; - private String mwsAuthToken; - + /** * @param amazonProviderCreditId Provide Amazon Provider Credit ID in the request * @@ -46,15 +49,15 @@ public class ReverseProviderCreditRequest implements Serializable{ * * @param creditReversalAmount The reversal amount */ - public ReverseProviderCreditRequest(String amazonProviderCreditId, String creditReversalReferenceId, String sellerId, String creditReversalAmount){ + public ReverseProviderCreditRequest(String amazonProviderCreditId, String creditReversalReferenceId, String sellerId, String creditReversalAmount) { this.amazonProviderCreditId = amazonProviderCreditId; this.creditReversalReferenceId = creditReversalReferenceId; this.creditReversalAmount = creditReversalAmount; - this.sellerId = sellerId; + setSellerId(sellerId); } - + /** - * + * * @param currencyCode Three-digit currency code. In ISO 4217 format. * * @return the Currency Code @@ -64,9 +67,8 @@ public ReverseProviderCreditRequest setCreditReversalCurrencyCode(CurrencyCode c return this; } - /** - * + * * @param creditReversalNote Sets the credit reversal note. * * @return the credit reversal note. @@ -75,21 +77,9 @@ public ReverseProviderCreditRequest setCreditReversalNote(String creditReversalN this.creditReversalNote = creditReversalNote; return this; } - - /** - * - * @param mwsAuthToken Sets MWSAuthToken. Applicable for third-party - * solution providers only. - * - * @return the MWSAuthToken - */ - public ReverseProviderCreditRequest setMwsAuthToken(String mwsAuthToken) { - this.mwsAuthToken = mwsAuthToken; - return this; - } /** - * + * * @return amazonProviderCreditId */ public String getAmazonProviderCreditId() { @@ -97,7 +87,7 @@ public String getAmazonProviderCreditId() { } /** - * + * * @return creditReversalReferenceId */ public String getCreditReversalReferenceId() { @@ -105,7 +95,7 @@ public String getCreditReversalReferenceId() { } /** - * + * * @return creditReversalAmount */ public String getCreditReversalAmount() { @@ -113,7 +103,7 @@ public String getCreditReversalAmount() { } /** - * + * * @return creditReversalAmountCurrencyCode */ public CurrencyCode getCreditReversalAmountCurrencyCode() { @@ -121,29 +111,13 @@ public CurrencyCode getCreditReversalAmountCurrencyCode() { } /** - * - * @return sellerId - */ - public String getSellerId() { - return sellerId; - } - - /** - * + * * @return creditReversalNote */ public String getCreditReversalNote() { return creditReversalNote; } - /** - * - * @return mwsAuthToken - */ - public String getMwsAuthToken() { - return mwsAuthToken; - } - /** * Returns a string representation of this object; useful for testing and * debugging. @@ -154,11 +128,14 @@ public String getMwsAuthToken() { */ @Override public String toString() { - return "ReverseProviderCreditRequest{" + "amazonProviderCreditId=" + amazonProviderCreditId + ", creditReversalReferenceId=" - + creditReversalReferenceId + ", creditReversalAmount=" + creditReversalAmount + ", creditReversalAmountCurrencyCode=" - + creditReversalAmountCurrencyCode + ", sellerId=" + sellerId + ", creditReversalNote=" + creditReversalNote + ", mwsAuthToken=" - + mwsAuthToken + '}'; + return "ReverseProviderCreditRequest{" + + "amazonProviderCreditId=" + amazonProviderCreditId + + ", creditReversalReferenceId=" + creditReversalReferenceId + + ", creditReversalAmount=" + creditReversalAmount + + ", creditReversalAmountCurrencyCode=" + creditReversalAmountCurrencyCode + + ", sellerId=" + getSellerId() + + ", creditReversalNote=" + creditReversalNote + + ", mwsAuthToken=" + getMwsAuthToken() + '}'; } - } diff --git a/src/com/amazon/pay/request/SetBillingAgreementDetailsRequest.java b/src/com/amazon/pay/request/SetBillingAgreementDetailsRequest.java index 4c1b5a9..5e17928 100644 --- a/src/com/amazon/pay/request/SetBillingAgreementDetailsRequest.java +++ b/src/com/amazon/pay/request/SetBillingAgreementDetailsRequest.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2016-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -14,6 +14,8 @@ */ package com.amazon.pay.request; +import com.amazon.pay.response.model.Price; +import com.amazon.pay.types.BillingAgreementType; import java.io.Serializable; /** @@ -21,7 +23,12 @@ * For more information documentation, see * https://pay.amazon.com/documentation/ */ -public class SetBillingAgreementDetailsRequest implements Serializable{ +public class SetBillingAgreementDetailsRequest extends DelegateRequest implements Serializable { + + @Override + protected SetBillingAgreementDetailsRequest getThis() { + return this; + } //required parameters private String amazonBillingAgreementId; @@ -32,11 +39,12 @@ public class SetBillingAgreementDetailsRequest implements Serializable{ private String sellerBillingAgreementId; private String storeName; private String customInformation; - private String mwsAuthToken; + private BillingAgreementType billingAgreementType; + private Price subscriptionAmount; /** * - * @param amazonBillingAgreementId The billing agreement identifier. + * @param amazonBillingAgreementId The billing agreement identifier. * This value is retrieved from the Amazon Button, AddressBook, or Wallet widgets. */ public SetBillingAgreementDetailsRequest(String amazonBillingAgreementId) { @@ -44,21 +52,9 @@ public SetBillingAgreementDetailsRequest(String amazonBillingAgreementId) { } /** - * Sets MWSAuthToken. This is applicable for third-party solution providers only - * @param mwsAuthToken Sets MWSAuthToken. Applicable for third-party - * solution providers only. - * - * @return the MWSAuthToken - */ - public SetBillingAgreementDetailsRequest setMWSAuthToken(String mwsAuthToken) { - this.mwsAuthToken = mwsAuthToken; - return this; - } - - /** - * Sets the SellerId of the Solution Provider that developed the platform. - * This value should only be provided by Solution Providers. It should not be - * provided by merchants creating their own custom integration. Do not specify + * Sets the SellerId of the Solution Provider that developed the platform. + * This value should only be provided by Solution Providers. It should not be + * provided by merchants creating their own custom integration. Do not specify * the SellerId of the merchant for this request parameter. * @param platformId Represents the SellerId of the Solution Provider that developed the platform. * This value should only be provided by Solution Providers. It should @@ -94,7 +90,7 @@ public SetBillingAgreementDetailsRequest setSellerBillingAgreementId(String sell } /** - * Sets identifier of the store from which the order was placed. + * Sets identifier of the store from which the order was placed. * This overrides the default value in Seller Central under Settings > Account Settings. * @param storeName the identifier of the store from which the order was placed. * @@ -116,6 +112,28 @@ public SetBillingAgreementDetailsRequest setCustomInformation(String customInfor return this; } + /** + * Sets attribute to determine whether the BillingAgreement is merchant initiated or customer initiated. + * @param billingAgreementType can be either "CustomerInitiatedTransaction” or “MerchantInitiatedTransaction" + * + * @return BillingAgreementType + */ + public SetBillingAgreementDetailsRequest setBillingAgreementType(BillingAgreementType billingAgreementType) { + this.billingAgreementType = billingAgreementType; + return this; + } + + /** + * Sets the subscription amount for every charge till the subscription period + * @param subscriptionAmount The subscription amount for every charge till the subscription period. + * + * @return Subscription Amount + */ + public SetBillingAgreementDetailsRequest setSubscriptionAmount(Price subscriptionAmount) { + this.subscriptionAmount = subscriptionAmount; + return this; + } + /** * * @return amazonBillingAgreementId @@ -166,10 +184,18 @@ public String getCustomInformation() { /** * - * @return mwsAuthToken + * @return billingAgreementType */ - public String getMwsAuthToken() { - return mwsAuthToken; + public BillingAgreementType getBillingAgreementType() { + return billingAgreementType; + } + + /** + * + * @return subscriptionAmount + */ + public Price getSubscriptionAmount() { + return subscriptionAmount; } /** @@ -181,8 +207,16 @@ public String getMwsAuthToken() { */ @Override public String toString() { - return "SetBillingAgreementDetailsRequest{" + "amazonBillingAgreementId=" + amazonBillingAgreementId + ", platformId=" - + platformId + ", sellerNote=" + sellerNote + ", sellerBillingAgreementId=" + sellerBillingAgreementId + ", storeName=" - + storeName + ", customInformation=" + customInformation + ", mwsAuthToken=" + mwsAuthToken + '}'; + return "SetBillingAgreementDetailsRequest{" + + "amazonBillingAgreementId=" + amazonBillingAgreementId + + ", platformId=" + platformId + + ", sellerNote=" + sellerNote + + ", sellerBillingAgreementId=" + sellerBillingAgreementId + + ", storeName=" + storeName + + ", customInformation=" + customInformation + + ", billingAgreementType=" + billingAgreementType + + ", subscriptionAmount=" + subscriptionAmount + + ", mwsAuthToken=" + getMwsAuthToken() + '}'; } + } diff --git a/src/com/amazon/pay/request/SetMWSAuthToken.java b/src/com/amazon/pay/request/SetMWSAuthToken.java deleted file mode 100644 index 5c7e775..0000000 --- a/src/com/amazon/pay/request/SetMWSAuthToken.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://aws.amazon.com/apache2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ -package com.amazon.pay.request; - -public abstract class SetMWSAuthToken { - private String mwsAuthToken; - - /** - * Returns the MWS Auth Token - * - * @return mwsAuthToken - */ - public String getMwsAuthToken() { - return mwsAuthToken; - } - - /** - *@param mwsAuthToken Sets MWSAuthToken parameter in request. MWSAuthToken is required - * only for third-party solution providers and marketplaces. Do not - * specify this parameter for merchants creating their own custom integration. - * - * @return The MWSAuthToken - */ - public SetMWSAuthToken setMwsAuthToken(String mwsAuthToken) { - this.mwsAuthToken = mwsAuthToken; - return this; - } -} diff --git a/src/com/amazon/pay/request/SetOrderAttributesRequest.java b/src/com/amazon/pay/request/SetOrderAttributesRequest.java index ab45a7d..4a0b6a6 100644 --- a/src/com/amazon/pay/request/SetOrderAttributesRequest.java +++ b/src/com/amazon/pay/request/SetOrderAttributesRequest.java @@ -1,5 +1,5 @@ /** - * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -25,7 +25,12 @@ * For more information documentation, see * https://pay.amazon.com/documentation/ */ -public class SetOrderAttributesRequest extends SetMWSAuthToken implements Serializable { +public class SetOrderAttributesRequest extends DelegateRequest implements Serializable { + + @Override + protected SetOrderAttributesRequest getThis() { + return this; + } //required parameters private String amazonOrderReferenceId; @@ -40,6 +45,7 @@ public class SetOrderAttributesRequest extends SetMWSAuthToken implements Serial private Boolean requestPaymentAuthorization; private String sellerOrderId; private String storeName; + private String supplementaryData; private String customInformation; private String paymentServiceProviderId; private String paymentServiceProviderOrderId; @@ -237,6 +243,28 @@ public SetOrderAttributesRequest setStoreName(String storeName) { return this; } + /** + * Returns the trusted authorization supplementary data. + * + * @return supplementaryData as a JSON string + */ + public String getSupplementaryData() { + return supplementaryData; + } + + /** + * Set the trusted authorization supplementary data. + * Use only as directed by Amazon Pay. + * + * @param supplementaryData Trusted authorization supplementary data (JSON string) + * + * @return Request object + */ + public SetOrderAttributesRequest setSupplementaryData(final String supplementaryData) { + this.supplementaryData = supplementaryData; + return this; + } + /** * Returns the custom information * @@ -342,6 +370,7 @@ public String toString() { + ", sellerNote=" + sellerNote + ", sellerOrderId=" + sellerOrderId + ", storeName=" + storeName + + ", supplementaryData=" + supplementaryData + ", customInformation=" + customInformation + ", requesPaymentAuthorization=" + requestPaymentAuthorization.toString() + ", paymentServiceProviderId=" + paymentServiceProviderId diff --git a/src/com/amazon/pay/request/SetOrderReferenceDetailsRequest.java b/src/com/amazon/pay/request/SetOrderReferenceDetailsRequest.java index 94906bf..3ecbbef 100644 --- a/src/com/amazon/pay/request/SetOrderReferenceDetailsRequest.java +++ b/src/com/amazon/pay/request/SetOrderReferenceDetailsRequest.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -22,7 +22,12 @@ * For more information documentation, see * https://pay.amazon.com/documentation/ */ -public class SetOrderReferenceDetailsRequest implements Serializable{ +public class SetOrderReferenceDetailsRequest extends DelegateRequest implements Serializable { + + @Override + protected SetOrderReferenceDetailsRequest getThis() { + return this; + } //required parameters private String amazonOrderReferenceId; @@ -34,14 +39,14 @@ public class SetOrderReferenceDetailsRequest implements Serializable{ private String sellerNote; private String sellerOrderId; private String storeName; + private String supplementaryData; private String customInformation; - private String mwsAuthToken; private Boolean requestPaymentAuthorization; /** * * @param amazonOrderReferenceId - * This value is retrieved from the Amazon Button widget + * This value is retrieved from the Amazon Button widget * after the buyer has successfully authenticated with Amazon. * * @param orderAmount @@ -66,9 +71,9 @@ public SetOrderReferenceDetailsRequest setOrderCurrencyCode(CurrencyCode currenc } /** - * Represents the SellerId of the Solution Provider that developed the platform. - * This value should only be provided by Solution Providers. It should not be - * provided by merchants creating their own custom integration. + * Represents the SellerId of the Solution Provider that developed the platform. + * This value should only be provided by Solution Providers. It should not be + * provided by merchants creating their own custom integration. * * @param platformId Represents the SellerId of the Solution Provider that developed the platform. * This value should only be provided by Solution Providers. It should @@ -94,7 +99,7 @@ public SetOrderReferenceDetailsRequest setSellerNote(String sellerNote) { } /** - * The merchant-specified identifier of this order. This is displayed to the + * The merchant-specified identifier of this order. This is displayed to the * buyer in their emails and transaction history on the Amazon Pay website. * * @param sellerOrderId merchant-specified identifier of the order. @@ -107,9 +112,9 @@ public SetOrderReferenceDetailsRequest setSellerOrderId(String sellerOrderId) { } /** - * The identifier of the store from which the order was placed. This overrides + * The identifier of the store from which the order was placed. This overrides * the default value in Seller Central under Settings > Account Settings. It is - * displayed to the buyer in their emails and transaction history on the + * displayed to the buyer in their emails and transaction history on the * Amazon Pay website. * * @param storeName the identifier of the store from which the order was placed. @@ -122,28 +127,27 @@ public SetOrderReferenceDetailsRequest setStoreName(String storeName) { } /** - * Any additional information that you want to include with this order reference. + * Set the trusted authorization supplementary data. + * Use only as directed by Amazon Pay. * - * @param customInformation Additional information that merchant wants to pass for the order. + * @param supplementaryData Trusted authorization supplementary data (JSON string) * - * @return Custom Information + * @return Request object */ - public SetOrderReferenceDetailsRequest setCustomInformation(String customInformation) { - this.customInformation = customInformation; + public SetOrderReferenceDetailsRequest setSupplementaryData(final String supplementaryData) { + this.supplementaryData = supplementaryData; return this; } /** - * Applicable only for third-party solution providers or marketplaces. It should not be - * provided by merchants creating their own custom integration. + * Any additional information that you want to include with this order reference. * - * @param mwsAuthToken Sets MWSAuthToken. Applicable for third-party - * solution providers only. + * @param customInformation Additional information that merchant wants to pass for the order. * - * @return the MWSAuthToken + * @return Custom Information */ - public SetOrderReferenceDetailsRequest setMWSAuthToken(String mwsAuthToken) { - this.mwsAuthToken = mwsAuthToken; + public SetOrderReferenceDetailsRequest setCustomInformation(String customInformation) { + this.customInformation = customInformation; return this; } @@ -204,19 +208,20 @@ public String getStoreName() { } /** + * Returns the trusted authorization supplementary data. * - * @return CustomInformation + * @return supplementaryData as a JSON string */ - public String getCustomInformation() { - return customInformation; + public String getSupplementaryData() { + return supplementaryData; } /** * - * @return MWSAuthToken + * @return CustomInformation */ - public String getMwsAuthToken() { - return mwsAuthToken; + public String getCustomInformation() { + return customInformation; } /** @@ -251,8 +256,17 @@ public SetOrderReferenceDetailsRequest setRequestPaymentAuthorization(Boolean re */ @Override public String toString() { - return "SetOrderReferenceDetailsRequest{" + "amazonOrderReferenceId=" + amazonOrderReferenceId + ", orderAmount=" + orderAmount - + ", orderCurrencyCode=" + orderCurrencyCode + ", platformId=" + platformId + ", sellerNote=" + sellerNote + ", sellerOrderId=" - + sellerOrderId + ", storeName=" + storeName + ", customInformation=" + customInformation + ", mwsAuthToken=" + mwsAuthToken + '}'; + return "SetOrderReferenceDetailsRequest{" + + "amazonOrderReferenceId=" + amazonOrderReferenceId + + ", orderAmount=" + orderAmount + + ", orderCurrencyCode=" + orderCurrencyCode + + ", platformId=" + platformId + + ", sellerNote=" + sellerNote + + ", sellerOrderId=" + sellerOrderId + + ", storeName=" + storeName + + ", supplementaryData=" + supplementaryData + + ", customInformation=" + customInformation + + ", mwsAuthToken=" + getMwsAuthToken() + '}'; } + } diff --git a/src/com/amazon/pay/request/ValidateBillingAgreementRequest.java b/src/com/amazon/pay/request/ValidateBillingAgreementRequest.java index bd36391..06c085d 100644 --- a/src/com/amazon/pay/request/ValidateBillingAgreementRequest.java +++ b/src/com/amazon/pay/request/ValidateBillingAgreementRequest.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -21,35 +21,25 @@ * For more information documentation, see * https://pay.amazon.com/documentation/ */ -public class ValidateBillingAgreementRequest implements Serializable{ +public class ValidateBillingAgreementRequest extends DelegateRequest implements Serializable { + + @Override + protected ValidateBillingAgreementRequest getThis() { + return this; + } //required parameters private String amazonBillingAgreementId; - //optional parameters - private String mwsAuthToken; - /** * - * @param amazonBillingAgreementId The billing agreement identifier. + * @param amazonBillingAgreementId The billing agreement identifier. * This value is retrieved from the Amazon Button, AddressBook, or Wallet widgets. */ public ValidateBillingAgreementRequest(String amazonBillingAgreementId) { this.amazonBillingAgreementId = amazonBillingAgreementId; } - /** - * Sets MWSAuthToken. This is applicable for third-party solution providers only - * @param mwsAuthToken Sets MWSAuthToken. Applicable for third-party - * solution providers only. - * - * @return the MWSAuthToken - */ - public ValidateBillingAgreementRequest setMWSAuthToken(String mwsAuthToken) { - this.mwsAuthToken = mwsAuthToken; - return this; - } - /** * * @return AmazonBillingAgreementId @@ -58,14 +48,6 @@ public String getAmazonBillingAgreementId() { return amazonBillingAgreementId; } - /** - * - * @return MWSAuthToken - */ - public String getMwsAuthToken() { - return mwsAuthToken; - } - /** * Returns a string representation of this object; useful for testing and * debugging. @@ -76,6 +58,9 @@ public String getMwsAuthToken() { */ @Override public String toString() { - return "ValidateBillingAgreementRequest{" + "amazonBillingAgreementId=" + amazonBillingAgreementId + ", mwsAuthToken=" + mwsAuthToken + '}'; + return "ValidateBillingAgreementRequest{" + + "amazonBillingAgreementId=" + amazonBillingAgreementId + + ", mwsAuthToken=" + getMwsAuthToken() + '}'; } + } diff --git a/src/com/amazon/pay/response/model/AccountStatus.java b/src/com/amazon/pay/response/model/AccountStatus.java new file mode 100644 index 0000000..81ae979 --- /dev/null +++ b/src/com/amazon/pay/response/model/AccountStatus.java @@ -0,0 +1,30 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package com.amazon.pay.response.model; + +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlEnumValue; +import javax.xml.bind.annotation.XmlType; + +@XmlType(name = "AccountStatus") +@XmlEnum +public enum AccountStatus { + + @XmlEnumValue("ACTIVE") + ACTIVE, + @XmlEnumValue("INACTIVE") + INACTIVE + +} diff --git a/src/com/amazon/pay/response/model/BillingAgreementDetails.java b/src/com/amazon/pay/response/model/BillingAgreementDetails.java index c5cd248..b11406d 100644 --- a/src/com/amazon/pay/response/model/BillingAgreementDetails.java +++ b/src/com/amazon/pay/response/model/BillingAgreementDetails.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2016-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -14,6 +14,8 @@ */ package com.amazon.pay.response.model; +import com.amazon.pay.types.BillingAgreementType; + import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; @@ -23,21 +25,23 @@ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "BillingAgreementDetails", propOrder = { - "amazonBillingAgreementId", - "billingAgreementLimits", - "buyer", - "sellerNote", - "platformId", - "destination", - "billingAddress", - "releaseEnvironment", - "sellerBillingAgreementAttributes", - "billingAgreementStatus", - "constraints", - "creationTimestamp", - "expirationTimestamp", - "billingAgreementConsent", - "orderLanguage" + "amazonBillingAgreementId", + "billingAgreementLimits", + "buyer", + "sellerNote", + "platformId", + "destination", + "billingAddress", + "releaseEnvironment", + "sellerBillingAgreementAttributes", + "billingAgreementStatus", + "constraints", + "creationTimestamp", + "expirationTimestamp", + "billingAgreementConsent", + "orderLanguage", + "subscriptionAmount", + "billingAgreementType" }) public class BillingAgreementDetails { @@ -73,7 +77,11 @@ public class BillingAgreementDetails { protected Boolean billingAgreementConsent; @XmlElement(name = "OrderLanguage") protected String orderLanguage; - + @XmlElement(name = "SubscriptionAmount") + protected Price subscriptionAmount; + @XmlElement(name = "BillingAgreementType") + protected BillingAgreementType billingAgreementType; + public BillingAgreementDetails() { super(); @@ -81,7 +89,7 @@ public BillingAgreementDetails() { /** * This value is retrieved from the Amazon Button, AddressBook, or Wallet widgets. - * + * * @return amazonBillingAgreementId */ public String getAmazonBillingAgreementId() { @@ -91,7 +99,7 @@ public String getAmazonBillingAgreementId() { /** * Represents the total amount that you can charge a buyer in a given time period. - * + * * @return billingAgreementLimits */ public BillingAgreementLimits getBillingAgreementLimits() { @@ -99,9 +107,9 @@ public BillingAgreementLimits getBillingAgreementLimits() { } /** - * Provides details about the buyer. This information will + * Provides details about the buyer. This information will * only be returned after you confirm the billing agreement. - * + * * @return buyer */ public Buyer getBuyer() { @@ -109,11 +117,11 @@ public Buyer getBuyer() { } /** - * Represents a description of the billing agreement that is displayed + * Represents a description of the billing agreement that is displayed * in emails to the buyer and on the Amazon Pay website. This response - * element is not returned if you have not set it by calling the + * element is not returned if you have not set it by calling the * SetBillingAgreementDetails operation. - * + * * @return sellerNote */ public String getSellerNote() { @@ -122,7 +130,7 @@ public String getSellerNote() { /** * Represents the SellerId of the Solution Provider that developed the platform. - * + * * @return platformId */ public String getPlatformId() { @@ -130,13 +138,13 @@ public String getPlatformId() { } /** - * - * Represents the address selected by the buyer through the AddressBook widget. - * Complete buyer information will only be returned after you have confirmed the - * billing agreement or have specified a valid AddressConsentToken in the + * + * Represents the address selected by the buyer through the AddressBook widget. + * Complete buyer information will only be returned after you have confirmed the + * billing agreement or have specified a valid AddressConsentToken in the * GetBillingAgreementDetails operation. Until then, only the City, StateOrRegion, * PostalCode, and CountryCode elements are returned. - * + * * @return destination */ public Destination getDestination() { @@ -149,7 +157,7 @@ public BillingAddress getBillingAddress() { /** * Indicates if the order is for a Live (Production) or Sandbox environment. - * + * * @return releaseEnvironment */ public Environment getReleaseEnvironment() { @@ -157,10 +165,10 @@ public Environment getReleaseEnvironment() { } /** - * Provides more context about the billing agreement represented by this Billing Agreement object. - * This response element is not returned if you have not set it by calling the + * Provides more context about the billing agreement represented by this Billing Agreement object. + * This response element is not returned if you have not set it by calling the * SetBillingAgreementDetails operation. - * + * * @return sellerBillingAgreementAttributes */ public SellerBillingAgreementAttributes getSellerBillingAgreementAttributes() { @@ -168,10 +176,10 @@ public SellerBillingAgreementAttributes getSellerBillingAgreementAttributes() { } /** - * Indicates the current status of the billing agreement. - * For more information about the State and ReasonCode response elements, + * Indicates the current status of the billing agreement. + * For more information about the State and ReasonCode response elements, * see Billing Agreement States and Reason Codes. - * + * * @return billingAgreementStatus */ public BillingAgreementStatus getBillingAgreementStatus() { @@ -179,10 +187,10 @@ public BillingAgreementStatus getBillingAgreementStatus() { } /** - * A list of constraints that indicates mandatory information that is missing - * or incorrect. The presence of constraints indicates that the billing agreement + * A list of constraints that indicates mandatory information that is missing + * or incorrect. The presence of constraints indicates that the billing agreement * is not ready to be confirmed and cannot be used for payment operations. - * + * * @return constraints */ public Constraints getConstraints() { @@ -191,7 +199,7 @@ public Constraints getConstraints() { /** * The date and time, in UTC, when the billing agreement was created. In ISO 8601 format. - * + * * @return creationTimestamp */ public XMLGregorianCalendar getCreationTimestamp() { @@ -199,7 +207,7 @@ public XMLGregorianCalendar getCreationTimestamp() { } /** - * + * * @return expirationTimestamp */ public XMLGregorianCalendar getExpirationTimestamp() { @@ -215,13 +223,29 @@ public Boolean isBillingAgreementConsent() { } /** - * + * * @return orderLanguage */ public String getOrderLanguage() { return orderLanguage; } + /** + * + * @return subscriptionAmount + */ + public Price getSubscriptionAmount() { + return subscriptionAmount; + } + + /** + * + * @return billingAgreementType + */ + public BillingAgreementType getBillingAgreementType() { + return billingAgreementType; + } + /** * String representation of Billing Agreement */ @@ -242,7 +266,9 @@ public String toString() { + ", creationTimestamp=" + creationTimestamp + ", expirationTimestamp=" + expirationTimestamp + ", billingAgreementConsent=" + billingAgreementConsent - + ", orderLanguage=" + orderLanguage + '}'; + + ", orderLanguage=" + orderLanguage + + ", subscriptionAmount=" + subscriptionAmount + + ", billingAgreementType=" + billingAgreementType + '}'; } diff --git a/src/com/amazon/pay/response/model/ErrorResponse.java b/src/com/amazon/pay/response/model/ErrorResponse.java index 49a1706..529eef1 100644 --- a/src/com/amazon/pay/response/model/ErrorResponse.java +++ b/src/com/amazon/pay/response/model/ErrorResponse.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -22,18 +22,23 @@ import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; + @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "error", - "requestId" + "requestId", + "requestID" }) @XmlRootElement(name = "ErrorResponse") public class ErrorResponse { @XmlElement(name = "Error", required = true) protected List error; - @XmlElement(name = "RequestId", required = true) + @XmlElement(name = "RequestId") protected String requestId; + // Throttled error requests come back with "RequestID" node names instaed of "RequestId" + @XmlElement(name = "RequestID") + protected String requestID; public ErrorResponse() { super(); @@ -47,8 +52,13 @@ public List getError() { return this.error; } + // Regardless of type of error, return the RequestId in a consistent way public String getRequestId() { - return requestId; + if (requestId != null) { + return requestId; + } else { + return requestID; + } } diff --git a/src/com/amazon/pay/response/model/GetMerchantAccountStatusResponse.java b/src/com/amazon/pay/response/model/GetMerchantAccountStatusResponse.java new file mode 100644 index 0000000..c22a3a2 --- /dev/null +++ b/src/com/amazon/pay/response/model/GetMerchantAccountStatusResponse.java @@ -0,0 +1,65 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package com.amazon.pay.response.model; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +/** + * This represents the parsed response from the Amazon Pay + * GetMerchantAccountStatus API. + * + *
{@code
+ *      
+ *        
+ *          ACTIVE
+ *        
+ *        
+ *          986dce6b-45e2-4883-bbf4-17adce5994a4
+ *        
+ *      
+ *  }
+ * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "getMerchantAccountStatusResult", + "responseMetadata" +}) +@XmlRootElement(name = "GetMerchantAccountStatusResponse") +public class GetMerchantAccountStatusResponse { + + @XmlElement(name = "GetMerchantAccountStatusResult", required = true) + protected GetMerchantAccountStatusResult getMerchantAccountStatusResult; + + @XmlElement(name = "ResponseMetadata", required = true) + protected ResponseMetadata responseMetadata; + + public GetMerchantAccountStatusResponse() { + super(); + } + + public GetMerchantAccountStatusResult getMerchantAccountStatusResult() { + return getMerchantAccountStatusResult; + } + + public ResponseMetadata getResponseMetadata() { + return responseMetadata; + } + +} diff --git a/src/com/amazon/pay/response/model/GetMerchantAccountStatusResult.java b/src/com/amazon/pay/response/model/GetMerchantAccountStatusResult.java new file mode 100644 index 0000000..d0b0d97 --- /dev/null +++ b/src/com/amazon/pay/response/model/GetMerchantAccountStatusResult.java @@ -0,0 +1,64 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package com.amazon.pay.response.model; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +/** + * This represents the GetMerchantAccountStatusResult node parsed + * from the Amazon Pay GetMerchantAccountStatusResponse. + * + *
{@code
+ *      
+ *        ACTIVE
+ *      
+ *  }
+ * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = { + "accountStatus" +}) +@XmlRootElement(name = "GetMerchantAccountStatusResult") +public class GetMerchantAccountStatusResult { + + @XmlElement(name = "AccountStatus", required = true) + protected AccountStatus accountStatus; + + public GetMerchantAccountStatusResult() { + super(); + } + + /** + * @return account status: + * ACTIVE - Merchant account is active + * INACTIVE - Merchant account is not active + */ + public AccountStatus getAccountStatus() { + return accountStatus; + } + + /** + * Returns the string representation of GetMerchantAccountStatusResult + */ + @Override + public String toString() { + return "GetMerchantAccountStatus{" + "accountStatus=" + accountStatus + "}"; + } +} diff --git a/src/com/amazon/pay/response/model/GetOrderReferenceDetailsResponse.java b/src/com/amazon/pay/response/model/GetOrderReferenceDetailsResponse.java index 7984495..96617ec 100644 --- a/src/com/amazon/pay/response/model/GetOrderReferenceDetailsResponse.java +++ b/src/com/amazon/pay/response/model/GetOrderReferenceDetailsResponse.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -37,7 +37,7 @@ public class GetOrderReferenceDetailsResponse { public GetOrderReferenceDetailsResponse() { super(); } - + public GetOrderReferenceDetailsResult getGetOrderReferenceDetailsResult() { return getOrderReferenceDetailsResult; } @@ -45,8 +45,7 @@ public GetOrderReferenceDetailsResult getGetOrderReferenceDetailsResult() { public ResponseMetadata getResponseMetadata() { return responseMetadata; } - - + @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "orderReferenceDetails" @@ -65,4 +64,4 @@ public OrderReferenceDetails getOrderReferenceDetails() { return orderReferenceDetails; } } -} \ No newline at end of file +} diff --git a/src/com/amazon/pay/response/model/OrderReferenceDetails.java b/src/com/amazon/pay/response/model/OrderReferenceDetails.java index f122121..e1da6f1 100644 --- a/src/com/amazon/pay/response/model/OrderReferenceDetails.java +++ b/src/com/amazon/pay/response/model/OrderReferenceDetails.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2016-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -44,7 +44,9 @@ "idList", "orderLanguage", "requestPaymentAuthorization", - "paymentServiceProviderAttributes" + "paymentServiceProviderAttributes", + "paymentReference", + "paymentAuthenticationStatus" }) public class OrderReferenceDetails { @@ -88,6 +90,10 @@ public class OrderReferenceDetails { protected Boolean requestPaymentAuthorization; @XmlElement(name = "PaymentServiceProviderAttributes") protected PaymentServiceProviderAttributes paymentServiceProviderAttributes; + @XmlElement(name = "PaymentReference") + protected PaymentReference paymentReference; + @XmlElement(name = "PaymentAuthenticationStatus") + protected PaymentAuthenticationStatus paymentAuthenticationStatus; public OrderReferenceDetails() { super(); @@ -284,9 +290,24 @@ public PaymentServiceProviderAttributes getPaymentServiceProviderAttributes() { } /** - * String representation of OrderReferenceDetails + * + * @return paymentReference */ + public PaymentReference getPaymentReference() { + return paymentReference; + } + /** + * + * @return paymentAuthenticationStatus + */ + public PaymentAuthenticationStatus getPaymentAuthenticationStatus() { + return paymentAuthenticationStatus; + } + + /** + * String representation of OrderReferenceDetails + */ @Override public String toString() { return "OrderReferenceDetails{" @@ -308,6 +329,9 @@ public String toString() { + ", idList=" + idList + ", orderLanguage=" + orderLanguage + ", requestPaymentAuthorization=" + requestPaymentAuthorization - + ", paymentServiceProviderAttributes=" + paymentServiceProviderAttributes + '}'; + + ", paymentServiceProviderAttributes=" + paymentServiceProviderAttributes + + ", paymentReference=" + paymentReference + + ", paymentAuthenticationStatus=" + paymentAuthenticationStatus + + '}'; } } diff --git a/src/com/amazon/pay/response/model/OrderReferenceList.java b/src/com/amazon/pay/response/model/OrderReferenceList.java index 8079282..e3f984f 100644 --- a/src/com/amazon/pay/response/model/OrderReferenceList.java +++ b/src/com/amazon/pay/response/model/OrderReferenceList.java @@ -23,6 +23,18 @@ import java.util.ArrayList; import java.util.List; +/** + * This represents the OrderReferenceList node parsed + * from the Amazon Pay ListOrderReference API response. + * + * <OrderReferenceList> + * <OrderReference> + * ... + * </OrderReference> + * </OrderReferenceList> + * + */ + @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "orderReferences" @@ -47,4 +59,4 @@ public List getOrderReferences() { } return orderReferences; } -} \ No newline at end of file +} diff --git a/src/com/amazon/pay/response/model/PaymentAuthenticationStatus.java b/src/com/amazon/pay/response/model/PaymentAuthenticationStatus.java new file mode 100644 index 0000000..1bad2f1 --- /dev/null +++ b/src/com/amazon/pay/response/model/PaymentAuthenticationStatus.java @@ -0,0 +1,50 @@ +/** + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package com.amazon.pay.response.model; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlType; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "PaymentAuthenticationStatus", propOrder = { + "state" +}) + +public class PaymentAuthenticationStatus { + @XmlElement(name = "State") + protected String state; + + public PaymentAuthenticationStatus() { + super(); + } + + /** + * @return The Strong Customer Authentication (SCA) payment authentication status flag + */ + @Deprecated + public String getState() { + return state; + } + + @Override + public String toString() { + return "PaymentAuthenticationStatus{" + + "state=" + state + + '}'; + } +} diff --git a/src/com/amazon/pay/response/model/PaymentReference.java b/src/com/amazon/pay/response/model/PaymentReference.java new file mode 100644 index 0000000..e776309 --- /dev/null +++ b/src/com/amazon/pay/response/model/PaymentReference.java @@ -0,0 +1,50 @@ +/** + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package com.amazon.pay.response.model; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlType; + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "PaymentReference", propOrder = { + "staticToken" +}) + +public class PaymentReference { + @XmlElement(name = "StaticToken") + protected String staticToken; + + public PaymentReference() { + super(); + } + + /** + * @return The unique payment instrument token. + */ + @Deprecated + public String getStaticToken() { + return staticToken; + } + + @Override + public String toString() { + return "PaymentReference{" + + "staticToken=" + staticToken + + '}'; + } +} diff --git a/src/com/amazon/pay/response/model/SellerOrderAttributes.java b/src/com/amazon/pay/response/model/SellerOrderAttributes.java index 5fa1ba9..49a652d 100644 --- a/src/com/amazon/pay/response/model/SellerOrderAttributes.java +++ b/src/com/amazon/pay/response/model/SellerOrderAttributes.java @@ -26,6 +26,7 @@ @XmlType(name = "SellerOrderAttributes", propOrder = { "sellerOrderId", "storeName", + "supplementaryData", "orderItemCategories", "customInformation", "sellerId" @@ -36,6 +37,8 @@ public class SellerOrderAttributes { protected String sellerOrderId; @XmlElement(name = "StoreName") protected String storeName; + @XmlElement(name = "SupplementaryData") + protected String supplementaryData; @XmlElement(name = "OrderItemCategories") protected OrderItemCategories orderItemCategories; @XmlElement(name = "CustomInformation") @@ -72,6 +75,16 @@ public String getStoreName() { } + /** + * Returns the trusted authorization supplementary data. + * + * @return supplementaryData as a JSON string + */ + public String getSupplementaryData() { + return supplementaryData; + } + + /** * * @return orderItemCategories @@ -110,6 +123,7 @@ public String toString() { return "SellerOrderAttributes{" + "sellerOrderId=" + sellerOrderId + ", storeName=" + storeName + + ", supplementaryData=" + supplementaryData + ", sellerId=" + sellerId + ", orderItemCategorie=" + orderItemCategories + ", customInformation=" + customInformation + '}'; diff --git a/src/com/amazon/pay/response/parser/GetMerchantAccountStatusResponseData.java b/src/com/amazon/pay/response/parser/GetMerchantAccountStatusResponseData.java new file mode 100644 index 0000000..832942e --- /dev/null +++ b/src/com/amazon/pay/response/parser/GetMerchantAccountStatusResponseData.java @@ -0,0 +1,70 @@ +/** + * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package com.amazon.pay.response.parser; + +import com.amazon.pay.response.model.AccountStatus; +import com.amazon.pay.response.model.GetMerchantAccountStatusResponse; + +import java.io.Serializable; + +/** + * Response from GetMerchantAccountStatus API, as returned by Amazon Pay + */ +public final class GetMerchantAccountStatusResponseData extends ResponseData implements Serializable { + + private String requestId; + private AccountStatus accountStatus; + + public GetMerchantAccountStatusResponseData(GetMerchantAccountStatusResponse response, ResponseData rawResponse) { + super(rawResponse); + if (response != null) { + this.requestId = response.getResponseMetadata().getRequestId(); + if (response.getMerchantAccountStatusResult() != null) { + accountStatus = response.getMerchantAccountStatusResult().getAccountStatus(); + } + } + } + + /** + * The AccountStatus enum that identifies the merchant acconut as + * being ACTIVE or INACTIVE. + * + * @return The AccountStatus enum. + */ + public AccountStatus getAccountStatus() { + return accountStatus; + } + + /** + * The requestID that uniquely identifies the service request + * the caller made. + * + * @return The requestID that uniquely identifies the service request + * the caller made. + */ + public String getRequestId() { + return requestId; + } + + /** + * Returns the string representation of GetOrderReferenceDetailsResponseData + */ + @Override + public String toString() { + return "GetServiceStatusResponseData{" + "requestId=" + requestId + + ", accountStatus=" + accountStatus + "}"; + } + +} diff --git a/src/com/amazon/pay/response/parser/GetOrderReferenceDetailsResponseData.java b/src/com/amazon/pay/response/parser/GetOrderReferenceDetailsResponseData.java index cbf5f15..d5cb337 100644 --- a/src/com/amazon/pay/response/parser/GetOrderReferenceDetailsResponseData.java +++ b/src/com/amazon/pay/response/parser/GetOrderReferenceDetailsResponseData.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -21,16 +21,16 @@ /** * Response from GetOrderReferenceDetails service API, as returned by Amazon Pay */ -public final class GetOrderReferenceDetailsResponseData extends ResponseData implements Serializable{ - +public final class GetOrderReferenceDetailsResponseData extends ResponseData implements Serializable { + private String requestId; private OrderReferenceDetails orderReferenceDetails; - + public GetOrderReferenceDetailsResponseData(GetOrderReferenceDetailsResponse response , ResponseData rawResponse) { super(rawResponse); - if(response != null) { + if (response != null) { this.requestId = response.getResponseMetadata().getRequestId(); - if(response.getGetOrderReferenceDetailsResult() != null) { + if (response.getGetOrderReferenceDetailsResult() != null) { orderReferenceDetails = response.getGetOrderReferenceDetailsResult().getOrderReferenceDetails(); } } @@ -39,7 +39,7 @@ public GetOrderReferenceDetailsResponseData(GetOrderReferenceDetailsResponse res /** * The requestID that uniquely identifies the service request * the caller made. - * + * * @return The requestID that uniquely identifies the service request * the caller made. */ @@ -63,8 +63,5 @@ public OrderReferenceDetails getDetails() { public String toString() { return "GetOrderReferenceDetailsResponseData{" + "requestId=" + requestId + ", orderReferenceDetails=" + orderReferenceDetails.toString() + '}'; } - - - } diff --git a/src/com/amazon/pay/response/parser/Parser.java b/src/com/amazon/pay/response/parser/Parser.java index 08ab564..779f3d9 100644 --- a/src/com/amazon/pay/response/parser/Parser.java +++ b/src/com/amazon/pay/response/parser/Parser.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ import com.amazon.pay.response.model.GetBillingAgreementDetailsResponse; import com.amazon.pay.response.model.GetCaptureDetailsResponse; import com.amazon.pay.response.model.GetOrderReferenceDetailsResponse; +import com.amazon.pay.response.model.GetMerchantAccountStatusResponse; import com.amazon.pay.response.model.GetProviderCreditReversalDetailsResponse; import com.amazon.pay.response.model.GetProviderCreditDetailsResponse; import com.amazon.pay.response.model.GetRefundDetailsResponse; @@ -178,17 +179,22 @@ public static CreateOrderReferenceForIdResponseData createOrderReferenceForId( public static ListOrderReferenceResponseData listOrderReference(ResponseData rawResponse) throws AmazonServiceException { final ListOrderReferenceResponse response = marshalXML(ListOrderReferenceResponse.class, rawResponse); - return new ListOrderReferenceResponseData(response,rawResponse); + return new ListOrderReferenceResponseData(response, rawResponse); } public static ListOrderReferenceByNextTokenResponseData listOrderReferenceByNextToken(ResponseData rawResponse) throws AmazonServiceException { final ListOrderReferenceByNextTokenResponse response = marshalXML(ListOrderReferenceByNextTokenResponse.class, rawResponse); - return new ListOrderReferenceByNextTokenResponseData(response,rawResponse); + return new ListOrderReferenceByNextTokenResponseData(response, rawResponse); } public static SetOrderAttributesResponseData setOrderAttributes(ResponseData rawResponse) throws AmazonServiceException { final SetOrderAttributesResponse response = marshalXML(SetOrderAttributesResponse.class, rawResponse); - return new SetOrderAttributesResponseData(response,rawResponse); + return new SetOrderAttributesResponseData(response, rawResponse); + } + + public static GetMerchantAccountStatusResponseData getMerchantAccountStatus(ResponseData rawResponse) throws AmazonServiceException { + final GetMerchantAccountStatusResponse response = marshalXML(GetMerchantAccountStatusResponse.class, rawResponse); + return new GetMerchantAccountStatusResponseData(response, rawResponse); } public static T marshalXML(Class clazz, ResponseData rawResponse) throws AmazonServiceException { @@ -232,7 +238,7 @@ public static void generateErrorException(ResponseData rawResponse) throws Amazo final StringReader reader = new StringReader(noNamespaceXML); final Unmarshaller unmarshaller = context.createUnmarshaller(); - final XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory(); + final XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance(); xmlInputFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false); try { diff --git a/src/com/amazon/pay/response/parser/ResponseData.java b/src/com/amazon/pay/response/parser/ResponseData.java index f36a885..2d1aedd 100644 --- a/src/com/amazon/pay/response/parser/ResponseData.java +++ b/src/com/amazon/pay/response/parser/ResponseData.java @@ -59,6 +59,8 @@ public String toXML() { /** * Converts the raw XML response to JSON format * + * @throws JSONException + * If the XML response cannot be converted into JSON * @return * JSON representation of response returned by Amazon Service API */ diff --git a/src/com/amazon/pay/types/BillingAgreementType.java b/src/com/amazon/pay/types/BillingAgreementType.java new file mode 100644 index 0000000..3fd87c3 --- /dev/null +++ b/src/com/amazon/pay/types/BillingAgreementType.java @@ -0,0 +1,25 @@ +/** + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package com.amazon.pay.types; + +/** + * Attribute to determine whether the Billing Agreement is merchant initiated or customer initiated. + */ + +public enum BillingAgreementType { + CustomerInitiatedTransaction, + MerchantInitiatedTransaction +} diff --git a/src/com/amazon/pay/types/ServiceConstants.java b/src/com/amazon/pay/types/ServiceConstants.java index 569f636..b6ca2c0 100644 --- a/src/com/amazon/pay/types/ServiceConstants.java +++ b/src/com/amazon/pay/types/ServiceConstants.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2016-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -42,11 +42,17 @@ public class ServiceConstants { public static final String BA_CUSTOM_INFORMATION = "SellerOrderAttributes.CustomInformation"; public static final String BA_SELLER_ORDER_ID = "SellerOrderAttributes.SellerOrderId"; public static final String BA_STORE_NAME = "SellerOrderAttributes.StoreName"; + public static final String BA_SUPPLEMENTARY_DATA = "SellerOrderAttributes.SupplementaryData"; + public static final String BA_SELLER_NOTE = "SellerNote"; + public static final String BA_PLATFORM_ID = "PlatformId"; public static final String BILLING_AGREEMENT_PLATFORM_ID = "BillingAgreementAttributes.PlatformId"; public static final String BILLING_AGREEMENT_SELLER_BILLING_AGREEMENT_ID = "BillingAgreementAttributes.SellerBillingAgreementAttributes.SellerBillingAgreementId"; public static final String BILLING_AGREEMENT_SELLER_CUSTOM_INFORMATION = "BillingAgreementAttributes.SellerBillingAgreementAttributes.CustomInformation"; public static final String BILLING_AGREEMENT_SELLER_NOTE = "BillingAgreementAttributes.SellerNote"; public static final String BILLING_AGREEMENT_SELLER_STORE_NAME = "BillingAgreementAttributes.SellerBillingAgreementAttributes.StoreName"; + public static final String BILLING_AGREEMENT_TYPE = "BillingAgreementAttributes.BillingAgreementType"; + public static final String BILLING_AGREEMENT_SUBSCRIPTION_AMOUNT_CURRENCY_CODE = "BillingAgreementAttributes.SubscriptionAmount.CurrencyCode"; + public static final String BILLING_AGREEMENT_SUBSCRIPTION_AMOUNT_AMOUNT = "BillingAgreementAttributes.SubscriptionAmount.Amount"; public static final String CANCELATION_REASON = "CancelationReason"; public static final String CAPTURE_AMOUNT = "CaptureAmount.Amount"; public static final String CAPTURE_CURRENCEYCODE = "CaptureAmount.CurrencyCode"; @@ -75,6 +81,7 @@ public class ServiceConstants { public static final String SELLER_REFUND_NOTE = "SellerRefundNote"; public static final String SOFT_DESCRIPTOR = "SoftDescriptor"; public static final String STORE_NAME = "OrderReferenceAttributes.SellerOrderAttributes.StoreName"; + public static final String SUPPLEMENTARY_DATA = "OrderReferenceAttributes.SellerOrderAttributes.SupplementaryData"; public static final String REQUEST_PAYMENT_AUTHORIZATION = "OrderReferenceAttributes.RequestPaymentAuthorization"; public static final String TRANSACTION_TIMEOUT = "TransactionTimeout"; public static final String ORDER_ATTRIBUTES_AMOUNT = "OrderAttributes.OrderTotal.Amount"; @@ -88,6 +95,10 @@ public class ServiceConstants { public static final String ORDER_ATTRIBUTES_ORDER_ITEM_CATEGORIES = "OrderAttributes.SellerOrderAttributes.OrderItemCategories.OrderItemCategory"; public static final String ORDER_ATTRIBUTES_SELLER_ORDER_ID = "OrderAttributes.SellerOrderAttributes.SellerOrderId"; public static final String ORDER_ATTRIBUTES_STORE_NAME = "OrderAttributes.SellerOrderAttributes.StoreName"; + public static final String ORDER_ATTRIBUTES_SUPPLEMENTARY_DATA = "OrderAttributes.SellerOrderAttributes.SupplementaryData"; + public static final String SUCCESS_URL = "SuccessUrl"; + public static final String FAILURE_URL = "FailureUrl"; + public static final String EXPECT_IMMEDIATE_AUTHORIZATION = "ExpectImmediateAuthorization"; // API Request Parameters - (Mostly) Required Parameters public static final String ACTION = "Action"; @@ -139,9 +150,10 @@ public class ServiceConstants { public static final String LIST_ORDER_REFERENCE = "ListOrderReference"; public static final String LIST_ORDER_REFERENCE_BY_NEXT_TOKEN = "ListOrderReferenceByNextToken"; public static final String SET_ORDER_ATTRIBUTES = "SetOrderAttributes"; + public static final String GET_MERCHANT_ACCOUNT_STATUS = "GetMerchantAccountStatus"; // SDK version - public static final String APPLICATION_LIBRARY_VERSION = "3.3.2"; + public static final String APPLICATION_LIBRARY_VERSION = "3.7.1"; public static final String GITHUB_SDK_NAME = "amazon-pay-sdk-java"; // Exponential backoff wait times (milliseconds) for retry operations @@ -149,6 +161,10 @@ public class ServiceConstants { public static final int SECOND_RETRY_WAIT_TIME = 4000; public static final int THIRD_RETRY_WAIT_TIME = 10000; + // HTTP timeouts (milliseconds) + public static final int HTTP_READ_TIMEOUT = 30000; + public static final int HTTP_CONNECT_TIMEOUT = 30000; + static { Map mwsEndpointMappingsMap = new HashMap(); mwsEndpointMappingsMap.put(Region.UK, "https://mws-eu.amazonservices.com"); @@ -172,4 +188,13 @@ public class ServiceConstants { profileEndpointSandboxMappings = Collections.unmodifiableMap(profileEndpointSandboxMappingsMap); } + public static final String ERROR_DESCRIPTION = "error_description"; + public static final String ERROR = "error"; + public static final String GET = "GET"; + public static final String UTF_8 = "UTF-8"; + public static final String X_AMZ_ACCESS_TOKEN = "x-amz-access-token"; + public static final String AUTH_O2_TOKENINFO_URI = "/auth/o2/tokeninfo"; + public static final String USER_PROFILE_URI = "/user/profile"; + public static final String HMAC_SHA256 = "HmacSHA256"; + } diff --git a/tst/com/amazon/pay/TestConstants.java b/tst/com/amazon/pay/TestConstants.java index 606d27f..f5e7b9f 100644 --- a/tst/com/amazon/pay/TestConstants.java +++ b/tst/com/amazon/pay/TestConstants.java @@ -1,5 +1,5 @@ /** - * Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2016-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -16,8 +16,9 @@ package com.amazon.pay; public class TestConstants { + public static final String billingAgreementId = "CTEST_AMAZON_BILLING_AGREEMENT_ID"; - public static final String billinAgreementIdDraft ="TEST_AMAZON_BILLING_AGREEMENT_ID_DRAFT"; + public static final String billinAgreementIdDraft = "TEST_AMAZON_BILLING_AGREEMENT_ID_DRAFT"; public static final String addressConsentToken = "TEST_ADDRESS_CONSENT_TOKEN"; public static final String clientId = "TEST_CLIENT_ID"; public static final String tokenInfoResponse = "{\"aud\":\"TEST_CLIENT_ID\",\"user_id\":\"amzn1.account.AF5W6J2OG52NKFJGEN52GEZ5CWFQ\",\"iss\":\"https://www.amazon.com\",\"exp\":2370,\"app_id\":\"amzn1.application.5286e3c9cac24d8188908b500f4a05a5\",\"iat\":1446510240}"; @@ -25,21 +26,22 @@ public class TestConstants { public static final String userInfoResponse = "{\"user_id\":\"amzn1.account.AF5W6J2OG52NKFJGEN52GEZ5CWFQ\",\"name\":\"Test Buyer\",\"email\":\"testbuyer2@amazon.com\"}"; public static final String merchantId = "TEST_MERCHANT_ID"; public static final String accessKey = "TEST_ACCESS_KEY"; - public static final String secretKey = "TEST_SECRET_KEY"; + public static final char [] secretKey = new char[] {'T','E','S','T','_','S','E','C','R','E','T','_','K','E','Y'}; public static final String region = "us"; public static final String sandbox_mode = "true"; - public static final String timeStamp = "2015-00-00T00:00:00Z"; - public static final String urlEncoded_TimeStamp = "2015-00-00T00%3A00%3A00Z"; + public static final String timeStamp = "2015-12-31T23:59:58Z"; + public static final String urlEncoded_TimeStamp = "2015-12-31T23%3A59%3A58Z"; public static final String platformId = "A11WKBU7ADWTAU"; public static final String MWS_URL = "https://mws.amazonservices.com/OffAmazonPayments_Sandbox/2013-01-01"; public static final String mwsAuthToken = "TEST_MWS_AUTH_TOKEN"; - public static final String sampletext ="testNote"; - public static final String storeName ="TestStore"; + public static final String sampletext = "testNote"; + public static final String storeName = "TestStore"; public static final String sellerBillingAgreementId = "TEST_BILLING_AGREEMENT_ID"; public static final String softDescriptor = "AMZNTestTest"; public static final String amazonOrderReferenceId = "AMAZON_ORDER_REFERENCE_ID"; public static final String Endpoint500 = "https://www.example.com/"; public static final String providerSellerId = "TEST_PROVIDER_SELLER_ID"; + public static final String overrideSellerId = "OVERRIDE_SELLER_ID"; public static final String providerCreditId = "TEST_PROVIDER_CREDIT"; public static final String reversalProviderCreditId = "TEST_PROVIDER_REVERSAL_CREDIT"; public static final String reversalProviderCreditReferenceId = "TEST_PROVIDER_REVERSAL_CREDIT_REFERENCE_ID"; @@ -47,11 +49,16 @@ public class TestConstants { public static final String creditReferenceReversalId = "TEST_CREDIT_REFERENCE_REVERSAL_ID"; public static final String authorizationReferenceId = "TEST_AUTHORIZATION_REFERENCE_ID"; public static final String userProfileURL = "https://api.sandbox.amazon.com/user/profile"; - public static final String tokenInfoURL = "https://api.sandbox.amazon.com/auth/o2/tokeninfo?access_token="; + public static final String tokenInfoURL = "https://api.sandbox.amazon.com/auth/o2/tokeninfo"; public static final String OVERRIDE_SERVICE_URL = "https://override.service.test"; public static final String OVERRIDE_PROFILE_URL = "https://override.profile.test"; public static final String queryId = "OR-12345"; public static final String queryIdType = "SellerOrderId"; public static final int pageSize = 5; public static final String nextPageToken = "1eUc0QkJMVnJpcGgrbDNHclpIUT09IiwibWFya2V0cGxhY2VJZCI6IkEzQlhCMFlOM1hIMTdIIn0="; + public static final String SUPPLEMENTARY_DATA = "{\"AirlineMetaData\" : {\"version\": 1.0, \"airlineCode\": \"WN\", \"flightDate\": \"2018-03-24T20:29:19.22Z\", \"departureAirport\": \"CDG\", \"destinationAirport\": \"LUX\", \"bookedLastTime\": -1, \"classOfTravel\": \"F\", \"passengers\": {\"numberOfPassengers\": 4, \"numberOfChildren\": 1, \"numberOfInfants\": 1 }}, \"AccommodationMetaData\": {\"version\": 1.0, \"startDate\": \"2018-03-24T20:29:19.22Z\", \"endDate\": \"2018-03-24T20:29:19.22Z\", \"lengthOfStay\": 5, \"numberOfGuests\": 4, \"class\": \"Standard\", \"starRating\": 5, \"bookedLastTime\": -1 }, \"OrderMetaData\": {\"version\": 1.0, \"numberOfItems\": 3, \"type\": \"Digital\" }, \"BuyerMetaData\": {\"version\" : 1.0, \"isFirstTimeCustomer\" : true, \"numberOfPastPurchases\" : 2, \"numberOfDisputedPurchases\" : 3, \"hasOpenDispute\" : true, \"riskScore\" : 0.75 }}"; + public static final String AUTHORIZE_AMOUNT = "0.01"; + public static final String SUCCESS_URL = "https://pay.amazon.com/success.html"; + public static final String FAILURE_URL = "https://pay.amazon.com/failure.html"; + } diff --git a/tst/com/amazon/pay/impl/LoginUserInfoTest.java b/tst/com/amazon/pay/impl/LoginUserInfoTest.java index 2a2e056..fb7ae37 100644 --- a/tst/com/amazon/pay/impl/LoginUserInfoTest.java +++ b/tst/com/amazon/pay/impl/LoginUserInfoTest.java @@ -1,3 +1,17 @@ +/** + * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ package com.amazon.pay.impl; import com.amazon.pay.TestConstants; @@ -5,7 +19,9 @@ import com.amazon.pay.response.parser.ResponseData; import com.amazon.pay.types.CurrencyCode; import com.amazon.pay.types.Region; +import com.amazon.pay.types.ServiceConstants; import com.amazon.pay.types.User; +import java.net.HttpURLConnection; import java.net.URLDecoder; import java.util.HashMap; import java.util.Map; @@ -17,16 +33,15 @@ import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; - @RunWith(PowerMockRunner.class) @PrepareForTest(Util.class) public class LoginUserInfoTest { - + private final String accessToken = TestConstants.addressConsentToken; private final String clientId = TestConstants.clientId; private PayConfig config; private PayClient client; - + @Before public void setUp() throws Exception { PowerMockito.spy(Util.class); @@ -37,36 +52,34 @@ public void setUp() throws Exception { .withCurrencyCode(CurrencyCode.USD) .withSandboxMode(true) .withRegion(Region.US); - client = new PayClient(config); } - - @Test + + @Test public void testGetUserInfo() throws Exception { - - ResponseData tokenInfoResponse = new ResponseData(200 , TestConstants.tokenInfoResponse); - String tokenInfoURL = TestConstants.tokenInfoURL + URLDecoder.decode(accessToken, "UTF-8"); - PowerMockito.doReturn(tokenInfoResponse).when(Util.class, "httpSendRequest" , "GET", tokenInfoURL , null , new HashMap(), null); - - ResponseData userInfoResponse = new ResponseData(200 , TestConstants.userInfoResponse); - Map headerValues = new HashMap(); - headerValues.put("Authorization" , "bearer " + URLDecoder.decode(accessToken, "UTF-8")); - PowerMockito.doReturn(userInfoResponse).when(Util.class, "httpSendRequest" , - "GET", TestConstants.userProfileURL , null , headerValues); + final Map headerValues = new HashMap(); + headerValues.put(ServiceConstants.X_AMZ_ACCESS_TOKEN, accessToken); + final ResponseData tokenInfoResponse = new ResponseData(HttpURLConnection.HTTP_OK, TestConstants.tokenInfoResponse); + final String tokenInfoURL = TestConstants.tokenInfoURL; + PowerMockito.doReturn(tokenInfoResponse).when(Util.class, "httpSendRequest", ServiceConstants.GET, tokenInfoURL, null, headerValues, null); + final ResponseData userInfoResponse = new ResponseData(HttpURLConnection.HTTP_OK, TestConstants.userInfoResponse); + PowerMockito.doReturn(userInfoResponse).when(Util.class, "httpSendRequest", + ServiceConstants.GET, TestConstants.userProfileURL, null, headerValues); User user = client.getUserInfo(accessToken, clientId); Assert.assertEquals("testbuyer2@amazon.com", user.getEmail()); Assert.assertEquals("Test Buyer", user.getName()); Assert.assertEquals("amzn1.account.AF5W6J2OG52NKFJGEN52GEZ5CWFQ", user.getUserId()); - } - + @Test(expected=AmazonServiceException.class) - public void testInvalidAccessToken () throws Exception{ - ResponseData userProfileErrorResponse = new ResponseData(200 , TestConstants.userProfileErrorResponse); - String tokenInfoURL = TestConstants.tokenInfoURL + URLDecoder.decode(accessToken, "UTF-8"); - PowerMockito.doReturn(userProfileErrorResponse).when(Util.class, "httpSendRequest" , "GET", tokenInfoURL , null , new HashMap()); - User user = client.getUserInfo(accessToken, clientId); + public void testInvalidAccessToken() throws Exception { + final Map headerValues = new HashMap(); + headerValues.put(ServiceConstants.X_AMZ_ACCESS_TOKEN, accessToken); + final ResponseData userProfileErrorResponse = new ResponseData(HttpURLConnection.HTTP_OK, TestConstants.userProfileErrorResponse); + final String tokenInfoURL = TestConstants.tokenInfoURL; + PowerMockito.doReturn(userProfileErrorResponse).when(Util.class, "httpSendRequest", ServiceConstants.GET, tokenInfoURL, null, headerValues); + final User user = client.getUserInfo(accessToken, clientId); } } diff --git a/tst/com/amazon/pay/impl/PaymentsConfigTest.java b/tst/com/amazon/pay/impl/PaymentsConfigTest.java index 8ca4a81..192a464 100644 --- a/tst/com/amazon/pay/impl/PaymentsConfigTest.java +++ b/tst/com/amazon/pay/impl/PaymentsConfigTest.java @@ -92,7 +92,7 @@ public void testPaymentsPropertiesConfigOverride() throws Exception { private void assertConfigValues(PayConfig config, boolean usingOverride) { Assert.assertEquals(config.getAccessKey() , TestConstants.accessKey); - Assert.assertEquals(config.getSecretKey() , TestConstants.secretKey); + Assert.assertArrayEquals(config.getSecretKey() , TestConstants.secretKey); Assert.assertEquals(config.getRegion(), Region.US); Assert.assertEquals(config.getRegion().toString().toLowerCase(), "us"); Assert.assertEquals(Region.valueOf("US"), Region.US); diff --git a/tst/com/amazon/pay/impl/SignatureAndURLTest.java b/tst/com/amazon/pay/impl/SignatureAndURLTest.java index 5aa43c3..8773aca 100644 --- a/tst/com/amazon/pay/impl/SignatureAndURLTest.java +++ b/tst/com/amazon/pay/impl/SignatureAndURLTest.java @@ -1,7 +1,22 @@ +/** + * Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ package com.amazon.pay.impl; import com.amazon.pay.request.RequestHelper; import com.amazon.pay.TestConstants; +import com.amazon.pay.request.ConfirmOrderReferenceRequest; import com.amazon.pay.request.GetOrderReferenceDetailsRequest; import com.amazon.pay.request.SetOrderReferenceDetailsRequest; import com.amazon.pay.response.model.Environment; @@ -16,16 +31,14 @@ import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; - @RunWith(PowerMockRunner.class) @PowerMockIgnore({"javax.crypto.*" }) @PrepareForTest(Util.class) public class SignatureAndURLTest { - - PayConfig config; - String mcokTimeStamp = "2015-01-01"; - RequestHelper helper; - + + private PayConfig config; + private RequestHelper helper; + @Before public void setUp() throws Exception { config = new PayConfig().withAccessKey(TestConstants.accessKey) @@ -35,33 +48,146 @@ public void setUp() throws Exception { .withRegion(Region.US) .withSandboxMode(true); this.helper = new RequestHelper(config); - PowerMockito.stub(PowerMockito.method(Util.class , "getTimestamp")).toReturn(mcokTimeStamp); + PowerMockito.stub(PowerMockito.method(Util.class , "getTimestamp")).toReturn(TestConstants.timeStamp); } - @Test - public void testRequestUrlAndSignature() throws Exception{ + @Test + public void testRequestUrlAndSignature() throws Exception { this.helper = new RequestHelper(config); - PowerMockito.stub(PowerMockito.method(Util.class , "getTimestamp")).toReturn(mcokTimeStamp); - GetOrderReferenceDetailsRequest request = new GetOrderReferenceDetailsRequest(TestConstants.amazonOrderReferenceId); - String action = "GetOrderReferenceDetails"; - String signature = "f5nzn7c4GBTiiDQC9N2uSFSmOLgOsP3ReAKTmGlNpE4%3D"; - String expectedURL = "AWSAccessKeyId="+TestConstants.accessKey+"&Action="+action+"&AmazonOrderReferenceId="+TestConstants.amazonOrderReferenceId+"&SellerId="+TestConstants.merchantId+"&Signature="+signature+"&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp="+mcokTimeStamp+"&Version=2013-01-01"; + PowerMockito.stub(PowerMockito.method(Util.class, "getTimestamp")).toReturn(TestConstants.timeStamp); + final GetOrderReferenceDetailsRequest request = new GetOrderReferenceDetailsRequest(TestConstants.amazonOrderReferenceId); + final String action = "GetOrderReferenceDetails"; + final String signature = "cpkDC72d5lMIbo5ET2dvERTw4F2cGQJL3eQPzUe2pAE%3D"; + final String expectedURL = + "AWSAccessKeyId=" + TestConstants.accessKey + + "&Action=" + action + + "&AmazonOrderReferenceId=" + TestConstants.amazonOrderReferenceId + + "&SellerId=" + TestConstants.merchantId + + "&Signature=" + signature + + "&SignatureMethod=HmacSHA256" + + "&SignatureVersion=2" + + "&Timestamp=" + TestConstants.urlEncoded_TimeStamp + + "&Version=2013-01-01"; Assert.assertEquals(expectedURL, this.helper.getPostURL(request)); } + @Test + public void testRequestUrlAndSignatureWithMwsDelegation() throws Exception { + this.helper = new RequestHelper(config); + PowerMockito.stub(PowerMockito.method(Util.class, "getTimestamp")).toReturn(TestConstants.timeStamp); + final GetOrderReferenceDetailsRequest request = + new GetOrderReferenceDetailsRequest(TestConstants.amazonOrderReferenceId) + .setSellerId(TestConstants.overrideSellerId) + .setMWSAuthToken(TestConstants.mwsAuthToken); + final String action = "GetOrderReferenceDetails"; + final String signature = "MelQJXDdQJ85Z7aB85s7eYWm5TdGv6xYAQt%2FjoOhXCo%3D"; + final String expectedURL = + "AWSAccessKeyId=" + TestConstants.accessKey + + "&Action=" + action + + "&AmazonOrderReferenceId=" + TestConstants.amazonOrderReferenceId + + "&MWSAuthToken=" + TestConstants.mwsAuthToken + + "&SellerId=" + TestConstants.overrideSellerId + + "&Signature=" + signature + + "&SignatureMethod=HmacSHA256" + + "&SignatureVersion=2" + + "&Timestamp=" + TestConstants.urlEncoded_TimeStamp + + "&Version=2013-01-01"; + Assert.assertEquals(expectedURL, this.helper.getPostURL(request)); + } @Test - public void testRequestParameterConstructorSignature_2() throws Exception{ + public void testRequestParameterConstructorSignature_2() throws Exception { helper = new RequestHelper(config); - PowerMockito.stub(PowerMockito.method(Util.class , "getTimestamp")).toReturn(mcokTimeStamp); - String orderAmount = "2"; - SetOrderReferenceDetailsRequest request = new SetOrderReferenceDetailsRequest(TestConstants.amazonOrderReferenceId , orderAmount); - String action = "SetOrderReferenceDetails"; - String signature = "SAz7bebEm8G63ycFtygCiAI8L4jUoK5katCaU6wlXUI%3D"; - String expectedURL = "AWSAccessKeyId="+TestConstants.accessKey+"&Action="+action+"&AmazonOrderReferenceId="+TestConstants.amazonOrderReferenceId+"&OrderReferenceAttributes.OrderTotal.Amount="+orderAmount+"&OrderReferenceAttributes.OrderTotal.CurrencyCode=USD&SellerId="+TestConstants.merchantId+"&Signature="+signature+"&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp="+mcokTimeStamp+"&Version=2013-01-01"; - Assert.assertEquals(expectedURL, this.helper.getPostURL(request)); + PowerMockito.stub(PowerMockito.method(Util.class, "getTimestamp")).toReturn(TestConstants.timeStamp); + final String orderAmount = "2"; + final SetOrderReferenceDetailsRequest request = new SetOrderReferenceDetailsRequest(TestConstants.amazonOrderReferenceId, orderAmount); + final String action = "SetOrderReferenceDetails"; + final String signature = "i51MSGv9O2G2LHIlhCXLigA3ZKaZRoc7Mb5A1VX2QTA%3D"; + final String expectedURL = + "AWSAccessKeyId=" + TestConstants.accessKey + + "&Action=" + action + + "&AmazonOrderReferenceId=" + TestConstants.amazonOrderReferenceId + + "&OrderReferenceAttributes.OrderTotal.Amount=" + orderAmount + + "&OrderReferenceAttributes.OrderTotal.CurrencyCode=USD" + + "&SellerId=" + TestConstants.merchantId + + "&Signature=" + signature + + "&SignatureMethod=HmacSHA256" + + "&SignatureVersion=2" + + "&Timestamp=" + TestConstants.urlEncoded_TimeStamp + + "&Version=2013-01-01"; + Assert.assertEquals(expectedURL, this.helper.getPostURL(request)); } + @Test + public void testRequestUrlAndSignatureForConfirmOrderReference() throws Exception { + // Non-MFA Confirm request + this.helper = new RequestHelper(config); + PowerMockito.stub(PowerMockito.method(Util.class, "getTimestamp")).toReturn(TestConstants.timeStamp); + final ConfirmOrderReferenceRequest request = + new ConfirmOrderReferenceRequest(TestConstants.amazonOrderReferenceId) + .setSellerId(TestConstants.overrideSellerId) + .setMWSAuthToken(TestConstants.mwsAuthToken); + final String action = "ConfirmOrderReference"; + final String signature = "mbJBrZKC4Jz8J%2BrhRqyfYsY6TkSapWOvCTlC%2BUDUTok%3D"; + final String expectedURL = + "AWSAccessKeyId=" + TestConstants.accessKey + + "&Action=" + action + + "&AmazonOrderReferenceId=" + TestConstants.amazonOrderReferenceId + + "&MWSAuthToken=" + TestConstants.mwsAuthToken + + "&SellerId=" + TestConstants.overrideSellerId + + "&Signature=" + signature + + "&SignatureMethod=HmacSHA256" + + "&SignatureVersion=2" + + "&Timestamp=" + TestConstants.urlEncoded_TimeStamp + + "&Version=2013-01-01"; + Assert.assertEquals(expectedURL, this.helper.getPostURL(request)); + + // Adding a curency code without an amount should result in same request + request.setAuthorizationCurrencyCode(CurrencyCode.EUR); + Assert.assertEquals(expectedURL, this.helper.getPostURL(request)); + + // Full MFA parameter set + final String mfaSignature = "KeZbecFqPMxhR4g35iFWsdLmq1rAgwdn4B2WTIFMTHg%3D"; + request.setSuccessUrl(TestConstants.SUCCESS_URL); + request.setFailureUrl(TestConstants.FAILURE_URL); + request.setAuthorizationAmount(TestConstants.AUTHORIZE_AMOUNT); + final String expectedURLforMFA = + "AWSAccessKeyId=" + TestConstants.accessKey + + "&Action=" + action + + "&AmazonOrderReferenceId=" + TestConstants.amazonOrderReferenceId + + "&AuthorizationAmount.Amount=" + TestConstants.AUTHORIZE_AMOUNT + + "&AuthorizationAmount.CurrencyCode=" + CurrencyCode.EUR + + "&FailureUrl=" + Util.urlEncode(TestConstants.FAILURE_URL) + + "&MWSAuthToken=" + TestConstants.mwsAuthToken + + "&SellerId=" + TestConstants.overrideSellerId + + "&Signature=" + mfaSignature + + "&SignatureMethod=HmacSHA256" + + "&SignatureVersion=2" + + "&SuccessUrl=" + Util.urlEncode(TestConstants.SUCCESS_URL) + + "&Timestamp=" + TestConstants.urlEncoded_TimeStamp + + "&Version=2013-01-01"; + Assert.assertEquals(expectedURLforMFA, this.helper.getPostURL(request)); + // Partial MFA parameter set - not including FailureURL or CurrencyCode + // Should default to the Config object currency code in this scenario (USD instead of EUR) + final String partialMfaSignature = "vGiWtNsdtNKx3QGB%2BcNNq8tLisqwOeg2a5aIy3p6exw%3D"; + request.setAuthorizationCurrencyCode(null); + request.setFailureUrl(null); + final String expectedURLforPartialMFA = + "AWSAccessKeyId=" + TestConstants.accessKey + + "&Action=" + action + + "&AmazonOrderReferenceId=" + TestConstants.amazonOrderReferenceId + + "&AuthorizationAmount.Amount=" + TestConstants.AUTHORIZE_AMOUNT + + "&AuthorizationAmount.CurrencyCode=" + CurrencyCode.USD + + "&MWSAuthToken=" + TestConstants.mwsAuthToken + + "&SellerId=" + TestConstants.overrideSellerId + + "&Signature=" + partialMfaSignature + + "&SignatureMethod=HmacSHA256" + + "&SignatureVersion=2" + + "&SuccessUrl=" + Util.urlEncode(TestConstants.SUCCESS_URL) + + "&Timestamp=" + TestConstants.urlEncoded_TimeStamp + + "&Version=2013-01-01"; + Assert.assertEquals(expectedURLforPartialMFA, this.helper.getPostURL(request)); + } } diff --git a/tst/com/amazon/pay/impl/ipn/NotificationFactoryTest.java b/tst/com/amazon/pay/impl/ipn/NotificationFactoryTest.java index 2b07a90..350dde8 100644 --- a/tst/com/amazon/pay/impl/ipn/NotificationFactoryTest.java +++ b/tst/com/amazon/pay/impl/ipn/NotificationFactoryTest.java @@ -1,3 +1,17 @@ +/** + * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ package com.amazon.pay.impl.ipn; import com.amazon.pay.response.ipn.model.ProviderCreditNotification; diff --git a/tst/com/amazon/pay/impl/ipn/NotificationVerificationTest.java b/tst/com/amazon/pay/impl/ipn/NotificationVerificationTest.java index c3d77fa..663b269 100644 --- a/tst/com/amazon/pay/impl/ipn/NotificationVerificationTest.java +++ b/tst/com/amazon/pay/impl/ipn/NotificationVerificationTest.java @@ -1,3 +1,17 @@ +/** + * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ package com.amazon.pay.impl.ipn; import com.amazon.pay.exceptions.AmazonClientException; diff --git a/tst/com/amazon/pay/impl/ipn/SigningCertURLTest.java b/tst/com/amazon/pay/impl/ipn/SigningCertURLTest.java index bf461c5..c4d211d 100644 --- a/tst/com/amazon/pay/impl/ipn/SigningCertURLTest.java +++ b/tst/com/amazon/pay/impl/ipn/SigningCertURLTest.java @@ -1,3 +1,17 @@ +/** + * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ package com.amazon.pay.impl.ipn; import java.lang.reflect.InvocationTargetException; @@ -6,7 +20,7 @@ import org.junit.Test; public class SigningCertURLTest { - + private static final String VALID_CERT_URL = "https://sns.us-east-1.amazonaws.com/SimpleNotificationService-bb750dd426d95ee9390147a5624348ee.pem"; private static final String VALID_CERT_CN_URL = "https://sns.us-east-1.amazonaws.com.cn/SimpleNotificationService-bb750dd426d95ee9390147a5624348ee.pem"; private static final String INVALID_PROTOCOL_CERT_URL = "http://sns.us-east-1.amazonaws.com/SimpleNotificationService-bb750dd426d95ee9390147a5624348ee.pem"; @@ -14,8 +28,8 @@ public class SigningCertURLTest { private static final String INVALID_DOMAIN1_CERT_URL = "https://sns.us-east-1.fakecert.com/SimpleNotificationService-bb750dd426d95ee9390147a5624348ee.pem"; private static final String INVALID_DOMAIN2_CERT_URL = "https://sni.us-east-1.amazonaws.com/SimpleNotificationService-bb750dd426d95ee9390147a5624348ee.pem"; private static final String INVALID_DOMAIN3_CERT_URL = "https://sns.us.amazonaws.com/SimpleNotificationService-bb750dd426d95ee9390147a5624348ee.pem"; - private static final String INVALID_DOMAIN4_CERT_URL = "https://sns.us-east-1.amazonaws.com.com/SimpleNotificationService-bb750dd426d95ee9390147a5624348ee.pem"; - + private static final String INVALID_DOMAIN4_CERT_URL = "https://sns.us-east-1.amazonaws.com.com/SimpleNotificationService-bb750dd426d95ee9390147a5624348ee.pem"; + /** * SigningCertURL parameter with invalid protocol */ @@ -23,7 +37,7 @@ public class SigningCertURLTest { public void testIllegalProtocolSigningCertURL() throws Throwable { testSigningCertURL(INVALID_PROTOCOL_CERT_URL); } - + /** * SigningCertURL parameter with invalid file type */ @@ -31,7 +45,7 @@ public void testIllegalProtocolSigningCertURL() throws Throwable { public void testInvalidFileSigningCertURL() throws Throwable { testSigningCertURL(INVALID_FILE_CERT_URL); } - + /** * SigningCertURL parameter with invalid host name */ @@ -40,7 +54,7 @@ public void testInvalidDomain1SigningCertURL() throws Throwable { String testURL = INVALID_DOMAIN1_CERT_URL; testSigningCertURL(testURL); } - + /** * SigningCertURL parameter with invalid host name */ @@ -49,7 +63,7 @@ public void testInvalidDomain2SigningCertURL() throws Throwable { String testURL = INVALID_DOMAIN2_CERT_URL; testSigningCertURL(testURL); } - + /** * SigningCertURL parameter with invalid host name */ @@ -58,7 +72,7 @@ public void testInvalidDomain3SigningCertURL() throws Throwable { String testURL = INVALID_DOMAIN3_CERT_URL; testSigningCertURL(testURL); } - + /** * SigningCertURL parameter with invalid host name */ @@ -67,7 +81,7 @@ public void testInvalidDomain4SigningCertURL() throws Throwable { String testURL = INVALID_DOMAIN4_CERT_URL; testSigningCertURL(testURL); } - + /** * SigningCertURL parameter with valid URL */ @@ -76,7 +90,7 @@ public void testValidSigningCertURL() throws Throwable { String testURL = VALID_CERT_URL; testSigningCertURL(testURL); } - + /** * SigningCertURL parameter with valid CN URL */ @@ -85,21 +99,19 @@ public void testValid2SigningCertURL() throws Throwable { String testURL = VALID_CERT_CN_URL; testSigningCertURL(testURL); } - + private void testSigningCertURL(String testURL) throws Throwable { NotificationVerification nv = new NotificationVerification(); Method m = nv.getClass().getDeclaredMethod("isValidSigningCertURL", URL.class); m.setAccessible(true); - try { - m.invoke(nv , new URL(testURL) ); - } catch(InvocationTargetException e) { + try { + m.invoke(nv , new URL(testURL) ); + } catch (InvocationTargetException e) { Throwable targetException = e.getTargetException(); - if(targetException instanceof SecurityException ) { + if (targetException instanceof SecurityException) { throw targetException; } } } - - } diff --git a/tst/com/amazon/pay/request/PaymentsAPIRequestTest.java b/tst/com/amazon/pay/request/PaymentsAPIRequestTest.java index 8425a09..ebfdf12 100644 --- a/tst/com/amazon/pay/request/PaymentsAPIRequestTest.java +++ b/tst/com/amazon/pay/request/PaymentsAPIRequestTest.java @@ -1,8 +1,23 @@ +/** + * Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ package com.amazon.pay.request; import com.amazon.pay.response.model.Price; import com.amazon.pay.response.model.ProviderCredit; import com.amazon.pay.types.AmazonReferenceIdType; +import com.amazon.pay.types.BillingAgreementType; import com.amazon.pay.types.CurrencyCode; import com.amazon.pay.types.OrderReferenceStatus; import com.amazon.pay.types.SortOrder; @@ -23,11 +38,12 @@ public class PaymentsAPIRequestTest { private final List PCL = Collections.singletonList( - new ProviderCredit("providerId", new Price("1", "USD"))); + new ProviderCredit("providerId", new Price("1", "USD"))); + private final Price subscriptionAmount = new Price("1.25", "EUR"); @Test public void testAuthorizeRequest() { - AuthorizeRequest request = new AuthorizeRequest(TestConstants.amazonOrderReferenceId, TestConstants.authorizationReferenceId, "2") + final AuthorizeRequest request = new AuthorizeRequest(TestConstants.amazonOrderReferenceId, TestConstants.authorizationReferenceId, "2") .setMWSAuthToken(TestConstants.mwsAuthToken) .setCaptureNow(true) .setSoftDescriptor(TestConstants.softDescriptor) @@ -49,10 +65,10 @@ public void testAuthorizeRequest() { @Test public void testCancelOrderReferenceRequest() { - CancelOrderReferenceRequest request = + final CancelOrderReferenceRequest request = new CancelOrderReferenceRequest(TestConstants.amazonOrderReferenceId) - .setMWSAuthToken(TestConstants.mwsAuthToken) - .setCancelReason(TestConstants.sampletext); + .setMWSAuthToken(TestConstants.mwsAuthToken) + .setCancelReason(TestConstants.sampletext); Assert.assertEquals(request.getAmazonOrderReferenceId(),TestConstants.amazonOrderReferenceId); Assert.assertEquals(request.getCancelationReason(), TestConstants.sampletext); Assert.assertEquals(request.getMwsAuthToken(), TestConstants.mwsAuthToken); @@ -60,7 +76,7 @@ public void testCancelOrderReferenceRequest() { @Test public void testCapture() { - CaptureRequest request = new CaptureRequest(TestConstants.amazonOrderReferenceId, "Capt123", "2") + final CaptureRequest request = new CaptureRequest(TestConstants.amazonOrderReferenceId, "Capt123", "2") .setMWSAuthToken(TestConstants.mwsAuthToken) .setSellerCaptureNote(TestConstants.sampletext) .setSoftDescriptor(TestConstants.softDescriptor) @@ -79,10 +95,10 @@ public void testCapture() { @Test public void testCloseAuthorizationRequest() { - CloseAuthorizationRequest request = + final CloseAuthorizationRequest request = new CloseAuthorizationRequest("Auth123") - .setMWSAuthToken(TestConstants.mwsAuthToken) - .setClosureReason(TestConstants.sampletext); + .setMWSAuthToken(TestConstants.mwsAuthToken) + .setClosureReason(TestConstants.sampletext); Assert.assertEquals(request.getAmazonAuthorizationId(), "Auth123"); Assert.assertEquals(request.getClosureReason(), TestConstants.sampletext); @@ -91,10 +107,10 @@ public void testCloseAuthorizationRequest() { @Test public void testCloseOrderReferenceRequest() { - CloseOrderReferenceRequest request = + final CloseOrderReferenceRequest request = new CloseOrderReferenceRequest(TestConstants.amazonOrderReferenceId) - .setMWSAuthToken(TestConstants.mwsAuthToken) - .setClosureReason(TestConstants.sampletext); + .setMWSAuthToken(TestConstants.mwsAuthToken) + .setClosureReason(TestConstants.sampletext); Assert.assertEquals(request.getAmazonOrderReferenceId(),TestConstants.amazonOrderReferenceId); Assert.assertEquals(request.getClosureReason(), TestConstants.sampletext); @@ -103,16 +119,26 @@ public void testCloseOrderReferenceRequest() { @Test public void testConfirmOrderReferenceRequest() { - ConfirmOrderReferenceRequest request = new ConfirmOrderReferenceRequest(TestConstants.amazonOrderReferenceId) - .setMWSAuthToken(TestConstants.mwsAuthToken); + final ConfirmOrderReferenceRequest request = new ConfirmOrderReferenceRequest(TestConstants.amazonOrderReferenceId) + .setMWSAuthToken(TestConstants.mwsAuthToken) + .setAuthorizationAmount(TestConstants.AUTHORIZE_AMOUNT) + .setAuthorizationCurrencyCode(CurrencyCode.EUR) + .setSuccessUrl(TestConstants.SUCCESS_URL) + .setFailureUrl(TestConstants.FAILURE_URL) + .setExpectImmediateAuthorization(true); Assert.assertEquals(request.getAmazonOrderReferenceId(),TestConstants.amazonOrderReferenceId); Assert.assertEquals(request.getMwsAuthToken(), TestConstants.mwsAuthToken); + Assert.assertEquals(request.getAuthorizationAmount(), TestConstants.AUTHORIZE_AMOUNT); + Assert.assertEquals(request.getAuthorizationCurrencyCode(), CurrencyCode.EUR); + Assert.assertEquals(request.getSuccessUrl(), TestConstants.SUCCESS_URL); + Assert.assertEquals(request.getFailureUrl(), TestConstants.FAILURE_URL); + Assert.assertEquals(request.isExpectImmediateAuthorization(), true); } @Test public void testGetAuthorizationDetailsRequest() { - GetAuthorizationDetailsRequest request = new GetAuthorizationDetailsRequest("Auth123") + final GetAuthorizationDetailsRequest request = new GetAuthorizationDetailsRequest("Auth123") .setMWSAuthToken(TestConstants.mwsAuthToken); Assert.assertEquals(request.getAmazonAuthorizationId(), "Auth123"); Assert.assertEquals(request.getMwsAuthToken(), TestConstants.mwsAuthToken); @@ -120,7 +146,7 @@ public void testGetAuthorizationDetailsRequest() { @Test public void testGetCaptureDetailsRequest() { - GetCaptureDetailsRequest request = new GetCaptureDetailsRequest("Capt123") + final GetCaptureDetailsRequest request = new GetCaptureDetailsRequest("Capt123") .setMWSAuthToken(TestConstants.mwsAuthToken); Assert.assertEquals(request.getAmazonCaptureId(), "Capt123"); @@ -129,11 +155,11 @@ public void testGetCaptureDetailsRequest() { @Test public void testGetOrderReferenceDetailsRequest() { - GetOrderReferenceDetailsRequest request = + final GetOrderReferenceDetailsRequest request = new GetOrderReferenceDetailsRequest(TestConstants.amazonOrderReferenceId) - .setAddressConsentToken("Atza|IwEBIDcwh13A-nf8EuZahCu") - .setAccessToken("Atza|oVsmstLsCYekhCdyR1Hu6FFveZC") - .setMWSAuthToken(TestConstants.mwsAuthToken); + .setAddressConsentToken("Atza|IwEBIDcwh13A-nf8EuZahCu") + .setAccessToken("Atza|oVsmstLsCYekhCdyR1Hu6FFveZC") + .setMWSAuthToken(TestConstants.mwsAuthToken); Assert.assertEquals(request.getAmazonOrderReferenceId(), TestConstants.amazonOrderReferenceId); Assert.assertEquals(request.getAddressConsentToken(), "Atza|IwEBIDcwh13A-nf8EuZahCu"); @@ -143,7 +169,7 @@ public void testGetOrderReferenceDetailsRequest() { @Test public void testGetRefundDetailsRequest() { - GetRefundDetailsRequest request = new GetRefundDetailsRequest("Ref123") + final GetRefundDetailsRequest request = new GetRefundDetailsRequest("Ref123") .setMWSAuthToken(TestConstants.mwsAuthToken); Assert.assertEquals(request.getAmazonRefundId(), "Ref123"); @@ -152,7 +178,7 @@ public void testGetRefundDetailsRequest() { @Test public void testRefundRequest() { - RefundRequest request = new RefundRequest("C1233421424","Ref123", "2") + final RefundRequest request = new RefundRequest("C1233421424","Ref123", "2") .setMWSAuthToken(TestConstants.mwsAuthToken) .setSellerRefundNote(TestConstants.sampletext) .setSoftDescriptor(TestConstants.softDescriptor) @@ -176,11 +202,12 @@ public void testRefundRequest() { @Test public void testSetOrderReferenceDetailsRequest() { - SetOrderReferenceDetailsRequest request = new SetOrderReferenceDetailsRequest(TestConstants.amazonOrderReferenceId, "2") + final SetOrderReferenceDetailsRequest request = new SetOrderReferenceDetailsRequest(TestConstants.amazonOrderReferenceId, "2") .setMWSAuthToken(TestConstants.mwsAuthToken) .setPlatformId("platformId") .setSellerOrderId("sellerOrderId") .setStoreName("testStore") + .setSupplementaryData(TestConstants.SUPPLEMENTARY_DATA) .setCustomInformation("customInfo") .setSellerNote("sampleText") .setOrderCurrencyCode(CurrencyCode.USD) @@ -190,8 +217,9 @@ public void testSetOrderReferenceDetailsRequest() { Assert.assertEquals(request.getOrderAmount(), "2"); Assert.assertEquals(request.getOrderCurrencyCode(), CurrencyCode.USD); Assert.assertEquals(request.getMwsAuthToken(), TestConstants.mwsAuthToken); - Assert.assertEquals(request.getSellerOrderId(),"sellerOrderId"); + Assert.assertEquals(request.getSellerOrderId(), "sellerOrderId"); Assert.assertEquals(request.getStoreName(), "testStore"); + Assert.assertEquals(request.getSupplementaryData(), TestConstants.SUPPLEMENTARY_DATA); Assert.assertEquals(request.getPlatformId(), "platformId"); Assert.assertEquals(request.getCustomInformation(), "customInfo"); Assert.assertEquals(request.getSellerNote(), "sampleText"); @@ -209,6 +237,7 @@ private AuthorizeOnBillingAgreementRequest testAuthorizeOnBillingAgreementSetup( .setSellerNote("sampletex") .setSellerOrderId("Order123") .setStoreName("Store") + .setSupplementaryData(TestConstants.SUPPLEMENTARY_DATA) .setTransactionTimeout("10") .setAuthorizationCurrencyCode(CurrencyCode.USD) .setSoftDescriptor("AMZN*Test"); @@ -229,6 +258,7 @@ private void testAuthorizeOnBillingAgreementAssert(final AuthorizeOnBillingAgree Assert.assertEquals("sampletex", request.getSellerNote()); Assert.assertEquals("Order123", request.getSellerOrderId()); Assert.assertEquals("Store", request.getStoreName()); + Assert.assertEquals(TestConstants.SUPPLEMENTARY_DATA, request.getSupplementaryData()); Assert.assertEquals("AMZN*Test", request.getSoftDescriptor()); } @@ -265,6 +295,20 @@ public void testConfirmBillingAgreement() { Assert.assertEquals(request.getMwsAuthToken(), TestConstants.mwsAuthToken); } + @Test + public void testConfirmBillingAgreementWithSCA() { + ConfirmBillingAgreementRequest request = new ConfirmBillingAgreementRequest(TestConstants.billingAgreementId) + .setMWSAuthToken(TestConstants.mwsAuthToken) + .setSuccessUrl(TestConstants.SUCCESS_URL) + .setFailureUrl(TestConstants.FAILURE_URL); + + + Assert.assertEquals(request.getAmazonBillingAgreementId(), TestConstants.billingAgreementId); + Assert.assertEquals(request.getMwsAuthToken(), TestConstants.mwsAuthToken); + Assert.assertEquals(request.getSuccessUrl(), TestConstants.SUCCESS_URL); + Assert.assertEquals(request.getFailureUrl(), TestConstants.FAILURE_URL); + } + @Test public void testGetBillingAgreementDetails() { GetBillingAgreementDetailsRequest request = new GetBillingAgreementDetailsRequest(TestConstants.billingAgreementId) @@ -277,7 +321,7 @@ public void testGetBillingAgreementDetails() { @Test public void testSetBillingAgreementDetails() { - SetBillingAgreementDetailsRequest request = new SetBillingAgreementDetailsRequest(TestConstants.billingAgreementId) + final SetBillingAgreementDetailsRequest request = new SetBillingAgreementDetailsRequest(TestConstants.billingAgreementId) .setMWSAuthToken(TestConstants.mwsAuthToken) .setCustomInformation("custom") .setPlatformId("platformId") @@ -294,11 +338,35 @@ public void testSetBillingAgreementDetails() { Assert.assertEquals(request.getStoreName(), "store"); } + @Test + public void testSetBillingAgreementDetailsWithSCA() { + final SetBillingAgreementDetailsRequest request = new SetBillingAgreementDetailsRequest(TestConstants.billingAgreementId) + .setMWSAuthToken(TestConstants.mwsAuthToken) + .setCustomInformation("custom") + .setPlatformId("platformId") + .setSellerBillingAgreementId("B12") + .setSellerNote("note12") + .setStoreName("store") + .setBillingAgreementType(BillingAgreementType.CustomerInitiatedTransaction) + .setSubscriptionAmount(subscriptionAmount); + + Assert.assertEquals(request.getAmazonBillingAgreementId(), TestConstants.billingAgreementId); + Assert.assertEquals(request.getMwsAuthToken(), TestConstants.mwsAuthToken); + Assert.assertEquals(request.getCustomInformation(), "custom"); + Assert.assertEquals(request.getPlatformId(), "platformId"); + Assert.assertEquals(request.getSellerBillingAgreementId(), "B12"); + Assert.assertEquals(request.getSellerNote(), "note12"); + Assert.assertEquals(request.getStoreName(), "store"); + Assert.assertEquals(request.getBillingAgreementType(), BillingAgreementType.CustomerInitiatedTransaction); + Assert.assertEquals(request.getSubscriptionAmount().getAmount(), "1.25"); + Assert.assertEquals(request.getSubscriptionAmount().getCurrencyCode(), "EUR"); + } + @Test public void testValidateBillingAgreement() { - ValidateBillingAgreementRequest request = + final ValidateBillingAgreementRequest request = new ValidateBillingAgreementRequest(TestConstants.billingAgreementId) - .setMWSAuthToken(TestConstants.mwsAuthToken); + .setMWSAuthToken(TestConstants.mwsAuthToken); Assert.assertEquals(request.getAmazonBillingAgreementId(), TestConstants.billingAgreementId); Assert.assertEquals(request.getMwsAuthToken(), TestConstants.mwsAuthToken); @@ -306,9 +374,9 @@ public void testValidateBillingAgreement() { @Test public void testGetProviderCreditDetails() { - GetProviderCreditDetailsRequest request = + final GetProviderCreditDetailsRequest request = new GetProviderCreditDetailsRequest(TestConstants.providerCreditId, TestConstants.providerSellerId) - .setMwsAuthToken(TestConstants.mwsAuthToken); + .setMWSAuthToken(TestConstants.mwsAuthToken); Assert.assertEquals(request.getAmazonProviderCreditId(), TestConstants.providerCreditId); Assert.assertEquals(request.getSellerId(), TestConstants.providerSellerId); @@ -317,10 +385,10 @@ public void testGetProviderCreditDetails() { @Test public void testGetProviderCreditReversalDetails() { - GetProviderCreditReversalDetailsRequest request = - new GetProviderCreditReversalDetailsRequest( - TestConstants.reversalProviderCreditId, TestConstants.providerSellerId) - .setMwsAuthToken(TestConstants.mwsAuthToken); + final GetProviderCreditReversalDetailsRequest request = + new GetProviderCreditReversalDetailsRequest( + TestConstants.reversalProviderCreditId, TestConstants.providerSellerId) + .setMWSAuthToken(TestConstants.mwsAuthToken); Assert.assertEquals(TestConstants.reversalProviderCreditId, request.getAmazonProviderCreditReversalId()); Assert.assertEquals(TestConstants.providerSellerId, request.getSellerId()); @@ -329,11 +397,11 @@ public void testGetProviderCreditReversalDetails() { @Test public void testReverseProviderCreditDetails() { - ReverseProviderCreditRequest request = new ReverseProviderCreditRequest(TestConstants.reversalProviderCreditId, + final ReverseProviderCreditRequest request = new ReverseProviderCreditRequest(TestConstants.reversalProviderCreditId, TestConstants.reversalProviderCreditReferenceId, TestConstants.providerSellerId, TestConstants.reversalProviderAmount) - .setMwsAuthToken(TestConstants.mwsAuthToken) + .setMWSAuthToken(TestConstants.mwsAuthToken) .setCreditReversalNote(TestConstants.sampletext) .setCreditReversalCurrencyCode(CurrencyCode.USD); @@ -344,7 +412,7 @@ public void testReverseProviderCreditDetails() { Assert.assertEquals(request.getMwsAuthToken(), TestConstants.mwsAuthToken); Assert.assertEquals(request.getCreditReversalAmountCurrencyCode(), CurrencyCode.USD); Assert.assertEquals(request.getCreditReversalNote(), TestConstants.sampletext); - } + } private ChargeRequest testChargeSetup() { return new ChargeRequest() @@ -397,16 +465,17 @@ public void testChargeString() { public void testCreateOrderReferenceForId() { final CreateOrderReferenceForIdRequest request = new CreateOrderReferenceForIdRequest( - TestConstants.billingAgreementId, AmazonReferenceIdType.BILLING_AGREEMENT_ID) - .setInheritShippingAddress(false) - .setConfirmNow(true) - .setOrderTotalCurrencyCode(CurrencyCode.USD) - .setSellerNote("Test Seller Note") - .setSellerOrderId("Test Order ID") - .setStoreName(TestConstants.storeName) - .setCustomInformation("Test Custom Information") - .setOrderTotalAmount("567.89") - .setPlatformId(TestConstants.platformId); + TestConstants.billingAgreementId, AmazonReferenceIdType.BILLING_AGREEMENT_ID) + .setInheritShippingAddress(false) + .setConfirmNow(true) + .setOrderTotalCurrencyCode(CurrencyCode.USD) + .setSellerNote("Test Seller Note") + .setSellerOrderId("Test Order ID") + .setStoreName(TestConstants.storeName) + .setSupplementaryData(TestConstants.SUPPLEMENTARY_DATA) + .setCustomInformation("Test Custom Information") + .setOrderTotalAmount("567.89") + .setPlatformId(TestConstants.platformId); Assert.assertEquals(request.getId(), TestConstants.billingAgreementId); Assert.assertEquals(request.getIdType(), AmazonReferenceIdType.BILLING_AGREEMENT_ID); @@ -416,6 +485,7 @@ public void testCreateOrderReferenceForId() { Assert.assertEquals(request.getSellerNote(), "Test Seller Note"); Assert.assertEquals(request.getSellerOrderId(), "Test Order ID"); Assert.assertEquals(request.getStoreName(), TestConstants.storeName); + Assert.assertEquals(request.getSupplementaryData(), TestConstants.SUPPLEMENTARY_DATA); Assert.assertEquals(request.getCustomInformation(), "Test Custom Information"); Assert.assertEquals(request.getOrderTotalAmount(), "567.89"); Assert.assertEquals(request.getPlatformId(), TestConstants.platformId); @@ -455,7 +525,7 @@ public void testListOrderReferenceByNextToken() { @Test public void testSetOrderAttributes() { - Set orderItemCategories = new HashSet(); + final Set orderItemCategories = new HashSet(); orderItemCategories.add("Antiques"); orderItemCategories.add("Apparel"); final SetOrderAttributesRequest request = @@ -466,6 +536,7 @@ public void testSetOrderAttributes() { .setPlatformId("platformId") .setSellerOrderId("sellerOrderId") .setStoreName("storeName") + .setSupplementaryData(TestConstants.SUPPLEMENTARY_DATA) .setRequestPaymentAuthorization(true) .setPaymentServiceProviderId("paymentServiceProviderId") .setPaymentServiceProviderOrderId("paymentServiceProviderOrderId") @@ -476,8 +547,9 @@ public void testSetOrderAttributes() { Assert.assertEquals(request.getCustomInformation(), "customInfo"); Assert.assertEquals(request.getSellerNote(), "sellerNote"); Assert.assertEquals(request.getPlatformId(), "platformId"); - Assert.assertEquals(request.getSellerOrderId(),"sellerOrderId"); - Assert.assertEquals(request.getStoreName(),"storeName"); + Assert.assertEquals(request.getSellerOrderId(), "sellerOrderId"); + Assert.assertEquals(request.getStoreName(), "storeName"); + Assert.assertEquals(request.getSupplementaryData(), TestConstants.SUPPLEMENTARY_DATA); Assert.assertEquals(request.getRequestPaymentAuthorization(),true); Assert.assertEquals(request.getPaymentServiceProviderId(),"paymentServiceProviderId"); Assert.assertEquals(request.getPaymentServiceProviderOrderId(),"paymentServiceProviderOrderId"); @@ -485,4 +557,13 @@ public void testSetOrderAttributes() { Assert.assertTrue(request.getOrderItemCategories().contains("Apparel")); } + @Test + public void testGetMerchantAccountStatus() { + final GetMerchantAccountStatusRequest request = new GetMerchantAccountStatusRequest() + .setMWSAuthToken(TestConstants.mwsAuthToken) + .setSellerId(TestConstants.providerSellerId); + Assert.assertEquals(request.getSellerId(), TestConstants.providerSellerId); + Assert.assertEquals(request.getMwsAuthToken(), TestConstants.mwsAuthToken); + } + } diff --git a/tst/com/amazon/pay/response/PaymentsAPIResponseTest.java b/tst/com/amazon/pay/response/PaymentsAPIResponseTest.java index 6c7a05e..7419606 100644 --- a/tst/com/amazon/pay/response/PaymentsAPIResponseTest.java +++ b/tst/com/amazon/pay/response/PaymentsAPIResponseTest.java @@ -1,6 +1,25 @@ +/** + * Copyright 2018-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ package com.amazon.pay.response; +import com.amazon.pay.TestConstants; +import com.amazon.pay.exceptions.AmazonServiceException; +import com.amazon.pay.impl.PayLogUtil; +import com.amazon.pay.response.model.AccountStatus; import com.amazon.pay.response.model.AuthorizationDetails; +import com.amazon.pay.response.model.BillingAgreementDetails; import com.amazon.pay.response.model.CaptureDetails; import com.amazon.pay.response.model.Environment; import com.amazon.pay.response.model.ErrorResponse; @@ -26,6 +45,7 @@ import com.amazon.pay.response.parser.GetBillingAgreementDetailsResponseData; import com.amazon.pay.response.parser.GetCaptureDetailsResponseData; import com.amazon.pay.response.parser.GetOrderReferenceDetailsResponseData; +import com.amazon.pay.response.parser.GetMerchantAccountStatusResponseData; import com.amazon.pay.response.parser.GetPaymentDetails; import com.amazon.pay.response.parser.GetProviderCreditDetailsResponseData; import com.amazon.pay.response.parser.GetProviderCreditReversalDetailsResponseData; @@ -43,6 +63,7 @@ import com.amazon.pay.exceptions.AmazonClientException; import com.amazon.pay.exceptions.AmazonServiceException; import com.amazon.pay.response.parser.ResponseData; +import com.amazon.pay.types.BillingAgreementType; import java.io.FileInputStream; import java.io.IOException; @@ -96,15 +117,16 @@ public void testGetOrderReferenceDetailsResponse() throws Exception { Assert.assertEquals(res.getRequestId(), "5f20169b-7ab2-11df-bcef-d35615e2b044"); Assert.assertEquals(res.getDetails().getReleaseEnvironment().value(), "LIVE"); Assert.assertEquals(res.getDetails().getDestination().getPhysicalDestination().getCountryCode(), "US"); - Assert.assertEquals(res.getDetails().getDestination().getPhysicalDestination().getCity(), "New York"); + Assert.assertEquals(res.getDetails().getDestination().getPhysicalDestination().getCity(), "äöüßâêîôûàèùé"); Assert.assertEquals(res.getDetails().getDestination().getPhysicalDestination().getPostalCode(), "10101-9876"); - Assert.assertEquals(res.getDetails().getDestination().getPhysicalDestination().getStateOrRegion(), "NY"); + Assert.assertEquals(res.getDetails().getDestination().getPhysicalDestination().getStateOrRegion(), "宋 俊华 市区-徐汇区 广东省"); Assert.assertNotNull(res.getDetails().getPaymentDescriptor()); Assert.assertEquals(res.getDetails().getPaymentDescriptor().getName() , "Visa"); Assert.assertEquals(res.getDetails().getPaymentDescriptor().getAccountNumberTail() , "11"); Assert.assertEquals(res.getDetails().getPaymentDescriptor().getFullDescriptor() , "Amazon Pay (Visa **11)"); Assert.assertEquals(res.getDetails().getPaymentDescriptor().isUseAmazonBalanceFirst() , false); Assert.assertNotEquals(res.getDetails().getPaymentDescriptor().isUseAmazonBalanceFirst(), true); + Assert.assertEquals(res.getDetails().getSellerOrderAttributes().getSupplementaryData(), TestConstants.SUPPLEMENTARY_DATA); Assert.assertEquals(res.toXML(), rawResponse); } @@ -131,19 +153,32 @@ public void testNoPaymentDescriptor() throws Exception { } @Test - public void testSanitizedData() throws Exception { - final String rawResponse = loadTestFile("SanitizedData.xml"); + public void testGetOrderReferenceDetailsScaResponse() throws Exception { + final String rawResponse = loadTestFile("GetOrderReferenceDetailsScaResponse.xml"); final ResponseData response = new ResponseData(HttpURLConnection.HTTP_OK, rawResponse); - final SetOrderReferenceDetailsResponseData res = Parser.setOrderReferenceDetails(response); + final GetOrderReferenceDetailsResponseData res = Parser.getOrderReferenceDetails(response); + Assert.assertEquals(res.getDetails().getPaymentReference().getStaticToken(), "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx20="); + Assert.assertEquals(res.getDetails().getPaymentAuthenticationStatus().getState(), "REQUIRED"); + Assert.assertEquals(res.toXML(), rawResponse); + } - Assert.assertEquals(res.getDetails().getAmazonOrderReferenceId(), "S01-9821095-0000200"); - Assert.assertEquals(res.getDetails().getOrderReferenceStatus().getState(), "Draft"); - Assert.assertEquals(res.getDetails().getDestination().getDestinationType(), "Physical"); - Assert.assertEquals(res.getDetails().getDestination().getPhysicalDestination().getCountryCode(), null); - Assert.assertEquals(res.getDetails().getDestination().getPhysicalDestination().getStateOrRegion(), null); - Assert.assertEquals(res.getDetails().getDestination().getPhysicalDestination().getCity(), null); - Assert.assertEquals(res.getDetails().getDestination().getPhysicalDestination().getPostalCode(), null); - Assert.assertEquals(res.getDetails().getSellerNote(), "*** Removed ***"); + @Test + public void testSetOrderAttributesScaResponse() throws Exception { + final String rawResponse = loadTestFile("SetOrderAttributesScaResponse.xml"); + final ResponseData response = new ResponseData(HttpURLConnection.HTTP_OK, rawResponse); + final SetOrderAttributesResponseData res = Parser.setOrderAttributes(response); + Assert.assertEquals(res.getOrderReferenceDetails().getPaymentAuthenticationStatus().getState(), "REQUIRED"); + Assert.assertEquals(res.toXML(), rawResponse); + } + + @Test + public void testSanitizedData() throws Exception { + final String rawResponse = loadTestFile("SanitizedDataBefore.xml").trim(); + final String expectedSanitizedResponse = loadTestFile("SanitizedData.xml").trim(); + + final PayLogUtil logUtil = new PayLogUtil(); + final String sanitizedString = logUtil.sanitizeString(rawResponse); + Assert.assertEquals(expectedSanitizedResponse, sanitizedString); } @Test @@ -199,6 +234,7 @@ public void testSetOrderReferenceDetailsResponse() throws Exception { Assert.assertEquals(res.getDetails().getOrderTotal().getCurrencyCode(), "USD"); Assert.assertEquals(res.getDetails().getSellerOrderAttributes().getSellerOrderId(), "test1234"); Assert.assertEquals(res.getDetails().getSellerOrderAttributes().getStoreName(), "myTestStore"); + Assert.assertEquals(res.getDetails().getSellerOrderAttributes().getSupplementaryData(), TestConstants.SUPPLEMENTARY_DATA); Assert.assertEquals(res.getDetails().getSellerOrderAttributes().getCustomInformation(), "myCustomInformation"); Assert.assertEquals(res.getDetails().getRequestPaymentAuthorization(), false); @@ -367,7 +403,7 @@ public void testCaptureDetailsResponseMulticurrency() throws Exception { Assert.assertEquals(res.toXML(), rawResponse); } - @Test + @Test public void testCancelOrderReferenceResponse() throws Exception { final String rawResponse = loadTestFile("CancelOrderReferenceResponse.xml"); final ResponseData response = new ResponseData(HttpURLConnection.HTTP_OK, rawResponse); @@ -376,7 +412,7 @@ public void testCancelOrderReferenceResponse() throws Exception { Assert.assertEquals(res.toXML(), rawResponse); } - @Test + @Test public void testCloseOrderReferenceResponse() throws Exception { final String rawResponse = loadTestFile("CloseOrderReferenceResponse.xml"); final ResponseData response = new ResponseData(HttpURLConnection.HTTP_OK, rawResponse); @@ -385,7 +421,7 @@ public void testCloseOrderReferenceResponse() throws Exception { Assert.assertEquals(res.toXML(), rawResponse); } - @Test + @Test public void testCloseAuthorizationResponse() throws Exception { final String rawResponse = loadTestFile("CloseAuthorizationResponse.xml"); final ResponseData response = new ResponseData(HttpURLConnection.HTTP_OK, rawResponse); @@ -518,11 +554,53 @@ public void testGetBillingAgreementDetailsResponse() throws Exception { Assert.assertEquals(res.getDetails().getBillingAddress(), null); Assert.assertEquals(res.getDetails().getPlatformId(), null); Assert.assertEquals(res.getDetails().getSellerNote(), null); - Assert.assertEquals(res.getRequestId(), "d69e8d60-3682-43d7-bf5e-e2ef64dc685e"); Assert.assertEquals(res.toXML(), rawResponse); } + @Test + public void testGetBillingAgreementDetailsWithSCAResponse() throws Exception { + final String rawResponse = loadTestFile("GetBillingAgreementDetailsWithSCAResponse.xml"); + final ResponseData response = new ResponseData(HttpURLConnection.HTTP_OK, rawResponse); + final GetBillingAgreementDetailsResponseData res = Parser.getBillingAgreementDetailsData(response); + Assert.assertEquals(res.getDetails().getAmazonBillingAgreementId(), "C02-5533845-8537141"); + Assert.assertEquals(res.getDetails().getBillingAgreementStatus().getLastUpdatedTimestamp(), null); + Assert.assertEquals(res.getDetails().getBillingAgreementStatus().getState(), "Draft"); + Assert.assertEquals(res.getDetails().getDestination().getDestinationType(), "Physical"); + Assert.assertEquals(res.getDetails().getDestination().getPhysicalDestination().getCity(), "Chicago"); + Assert.assertEquals(res.getDetails().getDestination().getPhysicalDestination().getCountryCode(), "US"); + Assert.assertEquals(res.getDetails().getDestination().getPhysicalDestination().getPostalCode(), "60602"); + Assert.assertEquals(res.getDetails().getDestination().getPhysicalDestination().getCounty(), null); + Assert.assertEquals(res.getDetails().getDestination().getPhysicalDestination().getDistrict(), null); + Assert.assertEquals(res.getDetails().getConstraints().getConstraint().get(0).getConstraintID(), "BuyerConsentNotSet"); + Assert.assertEquals(res.getDetails().getConstraints().getConstraint().get(0).getDescription(), "The buyer has not given consent for this billing agreement."); + Assert.assertEquals(res.getDetails().getBillingAgreementType(), BillingAgreementType.MerchantInitiatedTransaction); + Assert.assertEquals(res.getDetails().getReleaseEnvironment().SANDBOX, Environment.SANDBOX); + final XMLGregorianCalendar xgc3 = DatatypeFactory.newInstance().newXMLGregorianCalendar("2019-08-20T22:03:09.297Z"); + Assert.assertEquals(res.getDetails().getCreationTimestamp(), xgc3); + Assert.assertEquals(res.getDetails().getBillingAgreementLimits().getAmountLimitPerTimePeriod().getAmount(), "500"); + Assert.assertEquals(res.getDetails().getBillingAgreementLimits().getAmountLimitPerTimePeriod().getCurrencyCode(), "GBP"); + Assert.assertEquals(res.getDetails().getBillingAgreementLimits().getCurrentRemainingBalance().getAmount(), "500.00"); + Assert.assertEquals(res.getDetails().getBillingAgreementLimits().getCurrentRemainingBalance().getCurrencyCode(), "GBP"); + final XMLGregorianCalendar xgc2 = DatatypeFactory.newInstance().newXMLGregorianCalendar("2019-09-01T00:00:00Z"); + Assert.assertEquals(res.getDetails().getBillingAgreementLimits().getTimePeriodEndDate(), xgc2); + final XMLGregorianCalendar xgc4 = DatatypeFactory.newInstance().newXMLGregorianCalendar("2019-08-01T00:00:00Z"); + Assert.assertEquals(res.getDetails().getBillingAgreementLimits().getTimePeriodStartDate(), xgc4); + Assert.assertEquals(res.getDetails().getOrderLanguage(), "en-GB"); + Assert.assertEquals(res.getDetails().isBillingAgreementConsent(), false); + Assert.assertEquals(res.getDetails().getExpirationTimestamp(), null); + Assert.assertEquals(res.getDetails().getSellerBillingAgreementAttributes().getCustomInformation(), "any custom information"); + Assert.assertEquals(res.getDetails().getSellerBillingAgreementAttributes().getSellerBillingAgreementId(), "5678-example-order"); + Assert.assertEquals(res.getDetails().getSellerBillingAgreementAttributes().getStoreName(), "SDK Sample Store Name"); + Assert.assertEquals(res.getDetails().getBillingAddress(), null); + Assert.assertEquals(res.getDetails().getPlatformId(), null); + Assert.assertEquals(res.getDetails().getSellerNote(), "Testing PHP SDK Recurring Samples"); + Assert.assertEquals(res.getDetails().getSubscriptionAmount().getAmount(), "25.00"); + Assert.assertEquals(res.getDetails().getSubscriptionAmount().getCurrencyCode(), "GBP"); + Assert.assertEquals(res.getRequestId(), "954d87bd-b48f-4eb2-b84b-a0200da333cf"); + Assert.assertEquals(res.toXML(), rawResponse); + } + @Test public void testSetBillingAgreementDetailsResponse() throws Exception { final String rawResponse = loadTestFile("SetBillingAgreementDetailsResponse.xml"); @@ -554,6 +632,40 @@ public void testSetBillingAgreementDetailsResponse() throws Exception { Assert.assertEquals(res.toXML(), rawResponse); } + @Test + public void testSetBillingAgreementDetailsWithSCAResponse() throws Exception { + final String rawResponse = loadTestFile("SetBillingAgreementDetailsWithSCAResponse.xml"); + final ResponseData response = new ResponseData(HttpURLConnection.HTTP_OK, rawResponse); + final SetBillingAgreementDetailsResponseData res = Parser.getSetBillingAgreementDetailsResponse(response); + Assert.assertEquals(res.getDetails().getAmazonBillingAgreementId(), "C02-5533845-8537141"); + Assert.assertEquals(res.getDetails().getBillingAgreementStatus().getLastUpdatedTimestamp(), null); + Assert.assertEquals(res.getDetails().getBillingAgreementStatus().getState(), "Draft"); + Assert.assertEquals(res.getDetails().getBillingAgreementStatus().getReasonCode(), null); + Assert.assertEquals(res.getDetails().getBillingAgreementStatus().getReasonDescription(), null); + Assert.assertEquals(res.getDetails().getDestination().getDestinationType(), "Physical"); + Assert.assertEquals(res.getDetails().getDestination().getPhysicalDestination().getCity(), "Chicago"); + Assert.assertEquals(res.getDetails().getDestination().getPhysicalDestination().getCountryCode(), "US"); + Assert.assertEquals(res.getDetails().getDestination().getPhysicalDestination().getPostalCode(), "60602"); + Assert.assertEquals(res.getDetails().getConstraints().getConstraint().get(0).getConstraintID(), "BuyerConsentNotSet"); + Assert.assertEquals(res.getDetails().getConstraints().getConstraint().get(0).getDescription(), "The buyer has not given consent for this billing agreement."); + Assert.assertEquals(res.getDetails().getReleaseEnvironment().SANDBOX, Environment.SANDBOX); + final XMLGregorianCalendar xgc3 = DatatypeFactory.newInstance().newXMLGregorianCalendar("2019-08-20T22:03:09.297Z"); + Assert.assertEquals(res.getDetails().getCreationTimestamp(), xgc3); + Assert.assertEquals(res.getDetails().getBillingAgreementLimits().getAmountLimitPerTimePeriod().getAmount(), "500"); + Assert.assertEquals(res.getDetails().getBillingAgreementLimits().getAmountLimitPerTimePeriod().getCurrencyCode(), "GBP"); + Assert.assertEquals(res.getDetails().getBillingAgreementLimits().getCurrentRemainingBalance().getAmount(), "500.00"); + Assert.assertEquals(res.getDetails().getBillingAgreementLimits().getCurrentRemainingBalance().getCurrencyCode(), "GBP"); + final XMLGregorianCalendar xgc2 = DatatypeFactory.newInstance().newXMLGregorianCalendar("2019-09-01T00:00:00Z"); + Assert.assertEquals(res.getDetails().getBillingAgreementLimits().getTimePeriodEndDate(), xgc2); + final XMLGregorianCalendar xgc4 = DatatypeFactory.newInstance().newXMLGregorianCalendar("2019-08-01T00:00:00Z"); + Assert.assertEquals(res.getDetails().getBillingAgreementLimits().getTimePeriodStartDate(), xgc4); + Assert.assertEquals(res.getDetails().getBillingAgreementType(), BillingAgreementType.MerchantInitiatedTransaction); + Assert.assertEquals(res.getDetails().getSubscriptionAmount().getAmount(), "25.00"); + Assert.assertEquals(res.getDetails().getSubscriptionAmount().getCurrencyCode(), "GBP"); + Assert.assertEquals(res.getRequestId(), "2dee6992-29f6-4d3e-bc86-2cf339241c58"); + Assert.assertEquals(res.toXML(), rawResponse); + } + @Test public void testConfirmBillingAgreementDetailsResponse() throws Exception { final String rawResponse = loadTestFile("ConfirmBillingAgreementResponse.xml"); @@ -684,7 +796,7 @@ public void testGetRefundDetailsResponseMulticurrency() throws Exception { final XMLGregorianCalendar xgc2 = DatatypeFactory.newInstance().newXMLGregorianCalendar("2017-06-28T18:14:34.752Z"); Assert.assertEquals(res.getDetails().getCreationTimestamp(), xgc2); Assert.assertEquals(res.getDetails().getProviderCreditReversalSummaryList(), null); - Assert.assertEquals(res.getDetails().getSoftDescriptor(), "AMZ*Matt's Test Stor"); + Assert.assertEquals(res.getDetails().getSoftDescriptor(), "AMZ*Matt's Test Stor"); // The three new multi-currency specific fields Assert.assertEquals(res.getDetails().getConvertedAmount().getAmount(), "0.03"); @@ -818,7 +930,21 @@ public void testErrorResponse() throws Exception { Assert.assertEquals(e.getErrorType(), "Sender"); Assert.assertEquals(e.getRequestId(), "6d4699b8-1238-4c09-b539-176e2c2f5462"); Assert.assertEquals(e.getErrorMessage(), "OrderReference S01-5695290-1354077 is not in draft state and cannot be modified with the request submitted by you."); + } + } + @Test + public void testThrottledRequest() throws Exception { + final String rawResponse = loadTestFile("Throttled.xml"); + final ResponseData response = new ResponseData(HttpURLConnection.HTTP_UNAVAILABLE, rawResponse); + try { + Parser.marshalXML(ErrorResponse.class, response); + Assert.fail(); + } catch (AmazonServiceException e) { + Assert.assertEquals(e.getResponseXml(), rawResponse); + Assert.assertEquals(e.getStatusCode(), HttpURLConnection.HTTP_UNAVAILABLE); + Assert.assertEquals(e.getErrorCode(), "RequestThrottled"); + Assert.assertEquals(e.getRequestId(), "d702fd8e-206f-4da4-95e0-1e7422474077"); } } @@ -865,7 +991,43 @@ public void testSetOrderAttributesResponse() throws Exception { Assert.assertEquals(res.getOrderReferenceDetails().getReleaseEnvironment().value(), "LIVE"); Assert.assertEquals(res.getOrderReferenceDetails().getOrderReferenceStatus().getState(),"Draft"); Assert.assertEquals(res.getOrderReferenceDetails().getSellerOrderAttributes().getOrderItemCategories().getOrderItemCategory().size(),2); + } + @Test + public void testGetMerchantAccountStatusActiveResponse() throws Exception { + final String rawResponse = loadTestFile("GetMerchantAccountStatusActive.xml"); + final ResponseData response = new ResponseData(HttpURLConnection.HTTP_OK, rawResponse); + final GetMerchantAccountStatusResponseData res = Parser.getMerchantAccountStatus(response); + + Assert.assertEquals(res.getRequestId(), "4b84390f-748b-40a3-ab07-9395e3616310"); + Assert.assertEquals(res.getAccountStatus(), AccountStatus.ACTIVE); } -} + @Test + public void testGetMerchantAccountStatusInactiveResponse() throws Exception { + final String rawResponse = loadTestFile("GetMerchantAccountStatusInactive.xml"); + final ResponseData response = new ResponseData(HttpURLConnection.HTTP_OK, rawResponse); + final GetMerchantAccountStatusResponseData res = Parser.getMerchantAccountStatus(response); + + Assert.assertEquals(res.getRequestId(), "0441027b-eaf7-443f-bd39-53075c3b8f4f"); + Assert.assertEquals(res.getAccountStatus(), AccountStatus.INACTIVE); + } + + @Test + public void testGetMerchantAccountStatusErrorResponse() throws Exception { + final String rawResponse = loadTestFile("GetMerchantAccountStatusError.xml"); + final ResponseData response = new ResponseData(HttpURLConnection.HTTP_FORBIDDEN, rawResponse); + try { + Parser.marshalXML(ErrorResponse.class, response); + Assert.fail(); + } catch (AmazonServiceException e) { + Assert.assertEquals(e.getResponseXml(), rawResponse); + Assert.assertEquals(e.getStatusCode(), HttpURLConnection.HTTP_FORBIDDEN); + Assert.assertEquals(e.getErrorCode(), "UnauthorizedSolutionProvider"); + Assert.assertEquals(e.getErrorType(), "Sender"); + Assert.assertEquals(e.getRequestId(), "b1c459b9-61c7-4f0b-b0b6-d6afcd314ef9"); + Assert.assertEquals(e.getErrorMessage(), "The Solution Provider : A2J2RH3AOT7N6C is not authorized for getting the status of provided merchant : A3URCZVLDMDI45"); + } + } + +} diff --git a/tst/com/amazon/pay/response/xml/GetBillingAgreementDetailsWithSCAResponse.xml b/tst/com/amazon/pay/response/xml/GetBillingAgreementDetailsWithSCAResponse.xml new file mode 100644 index 0000000..77c23dd --- /dev/null +++ b/tst/com/amazon/pay/response/xml/GetBillingAgreementDetailsWithSCAResponse.xml @@ -0,0 +1,56 @@ + + + + + C02-5533845-8537141 + + Draft + + en-GB + false + + Physical + + IL + Chicago + US + 60602 + + + + + BuyerConsentNotSet + The buyer has not given consent for this billing agreement. + + + MerchantInitiatedTransaction + + SDK Sample Store Name + any custom information + 5678-example-order + + Sandbox + Testing PHP SDK Recurring Samples + + GBP + 25.00 + + 2019-08-20T22:03:09.297Z + + 2019-08-01T00:00:00Z + + GBP + 500.00 + + + GBP + 500 + + 2019-09-01T00:00:00Z + + + + + 954d87bd-b48f-4eb2-b84b-a0200da333cf + + diff --git a/tst/com/amazon/pay/response/xml/GetMerchantAccountStatusActive.xml b/tst/com/amazon/pay/response/xml/GetMerchantAccountStatusActive.xml new file mode 100644 index 0000000..1a928f4 --- /dev/null +++ b/tst/com/amazon/pay/response/xml/GetMerchantAccountStatusActive.xml @@ -0,0 +1,9 @@ + + + ACTIVE + + + 4b84390f-748b-40a3-ab07-9395e3616310 + + + diff --git a/tst/com/amazon/pay/response/xml/GetMerchantAccountStatusError.xml b/tst/com/amazon/pay/response/xml/GetMerchantAccountStatusError.xml new file mode 100644 index 0000000..4898f5f --- /dev/null +++ b/tst/com/amazon/pay/response/xml/GetMerchantAccountStatusError.xml @@ -0,0 +1,9 @@ + + + Sender + UnauthorizedSolutionProvider + The Solution Provider : A2J2RH3AOT7N6C is not authorized for getting the status of provided merchant : A3URCZVLDMDI45 + + b1c459b9-61c7-4f0b-b0b6-d6afcd314ef9 + + diff --git a/tst/com/amazon/pay/response/xml/GetMerchantAccountStatusInactive.xml b/tst/com/amazon/pay/response/xml/GetMerchantAccountStatusInactive.xml new file mode 100644 index 0000000..82b8e8a --- /dev/null +++ b/tst/com/amazon/pay/response/xml/GetMerchantAccountStatusInactive.xml @@ -0,0 +1,8 @@ + + + INACTIVE + + + 0441027b-eaf7-443f-bd39-53075c3b8f4f + + diff --git a/tst/com/amazon/pay/response/xml/GetOrderReferenceDetailsResponse.xml b/tst/com/amazon/pay/response/xml/GetOrderReferenceDetailsResponse.xml index 48ee5e8..2f66739 100644 --- a/tst/com/amazon/pay/response/xml/GetOrderReferenceDetailsResponse.xml +++ b/tst/com/amazon/pay/response/xml/GetOrderReferenceDetailsResponse.xml @@ -8,11 +8,14 @@ Draft + + {"AirlineMetaData" : {"version": 1.0, "airlineCode": "WN", "flightDate": "2018-03-24T20:29:19.22Z", "departureAirport": "CDG", "destinationAirport": "LUX", "bookedLastTime": -1, "classOfTravel": "F", "passengers": {"numberOfPassengers": 4, "numberOfChildren": 1, "numberOfInfants": 1 }}, "AccommodationMetaData": {"version": 1.0, "startDate": "2018-03-24T20:29:19.22Z", "endDate": "2018-03-24T20:29:19.22Z", "lengthOfStay": 5, "numberOfGuests": 4, "class": "Standard", "starRating": 5, "bookedLastTime": -1 }, "OrderMetaData": {"version": 1.0, "numberOfItems": 3, "type": "Digital" }, "BuyerMetaData": {"version" : 1.0, "isFirstTimeCustomer" : true, "numberOfPastPurchases" : 2, "numberOfDisputedPurchases" : 3, "hasOpenDispute" : true, "riskScore" : 0.75 }} + Physical - New York - NY + äöüßâêîôûàèùé + 宋 俊华 市区-徐汇区 广东省 10101-9876 US @@ -29,4 +32,4 @@ 5f20169b-7ab2-11df-bcef-d35615e2b044 - \ No newline at end of file + diff --git a/tst/com/amazon/pay/response/xml/GetOrderReferenceDetailsScaResponse.xml b/tst/com/amazon/pay/response/xml/GetOrderReferenceDetailsScaResponse.xml new file mode 100644 index 0000000..ee40b85 --- /dev/null +++ b/tst/com/amazon/pay/response/xml/GetOrderReferenceDetailsScaResponse.xml @@ -0,0 +1,62 @@ + + + + + 2019-04-18T14:44:14.086Z + InvalidPaymentMethod + Suspended + + en-GB + + xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx20= + + + Physical + + IL + Chicago + 800-000-0000 + US + 60602 + Susie Smith + 10 Ditka Ave + Suite 2500 + + + 2019-10-15T14:43:34.847Z + + S02-7295856-8712939-A063411 + + + SDK Sample Store Name + Any custom information + 123456-TestOrder-123456 + + + + PaymentPlanNotSet + The buyer has not been able to select a Payment method for the given Order Reference. + + + + GBP + 19.95 + + + REQUIRED + + + Sandbox Test + test+sandbox@amazon.com + + Sandbox + The Seller Note + S02-7295856-8712939 + 2019-04-18T14:43:34.847Z + false + + + + df57b851-c556-46f0-a561-9e412d3b651d + + diff --git a/tst/com/amazon/pay/response/xml/SanitizedData.xml b/tst/com/amazon/pay/response/xml/SanitizedData.xml index d648b13..e44c19c 100644 --- a/tst/com/amazon/pay/response/xml/SanitizedData.xml +++ b/tst/com/amazon/pay/response/xml/SanitizedData.xml @@ -1,5 +1,4 @@ - - + @@ -29,4 +28,4 @@ eab0140b-e59c-4875-859b-f5012944ba - \ No newline at end of file + diff --git a/tst/com/amazon/pay/response/xml/SanitizedDataBefore.xml b/tst/com/amazon/pay/response/xml/SanitizedDataBefore.xml new file mode 100644 index 0000000..706465f --- /dev/null +++ b/tst/com/amazon/pay/response/xml/SanitizedDataBefore.xml @@ -0,0 +1,37 @@ + + + + + + Draft + + + Physical + + äöüßâêîôûàèùé + 宋 俊华 市区-徐汇区 广东省 + 10101-9876 + US + + + 2016-04-27T20:43:45.183Z + ANDRCTOTP9 + + myTestStore + myCustomInformation + test1234 + + + USD + 500.00 + + Sandbox + This is a note that will get sanitized! + S01-9821095-0000200 + 2015-10-30T20:43:45.183Z + + + + eab0140b-e59c-4875-859b-f5012944ba + + diff --git a/tst/com/amazon/pay/response/xml/SetBillingAgreementDetailsWithSCAResponse.xml b/tst/com/amazon/pay/response/xml/SetBillingAgreementDetailsWithSCAResponse.xml new file mode 100644 index 0000000..f802c90 --- /dev/null +++ b/tst/com/amazon/pay/response/xml/SetBillingAgreementDetailsWithSCAResponse.xml @@ -0,0 +1,56 @@ + + + + + C02-5533845-8537141 + + Draft + + en-GB + false + + Physical + + IL + Chicago + US + 60602 + + + + + BuyerConsentNotSet + The buyer has not given consent for this billing agreement. + + + MerchantInitiatedTransaction + + SDK Sample Store Name + any custom information + 5678-example-order + + Sandbox + Testing PHP SDK Recurring Samples + + GBP + 25.00 + + 2019-08-20T22:03:09.297Z + + 2019-08-01T00:00:00Z + + GBP + 500.00 + + + GBP + 500 + + 2019-09-01T00:00:00Z + + + + + 2dee6992-29f6-4d3e-bc86-2cf339241c58 + + \ No newline at end of file diff --git a/tst/com/amazon/pay/response/xml/SetOrderAttributesScaResponse.xml b/tst/com/amazon/pay/response/xml/SetOrderAttributesScaResponse.xml new file mode 100644 index 0000000..9cdf7b6 --- /dev/null +++ b/tst/com/amazon/pay/response/xml/SetOrderAttributesScaResponse.xml @@ -0,0 +1,49 @@ + + + + + 2019-04-30T23:41:30.926Z + Open + + en-GB + + Physical + + IL + Chicago + 800-000-0000 + US + 60602 + Susie Smith + 10 Ditka Ave + Suite 2500 + + + 2019-10-27T23:24:14.907Z + + SDK Sample Store Name + abcdef + abcdef + + + GBP + 10.00 + + + REQUIRED + + + Sandbox Guillot + guillotb+sandbox@amazon.com + + Sandbox + The Seller Note + S02-4946804-1132193 + 2019-04-30T23:24:14.907Z + false + + + + 68258c6f-9a7b-4cdf-b72b-9e0886f39d9b + + diff --git a/tst/com/amazon/pay/response/xml/SetOrderReferenceDetailsResponse.xml b/tst/com/amazon/pay/response/xml/SetOrderReferenceDetailsResponse.xml index 9cba5fb..15fb726 100644 --- a/tst/com/amazon/pay/response/xml/SetOrderReferenceDetailsResponse.xml +++ b/tst/com/amazon/pay/response/xml/SetOrderReferenceDetailsResponse.xml @@ -20,6 +20,7 @@ myTestStore myCustomInformation test1234 + {"AirlineMetaData" : {"version": 1.0, "airlineCode": "WN", "flightDate": "2018-03-24T20:29:19.22Z", "departureAirport": "CDG", "destinationAirport": "LUX", "bookedLastTime": -1, "classOfTravel": "F", "passengers": {"numberOfPassengers": 4, "numberOfChildren": 1, "numberOfInfants": 1 }}, "AccommodationMetaData": {"version": 1.0, "startDate": "2018-03-24T20:29:19.22Z", "endDate": "2018-03-24T20:29:19.22Z", "lengthOfStay": 5, "numberOfGuests": 4, "class": "Standard", "starRating": 5, "bookedLastTime": -1 }, "OrderMetaData": {"version": 1.0, "numberOfItems": 3, "type": "Digital" }, "BuyerMetaData": {"version" : 1.0, "isFirstTimeCustomer" : true, "numberOfPastPurchases" : 2, "numberOfDisputedPurchases" : 3, "hasOpenDispute" : true, "riskScore" : 0.75 }} USD diff --git a/tst/com/amazon/pay/response/xml/Throttled.xml b/tst/com/amazon/pay/response/xml/Throttled.xml new file mode 100644 index 0000000..7290034 --- /dev/null +++ b/tst/com/amazon/pay/response/xml/Throttled.xml @@ -0,0 +1,9 @@ + + + + + RequestThrottled + Request is throttled + + d702fd8e-206f-4da4-95e0-1e7422474077 +