Search in sources :

Example 1 with PaymentMethodToken

use of com.google.android.gms.wallet.PaymentMethodToken in project connect-sdk-client-android by Ingenico-ePayments.

the class FullWalletConfirmationButtonFragment method fetchTransactionStatus.

/**
 * Here the client should connect to their server, process the credit card/instrument
 * and get back a status indicating whether charging the card was successful or not
 */
private void fetchTransactionStatus(FullWallet fullWallet) {
    // / Retrieve the payment product from the paymentRequest
    PaymentProduct androidPay = paymentRequest.getPaymentProduct();
    // Log payment method token, if it exists. This token will either be a direct integration
    // token or a Stripe token, depending on the method used when making the MaskedWalletRequest
    PaymentMethodToken token = fullWallet.getPaymentMethodToken();
    if (token != null && androidPay != null) {
        // getToken returns a JSON object as a String.
        // 
        // For a Stripe token, the 'id' field of the object contains the necessary token.
        // 
        // For a Direct Integration token, the object will have the following format:
        // {
        // encryptedMessage: <string,base64>
        // ephemeralPublicKey: <string,base64>
        // tag: <string,base64>
        // }
        // See the Android Pay documentation for more information on how to decrypt the token.
        paymentRequest.setValue(com.globalcollect.gateway.sdk.client.android.sdk.configuration.Constants.ANDROID_PAY_TOKEN_FIELD_ID, token.getToken());
        paymentRequest.setValue(com.globalcollect.gateway.sdk.client.android.sdk.configuration.Constants.ANDROID_PAY_GOOGLE_TRANSACTION_ID_FIELD_ID, fullWallet.getGoogleTransactionId());
        // Pretty-print the token to LogCat (newlines replaced with spaces).
        Log.d(TAG, "PaymentMethodToken:" + token.getToken().replace('\n', ' '));
        // Prepare the payment request for submission at the connect API. The callback for the
        // preparePayemntRequest method (onPaymentRequestPrepared) should take care of this.
        session.preparePaymentRequest(paymentRequest, getActivity().getApplicationContext(), this);
    } else {
        // Notify the user that an error has occurred
        showTechnicalErrorDialog();
    }
// Send details such as fullWallet.getProxyCard() or fullWallet.getBillingAddress()
// to your server and get back success or failure. If you used Stripe for processing,
// you can get the token from fullWallet.getPaymentMethodToken()
}
Also used : PaymentProduct(com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProduct) PaymentMethodToken(com.google.android.gms.wallet.PaymentMethodToken)

Example 2 with PaymentMethodToken

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

the class GooglePaymentCardNonceUnitTest method getPaymentData.

private PaymentData getPaymentData(String email, UserAddress billingAddress, UserAddress shippingAddress, String response) throws Exception {
    Constructor<PaymentMethodToken> paymentMethodTokenConstructor = PaymentMethodToken.class.getDeclaredConstructor(int.class, String.class);
    paymentMethodTokenConstructor.setAccessible(true);
    PaymentMethodToken paymentMethodToken = paymentMethodTokenConstructor.newInstance(0, response);
    Constructor<CardInfo> cardInfoConstructor = CardInfo.class.getDeclaredConstructor(String.class, String.class, String.class, int.class, UserAddress.class);
    cardInfoConstructor.setAccessible(true);
    CardInfo cardInfo = cardInfoConstructor.newInstance("MasterCard 0276", null, null, 0, billingAddress);
    Constructor<PaymentData> paymentDataConstructor = PaymentData.class.getDeclaredConstructor(String.class, CardInfo.class, UserAddress.class, PaymentMethodToken.class);
    paymentDataConstructor.setAccessible(true);
    return paymentDataConstructor.newInstance(email, cardInfo, shippingAddress, paymentMethodToken);
}
Also used : PaymentData(com.google.android.gms.wallet.PaymentData) PaymentMethodToken(com.google.android.gms.wallet.PaymentMethodToken) CardInfo(com.google.android.gms.wallet.CardInfo)

Example 3 with PaymentMethodToken

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

the class AndroidPayCardNonceUnitTest method getFullWallet.

private FullWallet getFullWallet(String response, UserAddress billingAddress, UserAddress shippingAddress) {
    PaymentMethodToken paymentMethodToken = mock(PaymentMethodToken.class);
    when(paymentMethodToken.getToken()).thenReturn(response);
    FullWallet wallet = mock(FullWallet.class);
    when(wallet.getPaymentMethodToken()).thenReturn(paymentMethodToken);
    when(wallet.getPaymentDescriptions()).thenReturn(new String[] { "MasterCard 0276" });
    when(wallet.getEmail()).thenReturn("android-user@example.com");
    when(wallet.getBuyerBillingAddress()).thenReturn(billingAddress);
    when(wallet.getBuyerShippingAddress()).thenReturn(shippingAddress);
    when(wallet.getGoogleTransactionId()).thenReturn("google-transaction-id");
    return wallet;
}
Also used : FullWallet(com.google.android.gms.wallet.FullWallet) PaymentMethodToken(com.google.android.gms.wallet.PaymentMethodToken)

Example 4 with PaymentMethodToken

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

the class AndroidPayTest method createFullWallet.

private FullWallet createFullWallet() throws Exception {
    Class paymentMethodTokenClass = PaymentMethodToken.class;
    Class[] tokenParams = new Class[] { int.class, String.class };
    Constructor<PaymentMethodToken> tokenConstructor = paymentMethodTokenClass.getDeclaredConstructor(tokenParams);
    tokenConstructor.setAccessible(true);
    PaymentMethodToken token = tokenConstructor.newInstance(0, stringFromFixture("payment_methods/android_pay_card.json"));
    Class fullWalletClass = FullWallet.class;
    Class[] walletParams = new Class[] { String.class, String.class, ProxyCard.class, String.class, com.google.android.gms.wallet.zza.class, com.google.android.gms.wallet.zza.class, String[].class, UserAddress.class, UserAddress.class, InstrumentInfo[].class, PaymentMethodToken.class };
    Constructor<FullWallet> walletConstructor = fullWalletClass.getDeclaredConstructor(walletParams);
    walletConstructor.setAccessible(true);
    return walletConstructor.newInstance(null, null, null, null, null, null, null, null, null, null, token);
}
Also used : FullWallet(com.google.android.gms.wallet.FullWallet) ProxyCard(com.google.android.gms.wallet.ProxyCard) PaymentMethodToken(com.google.android.gms.wallet.PaymentMethodToken) UserAddress(com.google.android.gms.identity.intents.model.UserAddress)

Aggregations

PaymentMethodToken (com.google.android.gms.wallet.PaymentMethodToken)4 FullWallet (com.google.android.gms.wallet.FullWallet)2 PaymentProduct (com.globalcollect.gateway.sdk.client.android.sdk.model.paymentproduct.PaymentProduct)1 UserAddress (com.google.android.gms.identity.intents.model.UserAddress)1 CardInfo (com.google.android.gms.wallet.CardInfo)1 PaymentData (com.google.android.gms.wallet.PaymentData)1 ProxyCard (com.google.android.gms.wallet.ProxyCard)1