Skip to content

Commit

Permalink
core c8AKL5a9 - Add VenmoAccount
Browse files Browse the repository at this point in the history
  • Loading branch information
braintreeps committed Nov 18, 2015
1 parent 3696b4c commit 690d135
Show file tree
Hide file tree
Showing 11 changed files with 221 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/com/braintreegateway/Customer.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class Customer {
private List<AndroidPayCard> androidPayCards;
private List<AmexExpressCheckoutCard> amexExpressCheckoutCards;
private List<CoinbaseAccount> coinbaseAccounts;
private List<VenmoAccount> venmoAccounts;
private List<Address> addresses;

public Customer(NodeWrapper node) {
Expand Down Expand Up @@ -61,6 +62,10 @@ public Customer(NodeWrapper node) {
for (NodeWrapper coinbaseAccountResponse : node.findAll("coinbase-accounts/coinbase-account")) {
coinbaseAccounts.add(new CoinbaseAccount(coinbaseAccountResponse));
}
venmoAccounts = new ArrayList<VenmoAccount>();
for (NodeWrapper venmoAccountResponse : node.findAll("venmo-accounts/venmo-account")) {
venmoAccounts.add(new VenmoAccount(venmoAccountResponse));
}
addresses = new ArrayList<Address>();
for (NodeWrapper addressResponse : node.findAll("addresses/address")) {
addresses.add(new Address(addressResponse));
Expand Down Expand Up @@ -139,13 +144,18 @@ public List<AmexExpressCheckoutCard> getAmexExpressCheckoutCards() {
return Collections.unmodifiableList(amexExpressCheckoutCards);
}

public List<VenmoAccount> getVenmoAccounts() {
return Collections.unmodifiableList(venmoAccounts);
}

public List<? extends PaymentMethod> getPaymentMethods() {
List<PaymentMethod> paymentMethods = new ArrayList<PaymentMethod>();
paymentMethods.addAll(getCreditCards());
paymentMethods.addAll(getPayPalAccounts());
paymentMethods.addAll(getApplePayCards());
paymentMethods.addAll(getAndroidPayCards());
paymentMethods.addAll(getAmexExpressCheckoutCards());
paymentMethods.addAll(getVenmoAccounts());
return Collections.unmodifiableList(paymentMethods);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ public final class PaymentInstrumentType {
public static final String ANDROID_PAY_CARD = "android_pay_card";
public static final String AMEX_EXPRESS_CHECKOUT_CARD = "amex_express_checkout_card";
public static final String COINBASE_ACCOUNT = "coinbase_account";
public static final String VENMO_ACCOUNT = "venmo_account";
}
4 changes: 4 additions & 0 deletions src/main/java/com/braintreegateway/PaymentMethodGateway.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public PaymentMethod find(String token) {
return new AmexExpressCheckoutCard(response);
} else if (response.getElementName() == "coinbase-account") {
return new CoinbaseAccount(response);
} else if (response.getElementName() == "venmo-account") {
return new VenmoAccount(response);
} else {
return new UnknownPaymentMethod(response);
}
Expand All @@ -68,6 +70,8 @@ public Result<? extends PaymentMethod> parseResponse(NodeWrapper response) {
return new Result<AmexExpressCheckoutCard>(response, AmexExpressCheckoutCard.class);
} else if (response.getElementName() == "coinbase-account") {
return new Result<CoinbaseAccount>(response, CoinbaseAccount.class);
} else if (response.getElementName() == "venmo-account") {
return new Result<VenmoAccount>(response, VenmoAccount.class);
} else {
return new Result<UnknownPaymentMethod>(response, UnknownPaymentMethod.class);
}
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/braintreegateway/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public String toString() {
private ApplePayDetails applePayDetails;
private AndroidPayDetails androidPayDetails;
private AmexExpressCheckoutDetails amexExpressCheckoutDetails;
private VenmoAccountDetails venmoAccountDetails;
private String planId;
private String processorAuthorizationCode;
private String processorResponseCode;
Expand Down Expand Up @@ -215,6 +216,10 @@ public Transaction(NodeWrapper node) {
if (coinbaseNode != null) {
coinbaseDetails = new CoinbaseDetails(coinbaseNode);
}
NodeWrapper venmoAccountNode = node.findFirst("venmo-account");
if (venmoAccountNode != null) {
venmoAccountDetails = new VenmoAccountDetails(venmoAccountNode);
}
planId = node.findString("plan-id");
processorAuthorizationCode = node.findString("processor-authorization-code");
processorResponseCode = node.findString("processor-response-code");
Expand Down Expand Up @@ -392,6 +397,10 @@ public CoinbaseDetails getCoinbaseDetails() {
return coinbaseDetails;
}

public VenmoAccountDetails getVenmoAccountDetails() {
return venmoAccountDetails;
}

public String getPlanId() {
return planId;
}
Expand Down
78 changes: 78 additions & 0 deletions src/main/java/com/braintreegateway/VenmoAccount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.braintreegateway;

import com.braintreegateway.util.NodeWrapper;
import java.util.Calendar;
import java.util.List;
import java.util.ArrayList;

public class VenmoAccount implements PaymentMethod {
private String token;
private String username;
private String venmoUserId;
private String sourceDescription;
private String imageUrl;
private Calendar createdAt;
private Calendar updatedAt;
private List<Subscription> subscriptions;
private String customerId;
private Boolean isDefault;

public VenmoAccount(NodeWrapper node) {
this.token = node.findString("token");
this.username = node.findString("username");
this.venmoUserId = node.findString("venmo-user-id");
this.sourceDescription = node.findString("source-description");
this.imageUrl = node.findString("image-url");

this.createdAt = node.findDateTime("created-at");
this.updatedAt = node.findDateTime("updated-at");
this.subscriptions = new ArrayList<Subscription>();
for (NodeWrapper subscriptionResponse : node.findAll("subscriptions/subscription")) {
this.subscriptions.add(new Subscription(subscriptionResponse));
}

this.customerId = node.findString("customer-id");
this.isDefault = node.findBoolean("default");
}

public String getToken() {
return token;
}

public String getUsername() {
return username;
}

public String getVenmoUserId() {
return venmoUserId;
}

public String getSourceDescription() {
return sourceDescription;
}

public String getImageUrl() {
return imageUrl;
}

public Calendar getCreatedAt() {
return createdAt;
}

public Calendar getUpdatedAt() {
return updatedAt;
}

public List<Subscription> getSubscriptions() {
return subscriptions;
}

public String getCustomerId() {
return customerId;
}

public boolean isDefault() {
return isDefault;
}
}

41 changes: 41 additions & 0 deletions src/main/java/com/braintreegateway/VenmoAccountDetails.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.braintreegateway;

import com.braintreegateway.util.NodeWrapper;

public class VenmoAccountDetails {

private String token;
private String username;
private String venmoUserId;
private String imageUrl;
private String sourceDescription;

public VenmoAccountDetails(NodeWrapper node) {
this.token = node.findString("token");
this.username = node.findString("username");
this.venmoUserId = node.findString("venmo-user-id");
this.imageUrl = node.findString("image-url");
this.sourceDescription = node.findString("source-description");
}

public String getToken() {
return token;
}

public String getUsername() {
return username;
}

public String getVenmoUserId() {
return venmoUserId;
}

public String getImageUrl() {
return imageUrl;
}

public String getSourceDescription() {
return sourceDescription;
}

}
1 change: 1 addition & 0 deletions src/main/java/com/braintreegateway/test/Nonce.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class Nonce {
public static String AndroidPayMasterCard = "fake-android-pay-mastercard-nonce";
public static String AndroidPayAmEx = "fake-android-pay-amex-nonce";
public static String AmexExpressCheckout = "fake-amex-express-checkout-nonce";
public static String VenmoAccount = "fake-venmo-account-nonce";
public static String TransactableVisa = "fake-valid-visa-nonce";
public static String TransactableAmEx = "fake-valid-amex-nonce";
public static String TransactableMasterCard = "fake-valid-mastercard-nonce";
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/com/braintreegateway/integrationtest/CustomerIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,24 @@ public void createWithAmexExpressCheckoutCard() {
assertEquals(1, foundCustomer.getPaymentMethods().size());
}

@Test
public void createWithVenmoAccount() {
CustomerRequest request = new CustomerRequest()
.paymentMethodNonce(Nonce.VenmoAccount);
Customer customer = gateway.customer().create(request).getTarget();

Customer foundCustomer = gateway.customer().find(customer.getId());
assertEquals(customer.getId(), foundCustomer.getId());
assertNotNull(foundCustomer.getVenmoAccounts());
assertEquals(1, foundCustomer.getVenmoAccounts().size());
assertEquals(1, foundCustomer.getPaymentMethods().size());

VenmoAccount account = foundCustomer.getVenmoAccounts().get(0);
assertNotNull(account);
assertEquals(account.getUsername(), "venmojoe");
assertEquals(account.getVenmoUserId(), "Venmo-Joe-1");
}

@Test
public void findDuplicateCreditCardsGivenPaymentMethodToken() {
CustomerRequest request = new CustomerRequest().
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,39 @@ public void createAmexExpressCheckoutCardFromNonce() {
assertNotNull(amexExpressCheckoutCard.getToken());
}

@Test public void createVenmoAccountFromNonce() {
Result<Customer> customerResult = gateway.customer().create(new CustomerRequest());
assertTrue(customerResult.isSuccess());
Customer customer = customerResult.getTarget();

String nonce = Nonce.VenmoAccount;
PaymentMethodRequest request = new PaymentMethodRequest()
.customerId(customer.getId())
.paymentMethodNonce(nonce)
.options()
.makeDefault(true)
.done();

Result<? extends PaymentMethod> result = gateway.paymentMethod().create(request);

assertTrue(result.isSuccess());

PaymentMethod paymentMethod = result.getTarget();
assertNotNull(paymentMethod.getToken());
assertTrue(paymentMethod.isDefault());

VenmoAccount venmoAccount = (VenmoAccount) paymentMethod;
assertNotNull(venmoAccount.getToken());
assertNotNull(venmoAccount.getUsername());
assertNotNull(venmoAccount.getVenmoUserId());
assertNotNull(venmoAccount.getSourceDescription());
assertNotNull(venmoAccount.getCreatedAt());
assertNotNull(venmoAccount.getUpdatedAt());
assertNotNull(venmoAccount.getSubscriptions());
assertNotNull(venmoAccount.getImageUrl());
assertNotNull(venmoAccount.getCustomerId());
}

@Test
public void createAbstractPaymentMethod() {
Result<Customer> customerResult = gateway.customer().create(new CustomerRequest());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,31 @@ public void saleWithAmexExpressCheckoutCardNonce() {
assertNotNull(amexExpressCheckoutDetails.getSourceDescription());
}

@Test
public void saleWithVenmoAccountNonce() {
String venmoAccountNonce = Nonce.VenmoAccount;

TransactionRequest request = new TransactionRequest()
.merchantAccountId(FAKE_VENMO_ACCOUNT_MERCHANT_ACCOUNT_ID)
.amount(SandboxValues.TransactionAmount.AUTHORIZE.amount)
.paymentMethodNonce(venmoAccountNonce);

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

assertEquals(PaymentInstrumentType.VENMO_ACCOUNT, transaction.getPaymentInstrumentType());

VenmoAccountDetails venmoAccountDetails = transaction.getVenmoAccountDetails();
assertNotNull(venmoAccountDetails);

assertNull(venmoAccountDetails.getToken());
assertNotNull(venmoAccountDetails.getUsername());
assertNotNull(venmoAccountDetails.getVenmoUserId());
assertNotNull(venmoAccountDetails.getImageUrl());
assertNotNull(venmoAccountDetails.getSourceDescription());
}

@Test
public void saleWithThreeDSecureOptionRequired() {
TransactionRequest request = new TransactionRequest().
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ public interface MerchantAccountTestConstants {
public static final String SANDBOX_MASTER_MERCHANT_ACCOUNT = "sandbox_master_merchant_account";
public static final String THREE_D_SECURE_MERCHANT_ACCOUNT_ID = "three_d_secure_merchant_account";
public static final String FAKE_AMEX_DIRECT_MERCHANT_ACCOUNT_ID = "fake_amex_direct_usd";
public static final String FAKE_VENMO_ACCOUNT_MERCHANT_ACCOUNT_ID = "fake_first_data_venmo_account";
}

0 comments on commit 690d135

Please sign in to comment.