Search in sources :

Example 1 with BraintreePaymentResult

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

the class BraintreeFragmentUnitTest method addAndRemoveListenersAddAndRemoveAllListeners.

@Test
public void addAndRemoveListenersAddAndRemoveAllListeners() throws InvalidArgumentException {
    BraintreeFragment fragment = BraintreeFragment.newInstance(mActivity, TOKENIZATION_KEY);
    ConfigurationListener configurationListener = new ConfigurationListener() {

        @Override
        public void onConfigurationFetched(Configuration configuration) {
        }
    };
    BraintreeErrorListener braintreeErrorListener = new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
        }
    };
    PaymentMethodNoncesUpdatedListener paymentMethodNoncesUpdatedListener = new PaymentMethodNoncesUpdatedListener() {

        @Override
        public void onPaymentMethodNoncesUpdated(List<PaymentMethodNonce> paymentMethodNonces) {
        }
    };
    PaymentMethodNonceCreatedListener paymentMethodNonceCreatedListener = new PaymentMethodNonceCreatedListener() {

        @Override
        public void onPaymentMethodNonceCreated(PaymentMethodNonce paymentMethodNonce) {
        }
    };
    BraintreeCancelListener braintreeCancelListener = new BraintreeCancelListener() {

        @Override
        public void onCancel(int requestCode) {
        }
    };
    UnionPayListener unionPayListener = new UnionPayListener() {

        @Override
        public void onCapabilitiesFetched(UnionPayCapabilities capabilities) {
        }

        @Override
        public void onSmsCodeSent(String enrollmentId, boolean smsCodeRequired) {
        }
    };
    AmericanExpressListener americanExpressListener = new AmericanExpressListener() {

        @Override
        public void onRewardsBalanceFetched(AmericanExpressRewardsBalance rewardsBalance) {
        }
    };
    BraintreePaymentResultListener braintreePaymentResultListener = new BraintreePaymentResultListener() {

        @Override
        public void onBraintreePaymentResult(BraintreePaymentResult result) {
        }
    };
    fragment.addListener(configurationListener);
    fragment.addListener(braintreeErrorListener);
    fragment.addListener(paymentMethodNoncesUpdatedListener);
    fragment.addListener(paymentMethodNonceCreatedListener);
    fragment.addListener(braintreeCancelListener);
    fragment.addListener(unionPayListener);
    fragment.addListener(americanExpressListener);
    fragment.addListener(braintreePaymentResultListener);
    assertEquals(8, fragment.getListeners().size());
    fragment.removeListener(configurationListener);
    fragment.removeListener(braintreeErrorListener);
    fragment.removeListener(paymentMethodNoncesUpdatedListener);
    fragment.removeListener(paymentMethodNonceCreatedListener);
    fragment.removeListener(braintreeCancelListener);
    fragment.removeListener(unionPayListener);
    fragment.removeListener(americanExpressListener);
    fragment.removeListener(braintreePaymentResultListener);
    assertEquals(0, fragment.getListeners().size());
}
Also used : PaymentMethodNoncesUpdatedListener(com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener) UnionPayListener(com.braintreepayments.api.interfaces.UnionPayListener) Configuration(com.braintreepayments.api.models.Configuration) BraintreeCancelListener(com.braintreepayments.api.interfaces.BraintreeCancelListener) UnionPayCapabilities(com.braintreepayments.api.models.UnionPayCapabilities) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) JSONException(org.json.JSONException) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) ConfigurationListener(com.braintreepayments.api.interfaces.ConfigurationListener) BraintreePaymentResult(com.braintreepayments.api.models.BraintreePaymentResult) AmericanExpressRewardsBalance(com.braintreepayments.api.models.AmericanExpressRewardsBalance) List(java.util.List) ArrayList(java.util.ArrayList) PaymentMethodNonceCreatedListener(com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener) AmericanExpressListener(com.braintreepayments.api.interfaces.AmericanExpressListener) PaymentMethodNonce(com.braintreepayments.api.models.PaymentMethodNonce) BraintreePaymentResultListener(com.braintreepayments.api.interfaces.BraintreePaymentResultListener) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with BraintreePaymentResult

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

the class IdealTest method startPayment_returnsPendingPayment.

@Test(timeout = 10000)
public void startPayment_returnsPendingPayment() throws InterruptedException {
    IdealRequest builder = new IdealRequest().currency("EUR").amount("10").issuerId("INGBNL2A").orderId(UUID.randomUUID().toString().substring(0, 15));
    Ideal.startPayment(mBraintreeFragment, builder, null);
    String savedId;
    do {
        savedId = BraintreeSharedPreferences.getString(mBraintreeFragment.getApplicationContext(), Ideal.IDEAL_RESULT_ID);
        SystemClock.sleep(500);
    } while (savedId.equals(""));
    Ideal.onActivityResult(mBraintreeFragment, Activity.RESULT_OK);
    mBraintreeFragment.addListener(new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
            fail(error.getMessage());
        }
    });
    mBraintreeFragment.addListener(new BraintreePaymentResultListener() {

        @Override
        public void onBraintreePaymentResult(BraintreePaymentResult result) {
            assertTrue(result instanceof IdealResult);
            IdealResult idealResult = (IdealResult) result;
            assertFalse(TextUtils.isEmpty(idealResult.getId()));
            assertFalse(TextUtils.isEmpty(idealResult.getShortId()));
            assertFalse(TextUtils.isEmpty(idealResult.getStatus()));
            mCountDownLatch.countDown();
        }
    });
    mCountDownLatch.await();
}
Also used : BraintreePaymentResult(com.braintreepayments.api.models.BraintreePaymentResult) IdealRequest(com.braintreepayments.api.models.IdealRequest) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) IdealResult(com.braintreepayments.api.models.IdealResult) BraintreePaymentResultListener(com.braintreepayments.api.interfaces.BraintreePaymentResultListener) Test(org.junit.Test)

Example 3 with BraintreePaymentResult

use of com.braintreepayments.api.models.BraintreePaymentResult 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 4 with BraintreePaymentResult

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

the class IdealTest method startPayment_returnsError_whenOrderId_isAbsent.

@Test(timeout = 10000)
public void startPayment_returnsError_whenOrderId_isAbsent() throws InterruptedException {
    IdealRequest builder = new IdealRequest().currency("EUR").amount("10").issuerId("INGBNL2A");
    Ideal.startPayment(mBraintreeFragment, builder, null);
    mBraintreeFragment.addListener(new BraintreeErrorListener() {

        @Override
        public void onError(Exception error) {
            assertTrue(error instanceof BraintreeApiErrorResponse);
            mCountDownLatch.countDown();
        }
    });
    mBraintreeFragment.addListener(new BraintreePaymentResultListener() {

        @Override
        public void onBraintreePaymentResult(BraintreePaymentResult result) {
            fail("BraintreeApiErrorResponse expected");
        }
    });
    mCountDownLatch.await();
}
Also used : BraintreePaymentResult(com.braintreepayments.api.models.BraintreePaymentResult) BraintreeApiErrorResponse(com.braintreepayments.api.exceptions.BraintreeApiErrorResponse) IdealRequest(com.braintreepayments.api.models.IdealRequest) BraintreeErrorListener(com.braintreepayments.api.interfaces.BraintreeErrorListener) InvalidArgumentException(com.braintreepayments.api.exceptions.InvalidArgumentException) BraintreePaymentResultListener(com.braintreepayments.api.interfaces.BraintreePaymentResultListener) Test(org.junit.Test)

Aggregations

BraintreePaymentResult (com.braintreepayments.api.models.BraintreePaymentResult)4 InvalidArgumentException (com.braintreepayments.api.exceptions.InvalidArgumentException)3 BraintreeErrorListener (com.braintreepayments.api.interfaces.BraintreeErrorListener)3 BraintreePaymentResultListener (com.braintreepayments.api.interfaces.BraintreePaymentResultListener)3 Test (org.junit.Test)3 IdealRequest (com.braintreepayments.api.models.IdealRequest)2 PaymentMethodNonce (com.braintreepayments.api.models.PaymentMethodNonce)2 Parcelable (android.os.Parcelable)1 DropInResult (com.braintreepayments.api.dropin.DropInResult)1 BraintreeApiErrorResponse (com.braintreepayments.api.exceptions.BraintreeApiErrorResponse)1 AmericanExpressListener (com.braintreepayments.api.interfaces.AmericanExpressListener)1 BraintreeCancelListener (com.braintreepayments.api.interfaces.BraintreeCancelListener)1 ConfigurationListener (com.braintreepayments.api.interfaces.ConfigurationListener)1 PaymentMethodNonceCreatedListener (com.braintreepayments.api.interfaces.PaymentMethodNonceCreatedListener)1 PaymentMethodNoncesUpdatedListener (com.braintreepayments.api.interfaces.PaymentMethodNoncesUpdatedListener)1 UnionPayListener (com.braintreepayments.api.interfaces.UnionPayListener)1 AmericanExpressRewardsBalance (com.braintreepayments.api.models.AmericanExpressRewardsBalance)1 Configuration (com.braintreepayments.api.models.Configuration)1 IdealResult (com.braintreepayments.api.models.IdealResult)1 UnionPayCapabilities (com.braintreepayments.api.models.UnionPayCapabilities)1