PageRenderTime 54ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/src/test/java/com/braintreegateway/integrationtest/PaymentMethodNonceIT.java

http://github.com/braintree/braintree_java
Java | 345 lines | 300 code | 45 blank | 0 comment | 0 complexity | d0d15b27cfde746a8f9df950c80f7646 MD5 | raw file
Possible License(s): MIT
  1. package com.braintreegateway.integrationtest;
  2. import com.braintreegateway.*;
  3. import com.braintreegateway.CreditCard.Commercial;
  4. import com.braintreegateway.CreditCard.DurbinRegulated;
  5. import com.braintreegateway.CreditCard.Debit;
  6. import com.braintreegateway.CreditCard.Healthcare;
  7. import com.braintreegateway.CreditCard.Payroll;
  8. import com.braintreegateway.CreditCard.Prepaid;
  9. import com.braintreegateway.testhelpers.TestHelper;
  10. import com.braintreegateway.testhelpers.MerchantAccountTestConstants;
  11. import com.braintreegateway.exceptions.NotFoundException;
  12. import java.math.BigDecimal;
  13. import org.junit.jupiter.api.Test;
  14. import static org.junit.jupiter.api.Assertions.*;
  15. public class PaymentMethodNonceIT extends IntegrationTest {
  16. @Test
  17. public void createFromExistingPaymentMethod() {
  18. Result<Customer> customerResult = gateway.customer().create(new CustomerRequest());
  19. Customer customer = customerResult.getTarget();
  20. String nonce = TestHelper.generateUnlockedNonce(gateway, null, SandboxValues.CreditCardNumber.VISA.number);
  21. PaymentMethodRequest request = new PaymentMethodRequest().
  22. customerId(customer.getId()).
  23. paymentMethodNonce(nonce);
  24. Result<? extends PaymentMethod> paymentMethodResult = gateway.paymentMethod().create(request);
  25. PaymentMethod paymentMethod = paymentMethodResult.getTarget();
  26. Result<PaymentMethodNonce> result = gateway.paymentMethodNonce().create(paymentMethod.getToken());
  27. assertTrue(result.isSuccess());
  28. PaymentMethodNonce newNonce = result.getTarget();
  29. assertNotNull(newNonce);
  30. assertNotNull(newNonce.getNonce());
  31. }
  32. @Test
  33. public void createReturnsAuthenticationInsightWhenRequested() {
  34. Result<Customer> customerResult = gateway.customer().create(new CustomerRequest());
  35. Customer customer = customerResult.getTarget();
  36. String nonce = TestHelper.generateUnlockedNonce(gateway, null, SandboxValues.CreditCardNumber.VISA.number);
  37. PaymentMethodRequest request = new PaymentMethodRequest().
  38. customerId(customer.getId()).
  39. paymentMethodNonce(nonce);
  40. Result<? extends PaymentMethod> paymentMethodResult = gateway.paymentMethod().create(request);
  41. PaymentMethod paymentMethod = paymentMethodResult.getTarget();
  42. PaymentMethodNonceRequest createRequest = new PaymentMethodNonceRequest().
  43. paymentMethodToken(paymentMethod.getToken()).
  44. merchantAccountId(MerchantAccountTestConstants.DEFAULT_MERCHANT_ACCOUNT_ID).
  45. authenticationInsight(Boolean.TRUE);
  46. Result<PaymentMethodNonce> result = gateway.paymentMethodNonce().create(createRequest);
  47. assertTrue(result.isSuccess());
  48. PaymentMethodNonce newNonce = result.getTarget();
  49. assertNotNull(newNonce);
  50. assertNotNull(newNonce.getNonce());
  51. assertNotNull(newNonce.getAuthenticationInsight());
  52. assertNotNull(newNonce.getAuthenticationInsight().getRegulationEnvironment());
  53. assertNull(newNonce.getAuthenticationInsight().getScaIndicator());
  54. }
  55. @Test
  56. public void createReturnsAuthenticationInsightWithScaRequirementWhenGivenAmount() {
  57. PaymentMethodNonceRequest createRequest = new PaymentMethodNonceRequest().
  58. paymentMethodToken("india_visa_credit").
  59. merchantAccountId(MerchantAccountTestConstants.INDIA_THREE_D_SECURE_MERCHANT_ACCOUNT_ID).
  60. authenticationInsight(Boolean.TRUE).
  61. authenticationInsightOptions().
  62. amount(new BigDecimal("2500")).
  63. done();
  64. Result<PaymentMethodNonce> result = gateway.paymentMethodNonce().create(createRequest);
  65. assertTrue(result.isSuccess());
  66. PaymentMethodNonce newNonce = result.getTarget();
  67. assertNotNull(newNonce);
  68. assertNotNull(newNonce.getNonce());
  69. assertNotNull(newNonce.getAuthenticationInsight());
  70. assertEquals("rbi", newNonce.getAuthenticationInsight().getRegulationEnvironment());
  71. assertEquals("sca_required", newNonce.getAuthenticationInsight().getScaIndicator());
  72. }
  73. @Test
  74. public void createReturnsAuthenticationInsightWithAnotherScaIndicator() {
  75. PaymentMethodNonceRequest createRequest = new PaymentMethodNonceRequest().
  76. paymentMethodToken("india_visa_credit").
  77. merchantAccountId(MerchantAccountTestConstants.INDIA_THREE_D_SECURE_MERCHANT_ACCOUNT_ID).
  78. authenticationInsight(Boolean.TRUE);
  79. Result<PaymentMethodNonce> result = gateway.paymentMethodNonce().create(createRequest);
  80. assertTrue(result.isSuccess());
  81. PaymentMethodNonce newNonce = result.getTarget();
  82. assertNotNull(newNonce);
  83. assertNotNull(newNonce.getNonce());
  84. assertNotNull(newNonce.getAuthenticationInsight());
  85. assertEquals("rbi", newNonce.getAuthenticationInsight().getRegulationEnvironment());
  86. assertNotEquals("sca_required", newNonce.getAuthenticationInsight().getScaIndicator());
  87. assertNotNull(newNonce.getAuthenticationInsight().getScaIndicator());
  88. }
  89. @Test
  90. public void createRaisesIfNotFound() {
  91. try {
  92. gateway.paymentMethodNonce().create("not-a-token");
  93. fail("Should throw NotFoundException");
  94. } catch (NotFoundException e) {
  95. }
  96. }
  97. @Test
  98. public void findCreditCardNonceReturnsValidValues() {
  99. String nonceString = "fake-valid-nonce";
  100. PaymentMethodNonce nonce = gateway.paymentMethodNonce().find(nonceString);
  101. assertNotNull(nonce);
  102. assertEquals(nonceString, nonce.getNonce());
  103. assertEquals(false, nonce.isConsumed());
  104. assertEquals(false, nonce.isDefault());
  105. assertNotNull(nonce.getDetails());
  106. assertEquals("401288", nonce.getDetails().getBin());
  107. assertEquals("81", nonce.getDetails().getLastTwo());
  108. assertEquals("Visa", nonce.getDetails().getCardType());
  109. }
  110. @Test
  111. public void findVenmoAccountNonceReturnsValidValues() {
  112. String nonceString = "fake-venmo-account-nonce";
  113. PaymentMethodNonce nonce = gateway.paymentMethodNonce().find(nonceString);
  114. assertNotNull(nonce);
  115. assertEquals(nonceString, nonce.getNonce());
  116. assertEquals(false, nonce.isConsumed());
  117. assertEquals(false, nonce.isDefault());
  118. assertNotNull(nonce.getDetails());
  119. assertEquals("99", nonce.getDetails().getLastTwo());
  120. assertEquals("venmojoe", nonce.getDetails().getUsername());
  121. assertEquals("Venmo-Joe-1", nonce.getDetails().getVenmoUserId());
  122. }
  123. @Test
  124. public void findApplePayCardNonceReturnsValidValues() {
  125. String nonceString = "fake-apple-pay-visa-nonce";
  126. PaymentMethodNonce nonce = gateway.paymentMethodNonce().find(nonceString);
  127. assertNotNull(nonce);
  128. assertEquals(nonceString, nonce.getNonce());
  129. assertEquals(false, nonce.isConsumed());
  130. assertEquals(false, nonce.isDefault());
  131. assertNotNull(nonce.getDetails());
  132. assertEquals("Visa", nonce.getDetails().getCardType());
  133. assertEquals("Visa Apple Pay Cardholder", nonce.getDetails().getCardholderName());
  134. assertEquals("Visa 8886", nonce.getDetails().getPaymentInstrumentName());
  135. assertEquals("81", nonce.getDetails().getDpanLastTwo());
  136. }
  137. @Test
  138. public void findPayPalAccountNonceReturnsValidValues() {
  139. String nonceString = "fake-paypal-billing-agreement-nonce";
  140. PaymentMethodNonce nonce = gateway.paymentMethodNonce().find(nonceString);
  141. assertNotNull(nonce);
  142. assertEquals(nonceString, nonce.getNonce());
  143. assertEquals(false, nonce.isConsumed());
  144. assertEquals(false, nonce.isDefault());
  145. assertNotNull(nonce.getDetails());
  146. assertEquals("jane.doe@paypal.com", nonce.getDetails().getEmail());
  147. }
  148. @Test
  149. public void findPayPalAccountNonceWithValidPayerInfoValues() {
  150. String nonceString = "fake-paypal-one-time-nonce";
  151. PaymentMethodNonce nonce = gateway.paymentMethodNonce().find(nonceString);
  152. assertNotNull(nonce);
  153. assertEquals(nonceString, nonce.getNonce());
  154. assertEquals(false, nonce.isConsumed());
  155. assertEquals(false, nonce.isDefault());
  156. assertNotNull(nonce.getDetails().getPayerInfo());
  157. PaymentMethodNonceDetailsPayerInfo payerInfo = nonce.getDetails().getPayerInfo();
  158. assertNotNull(payerInfo.getEmail());
  159. assertNotNull(payerInfo.getPayerId());
  160. assertNotNull(payerInfo.getBillingAddress().getRecipientName());
  161. assertNotNull(payerInfo.getBillingAddress().getStreetAddress());
  162. assertNotNull(payerInfo.getBillingAddress().getLocality());
  163. assertNotNull(payerInfo.getBillingAddress().getRegion());
  164. assertNotNull(payerInfo.getBillingAddress().getPostalCode());
  165. assertNotNull(payerInfo.getBillingAddress().getCountryCodeAlpha2());
  166. assertNotNull(payerInfo.getShippingAddress().getRecipientName());
  167. assertNotNull(payerInfo.getShippingAddress().getStreetAddress());
  168. assertNotNull(payerInfo.getShippingAddress().getLocality());
  169. assertNotNull(payerInfo.getShippingAddress().getRegion());
  170. assertNotNull(payerInfo.getShippingAddress().getPostalCode());
  171. assertNotNull(payerInfo.getShippingAddress().getCountryCodeAlpha2());
  172. }
  173. @Test
  174. public void findCreditCardNonceReturnsValidBinDataPrepaidValue() {
  175. String nonceString = "fake-valid-prepaid-nonce";
  176. PaymentMethodNonce nonce = gateway.paymentMethodNonce().find(nonceString);
  177. assertNotNull(nonce);
  178. assertEquals(nonceString, nonce.getNonce());
  179. assertEquals(Prepaid.YES, nonce.getBinData().getPrepaid());
  180. }
  181. @Test
  182. public void findCreditCardNonceReturnsValidBinDataCommercialValue() {
  183. String nonceString = "fake-valid-commercial-nonce";
  184. PaymentMethodNonce nonce = gateway.paymentMethodNonce().find(nonceString);
  185. assertNotNull(nonce);
  186. assertEquals(nonceString, nonce.getNonce());
  187. assertEquals(Commercial.YES, nonce.getBinData().getCommercial());
  188. }
  189. @Test
  190. public void findCreditCardNonceReturnsValidBinDataDurbinRegulatedValue() {
  191. String nonceString = "fake-valid-durbin-regulated-nonce";
  192. PaymentMethodNonce nonce = gateway.paymentMethodNonce().find(nonceString);
  193. assertNotNull(nonce);
  194. assertEquals(nonceString, nonce.getNonce());
  195. assertEquals(DurbinRegulated.YES, nonce.getBinData().getDurbinRegulated());
  196. }
  197. @Test
  198. public void findCreditCardNonceReturnsValidBinDataHealthcareValue() {
  199. String nonceString = "fake-valid-healthcare-nonce";
  200. PaymentMethodNonce nonce = gateway.paymentMethodNonce().find(nonceString);
  201. assertNotNull(nonce);
  202. assertEquals(nonceString, nonce.getNonce());
  203. assertEquals(Healthcare.YES, nonce.getBinData().getHealthcare());
  204. assertEquals("J3", nonce.getBinData().getProductId());
  205. }
  206. @Test
  207. public void findCreditCardNonceReturnsValidBinDataDebitValue() {
  208. String nonceString = "fake-valid-debit-nonce";
  209. PaymentMethodNonce nonce = gateway.paymentMethodNonce().find(nonceString);
  210. assertNotNull(nonce);
  211. assertEquals(nonceString, nonce.getNonce());
  212. assertEquals(Debit.YES, nonce.getBinData().getDebit());
  213. }
  214. @Test
  215. public void findCreditCardNonceReturnsValidBinDataPayrollValue() {
  216. String nonceString = "fake-valid-payroll-nonce";
  217. PaymentMethodNonce nonce = gateway.paymentMethodNonce().find(nonceString);
  218. assertNotNull(nonce);
  219. assertEquals(nonceString, nonce.getNonce());
  220. assertEquals(Payroll.YES, nonce.getBinData().getPayroll());
  221. assertEquals("MSA", nonce.getBinData().getProductId());
  222. }
  223. @Test
  224. public void findCreditCardNonceReturnsValidBinDataCountryOfIssuanceValue() {
  225. String nonceString = "fake-valid-country-of-issuance-cad-nonce";
  226. PaymentMethodNonce nonce = gateway.paymentMethodNonce().find(nonceString);
  227. assertNotNull(nonce);
  228. assertEquals(nonceString, nonce.getNonce());
  229. assertEquals("CAN", nonce.getBinData().getCountryOfIssuance());
  230. }
  231. @Test
  232. public void findCreditCardNonceReturnsValidBinDataIssuingBankValue() {
  233. String nonceString = "fake-valid-issuing-bank-network-only-nonce";
  234. PaymentMethodNonce nonce = gateway.paymentMethodNonce().find(nonceString);
  235. assertNotNull(nonce);
  236. assertEquals(nonceString, nonce.getNonce());
  237. assertEquals("NETWORK ONLY", nonce.getBinData().getIssuingBank());
  238. }
  239. @Test
  240. public void findCreditCardNonceReturnsValidBinDataUnknownValues() {
  241. String nonceString = "fake-valid-unknown-indicators-nonce";
  242. PaymentMethodNonce nonce = gateway.paymentMethodNonce().find(nonceString);
  243. assertNotNull(nonce);
  244. assertEquals(nonceString, nonce.getNonce());
  245. assertEquals(Commercial.UNKNOWN, nonce.getBinData().getCommercial());
  246. assertEquals(DurbinRegulated.UNKNOWN, nonce.getBinData().getDurbinRegulated());
  247. assertEquals(Debit.UNKNOWN, nonce.getBinData().getDebit());
  248. assertEquals(Healthcare.UNKNOWN, nonce.getBinData().getHealthcare());
  249. assertEquals(Payroll.UNKNOWN, nonce.getBinData().getPayroll());
  250. assertEquals(Prepaid.UNKNOWN, nonce.getBinData().getPrepaid());
  251. assertEquals("Unknown", nonce.getBinData().getProductId());
  252. assertEquals("Unknown", nonce.getBinData().getCountryOfIssuance());
  253. assertEquals("Unknown", nonce.getBinData().getIssuingBank());
  254. }
  255. @Test
  256. public void findReturnsPaymentMethodNonceWith3DSDetails() {
  257. CreditCardRequest creditCardRequest = new CreditCardRequest().
  258. number(SandboxValues.CreditCardNumber.VISA.number).
  259. expirationMonth("12").
  260. expirationYear("2020");
  261. String nonce = TestHelper.generateThreeDSecureNonce(gateway, creditCardRequest);
  262. PaymentMethodNonce foundNonce = gateway.paymentMethodNonce().find(nonce);
  263. ThreeDSecureInfo info = foundNonce.getThreeDSecureInfo();
  264. assertEquals(nonce, foundNonce.getNonce());
  265. assertTrue(info.isLiabilityShifted());
  266. assertTrue(info.isLiabilityShiftPossible());
  267. assertNotNull(info.getStatus());
  268. assertEquals("test_cavv", info.getCAVV());
  269. assertEquals("test_xid", info.getXID());
  270. assertEquals("test_eci", info.getECIFlag());
  271. assertEquals("1.0.2", info.getThreeDSecureVersion());
  272. assertEquals((String)null, info.getDsTransactionId());
  273. assertTrue(info.getThreeDSecureLookupInfo() instanceof ThreeDSecureLookupInfo);
  274. assertTrue(info.getThreeDSecureAuthenticateInfo() instanceof ThreeDSecureAuthenticateInfo);
  275. }
  276. @Test
  277. public void findReturnsNull3DSDetailsIfNotPresent() {
  278. Result<Customer> customerResult = gateway.customer().create(new CustomerRequest());
  279. Customer customer = customerResult.getTarget();
  280. String nonce = TestHelper.generateUnlockedNonce(gateway, null, SandboxValues.CreditCardNumber.VISA.number);
  281. PaymentMethodNonce foundNonce = gateway.paymentMethodNonce().find(nonce);
  282. assertNull(foundNonce.getThreeDSecureInfo());
  283. }
  284. @Test
  285. public void findReturnsNullAuthenticationInsight() {
  286. String nonceString = "fake-valid-nonce";
  287. PaymentMethodNonce nonce = gateway.paymentMethodNonce().find(nonceString);
  288. assertNotNull(nonce);
  289. assertEquals(nonceString, nonce.getNonce());
  290. assertNull(nonce.getAuthenticationInsight());
  291. }
  292. @Test
  293. public void findRaisesIfNotFound() {
  294. try {
  295. gateway.paymentMethodNonce().find("not-a-nonce");
  296. fail("Should throw NotFoundException");
  297. } catch (NotFoundException e) {
  298. }
  299. }
  300. }