@Test public void startPayment_callsExceptionListener_localPaymentRequestIsNull() throws InvalidArgumentException, JSONException { LocalPayment.startPayment(mBraintreeFragment, null, new BraintreeResponseListener<LocalPaymentRequest>() { @Override public void onResponse(LocalPaymentRequest localPaymentRequest) { LocalPayment.approvePayment(mBraintreeFragment, localPaymentRequest); } }); verify(mBraintreeFragment).postCallback(any(BraintreeException.class)); }
@Test public void startPayment_callsExceptionListener_whenListenerIsNull() throws InvalidArgumentException, JSONException { LocalPayment.startPayment(mBraintreeFragment, getIdealLocalPaymentRequest(),null); verify(mBraintreeFragment).postCallback(any(BraintreeException.class)); }
@Test public void startPayment_callsExceptionListener_whenApprovalUrlIsSet() throws InvalidArgumentException, JSONException { LocalPaymentRequest request = getIdealLocalPaymentRequest() .approvalUrl("aUrl"); LocalPayment.startPayment(mBraintreeFragment, request, new BraintreeResponseListener<LocalPaymentRequest>() { @Override public void onResponse(LocalPaymentRequest localPaymentRequest) { LocalPayment.approvePayment(mBraintreeFragment, localPaymentRequest); } }); verify(mBraintreeFragment).postCallback(any(BraintreeException.class)); }
@Test public void startPayment_callsExceptionListener_amountIsNull() throws InvalidArgumentException, JSONException { LocalPaymentRequest request = getIdealLocalPaymentRequest() .amount(null); LocalPayment.startPayment(mBraintreeFragment, request, new BraintreeResponseListener<LocalPaymentRequest>() { @Override public void onResponse(LocalPaymentRequest localPaymentRequest) { LocalPayment.approvePayment(mBraintreeFragment, localPaymentRequest); } }); verify(mBraintreeFragment).postCallback(any(BraintreeException.class)); }
@Test public void startPayment_callsExceptionListener_whenPaymentIdIsSet() throws InvalidArgumentException, JSONException { LocalPaymentRequest request = getIdealLocalPaymentRequest() .paymentId("pid"); LocalPayment.startPayment(mBraintreeFragment, request, new BraintreeResponseListener<LocalPaymentRequest>() { @Override public void onResponse(LocalPaymentRequest localPaymentRequest) { LocalPayment.approvePayment(mBraintreeFragment, localPaymentRequest); } }); verify(mBraintreeFragment).postCallback(any(BraintreeException.class)); }
@Test public void startPayment_callsExceptionListener_paymentTypeIsNull() throws InvalidArgumentException, JSONException { LocalPaymentRequest request = getIdealLocalPaymentRequest() .paymentType(null); LocalPayment.startPayment(mBraintreeFragment, request, new BraintreeResponseListener<LocalPaymentRequest>() { @Override public void onResponse(LocalPaymentRequest localPaymentRequest) { LocalPayment.approvePayment(mBraintreeFragment, localPaymentRequest); } }); verify(mBraintreeFragment).postCallback(any(BraintreeException.class)); }
@Test public void startPayment_success_sendsAnalyticsEvent() throws JSONException { final CountDownLatch latch = new CountDownLatch(1); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { HttpResponseCallback callback = (HttpResponseCallback) invocation.getArguments()[2]; callback.success(stringFromFixture("payment_methods/local_payment_create_response.json")); return null; } }).when(mMockHttpClient).post(eq("/v1/paypal_hermes/create_payment_resource"), any(String.class), any(HttpResponseCallback.class)); LocalPayment.startPayment(mBraintreeFragment, getIdealLocalPaymentRequest(), new BraintreeResponseListener<LocalPaymentRequest>() { @Override public void onResponse(LocalPaymentRequest localPaymentRequest) { LocalPayment.approvePayment(mBraintreeFragment, localPaymentRequest); } }); verify(mBraintreeFragment).sendAnalyticsEvent(eq("ideal.local-payment.start-payment.selected")); verify(mBraintreeFragment).sendAnalyticsEvent(eq("ideal.local-payment.webswitch.initiate.succeeded")); latch.countDown(); }
@Test public void startPayment_setsApprovalUrl_andPaymentId_beforeListener_isCalled() throws InvalidArgumentException, JSONException { final CountDownLatch latch = new CountDownLatch(1); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { HttpResponseCallback callback = (HttpResponseCallback) invocation.getArguments()[2]; callback.success(stringFromFixture("payment_methods/local_payment_create_response.json")); return null; } }).when(mMockHttpClient).post(eq("/v1/paypal_hermes/create_payment_resource"), any(String.class), any(HttpResponseCallback.class)); LocalPayment.startPayment(mBraintreeFragment, getIdealLocalPaymentRequest(), new BraintreeResponseListener<LocalPaymentRequest>() { @Override public void onResponse(LocalPaymentRequest localPaymentRequest) { assertEquals("local-payment-id-123", localPaymentRequest.getPaymentId()); assertEquals("https://checkout.paypal.com/latinum?token=payment-token", localPaymentRequest.getApprovalUrl()); LocalPayment.approvePayment(mBraintreeFragment, localPaymentRequest); } }); latch.countDown(); }
@Test public void startPayment_failure_sendsAnalyticsEvent() throws JSONException, InvalidArgumentException { final CountDownLatch latch = new CountDownLatch(1); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { HttpResponseCallback callback = (HttpResponseCallback) invocation.getArguments()[2]; callback.success(stringFromFixture("error_response.json")); return null; } }).when(mMockHttpClient).post(eq("/v1/paypal_hermes/create_payment_resource"), any(String.class), any(HttpResponseCallback.class)); LocalPayment.startPayment(mBraintreeFragment, getIdealLocalPaymentRequest(), new BraintreeResponseListener<LocalPaymentRequest>() { @Override public void onResponse(LocalPaymentRequest localPaymentRequest) { LocalPayment.approvePayment(mBraintreeFragment, localPaymentRequest); } }); verify(mBraintreeFragment).sendAnalyticsEvent(eq("ideal.local-payment.start-payment.selected")); verify(mBraintreeFragment).sendAnalyticsEvent(eq("ideal.local-payment.webswitch.initiate.failed")); latch.countDown(); }
@Test public void startPayment_callsExceptionListenerOnHttpError() throws InvalidArgumentException, JSONException { final Exception expectedException = new Exception(); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { HttpResponseCallback callback = (HttpResponseCallback) invocation.getArguments()[2]; callback.failure(expectedException); return null; } }).when(mMockHttpClient).post(eq("/v1/paypal_hermes/create_payment_resource"), any(String.class), any(HttpResponseCallback.class)); LocalPayment.startPayment(mBraintreeFragment, getIdealLocalPaymentRequest(), new BraintreeResponseListener<LocalPaymentRequest>() { @Override public void onResponse(LocalPaymentRequest localPaymentRequest) { LocalPayment.approvePayment(mBraintreeFragment, localPaymentRequest); } }); verify(mBraintreeFragment).postCallback(eq(expectedException)); }
LocalPayment.startPayment(mBraintreeFragment, getIdealLocalPaymentRequest(), new BraintreeResponseListener<LocalPaymentRequest>() { @Override public void onResponse(LocalPaymentRequest localPaymentRequest) {
@Test public void onActivityResult_tokenize_sendsAnalyticsEvent() throws JSONException, InterruptedException { final CountDownLatch latch = new CountDownLatch(1); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { HttpResponseCallback callback = (HttpResponseCallback) invocation.getArguments()[2]; callback.success(stringFromFixture("error_response.json")); latch.countDown(); return null; } }).when(mMockHttpClient).post(eq("/v1/paypal_hermes/create_payment_resource"), any(String.class), any(HttpResponseCallback.class)); LocalPayment.startPayment(mBraintreeFragment, getIdealLocalPaymentRequest(), new BraintreeResponseListener<LocalPaymentRequest>() { @Override public void onResponse(LocalPaymentRequest localPaymentRequest) { LocalPayment.approvePayment(mBraintreeFragment, localPaymentRequest); } }); latch.await(); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { HttpResponseCallback callback = (HttpResponseCallback) invocation.getArguments()[2]; callback.success(stringFromFixture("payment_methods/local_payment_response.json")); return null; } }).when(mMockHttpClient).post(eq("/v1/payment_methods/paypal_accounts"), any(String.class), any(HttpResponseCallback.class)); LocalPayment.onActivityResult(mBraintreeFragment, Activity.RESULT_OK, getSuccessResponseIntent()); verify(mBraintreeFragment).sendAnalyticsEvent(eq("ideal.local-payment.tokenize.succeeded")); }
@Test public void onActivityResult_cancel_sendsAnalyticsEvent() throws JSONException, InterruptedException { final CountDownLatch latch = new CountDownLatch(1); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { HttpResponseCallback callback = (HttpResponseCallback) invocation.getArguments()[2]; callback.success(stringFromFixture("error_response.json")); latch.countDown(); return null; } }).when(mMockHttpClient).post(eq("/v1/paypal_hermes/create_payment_resource"), any(String.class), any(HttpResponseCallback.class)); LocalPayment.startPayment(mBraintreeFragment, getIdealLocalPaymentRequest(), new BraintreeResponseListener<LocalPaymentRequest>() { @Override public void onResponse(LocalPaymentRequest localPaymentRequest) { LocalPayment.approvePayment(mBraintreeFragment, localPaymentRequest); } }); latch.await(); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { HttpResponseCallback callback = (HttpResponseCallback) invocation.getArguments()[2]; callback.success(stringFromFixture("payment_methods/local_payment_response.json")); return null; } }).when(mMockHttpClient).post(eq("/v1/payment_methods/paypal_accounts"), any(String.class), any(HttpResponseCallback.class)); LocalPayment.onActivityResult(mBraintreeFragment, Activity.RESULT_OK, getCancelResponseIntent()); verify(mBraintreeFragment).sendAnalyticsEvent(eq("ideal.local-payment.webswitch.canceled")); }
public void launchIdeal(View v) { PostalAddress address = new PostalAddress() .streetAddress("836486 of 22321 Park Lake") .countryCodeAlpha2("NL") .locality("Den Haag") .postalCode("2585 GJ"); LocalPaymentRequest request = new LocalPaymentRequest() .paymentType("ideal") .amount("1.10") .address(address) .phone("639847934") .email("lingo-buyer@paypal.com") .givenName("Linh") .surname("Ngo") .shippingAddressRequired(true) .currencyCode("EUR"); LocalPayment.startPayment(mBraintreeFragment, request, new BraintreeResponseListener<LocalPaymentRequest>() { @Override public void onResponse(LocalPaymentRequest localPaymentRequest) { LocalPayment.approvePayment(mBraintreeFragment, localPaymentRequest); } }); }
.shippingAddressRequired(true) .currencyCode("EUR"); LocalPayment.startPayment(mBraintreeFragment, request, new BraintreeResponseListener<LocalPaymentRequest>() { @Override public void onResponse(LocalPaymentRequest localPaymentRequest) {