Search in sources :

Example 11 with PaymentMethodNonce

use of com.braintreepayments.api.models.PaymentMethodNonce in project braintree_android by braintree.

the class MainActivity method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        if (requestCode == DROP_IN_REQUEST) {
            DropInResult result = data.getParcelableExtra(DropInResult.EXTRA_DROP_IN_RESULT);
            displayNonce(result.getPaymentMethodNonce(), result.getDeviceData());
        } else {
            Parcelable returnedData = data.getParcelableExtra(EXTRA_PAYMENT_RESULT);
            String deviceData = data.getStringExtra(EXTRA_DEVICE_DATA);
            if (returnedData instanceof PaymentMethodNonce) {
                displayNonce((PaymentMethodNonce) returnedData, deviceData);
            } else if (returnedData instanceof BraintreePaymentResult) {
                displayBraintreeResult((BraintreePaymentResult) returnedData);
            }
            mCreateTransactionButton.setEnabled(true);
        }
    } else if (resultCode != RESULT_CANCELED) {
        showDialog(((Exception) data.getSerializableExtra(DropInActivity.EXTRA_ERROR)).getMessage());
    }
}
Also used : BraintreePaymentResult(com.braintreepayments.api.models.BraintreePaymentResult) DropInResult(com.braintreepayments.api.dropin.DropInResult) Parcelable(android.os.Parcelable) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce)

Example 12 with PaymentMethodNonce

use of com.braintreepayments.api.models.PaymentMethodNonce in project braintree_android by braintree.

the class ThreeDSecureVerificationTest method performVerification_doesALookupAndReturnsACardWhenThereIsALookupError.

@Test(timeout = 10000)
public void performVerification_doesALookupAndReturnsACardWhenThereIsALookupError() throws InterruptedException {
    BraintreeFragment fragment = getFragment();
    fragment.addListener(new PaymentMethodNonceCreatedListener() {

        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
            assertIsANonce(paymentMethodNonce.getNonce());
            CardNonce cardNonce = (CardNonce) paymentMethodNonce;
            assertEquals("77", cardNonce.getLastTwo());
            assertFalse(cardNonce.getThreeDSecureInfo().isLiabilityShifted());
            assertFalse(cardNonce.getThreeDSecureInfo().isLiabilityShiftPossible());
            assertTrue(((CardNonce) paymentMethodNonce).getThreeDSecureInfo().wasVerified());
            mCountDownLatch.countDown();
        }
    });
    CardBuilder cardBuilder = new CardBuilder().cardNumber(THREE_D_SECURE_LOOKUP_ERROR).expirationDate("12/20");
    ThreeDSecure.performVerification(fragment, cardBuilder, TEST_AMOUNT);
    mCountDownLatch.await();
}
Also used : CardBuilder(com.braintreepayments.api.models.CardBuilder) CardNonce(com.braintreepayments.api.models.CardNonce) PaymentMethodNonceCreatedListener(com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) Test(org.junit.Test)

Example 13 with PaymentMethodNonce

use of com.braintreepayments.api.models.PaymentMethodNonce in project braintree_android by braintree.

the class PayPalUnitTest method requestBillingAgreement_paypalCreditReturnedInResponse.

@Test
public void requestBillingAgreement_paypalCreditReturnedInResponse() throws InterruptedException {
    BraintreeFragment fragment = mMockFragmentBuilder.successResponse(stringFromFixture("paypal_hermes_billing_agreement_response.json")).build();
    mockStatic(TokenizationClient.class);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            ((PaymentMethodNonceCallback) invocation.getArguments()[2]).success(PayPalAccountNonce.fromJson(stringFromFixture("payment_methods/paypal_account_response.json")));
            return null;
        }
    }).when(TokenizationClient.class);
    TokenizationClient.tokenize(any(BraintreeFragment.class), any(PaymentMethodBuilder.class), any(PaymentMethodNonceCallback.class));
    PayPal.requestBillingAgreement(fragment, new PayPalRequest().offerCredit(true), new PayPalApprovalHandler() {

        @Override
        public void handleApproval(Request request, PayPalApprovalCallback paypalApprovalCallback) {
            paypalApprovalCallback.onComplete(new Intent().setData(Uri.parse("com.braintreepayments.api.test.braintree://onetouch/v1/success?PayerID=HERMES-SANDBOX-PAYER-ID&paymentId=HERMES-SANDBOX-PAYMENT-ID&ba_token=EC-HERMES-SANDBOX-EC-TOKEN")));
        }
    });
    ArgumentCaptor<PaymentMethodNonce> nonceCaptor = ArgumentCaptor.forClass(PaymentMethodNonce.class);
    verify(fragment).postCallback(nonceCaptor.capture());
    verify(fragment).sendAnalyticsEvent("paypal.credit.accepted");
    assertTrue(nonceCaptor.getValue() instanceof PayPalAccountNonce);
    PayPalAccountNonce payPalAccountNonce = (PayPalAccountNonce) nonceCaptor.getValue();
    assertNotNull(payPalAccountNonce.getCreditFinancing());
    assertEquals(18, payPalAccountNonce.getCreditFinancing().getTerm());
}
Also used : PaymentMethodBuilder(com.braintreepayments.api.models.PaymentMethodBuilder) PaymentMethodNonceCallback(com.braintreepayments.api.interfaces.PaymentMethodNonceCallback) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) AuthorizationRequest(com.paypal.android.sdk.onetouch.core.AuthorizationRequest) Request(com.paypal.android.sdk.onetouch.core.Request) Intent(android.content.Intent) PowerMockito.doAnswer(org.powermock.api.mockito.PowerMockito.doAnswer) Answer(org.mockito.stubbing.Answer) PayPalApprovalHandler(com.braintreepayments.api.interfaces.PayPalApprovalHandler) PayPalApprovalCallback(com.braintreepayments.api.interfaces.PayPalApprovalCallback) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PayPalAccountNonce(com.braintreepayments.api.models.PayPalAccountNonce) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 14 with PaymentMethodNonce

use of com.braintreepayments.api.models.PaymentMethodNonce in project braintree_android by braintree.

the class PayPalUnitTest method requestOneTimePayment_paypalCreditReturnedInResponse.

@Test
public void requestOneTimePayment_paypalCreditReturnedInResponse() throws InterruptedException {
    BraintreeFragment fragment = mMockFragmentBuilder.successResponse(stringFromFixture("paypal_hermes_response.json")).build();
    mockStatic(TokenizationClient.class);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            ((PaymentMethodNonceCallback) invocation.getArguments()[2]).success(PayPalAccountNonce.fromJson(stringFromFixture("payment_methods/paypal_account_response.json")));
            return null;
        }
    }).when(TokenizationClient.class);
    TokenizationClient.tokenize(any(BraintreeFragment.class), any(PaymentMethodBuilder.class), any(PaymentMethodNonceCallback.class));
    PayPal.requestOneTimePayment(fragment, new PayPalRequest("1").offerCredit(true), new PayPalApprovalHandler() {

        @Override
        public void handleApproval(Request request, PayPalApprovalCallback paypalApprovalCallback) {
            paypalApprovalCallback.onComplete(new Intent().setData(Uri.parse("com.braintreepayments.demo.braintree://onetouch/v1/success?PayerID=HERMES-SANDBOX-PAYER-ID&paymentId=HERMES-SANDBOX-PAYMENT-ID&token=EC-HERMES-SANDBOX-EC-TOKEN")));
        }
    });
    ArgumentCaptor<PaymentMethodNonce> nonceCaptor = ArgumentCaptor.forClass(PaymentMethodNonce.class);
    verify(fragment).postCallback(nonceCaptor.capture());
    verify(fragment).sendAnalyticsEvent("paypal.credit.accepted");
    assertTrue(nonceCaptor.getValue() instanceof PayPalAccountNonce);
    PayPalAccountNonce payPalAccountNonce = (PayPalAccountNonce) nonceCaptor.getValue();
    assertNotNull(payPalAccountNonce.getCreditFinancing());
    assertEquals(18, payPalAccountNonce.getCreditFinancing().getTerm());
}
Also used : PaymentMethodBuilder(com.braintreepayments.api.models.PaymentMethodBuilder) PaymentMethodNonceCallback(com.braintreepayments.api.interfaces.PaymentMethodNonceCallback) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) AuthorizationRequest(com.paypal.android.sdk.onetouch.core.AuthorizationRequest) Request(com.paypal.android.sdk.onetouch.core.Request) Intent(android.content.Intent) PowerMockito.doAnswer(org.powermock.api.mockito.PowerMockito.doAnswer) Answer(org.mockito.stubbing.Answer) PayPalApprovalHandler(com.braintreepayments.api.interfaces.PayPalApprovalHandler) PayPalApprovalCallback(com.braintreepayments.api.interfaces.PayPalApprovalCallback) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PayPalAccountNonce(com.braintreepayments.api.models.PayPalAccountNonce) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 15 with PaymentMethodNonce

use of com.braintreepayments.api.models.PaymentMethodNonce in project braintree_android by braintree.

the class PayPalUnitTest method requestOneTimePayment_customHandlerSuccessCallbackIsInvoked.

@Test
public void requestOneTimePayment_customHandlerSuccessCallbackIsInvoked() throws InterruptedException {
    BraintreeFragment fragment = mMockFragmentBuilder.successResponse(stringFromFixture("paypal_hermes_response.json")).build();
    mockStatic(TokenizationClient.class);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            ((PaymentMethodNonceCallback) invocation.getArguments()[2]).success(new PayPalAccountNonce());
            return null;
        }
    }).when(TokenizationClient.class);
    TokenizationClient.tokenize(any(BraintreeFragment.class), any(PaymentMethodBuilder.class), any(PaymentMethodNonceCallback.class));
    PayPal.requestOneTimePayment(fragment, new PayPalRequest("1"), new PayPalApprovalHandler() {

        @Override
        public void handleApproval(Request request, PayPalApprovalCallback paypalApprovalCallback) {
            paypalApprovalCallback.onComplete(new Intent().setData(Uri.parse("com.braintreepayments.demo.braintree://onetouch/v1/success?PayerID=HERMES-SANDBOX-PAYER-ID&paymentId=HERMES-SANDBOX-PAYMENT-ID&token=EC-HERMES-SANDBOX-EC-TOKEN")));
        }
    });
    ArgumentCaptor<PaymentMethodNonce> nonceCaptor = ArgumentCaptor.forClass(PaymentMethodNonce.class);
    verify(fragment).postCallback(nonceCaptor.capture());
    assertTrue(nonceCaptor.getValue() instanceof PayPalAccountNonce);
}
Also used : PaymentMethodBuilder(com.braintreepayments.api.models.PaymentMethodBuilder) PaymentMethodNonceCallback(com.braintreepayments.api.interfaces.PaymentMethodNonceCallback) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) AuthorizationRequest(com.paypal.android.sdk.onetouch.core.AuthorizationRequest) Request(com.paypal.android.sdk.onetouch.core.Request) Intent(android.content.Intent) PowerMockito.doAnswer(org.powermock.api.mockito.PowerMockito.doAnswer) Answer(org.mockito.stubbing.Answer) PayPalApprovalHandler(com.braintreepayments.api.interfaces.PayPalApprovalHandler) PayPalApprovalCallback(com.braintreepayments.api.interfaces.PayPalApprovalCallback) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PayPalAccountNonce(com.braintreepayments.api.models.PayPalAccountNonce) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) PayPalRequest(com.braintreepayments.api.models.PayPalRequest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)38 Test (org.junit.Test)31 CardNonce (com.braintreepayments.api.models.CardNonce)22 PaymentMethodNonceCreatedListener (com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener)21 CardBuilder (com.braintreepayments.api.models.CardBuilder)15 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)11 PaymentMethodNonceCallback (com.braintreepayments.api.interfaces.PaymentMethodNonceCallback)8 JSONException (org.json.JSONException)7 Intent (android.content.Intent)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 PaymentMethodNoncesUpdatedListener (com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener)5 AndroidPayCardNonce (com.braintreepayments.api.models.AndroidPayCardNonce)5 PayPalAccountNonce (com.braintreepayments.api.models.PayPalAccountNonce)5 PayPalRequest (com.braintreepayments.api.models.PayPalRequest)4 UnionPayCardBuilder (com.braintreepayments.api.models.UnionPayCardBuilder)4 TestClientTokenBuilder (com.braintreepayments.api.test.TestClientTokenBuilder)4 TestConfigurationBuilder (com.braintreepayments.testutils.TestConfigurationBuilder)4 ArrayList (java.util.ArrayList)4 BraintreeException (com.braintreepayments.api.exceptions.BraintreeException)3 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)3