Skip to content

Commit

Permalink
2.54.0
Browse files Browse the repository at this point in the history
  • Loading branch information
braintreeps committed Jan 14, 2016
1 parent 22471fc commit 52c728f
Show file tree
Hide file tree
Showing 20 changed files with 556 additions and 285 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.54.0
* Add verification create API
* Add support for options in `submit_for_settlement` transaction flows

## 2.53.0
* Include Coinbase Accounts in `Customer#getPaymentMethods` (Thanks @danmidwood)
* Add VenmoAccount
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.braintreepayments.gateway</groupId>
<artifactId>braintree-java</artifactId>
<version>2.53.0-SNAPSHOT</version>
<version>2.54.0-SNAPSHOT</version>
<description>Java Client Library for Braintree Payments Gateway</description>
<packaging>jar</packaging>
<name>Braintree Gateway Java Client Library</name>
Expand Down Expand Up @@ -30,7 +30,7 @@
<developerConnection>
${scmConnection}
</developerConnection>
<tag>2.53.0</tag>
<tag>2.54.0</tag>
</scm>

<distributionManagement>
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/braintreegateway/BraintreeGateway.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public BraintreeGateway(Environment environment, String merchantId, String publi
this.http = new Http(configuration);
}

public BraintreeGateway(String environment, String merchantId, String publicKey, String privateKey) {
this.configuration = new Configuration(environment, merchantId, publicKey, privateKey);
this.http = new Http(configuration);
}

public BraintreeGateway(String clientId, String clientSecret) {
this.configuration = new Configuration(clientId, clientSecret);
this.http = new Http(configuration);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/braintreegateway/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ public Configuration(Environment environment, String merchantId, String publicKe
this.privateKey = privateKey;
}

public Configuration(String environment, String merchantId, String publicKey, String privateKey) {
this.environment = Environment.parseEnvironment(environment);
this.merchantId = merchantId;
this.publicKey = publicKey;
this.privateKey = privateKey;
}

public Configuration(String clientId, String clientSecret) {
CredentialsParser parser = new CredentialsParser(clientId, clientSecret);
this.environment = parser.environment;
Expand Down
10 changes: 1 addition & 9 deletions src/main/java/com/braintreegateway/CredentialsParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,7 @@ public CredentialsParser(String accessToken) {

private Environment parseEnvironment(String credential) {
String environment = credential.split("\\$")[1];
if (environment.equals("development") || environment.equals("integration")) {
return Environment.DEVELOPMENT;
} else if (environment.equals("sandbox")) {
return Environment.SANDBOX;
} else if (environment.equals("production")) {
return Environment.PRODUCTION;
} else {
throw new IllegalArgumentException("Unknown environment: " + environment);
}
return Environment.parseEnvironment(environment);
}

private String parseMerchantId(String accessToken) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package com.braintreegateway;

public class CreditCardVerificationBillingAddressRequest extends Request {
private CreditCardVerificationCreditCardRequest parent;
private String company;
private String countryCodeAlpha2;
private String countryCodeAlpha3;
private String countryCodeNumeric;
private String countryName;
private String extendedAddress;
private String firstName;
private String lastName;
private String locality;
private String postalCode;
private String region;
private String streetAddress;

public CreditCardVerificationBillingAddressRequest(CreditCardVerificationCreditCardRequest parent) {
this.parent = parent;
}

public CreditCardVerificationBillingAddressRequest company(String company) {
this.company = company;
return this;
}

public CreditCardVerificationBillingAddressRequest countryCodeAlpha2(String countryCodeAlpha2) {
this.countryCodeAlpha2 = countryCodeAlpha2;
return this;
}

public CreditCardVerificationBillingAddressRequest countryCodeAlpha3(String countryCodeAlpha3) {
this.countryCodeAlpha3 = countryCodeAlpha3;
return this;
}

public CreditCardVerificationBillingAddressRequest countryCodeNumeric(String countryCodeNumeric) {
this.countryCodeNumeric = countryCodeNumeric;
return this;
}

public CreditCardVerificationBillingAddressRequest countryName(String countryName) {
this.countryName = countryName;
return this;
}

public CreditCardVerificationBillingAddressRequest extendedAddress(String extendedAddress) {
this.extendedAddress = extendedAddress;
return this;
}

public CreditCardVerificationBillingAddressRequest firstName(String firstName) {
this.firstName = firstName;
return this;
}

public CreditCardVerificationBillingAddressRequest lastName(String lastName) {
this.lastName = lastName;
return this;
}

public CreditCardVerificationBillingAddressRequest locality(String locality) {
this.locality = locality;
return this;
}

public CreditCardVerificationBillingAddressRequest postalCode(String postalCode) {
this.postalCode = postalCode;
return this;
}

public CreditCardVerificationBillingAddressRequest region(String region) {
this.region = region;
return this;
}

public CreditCardVerificationBillingAddressRequest streetAddress(String streetAddress) {
this.streetAddress = streetAddress;
return this;
}

public CreditCardVerificationCreditCardRequest done() {
return parent;
}

@Override
public String toXML() {
return buildRequest("billingAddress").toXML();
}

protected RequestBuilder buildRequest(String root) {
RequestBuilder builder = new RequestBuilder(root).
addElement("company", company).
addElement("countryCodeAlpha2", countryCodeAlpha2).
addElement("countryCodeAlpha3", countryCodeAlpha3).
addElement("countryCodeNumeric", countryCodeNumeric).
addElement("countryName", countryName).
addElement("extendedAddress", extendedAddress).
addElement("firstName", firstName).
addElement("lastName", lastName).
addElement("locality", locality).
addElement("postalCode", postalCode).
addElement("region", region).
addElement("streetAddress", streetAddress);
return builder;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.braintreegateway;

public class CreditCardVerificationCreditCardRequest extends Request {
private CreditCardVerificationRequest parent;
private String cardholderName;
private String cvv;
private String expirationDate;
private String expirationMonth;
private String expirationYear;
private String number;
private CreditCardVerificationBillingAddressRequest billingAddress;

public CreditCardVerificationCreditCardRequest(CreditCardVerificationRequest parent) {
this.parent = parent;
}

public CreditCardVerificationRequest done() {
return parent;
}

public CreditCardVerificationCreditCardRequest cardholderName(String cardholderName) {
this.cardholderName = cardholderName;
return this;
}

public CreditCardVerificationCreditCardRequest cvv(String cvv) {
this.cvv = cvv;
return this;
}

public CreditCardVerificationCreditCardRequest expirationDate(String expirationDate) {
this.expirationDate = expirationDate;
return this;
}

public CreditCardVerificationCreditCardRequest expirationMonth(String expirationMonth) {
this.expirationMonth = expirationMonth;
return this;
}

public CreditCardVerificationCreditCardRequest expirationYear(String expirationYear) {
this.expirationYear = expirationYear;
return this;
}

public CreditCardVerificationCreditCardRequest number(String number) {
this.number = number;
return this;
}

public CreditCardVerificationBillingAddressRequest billingAddress() {
billingAddress = new CreditCardVerificationBillingAddressRequest(this);
return billingAddress;
}

@Override
public String toXML() {
return buildRequest("creditCard").toXML();
}

protected RequestBuilder buildRequest(String root) {
return new RequestBuilder(root).
addElement("cardholderName", cardholderName).
addElement("cvv", cvv).
addElement("number", number).
addElement("expirationDate", expirationDate).
addElement("expirationMonth", expirationMonth).
addElement("expirationYear", expirationYear).
addElement("billingAddress", billingAddress);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ public ResourceCollection<CreditCardVerification> search(CreditCardVerificationS
NodeWrapper node = http.post(configuration.getMerchantPath() + "/verifications/advanced_search_ids", query);
return new ResourceCollection<CreditCardVerification>(new CreditCardVerificationPager(this, query), node);
}

public Result<CreditCardVerification> create(CreditCardVerificationRequest request) {
NodeWrapper response = http.post(configuration.getMerchantPath() + "/verifications", request);
return new Result<CreditCardVerification>(response, CreditCardVerification.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.braintreegateway;

public class CreditCardVerificationOptionsRequest extends Request {
private CreditCardVerificationRequest parent;
private String merchantAccountId;
private String amount;

public CreditCardVerificationOptionsRequest(CreditCardVerificationRequest parent) {
this.parent = parent;
}

public CreditCardVerificationOptionsRequest merchantAccountId(String merchantAccountId) {
this.merchantAccountId = merchantAccountId;
return this;
}

public CreditCardVerificationOptionsRequest amount(String amount) {
this.amount = amount;
return this;
}

public CreditCardVerificationRequest done() {
return parent;
}

@Override
public String toXML() {
return buildRequest("options").toXML();
}

protected RequestBuilder buildRequest(String root) {
RequestBuilder builder = new RequestBuilder(root).
addElement("merchantAccountId", merchantAccountId).
addElement("amount", amount);
return builder;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.braintreegateway;

public class CreditCardVerificationRequest extends Request {

private CreditCardVerificationCreditCardRequest creditCardRequest;
private CreditCardVerificationOptionsRequest optionsRequest;

public CreditCardVerificationRequest() {
}

public CreditCardVerificationCreditCardRequest creditCard() {
creditCardRequest = new CreditCardVerificationCreditCardRequest(this);
return creditCardRequest;
}

public CreditCardVerificationOptionsRequest options() {
optionsRequest = new CreditCardVerificationOptionsRequest(this);
return optionsRequest;
}

@Override
public String toXML() {
return buildRequest("verification").toXML();
}

protected RequestBuilder buildRequest(String root) {
RequestBuilder builder = new RequestBuilder(root).
addElement("creditCard", creditCardRequest).
addElement("options", optionsRequest);
return builder;
}
}
16 changes: 16 additions & 0 deletions src/main/java/com/braintreegateway/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ public Environment(String baseURL, String authURL, String[] certificateFilenames
this.environmentName = environmentName;
}

public static Environment parseEnvironment(String environment) {
if (environment.equals("development") || environment.equals("integration")) {
return DEVELOPMENT;
} else if (environment.equals("sandbox")) {
return SANDBOX;
} else if (environment.equals("production")) {
return PRODUCTION;
} else {
throw new IllegalArgumentException("Unknown environment: " + environment);
}
}

private static String developmentBaseURL() {
if (System.getenv().get("GATEWAY_BASE_URL") != null) {
return System.getenv().get("GATEWAY_BASE_URL");
Expand All @@ -47,4 +59,8 @@ public static String developmentPort() {
public String getEnvironmentName() {
return this.environmentName;
}

public String toString() {
return getEnvironmentName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public String toQueryString(String root) {
public String toQueryString() {
return toQueryString("creditCard");
}

protected RequestBuilder buildRequest(String root) {
return new RequestBuilder(root).
addElement("cardholderName", cardholderName).
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/braintreegateway/TransactionGateway.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,18 @@ public Result<Transaction> voidTransaction(String id) {
*/
public Result<Transaction> submitForPartialSettlement(String id, BigDecimal amount) {
TransactionRequest request = new TransactionRequest().amount(amount);
return submitForPartialSettlement(id, request);
}

/**
* Submits a partial settlement transaction for the given id.
* @param id of the transaction to add the partial settlement transaction for.
* @param request the request.
* @return {@link Result}.
*/
public Result<Transaction> submitForPartialSettlement(String id, TransactionRequest request) {
NodeWrapper response = http.post(configuration.getMerchantPath() + "/transactions/" + id + "/submit_for_partial_settlement", request);
return new Result<Transaction>(response, Transaction.class);
}

}
Loading

0 comments on commit 52c728f

Please sign in to comment.