com.google.android.gms.wallet.FullWallet Java Examples

The following examples show how to use com.google.android.gms.wallet.FullWallet. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FullWalletConfirmationButtonFragment.java    From androidpay-quickstart with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    mProgressDialog.hide();

    // retrieve the error code, if available
    int errorCode = -1;
    if (data != null) {
        errorCode = data.getIntExtra(WalletConstants.EXTRA_ERROR_CODE, -1);
    }

    switch (requestCode) {
        case REQUEST_CODE_RESOLVE_LOAD_FULL_WALLET:
            switch (resultCode) {
                case Activity.RESULT_OK:
                    if (data != null && data.hasExtra(WalletConstants.EXTRA_FULL_WALLET)) {
                        FullWallet fullWallet = data.getParcelableExtra(WalletConstants.EXTRA_FULL_WALLET);
                        // the full wallet can now be used to process the customer's payment
                        // send the wallet info up to server to process, and to get the result
                        // for sending a transaction status
                        fetchTransactionStatus(fullWallet);
                    } else if (data != null && data.hasExtra(WalletConstants.EXTRA_MASKED_WALLET)) {
                        // re-launch the activity with new masked wallet information
                        mMaskedWallet =  data.getParcelableExtra(WalletConstants.EXTRA_MASKED_WALLET);
                        mActivityLaunchIntent.putExtra(Constants.EXTRA_MASKED_WALLET,
                                mMaskedWallet);
                        startActivity(mActivityLaunchIntent);
                    }
                    break;
                case Activity.RESULT_CANCELED:
                    // nothing to do here
                    break;
                default:
                    handleError(errorCode);
                    break;
            }
            break;
    }
}
 
Example #2
Source File: FullWalletConfirmationButtonFragment.java    From androidpay-quickstart with Apache License 2.0 5 votes vote down vote up
/**
 * 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) {
    if (mProgressDialog.isShowing()) {
        mProgressDialog.dismiss();
    }

    // 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) {
        // 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.

        // Pretty-print the token to LogCat (newlines replaced with spaces).
        Log.d(TAG, "PaymentMethodToken:" + token.getToken().replace('\n', ' '));
    }

    // TODO: 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()

    Intent intent = new Intent(getActivity(), OrderCompleteActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(Constants.EXTRA_FULL_WALLET, fullWallet);
    startActivity(intent);
}
 
Example #3
Source File: PaymentFormActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
    if (requestCode == LOAD_MASKED_WALLET_REQUEST_CODE) {
        if (resultCode == Activity.RESULT_OK) {
            showEditDoneProgress(true, true);
            setDonePressed(true);

            MaskedWallet maskedWallet = data.getParcelableExtra(WalletConstants.EXTRA_MASKED_WALLET);

            Cart.Builder cardBuilder = Cart.newBuilder()
                    .setCurrencyCode(paymentForm.invoice.currency)
                    .setTotalPrice(totalPriceDecimal);

            ArrayList<TLRPC.TL_labeledPrice> arrayList = new ArrayList<>(paymentForm.invoice.prices);
            if (shippingOption != null) {
                arrayList.addAll(shippingOption.prices);
            }
            for (int a = 0; a < arrayList.size(); a++) {
                TLRPC.TL_labeledPrice price = arrayList.get(a);
                String amount = LocaleController.getInstance().formatCurrencyDecimalString(price.amount, paymentForm.invoice.currency, false);
                cardBuilder.addLineItem(LineItem.newBuilder()
                        .setCurrencyCode(paymentForm.invoice.currency)
                        .setQuantity("1")
                        .setDescription(price.label)
                        .setTotalPrice(amount)
                        .setUnitPrice(amount).build());
            }
            FullWalletRequest fullWalletRequest = FullWalletRequest.newBuilder()
                    .setCart(cardBuilder.build())
                    .setGoogleTransactionId(maskedWallet.getGoogleTransactionId())
                    .build();
            Wallet.Payments.loadFullWallet(googleApiClient, fullWalletRequest, LOAD_FULL_WALLET_REQUEST_CODE);
        } else {
            showEditDoneProgress(true, false);
            setDonePressed(false);
        }
    } else if (requestCode == LOAD_FULL_WALLET_REQUEST_CODE) {
        if (resultCode == Activity.RESULT_OK) {
            FullWallet fullWallet = data.getParcelableExtra(WalletConstants.EXTRA_FULL_WALLET);
            String tokenJSON = fullWallet.getPaymentMethodToken().getToken();
            try {
                if (androidPayPublicKey != null) {
                    androidPayCredentials = new TLRPC.TL_inputPaymentCredentialsAndroidPay();
                    androidPayCredentials.payment_token = new TLRPC.TL_dataJSON();
                    androidPayCredentials.payment_token.data = tokenJSON;
                    androidPayCredentials.google_transaction_id = fullWallet.getGoogleTransactionId();
                    String[] descriptions = fullWallet.getPaymentDescriptions();
                    if (descriptions.length > 0) {
                        cardName = descriptions[0];
                    } else {
                        cardName = "Android Pay";
                    }
                } else {
                    Token token = TokenParser.parseToken(tokenJSON);
                    paymentJson = String.format(Locale.US, "{\"type\":\"%1$s\", \"id\":\"%2$s\"}", token.getType(), token.getId());
                    Card card = token.getCard();
                    cardName = card.getType() + " *" + card.getLast4();
                }
                goToNextStep();
                showEditDoneProgress(true, false);
                setDonePressed(false);
            } catch (JSONException ignore) {
                showEditDoneProgress(true, false);
                setDonePressed(false);
            }
        } else {
            showEditDoneProgress(true, false);
            setDonePressed(false);
        }
    }
}
 
Example #4
Source File: PaymentFormActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
    if (requestCode == LOAD_MASKED_WALLET_REQUEST_CODE) {
        if (resultCode == Activity.RESULT_OK) {
            showEditDoneProgress(true, true);
            setDonePressed(true);

            MaskedWallet maskedWallet = data.getParcelableExtra(WalletConstants.EXTRA_MASKED_WALLET);

            Cart.Builder cardBuilder = Cart.newBuilder()
                    .setCurrencyCode(paymentForm.invoice.currency)
                    .setTotalPrice(totalPriceDecimal);

            ArrayList<TLRPC.TL_labeledPrice> arrayList = new ArrayList<>(paymentForm.invoice.prices);
            if (shippingOption != null) {
                arrayList.addAll(shippingOption.prices);
            }
            for (int a = 0; a < arrayList.size(); a++) {
                TLRPC.TL_labeledPrice price = arrayList.get(a);
                String amount = LocaleController.getInstance().formatCurrencyDecimalString(price.amount, paymentForm.invoice.currency, false);
                cardBuilder.addLineItem(LineItem.newBuilder()
                        .setCurrencyCode(paymentForm.invoice.currency)
                        .setQuantity("1")
                        .setDescription(price.label)
                        .setTotalPrice(amount)
                        .setUnitPrice(amount).build());
            }
            FullWalletRequest fullWalletRequest = FullWalletRequest.newBuilder()
                    .setCart(cardBuilder.build())
                    .setGoogleTransactionId(maskedWallet.getGoogleTransactionId())
                    .build();
            Wallet.Payments.loadFullWallet(googleApiClient, fullWalletRequest, LOAD_FULL_WALLET_REQUEST_CODE);
        } else {
            showEditDoneProgress(true, false);
            setDonePressed(false);
        }
    } else if (requestCode == LOAD_FULL_WALLET_REQUEST_CODE) {
        if (resultCode == Activity.RESULT_OK) {
            FullWallet fullWallet = data.getParcelableExtra(WalletConstants.EXTRA_FULL_WALLET);
            String tokenJSON = fullWallet.getPaymentMethodToken().getToken();
            try {
                if (androidPayPublicKey != null) {
                    androidPayCredentials = new TLRPC.TL_inputPaymentCredentialsAndroidPay();
                    androidPayCredentials.payment_token = new TLRPC.TL_dataJSON();
                    androidPayCredentials.payment_token.data = tokenJSON;
                    androidPayCredentials.google_transaction_id = fullWallet.getGoogleTransactionId();
                    String[] descriptions = fullWallet.getPaymentDescriptions();
                    if (descriptions.length > 0) {
                        cardName = descriptions[0];
                    } else {
                        cardName = "Android Pay";
                    }
                } else {
                    Token token = TokenParser.parseToken(tokenJSON);
                    paymentJson = String.format(Locale.US, "{\"type\":\"%1$s\", \"id\":\"%2$s\"}", token.getType(), token.getId());
                    Card card = token.getCard();
                    cardName = card.getType() + " *" + card.getLast4();
                }
                goToNextStep();
                showEditDoneProgress(true, false);
                setDonePressed(false);
            } catch (JSONException ignore) {
                showEditDoneProgress(true, false);
                setDonePressed(false);
            }
        } else {
            showEditDoneProgress(true, false);
            setDonePressed(false);
        }
    }
}