Skip to content

Commit

Permalink
Merge pull request braintree#41 from braintree/shared_vault_parameters
Browse files Browse the repository at this point in the history
modest/product #178 - Adds shared vault parameters
  • Loading branch information
joshuaknox committed Mar 2, 2016
2 parents f974e72 + fbc8351 commit 765029c
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/main/java/com/braintreegateway/TransactionRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public class TransactionRequest extends Request {
private String threeDSecureToken;
private Boolean threeDSecureTransaction;

private String sharedPaymentMethodToken;
private String sharedCustomerId;
private String sharedShippingAddressId;
private String sharedBillingAddressId;

public TransactionRequest() {
this.customFields = new HashMap<String, String>();
this.threeDSecureTransaction = false;
Expand Down Expand Up @@ -193,6 +198,26 @@ public TransactionRequest threeDSecureToken(String threeDSecureToken) {
return this;
}

public TransactionRequest sharedPaymentMethodToken(String sharedPaymentMethodToken) {
this.sharedPaymentMethodToken = sharedPaymentMethodToken;
return this;
}

public TransactionRequest sharedCustomerId(String sharedCustomerId) {
this.sharedCustomerId = sharedCustomerId;
return this;
}

public TransactionRequest sharedShippingAddressId(String sharedShippingAddressId) {
this.sharedShippingAddressId = sharedShippingAddressId;
return this;
}

public TransactionRequest sharedBillingAddressId(String sharedBillingAddressId) {
this.sharedBillingAddressId = sharedBillingAddressId;
return this;
}

@Override
public String toQueryString() {
return toQueryString("transaction");
Expand Down Expand Up @@ -240,6 +265,10 @@ protected RequestBuilder buildRequest(String root) {
addElement("deviceSessionId", deviceSessionId).
addElement("fraudMerchantId", fraudMerchantId).
addElement("venmoSdkPaymentMethodCode", venmoSdkPaymentMethodCode).
addElement("sharedPaymentMethodToken", sharedPaymentMethodToken).
addElement("sharedCustomerId", sharedCustomerId).
addElement("sharedShippingAddressId", sharedShippingAddressId).
addElement("sharedBillingAddressId", sharedBillingAddressId).
addElement("serviceFeeAmount", serviceFeeAmount);

if (!customFields.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4319,4 +4319,43 @@ public void cannotCreatePartialSettlementTransactionsOnPartialSettlementTransact
assertEquals(ValidationErrorCode.TRANSACTION_CANNOT_SUBMIT_FOR_PARTIAL_SETTLEMENT,
partialSettlementResult2.getErrors().forObject("transaction").onField("base").get(0).getCode());
}

@Test
public void sharedPaymentMethods() {
BraintreeGateway sharerGateway = new BraintreeGateway(Environment.DEVELOPMENT, "integration_merchant_public_id", "oauth_app_partner_user_public_key", "oauth_app_partner_user_private_key");
Customer customer = sharerGateway.customer().create(new CustomerRequest().
creditCard().
number("5105105105105100").
expirationDate("05/19").
billingAddress().
postalCode("94107").
done().
done()
).getTarget();
CreditCard card = customer.getCreditCards().get(0);
Address billingAddress = card.getBillingAddress();
Address shippingAddress = sharerGateway.address().create(customer.getId(),
new AddressRequest().postalCode("94107")).getTarget();

BraintreeGateway oauthGateway = new BraintreeGateway("client_id$development$integration_client_id", "client_secret$development$integration_client_secret");
String code = TestHelper.createOAuthGrant(oauthGateway, "integration_merchant_id", "shared_vault_transactions");

OAuthCredentialsRequest oauthRequest = new OAuthCredentialsRequest().
code(code).
scope("shared_vault_transactions");

Result<OAuthCredentials> accessTokenResult = oauthGateway.oauth().createTokenFromCode(oauthRequest);

BraintreeGateway gateway = new BraintreeGateway(accessTokenResult.getTarget().getAccessToken());

TransactionRequest request = new TransactionRequest().
amount(TransactionAmount.AUTHORIZE.amount).
sharedPaymentMethodToken(card.getToken()).
sharedCustomerId(customer.getId()).
sharedShippingAddressId(shippingAddress.getId()).
sharedBillingAddressId(billingAddress.getId());

Result<Transaction> result = gateway.transaction().sale(request);
assertTrue(result.isSuccess());
}
}

0 comments on commit 765029c

Please sign in to comment.