├── ci.sh ├── .github ├── CODEOWNERS ├── workflows │ └── security.dependency-review.yml ├── PULL_REQUEST_TEMPLATE.md └── ISSUE_TEMPLATE.md ├── src ├── main │ ├── resources │ │ └── braintree.properties │ └── java │ │ └── com │ │ └── braintreegateway │ │ ├── SimplePager.java │ │ ├── Pager.java │ │ ├── util │ │ ├── Hasher.java │ │ ├── NodeWrapperFactory.java │ │ ├── SimpleNodeWrapperFactory.java │ │ ├── SignatureService.java │ │ ├── Experimental.java │ │ ├── Crypto.java │ │ ├── MapUtils.java │ │ ├── EnumUtils.java │ │ ├── Sha1Hasher.java │ │ ├── Sha256Hasher.java │ │ └── ClientLibraryProperties.java │ │ ├── exceptions │ │ ├── TestOperationPerformedInProductionException.java │ │ ├── AuthenticationException.java │ │ ├── ForgedQueryStringException.java │ │ ├── UpgradeRequiredException.java │ │ ├── ServiceUnavailableException.java │ │ ├── ConfigurationException.java │ │ ├── GatewayTimeoutException.java │ │ ├── RequestTimeoutException.java │ │ ├── AuthorizationException.java │ │ ├── InvalidChallengeException.java │ │ ├── ServerException.java │ │ ├── NotFoundException.java │ │ ├── InvalidSignatureException.java │ │ ├── TooManyRequestsException.java │ │ ├── TimeoutException.java │ │ ├── UnexpectedException.java │ │ └── BraintreeException.java │ │ ├── AddOn.java │ │ ├── Discount.java │ │ ├── IdsSearchRequest.java │ │ ├── graphql │ │ ├── enums │ │ │ ├── Recommendations.java │ │ │ └── RecommendedPaymentOption.java │ │ ├── inputs │ │ │ └── MonetaryAmountInput.java │ │ └── types │ │ │ ├── PaymentOptions.java │ │ │ └── PaymentRecommendation.java │ │ ├── PaymentMethod.java │ │ ├── IsNode.java │ │ ├── EqualityNode.java │ │ ├── TextNode.java │ │ ├── EndsWithNode.java │ │ ├── OAuthResult.java │ │ ├── enums │ │ ├── Business.java │ │ ├── Consumer.java │ │ ├── Purchase.java │ │ ├── Corporate.java │ │ └── PrepaidReloadable.java │ │ ├── test │ │ ├── CreditCardDefaults.java │ │ ├── MerchantAccount.java │ │ ├── VenmoSdk.java │ │ └── CreditCardNumbers.java │ │ ├── ProcessorResponseType.java │ │ ├── KeyValueNode.java │ │ ├── LocalPaymentReversed.java │ │ ├── MerchantAccountPager.java │ │ ├── BlikAlias.java │ │ ├── ExpiredCreditCardPager.java │ │ ├── PartialMatchNode.java │ │ ├── DisputePager.java │ │ ├── ExternalVault.java │ │ ├── OAuthRevokeAccessTokenRequest.java │ │ ├── CustomerPager.java │ │ ├── MultipleValueOrTextNode.java │ │ ├── BankAccountInstantVerificationJwt.java │ │ ├── TransactionPager.java │ │ ├── AchMandate.java │ │ ├── CustomActionsPaymentMethodField.java │ │ ├── SubscriptionPager.java │ │ ├── ExpiringCreditCardPager.java │ │ ├── TransactionDetails.java │ │ ├── RecipientPhone.java │ │ ├── LocalPaymentExpired.java │ │ ├── MonetaryAmount.java │ │ ├── LiabilityShift.java │ │ ├── AccountUpdaterDailyReport.java │ │ ├── CreditCardVerificationPager.java │ │ ├── MerchantGateway.java │ │ ├── MultipleValueNode.java │ │ ├── OAuthAccessRevocation.java │ │ ├── SettlementBatchSummary.java │ │ ├── UsBankAccountVerificationPager.java │ │ ├── PaginatedResult.java │ │ ├── PaymentMethodDeleteRequest.java │ │ ├── SubscriptionDetails.java │ │ ├── TransactionIndustryRequest.java │ │ ├── AchReturnResponse.java │ │ ├── DisputePayPalMessage.java │ │ ├── DocumentUploadRequest.java │ │ ├── InternationalPhone.java │ │ ├── TransactionDescriptorRequest.java │ │ ├── DateRangeNode.java │ │ ├── DocumentUploadGateway.java │ │ ├── SubscriptionDescriptorRequest.java │ │ ├── ThreeDSecureLookup.java │ │ ├── FacilitatedDetails.java │ │ ├── UsBankAccountVerificationConfirmRequest.java │ │ ├── AddOnGateway.java │ │ ├── PaymentMethodGrantRevokeRequest.java │ │ ├── PayPalAccountRequest.java │ │ ├── MerchantAccountCreateForCurrencyRequest.java │ │ ├── Descriptor.java │ │ ├── PayPalPaymentResourceGateway.java │ │ ├── SepaDirectDebitAccountGateway.java │ │ ├── ThreeDSecureLookupInfo.java │ │ ├── DiscountGateway.java │ │ ├── LocalPaymentFunded.java │ │ ├── ThreeDSecureLookupResponse.java │ │ ├── SepaDirectDebitAccountRequest.java │ │ ├── SubscriptionOptionsPayPalRequest.java │ │ ├── ExternalVaultCardRequest.java │ │ ├── EnrichedCustomerData.java │ │ ├── SearchCriteria.java │ │ ├── SearchNode.java │ │ ├── ThreeDSecureAuthenticateInfo.java │ │ ├── FacilitatorDetails.java │ │ ├── ApplePayCardOptionsRequest.java │ │ ├── FileEvidenceRequest.java │ │ ├── CustomerOptionsRequest.java │ │ ├── SubscriptionTransactionOptionsRequest.java │ │ ├── AndroidPayCardOptionsRequest.java │ │ ├── UsBankAccountGateway.java │ │ ├── Request.java │ │ ├── ConnectedMerchantPayPalStatusChanged.java │ │ ├── ConnectedMerchantStatusTransitioned.java │ │ ├── PayPalAccountOptionsRequest.java │ │ ├── UnknownPaymentMethod.java │ │ ├── AndroidPayNetworkTokenOptionsRequest.java │ │ ├── SepaDirectDebitAccountOptionsRequest.java │ │ ├── AuthenticationInsight.java │ │ ├── IndustryRequest.java │ │ ├── InstallmentRequest.java │ │ ├── OAuthCredentials.java │ │ ├── ExchangeRateQuoteRequest.java │ │ ├── RevokedPaymentMethodMetadata.java │ │ ├── TransactionOptionsVenmoRequest.java │ │ ├── VenmoAccountDetails.java │ │ ├── PayPalAccountGateway.java │ │ ├── OAuthCredentialsRequest.java │ │ ├── CustomerInternationalPhoneRequest.java │ │ ├── DescriptorRequest.java │ │ ├── TransactionOptionsThreeDSecureRequest.java │ │ ├── TransactionLevelFeeReportRequest.java │ │ ├── TransactionOptionsCloneRequest.java │ │ ├── CreditCardAddressOptionsRequest.java │ │ ├── PaymentInstrumentType.java │ │ ├── DisputeStatusHistory.java │ │ ├── PaymentMethodAddressOptionsRequest.java │ │ ├── AuthenticationInsightOptionsRequest.java │ │ ├── TransactionLevelFeeReport.java │ │ ├── AddressInternationalPhoneRequest.java │ │ ├── Adjustment.java │ │ ├── PayPalOnlyAccountRequest.java │ │ ├── TextEvidenceRequest.java │ │ ├── DocumentUpload.java │ │ ├── TransactionReview.java │ │ ├── TransactionCloneRequest.java │ │ ├── ShippingInternationalPhoneRequest.java │ │ ├── PartnerMerchant.java │ │ ├── PartyInternationalPhoneRequest.java │ │ ├── TransactionAddressInternationalPhoneRequest.java │ │ ├── ExternalVaultRequest.java │ │ ├── MerchantAccount.java │ │ ├── StatusEvent.java │ │ ├── PackageDetails.java │ │ ├── AddModificationRequest.java │ │ ├── TaxIdentifierRequest.java │ │ ├── Installment.java │ │ ├── PaymentMethodCustomerDataUpdatedMetadata.java │ │ ├── TransactionSubMerchantInternationalPhoneRequest.java │ │ ├── CustomActionsPaymentMethodDetails.java │ │ ├── PaymentMethodNonceGateway.java │ │ ├── SubscriptionTransactionRequest.java │ │ ├── SettlementBatchSummaryGateway.java │ │ ├── ValidationError.java │ │ └── DisputeEvidence.java └── test │ ├── resources │ ├── keystore.jks │ ├── fixtures │ │ ├── bt_logo.png │ │ ├── too_long.pdf │ │ ├── malformed_pdf.pdf │ │ └── gif_extension_bt_logo.gif │ ├── unittest │ │ └── customer_session │ │ │ ├── create_session_with_errors.json │ │ │ ├── update_session_with_errors.json │ │ │ ├── customer_recommendations_with_errors.json │ │ │ ├── create_session_unparseable_response.json │ │ │ ├── update_session_unparseable_response.json │ │ │ ├── create_session_successful_response.json │ │ │ ├── update_session_successful_response.json │ │ │ ├── customer_recommendations_unparseable_response.json │ │ │ └── customer_recommendations_successful_response.json │ ├── privateKey.key │ └── certificate.crt │ └── java │ └── com │ └── braintreegateway │ ├── unittest │ ├── util │ │ ├── Sha1HasherTest.java │ │ ├── Sha256HasherTest.java │ │ ├── CryptoTest.java │ │ └── HttpsTest.java │ ├── PaymentMethodDeleteRequestTest.java │ ├── graphql │ │ ├── PhoneInputTest.java │ │ └── PayPalPayeeInputTest.java │ ├── ApplePayCardOptionsTest.java │ ├── AndroidPayCardOptionsTest.java │ ├── AndroidPayNetworkTokenOptionsTest.java │ ├── RiskDataCustomerRequestTest.java │ ├── OAuthAccessRevocationTest.java │ ├── ThreeDSecureLookupTest.java │ ├── FacilitatedDetailsTest.java │ ├── CreditCardOptionsRequestTest.java │ ├── PaymentMethodOptionsRequestTest.java │ ├── TransactionSearchRequestTest.java │ ├── CreditCardVerificationOptionsRequestTest.java │ ├── ShippingOptionRequestTest.java │ ├── DocumentUploadRequestTest.java │ ├── LiabilityShiftTest.java │ ├── PaginatedCollectionTest.java │ ├── SepaDirectDebitAccountRequestTest.java │ ├── SearchRequestTest.java │ ├── CreditCardGatewayTest.java │ └── GraphQLClientTest.java │ ├── integrationtest │ ├── ValidationErrorCodeIT.java │ ├── GraphQLClientIT.java │ ├── UnknownPaymentMethodIT.java │ ├── DisbursementDetailsIT.java │ ├── ApplePayCardIT.java │ └── AndroidPayCardIT.java │ ├── TransactionIndustryDataRequestTest.java │ └── testhelpers │ └── MerchantAccountTestConstants.java ├── Dockerfile ├── Makefile ├── .gitignore ├── ACKNOWLEDGEMENTS.md ├── NOTICE ├── DEVELOPMENT.md └── LICENSE /ci.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | rake --trace test 4 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @PayPal-Braintree/team-sdk-server 2 | -------------------------------------------------------------------------------- /src/main/resources/braintree.properties: -------------------------------------------------------------------------------- 1 | braintree.gateway.version=${pom.version} 2 | -------------------------------------------------------------------------------- /src/test/resources/keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/braintree/braintree_java/HEAD/src/test/resources/keystore.jks -------------------------------------------------------------------------------- /src/test/resources/fixtures/bt_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/braintree/braintree_java/HEAD/src/test/resources/fixtures/bt_logo.png -------------------------------------------------------------------------------- /src/test/resources/fixtures/too_long.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/braintree/braintree_java/HEAD/src/test/resources/fixtures/too_long.pdf -------------------------------------------------------------------------------- /src/test/resources/unittest/customer_session/create_session_with_errors.json: -------------------------------------------------------------------------------- 1 | { 2 | "errors": [ 3 | { "message": "validation error"} 4 | ] 5 | } -------------------------------------------------------------------------------- /src/test/resources/unittest/customer_session/update_session_with_errors.json: -------------------------------------------------------------------------------- 1 | { 2 | "errors": [ 3 | { "message": "validation error"} 4 | ] 5 | } -------------------------------------------------------------------------------- /src/test/resources/fixtures/malformed_pdf.pdf: -------------------------------------------------------------------------------- 1 | XXXXXXXXXXX¾?^gfkbfu¶šÙú”¼Åxc¯ÄÖñ•:x„BºS·É=] óqçÅÒÐwî+= x wÁ¼/7ú7ÀݛeÀÅA¿8?À­‹6Á2[î(†¤Ö@+3[ß} 2 | -------------------------------------------------------------------------------- /src/test/resources/unittest/customer_session/customer_recommendations_with_errors.json: -------------------------------------------------------------------------------- 1 | { 2 | "errors": [ 3 | { "message": "validation error"} 4 | ] 5 | } -------------------------------------------------------------------------------- /src/test/resources/fixtures/gif_extension_bt_logo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/braintree/braintree_java/HEAD/src/test/resources/fixtures/gif_extension_bt_logo.gif -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/SimplePager.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public interface SimplePager { 4 | public PaginatedResult getPage(int page); 5 | } 6 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM dockerhub.braintree.tools/bt/java:8-stretch 2 | 3 | RUN apt-get update 4 | RUN apt-get -y install --force-yes rake ant ant-optional maven procps 5 | 6 | WORKDIR /braintree-java 7 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: console build 2 | 3 | console: build 4 | docker run -it -v="$(PWD):/braintree-java" --net="host" braintree-java /bin/bash -l 5 | 6 | build: 7 | docker build -t braintree-java . 8 | -------------------------------------------------------------------------------- /src/test/resources/unittest/customer_session/create_session_unparseable_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "data": { 3 | "causesParsingError": { 4 | "sessionId": "customer-session-id" 5 | } 6 | } 7 | } -------------------------------------------------------------------------------- /src/test/resources/unittest/customer_session/update_session_unparseable_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "data": { 3 | "causesParsingError": { 4 | "sessionId": "customer-session-id" 5 | } 6 | } 7 | } -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/Pager.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import java.util.List; 4 | 5 | public interface Pager { 6 | public List getPage(List ids); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/util/Hasher.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.util; 2 | 3 | public interface Hasher { 4 | 5 | public String hmacHash(String privateKey, String content); 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/test/resources/unittest/customer_session/create_session_successful_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "data": { 3 | "createCustomerSession": { 4 | "sessionId": "customer-session-id" 5 | } 6 | } 7 | } -------------------------------------------------------------------------------- /src/test/resources/unittest/customer_session/update_session_successful_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "data": { 3 | "updateCustomerSession": { 4 | "sessionId": "customer-session-id" 5 | } 6 | } 7 | } -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/exceptions/TestOperationPerformedInProductionException.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.exceptions; 2 | 3 | public class TestOperationPerformedInProductionException extends BraintreeException { 4 | } 5 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/exceptions/AuthenticationException.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.exceptions; 2 | 3 | public class AuthenticationException extends BraintreeException { 4 | private static final long serialVersionUID = 1L; 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/exceptions/ForgedQueryStringException.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.exceptions; 2 | 3 | public class ForgedQueryStringException extends BraintreeException { 4 | private static final long serialVersionUID = 1L; 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/exceptions/UpgradeRequiredException.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.exceptions; 2 | 3 | public class UpgradeRequiredException extends BraintreeException { 4 | private static final long serialVersionUID = 1L; 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/exceptions/ServiceUnavailableException.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.exceptions; 2 | 3 | public class ServiceUnavailableException extends BraintreeException { 4 | private static final long serialVersionUID = 1L; 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/util/NodeWrapperFactory.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.util; 2 | 3 | public interface NodeWrapperFactory { 4 | NodeWrapperFactory instance = new SimpleNodeWrapperFactory(); 5 | 6 | NodeWrapper create(String xml); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/AddOn.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | 5 | public class AddOn extends Modification { 6 | public AddOn(NodeWrapper node) { 7 | super(node); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/Discount.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | 5 | public class Discount extends Modification { 6 | public Discount(NodeWrapper node) { 7 | super(node); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /.github/workflows/security.dependency-review.yml: -------------------------------------------------------------------------------- 1 | name: Security 2 | 3 | on: 4 | pull_request: 5 | branches: [ master ] 6 | workflow_dispatch: 7 | 8 | jobs: 9 | dependency-review: 10 | uses: PayPal-Braintree/security-workflows/.github/workflows/dependency-review.yml@main 11 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/util/SimpleNodeWrapperFactory.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.util; 2 | 3 | public class SimpleNodeWrapperFactory implements NodeWrapperFactory { 4 | public NodeWrapper create(String xml) { 5 | return SimpleNodeWrapper.parse(xml); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .classpath 2 | .project 3 | .settings 4 | .settings/* 5 | /.idea 6 | /.vscode 7 | *.iml 8 | /*.jar 9 | /*.gz 10 | /classes 11 | /doc 12 | /test-classes 13 | .DS_Store 14 | /tags 15 | .idea 16 | out/ 17 | .metadata/ 18 | target/ 19 | large_file.png 20 | empty_file.png 21 | .vscode/ 22 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/exceptions/ConfigurationException.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.exceptions; 2 | 3 | public class ConfigurationException extends BraintreeException { 4 | 5 | public ConfigurationException(String message) { 6 | super(message); 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/IdsSearchRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class IdsSearchRequest extends SearchRequest { 4 | public MultipleValueNode ids() { 5 | return new MultipleValueNode("ids", this); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/graphql/enums/Recommendations.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.graphql.enums; 2 | 3 | import com.braintreegateway.util.Experimental; 4 | 5 | @Experimental("This class is experimental and may change in future releases.") 6 | public enum Recommendations { 7 | PAYMENT_RECOMMENDATIONS 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/exceptions/GatewayTimeoutException.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.exceptions; 2 | 3 | public class GatewayTimeoutException extends BraintreeException { 4 | private static final long serialVersionUID = 1L; 5 | 6 | public GatewayTimeoutException() { 7 | super(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/exceptions/RequestTimeoutException.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.exceptions; 2 | 3 | public class RequestTimeoutException extends BraintreeException { 4 | private static final long serialVersionUID = 1L; 5 | 6 | public RequestTimeoutException() { 7 | super(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/PaymentMethod.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import java.util.List; 4 | 5 | public interface PaymentMethod { 6 | 7 | String getToken(); 8 | boolean isDefault(); 9 | String getImageUrl(); 10 | String getCustomerId(); 11 | List getSubscriptions(); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/exceptions/AuthorizationException.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.exceptions; 2 | 3 | public class AuthorizationException extends BraintreeException { 4 | private static final long serialVersionUID = 1L; 5 | 6 | public AuthorizationException(String message) { 7 | super(message); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/IsNode.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class IsNode extends SearchNode { 4 | public IsNode(String nodeName, T parent) { 5 | super(nodeName, parent); 6 | } 7 | 8 | public T is(String value) { 9 | return assembleCriteria("is", value); 10 | } 11 | } -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/EqualityNode.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class EqualityNode extends IsNode { 4 | public EqualityNode(String nodeName, T parent) { 5 | super(nodeName, parent); 6 | } 7 | 8 | public T isNot(String value) { 9 | return assembleCriteria("is_not", value); 10 | } 11 | } -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/exceptions/InvalidChallengeException.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.exceptions; 2 | 3 | public class InvalidChallengeException extends BraintreeException { 4 | public InvalidChallengeException(String message) { 5 | super(message); 6 | } 7 | 8 | public InvalidChallengeException() { 9 | super(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/TextNode.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class TextNode extends PartialMatchNode { 4 | public TextNode(String nodeName, T parent) { 5 | super(nodeName, parent); 6 | } 7 | 8 | public T contains(String value) { 9 | return assembleCriteria("contains", value); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/EndsWithNode.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class EndsWithNode extends SearchNode { 4 | public EndsWithNode(String nodeName, T parent) { 5 | super(nodeName, parent); 6 | } 7 | 8 | public T endsWith(String value) { 9 | return assembleCriteria("ends_with", value); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/exceptions/ServerException.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.exceptions; 2 | 3 | public class ServerException extends BraintreeException { 4 | private static final long serialVersionUID = 1L; 5 | 6 | public ServerException(String message) { 7 | super(message); 8 | } 9 | 10 | public ServerException() { 11 | super(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/OAuthResult.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | 5 | public class OAuthResult { 6 | 7 | private Boolean result; 8 | 9 | public OAuthResult(NodeWrapper node) { 10 | result = node.findBoolean("success"); 11 | } 12 | 13 | public Boolean getResult() { 14 | return result; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/enums/Business.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.enums; 2 | 3 | public enum Business { 4 | YES("Yes"), 5 | NO("No"), 6 | UNKNOWN("Unknown"); 7 | 8 | private final String value; 9 | 10 | Business(String value) { 11 | this.value = value; 12 | } 13 | 14 | @Override 15 | public String toString() { 16 | return value; 17 | } 18 | } -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/enums/Consumer.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.enums; 2 | 3 | public enum Consumer { 4 | YES("Yes"), 5 | NO("No"), 6 | UNKNOWN("Unknown"); 7 | 8 | private final String value; 9 | 10 | Consumer(String value) { 11 | this.value = value; 12 | } 13 | 14 | @Override 15 | public String toString() { 16 | return value; 17 | } 18 | } -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/enums/Purchase.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.enums; 2 | 3 | public enum Purchase { 4 | YES("Yes"), 5 | NO("No"), 6 | UNKNOWN("Unknown"); 7 | 8 | private final String value; 9 | 10 | Purchase(String value) { 11 | this.value = value; 12 | } 13 | 14 | @Override 15 | public String toString() { 16 | return value; 17 | } 18 | } -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/exceptions/NotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.exceptions; 2 | 3 | public class NotFoundException extends BraintreeException { 4 | private static final long serialVersionUID = 1L; 5 | 6 | public NotFoundException(String message) { 7 | super(message); 8 | } 9 | 10 | public NotFoundException() { 11 | super(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/enums/Corporate.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.enums; 2 | 3 | public enum Corporate { 4 | YES("Yes"), 5 | NO("No"), 6 | UNKNOWN("Unknown"); 7 | 8 | private final String value; 9 | 10 | Corporate(String value) { 11 | this.value = value; 12 | } 13 | 14 | @Override 15 | public String toString() { 16 | return value; 17 | } 18 | } -------------------------------------------------------------------------------- /ACKNOWLEDGEMENTS.md: -------------------------------------------------------------------------------- 1 | Acknowledgements 2 | ---------------- 3 | 4 | The Braintree SDK uses code from the following libraries: 5 | 6 | * [Mockito](https://github.com/mockito/mockito), MIT License 7 | * [JUnit](https://github.com/junit-team/junit5), Eclipse Public License - v 1.0 8 | * [OSGI Core](https://www.osgi.org), Apache License, Version 2.0 9 | * [XMLUnit](https://www.xmlunit.org), Apache License, Version 2.0 10 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/test/CreditCardDefaults.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.test; 2 | 3 | public enum CreditCardDefaults { 4 | 5 | IssuingBank("NETWORK ONLY"), 6 | CountryOfIssuance("USA"); 7 | 8 | private final String value; 9 | 10 | public String getValue() { 11 | return value; 12 | } 13 | 14 | private CreditCardDefaults(String value) { 15 | this.value = value; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/ProcessorResponseType.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | /** 4 | * An Enum representing all of the processor response types from the gateway 5 | * that are present on Transaction, AuthorizationAdjustment and 6 | * CreditCardVerification. 7 | */ 8 | public enum ProcessorResponseType { 9 | APPROVED, 10 | SOFT_DECLINED, 11 | HARD_DECLINED, 12 | UNRECOGNIZED 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/enums/PrepaidReloadable.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.enums; 2 | 3 | public enum PrepaidReloadable { 4 | YES("Yes"), 5 | NO("No"), 6 | UNKNOWN("Unknown"); 7 | 8 | private final String value; 9 | 10 | PrepaidReloadable(String value) { 11 | this.value = value; 12 | } 13 | 14 | @Override 15 | public String toString() { 16 | return value; 17 | } 18 | } -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/KeyValueNode.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class KeyValueNode extends SearchNode { 4 | public KeyValueNode(String nodeName, T parent) { 5 | super(nodeName, parent); 6 | } 7 | 8 | public T is(Object value) { 9 | parent.addKeyValueCriteria(nodeName.toString(), value.toString()); 10 | return parent; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/exceptions/InvalidSignatureException.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.exceptions; 2 | 3 | public class InvalidSignatureException extends BraintreeException { 4 | private static final long serialVersionUID = 1L; 5 | 6 | public InvalidSignatureException(String message) { 7 | super(message); 8 | } 9 | 10 | public InvalidSignatureException() { 11 | super(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/exceptions/TooManyRequestsException.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.exceptions; 2 | 3 | public class TooManyRequestsException extends BraintreeException { 4 | private static final long serialVersionUID = 1L; 5 | 6 | public TooManyRequestsException() { 7 | super(); 8 | } 9 | 10 | public TooManyRequestsException(String message) { 11 | super(message); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/LocalPaymentReversed.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | 5 | public class LocalPaymentReversed { 6 | private String paymentId; 7 | 8 | public LocalPaymentReversed(NodeWrapper node) { 9 | this.paymentId = node.findString("payment-id"); 10 | } 11 | 12 | public String getPaymentId() { 13 | return paymentId; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/exceptions/TimeoutException.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.exceptions; 2 | 3 | public class TimeoutException extends BraintreeException { 4 | private static final long serialVersionUID = 1L; 5 | 6 | public TimeoutException(String message) { 7 | super(message); 8 | } 9 | 10 | public TimeoutException(String message, Throwable cause) { 11 | super(message, cause); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/graphql/enums/RecommendedPaymentOption.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.graphql.enums; 2 | 3 | import com.braintreegateway.util.Experimental; 4 | 5 | /** 6 | * Represents available payment options related to PayPal customer session recommendations. 7 | */ 8 | @Experimental("This class is experimental and may change in future releases.") 9 | public enum RecommendedPaymentOption { 10 | PAYPAL, 11 | VENMO 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/exceptions/UnexpectedException.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.exceptions; 2 | 3 | public class UnexpectedException extends BraintreeException { 4 | 5 | private static final long serialVersionUID = 1L; 6 | 7 | public UnexpectedException(String message) { 8 | super(message); 9 | } 10 | 11 | public UnexpectedException(String message, Throwable cause) { 12 | super(message, cause); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/MerchantAccountPager.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class MerchantAccountPager implements SimplePager { 4 | 5 | private MerchantAccountGateway gateway; 6 | 7 | public MerchantAccountPager(MerchantAccountGateway gateway) { 8 | this.gateway = gateway; 9 | } 10 | 11 | public PaginatedResult getPage(int page) { 12 | return gateway.fetchMerchantAccounts(page); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/BlikAlias.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | 5 | public class BlikAlias { 6 | private String key; 7 | private String label; 8 | 9 | public BlikAlias(NodeWrapper node) { 10 | key = node.findString("key"); 11 | label = node.findString("label"); 12 | } 13 | 14 | public String getKey() { 15 | return key; 16 | } 17 | 18 | public String getLabel() { 19 | return label; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/resources/unittest/customer_session/customer_recommendations_unparseable_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "data": { 3 | "causesParsingError": { 4 | "isInPayPalNetwork": true, 5 | "recommendations": { 6 | "paymentOptions": [ 7 | { 8 | "paymentOption": "PAYPAL", 9 | "priority": 1 10 | }, 11 | { 12 | "paymentOption": "VENMO", 13 | "priority": 2 14 | } 15 | ] 16 | } 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/ExpiredCreditCardPager.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import java.util.List; 4 | 5 | public class ExpiredCreditCardPager implements Pager { 6 | 7 | private CreditCardGateway gateway; 8 | 9 | public ExpiredCreditCardPager(CreditCardGateway gateway) { 10 | this.gateway = gateway; 11 | } 12 | 13 | public List getPage(List ids) { 14 | return gateway.fetchExpiredCreditCards(ids); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/PartialMatchNode.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class PartialMatchNode extends EqualityNode { 4 | public PartialMatchNode(String nodeName, T parent) { 5 | super(nodeName, parent); 6 | } 7 | 8 | public T endsWith(String value) { 9 | return assembleCriteria("ends_with", value); 10 | } 11 | 12 | public T startsWith(String value) { 13 | return assembleCriteria("starts_with", value); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/exceptions/BraintreeException.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.exceptions; 2 | 3 | public class BraintreeException extends RuntimeException { 4 | private static final long serialVersionUID = 1L; 5 | 6 | public BraintreeException(String message, Throwable cause) { 7 | super(message, cause); 8 | } 9 | 10 | public BraintreeException(String message) { 11 | super(message); 12 | } 13 | 14 | public BraintreeException() { 15 | super(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/test/resources/unittest/customer_session/customer_recommendations_successful_response.json: -------------------------------------------------------------------------------- 1 | { 2 | "data": { 3 | "generateCustomerRecommendations": { 4 | "sessionId": "a-customer-session-id", 5 | "isInPayPalNetwork": true, 6 | "paymentRecommendations": [ 7 | { 8 | "paymentOption": "PAYPAL", 9 | "recommendedPriority": 1 10 | }, 11 | { 12 | "paymentOption": "VENMO", 13 | "recommendedPriority": 2 14 | } 15 | ] 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/DisputePager.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class DisputePager implements SimplePager { 4 | private DisputeGateway gateway; 5 | private DisputeSearchRequest query; 6 | 7 | public DisputePager(DisputeGateway gateway, DisputeSearchRequest query) { 8 | this.gateway = gateway; 9 | this.query = query; 10 | } 11 | 12 | public PaginatedResult getPage(int page) { 13 | return gateway.fetchDisputes(query, page); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/ExternalVault.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class ExternalVault { 4 | private ExternalVault() { 5 | 6 | } 7 | 8 | public enum Status { 9 | WILL_VAULT("will_vault"), 10 | VAULTED("vaulted"); 11 | 12 | private final String name; 13 | 14 | Status(String name) { 15 | this.name = name; 16 | } 17 | 18 | @Override 19 | public String toString() { 20 | return name; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/unittest/util/Sha1HasherTest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.unittest.util; 2 | 3 | import com.braintreegateway.util.Sha1Hasher; 4 | 5 | import org.junit.jupiter.api.Test; 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | public class Sha1HasherTest { 9 | 10 | @Test 11 | public void hmacHash() { 12 | String actual = new Sha1Hasher().hmacHash("secretKey", "hello world"); 13 | assertEquals("d503d7a1a6adba1e6474e9ff2c4167f9dfdf4247", actual); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/OAuthRevokeAccessTokenRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class OAuthRevokeAccessTokenRequest extends Request { 4 | 5 | public String token; 6 | 7 | public OAuthRevokeAccessTokenRequest token(String token) { 8 | this.token = token; 9 | return this; 10 | } 11 | 12 | @Override 13 | public String toXML() { 14 | return new RequestBuilder("credentials") 15 | .addElement("token", token) 16 | .toXML(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/test/MerchantAccount.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.test; 2 | 3 | public class MerchantAccount { 4 | public static String Approve = "approve_me"; 5 | 6 | public static String InsufficientFundsContactUs = "insufficient_funds__contact"; 7 | public static String AccountNotAuthorizedContactUs = "account_not_authorized__contact"; 8 | public static String BankRejectedUpdateFundingInformation = "bank_rejected__update"; 9 | public static String BankRejectedNone = "bank_rejected__none"; 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/CustomerPager.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import java.util.List; 4 | 5 | public class CustomerPager implements Pager { 6 | private CustomerGateway gateway; 7 | private CustomerSearchRequest query; 8 | 9 | public CustomerPager(CustomerGateway gateway, CustomerSearchRequest query) { 10 | this.gateway = gateway; 11 | this.query = query; 12 | } 13 | 14 | public List getPage(List ids) { 15 | return gateway.fetchCustomers(query, ids); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/util/SignatureService.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.util; 2 | 3 | public class SignatureService { 4 | private final String key; 5 | private final Hasher hasher; 6 | 7 | public SignatureService(String key, Hasher hasher) { 8 | this.key = key; 9 | this.hasher = hasher; 10 | } 11 | 12 | public String sign(String query) { 13 | return hash(query) + "|" + query; 14 | } 15 | 16 | private String hash(String string) { 17 | return hasher.hmacHash(key, string); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/unittest/util/Sha256HasherTest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.unittest.util; 2 | 3 | import com.braintreegateway.util.Sha256Hasher; 4 | 5 | import org.junit.jupiter.api.Test; 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | public class Sha256HasherTest { 9 | 10 | @Test 11 | public void hmacHash() { 12 | String actual = new Sha256Hasher().hmacHash("secretKey", "hello world"); 13 | assertEquals("a31288ecf77d266463fc7e2a63799cb1ce6dcff156610373f722fa298e932340", actual); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/MultipleValueOrTextNode.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | public class MultipleValueOrTextNode extends TextNode { 7 | public MultipleValueOrTextNode(String nodeName, T parent) { 8 | super(nodeName, parent); 9 | } 10 | 11 | public T in(List items) { 12 | return assembleMultiValueCriteria(items); 13 | } 14 | 15 | public T in(S... items) { 16 | return in(Arrays.asList(items)); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/util/Experimental.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.util; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | /** 9 | * Marks a class, method, or field as experimental. 10 | * Experimental features may change at any time. 11 | */ 12 | @Retention(RetentionPolicy.RUNTIME) 13 | @Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD}) 14 | public @interface Experimental { 15 | String value() default ""; 16 | } -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/BankAccountInstantVerificationJwt.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | /** 4 | * Represents a Bank Account Instant Verification JWT. 5 | */ 6 | public class BankAccountInstantVerificationJwt { 7 | private final String jwt; 8 | 9 | public BankAccountInstantVerificationJwt(String jwt) { 10 | this.jwt = jwt; 11 | } 12 | 13 | /** 14 | * Returns the JWT for Bank Account Instant Verification. 15 | * 16 | * @return the JWT as a string 17 | */ 18 | public String getJwt() { 19 | return jwt; 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/TransactionPager.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import java.util.List; 4 | 5 | public class TransactionPager implements Pager { 6 | private TransactionGateway gateway; 7 | private TransactionSearchRequest query; 8 | 9 | public TransactionPager(TransactionGateway gateway, TransactionSearchRequest query) { 10 | this.gateway = gateway; 11 | this.query = query; 12 | } 13 | 14 | public List getPage(List ids) { 15 | return gateway.fetchTransactions(query, ids); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/AchMandate.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | import java.util.Calendar; 5 | 6 | public class AchMandate { 7 | 8 | private String text; 9 | private Calendar acceptedAt; 10 | 11 | public AchMandate(NodeWrapper node) { 12 | text = node.findString("text"); 13 | acceptedAt = node.findDate("accepted-at"); 14 | } 15 | 16 | public String getText() { 17 | return text; 18 | } 19 | 20 | public Calendar getAcceptedAt() { 21 | return acceptedAt; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/CustomActionsPaymentMethodField.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | 5 | public class CustomActionsPaymentMethodField { 6 | 7 | private String displayValue; 8 | private String name; 9 | 10 | public CustomActionsPaymentMethodField(NodeWrapper node) { 11 | name = node.findString("name"); 12 | displayValue = node.findString("display-value"); 13 | } 14 | 15 | public String getName() { 16 | return name; 17 | } 18 | 19 | public String getDisplayValue() { 20 | return displayValue; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/SubscriptionPager.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import java.util.List; 4 | 5 | public class SubscriptionPager implements Pager { 6 | private SubscriptionGateway gateway; 7 | private SubscriptionSearchRequest search; 8 | 9 | public SubscriptionPager(SubscriptionGateway gateway, SubscriptionSearchRequest search) { 10 | this.gateway = gateway; 11 | this.search = search; 12 | } 13 | 14 | public List getPage(List ids) { 15 | return gateway.fetchSubscriptions(search, ids); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/ExpiringCreditCardPager.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import java.util.List; 4 | 5 | public class ExpiringCreditCardPager implements Pager { 6 | 7 | private CreditCardGateway gateway; 8 | private String queryString; 9 | 10 | public ExpiringCreditCardPager(CreditCardGateway gateway, String queryString) { 11 | this.gateway = gateway; 12 | this.queryString = queryString; 13 | } 14 | 15 | public List getPage(List ids) { 16 | return gateway.fetchExpiringCreditCards(ids, queryString); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/TransactionDetails.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | import java.math.BigDecimal; 5 | 6 | public final class TransactionDetails { 7 | private final String id; 8 | private final BigDecimal amount; 9 | 10 | public TransactionDetails(NodeWrapper node) { 11 | id = node.findString("id"); 12 | amount = node.findBigDecimal("amount"); 13 | } 14 | 15 | public String getId() { 16 | return id; 17 | } 18 | 19 | public BigDecimal getAmount() { 20 | return amount; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/util/Crypto.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.util; 2 | 3 | public class Crypto { 4 | public Boolean secureCompare(String left, String right) { 5 | if (left == null || right == null || (left.length() != right.length())) { 6 | return false; 7 | } 8 | 9 | byte[] leftBytes = left.getBytes(); 10 | byte[] rightBytes = right.getBytes(); 11 | 12 | int result = 0; 13 | for (int i = 0; i < left.length(); i++) { 14 | result = result | leftBytes[i] ^ rightBytes[i]; 15 | } 16 | return result == 0; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/unittest/PaymentMethodDeleteRequestTest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.unittest; 2 | 3 | import com.braintreegateway.PaymentMethodDeleteRequest; 4 | import com.braintreegateway.testhelpers.TestHelper; 5 | 6 | import org.junit.jupiter.api.Test; 7 | 8 | public class PaymentMethodDeleteRequestTest { 9 | 10 | @Test 11 | public void toQueryStringIncludesRevokeAllGrants() { 12 | PaymentMethodDeleteRequest request = new PaymentMethodDeleteRequest().revokeAllGrants(true); 13 | TestHelper.assertIncludes("revoke_all_grants=true", request.toQueryString()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/RecipientPhone.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | 5 | public class RecipientPhone { 6 | private String countryCode; 7 | private String nationalNumber; 8 | 9 | public RecipientPhone(NodeWrapper node){ 10 | countryCode = node.findString("country-code"); 11 | nationalNumber = node.findString("national-number"); 12 | } 13 | 14 | public String getCountryCode(){ 15 | return countryCode; 16 | } 17 | 18 | public String getNationalNumber(){ 19 | return nationalNumber; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/LocalPaymentExpired.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | 5 | public class LocalPaymentExpired { 6 | private String paymentId; 7 | private String paymentContextId; 8 | 9 | public LocalPaymentExpired(NodeWrapper node) { 10 | this.paymentId = node.findString("payment-id"); 11 | this.paymentContextId = node.findString("payment-context-id"); 12 | } 13 | 14 | public String getPaymentId() { 15 | return paymentId; 16 | } 17 | 18 | public String getPaymentContextId() { 19 | return paymentContextId; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/MonetaryAmount.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import java.math.BigDecimal; 4 | import java.util.Map; 5 | import java.util.HashMap; 6 | 7 | public class MonetaryAmount { 8 | 9 | private BigDecimal value; 10 | 11 | private String currencyCode; 12 | 13 | public BigDecimal getValue() { 14 | return value; 15 | } 16 | 17 | public void setValue(BigDecimal value) { 18 | this.value = value; 19 | } 20 | 21 | public String getCurrencyCode() { 22 | return currencyCode; 23 | } 24 | 25 | public void setCurrencyCode(String currencyCode) { 26 | this.currencyCode = currencyCode; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/LiabilityShift.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import java.util.List; 4 | 5 | import com.braintreegateway.util.NodeWrapper; 6 | 7 | public class LiabilityShift { 8 | 9 | private String responsibleParty; 10 | private List conditions; 11 | 12 | public LiabilityShift(NodeWrapper node) { 13 | responsibleParty = node.findString("responsible-party"); 14 | conditions = node.findAllStrings("conditions"); 15 | } 16 | 17 | public String getResponsibleParty() { 18 | return responsibleParty; 19 | } 20 | 21 | public List getConditions() { 22 | return conditions; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/AccountUpdaterDailyReport.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | import java.util.Calendar; 5 | 6 | public final class AccountUpdaterDailyReport { 7 | private final String reportUrl; 8 | private final Calendar reportDate; 9 | 10 | public AccountUpdaterDailyReport(NodeWrapper node) { 11 | this.reportUrl = node.findString("report-url"); 12 | this.reportDate = node.findDate("report-date"); 13 | } 14 | 15 | public String getReportUrl() { 16 | return reportUrl; 17 | } 18 | 19 | public Calendar getReportDate() { 20 | return reportDate; 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/CreditCardVerificationPager.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import java.util.List; 4 | 5 | public class CreditCardVerificationPager implements Pager { 6 | private CreditCardVerificationGateway gateway; 7 | private CreditCardVerificationSearchRequest query; 8 | 9 | public CreditCardVerificationPager(CreditCardVerificationGateway gateway, CreditCardVerificationSearchRequest query) { 10 | this.gateway = gateway; 11 | this.query = query; 12 | } 13 | 14 | public List getPage(List ids) { 15 | return gateway.fetchCreditCardVerifications(query, ids); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/MerchantGateway.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.Http; 4 | import com.braintreegateway.util.NodeWrapper; 5 | 6 | public class MerchantGateway { 7 | 8 | private Http http; 9 | private Configuration configuration; 10 | 11 | public MerchantGateway(Http http, Configuration configuration) { 12 | this.http = http; 13 | this.configuration = configuration; 14 | } 15 | 16 | public Result create(MerchantRequest request) { 17 | NodeWrapper response = http.post("/merchants/create_via_api", request); 18 | return new Result(response, Merchant.class); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/integrationtest/ValidationErrorCodeIT.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.integrationtest; 2 | 3 | import com.braintreegateway.ValidationErrorCode; 4 | 5 | import org.junit.jupiter.api.Test; 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | public class ValidationErrorCodeIT { 9 | 10 | @Test 11 | public void findByCode() { 12 | assertEquals(ValidationErrorCode.ADDRESS_CANNOT_BE_BLANK, ValidationErrorCode.findByCode("81801")); 13 | } 14 | 15 | @Test 16 | public void findByCodeFallsBackWhenNotFound() { 17 | assertEquals(ValidationErrorCode.UNKNOWN_VALIDATION_ERROR, ValidationErrorCode.findByCode("-9999")); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/MultipleValueNode.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | public class MultipleValueNode extends SearchNode { 7 | public MultipleValueNode(String nodeName, T parent) { 8 | super(nodeName, parent); 9 | } 10 | 11 | public T in(List items) { 12 | return assembleMultiValueCriteria(items); 13 | } 14 | 15 | @SuppressWarnings("unchecked") 16 | public T in(S... items) { 17 | return in(Arrays.asList(items)); 18 | } 19 | 20 | @SuppressWarnings("unchecked") 21 | public T is(S item) { 22 | return in(item); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/OAuthAccessRevocation.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | 5 | public final class OAuthAccessRevocation { 6 | private final String merchantId; 7 | private final String oauthApplicationClientId; 8 | 9 | public OAuthAccessRevocation(NodeWrapper node) { 10 | this.merchantId = node.findString("merchant-id"); 11 | this.oauthApplicationClientId = node.findString("oauth-application-client-id"); 12 | } 13 | 14 | public String getMerchantId() { 15 | return merchantId; 16 | } 17 | 18 | public String getOauthApplicationClientId() { 19 | return oauthApplicationClientId; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/SettlementBatchSummary.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | public class SettlementBatchSummary { 9 | 10 | private List> records; 11 | 12 | public SettlementBatchSummary(NodeWrapper node) { 13 | records = new ArrayList>(); 14 | 15 | for (NodeWrapper record : node.findAll("records/record")) { 16 | records.add(record.findMap("*")); 17 | } 18 | } 19 | 20 | public List> getRecords() { 21 | return records; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/util/MapUtils.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.util; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class MapUtils { 7 | public static Map toMap(Object... args) { 8 | if (args.length % 2 == 1) { 9 | throw new RuntimeException("toMap must be called with an even number of parameters"); 10 | } 11 | HashMap map = new HashMap(); 12 | for (int i = 0; i < args.length; i += 2) { 13 | String key = String.valueOf(args[i]); 14 | Object value = args[i + 1]; 15 | map.put(key, value); 16 | } 17 | return map; 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/UsBankAccountVerificationPager.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import java.util.List; 4 | 5 | public class UsBankAccountVerificationPager implements Pager { 6 | private UsBankAccountVerificationGateway gateway; 7 | private UsBankAccountVerificationSearchRequest query; 8 | 9 | public UsBankAccountVerificationPager(UsBankAccountVerificationGateway gateway, UsBankAccountVerificationSearchRequest query) { 10 | this.gateway = gateway; 11 | this.query = query; 12 | } 13 | 14 | public List getPage(List ids) { 15 | return gateway.fetchUsBankAccountVerifications(query, ids); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/PaginatedResult.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import java.util.List; 4 | 5 | public class PaginatedResult { 6 | private int totalItems; 7 | private int pageSize; 8 | private List currentPage; 9 | 10 | public PaginatedResult(int totalItems, int pageSize, List currentPage) { 11 | this.totalItems = totalItems; 12 | this.pageSize = pageSize; 13 | this.currentPage = currentPage; 14 | } 15 | 16 | public int getTotalItems() { 17 | return totalItems; 18 | } 19 | 20 | public int getPageSize() { 21 | return pageSize; 22 | } 23 | 24 | public List getCurrentPage() { 25 | return currentPage; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # Summary 2 | 3 | # Checklist 4 | 5 | - [ ] Added changelog entry 6 | - [ ] Ran unit tests (`rake test:unit`) 7 | - [ ] I alphabetized all attributes, parameters, and methods by name in any class file I changed 8 | - [ ] I have linked the JIRA ticket in the summary section 9 | - [ ] I have reviewed the JIRA ticket to ensure all AC's are met 10 | - [ ] I understand that unless this is a Draft PR or has a DO NOT MERGE label, this PR is considered to be in a deploy ready state and can be deployed if merged to main 11 | 12 | 15 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/PaymentMethodDeleteRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class PaymentMethodDeleteRequest extends Request { 4 | private boolean revokeAllGrants; 5 | 6 | public PaymentMethodDeleteRequest() { 7 | } 8 | 9 | public PaymentMethodDeleteRequest revokeAllGrants(boolean revokeAllGrants) { 10 | this.revokeAllGrants = revokeAllGrants; 11 | return this; 12 | } 13 | 14 | @Override 15 | public String toQueryString() { 16 | return buildRequest().toQueryString(); 17 | } 18 | 19 | protected RequestBuilder buildRequest() { 20 | return new RequestBuilder("") 21 | .addTopLevelElement("revokeAllGrants", Boolean.toString(revokeAllGrants)); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/SubscriptionDetails.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | import java.util.Calendar; 5 | 6 | public class SubscriptionDetails { 7 | 8 | private Calendar billingPeriodEndDate; 9 | private Calendar billingPeriodStartDate; 10 | 11 | public SubscriptionDetails(NodeWrapper node) { 12 | billingPeriodEndDate = node.findDate("billing-period-end-date"); 13 | billingPeriodStartDate = node.findDate("billing-period-start-date"); 14 | } 15 | 16 | public Calendar getBillingPeriodEndDate() { 17 | return billingPeriodEndDate; 18 | } 19 | 20 | public Calendar getBillingPeriodStartDate() { 21 | return billingPeriodStartDate; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ### General information 4 | 5 | * SDK/Library version: 6 | * Environment: 7 | * Language, language version, and OS: 8 | 9 | ### Issue description 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/TransactionIndustryRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class TransactionIndustryRequest extends IndustryRequest { 4 | private TransactionRequest parent; 5 | 6 | public TransactionIndustryRequest(TransactionRequest parent) { 7 | this.parent = parent; 8 | } 9 | 10 | public TransactionIndustryRequest industryType(Transaction.IndustryType industryType) { 11 | super.industryType(industryType); 12 | return this; 13 | } 14 | 15 | public TransactionIndustryDataRequest data(String data) { 16 | super.data = new TransactionIndustryDataRequest(this); 17 | return super.data; 18 | } 19 | 20 | public TransactionRequest done() { 21 | return parent; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/AchReturnResponse.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | 5 | public class AchReturnResponse { 6 | 7 | private String createdAt; 8 | private String reasonCode; 9 | private String rejectReason; 10 | 11 | public AchReturnResponse(NodeWrapper node) { 12 | createdAt = node.findString("created-at"); 13 | reasonCode = node.findString("reason-code"); 14 | rejectReason = node.findString("reject-reason"); 15 | } 16 | 17 | public String getCreatedAt() { 18 | return createdAt; 19 | } 20 | 21 | public String getReasonCode() { 22 | return reasonCode; 23 | } 24 | 25 | public String getRejectReason() { 26 | return rejectReason; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/unittest/graphql/PhoneInputTest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.unittest.graphql; 2 | 3 | import java.util.Map; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import com.braintreegateway.graphql.inputs.PhoneInput; 9 | 10 | class PhoneInputTest { 11 | 12 | @Test 13 | void testToGraphQLVariables() { 14 | PhoneInput input = 15 | PhoneInput.builder().countryPhoneCode("1").phoneNumber("5555555555").extensionNumber("5555").build(); 16 | 17 | Map map = input.toGraphQLVariables(); 18 | 19 | assertEquals("1", map.get("countryPhoneCode")); 20 | assertEquals("5555555555", map.get("phoneNumber")); 21 | assertEquals("5555", map.get("extensionNumber")); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/unittest/util/CryptoTest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.unittest.util; 2 | 3 | import com.braintreegateway.util.Crypto; 4 | 5 | import org.junit.jupiter.api.Test; 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | 9 | public class CryptoTest { 10 | 11 | @Test 12 | public void secureCompareWithEqualStrings() { 13 | assertTrue(new Crypto().secureCompare("a_string", "a_string")); 14 | } 15 | 16 | @Test 17 | public void secureCompareWithNotEqualStrings() { 18 | assertFalse(new Crypto().secureCompare("a_string", "a_strong")); 19 | } 20 | 21 | @Test 22 | public void secureCompareWithLongerNotEqualStrings() { 23 | assertFalse(new Crypto().secureCompare("a_string", "a_string_that_is_longer")); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/integrationtest/GraphQLClientIT.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.integrationtest; 2 | 3 | import java.util.Map; 4 | 5 | import com.braintreegateway.Configuration; 6 | import com.braintreegateway.util.GraphQLClient; 7 | 8 | import org.junit.jupiter.api.Test; 9 | import static org.junit.jupiter.api.Assertions.*; 10 | 11 | public class GraphQLClientIT extends IntegrationTest { 12 | 13 | public String pingQuery = 14 | "query {" + 15 | " ping" + 16 | "}"; 17 | 18 | @Test 19 | public void smokeTestQueryWithoutVariables() { 20 | Configuration configuration = gateway.getConfiguration(); 21 | 22 | Map result = new GraphQLClient(configuration).query(pingQuery); 23 | assertNotNull(result); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/DisputePayPalMessage.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | import java.util.Calendar; 5 | 6 | public final class DisputePayPalMessage { 7 | 8 | private final String message; 9 | private final String sender; 10 | private final Calendar sentAt; 11 | 12 | public DisputePayPalMessage(NodeWrapper node) { 13 | message = node.findString("message"); 14 | sender = node.findString("sender"); 15 | sentAt = node.findDateTime("sent-at"); 16 | } 17 | 18 | public String getMessage() { 19 | return message; 20 | } 21 | 22 | public String getSender() { 23 | return sender; 24 | } 25 | 26 | public Calendar getSentAt() { 27 | return sentAt; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/DocumentUploadRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import java.io.File; 4 | 5 | public class DocumentUploadRequest extends Request { 6 | 7 | private DocumentUpload.Kind kind; 8 | private File file; 9 | 10 | public DocumentUploadRequest(DocumentUpload.Kind kind, File file) { 11 | if (kind == null) { 12 | throw new IllegalArgumentException("DocumentUpload.Kind must not be null"); 13 | } 14 | 15 | if (file == null) { 16 | throw new IllegalArgumentException("File must not be null"); 17 | } 18 | 19 | this.kind = kind; 20 | this.file = file; 21 | } 22 | 23 | public String getRequest() { 24 | return "{\"document_upload[kind]\": \"" + kind.toString() + "\"}"; 25 | } 26 | 27 | public File getFile() { 28 | return file; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/InternationalPhone.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | 5 | public class InternationalPhone { 6 | private String countryCode; 7 | private String nationalNumber; 8 | 9 | public InternationalPhone(NodeWrapper node) { 10 | countryCode = node.findString("country-code"); 11 | nationalNumber = node.findString("national-number"); 12 | } 13 | 14 | public InternationalPhone(String countryCode, String nationalNumber) { 15 | this.countryCode = countryCode; 16 | this.nationalNumber = nationalNumber; 17 | } 18 | 19 | public String getCountryCode() { 20 | return countryCode; 21 | } 22 | 23 | public String getNationalNumber() { 24 | return nationalNumber; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/unittest/graphql/PayPalPayeeInputTest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.unittest.graphql; 2 | 3 | import java.util.Map; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | import org.junit.jupiter.api.Test; 7 | 8 | import com.braintreegateway.graphql.inputs.PayPalPayeeInput; 9 | 10 | class PayPalPayeeInputTest { 11 | 12 | @Test 13 | void testToGraphQLVariables() { 14 | PayPalPayeeInput input = 15 | PayPalPayeeInput.builder() 16 | .clientId("client-id") 17 | .emailAddress("testEmail@paypal.com") 18 | .build(); 19 | 20 | Map map = input.toGraphQLVariables(); 21 | 22 | assertEquals("client-id", map.get("clientId")); 23 | assertEquals("testEmail@paypal.com", map.get("emailAddress")); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/TransactionDescriptorRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class TransactionDescriptorRequest extends DescriptorRequest { 4 | private TransactionRequest parent; 5 | 6 | public TransactionDescriptorRequest(TransactionRequest parent) { 7 | this.parent = parent; 8 | } 9 | 10 | public TransactionDescriptorRequest name(String name) { 11 | super.name(name); 12 | return this; 13 | } 14 | 15 | public TransactionDescriptorRequest phone(String phone) { 16 | super.phone(phone); 17 | return this; 18 | } 19 | 20 | public TransactionDescriptorRequest url(String url) { 21 | super.url(url); 22 | return this; 23 | } 24 | 25 | public TransactionRequest done() { 26 | return parent; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/DateRangeNode.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import java.util.Calendar; 4 | 5 | public class DateRangeNode extends SearchNode { 6 | 7 | public DateRangeNode(String nodeName, T parent) { 8 | super(nodeName, parent); 9 | } 10 | 11 | public T between(Calendar min, Calendar max) { 12 | greaterThanOrEqualTo(min); 13 | lessThanOrEqualTo(max); 14 | return parent; 15 | } 16 | 17 | public T greaterThanOrEqualTo(Calendar min) { 18 | parent.addRangeCriteria(nodeName, new SearchCriteria("min", min)); 19 | return parent; 20 | } 21 | 22 | public T lessThanOrEqualTo(Calendar max) { 23 | parent.addRangeCriteria(nodeName, new SearchCriteria("max", max)); 24 | return parent; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/DocumentUploadGateway.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.Http; 4 | import com.braintreegateway.util.NodeWrapper; 5 | 6 | public class DocumentUploadGateway { 7 | private final Http http; 8 | private final Configuration configuration; 9 | 10 | private final String BASE_URL = "/document_uploads"; 11 | 12 | public DocumentUploadGateway(Http http, Configuration configuration) { 13 | this.http = http; 14 | this.configuration = configuration; 15 | } 16 | 17 | public Result create(DocumentUploadRequest request) { 18 | final NodeWrapper response = http.postMultipart(configuration.getMerchantPath() + BASE_URL, request.getRequest(), request.getFile()); 19 | return new Result(response, DocumentUpload.class); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/SubscriptionDescriptorRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class SubscriptionDescriptorRequest extends DescriptorRequest { 4 | private SubscriptionRequest parent; 5 | 6 | public SubscriptionDescriptorRequest(SubscriptionRequest parent) { 7 | this.parent = parent; 8 | } 9 | 10 | public SubscriptionDescriptorRequest name(String name) { 11 | super.name(name); 12 | return this; 13 | } 14 | 15 | public SubscriptionDescriptorRequest phone(String phone) { 16 | super.phone(phone); 17 | return this; 18 | } 19 | 20 | public SubscriptionDescriptorRequest url(String url) { 21 | super.url(url); 22 | return this; 23 | } 24 | 25 | public SubscriptionRequest done() { 26 | return parent; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/ThreeDSecureLookup.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import java.util.Map; 4 | 5 | public class ThreeDSecureLookup { 6 | private final String acsUrl; 7 | private final String threeDSecureVersion; 8 | private final String transactionId; 9 | 10 | public ThreeDSecureLookup(Map lookupResponse) { 11 | acsUrl = lookupResponse.get("acsUrl"); 12 | threeDSecureVersion = lookupResponse.get("threeDSecureVersion"); 13 | transactionId = lookupResponse.get("transactionId"); 14 | } 15 | 16 | public String getAcsUrl() { 17 | return acsUrl; 18 | } 19 | 20 | public String getThreeDSecureVersion() { 21 | return threeDSecureVersion; 22 | } 23 | 24 | public String getTransactionId() { 25 | return transactionId; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/FacilitatedDetails.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | 5 | public final class FacilitatedDetails { 6 | private final String merchantId; 7 | private final String merchantName; 8 | private final String paymentMethodNonce; 9 | 10 | public FacilitatedDetails(NodeWrapper node) { 11 | merchantId = node.findString("merchant-id"); 12 | merchantName = node.findString("merchant-name"); 13 | paymentMethodNonce = node.findString("payment-method-nonce"); 14 | } 15 | 16 | public String getMerchantId() { 17 | return merchantId; 18 | } 19 | 20 | public String getMerchantName() { 21 | return merchantName; 22 | } 23 | 24 | public String getPaymentMethodNonce() { 25 | return paymentMethodNonce; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/UsBankAccountVerificationConfirmRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import java.util.List; 4 | 5 | public class UsBankAccountVerificationConfirmRequest extends Request { 6 | private List depositAmounts; 7 | 8 | public UsBankAccountVerificationConfirmRequest() { 9 | } 10 | 11 | public UsBankAccountVerificationConfirmRequest depositAmounts(List depositAmounts) { 12 | this.depositAmounts = depositAmounts; 13 | return this; 14 | } 15 | 16 | @Override 17 | public String toXML() { 18 | RequestBuilder builder = new RequestBuilder("usBankAccountVerification"); 19 | 20 | if (!depositAmounts.isEmpty()) { 21 | builder.addElement("depositAmounts", this.depositAmounts); 22 | } 23 | 24 | return builder.toXML(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | This project includes files from the commons-codec project (http://commons.apache.org/codec/) 2 | in the com/braintreegateway/org/apache/commons/codec directory: 3 | 4 | Apache Commons Codec 5 | Copyright 2002-2009 The Apache Software Foundation 6 | 7 | This product includes software developed by 8 | The Apache Software Foundation (http://www.apache.org/). 9 | 10 | -------------------------------------------------------------------------------- 11 | src/test/org/apache/commons/codec/language/DoubleMetaphoneTest.java contains 12 | test data from http://aspell.sourceforge.net/test/batch0.tab. 13 | 14 | Copyright (C) 2002 Kevin Atkinson (kevina@gnu.org). Verbatim copying 15 | and distribution of this entire article is permitted in any medium, 16 | provided this notice is preserved. 17 | -------------------------------------------------------------------------------- 18 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/AddOnGateway.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.Http; 4 | import com.braintreegateway.util.NodeWrapper; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | public class AddOnGateway { 9 | private Http http; 10 | private Configuration configuration; 11 | 12 | public AddOnGateway(Http http, Configuration configuration) { 13 | this.http = http; 14 | this.configuration = configuration; 15 | } 16 | 17 | public List all() { 18 | NodeWrapper node = http.get(configuration.getMerchantPath() + "/add_ons"); 19 | 20 | List addOns = new ArrayList(); 21 | 22 | for (NodeWrapper addOnResponse : node.findAll("add-on")) { 23 | addOns.add(new AddOn(addOnResponse)); 24 | } 25 | 26 | return addOns; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/PaymentMethodGrantRevokeRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class PaymentMethodGrantRevokeRequest extends Request { 4 | private String sharedPaymentMethodToken; 5 | 6 | public PaymentMethodGrantRevokeRequest() { 7 | } 8 | 9 | protected PaymentMethodGrantRevokeRequest sharedPaymentMethodToken(String sharedPaymentMethodToken) { 10 | this.sharedPaymentMethodToken = sharedPaymentMethodToken; 11 | return this; 12 | } 13 | 14 | @Override 15 | public String toXML() { 16 | return buildRequest("payment-method").toXML(); 17 | } 18 | 19 | protected RequestBuilder buildRequest(String root) { 20 | RequestBuilder builder = new RequestBuilder(root) 21 | .addElement("shared-payment-method-token", sharedPaymentMethodToken); 22 | 23 | return builder; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/PayPalAccountRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class PayPalAccountRequest extends Request { 4 | private String token; 5 | private PayPalAccountOptionsRequest optionsRequest; 6 | 7 | public PayPalAccountRequest token(String token) { 8 | this.token = token; 9 | return this; 10 | } 11 | 12 | public PayPalAccountOptionsRequest options() { 13 | this.optionsRequest = new PayPalAccountOptionsRequest(this); 14 | return optionsRequest; 15 | } 16 | 17 | @Override 18 | public String toXML() { 19 | return buildRequest("paypalAccount").toXML(); 20 | } 21 | 22 | protected RequestBuilder buildRequest(String root) { 23 | return new RequestBuilder(root) 24 | .addElement("options", optionsRequest) 25 | .addElement("token", token); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/MerchantAccountCreateForCurrencyRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class MerchantAccountCreateForCurrencyRequest extends Request { 4 | 5 | private String currency; 6 | private String id; 7 | 8 | public MerchantAccountCreateForCurrencyRequest currency(String currency) { 9 | this.currency = currency; 10 | return this; 11 | } 12 | 13 | public MerchantAccountCreateForCurrencyRequest id(String id) { 14 | this.id = id; 15 | return this; 16 | } 17 | 18 | @Override 19 | public String toXML() { 20 | return buildRequest("merchant_account").toXML(); 21 | } 22 | 23 | protected RequestBuilder buildRequest(String root) { 24 | return new RequestBuilder(root) 25 | .addElement("currency", currency) 26 | .addElement("id", id); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/Descriptor.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | 5 | /** 6 | * An address can belong to: 7 | *
    8 | *
  • a CreditCard as the billing address 9 | *
  • a Customer as an address 10 | *
  • a Transaction as a billing or shipping address 11 | *
12 | * 13 | */ 14 | public class Descriptor { 15 | 16 | private String name; 17 | private String phone; 18 | private String url; 19 | 20 | public Descriptor(NodeWrapper node) { 21 | name = node.findString("name"); 22 | phone = node.findString("phone"); 23 | url = node.findString("url"); 24 | } 25 | 26 | public String getName() { 27 | return name; 28 | } 29 | 30 | public String getPhone() { 31 | return phone; 32 | } 33 | 34 | public String getUrl() { 35 | return url; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/PayPalPaymentResourceGateway.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.PayPalPaymentResourceRequest; 4 | import com.braintreegateway.PaymentMethodNonce; 5 | import com.braintreegateway.util.Http; 6 | import com.braintreegateway.util.NodeWrapper; 7 | 8 | public class PayPalPaymentResourceGateway { 9 | private Http http; 10 | private Configuration configuration; 11 | 12 | public PayPalPaymentResourceGateway(Http http, Configuration configuration) { 13 | this.http = http; 14 | this.configuration = configuration; 15 | } 16 | 17 | public Result update(PayPalPaymentResourceRequest request) { 18 | NodeWrapper response = http.put(configuration.getMerchantPath() + "/paypal/payment_resource", request); 19 | return new Result(response, PaymentMethodNonce.class); 20 | } 21 | } -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/SepaDirectDebitAccountGateway.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.Http; 4 | 5 | public class SepaDirectDebitAccountGateway { 6 | private Http http; 7 | private Configuration configuration; 8 | 9 | public SepaDirectDebitAccountGateway(Http http, Configuration configuration) { 10 | this.http = http; 11 | this.configuration = configuration; 12 | } 13 | 14 | public SepaDirectDebitAccount find(String token) { 15 | return new SepaDirectDebitAccount(http.get(configuration.getMerchantPath() + "/payment_methods/sepa_debit_account/" + token)); 16 | } 17 | 18 | public Result delete(String token) { 19 | http.delete(configuration.getMerchantPath() + "/payment_methods/sepa_debit_account/" + token); 20 | return new Result(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/ThreeDSecureLookupInfo.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | import java.util.Map; 5 | 6 | public class ThreeDSecureLookupInfo { 7 | 8 | private String transStatus; 9 | private String transStatusReason; 10 | 11 | public ThreeDSecureLookupInfo(NodeWrapper node) { 12 | transStatus = node.findString("trans-status"); 13 | transStatusReason = node.findString("trans-status-reason"); 14 | } 15 | 16 | public ThreeDSecureLookupInfo(Map map) { 17 | transStatus = (String) map.get("transStatus"); 18 | transStatusReason = (String) map.get("transStatusReason"); 19 | } 20 | 21 | public String getTransStatus() { 22 | return transStatus; 23 | } 24 | 25 | public String getTransStatusReason() { 26 | return transStatusReason; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/DiscountGateway.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.Http; 4 | import com.braintreegateway.util.NodeWrapper; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | public class DiscountGateway { 9 | private Http http; 10 | private Configuration configuration; 11 | 12 | public DiscountGateway(Http http, Configuration configuration) { 13 | this.http = http; 14 | this.configuration = configuration; 15 | } 16 | 17 | public List all() { 18 | NodeWrapper node = http.get(configuration.getMerchantPath() + "/discounts"); 19 | 20 | List discounts = new ArrayList(); 21 | 22 | for (NodeWrapper discountResponse : node.findAll("discount")) { 23 | discounts.add(new Discount(discountResponse)); 24 | } 25 | 26 | return discounts; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/LocalPaymentFunded.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | 5 | public class LocalPaymentFunded { 6 | private String paymentId; 7 | private String paymentContextId; 8 | private Transaction transaction; 9 | 10 | public LocalPaymentFunded(NodeWrapper node) { 11 | this.paymentId = node.findString("payment-id"); 12 | this.paymentContextId = node.findString("payment-context-id"); 13 | 14 | NodeWrapper transactionNode = node.findFirst("transaction"); 15 | this.transaction = new Transaction(transactionNode); 16 | } 17 | 18 | public String getPaymentId() { 19 | return paymentId; 20 | } 21 | 22 | public Transaction getTransaction() { 23 | return transaction; 24 | } 25 | 26 | public String getPaymentContextId() { 27 | return paymentContextId; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/ThreeDSecureLookupResponse.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import java.util.Map; 4 | 5 | public class ThreeDSecureLookupResponse { 6 | private ThreeDSecureLookup lookup; 7 | private PaymentMethodNonce paymentMethod; 8 | private String payloadString; 9 | 10 | public ThreeDSecureLookupResponse(Map jsonResponse, String lookupResponse) { 11 | payloadString = lookupResponse; 12 | lookup = new ThreeDSecureLookup((Map) jsonResponse.get("lookup")); 13 | paymentMethod = new PaymentMethodNonce((Map) jsonResponse.get("paymentMethod")); 14 | } 15 | 16 | public ThreeDSecureLookup getLookup() { 17 | return lookup; 18 | } 19 | 20 | public PaymentMethodNonce getPaymentMethod() { 21 | return paymentMethod; 22 | } 23 | 24 | public String getPayloadString() { 25 | return payloadString; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/util/EnumUtils.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.util; 2 | 3 | public class EnumUtils { 4 | 5 | public static > T findByName(Class enumType, String name, T defaultValue) { 6 | if (name == null) { 7 | return null; 8 | } 9 | try { 10 | return Enum.valueOf(enumType, name.toUpperCase().replace(' ', '_')); 11 | } catch (IllegalArgumentException e) { 12 | return defaultValue; 13 | } 14 | } 15 | 16 | public static > T findByToString(T[] values, String name, T defaultValue) { 17 | if (name == null || values == null) { 18 | return defaultValue; 19 | } 20 | for (T value : values) { 21 | if (name.equals(value.toString())) { 22 | return value; 23 | } 24 | } 25 | return defaultValue; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/test/VenmoSdk.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.test; 2 | 3 | // NEXT_MAJOR_VERSION remove this class 4 | // The old venmo SDK integration has been deprecated 5 | @Deprecated 6 | public class VenmoSdk { 7 | public enum PaymentMethodCode { 8 | Visa("4111111111111111"), Invalid("invalid-payment-method-code"); 9 | 10 | public String code; 11 | 12 | private PaymentMethodCode(String number) { 13 | this.code = VenmoSdk.generateTestPaymentMethodCode(number); 14 | } 15 | } 16 | 17 | public static String generateTestPaymentMethodCode(String number) { 18 | return "stub-" + number; 19 | } 20 | 21 | public enum Session { 22 | Valid("stub-session"), Invalid("stub-invalid-session"); 23 | 24 | public String value; 25 | 26 | private Session(String validity) { 27 | this.value = validity; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/SepaDirectDebitAccountRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class SepaDirectDebitAccountRequest extends Request { 4 | private String token; 5 | private SepaDirectDebitAccountOptionsRequest optionsRequest; 6 | 7 | public SepaDirectDebitAccountRequest token(String token) { 8 | this.token = token; 9 | return this; 10 | } 11 | 12 | public SepaDirectDebitAccountOptionsRequest options() { 13 | this.optionsRequest = new SepaDirectDebitAccountOptionsRequest(this); 14 | return optionsRequest; 15 | } 16 | 17 | @Override 18 | public String toXML() { 19 | return buildRequest("sepaDebitAccount").toXML(); 20 | } 21 | 22 | protected RequestBuilder buildRequest(String root) { 23 | return new RequestBuilder(root) 24 | .addElement("options", optionsRequest) 25 | .addElement("token", token); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/SubscriptionOptionsPayPalRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class SubscriptionOptionsPayPalRequest extends Request { 4 | private SubscriptionOptionsRequest parent; 5 | private String description; 6 | 7 | public SubscriptionOptionsPayPalRequest(SubscriptionOptionsRequest parent) { 8 | this.parent = parent; 9 | } 10 | 11 | public SubscriptionOptionsRequest done() { 12 | return parent; 13 | } 14 | 15 | public SubscriptionOptionsPayPalRequest description(String description) { 16 | this.description = description; 17 | return this; 18 | } 19 | 20 | @Override 21 | public String toXML() { 22 | return buildRequest("paypal").toXML(); 23 | } 24 | 25 | protected RequestBuilder buildRequest(String root) { 26 | return new RequestBuilder(root) 27 | .addElement("description", description); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/unittest/ApplePayCardOptionsTest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.unittest; 2 | 3 | import java.io.IOException; 4 | 5 | import org.custommonkey.xmlunit.XMLAssert; 6 | import org.custommonkey.xmlunit.XMLUnit; 7 | import org.junit.jupiter.api.Test; 8 | import org.xml.sax.SAXException; 9 | 10 | import com.braintreegateway.ApplePayCardOptionsRequest; 11 | 12 | public class ApplePayCardOptionsTest { 13 | @Test 14 | public void toXmlIncludesAllElements() throws IOException, SAXException { 15 | ApplePayCardOptionsRequest request = new ApplePayCardOptionsRequest(). 16 | makeDefault(true); 17 | 18 | String expectedXML = 19 | " \n" 20 | + " true\n" 21 | + " \n"; 22 | 23 | XMLUnit.setIgnoreWhitespace(true); 24 | 25 | XMLAssert.assertXMLEqual(expectedXML, request.toXML()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/ExternalVaultCardRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class ExternalVaultCardRequest extends Request { 4 | private CreditCardRequest parent; 5 | private String networkTransactionId; 6 | 7 | public ExternalVaultCardRequest(CreditCardRequest parent) { 8 | this.parent = parent; 9 | } 10 | 11 | public ExternalVaultCardRequest networkTransactionId(String networkTransactionId) { 12 | this.networkTransactionId = networkTransactionId; 13 | return this; 14 | } 15 | 16 | public CreditCardRequest done(){ 17 | return parent; 18 | } 19 | 20 | @Override 21 | public String toXML() { 22 | return buildRequest("externalVault").toXML(); 23 | } 24 | 25 | protected RequestBuilder buildRequest(String root) { 26 | return new RequestBuilder(root) 27 | .addElement("networkTransactionId", networkTransactionId); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/unittest/AndroidPayCardOptionsTest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.unittest; 2 | 3 | import java.io.IOException; 4 | 5 | import org.custommonkey.xmlunit.XMLAssert; 6 | import org.custommonkey.xmlunit.XMLUnit; 7 | import org.junit.jupiter.api.Test; 8 | import org.xml.sax.SAXException; 9 | 10 | import com.braintreegateway.AndroidPayCardOptionsRequest; 11 | 12 | public class AndroidPayCardOptionsTest { 13 | @Test 14 | public void toXmlIncludesAllElements() throws IOException, SAXException { 15 | AndroidPayCardOptionsRequest request = new AndroidPayCardOptionsRequest(). 16 | makeDefault(true); 17 | 18 | String expectedXML = 19 | " \n" 20 | + " true\n" 21 | + " \n"; 22 | 23 | XMLUnit.setIgnoreWhitespace(true); 24 | 25 | XMLAssert.assertXMLEqual(expectedXML, request.toXML()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/resources/privateKey.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIICXAIBAAKBgQCrUO6cm5QqdJLLcMIygeIzyBUYl7iWiHqPy6fmxzj3SsFbTAY8 3 | tXT8C2jh3cWi0qNGXuxwSK6pClFwkPmW5znjCPbq9Ifa6mAU4+NoCzjTCAWxY3K1 4 | p6eW2s1gA82JBJF9/X4umdx9NbkOeoZWselJa7K0hztjOSBZXjXNfMYOiQIDAQAB 5 | AoGBAI0I/rdc+XiOKb9kH+u2s8NPZ9asKSF8T/ILhjleL46eM1p21veppxpMRlcT 6 | 3T2zTQmE4f96RpgRT4RtRZyu1R6zaSuVlmnKeD8BwEFgYaJUNBHyJuiG2f59gD5f 7 | S09NOXqvHQVMxUKYm9GZ3IG9TVQkpZlytXg8Y1SIHI9Cz8jRAkEA2CTGVWLuke/Z 8 | T+40+TSAbxOpXt7zyq1CO/jp7NsAy3MLIv3GHgxVzcK8tsAEyvPvRSnmMFdciZCx 9 | 5yTfFMHt1QJBAMroCmhLJWcwpjH5mO4kD/1eZNre1j5ZgGTt9fiIxo8Gns6kDLWX 10 | 7iLZ5sAdqle9KUm4BZKvnBtwFkBAwf9Pk+UCQBbdhRHBXoWXvwCCrZ3zXObjSJad 11 | tWKqg4g+o9iHroTXTcVM3WmOWoFi6X3XwGoL9jL15MEWbNastPVD5EmY3mUCQBj4 12 | Pzegb8ToHrutrJ05wOH8OMsaeyEHIJ7LDeb85fp55Rcm5w192edeC2B/BhRwCeGx 13 | jLYFeF+EBqj3jygdIeUCQGExaHBVu0nTHY9CnvJOjc2hs/I3TPwgXzm8rBisGm5W 14 | g0eJhfZ1uJ+oHaKhoTRgB6OOUVnpugx83vYvYiKj+1M= 15 | -----END RSA PRIVATE KEY----- 16 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/EnrichedCustomerData.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | public class EnrichedCustomerData { 8 | private List fieldsUpdated; 9 | private VenmoProfileData profileData; 10 | 11 | public EnrichedCustomerData(NodeWrapper node) { 12 | this.fieldsUpdated = new ArrayList(); 13 | for (NodeWrapper field : node.findAll("fields-updated/item")) { 14 | fieldsUpdated.add(field.findString(".")); 15 | } 16 | 17 | NodeWrapper venmoProfileDataNode = node.findFirst("profile-data"); 18 | this.profileData = new VenmoProfileData(venmoProfileDataNode); 19 | } 20 | 21 | public List getFieldsUpdated() { 22 | return fieldsUpdated; 23 | } 24 | 25 | public VenmoProfileData getProfileData() { 26 | return profileData; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/TransactionIndustryDataRequestTest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import org.junit.jupiter.api.Test; 4 | 5 | import static org.junit.jupiter.api.Assertions.assertEquals; 6 | 7 | class TransactionIndustryDataRequestTest { 8 | 9 | @Test 10 | void countryCode() { 11 | TransactionIndustryDataRequest transactionIndustryDataRequest = new TransactionIndustryDataRequest(null); 12 | String expectedXml = "US"; 13 | assertEquals(expectedXml, transactionIndustryDataRequest.countryCode("US").toXML()); 14 | } 15 | 16 | @Test 17 | void dateOfBirth() { 18 | TransactionIndustryDataRequest transactionIndustryDataRequest = new TransactionIndustryDataRequest(null); 19 | String expectedXml = "2012-12-12"; 20 | assertEquals(expectedXml, transactionIndustryDataRequest.dateOfBirth("2012-12-12").toXML()); 21 | } 22 | } -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/SearchCriteria.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import java.util.List; 4 | 5 | public class SearchCriteria extends Request { 6 | private String xml; 7 | 8 | public SearchCriteria(String type, Object value) { 9 | this.xml = buildXMLElement(type, value); 10 | } 11 | 12 | public SearchCriteria(List items) { 13 | StringBuilder builder = new StringBuilder(); 14 | for (Object item : items) { 15 | builder.append(buildXMLElement("item", item.toString())); 16 | } 17 | this.xml = builder.toString(); 18 | } 19 | 20 | @Override 21 | public String toXML() { 22 | return this.xml; 23 | } 24 | 25 | @Override 26 | public String toQueryString(String parent) { 27 | throw new UnsupportedOperationException(); 28 | } 29 | 30 | @Override 31 | public String toQueryString() { 32 | throw new UnsupportedOperationException(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/unittest/AndroidPayNetworkTokenOptionsTest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.unittest; 2 | 3 | import java.io.IOException; 4 | 5 | import org.custommonkey.xmlunit.XMLAssert; 6 | import org.custommonkey.xmlunit.XMLUnit; 7 | import org.junit.jupiter.api.Test; 8 | import org.xml.sax.SAXException; 9 | 10 | import com.braintreegateway.AndroidPayNetworkTokenOptionsRequest; 11 | 12 | public class AndroidPayNetworkTokenOptionsTest { 13 | @Test 14 | public void toXmlIncludesAllElements() throws IOException, SAXException { 15 | AndroidPayNetworkTokenOptionsRequest request = new AndroidPayNetworkTokenOptionsRequest(). 16 | makeDefault(true); 17 | 18 | String expectedXML = 19 | " \n" 20 | + " true\n" 21 | + " \n"; 22 | 23 | XMLUnit.setIgnoreWhitespace(true); 24 | 25 | XMLAssert.assertXMLEqual(expectedXML, request.toXML()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/SearchNode.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import java.util.List; 4 | 5 | public class SearchNode { 6 | protected String nodeName; 7 | protected T parent; 8 | 9 | public SearchNode(String nodeName, T parent) { 10 | this.nodeName = nodeName; 11 | this.parent = parent; 12 | } 13 | 14 | protected T assembleCriteria(String operation, String value) { 15 | this.parent.addCriteria(this.nodeName, new SearchCriteria(operation, defaultWithEmptyString(value))); 16 | return this.parent; 17 | } 18 | 19 | protected T assembleMultiValueCriteria(List items) { 20 | this.parent.addMultipleValueCriteria(this.nodeName, new SearchCriteria(items)); 21 | return this.parent; 22 | } 23 | 24 | private String defaultWithEmptyString(String value) { 25 | if (value == null) { 26 | return ""; 27 | } else { 28 | return value; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/ThreeDSecureAuthenticateInfo.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | import java.util.Map; 5 | 6 | // NEXT_MAJOR_VERSION rename this to ThreeDSecureAuthenticationInfo 7 | public class ThreeDSecureAuthenticateInfo { 8 | 9 | private String transStatus; 10 | private String transStatusReason; 11 | 12 | public ThreeDSecureAuthenticateInfo(NodeWrapper node) { 13 | transStatus = node.findString("trans-status"); 14 | transStatusReason = node.findString("trans-status-reason"); 15 | } 16 | 17 | public ThreeDSecureAuthenticateInfo(Map map) { 18 | transStatus = (String) map.get("transStatus"); 19 | transStatusReason = (String) map.get("transStatusReason"); 20 | } 21 | 22 | public String getTransStatus() { 23 | return transStatus; 24 | } 25 | 26 | public String getTransStatusReason() { 27 | return transStatusReason; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/FacilitatorDetails.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | 5 | public final class FacilitatorDetails { 6 | private final String oauthApplicationClientId; 7 | private final String oauthApplicationName; 8 | private final String sourcePaymentMethodToken; 9 | 10 | public FacilitatorDetails(NodeWrapper node) { 11 | oauthApplicationClientId = node.findString("oauth-application-client-id"); 12 | oauthApplicationName = node.findString("oauth-application-name"); 13 | sourcePaymentMethodToken = node.findString("source-payment-method-token"); 14 | } 15 | 16 | public String getOauthApplicationClientId() { 17 | return oauthApplicationClientId; 18 | } 19 | 20 | public String getOauthApplicationName() { 21 | return oauthApplicationName; 22 | } 23 | 24 | public String getSourcePaymentMethodToken() { 25 | return sourcePaymentMethodToken; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/ApplePayCardOptionsRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class ApplePayCardOptionsRequest extends Request { 4 | private Boolean makeDefault; 5 | private ApplePayCardRequest parent; 6 | 7 | public ApplePayCardOptionsRequest() {} 8 | 9 | public ApplePayCardOptionsRequest(ApplePayCardRequest parent) { 10 | this.parent = parent; 11 | } 12 | 13 | public ApplePayCardRequest done() { 14 | return parent; 15 | } 16 | 17 | public Boolean getMakeDefault() { 18 | return makeDefault; 19 | } 20 | 21 | public ApplePayCardOptionsRequest makeDefault(Boolean makeDefault) { 22 | this.makeDefault = makeDefault; 23 | return this; 24 | } 25 | 26 | @Override 27 | public String toXML() { 28 | return buildRequest("options").toXML(); 29 | } 30 | 31 | protected RequestBuilder buildRequest(String root) { 32 | return new RequestBuilder(root).addElement("makeDefault", makeDefault); 33 | } 34 | } -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/FileEvidenceRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | /** 4 | * Provides a fluent interface to build up requests around FileEvidence. 5 | */ 6 | public class FileEvidenceRequest extends Request { 7 | private String documentId; 8 | private String category; 9 | 10 | public FileEvidenceRequest documentId(String id) { 11 | this.documentId = id; 12 | return this; 13 | } 14 | 15 | public String getDocumentId() { 16 | return this.documentId; 17 | } 18 | 19 | public FileEvidenceRequest category(String category) { 20 | this.category = category; 21 | return this; 22 | } 23 | 24 | @Override 25 | public String toXML() { 26 | return buildRequest("evidence").toXML(); 27 | } 28 | 29 | protected RequestBuilder buildRequest(String root) { 30 | return new RequestBuilder(root) 31 | .addElement("document_upload_id", documentId) 32 | .addElement("category", category); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/CustomerOptionsRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class CustomerOptionsRequest extends Request { 4 | private CustomerRequest parent; 5 | private CustomerOptionsPayPalRequest customerOptionsPayPalRequest; 6 | 7 | public CustomerOptionsRequest() { 8 | 9 | } 10 | 11 | public CustomerOptionsRequest(CustomerRequest parent) { 12 | this.parent = parent; 13 | } 14 | 15 | public CustomerRequest done() { 16 | return parent; 17 | } 18 | 19 | public CustomerOptionsPayPalRequest paypal() { 20 | customerOptionsPayPalRequest = new CustomerOptionsPayPalRequest(this); 21 | return customerOptionsPayPalRequest; 22 | } 23 | 24 | @Override 25 | public String toXML() { 26 | return buildRequest("options").toXML(); 27 | } 28 | 29 | protected RequestBuilder buildRequest(String root) { 30 | return new RequestBuilder(root) 31 | .addElement("paypal", customerOptionsPayPalRequest); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/SubscriptionTransactionOptionsRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class SubscriptionTransactionOptionsRequest extends Request { 4 | private Boolean submitForSettlement; 5 | private SubscriptionTransactionRequest parent; 6 | 7 | public SubscriptionTransactionOptionsRequest(SubscriptionTransactionRequest parent) { 8 | this.parent = parent; 9 | } 10 | 11 | public SubscriptionTransactionRequest done() { 12 | return parent; 13 | } 14 | 15 | public SubscriptionTransactionOptionsRequest submitForSettlement(Boolean submitForSettlement) { 16 | this.submitForSettlement = submitForSettlement; 17 | return this; 18 | } 19 | 20 | @Override 21 | public String toXML() { 22 | return buildRequest("options").toXML(); 23 | } 24 | 25 | protected RequestBuilder buildRequest(String root) { 26 | return new RequestBuilder(root) 27 | .addElement("submitForSettlement", submitForSettlement); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/unittest/RiskDataCustomerRequestTest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.unittest; 2 | 3 | import java.io.IOException; 4 | 5 | import com.braintreegateway.RiskDataCustomerRequest; 6 | 7 | import org.custommonkey.xmlunit.XMLAssert; 8 | import org.custommonkey.xmlunit.XMLUnit; 9 | import org.xml.sax.SAXException; 10 | 11 | import org.junit.jupiter.api.Test; 12 | 13 | public class RiskDataCustomerRequestTest { 14 | @Test 15 | public void toXMLIncludesAllElements() throws IOException, SAXException { 16 | RiskDataCustomerRequest request = new RiskDataCustomerRequest() 17 | .customerIP("1234") 18 | .customerBrowser("Safari"); 19 | 20 | String expectedXML = "\n" 21 | + " 1234\n" 22 | + " Safari\n" 23 | + ""; 24 | 25 | XMLUnit.setIgnoreWhitespace(true); 26 | 27 | XMLAssert.assertXMLEqual(expectedXML, request.toXML()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/AndroidPayCardOptionsRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class AndroidPayCardOptionsRequest extends Request { 4 | private Boolean makeDefault; 5 | private AndroidPayCardRequest parent; 6 | 7 | public AndroidPayCardOptionsRequest() {} 8 | 9 | public AndroidPayCardOptionsRequest(AndroidPayCardRequest parent) { 10 | this.parent = parent; 11 | } 12 | 13 | public AndroidPayCardRequest done() { 14 | return parent; 15 | } 16 | 17 | public Boolean getMakeDefault() { 18 | return makeDefault; 19 | } 20 | 21 | public AndroidPayCardOptionsRequest makeDefault(Boolean makeDefault) { 22 | this.makeDefault = makeDefault; 23 | return this; 24 | } 25 | 26 | @Override 27 | public String toXML() { 28 | return buildRequest("options").toXML(); 29 | } 30 | 31 | protected RequestBuilder buildRequest(String root) { 32 | return new RequestBuilder(root).addElement("makeDefault", makeDefault); 33 | } 34 | } -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/UsBankAccountGateway.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.Http; 4 | 5 | public class UsBankAccountGateway { 6 | private BraintreeGateway gateway; 7 | private Http http; 8 | private Configuration configuration; 9 | 10 | public UsBankAccountGateway(BraintreeGateway gateway, Http http, Configuration configuration) { 11 | this.gateway = gateway; 12 | this.http = http; 13 | this.configuration = configuration; 14 | } 15 | 16 | public UsBankAccount find(String token) { 17 | return new UsBankAccount(http.get(configuration.getMerchantPath() + "/payment_methods/us_bank_account/" + token)); 18 | } 19 | 20 | public Result sale(String token, TransactionRequest transactionRequest) { 21 | transactionRequest 22 | .paymentMethodToken(token) 23 | .options() 24 | .submitForSettlement(true); 25 | return gateway.transaction().sale(transactionRequest); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/Request.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import java.util.Map; 4 | 5 | /** 6 | * Abstract class for fluent interface request builders. 7 | */ 8 | public abstract class Request { 9 | public String toXML() { 10 | throw new UnsupportedOperationException(); 11 | } 12 | 13 | public String toQueryString(String parent) { 14 | throw new UnsupportedOperationException(); 15 | } 16 | 17 | public String toQueryString() { 18 | throw new UnsupportedOperationException(); 19 | } 20 | 21 | public Map toGraphQLVariables() { 22 | throw new UnsupportedOperationException(); 23 | } 24 | 25 | public String getKind() { 26 | return null; 27 | } 28 | 29 | protected String buildXMLElement(Object element) { 30 | return RequestBuilder.buildXMLElement(element); 31 | } 32 | 33 | protected String buildXMLElement(String name, Object element) { 34 | return RequestBuilder.buildXMLElement(name, element); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/ConnectedMerchantPayPalStatusChanged.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | 5 | public final class ConnectedMerchantPayPalStatusChanged { 6 | private final String merchantPublicId; 7 | private final String oauthApplicationClientId; 8 | private final String action; 9 | 10 | public ConnectedMerchantPayPalStatusChanged(NodeWrapper node) { 11 | this.merchantPublicId = node.findString("merchant-public-id"); 12 | this.oauthApplicationClientId = node.findString("oauth-application-client-id"); 13 | this.action = node.findString("action"); 14 | } 15 | 16 | public String getMerchantPublicId() { 17 | return merchantPublicId; 18 | } 19 | 20 | public String getMerchantId() { 21 | return merchantPublicId; 22 | } 23 | 24 | public String getAction() { 25 | return action; 26 | } 27 | 28 | public String getOAuthApplicationClientId() { 29 | return oauthApplicationClientId; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/ConnectedMerchantStatusTransitioned.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | 5 | public final class ConnectedMerchantStatusTransitioned { 6 | private final String merchantPublicId; 7 | private final String oauthApplicationClientId; 8 | private final String status; 9 | 10 | public ConnectedMerchantStatusTransitioned(NodeWrapper node) { 11 | this.merchantPublicId = node.findString("merchant-public-id"); 12 | this.oauthApplicationClientId = node.findString("oauth-application-client-id"); 13 | this.status = node.findString("status"); 14 | } 15 | 16 | public String getMerchantPublicId() { 17 | return merchantPublicId; 18 | } 19 | 20 | public String getMerchantId() { 21 | return merchantPublicId; 22 | } 23 | 24 | public String getStatus() { 25 | return status; 26 | } 27 | 28 | public String getOAuthApplicationClientId() { 29 | return oauthApplicationClientId; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /DEVELOPMENT.md: -------------------------------------------------------------------------------- 1 | Development Notes 2 | ================= 3 | 4 | Notes for developing the Braintree Java SDK. 5 | 6 | ## Table of Contents 7 | 8 | * [Building](#building) 9 | * [Linting](#linting) 10 | * [Testing](#testing) 11 | 12 | ## Building 13 | 14 | The `Makefile` and `Dockerfile` will build an image containing the dependencies and drop you to a terminal where you can run tests. 15 | 16 | ``` 17 | make 18 | ``` 19 | 20 | ## Linting 21 | 22 | This project uses Checkstyle with the Google Java Style configuration. 23 | 24 | To run Checkstyle: 25 | 26 | ``` 27 | mvn site 28 | ``` 29 | 30 | View the results in the browser by visiting `file:///path/to/braintree-java/target/site/checkstyle.html`. 31 | 32 | ## Testing 33 | 34 | The unit tests can be run by anyone on any system, but the integration tests are meant to be run against a local development server of our gateway code. These integration tests are not meant for public consumption and will likely fail if run on your system. To run unit tests use rake(`rake test:unit`) or Maven(`mvn verify -DskipITs`). 35 | 36 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/PayPalAccountOptionsRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class PayPalAccountOptionsRequest extends Request { 4 | private Boolean makeDefault; 5 | private PayPalAccountRequest parent; 6 | 7 | public PayPalAccountOptionsRequest() { 8 | 9 | } 10 | 11 | public PayPalAccountOptionsRequest(PayPalAccountRequest parent) { 12 | this.parent = parent; 13 | } 14 | 15 | public PayPalAccountRequest done() { 16 | return parent; 17 | } 18 | 19 | public Boolean getMakeDefault() { 20 | return makeDefault; 21 | } 22 | 23 | public PayPalAccountOptionsRequest makeDefault(Boolean makeDefault) { 24 | this.makeDefault = makeDefault; 25 | return this; 26 | } 27 | 28 | @Override 29 | public String toXML() { 30 | return buildRequest("options").toXML(); 31 | } 32 | 33 | protected RequestBuilder buildRequest(String root) { 34 | return new RequestBuilder(root).addElement("makeDefault", makeDefault); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/unittest/OAuthAccessRevocationTest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.unittest; 2 | 3 | import com.braintreegateway.OAuthAccessRevocation; 4 | import com.braintreegateway.util.NodeWrapper; 5 | import com.braintreegateway.util.NodeWrapperFactory; 6 | 7 | import org.junit.jupiter.api.Test; 8 | import static org.junit.jupiter.api.Assertions.*; 9 | 10 | public class OAuthAccessRevocationTest { 11 | @Test 12 | public void assignsMerchantId() { 13 | String xmlPayload = "" + 14 | "abc123def" + 15 | "uvw789xyz" + 16 | ""; 17 | NodeWrapper node = NodeWrapperFactory.instance.create(xmlPayload); 18 | OAuthAccessRevocation revocation = new OAuthAccessRevocation(node); 19 | 20 | assertEquals(revocation.getMerchantId(), "abc123def"); 21 | assertEquals(revocation.getOauthApplicationClientId(), "uvw789xyz"); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/test/resources/certificate.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICsDCCAhmgAwIBAgIJALYNz+IiqwdkMA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNV 3 | BAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBX 4 | aWRnaXRzIFB0eSBMdGQwHhcNMDkxMjAyMjI1NTE3WhcNMTAxMjAyMjI1NTE3WjBF 5 | MQswCQYDVQQGEwJBVTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50 6 | ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB 7 | gQCrUO6cm5QqdJLLcMIygeIzyBUYl7iWiHqPy6fmxzj3SsFbTAY8tXT8C2jh3cWi 8 | 0qNGXuxwSK6pClFwkPmW5znjCPbq9Ifa6mAU4+NoCzjTCAWxY3K1p6eW2s1gA82J 9 | BJF9/X4umdx9NbkOeoZWselJa7K0hztjOSBZXjXNfMYOiQIDAQABo4GnMIGkMB0G 10 | A1UdDgQWBBRhqocfWHXEx0mT/IEFR1I5fqCHAjB1BgNVHSMEbjBsgBRhqocfWHXE 11 | x0mT/IEFR1I5fqCHAqFJpEcwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgTClNvbWUt 12 | U3RhdGUxITAfBgNVBAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZIIJALYNz+Ii 13 | qwdkMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADgYEAqeNLmBTdAGcdiTqS 14 | XfmLqbykyq1Qogg+J6s7uNhnP42tuvmHXrE0tC9cn8stbgYzTF4661f/AS97jOOn 15 | cL7c2kXzTzX+fiAd+dMHOckTBoTzRT95/YlphddJNvcdl2q/e2aWMg2VEnIqShJP 16 | jyWXlHrUWbOazZzroZwY9WviUdo= 17 | -----END CERTIFICATE----- 18 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/unittest/ThreeDSecureLookupTest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.unittest; 2 | 3 | import com.braintreegateway.ThreeDSecureLookup; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | import org.junit.jupiter.api.Test; 9 | import static org.junit.jupiter.api.Assertions.*; 10 | 11 | public class ThreeDSecureLookupTest { 12 | 13 | @Test 14 | public void setsPropertiesFromHash() { 15 | Map lookupResponse = new HashMap(); 16 | lookupResponse.put("acsUrl", "https://braintreepayments.com"); 17 | lookupResponse.put("threeDSecureVersion", "2.0"); 18 | lookupResponse.put("transactionId", "123-txn-id"); 19 | lookupResponse.put("unused", "value"); 20 | 21 | ThreeDSecureLookup lookup = new ThreeDSecureLookup(lookupResponse); 22 | 23 | assertEquals("https://braintreepayments.com", lookup.getAcsUrl()); 24 | assertEquals("2.0", lookup.getThreeDSecureVersion()); 25 | assertEquals("123-txn-id", lookup.getTransactionId()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/test/CreditCardNumbers.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.test; 2 | 3 | public class CreditCardNumbers { 4 | 5 | public enum CardTypeIndicators { 6 | Business("4229989800000003"), 7 | Commercial("4111111111131010"), 8 | Consumer("4229989700000004"), 9 | Corporate("4229989100000000"), 10 | CountryOfIssuance("4111111111121102"), 11 | Debit("4117101010101010"), 12 | DurbinRegulated("4111161010101010"), 13 | Healthcare("4111111510101010"), 14 | IssuingBank("4111111141010101"), 15 | Payroll("4111111114101010"), 16 | Prepaid("4111111111111210"), 17 | PrepaidReloadable("4229989900000002"), 18 | Purchase("4229989500000006"), 19 | No("4111111111310101"), 20 | Unknown("4111111111112101"); 21 | 22 | private final String value; 23 | 24 | public String getValue() { 25 | return value; 26 | } 27 | 28 | private CardTypeIndicators(String value) { 29 | this.value = value; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/integrationtest/UnknownPaymentMethodIT.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.integrationtest; 2 | 3 | import com.braintreegateway.*; 4 | import com.braintreegateway.util.NodeWrapper; 5 | import java.util.Collections; 6 | 7 | import static org.mockito.Mockito.mock; 8 | import static org.mockito.Mockito.when; 9 | 10 | import org.junit.jupiter.api.Test; 11 | import static org.junit.jupiter.api.Assertions.*; 12 | 13 | public class UnknownPaymentMethodIT extends IntegrationTest { 14 | 15 | @Test 16 | public void findReturnsNoSubscriptionsAssociatedWithUnknownPaymentMethod() { 17 | NodeWrapper wrapper = mock(NodeWrapper.class); 18 | UnknownPaymentMethod unknownPaymentMethod = new UnknownPaymentMethod(wrapper); 19 | 20 | PaymentMethodGateway gateway = mock(PaymentMethodGateway.class); 21 | when(gateway.find("token")).thenReturn(unknownPaymentMethod); 22 | 23 | PaymentMethod foundPaymentMethod = gateway.find("token"); 24 | assertEquals(foundPaymentMethod.getSubscriptions(), Collections.EMPTY_LIST); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/UnknownPaymentMethod.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | import java.util.Collections; 5 | import java.util.List; 6 | 7 | public class UnknownPaymentMethod implements PaymentMethod { 8 | private String token; 9 | private String customerId; 10 | private boolean isDefault; 11 | 12 | public UnknownPaymentMethod(NodeWrapper node) { 13 | token = node.findString("token"); 14 | customerId = node.findString("customer-id"); 15 | isDefault = node.findBoolean("default"); 16 | } 17 | 18 | public String getToken() { 19 | return token; 20 | } 21 | 22 | public boolean isDefault() { 23 | return isDefault; 24 | } 25 | 26 | public String getImageUrl() { 27 | return "https://assets.braintreegateway.com/payment_method_logo/unknown.png"; 28 | } 29 | 30 | public String getCustomerId() { 31 | return customerId; 32 | } 33 | 34 | public List getSubscriptions() { 35 | return Collections.EMPTY_LIST; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/AndroidPayNetworkTokenOptionsRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class AndroidPayNetworkTokenOptionsRequest extends Request { 4 | private Boolean makeDefault; 5 | private AndroidPayNetworkTokenRequest parent; 6 | 7 | public AndroidPayNetworkTokenOptionsRequest() {} 8 | 9 | public AndroidPayNetworkTokenOptionsRequest(AndroidPayNetworkTokenRequest parent) { 10 | this.parent = parent; 11 | } 12 | 13 | public AndroidPayNetworkTokenRequest done() { 14 | return parent; 15 | } 16 | 17 | public Boolean getMakeDefault() { 18 | return makeDefault; 19 | } 20 | 21 | public AndroidPayNetworkTokenOptionsRequest makeDefault(Boolean makeDefault) { 22 | this.makeDefault = makeDefault; 23 | return this; 24 | } 25 | 26 | @Override 27 | public String toXML() { 28 | return buildRequest("options").toXML(); 29 | } 30 | 31 | protected RequestBuilder buildRequest(String root) { 32 | return new RequestBuilder(root).addElement("makeDefault", makeDefault); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/SepaDirectDebitAccountOptionsRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class SepaDirectDebitAccountOptionsRequest extends Request { 4 | private Boolean makeDefault; 5 | private SepaDirectDebitAccountRequest parent; 6 | 7 | public SepaDirectDebitAccountOptionsRequest() {} 8 | 9 | public SepaDirectDebitAccountOptionsRequest(SepaDirectDebitAccountRequest parent) { 10 | this.parent = parent; 11 | } 12 | 13 | public SepaDirectDebitAccountRequest done() { 14 | return parent; 15 | } 16 | 17 | public Boolean getMakeDefault() { 18 | return makeDefault; 19 | } 20 | 21 | public SepaDirectDebitAccountOptionsRequest makeDefault(Boolean makeDefault) { 22 | this.makeDefault = makeDefault; 23 | return this; 24 | } 25 | 26 | @Override 27 | public String toXML() { 28 | return buildRequest("options").toXML(); 29 | } 30 | 31 | protected RequestBuilder buildRequest(String root) { 32 | return new RequestBuilder(root).addElement("makeDefault", makeDefault); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/unittest/FacilitatedDetailsTest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.unittest; 2 | 3 | import com.braintreegateway.FacilitatedDetails; 4 | import com.braintreegateway.util.SimpleNodeWrapper; 5 | 6 | import org.junit.jupiter.api.Test; 7 | import static org.junit.jupiter.api.Assertions.*; 8 | 9 | public class FacilitatedDetailsTest { 10 | @Test 11 | public void includesFields() { 12 | String nonce = "4004b83f-2559-0d79-2de0-c096d1ed9b92"; 13 | String xml = "" + 14 | "abc123" + 15 | "Cool Store" + 16 | "" + nonce + "" + 17 | ""; 18 | SimpleNodeWrapper node = SimpleNodeWrapper.parse(xml); 19 | 20 | FacilitatedDetails details = new FacilitatedDetails(node); 21 | 22 | assertEquals("abc123", details.getMerchantId()); 23 | assertEquals("Cool Store", details.getMerchantName()); 24 | assertEquals(nonce, details.getPaymentMethodNonce()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/graphql/inputs/MonetaryAmountInput.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.graphql.inputs; 2 | 3 | import java.math.BigDecimal; 4 | import java.util.Map; 5 | import java.util.HashMap; 6 | import com.braintreegateway.util.Experimental; 7 | 8 | @Experimental("This class is experimental and may change in future releases.") 9 | public class MonetaryAmountInput { 10 | 11 | private BigDecimal value; 12 | 13 | private String currencyCode; 14 | 15 | public BigDecimal getValue() { 16 | return value; 17 | } 18 | 19 | public void setValue(BigDecimal value) { 20 | this.value = value; 21 | } 22 | 23 | public String getCurrencyCode() { 24 | return currencyCode; 25 | } 26 | 27 | public void setCurrencyCode(String currencyCode) { 28 | this.currencyCode = currencyCode; 29 | } 30 | 31 | public Map toGraphQLVariables() { 32 | Map variables = new HashMap<>(); 33 | variables.put("value", value); 34 | if (currencyCode != null) { 35 | variables.put("currencyCode", currencyCode); 36 | } 37 | return variables; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/AuthenticationInsight.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | import java.util.Map; 5 | 6 | public class AuthenticationInsight { 7 | 8 | private String regulationEnvironment; 9 | private String scaIndicator; 10 | private String message; 11 | 12 | public AuthenticationInsight(NodeWrapper node) { 13 | regulationEnvironment = node.findString("regulation-environment"); 14 | scaIndicator = node.findString("sca-indicator"); 15 | message = node.findString("message"); 16 | } 17 | 18 | public AuthenticationInsight(Map map) { 19 | regulationEnvironment = (String) map.get("regulationEnvironment"); 20 | scaIndicator = (String) map.get("scaIndicator"); 21 | message = (String) map.get("message"); 22 | } 23 | 24 | public String getRegulationEnvironment() { 25 | return regulationEnvironment; 26 | } 27 | 28 | public String getScaIndicator() { 29 | return scaIndicator; 30 | } 31 | 32 | public String getMessage() { 33 | return message; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/unittest/CreditCardOptionsRequestTest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.unittest; 2 | 3 | import java.io.IOException; 4 | 5 | import org.custommonkey.xmlunit.XMLAssert; 6 | import org.custommonkey.xmlunit.XMLUnit; 7 | import org.junit.jupiter.api.Test; 8 | import org.xml.sax.SAXException; 9 | 10 | import com.braintreegateway.CreditCardRequest; 11 | import com.braintreegateway.CreditCardOptionsRequest; 12 | 13 | public class CreditCardOptionsRequestTest { 14 | @Test 15 | public void toXmlIncludesAccountInformationInquiry() throws IOException, SAXException { 16 | CreditCardRequest creditCardRequest = new CreditCardRequest(); 17 | CreditCardOptionsRequest request = new CreditCardOptionsRequest(creditCardRequest) 18 | .accountInformationInquiry("send_data"); 19 | 20 | String expectedXML = 21 | " \n" 22 | + " send_data\n" 23 | + " \n"; 24 | 25 | XMLUnit.setIgnoreWhitespace(true); 26 | 27 | XMLAssert.assertXMLEqual(expectedXML, request.toXML()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/IndustryRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public abstract class IndustryRequest extends Request { 4 | 5 | protected Transaction.IndustryType industryType; 6 | protected TransactionIndustryDataRequest data; 7 | 8 | public IndustryRequest() { 9 | super(); 10 | } 11 | 12 | public IndustryRequest industryType(Transaction.IndustryType industryType) { 13 | this.industryType = industryType; 14 | return this; 15 | } 16 | 17 | public TransactionIndustryDataRequest data() { 18 | this.data = new TransactionIndustryDataRequest(this); 19 | return data; 20 | } 21 | 22 | @Override 23 | public String toXML() { 24 | return buildRequest("industry").toXML(); 25 | } 26 | 27 | @Override 28 | public String toQueryString(String root) { 29 | return buildRequest(root).toQueryString(); 30 | } 31 | 32 | protected RequestBuilder buildRequest(String root) { 33 | return new RequestBuilder(root) 34 | .addElement("industryType", industryType) 35 | .addElement("data", data); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/graphql/types/PaymentOptions.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.graphql.types; 2 | 3 | import com.braintreegateway.graphql.enums.RecommendedPaymentOption; 4 | import com.braintreegateway.util.Experimental; 5 | 6 | /** 7 | * Represents the payment method and priority associated with a PayPal customer session. 8 | */ 9 | @Experimental("This class is experimental and may change in future releases.") 10 | public class PaymentOptions { 11 | 12 | private final RecommendedPaymentOption paymentOption; 13 | private final Integer recommendedPriority; 14 | 15 | public PaymentOptions(RecommendedPaymentOption paymentOption, Integer recommendedPriority) { 16 | this.paymentOption = paymentOption; 17 | this.recommendedPriority = recommendedPriority; 18 | } 19 | 20 | /** 21 | * 22 | * @return The payment option type. 23 | */ 24 | public RecommendedPaymentOption getPaymentOption() { 25 | return paymentOption; 26 | } 27 | 28 | /** 29 | * 30 | * @return Recommended priority of the payment option. 31 | */ 32 | public Integer getRecommendedPriority() { 33 | return recommendedPriority; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/InstallmentRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class InstallmentRequest extends Request { 4 | private Integer count; 5 | private 6 | TransactionRequest parent; 7 | 8 | public InstallmentRequest(TransactionRequest txnRequest) { 9 | this.parent = txnRequest; 10 | } 11 | 12 | public TransactionRequest done() { 13 | return parent; 14 | } 15 | 16 | @Override 17 | public String toXML() { 18 | return buildRequest("installments").toXML(); 19 | } 20 | 21 | @Override 22 | public String toQueryString() { 23 | return toQueryString("installments"); 24 | } 25 | 26 | @Override 27 | public String toQueryString(String root) { 28 | return buildRequest(root) 29 | .addTopLevelElement("count", count.toString()) 30 | .toQueryString(); 31 | } 32 | 33 | public InstallmentRequest count(Integer count) { 34 | this.count = count; 35 | return this; 36 | } 37 | 38 | protected RequestBuilder buildRequest(String root) { 39 | RequestBuilder builder = new RequestBuilder(root) 40 | .addElement("count", count); 41 | 42 | return builder; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/OAuthCredentials.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | import java.util.Calendar; 5 | 6 | public class OAuthCredentials { 7 | 8 | private String accessToken; 9 | private String refreshToken; 10 | private String tokenType; 11 | private String scope; 12 | private Calendar expiresAt; 13 | 14 | public OAuthCredentials(NodeWrapper node) { 15 | accessToken = node.findString("access-token"); 16 | refreshToken = node.findString("refresh-token"); 17 | tokenType = node.findString("token-type"); 18 | scope = node.findString("scope"); 19 | expiresAt = node.findDateTime("expires-at"); 20 | } 21 | 22 | public String getAccessToken() { 23 | return accessToken; 24 | } 25 | 26 | public String getRefreshToken() { 27 | return refreshToken; 28 | } 29 | 30 | public String getTokenType() { 31 | return tokenType; 32 | } 33 | 34 | public String getScope() { 35 | return scope; 36 | } 37 | 38 | public Calendar getExpiresAt() { 39 | return expiresAt; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/unittest/PaymentMethodOptionsRequestTest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.unittest; 2 | 3 | import java.io.IOException; 4 | 5 | import org.custommonkey.xmlunit.XMLAssert; 6 | import org.custommonkey.xmlunit.XMLUnit; 7 | import org.junit.jupiter.api.Test; 8 | import org.xml.sax.SAXException; 9 | 10 | import com.braintreegateway.PaymentMethodRequest; 11 | import com.braintreegateway.PaymentMethodOptionsRequest; 12 | 13 | public class PaymentMethodOptionsRequestTest { 14 | @Test 15 | public void toXmlIncludesAccountInformationInquiry() throws IOException, SAXException { 16 | PaymentMethodRequest paymentMethodRequest = new PaymentMethodRequest(); 17 | PaymentMethodOptionsRequest request = new PaymentMethodOptionsRequest() 18 | .accountInformationInquiry("send_data"); 19 | 20 | String expectedXML = 21 | " \n" 22 | + " send_data\n" 23 | + " \n"; 24 | 25 | XMLUnit.setIgnoreWhitespace(true); 26 | 27 | XMLAssert.assertXMLEqual(expectedXML, request.toXML()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/ExchangeRateQuoteRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | public class ExchangeRateQuoteRequest extends Request { 9 | 10 | private List quotes = new ArrayList<>(); 11 | 12 | public ExchangeRateQuoteInput addExchangeRateQuoteInput() { 13 | ExchangeRateQuoteInput newInput = new ExchangeRateQuoteInput(this); 14 | quotes.add(newInput); 15 | return newInput; 16 | } 17 | 18 | @Override 19 | public Map toGraphQLVariables() { 20 | 21 | Map variables = new HashMap<>(); 22 | Map input = new HashMap<>(); 23 | 24 | List> quotesList = new ArrayList<>(); 25 | 26 | for (ExchangeRateQuoteInput quote : this.quotes) { 27 | quotesList.add(quote.toGraphQLVariables()); 28 | } 29 | 30 | input.put("quotes", quotesList.toArray()); 31 | variables.put("exchangeRateQuoteRequest", input); 32 | 33 | return variables; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/RevokedPaymentMethodMetadata.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.exceptions.UnexpectedException; 4 | import com.braintreegateway.util.NodeWrapper; 5 | import com.braintreegateway.util.PaymentMethodParser; 6 | 7 | public class RevokedPaymentMethodMetadata { 8 | private String customerId; 9 | private String token; 10 | private PaymentMethod revokedPaymentMethod; 11 | 12 | public RevokedPaymentMethodMetadata(NodeWrapper node) { 13 | if (node.getChildren().size() == 0) { 14 | throw new UnexpectedException("Couldn't parse webhook"); 15 | } 16 | 17 | revokedPaymentMethod = PaymentMethodParser.parsePaymentMethod(node.getChildren().get(0)).getTarget(); 18 | customerId = revokedPaymentMethod.getCustomerId(); 19 | token = revokedPaymentMethod.getToken(); 20 | } 21 | 22 | public String getToken() { 23 | return token; 24 | } 25 | 26 | public String getCustomerId() { 27 | return customerId; 28 | } 29 | 30 | public PaymentMethod getRevokedPaymentMethod() { 31 | return revokedPaymentMethod; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/TransactionOptionsVenmoRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class TransactionOptionsVenmoRequest extends Request { 4 | private TransactionOptionsRequest parent; 5 | private String profileId; 6 | 7 | public TransactionOptionsVenmoRequest(TransactionOptionsRequest parent) { 8 | this.parent = parent; 9 | } 10 | 11 | public TransactionOptionsRequest done() { 12 | return parent; 13 | } 14 | 15 | public TransactionOptionsVenmoRequest profileId(String profileId) { 16 | this.profileId = profileId; 17 | return this; 18 | } 19 | 20 | @Override 21 | public String toXML() { 22 | return buildRequest("venmo").toXML(); 23 | } 24 | 25 | @Override 26 | public String toQueryString() { 27 | return toQueryString("venmo"); 28 | } 29 | 30 | @Override 31 | public String toQueryString(String root) { 32 | return buildRequest(root).toQueryString(); 33 | } 34 | 35 | protected RequestBuilder buildRequest(String root) { 36 | return new RequestBuilder(root) 37 | .addElement("profile-id", profileId); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/graphql/types/PaymentRecommendation.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.graphql.types; 2 | 3 | import com.braintreegateway.graphql.enums.RecommendedPaymentOption; 4 | import com.braintreegateway.util.Experimental; 5 | 6 | /** 7 | * Represents the payment method and priority associated with a PayPal customer session. 8 | */ 9 | @Experimental("This class is experimental and may change in future releases.") 10 | public class PaymentRecommendation { 11 | 12 | private final RecommendedPaymentOption paymentOption; 13 | private final Integer recommendedPriority; 14 | 15 | public PaymentRecommendation(RecommendedPaymentOption paymentOption, Integer recommendedPriority) { 16 | this.paymentOption = paymentOption; 17 | this.recommendedPriority = recommendedPriority; 18 | } 19 | 20 | /** 21 | * 22 | * @return The payment option type. 23 | */ 24 | public RecommendedPaymentOption getPaymentOption() { 25 | return paymentOption; 26 | } 27 | 28 | /** 29 | * 30 | * @return Recommended priority of the payment option. 31 | */ 32 | public Integer getRecommendedPriority() { 33 | return recommendedPriority; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | (The MIT License) 2 | 3 | Copyright (c) 2009-2017 Braintree, a division of PayPal, Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person 6 | obtaining a copy of this software and associated documentation 7 | files (the "Software"), to deal in the Software without 8 | restriction, including without limitation the rights to use, 9 | copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the 11 | Software is furnished to do so, subject to the following 12 | conditions: 13 | 14 | The above copyright notice and this permission notice shall be 15 | included in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | OTHER DEALINGS IN THE SOFTWARE. 25 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/VenmoAccountDetails.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | 5 | public class VenmoAccountDetails { 6 | 7 | private String token; 8 | private String username; 9 | private String venmoUserId; 10 | private String imageUrl; 11 | private String sourceDescription; 12 | 13 | public VenmoAccountDetails(NodeWrapper node) { 14 | this.token = node.findString("token"); 15 | this.username = node.findString("username"); 16 | this.venmoUserId = node.findString("venmo-user-id"); 17 | this.imageUrl = node.findString("image-url"); 18 | this.sourceDescription = node.findString("source-description"); 19 | } 20 | 21 | public String getToken() { 22 | return token; 23 | } 24 | 25 | public String getUsername() { 26 | return username; 27 | } 28 | 29 | public String getVenmoUserId() { 30 | return venmoUserId; 31 | } 32 | 33 | public String getImageUrl() { 34 | return imageUrl; 35 | } 36 | 37 | public String getSourceDescription() { 38 | return sourceDescription; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/unittest/TransactionSearchRequestTest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.unittest; 2 | 3 | import com.braintreegateway.TransactionSearchRequest; 4 | import com.braintreegateway.CreditCard; 5 | import org.junit.jupiter.api.Test; 6 | import static org.junit.jupiter.api.Assertions.*; 7 | 8 | public class TransactionSearchRequestTest { 9 | 10 | @Test 11 | public void sepaDirectPayPalV2OrderIdTest() { 12 | TransactionSearchRequest transactionSearchRequest = new TransactionSearchRequest(); 13 | 14 | String expectedXml = "hello"; 15 | assertEquals(expectedXml, transactionSearchRequest.sepaDirectDebitPayPalV2OrderId().is("hello").toXML()); 16 | } 17 | 18 | @Test 19 | public void debitNetworkTest() { 20 | TransactionSearchRequest transactionSearchRequest = new TransactionSearchRequest(); 21 | String expectedXml = "STAR"; 22 | assertEquals(expectedXml, transactionSearchRequest.debitNetwork().is(CreditCard.DebitNetwork.STAR).toXML()); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/PayPalAccountGateway.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.Http; 4 | import com.braintreegateway.util.NodeWrapper; 5 | 6 | public class PayPalAccountGateway { 7 | private Http http; 8 | private Configuration configuration; 9 | 10 | public PayPalAccountGateway(Http http, Configuration configuration) { 11 | this.http = http; 12 | this.configuration = configuration; 13 | } 14 | 15 | public PayPalAccount find(String token) { 16 | return new PayPalAccount(http.get(configuration.getMerchantPath() + "/payment_methods/paypal_account/" + token)); 17 | } 18 | 19 | public Result delete(String token) { 20 | http.delete(configuration.getMerchantPath() + "/payment_methods/paypal_account/" + token); 21 | return new Result(); 22 | } 23 | 24 | public Result update(String token, PayPalAccountRequest request) { 25 | NodeWrapper response = http.put(configuration.getMerchantPath() + "/payment_methods/paypal_account/" + token, request); 26 | return new Result(response, PayPalAccount.class); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/OAuthCredentialsRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class OAuthCredentialsRequest extends Request { 4 | 5 | public String code; 6 | public String scope; 7 | public String grantType; 8 | public String refreshToken; 9 | 10 | public OAuthCredentialsRequest code(String code) { 11 | this.code = code; 12 | return this; 13 | } 14 | 15 | public OAuthCredentialsRequest scope(String scope) { 16 | this.scope = scope; 17 | return this; 18 | } 19 | 20 | public OAuthCredentialsRequest grantType(String grantType) { 21 | this.grantType = grantType; 22 | return this; 23 | } 24 | 25 | public OAuthCredentialsRequest refreshToken(String refreshToken) { 26 | this.refreshToken = refreshToken; 27 | return this; 28 | } 29 | 30 | @Override 31 | public String toXML() { 32 | return new RequestBuilder("credentials") 33 | .addElement("code", code) 34 | .addElement("refreshToken", refreshToken) 35 | .addElement("scope", scope) 36 | .addElement("grantType", grantType) 37 | .toXML(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/CustomerInternationalPhoneRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class CustomerInternationalPhoneRequest extends Request { 4 | private CustomerRequest parent; 5 | private String countryCode; 6 | private String nationalNumber; 7 | 8 | public CustomerInternationalPhoneRequest(CustomerRequest parent) { 9 | this.parent = parent; 10 | } 11 | 12 | public CustomerRequest done() { 13 | return parent; 14 | } 15 | 16 | public CustomerInternationalPhoneRequest countryCode(String countryCode) { 17 | this.countryCode = countryCode; 18 | return this; 19 | } 20 | 21 | public CustomerInternationalPhoneRequest nationalNumber(String nationalNumber) { 22 | this.nationalNumber = nationalNumber; 23 | return this; 24 | } 25 | 26 | @Override 27 | public String toXML() { 28 | return buildRequest("internationalPhone").toXML(); 29 | } 30 | 31 | protected RequestBuilder buildRequest(String root) { 32 | return new RequestBuilder(root) 33 | .addElement("countryCode", countryCode) 34 | .addElement("nationalNumber", nationalNumber); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/DescriptorRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public abstract class DescriptorRequest extends Request { 4 | 5 | protected String name; 6 | protected String phone; 7 | protected String url; 8 | 9 | public DescriptorRequest() { 10 | super(); 11 | } 12 | 13 | public DescriptorRequest name(String name) { 14 | this.name = name; 15 | return this; 16 | } 17 | 18 | public DescriptorRequest phone(String phone) { 19 | this.phone = phone; 20 | return this; 21 | } 22 | 23 | public DescriptorRequest url(String url) { 24 | this.url = url; 25 | return this; 26 | } 27 | 28 | @Override 29 | public String toXML() { 30 | return buildRequest("descriptor").toXML(); 31 | } 32 | 33 | @Override 34 | public String toQueryString(String root) { 35 | return buildRequest(root).toQueryString(); 36 | } 37 | 38 | protected RequestBuilder buildRequest(String root) { 39 | return new RequestBuilder(root) 40 | .addElement("name", name) 41 | .addElement("phone", phone) 42 | .addElement("url", url); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/TransactionOptionsThreeDSecureRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class TransactionOptionsThreeDSecureRequest extends Request { 4 | private TransactionOptionsRequest parent; 5 | private boolean required; 6 | 7 | public TransactionOptionsThreeDSecureRequest(TransactionOptionsRequest parent) { 8 | this.parent = parent; 9 | } 10 | 11 | public TransactionOptionsRequest done() { 12 | return parent; 13 | } 14 | 15 | public TransactionOptionsThreeDSecureRequest required(boolean required) { 16 | this.required = required; 17 | return this; 18 | } 19 | 20 | @Override 21 | public String toXML() { 22 | return buildRequest("three-d-secure").toXML(); 23 | } 24 | 25 | @Override 26 | public String toQueryString() { 27 | return toQueryString("three-d-secure"); 28 | } 29 | 30 | @Override 31 | public String toQueryString(String root) { 32 | return buildRequest(root).toQueryString(); 33 | } 34 | 35 | protected RequestBuilder buildRequest(String root) { 36 | return new RequestBuilder(root) 37 | .addElement("required", required); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/TransactionLevelFeeReportRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.Calendar; 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | /** 9 | * Provides a fluent interface to build up requests around Transaction-Level Fee Reports. 10 | */ 11 | public class TransactionLevelFeeReportRequest extends Request { 12 | private String date; 13 | private String merchantAccountId; 14 | 15 | public TransactionLevelFeeReportRequest date(Calendar date) { 16 | this.date = new SimpleDateFormat("yyyy-MM-dd").format(date.getTime()); 17 | return this; 18 | } 19 | 20 | public TransactionLevelFeeReportRequest merchantAccountId(String merchantAccountId) { 21 | this.merchantAccountId = merchantAccountId; 22 | return this; 23 | } 24 | 25 | @Override 26 | public Map toGraphQLVariables() { 27 | Map variables = new HashMap(); 28 | 29 | variables.put("date", date); 30 | if (merchantAccountId != null) { 31 | variables.put("merchantAccountId", merchantAccountId); 32 | } 33 | 34 | return variables; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/TransactionOptionsCloneRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class TransactionOptionsCloneRequest extends Request { 4 | private TransactionCloneRequest parent; 5 | private Boolean submitForSettlement; 6 | 7 | public TransactionOptionsCloneRequest(TransactionCloneRequest parent) { 8 | this.parent = parent; 9 | } 10 | 11 | public TransactionOptionsCloneRequest submitForSettlement(Boolean submitForSettlement) { 12 | this.submitForSettlement = submitForSettlement; 13 | return this; 14 | } 15 | 16 | public TransactionCloneRequest done() { 17 | return parent; 18 | } 19 | 20 | @Override 21 | public String toXML() { 22 | return buildRequest("options").toXML(); 23 | } 24 | 25 | @Override 26 | public String toQueryString() { 27 | return toQueryString("options"); 28 | } 29 | 30 | @Override 31 | public String toQueryString(String root) { 32 | return buildRequest(root).toQueryString(); 33 | } 34 | 35 | protected RequestBuilder buildRequest(String root) { 36 | return new RequestBuilder(root).addElement("submitForSettlement", submitForSettlement); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/CreditCardAddressOptionsRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class CreditCardAddressOptionsRequest extends Request { 4 | 5 | private CreditCardAddressRequest parent; 6 | private Boolean updateExisting; 7 | 8 | public CreditCardAddressOptionsRequest(CreditCardAddressRequest parent) { 9 | this.parent = parent; 10 | } 11 | 12 | public CreditCardAddressRequest done() { 13 | return parent; 14 | } 15 | 16 | public CreditCardAddressOptionsRequest updateExisting(Boolean updateExisting) { 17 | this.updateExisting = updateExisting; 18 | return this; 19 | } 20 | 21 | @Override 22 | public String toQueryString() { 23 | return toQueryString("options"); 24 | } 25 | 26 | @Override 27 | public String toQueryString(String root) { 28 | return buildRequest(root).toQueryString(); 29 | } 30 | 31 | @Override 32 | public String toXML() { 33 | return buildRequest("options").toXML(); 34 | } 35 | 36 | protected RequestBuilder buildRequest(String root) { 37 | return new RequestBuilder(root) 38 | .addElement("updateExisting", updateExisting); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/PaymentInstrumentType.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public final class PaymentInstrumentType { 4 | public static final String AMEX_EXPRESS_CHECKOUT_CARD = "amex_express_checkout_card"; 5 | public static final String ANDROID_PAY_CARD = "android_pay_card"; 6 | public static final String APPLE_PAY_CARD = "apple_pay_card"; 7 | public static final String CREDIT_CARD = "credit_card"; 8 | public static final String LOCAL_PAYMENT = "local_payment"; 9 | public static final String MASTERPASS_CARD = "masterpass_card"; 10 | public static final String META_CHECKOUT_CARD = "meta_checkout_card"; 11 | public static final String META_CHECKOUT_TOKEN = "meta_checkout_token"; 12 | public static final String PAYPAL_ACCOUNT = "paypal_account"; 13 | public static final String PAYPAL_HERE = "paypal_here"; 14 | public static final String SAMSUNG_PAY_CARD = "samsung_pay_card"; 15 | public static final String SEPA_DIRECT_DEBIT_ACCOUNT = "sepa_debit_account"; 16 | public static final String US_BANK_ACCOUNT = "us_bank_account"; 17 | public static final String VENMO_ACCOUNT = "venmo_account"; 18 | public static final String VISA_CHECKOUT_CARD = "visa_checkout_card"; 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/DisputeStatusHistory.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.Dispute.Status; 4 | import com.braintreegateway.util.EnumUtils; 5 | import com.braintreegateway.util.NodeWrapper; 6 | import java.util.Calendar; 7 | 8 | public final class DisputeStatusHistory { 9 | 10 | private final Calendar disbursementDate; 11 | private final Calendar effectiveDate; 12 | private final Calendar timestamp; 13 | private final Dispute.Status status; 14 | 15 | public DisputeStatusHistory(NodeWrapper node) { 16 | disbursementDate = node.findDate("disbursement-date"); 17 | effectiveDate = node.findDate("effective-date"); 18 | timestamp = node.findDateTime("timestamp"); 19 | status = EnumUtils.findByName(Dispute.Status.class, node.findString("status"), Status.UNRECOGNIZED); 20 | } 21 | 22 | public Calendar getEffectiveDate() { 23 | return effectiveDate; 24 | } 25 | 26 | public Calendar getDisbursementDate() { 27 | return disbursementDate; 28 | } 29 | 30 | public Calendar getTimestamp() { 31 | return timestamp; 32 | } 33 | 34 | public Dispute.Status getStatus() { 35 | return status; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/PaymentMethodAddressOptionsRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class PaymentMethodAddressOptionsRequest extends Request { 4 | 5 | private PaymentMethodAddressRequest parent; 6 | private Boolean updateExisting; 7 | 8 | public PaymentMethodAddressOptionsRequest(PaymentMethodAddressRequest parent) { 9 | this.parent = parent; 10 | } 11 | 12 | public PaymentMethodAddressRequest done() { 13 | return parent; 14 | } 15 | 16 | public PaymentMethodAddressOptionsRequest updateExisting(Boolean updateExisting) { 17 | this.updateExisting = updateExisting; 18 | return this; 19 | } 20 | 21 | @Override 22 | public String toQueryString() { 23 | return toQueryString("options"); 24 | } 25 | 26 | @Override 27 | public String toQueryString(String root) { 28 | return buildRequest(root).toQueryString(); 29 | } 30 | 31 | @Override 32 | public String toXML() { 33 | return buildRequest("options").toXML(); 34 | } 35 | 36 | protected RequestBuilder buildRequest(String root) { 37 | return new RequestBuilder(root) 38 | .addElement("updateExisting", updateExisting); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/AuthenticationInsightOptionsRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class AuthenticationInsightOptionsRequest extends Request { 6 | private PaymentMethodNonceRequest parent; 7 | private BigDecimal amount; 8 | 9 | public AuthenticationInsightOptionsRequest(PaymentMethodNonceRequest parent) { 10 | this.parent = parent; 11 | } 12 | 13 | public AuthenticationInsightOptionsRequest amount(BigDecimal amount) { 14 | this.amount = amount; 15 | return this; 16 | } 17 | 18 | public PaymentMethodNonceRequest done() { 19 | return parent; 20 | } 21 | 22 | @Override 23 | public String toXML() { 24 | return buildRequest("authenticationInsightOptions").toXML(); 25 | } 26 | 27 | @Override 28 | public String toQueryString() { 29 | return toQueryString("AuthenticationInsightOptions"); 30 | } 31 | 32 | @Override 33 | public String toQueryString(String root) { 34 | return buildRequest(root).toQueryString(); 35 | } 36 | 37 | protected RequestBuilder buildRequest(String root) { 38 | return new RequestBuilder(root).addElement("amount", amount); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/TransactionLevelFeeReport.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStreamReader; 5 | import java.net.URL; 6 | import java.text.ParseException; 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | import org.apache.commons.csv.CSVFormat; 10 | import org.apache.commons.csv.CSVRecord; 11 | 12 | public class TransactionLevelFeeReport { 13 | private List csvRecords = new ArrayList(); 14 | private Boolean valid; 15 | 16 | public TransactionLevelFeeReport(String urlValue) throws IOException, ParseException { 17 | if (urlValue == null || "".equals(urlValue)) { 18 | this.valid = false; 19 | return; 20 | } 21 | 22 | this.valid = true; 23 | URL url = new URL(urlValue); 24 | InputStreamReader is = new InputStreamReader(url.openStream()); 25 | 26 | for (CSVRecord record : CSVFormat.EXCEL.withFirstRecordAsHeader().parse(is)) { 27 | csvRecords.add(record); 28 | } 29 | } 30 | 31 | public List getCSVRecords() { 32 | return csvRecords; 33 | } 34 | 35 | public Boolean isValid() { 36 | return this.valid; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/unittest/CreditCardVerificationOptionsRequestTest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.unittest; 2 | 3 | import java.io.IOException; 4 | 5 | import org.custommonkey.xmlunit.XMLAssert; 6 | import org.custommonkey.xmlunit.XMLUnit; 7 | import org.junit.jupiter.api.Test; 8 | import org.xml.sax.SAXException; 9 | 10 | import com.braintreegateway.CreditCardVerificationRequest; 11 | import com.braintreegateway.CreditCardVerificationOptionsRequest; 12 | 13 | public class CreditCardVerificationOptionsRequestTest { 14 | @Test 15 | public void toXmlIncludesAccountInformationInquiry() throws IOException, SAXException { 16 | CreditCardVerificationRequest creditcardverification = new CreditCardVerificationRequest(); 17 | CreditCardVerificationOptionsRequest request = new CreditCardVerificationOptionsRequest(creditcardverification) 18 | .accountInformationInquiry("send_data"); 19 | 20 | String expectedXML = 21 | " \n" 22 | + " send_data\n" 23 | + " \n"; 24 | 25 | XMLUnit.setIgnoreWhitespace(true); 26 | 27 | XMLAssert.assertXMLEqual(expectedXML, request.toXML()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/AddressInternationalPhoneRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class AddressInternationalPhoneRequest extends Request { 4 | private AddressRequest parent; 5 | private String countryCode; 6 | private String nationalNumber; 7 | 8 | public AddressInternationalPhoneRequest() {} 9 | 10 | public AddressInternationalPhoneRequest(AddressRequest parent) { 11 | this.parent = parent; 12 | } 13 | 14 | public AddressRequest done() { 15 | return parent; 16 | } 17 | 18 | public AddressInternationalPhoneRequest countryCode(String countryCode) { 19 | this.countryCode = countryCode; 20 | return this; 21 | } 22 | 23 | public AddressInternationalPhoneRequest nationalNumber(String nationalNumber) { 24 | this.nationalNumber = nationalNumber; 25 | return this; 26 | } 27 | 28 | @Override 29 | public String toXML() { 30 | return buildRequest("internationalPhone").toXML(); 31 | } 32 | 33 | protected RequestBuilder buildRequest(String root) { 34 | return new RequestBuilder(root) 35 | .addElement("countryCode", countryCode) 36 | .addElement("nationalNumber", nationalNumber); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/Adjustment.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import java.math.BigDecimal; 4 | import java.util.Calendar; 5 | 6 | import com.braintreegateway.util.EnumUtils; 7 | import com.braintreegateway.util.NodeWrapper; 8 | 9 | public class Adjustment { 10 | private Calendar projectedDisbursementDate; 11 | private Calendar actualDisbursementDate; 12 | private BigDecimal amount; 13 | private KIND kind; 14 | 15 | public enum KIND { 16 | REFUND, 17 | DISPUTE, 18 | UNRECOGNIZED; 19 | } 20 | 21 | public Adjustment(NodeWrapper node) { 22 | amount = node.findBigDecimal("amount"); 23 | projectedDisbursementDate = node.findDateTime("projected_disbursement_date"); 24 | actualDisbursementDate = node.findDateTime("actual_disbursement_date"); 25 | kind = EnumUtils.findByName(Adjustment.KIND.class, node.findString("kind"), KIND.UNRECOGNIZED); 26 | } 27 | 28 | public Calendar getProjectedDisbursementDate() { 29 | return projectedDisbursementDate; 30 | } 31 | 32 | public Calendar getActualDisbursementDate() { 33 | return actualDisbursementDate; 34 | } 35 | 36 | public BigDecimal getAmount() { 37 | return amount; 38 | } 39 | 40 | public KIND getKind() { 41 | return kind; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/unittest/ShippingOptionRequestTest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.unittest; 2 | 3 | import java.io.IOException; 4 | import java.math.BigDecimal; 5 | 6 | import org.custommonkey.xmlunit.XMLAssert; 7 | import org.custommonkey.xmlunit.XMLUnit; 8 | import org.junit.jupiter.api.Test; 9 | import org.xml.sax.SAXException; 10 | 11 | import com.braintreegateway.ShippingOptionRequest; 12 | import com.braintreegateway.util.SimpleNodeWrapper; 13 | 14 | public class ShippingOptionRequestTest { 15 | @Test 16 | public void testShippingOptionsFields() throws IOException, SAXException { 17 | ShippingOptionRequest request = new ShippingOptionRequest(). 18 | amount(new BigDecimal("10.00")). 19 | id("abc123"). 20 | label("fastShip"). 21 | selected(true). 22 | type("quick"); 23 | 24 | String expectedXML = 25 | "\n" 26 | + " 10.00\n" 27 | + " abc123\n" 28 | + " \n" 29 | + " true\n" 30 | + " quick\n" 31 | + ""; 32 | 33 | XMLUnit.setIgnoreWhitespace(true); 34 | 35 | XMLAssert.assertXMLEqual(expectedXML, request.toXML()); 36 | } 37 | } -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/PayPalOnlyAccountRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class PayPalOnlyAccountRequest extends Request { 4 | private String clientId; 5 | private String clientSecret; 6 | private MerchantRequest parent; 7 | 8 | public PayPalOnlyAccountRequest() { 9 | 10 | } 11 | 12 | public PayPalOnlyAccountRequest(MerchantRequest parent) { 13 | this.parent = parent; 14 | } 15 | 16 | public MerchantRequest done() { 17 | return parent; 18 | } 19 | 20 | public String getClientId() { 21 | return clientId; 22 | } 23 | 24 | public String getClientSecret() { 25 | return clientSecret; 26 | } 27 | 28 | public PayPalOnlyAccountRequest clientId(String clientId) { 29 | this.clientId = clientId; 30 | return this; 31 | } 32 | 33 | public PayPalOnlyAccountRequest clientSecret(String clientSecret) { 34 | this.clientSecret = clientSecret; 35 | return this; 36 | } 37 | 38 | @Override 39 | public String toXML() { 40 | return new RequestBuilder("paypalAccount") 41 | .addElement("clientId", clientId) 42 | .addElement("clientSecret", clientSecret) 43 | .toXML(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/TextEvidenceRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | /** 4 | * Provides a fluent interface to build up requests around TextEvidence. 5 | */ 6 | public class TextEvidenceRequest extends Request { 7 | 8 | private String content; 9 | private String category; 10 | private String sequenceNumber; 11 | 12 | public TextEvidenceRequest content(String content) { 13 | this.content = content; 14 | return this; 15 | } 16 | 17 | public String getContent() { 18 | return content; 19 | } 20 | 21 | public TextEvidenceRequest category(String category) { 22 | this.category = category; 23 | return this; 24 | } 25 | 26 | public TextEvidenceRequest sequenceNumber(String sequenceNumber) { 27 | this.sequenceNumber = sequenceNumber; 28 | return this; 29 | } 30 | 31 | @Override 32 | public String toXML() { 33 | return buildRequest("evidence").toXML(); 34 | } 35 | 36 | protected RequestBuilder buildRequest(String root) { 37 | return new RequestBuilder(root) 38 | .addElement("comments", content) 39 | .addElement("category", category) 40 | .addElement("sequenceNumber", sequenceNumber); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/DocumentUpload.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | 5 | public class DocumentUpload { 6 | 7 | public enum Kind { 8 | EVIDENCE_DOCUMENT("evidence_document"); 9 | 10 | private final String kind; 11 | 12 | Kind(String kind) { 13 | this.kind = kind; 14 | } 15 | 16 | @Override 17 | public String toString() { 18 | return kind; 19 | } 20 | } 21 | 22 | private final String id; 23 | private final Kind kind; 24 | private final String contentType; 25 | private final String name; 26 | private final int size; 27 | 28 | public DocumentUpload(NodeWrapper node) { 29 | kind = Kind.valueOf(node.findString("kind").toUpperCase()); 30 | id = node.findString("id"); 31 | contentType = node.findString("content-type"); 32 | name = node.findString("name"); 33 | size = node.findInteger("size"); 34 | } 35 | 36 | public String getId() { 37 | return id; 38 | } 39 | 40 | public Kind getKind() { 41 | return kind; 42 | } 43 | 44 | public String getContentType() { 45 | return contentType; 46 | } 47 | 48 | public String getName() { 49 | return name; 50 | } 51 | 52 | public int getSize() { 53 | return size; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/TransactionReview.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | import java.util.Calendar; 5 | 6 | public final class TransactionReview { 7 | private final String transactionId; 8 | private final String decision; 9 | private final String reviewerEmail; 10 | private final String reviewerNote; 11 | private final Calendar reviewedTime; 12 | 13 | public TransactionReview(NodeWrapper node) { 14 | this.transactionId = node.findString("transaction-id"); 15 | this.decision = node.findString("decision"); 16 | this.reviewerEmail = node.findString("reviewer-email"); 17 | this.reviewerNote = node.findString("reviewer-note"); 18 | this.reviewedTime = node.findDateTime("reviewed-time"); 19 | } 20 | 21 | public String getTransactionId() { 22 | return transactionId; 23 | } 24 | 25 | public String getDecision() { 26 | return decision; 27 | } 28 | 29 | public String getReviewerEmail() { 30 | return reviewerEmail; 31 | } 32 | 33 | public String getReviewerNote() { 34 | return reviewerNote; 35 | } 36 | 37 | public Calendar getReviewedTime() { 38 | return reviewedTime; 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/TransactionCloneRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class TransactionCloneRequest extends Request { 6 | private BigDecimal amount; 7 | private String channel; 8 | private TransactionOptionsCloneRequest transactionOptionsCloneRequest; 9 | 10 | public TransactionCloneRequest amount(BigDecimal amount) { 11 | this.amount = amount; 12 | return this; 13 | } 14 | 15 | public TransactionCloneRequest channel(String channel) { 16 | this.channel = channel; 17 | return this; 18 | } 19 | 20 | public TransactionOptionsCloneRequest options() { 21 | transactionOptionsCloneRequest = new TransactionOptionsCloneRequest(this); 22 | return transactionOptionsCloneRequest; 23 | } 24 | 25 | @Override 26 | public String toXML() { 27 | return buildRequest("transactionClone").toXML(); 28 | } 29 | 30 | protected RequestBuilder buildRequest(String root) { 31 | RequestBuilder builder = new RequestBuilder(root) 32 | .addElement("amount", amount) 33 | .addElement("channel", channel) 34 | .addElement("options", transactionOptionsCloneRequest); 35 | 36 | return builder; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/util/Sha1Hasher.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.util; 2 | 3 | import com.braintreegateway.org.apache.commons.codec.binary.Hex; 4 | import java.security.MessageDigest; 5 | import javax.crypto.Mac; 6 | import javax.crypto.spec.SecretKeySpec; 7 | 8 | public class Sha1Hasher implements Hasher { 9 | public String hmacHash(String privateKey, String content) { 10 | String hash = ""; 11 | try { 12 | SecretKeySpec signingKey = new SecretKeySpec(sha1Bytes(privateKey), "SHA1"); 13 | Mac mac = Mac.getInstance("HmacSHA1"); 14 | mac.init(signingKey); 15 | 16 | byte[] rawMac = mac.doFinal(content.getBytes("UTF-8")); 17 | byte[] hexBytes = new Hex().encode(rawMac); 18 | hash = new String(hexBytes, "ISO-8859-1"); 19 | } catch (Exception e) { 20 | throw new RuntimeException(e); 21 | } 22 | return hash; 23 | } 24 | 25 | private byte[] sha1Bytes(String string) { 26 | try { 27 | MessageDigest md = MessageDigest.getInstance("SHA1"); 28 | md.update(string.getBytes("UTF-8")); 29 | return md.digest(); 30 | } catch (Exception e) { 31 | throw new RuntimeException(e); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/ShippingInternationalPhoneRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class ShippingInternationalPhoneRequest extends AddressInternationalPhoneRequest { 4 | private PayPalPaymentResourceShippingRequest parent; 5 | private String countryCode; 6 | private String nationalNumber; 7 | 8 | public ShippingInternationalPhoneRequest(PayPalPaymentResourceShippingRequest parent) { 9 | super(); 10 | this.parent = parent; 11 | } 12 | 13 | public PayPalPaymentResourceShippingRequest done() { 14 | return parent; 15 | } 16 | 17 | public ShippingInternationalPhoneRequest countryCode(String countryCode) { 18 | this.countryCode = countryCode; 19 | return this; 20 | } 21 | 22 | public ShippingInternationalPhoneRequest nationalNumber(String nationalNumber) { 23 | this.nationalNumber = nationalNumber; 24 | return this; 25 | } 26 | 27 | @Override 28 | public String toXML() { 29 | return buildRequest("internationalPhone").toXML(); 30 | } 31 | 32 | protected RequestBuilder buildRequest(String root) { 33 | return new RequestBuilder(root) 34 | .addElement("countryCode", countryCode) 35 | .addElement("nationalNumber", nationalNumber); 36 | } 37 | } -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/util/Sha256Hasher.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.util; 2 | 3 | import com.braintreegateway.org.apache.commons.codec.binary.Hex; 4 | import java.security.MessageDigest; 5 | import javax.crypto.Mac; 6 | import javax.crypto.spec.SecretKeySpec; 7 | 8 | public class Sha256Hasher implements Hasher { 9 | 10 | public String hmacHash(String privateKey, String content) { 11 | String hash = ""; 12 | try { 13 | SecretKeySpec signingKey = new SecretKeySpec(sha256Bytes(privateKey), "SHA-256"); 14 | Mac mac = Mac.getInstance("HmacSHA256"); 15 | mac.init(signingKey); 16 | 17 | byte[] rawMac = mac.doFinal(content.getBytes("UTF-8")); 18 | byte[] hexBytes = new Hex().encode(rawMac); 19 | hash = new String(hexBytes, "ISO-8859-1"); 20 | } catch (Exception e) { 21 | throw new RuntimeException(e); 22 | } 23 | return hash; 24 | } 25 | 26 | private byte[] sha256Bytes(String string) { 27 | try { 28 | MessageDigest md = MessageDigest.getInstance("SHA-256"); 29 | md.update(string.getBytes("UTF-8")); 30 | return md.digest(); 31 | } catch (Exception e) { 32 | throw new RuntimeException(e); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/unittest/DocumentUploadRequestTest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.unittest; 2 | 3 | import java.net.URL; 4 | 5 | import com.braintreegateway.DocumentUpload; 6 | import com.braintreegateway.DocumentUploadRequest; 7 | 8 | import java.io.File; 9 | 10 | import org.junit.jupiter.api.Test; 11 | import static org.junit.jupiter.api.Assertions.*; 12 | 13 | public class DocumentUploadRequestTest { 14 | @Test 15 | public void documentUploadRequestThrowsExceptionWhenKindIsNull() { 16 | URL fileToUpload = getClass().getClassLoader().getResource("fixtures/bt_logo.png"); 17 | 18 | Exception e = assertThrows(IllegalArgumentException.class, () -> { 19 | DocumentUploadRequest uploadRequest = new DocumentUploadRequest(null, 20 | new File(fileToUpload.getFile())); 21 | }); 22 | 23 | assertEquals("DocumentUpload.Kind must not be null", e.getMessage()); 24 | } 25 | 26 | @Test 27 | public void documentUploadRequestThrowsExceptionWhenFileIsNull() { 28 | Exception e = assertThrows(IllegalArgumentException.class, () -> { 29 | DocumentUploadRequest uploadRequest = new DocumentUploadRequest(DocumentUpload.Kind.EVIDENCE_DOCUMENT, null); 30 | }); 31 | 32 | assertEquals("File must not be null", e.getMessage()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/unittest/LiabilityShiftTest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.unittest; 2 | 3 | import java.text.ParseException; 4 | import java.util.List; 5 | 6 | import com.braintreegateway.LiabilityShift; 7 | import com.braintreegateway.util.SimpleNodeWrapper; 8 | 9 | import org.junit.jupiter.api.Test; 10 | import static org.junit.jupiter.api.Assertions.*; 11 | 12 | public class LiabilityShiftTest { 13 | @Test 14 | public void testLiabilityShiftFields() throws ParseException { 15 | String xml = "\n" + 16 | "\n" + 17 | "paypal\n" + 18 | "\n" + 19 | " eeny\n" + 20 | " meeny\n" + 21 | "\n" + 22 | "\n"; 23 | 24 | SimpleNodeWrapper liabilityShiftNode = SimpleNodeWrapper.parse(xml); 25 | LiabilityShift liabilityShift = new LiabilityShift(liabilityShiftNode); 26 | List conditions = liabilityShift.getConditions(); 27 | 28 | assertEquals("paypal", liabilityShift.getResponsibleParty()); 29 | assertEquals(conditions, liabilityShift.getConditions()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/PartnerMerchant.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | 5 | public final class PartnerMerchant { 6 | private final String merchantPublicId; 7 | private final String publicKey; 8 | private final String privateKey; 9 | private final String partnerMerchantId; 10 | private final String clientSideEncryptionKey; 11 | 12 | public PartnerMerchant(NodeWrapper node) { 13 | this.merchantPublicId = node.findString("merchant-public-id"); 14 | this.publicKey = node.findString("public-key"); 15 | this.privateKey = node.findString("private-key"); 16 | this.partnerMerchantId = node.findString("partner-merchant-id"); 17 | this.clientSideEncryptionKey = node.findString("client-side-encryption-key"); 18 | } 19 | 20 | public String getMerchantPublicId() { 21 | return merchantPublicId; 22 | } 23 | 24 | public String getPublicKey() { 25 | return publicKey; 26 | } 27 | 28 | public String getPrivateKey() { 29 | return privateKey; 30 | } 31 | 32 | public String getPartnerMerchantId() { 33 | return partnerMerchantId; 34 | } 35 | 36 | public String getClientSideEncryptionKey() { 37 | return clientSideEncryptionKey; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/PartyInternationalPhoneRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class PartyInternationalPhoneRequest extends AddressInternationalPhoneRequest { 4 | private String countryCode; 5 | private String nationalNumber; 6 | private PartyAddressRequest parent; 7 | 8 | public PartyInternationalPhoneRequest() {} 9 | 10 | 11 | public PartyInternationalPhoneRequest(PartyAddressRequest parent) { 12 | super(); 13 | this.parent = parent; 14 | } 15 | 16 | public PartyAddressRequest done() { 17 | return parent; 18 | } 19 | 20 | public PartyInternationalPhoneRequest countryCode(String countryCode) { 21 | this.countryCode = countryCode; 22 | return this; 23 | } 24 | 25 | public PartyInternationalPhoneRequest nationalNumber(String nationalNumber) { 26 | this.nationalNumber = nationalNumber; 27 | return this; 28 | } 29 | 30 | @Override 31 | public String toXML() { 32 | return buildRequest("internationalPhone").toXML(); 33 | } 34 | 35 | protected RequestBuilder buildRequest(String root) { 36 | return new RequestBuilder(root) 37 | .addElement("countryCode", countryCode) 38 | .addElement("nationalNumber", nationalNumber); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/unittest/PaginatedCollectionTest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.unittest; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import com.braintreegateway.PaginatedCollection; 7 | import com.braintreegateway.PaginatedResult; 8 | import com.braintreegateway.SimplePager; 9 | 10 | import static org.mockito.Matchers.any; 11 | import static org.mockito.Mockito.mock; 12 | import static org.mockito.Mockito.times; 13 | import static org.mockito.Mockito.verify; 14 | import static org.mockito.Mockito.when; 15 | 16 | import org.junit.jupiter.api.Test; 17 | 18 | public class PaginatedCollectionTest { 19 | @Test 20 | public void testGetsSinglePageFullCollection() { 21 | SimplePager pager = mock(SimplePager.class); 22 | 23 | List values = new ArrayList(); 24 | values.add(1); 25 | when(pager.getPage(1)).thenReturn(new PaginatedResult(1, 1, values)); 26 | 27 | PaginatedCollection collection = new PaginatedCollection(pager); 28 | 29 | List results = new ArrayList(); 30 | for (Integer i : collection) { 31 | results.add(i); 32 | } 33 | 34 | verify(pager, times(1)).getPage(1); 35 | verify(pager, times(1)).getPage(any(int.class)); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/unittest/SepaDirectDebitAccountRequestTest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.unittest; 2 | 3 | import com.braintreegateway.SepaDirectDebitAccountRequest; 4 | import com.braintreegateway.SepaDirectDebitAccountOptionsRequest; 5 | 6 | import org.junit.jupiter.api.Test; 7 | import static org.junit.jupiter.api.Assertions.*; 8 | 9 | public class SepaDirectDebitAccountRequestTest { 10 | 11 | @Test 12 | public void token() { 13 | SepaDirectDebitAccountRequest sepaDirectDebitAccountRequest = new SepaDirectDebitAccountRequest(); 14 | sepaDirectDebitAccountRequest.token("123"); 15 | 16 | String expectedXml = "123"; 17 | assertEquals(expectedXml, sepaDirectDebitAccountRequest.toXML()); 18 | } 19 | 20 | @Test 21 | public void options() { 22 | SepaDirectDebitAccountRequest sepaDirectDebitAccountRequest = new SepaDirectDebitAccountRequest(); 23 | SepaDirectDebitAccountOptionsRequest options = sepaDirectDebitAccountRequest.options(); 24 | options.makeDefault(true).done(); 25 | 26 | String expectedXml = "true"; 27 | assertEquals(expectedXml, sepaDirectDebitAccountRequest.toXML()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/TransactionAddressInternationalPhoneRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class TransactionAddressInternationalPhoneRequest extends AddressInternationalPhoneRequest { 4 | private TransactionAddressRequest parent; 5 | private String countryCode; 6 | private String nationalNumber; 7 | 8 | public TransactionAddressInternationalPhoneRequest(TransactionAddressRequest parent) { 9 | super(); 10 | this.parent = parent; 11 | } 12 | 13 | public TransactionAddressRequest done() { 14 | return parent; 15 | } 16 | 17 | public TransactionAddressInternationalPhoneRequest countryCode(String countryCode) { 18 | this.countryCode = countryCode; 19 | return this; 20 | } 21 | 22 | public TransactionAddressInternationalPhoneRequest nationalNumber(String nationalNumber) { 23 | this.nationalNumber = nationalNumber; 24 | return this; 25 | } 26 | 27 | @Override 28 | public String toXML() { 29 | return buildRequest("internationalPhone").toXML(); 30 | } 31 | 32 | protected RequestBuilder buildRequest(String root) { 33 | return new RequestBuilder(root) 34 | .addElement("countryCode", countryCode) 35 | .addElement("nationalNumber", nationalNumber); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/util/ClientLibraryProperties.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.util; 2 | 3 | import com.braintreegateway.exceptions.UnexpectedException; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.util.Properties; 7 | 8 | public class ClientLibraryProperties { 9 | 10 | public static final String BRAINTREE_PROPERTY_FILE = "braintree.properties"; 11 | public static final String VERSION_PROPERTY_NAME = "braintree.gateway.version"; 12 | 13 | private final Properties properties = loadProperties(BRAINTREE_PROPERTY_FILE); 14 | 15 | public String version() { 16 | return properties.getProperty(VERSION_PROPERTY_NAME); 17 | } 18 | 19 | private Properties loadProperties(String propertyFile) { 20 | try { 21 | InputStream is = null; 22 | try { 23 | is = getClass().getClassLoader().getResourceAsStream(propertyFile); 24 | Properties p = new Properties(); 25 | p.load(is); 26 | return p; 27 | } finally { 28 | if (is != null) { 29 | is.close(); 30 | } 31 | } 32 | } catch (IOException e) { 33 | throw new UnexpectedException("Couldn't load " + BRAINTREE_PROPERTY_FILE + " can't continue", e); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/integrationtest/DisbursementDetailsIT.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.integrationtest; 2 | 3 | import com.braintreegateway.DisbursementDetails; 4 | import com.braintreegateway.testhelpers.CalendarTestUtils; 5 | import com.braintreegateway.util.NodeWrapper; 6 | 7 | import java.text.ParseException; 8 | import java.util.Calendar; 9 | 10 | import org.junit.jupiter.api.Test; 11 | import static org.junit.jupiter.api.Assertions.*; 12 | 13 | import static org.mockito.Mockito.mock; 14 | import static org.mockito.Mockito.when; 15 | 16 | public class DisbursementDetailsIT { 17 | @Test 18 | public void isValidTrue() throws ParseException { 19 | NodeWrapper wrapper = mock(NodeWrapper.class); 20 | Calendar disbursementDate = CalendarTestUtils.date("2013-04-10"); 21 | when(wrapper.findDate("disbursement-date")).thenReturn(disbursementDate); 22 | 23 | DisbursementDetails detail = new DisbursementDetails(wrapper); 24 | assertTrue(detail.isValid()); 25 | } 26 | 27 | @Test 28 | public void isValidFalse() throws ParseException { 29 | NodeWrapper wrapper = mock(NodeWrapper.class); 30 | when(wrapper.findDate("disbursement-date")).thenReturn(null); 31 | 32 | DisbursementDetails detail = new DisbursementDetails(wrapper); 33 | assertFalse(detail.isValid()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/unittest/SearchRequestTest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.unittest; 2 | 3 | import com.braintreegateway.SearchRequest; 4 | import com.braintreegateway.SearchCriteria; 5 | 6 | import org.junit.jupiter.api.Test; 7 | import static org.junit.jupiter.api.Assertions.*; 8 | 9 | public class SearchRequestTest { 10 | 11 | @Test 12 | public void generatesXMLForSingleSearchCriteria() { 13 | SearchRequest searchRequest = new SearchRequest(); 14 | searchRequest.addCriteria("credit_card_number", new SearchCriteria("starts_with", "4111")); 15 | 16 | String expectedXml = "4111"; 17 | assertEquals(expectedXml, searchRequest.toXML()); 18 | } 19 | 20 | @Test 21 | public void generatesXMLForMultipleSearchCriteriaInNode() { 22 | SearchRequest searchRequest = new SearchRequest(); 23 | searchRequest.addCriteria("credit_card_number", new SearchCriteria("starts_with", "4111")); 24 | searchRequest.addCriteria("credit_card_number", new SearchCriteria("ends_with", "1111")); 25 | 26 | String expectedXml = "41111111"; 27 | assertEquals(expectedXml, searchRequest.toXML()); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/ExternalVaultRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class ExternalVaultRequest extends Request { 4 | private TransactionRequest parent; 5 | private ExternalVault.Status status; 6 | private String previousNetworkTransactionId; 7 | 8 | public ExternalVaultRequest(TransactionRequest parent) { 9 | this.parent = parent; 10 | } 11 | 12 | public ExternalVaultRequest willVault() { 13 | this.status = ExternalVault.Status.WILL_VAULT; 14 | return this; 15 | } 16 | 17 | public ExternalVaultRequest vaulted() { 18 | this.status = ExternalVault.Status.VAULTED; 19 | return this; 20 | } 21 | 22 | public ExternalVaultRequest previousNetworkTransactionId(String previousNetworkTransactionId) { 23 | this.previousNetworkTransactionId = previousNetworkTransactionId; 24 | return this; 25 | } 26 | 27 | public TransactionRequest done() { 28 | return parent; 29 | } 30 | 31 | @Override 32 | public String toXML() { 33 | return buildRequest("externalVault").toXML(); 34 | } 35 | 36 | protected RequestBuilder buildRequest(String root) { 37 | return new RequestBuilder(root) 38 | .addElement("status", status) 39 | .addElement("previousNetworkTransactionId", previousNetworkTransactionId); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/MerchantAccount.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.EnumUtils; 4 | import com.braintreegateway.util.NodeWrapper; 5 | 6 | public class MerchantAccount { 7 | 8 | public enum Status { 9 | PENDING, 10 | ACTIVE, 11 | SUSPENDED, 12 | UNRECOGNIZED 13 | } 14 | 15 | private final String id; 16 | private final Status status; 17 | private final String currencyIsoCode; 18 | private final Boolean isDefault; 19 | 20 | public MerchantAccount(NodeWrapper node) { 21 | NodeWrapper responseNode = node.findFirst("merchant-account"); 22 | if (responseNode != null) { 23 | node = responseNode; 24 | } 25 | 26 | this.id = node.findString("id"); 27 | this.currencyIsoCode = node.findString("currency-iso-code"); 28 | this.status = EnumUtils.findByName(Status.class, node.findString("status"), Status.UNRECOGNIZED); 29 | this.isDefault = node.findBoolean("default"); 30 | 31 | } 32 | 33 | public String getId() { 34 | return id; 35 | } 36 | 37 | public Status getStatus() { 38 | return status; 39 | } 40 | 41 | public String getCurrencyIsoCode() { 42 | return currencyIsoCode; 43 | } 44 | 45 | public Boolean isDefault() { 46 | return isDefault; 47 | } 48 | 49 | } 50 | 51 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/StatusEvent.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.Transaction.Source; 4 | import com.braintreegateway.Transaction.Status; 5 | import com.braintreegateway.util.EnumUtils; 6 | import com.braintreegateway.util.NodeWrapper; 7 | import java.math.BigDecimal; 8 | import java.util.Calendar; 9 | 10 | public class StatusEvent { 11 | 12 | private BigDecimal amount; 13 | private Status status; 14 | private Calendar timestamp; 15 | private Source source; 16 | private String user; 17 | 18 | public StatusEvent(NodeWrapper node) { 19 | amount = node.findBigDecimal("amount"); 20 | status = EnumUtils.findByName(Status.class, node.findString("status"), Status.UNRECOGNIZED); 21 | timestamp = node.findDateTime("timestamp"); 22 | source = EnumUtils.findByName(Source.class, node.findString("transaction-source"), Source.UNRECOGNIZED); 23 | user = node.findString("user"); 24 | } 25 | 26 | public BigDecimal getAmount() { 27 | return amount; 28 | } 29 | 30 | public Status getStatus() { 31 | return status; 32 | } 33 | 34 | public Calendar getTimestamp() { 35 | return timestamp; 36 | } 37 | 38 | public Source getSource() { 39 | return source; 40 | } 41 | 42 | public String getUser() { 43 | return user; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/PackageDetails.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | 5 | // NEXT_MAJOR_VERSION remove paypalTrackingId and getPaypalTrackingId 6 | public class PackageDetails { 7 | private String carrier; 8 | private String id; 9 | private String paypalTrackingId; 10 | private String paypalTrackerId; 11 | private String trackingNumber; 12 | 13 | public PackageDetails(NodeWrapper node) { 14 | carrier = node.findString("carrier"); 15 | id = node.findString("id"); 16 | paypalTrackerId = node.findString("paypal-tracker-id"); 17 | paypalTrackingId = node.findString("paypal-tracking-id"); 18 | trackingNumber = node.findString("tracking-number"); 19 | } 20 | 21 | public String getId() { 22 | return id; 23 | } 24 | 25 | public String getTrackingNumber() { 26 | return trackingNumber; 27 | } 28 | 29 | public String getCarrier() { 30 | return carrier; 31 | } 32 | 33 | //NEXT_MAJOR_VERSION remove this method 34 | /** 35 | * @deprecated - The getPayPalTrackingId is deprecated in favor of getPayPalTrackerId. 36 | */ 37 | @Deprecated 38 | public String getPayPalTrackingId() { 39 | return paypalTrackingId; 40 | } 41 | 42 | public String getPayPalTrackerId() { 43 | return paypalTrackerId; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/AddModificationRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class AddModificationRequest extends ModificationRequest { 6 | 7 | private String inheritedFromId; 8 | 9 | public AddModificationRequest(ModificationsRequest parent) { 10 | super(parent); 11 | } 12 | 13 | @Override 14 | public AddModificationRequest amount(BigDecimal amount) { 15 | super.amount(amount); 16 | return this; 17 | } 18 | 19 | public AddModificationRequest inheritedFromId(String inheritedFromId) { 20 | this.inheritedFromId = inheritedFromId; 21 | return this; 22 | } 23 | 24 | @Override 25 | public AddModificationRequest neverExpires(Boolean neverExpires) { 26 | super.neverExpires(neverExpires); 27 | return this; 28 | } 29 | 30 | @Override 31 | public AddModificationRequest numberOfBillingCycles(Integer numberOfBillingCycles) { 32 | super.numberOfBillingCycles(numberOfBillingCycles); 33 | return this; 34 | } 35 | 36 | @Override 37 | public AddModificationRequest quantity(Integer quantity) { 38 | super.quantity(quantity); 39 | return this; 40 | } 41 | 42 | @Override 43 | protected RequestBuilder buildRequest(String root) { 44 | return super.buildRequest(root).addElement("inheritedFromId", inheritedFromId); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/TaxIdentifierRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class TaxIdentifierRequest extends Request { 4 | private CustomerRequest parent; 5 | private String countryCode; 6 | private String identifier; 7 | 8 | public TaxIdentifierRequest() { 9 | } 10 | 11 | public TaxIdentifierRequest(CustomerRequest parent) { 12 | this.parent = parent; 13 | } 14 | 15 | public TaxIdentifierRequest countryCode(String countryCode) { 16 | this.countryCode = countryCode; 17 | return this; 18 | } 19 | 20 | public TaxIdentifierRequest identifier(String identifier) { 21 | this.identifier = identifier; 22 | return this; 23 | } 24 | 25 | public CustomerRequest done() { 26 | return parent; 27 | } 28 | 29 | @Override 30 | public String toXML() { 31 | return buildRequest("taxIdentifier").toXML(); 32 | } 33 | 34 | @Override 35 | public String toQueryString() { 36 | return toQueryString("taxIdentifier"); 37 | } 38 | 39 | @Override 40 | public String toQueryString(String root) { 41 | return buildRequest(root).toQueryString(); 42 | } 43 | 44 | protected RequestBuilder buildRequest(String root) { 45 | return new RequestBuilder(root) 46 | .addElement("countryCode", countryCode) 47 | .addElement("identifier", identifier); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/unittest/CreditCardGatewayTest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.unittest; 2 | 3 | import com.braintreegateway.BraintreeGateway; 4 | import com.braintreegateway.CreditCardGateway; 5 | import com.braintreegateway.Environment; 6 | import com.braintreegateway.exceptions.NotFoundException; 7 | 8 | import org.junit.jupiter.api.Test; 9 | import org.junit.jupiter.api.BeforeEach; 10 | import static org.junit.jupiter.api.Assertions.*; 11 | 12 | public class CreditCardGatewayTest { 13 | private BraintreeGateway gateway; 14 | 15 | @BeforeEach 16 | public void createGateway() { 17 | this.gateway = new BraintreeGateway( 18 | Environment.DEVELOPMENT, 19 | "integration_merchant_id", 20 | "integration_public_key", 21 | "integration_private_key" 22 | ); 23 | } 24 | 25 | @Test 26 | public void findThrowsNotFoundExceptionOnNullPointer() { 27 | CreditCardGateway creditCardGateway = this.gateway.creditCard(); 28 | assertThrows(NotFoundException.class, () -> { 29 | creditCardGateway.find(null); 30 | }); 31 | } 32 | 33 | @Test 34 | public void fromNonceThrowsNotFoundExceptionOnNullPointer() { 35 | CreditCardGateway creditCardGateway = this.gateway.creditCard(); 36 | assertThrows(NotFoundException.class, () -> { 37 | creditCardGateway.fromNonce(null); 38 | }); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/Installment.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import java.math.BigDecimal; 4 | import java.util.ArrayList; 5 | import java.util.Calendar; 6 | import java.util.List; 7 | 8 | import com.braintreegateway.util.NodeWrapper; 9 | 10 | public class Installment { 11 | 12 | private String id; 13 | private Calendar projectedDisbursementDate; 14 | private Calendar actualDisbursementDate; 15 | private BigDecimal amount; 16 | private List adjustments; 17 | 18 | public Installment(NodeWrapper node) { 19 | id = node.findString("id"); 20 | amount = node.findBigDecimal("amount"); 21 | projectedDisbursementDate = node.findDateTime("projected_disbursement_date"); 22 | actualDisbursementDate = node.findDateTime("actual_disbursement_date"); 23 | adjustments = new ArrayList(); 24 | for (NodeWrapper adjustmentNode : node.findAll("adjustments/adjustment")) { 25 | adjustments.add(new Adjustment(adjustmentNode)); 26 | } 27 | } 28 | 29 | public String getId() { 30 | return id; 31 | } 32 | 33 | public Calendar getProjectedDisbursementDate() { 34 | return projectedDisbursementDate; 35 | } 36 | 37 | public Calendar getActualDisbursementDate() { 38 | return actualDisbursementDate; 39 | } 40 | 41 | public BigDecimal getAmount() { 42 | return amount; 43 | } 44 | 45 | public List getAdjustments() { 46 | return adjustments; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/PaymentMethodCustomerDataUpdatedMetadata.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | import com.braintreegateway.util.PaymentMethodParser; 5 | 6 | public class PaymentMethodCustomerDataUpdatedMetadata { 7 | private String token; 8 | private PaymentMethod paymentMethod; 9 | private String datetimeUpdated; 10 | private EnrichedCustomerData enrichedCustomerData; 11 | 12 | public PaymentMethodCustomerDataUpdatedMetadata(NodeWrapper node) { 13 | this.token = node.findString("token"); 14 | this.datetimeUpdated = node.findString("datetime-updated"); 15 | 16 | NodeWrapper paymentMethodNode = node.findFirst("payment-method"); 17 | this.paymentMethod = PaymentMethodParser.parsePaymentMethod(paymentMethodNode.getChildren().get(0)).getTarget(); 18 | 19 | NodeWrapper enrichedCustomerDataNode = node.findFirst("enriched-customer-data"); 20 | this.enrichedCustomerData = new EnrichedCustomerData(enrichedCustomerDataNode); 21 | } 22 | 23 | public String getToken() { 24 | return token; 25 | } 26 | 27 | public PaymentMethod getPaymentMethod() { 28 | return paymentMethod; 29 | } 30 | 31 | public String getDatetimeUpdated() { 32 | return datetimeUpdated; 33 | } 34 | 35 | public EnrichedCustomerData getEnrichedCustomerData() { 36 | return enrichedCustomerData; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/TransactionSubMerchantInternationalPhoneRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | public class TransactionSubMerchantInternationalPhoneRequest extends AddressInternationalPhoneRequest { 4 | private TransactionSubMerchantAddressRequest parent; 5 | private String countryCode; 6 | private String nationalNumber; 7 | 8 | public TransactionSubMerchantInternationalPhoneRequest() {} 9 | 10 | 11 | public TransactionSubMerchantInternationalPhoneRequest(TransactionSubMerchantAddressRequest parent) { 12 | super(); 13 | this.parent = parent; 14 | } 15 | 16 | public TransactionSubMerchantAddressRequest done() { 17 | return parent; 18 | } 19 | 20 | public TransactionSubMerchantInternationalPhoneRequest countryCode(String countryCode) { 21 | this.countryCode = countryCode; 22 | return this; 23 | } 24 | 25 | public TransactionSubMerchantInternationalPhoneRequest nationalNumber(String nationalNumber) { 26 | this.nationalNumber = nationalNumber; 27 | return this; 28 | } 29 | 30 | @Override 31 | public String toXML() { 32 | return buildRequest("internationalPhone").toXML(); 33 | } 34 | 35 | protected RequestBuilder buildRequest(String root) { 36 | return new RequestBuilder(root) 37 | .addElement("countryCode", countryCode) 38 | .addElement("nationalNumber", nationalNumber); 39 | } 40 | } -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/integrationtest/ApplePayCardIT.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.integrationtest; 2 | 3 | import com.braintreegateway.*; 4 | import com.braintreegateway.test.Nonce; 5 | 6 | import org.junit.jupiter.api.Test; 7 | import static org.junit.jupiter.api.Assertions.*; 8 | 9 | public class ApplePayCardIT extends IntegrationTest { 10 | 11 | @Test 12 | public void testBinFields() { 13 | Customer customer = gateway.customer().create(new CustomerRequest()).getTarget(); 14 | PaymentMethodRequest request = new PaymentMethodRequest(). 15 | customerId(customer.getId()). 16 | paymentMethodNonce(Nonce.ApplePayVisa); 17 | 18 | Result result = gateway.paymentMethod().create(request); 19 | assertTrue(result.isSuccess()); 20 | 21 | ApplePayCard applePayCard = (ApplePayCard) result.getTarget(); 22 | 23 | assertNotNull(applePayCard.getPrepaid()); 24 | assertNotNull(applePayCard.getPrepaidReloadable()); 25 | assertNotNull(applePayCard.getBusiness()); 26 | assertNotNull(applePayCard.getConsumer()); 27 | assertNotNull(applePayCard.getCorporate()); 28 | assertNotNull(applePayCard.getPurchase()); 29 | 30 | ApplePayCard foundApplePayCard = (ApplePayCard) gateway.paymentMethod().find(applePayCard.getToken()); 31 | assertEquals(applePayCard.getToken(), foundApplePayCard.getToken()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/unittest/GraphQLClientTest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.unittest; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | import com.braintreegateway.util.GraphQLClient; 7 | 8 | import org.junit.jupiter.api.Test; 9 | import static org.junit.jupiter.api.Assertions.*; 10 | 11 | public class GraphQLClientTest { 12 | 13 | @Test 14 | public void formatGraphQLRequestReturnsJsonString() { 15 | String query = "query string"; 16 | Map variables = new HashMap(); 17 | variables.put("key", "value"); 18 | 19 | String json = GraphQLClient.formatGraphQLRequest(query, variables); 20 | 21 | assertEquals("{\"query\":\"query string\",\"variables\":{\"key\":\"value\"}}", json); 22 | } 23 | 24 | @Test 25 | public void formatGraphQLRequestWithoutVariablesMapReturnsJsonString() { 26 | String query = "query string"; 27 | Map variables = null; 28 | 29 | String json = GraphQLClient.formatGraphQLRequest(query, variables); 30 | 31 | assertEquals("{\"query\":\"query string\"}", json); 32 | } 33 | 34 | @Test 35 | public void formatGraphQLRequestWithoutQueryReturnsJsonString() { 36 | String query = null; 37 | Map variables = null; 38 | 39 | String json = GraphQLClient.formatGraphQLRequest(query, variables); 40 | 41 | assertEquals("{}", json); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/CustomActionsPaymentMethodDetails.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | import java.util.ArrayList; 5 | import java.util.Collections; 6 | import java.util.List; 7 | 8 | public class CustomActionsPaymentMethodDetails { 9 | private String token; 10 | private String actionName; 11 | private String globalId; 12 | private String uniqueNumberIdentifier; 13 | private List fields; 14 | 15 | public CustomActionsPaymentMethodDetails(NodeWrapper node) { 16 | token = node.findString("token"); 17 | globalId = node.findString("global-id"); 18 | actionName = node.findString("action-name"); 19 | uniqueNumberIdentifier = node.findString("unique-number-identifier"); 20 | fields = new ArrayList(); 21 | for (NodeWrapper fieldResponse : node.findAll("fields/field")) { 22 | fields.add(new CustomActionsPaymentMethodField(fieldResponse)); 23 | } 24 | } 25 | 26 | public String getGlobalId() { 27 | return globalId; 28 | } 29 | 30 | public String getToken() { 31 | return token; 32 | } 33 | 34 | public String getActionName() { 35 | return actionName; 36 | } 37 | 38 | public String getUniqueNumberIdentifier() { 39 | return uniqueNumberIdentifier; 40 | } 41 | 42 | public List getFields() { 43 | return Collections.unmodifiableList(fields); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/unittest/util/HttpsTest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.unittest.util; 2 | 3 | import java.io.*; 4 | import java.security.*; 5 | import javax.net.ssl.*; 6 | 7 | public class HttpsTest { 8 | public static void main(String[] args) { 9 | String ksName = "keystore.jks"; 10 | char ksPass[] = "password".toCharArray(); 11 | char ctPass[] = "password".toCharArray(); 12 | 13 | try { 14 | KeyStore ks = KeyStore.getInstance("JKS"); 15 | ks.load(new FileInputStream(ksName), ksPass); 16 | 17 | KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509"); 18 | kmf.init(ks, ctPass); 19 | 20 | SSLContext sc = SSLContext.getInstance("TLS"); 21 | sc.init(kmf.getKeyManagers(), null, null); 22 | 23 | SSLServerSocketFactory ssf = sc.getServerSocketFactory(); 24 | SSLServerSocket s = (SSLServerSocket) ssf.createServerSocket(19443); 25 | System.out.println("Server started."); 26 | 27 | SSLSocket c = (SSLSocket) s.accept(); 28 | BufferedWriter w = new BufferedWriter(new OutputStreamWriter(c.getOutputStream())); 29 | BufferedReader r = new BufferedReader(new InputStreamReader(c.getInputStream())); 30 | 31 | w.write("HTTP/1.0 200 OK\nContent-Type: text/html\n\nHello world!\n"); 32 | w.flush(); 33 | w.close(); 34 | 35 | r.close(); 36 | c.close(); 37 | } catch (Exception e) { 38 | e.printStackTrace(); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/PaymentMethodNonceGateway.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.Http; 4 | import com.braintreegateway.util.NodeWrapper; 5 | 6 | public class PaymentMethodNonceGateway { 7 | private Http http; 8 | private Configuration configuration; 9 | 10 | public PaymentMethodNonceGateway(Http http, Configuration configuration) { 11 | this.http = http; 12 | this.configuration = configuration; 13 | } 14 | 15 | public Result create(String paymentMethodToken) { 16 | NodeWrapper response = http.post(configuration.getMerchantPath() + "/payment_methods/" + paymentMethodToken + "/nonces"); 17 | return parseResponse(response); 18 | } 19 | 20 | public Result create(PaymentMethodNonceRequest request) { 21 | NodeWrapper response = http.post(configuration.getMerchantPath() + "/payment_methods/" + request.getPaymentMethodToken() + "/nonces", request); 22 | return parseResponse(response); 23 | } 24 | 25 | public PaymentMethodNonce find(String paymentMethodNonce) { 26 | NodeWrapper response = http.get(configuration.getMerchantPath() + "/payment_method_nonces/" + paymentMethodNonce); 27 | return new PaymentMethodNonce(response); 28 | } 29 | 30 | public Result parseResponse(NodeWrapper response) { 31 | return new Result(response, PaymentMethodNonce.class); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/SubscriptionTransactionRequest.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.Transaction.Type; 4 | import java.math.BigDecimal; 5 | 6 | public class SubscriptionTransactionRequest extends Request { 7 | 8 | private BigDecimal amount; 9 | private String subscriptionId; 10 | private SubscriptionTransactionOptionsRequest subscriptionTransactionOptionsRequest; 11 | 12 | public SubscriptionTransactionRequest amount(BigDecimal amount) { 13 | this.amount = amount; 14 | return this; 15 | } 16 | 17 | public SubscriptionTransactionRequest subscriptionId(String subscriptionId) { 18 | this.subscriptionId = subscriptionId; 19 | return this; 20 | } 21 | 22 | public SubscriptionTransactionOptionsRequest options() { 23 | subscriptionTransactionOptionsRequest = new SubscriptionTransactionOptionsRequest(this); 24 | return subscriptionTransactionOptionsRequest; 25 | } 26 | 27 | @Override 28 | public String toXML() { 29 | return buildRequest("transaction").toXML(); 30 | } 31 | 32 | protected RequestBuilder buildRequest(String root) { 33 | return new RequestBuilder(root) 34 | .addElement("amount", amount) 35 | .addElement("subscriptionId", subscriptionId) 36 | .addElement("options", subscriptionTransactionOptionsRequest) 37 | .addElement("type", Type.SALE.toString().toLowerCase()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/SettlementBatchSummaryGateway.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.Http; 4 | import com.braintreegateway.util.NodeWrapper; 5 | import java.util.Calendar; 6 | 7 | public class SettlementBatchSummaryGateway { 8 | 9 | private Http http; 10 | private Configuration configuration; 11 | 12 | public SettlementBatchSummaryGateway(Http http, Configuration configuration) { 13 | this.http = http; 14 | this.configuration = configuration; 15 | } 16 | 17 | public Result generate(Calendar settlementDate) { 18 | SettlementBatchSummaryRequest request = new SettlementBatchSummaryRequest(); 19 | request.settlementDate(settlementDate); 20 | return doGenerate(request); 21 | } 22 | 23 | public Result generate(Calendar settlementDate, String groupByCustomField) { 24 | SettlementBatchSummaryRequest request = new SettlementBatchSummaryRequest(); 25 | request.settlementDate(settlementDate); 26 | request.groupByCustomField(groupByCustomField); 27 | return doGenerate(request); 28 | } 29 | 30 | private Result doGenerate(SettlementBatchSummaryRequest request) { 31 | NodeWrapper node = http.post(configuration.getMerchantPath() + "/settlement_batch_summary", request); 32 | return new Result(node, SettlementBatchSummary.class); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/ValidationError.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | /** 4 | * Represents an validation error from the gateway. 5 | */ 6 | public class ValidationError { 7 | private String attribute; 8 | private ValidationErrorCode code; 9 | private String message; 10 | 11 | public ValidationError(String attribute, ValidationErrorCode code, String message) { 12 | this.attribute = attribute; 13 | this.code = code; 14 | this.message = message; 15 | } 16 | 17 | /** 18 | * Returns the attribute that this error references, e.g. amount or expirationDate. 19 | * @return the attribute. 20 | */ 21 | public String getAttribute() { 22 | return attribute; 23 | } 24 | 25 | /** 26 | * Returns the {@link ValidationErrorCode} for the specific validation error. 27 | * @return a {@link ValidationErrorCode}. 28 | */ 29 | public ValidationErrorCode getCode() { 30 | return code; 31 | } 32 | 33 | /** 34 | * Returns the message associated with the validation error. Messages may change over time; rely on {@link #getCode()} for comparisons. 35 | * @return a String for the message. 36 | */ 37 | public String getMessage() { 38 | return message; 39 | } 40 | 41 | public boolean equals(Object e) { 42 | ValidationError ve = (ValidationError)e; 43 | return attribute.equals(ve.attribute) && code.equals(ve.code) && message.equals(ve.message); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/integrationtest/AndroidPayCardIT.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.integrationtest; 2 | 3 | import com.braintreegateway.*; 4 | import com.braintreegateway.test.Nonce; 5 | 6 | import java.util.*; 7 | 8 | import org.junit.jupiter.api.Test; 9 | import static org.junit.jupiter.api.Assertions.*; 10 | 11 | public class AndroidPayCardIT extends IntegrationTest { 12 | 13 | @Test 14 | public void testBinFields() { 15 | Customer customer = gateway.customer().create(new CustomerRequest()).getTarget(); 16 | PaymentMethodRequest request = new PaymentMethodRequest(). 17 | customerId(customer.getId()). 18 | paymentMethodNonce(Nonce.AndroidPayVisa); 19 | 20 | Result result = gateway.paymentMethod().create(request); 21 | assertTrue(result.isSuccess()); 22 | 23 | AndroidPayCard androidPayCard = (AndroidPayCard) result.getTarget(); 24 | assertNotNull(androidPayCard.getPrepaid()); 25 | assertNotNull(androidPayCard.getPrepaidReloadable()); 26 | assertNotNull(androidPayCard.getBusiness()); 27 | assertNotNull(androidPayCard.getConsumer()); 28 | assertNotNull(androidPayCard.getCorporate()); 29 | assertNotNull(androidPayCard.getPurchase()); 30 | 31 | AndroidPayCard foundAndroidPayCard = (AndroidPayCard) gateway.paymentMethod().find(androidPayCard.getToken()); 32 | assertEquals(androidPayCard.getToken(), foundAndroidPayCard.getToken()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/com/braintreegateway/testhelpers/MerchantAccountTestConstants.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway.testhelpers; 2 | 3 | public interface MerchantAccountTestConstants { 4 | public static final String DEFAULT_MERCHANT_ACCOUNT_ID = "sandbox_credit_card"; 5 | public static final String NON_DEFAULT_MERCHANT_ACCOUNT_ID = "sandbox_credit_card_non_default"; 6 | public static final String NON_DEFAULT_SUB_MERCHANT_ACCOUNT_ID = "sandbox_sub_merchant_account"; 7 | public static final String SANDBOX_MASTER_MERCHANT_ACCOUNT = "sandbox_master_merchant_account"; 8 | public static final String THREE_D_SECURE_MERCHANT_ACCOUNT_ID = "three_d_secure_merchant_account"; 9 | public static final String INDIA_THREE_D_SECURE_MERCHANT_ACCOUNT_ID = "india_three_d_secure_merchant_account"; 10 | public static final String PINLESS_DEBIT = "pinless_debit"; 11 | public static final String FAKE_AMEX_DIRECT_MERCHANT_ACCOUNT_ID = "fake_amex_direct_usd"; 12 | public static final String FAKE_FIRST_DATA_MERCHANT_ACCOUNT_ID = "fake_first_data_merchant_account"; 13 | public static final String FAKE_VENMO_ACCOUNT_MERCHANT_ACCOUNT_ID = "fake_first_data_venmo_account"; 14 | public static final String US_BANK_MERCHANT_ACCOUNT = "us_bank_merchant_account"; 15 | public static final String ANOTHER_US_BANK_MERCHANT_ACCOUNT = "another_us_bank_merchant_account"; 16 | public static final String ADYEN_MERCHANT_ACCOUNT_ID = "adyen_ma"; 17 | public static final String AIB_SWEDEN_MERCHANT_ACCOUNT_ID = "aib_swe_ma"; 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/braintreegateway/DisputeEvidence.java: -------------------------------------------------------------------------------- 1 | package com.braintreegateway; 2 | 3 | import com.braintreegateway.util.NodeWrapper; 4 | import java.util.Calendar; 5 | 6 | public final class DisputeEvidence { 7 | 8 | private final Calendar createdAt; 9 | private final Calendar sentToProcessorAt; 10 | private final String comment; 11 | private final String id; 12 | private final String url; 13 | private final String category; 14 | private final String sequenceNumber; 15 | 16 | public DisputeEvidence(NodeWrapper node) { 17 | createdAt = node.findDateTime("created-at"); 18 | sentToProcessorAt = node.findDate("sent-to-processor-at"); 19 | comment = node.findString("comment"); 20 | id = node.findString("id"); 21 | url = node.findString("url"); 22 | category = node.findString("category"); 23 | sequenceNumber = node.findString("sequence-number"); 24 | } 25 | 26 | public Calendar getCreatedAt() { 27 | return createdAt; 28 | } 29 | 30 | public Calendar getSentToProcessorAt() { 31 | return sentToProcessorAt; 32 | } 33 | 34 | public String getComment() { 35 | return comment; 36 | } 37 | 38 | public String getId() { 39 | return id; 40 | } 41 | 42 | public String getUrl() { 43 | return url; 44 | } 45 | 46 | public String getCategory() { 47 | return category; 48 | } 49 | 50 | public String getSequenceNumber() { 51 | return sequenceNumber; 52 | } 53 | } 54 | --------------------------------------------------------------------------------