diff --git a/src/main/java/com/braintreegateway/Customer.java b/src/main/java/com/braintreegateway/Customer.java index e9db6608..bdcc00f2 100644 --- a/src/main/java/com/braintreegateway/Customer.java +++ b/src/main/java/com/braintreegateway/Customer.java @@ -23,6 +23,7 @@ public class Customer { private List androidPayCards; private List amexExpressCheckoutCards; private List coinbaseAccounts; + private List venmoAccounts; private List
addresses; public Customer(NodeWrapper node) { @@ -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(); + for (NodeWrapper venmoAccountResponse : node.findAll("venmo-accounts/venmo-account")) { + venmoAccounts.add(new VenmoAccount(venmoAccountResponse)); + } addresses = new ArrayList
(); for (NodeWrapper addressResponse : node.findAll("addresses/address")) { addresses.add(new Address(addressResponse)); @@ -139,6 +144,10 @@ public List getAmexExpressCheckoutCards() { return Collections.unmodifiableList(amexExpressCheckoutCards); } + public List getVenmoAccounts() { + return Collections.unmodifiableList(venmoAccounts); + } + public List getPaymentMethods() { List paymentMethods = new ArrayList(); paymentMethods.addAll(getCreditCards()); @@ -146,6 +155,7 @@ public List getPaymentMethods() { paymentMethods.addAll(getApplePayCards()); paymentMethods.addAll(getAndroidPayCards()); paymentMethods.addAll(getAmexExpressCheckoutCards()); + paymentMethods.addAll(getVenmoAccounts()); return Collections.unmodifiableList(paymentMethods); } diff --git a/src/main/java/com/braintreegateway/PaymentInstrumentType.java b/src/main/java/com/braintreegateway/PaymentInstrumentType.java index c54ed7e4..a034cb43 100644 --- a/src/main/java/com/braintreegateway/PaymentInstrumentType.java +++ b/src/main/java/com/braintreegateway/PaymentInstrumentType.java @@ -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"; } diff --git a/src/main/java/com/braintreegateway/PaymentMethodGateway.java b/src/main/java/com/braintreegateway/PaymentMethodGateway.java index 5e7ecc27..a5130ab0 100644 --- a/src/main/java/com/braintreegateway/PaymentMethodGateway.java +++ b/src/main/java/com/braintreegateway/PaymentMethodGateway.java @@ -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); } @@ -68,6 +70,8 @@ public Result parseResponse(NodeWrapper response) { return new Result(response, AmexExpressCheckoutCard.class); } else if (response.getElementName() == "coinbase-account") { return new Result(response, CoinbaseAccount.class); + } else if (response.getElementName() == "venmo-account") { + return new Result(response, VenmoAccount.class); } else { return new Result(response, UnknownPaymentMethod.class); } diff --git a/src/main/java/com/braintreegateway/Transaction.java b/src/main/java/com/braintreegateway/Transaction.java index 37922b88..26c14cb7 100644 --- a/src/main/java/com/braintreegateway/Transaction.java +++ b/src/main/java/com/braintreegateway/Transaction.java @@ -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; @@ -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"); @@ -392,6 +397,10 @@ public CoinbaseDetails getCoinbaseDetails() { return coinbaseDetails; } + public VenmoAccountDetails getVenmoAccountDetails() { + return venmoAccountDetails; + } + public String getPlanId() { return planId; } diff --git a/src/main/java/com/braintreegateway/VenmoAccount.java b/src/main/java/com/braintreegateway/VenmoAccount.java new file mode 100644 index 00000000..850777a8 --- /dev/null +++ b/src/main/java/com/braintreegateway/VenmoAccount.java @@ -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 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(); + 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 getSubscriptions() { + return subscriptions; + } + + public String getCustomerId() { + return customerId; + } + + public boolean isDefault() { + return isDefault; + } +} + diff --git a/src/main/java/com/braintreegateway/VenmoAccountDetails.java b/src/main/java/com/braintreegateway/VenmoAccountDetails.java new file mode 100644 index 00000000..6e01c6fb --- /dev/null +++ b/src/main/java/com/braintreegateway/VenmoAccountDetails.java @@ -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; + } + +} diff --git a/src/main/java/com/braintreegateway/test/Nonce.java b/src/main/java/com/braintreegateway/test/Nonce.java index 008dfb09..d91c2967 100644 --- a/src/main/java/com/braintreegateway/test/Nonce.java +++ b/src/main/java/com/braintreegateway/test/Nonce.java @@ -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"; diff --git a/src/test/java/com/braintreegateway/integrationtest/CustomerIT.java b/src/test/java/com/braintreegateway/integrationtest/CustomerIT.java index 142856a8..4f316609 100644 --- a/src/test/java/com/braintreegateway/integrationtest/CustomerIT.java +++ b/src/test/java/com/braintreegateway/integrationtest/CustomerIT.java @@ -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(). diff --git a/src/test/java/com/braintreegateway/integrationtest/PaymentMethodIT.java b/src/test/java/com/braintreegateway/integrationtest/PaymentMethodIT.java index c047e143..5eebfce2 100644 --- a/src/test/java/com/braintreegateway/integrationtest/PaymentMethodIT.java +++ b/src/test/java/com/braintreegateway/integrationtest/PaymentMethodIT.java @@ -221,6 +221,39 @@ public void createAmexExpressCheckoutCardFromNonce() { assertNotNull(amexExpressCheckoutCard.getToken()); } + @Test public void createVenmoAccountFromNonce() { + Result 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 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 customerResult = gateway.customer().create(new CustomerRequest()); diff --git a/src/test/java/com/braintreegateway/integrationtest/TransactionIT.java b/src/test/java/com/braintreegateway/integrationtest/TransactionIT.java index f5f6dc5f..89924b6d 100644 --- a/src/test/java/com/braintreegateway/integrationtest/TransactionIT.java +++ b/src/test/java/com/braintreegateway/integrationtest/TransactionIT.java @@ -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 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(). diff --git a/src/test/java/com/braintreegateway/testhelpers/MerchantAccountTestConstants.java b/src/test/java/com/braintreegateway/testhelpers/MerchantAccountTestConstants.java index 1585f977..0d592c67 100644 --- a/src/test/java/com/braintreegateway/testhelpers/MerchantAccountTestConstants.java +++ b/src/test/java/com/braintreegateway/testhelpers/MerchantAccountTestConstants.java @@ -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"; }