Search in sources :

Example 1 with Cart

use of com.google.android.gms.wallet.Cart in project braintree_android by braintree.

the class AndroidPayCardNonceUnitTest method fromFullWallet_withCart_createsAndroidPayCardNonce.

@Test
public void fromFullWallet_withCart_createsAndroidPayCardNonce() throws JSONException {
    UserAddress billingAddress = mock(UserAddress.class);
    UserAddress shippingAddress = mock(UserAddress.class);
    Cart cart = Cart.newBuilder().build();
    FullWallet wallet = getFullWallet(stringFromFixture("payment_methods/android_pay_card_response.json"), billingAddress, shippingAddress);
    AndroidPayCardNonce androidPayCardNonce = AndroidPayCardNonce.fromFullWallet(wallet, cart);
    assertEquals("Android Pay", androidPayCardNonce.getTypeLabel());
    assertEquals("fake-android-pay-nonce", androidPayCardNonce.getNonce());
    assertEquals("MasterCard 0276", androidPayCardNonce.getDescription());
    assertEquals("Visa", androidPayCardNonce.getCardType());
    assertEquals("11", androidPayCardNonce.getLastTwo());
    assertEquals("android-user@example.com", androidPayCardNonce.getEmail());
    assertEquals(billingAddress, androidPayCardNonce.getBillingAddress());
    assertEquals(shippingAddress, androidPayCardNonce.getShippingAddress());
    assertEquals("google-transaction-id", androidPayCardNonce.getGoogleTransactionId());
    assertEquals(cart, androidPayCardNonce.getCart());
}
Also used : FullWallet(com.google.android.gms.wallet.FullWallet) UserAddress(com.google.android.gms.identity.intents.model.UserAddress) Cart(com.google.android.gms.wallet.Cart) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with Cart

use of com.google.android.gms.wallet.Cart in project braintree_android by braintree.

the class AndroidPayCardNonceUnitTest method parcelsCorrectly.

@Test
public void parcelsCorrectly() throws Exception {
    UserAddress billingAddress = getAddressObject();
    UserAddress shippingAddress = getAddressObject();
    Cart cart = Cart.newBuilder().build();
    FullWallet wallet = getFullWallet(stringFromFixture("payment_methods/android_pay_card_response.json"), billingAddress, shippingAddress);
    AndroidPayCardNonce androidPayCardNonce = AndroidPayCardNonce.fromFullWallet(wallet, cart);
    Parcel parcel = Parcel.obtain();
    androidPayCardNonce.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);
    AndroidPayCardNonce parceled = AndroidPayCardNonce.CREATOR.createFromParcel(parcel);
    assertEquals("Android Pay", parceled.getTypeLabel());
    assertEquals("fake-android-pay-nonce", parceled.getNonce());
    assertEquals("MasterCard 0276", parceled.getDescription());
    assertEquals("Visa", parceled.getCardType());
    assertEquals("11", parceled.getLastTwo());
    assertEquals("android-user@example.com", parceled.getEmail());
    assertNotNull(parceled.getBillingAddress());
    assertNotNull(parceled.getShippingAddress());
    assertEquals("google-transaction-id", parceled.getGoogleTransactionId());
    assertNotNull(parceled.getCart());
    assertBinDataEqual(androidPayCardNonce.getBinData(), parceled.getBinData());
}
Also used : FullWallet(com.google.android.gms.wallet.FullWallet) Parcel(android.os.Parcel) UserAddress(com.google.android.gms.identity.intents.model.UserAddress) Cart(com.google.android.gms.wallet.Cart) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with Cart

use of com.google.android.gms.wallet.Cart in project braintree_android by braintree.

the class AndroidPayTest method requestAndroidPay_startsActivity.

@Test
public void requestAndroidPay_startsActivity() {
    BraintreeFragment fragment = getSetupFragment();
    doNothing().when(fragment).startActivityForResult(any(Intent.class), anyInt());
    Cart cart = Cart.newBuilder().build();
    ArrayList<CountrySpecification> allowedCountries = new ArrayList<>();
    AndroidPay.requestAndroidPay(fragment, cart, true, true, allowedCountries);
    ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
    verify(fragment).startActivityForResult(captor.capture(), eq(BraintreeRequestCodes.ANDROID_PAY));
    Intent intent = captor.getValue();
    assertEquals(AndroidPayActivity.class.getName(), intent.getComponent().getClassName());
    assertEquals(AUTHORIZE, intent.getIntExtra(EXTRA_REQUEST_TYPE, -1));
    assertEquals(WalletConstants.ENVIRONMENT_TEST, intent.getIntExtra(EXTRA_ENVIRONMENT, -1));
    assertEquals("", intent.getStringExtra(EXTRA_MERCHANT_NAME));
    assertEquals(cart, intent.getParcelableExtra(EXTRA_CART));
    assertTrue(intent.getBooleanExtra(EXTRA_SHIPPING_ADDRESS_REQUIRED, false));
    assertTrue(intent.getBooleanExtra(EXTRA_PHONE_NUMBER_REQUIRED, false));
    assertEquals(allowedCountries, intent.getParcelableArrayListExtra(EXTRA_ALLOWED_COUNTRIES));
    assertNotNull(intent.getParcelableExtra(EXTRA_TOKENIZATION_PARAMETERS));
    assertNotNull(intent.getIntegerArrayListExtra(EXTRA_ALLOWED_CARD_NETWORKS));
}
Also used : ArrayList(java.util.ArrayList) Intent(android.content.Intent) CountrySpecification(com.google.android.gms.identity.intents.model.CountrySpecification) Cart(com.google.android.gms.wallet.Cart) Test(org.junit.Test)

Example 4 with Cart

use of com.google.android.gms.wallet.Cart in project braintree_android by braintree.

the class AndroidPayTest method changePaymentMethod_startsActivity.

@Test
public void changePaymentMethod_startsActivity() {
    BraintreeFragment fragment = getSetupFragment();
    doNothing().when(fragment).startActivityForResult(any(Intent.class), anyInt());
    AndroidPayCardNonce androidPayCardNonce = mock(AndroidPayCardNonce.class);
    when(androidPayCardNonce.getGoogleTransactionId()).thenReturn("google-transaction-id");
    Cart cart = Cart.newBuilder().build();
    when(androidPayCardNonce.getCart()).thenReturn(cart);
    AndroidPay.changePaymentMethod(fragment, androidPayCardNonce);
    ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
    verify(fragment).startActivityForResult(captor.capture(), eq(BraintreeRequestCodes.ANDROID_PAY));
    Intent intent = captor.getValue();
    assertEquals(AndroidPayActivity.class.getName(), intent.getComponent().getClassName());
    assertEquals(CHANGE_PAYMENT_METHOD, intent.getIntExtra(EXTRA_REQUEST_TYPE, -1));
    assertEquals(WalletConstants.ENVIRONMENT_TEST, intent.getIntExtra(EXTRA_ENVIRONMENT, -1));
    assertEquals("google-transaction-id", intent.getStringExtra(EXTRA_GOOGLE_TRANSACTION_ID));
    assertEquals(cart, intent.getParcelableExtra(EXTRA_CART));
}
Also used : AndroidPayCardNonce(com.braintreepayments.api.models.AndroidPayCardNonce) Intent(android.content.Intent) Cart(com.google.android.gms.wallet.Cart) Test(org.junit.Test)

Aggregations

Cart (com.google.android.gms.wallet.Cart)4 Test (org.junit.Test)4 Intent (android.content.Intent)2 UserAddress (com.google.android.gms.identity.intents.model.UserAddress)2 FullWallet (com.google.android.gms.wallet.FullWallet)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Parcel (android.os.Parcel)1 AndroidPayCardNonce (com.braintreepayments.api.models.AndroidPayCardNonce)1 CountrySpecification (com.google.android.gms.identity.intents.model.CountrySpecification)1 ArrayList (java.util.ArrayList)1