Java Code Examples for org.telegram.tgnet.TLRPC#TL_labeledPrice

The following examples show how to use org.telegram.tgnet.TLRPC#TL_labeledPrice . 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: PaymentFormActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private String getTotalPriceString(ArrayList<TLRPC.TL_labeledPrice> prices) {
    long amount = 0;
    for (int a = 0; a < prices.size(); a++) {
        amount += prices.get(a).amount;
    }
    return LocaleController.getInstance().formatCurrencyString(amount, paymentForm.invoice.currency);
}
 
Example 2
Source File: PaymentFormActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private String getTotalPriceDecimalString(ArrayList<TLRPC.TL_labeledPrice> prices) {
    long amount = 0;
    for (int a = 0; a < prices.size(); a++) {
        amount += prices.get(a).amount;
    }
    return LocaleController.getInstance().formatCurrencyDecimalString(amount, paymentForm.invoice.currency, false);
}
 
Example 3
Source File: PaymentFormActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private String getTotalPriceString(ArrayList<TLRPC.TL_labeledPrice> prices) {
    long amount = 0;
    for (int a = 0; a < prices.size(); a++) {
        amount += prices.get(a).amount;
    }
    return LocaleController.getInstance().formatCurrencyString(amount, paymentForm.invoice.currency);
}
 
Example 4
Source File: PaymentFormActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private String getTotalPriceDecimalString(ArrayList<TLRPC.TL_labeledPrice> prices) {
    long amount = 0;
    for (int a = 0; a < prices.size(); a++) {
        amount += prices.get(a).amount;
    }
    return LocaleController.getInstance().formatCurrencyDecimalString(amount, paymentForm.invoice.currency, false);
}
 
Example 5
Source File: PaymentFormActivity.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private String getTotalPriceString(ArrayList<TLRPC.TL_labeledPrice> prices) {
    long amount = 0;
    for (int a = 0; a < prices.size(); a++) {
        amount += prices.get(a).amount;
    }
    return LocaleController.getInstance().formatCurrencyString(amount, paymentForm.invoice.currency);
}
 
Example 6
Source File: PaymentFormActivity.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private String getTotalPriceDecimalString(ArrayList<TLRPC.TL_labeledPrice> prices) {
    long amount = 0;
    for (int a = 0; a < prices.size(); a++) {
        amount += prices.get(a).amount;
    }
    return LocaleController.getInstance().formatCurrencyDecimalString(amount, paymentForm.invoice.currency, false);
}
 
Example 7
Source File: PaymentFormActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private String getTotalPriceString(ArrayList<TLRPC.TL_labeledPrice> prices) {
    long amount = 0;
    for (int a = 0; a < prices.size(); a++) {
        amount += prices.get(a).amount;
    }
    return LocaleController.getInstance().formatCurrencyString(amount, paymentForm.invoice.currency);
}
 
Example 8
Source File: PaymentFormActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private String getTotalPriceDecimalString(ArrayList<TLRPC.TL_labeledPrice> prices) {
    long amount = 0;
    for (int a = 0; a < prices.size(); a++) {
        amount += prices.get(a).amount;
    }
    return LocaleController.getInstance().formatCurrencyDecimalString(amount, paymentForm.invoice.currency, false);
}
 
Example 9
Source File: PaymentFormActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private void showAndroidPay() {
    if (getParentActivity() == null || androidPayContainer == null) {
        return;
    }

    WalletFragmentOptions.Builder optionsBuilder = WalletFragmentOptions.newBuilder();
    optionsBuilder.setEnvironment(paymentForm.invoice.test ? WalletConstants.ENVIRONMENT_TEST : WalletConstants.ENVIRONMENT_PRODUCTION);
    optionsBuilder.setMode(WalletFragmentMode.BUY_BUTTON);

    WalletFragmentStyle walletFragmentStyle;
    if (androidPayPublicKey != null) {
        androidPayContainer.setBackgroundColor(androidPayBackgroundColor);
        walletFragmentStyle = new WalletFragmentStyle()
                .setBuyButtonText(WalletFragmentStyle.BuyButtonText.BUY_WITH)
                .setBuyButtonAppearance(androidPayBlackTheme ? WalletFragmentStyle.BuyButtonAppearance.ANDROID_PAY_LIGHT_WITH_BORDER : WalletFragmentStyle.BuyButtonAppearance.ANDROID_PAY_DARK)
                .setBuyButtonWidth(WalletFragmentStyle.Dimension.MATCH_PARENT);
    } else {
        walletFragmentStyle = new WalletFragmentStyle()
                .setBuyButtonText(WalletFragmentStyle.BuyButtonText.LOGO_ONLY)
                .setBuyButtonAppearance(WalletFragmentStyle.BuyButtonAppearance.ANDROID_PAY_LIGHT_WITH_BORDER)
                .setBuyButtonWidth(WalletFragmentStyle.Dimension.WRAP_CONTENT);
    }

    optionsBuilder.setFragmentStyle(walletFragmentStyle);
    WalletFragment walletFragment = WalletFragment.newInstance(optionsBuilder.build());
    FragmentManager fragmentManager = getParentActivity().getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.replace(fragment_container_id, walletFragment);
    fragmentTransaction.commit();

    ArrayList<TLRPC.TL_labeledPrice> arrayList = new ArrayList<>(paymentForm.invoice.prices);
    if (shippingOption != null) {
        arrayList.addAll(shippingOption.prices);
    }
    totalPriceDecimal = getTotalPriceDecimalString(arrayList);

    PaymentMethodTokenizationParameters parameters;
    if (androidPayPublicKey != null) {
        parameters = PaymentMethodTokenizationParameters.newBuilder()
                .setPaymentMethodTokenizationType(PaymentMethodTokenizationType.NETWORK_TOKEN)
                .addParameter("publicKey", androidPayPublicKey)
                .build();
    } else {
        parameters = PaymentMethodTokenizationParameters.newBuilder()
                .setPaymentMethodTokenizationType(PaymentMethodTokenizationType.PAYMENT_GATEWAY)
                .addParameter("gateway", "stripe")
                .addParameter("stripe:publishableKey", stripeApiKey)
                .addParameter("stripe:version", StripeApiHandler.VERSION)
                .build();
    }

    MaskedWalletRequest maskedWalletRequest = MaskedWalletRequest.newBuilder()
            .setPaymentMethodTokenizationParameters(parameters)
            .setEstimatedTotalPrice(totalPriceDecimal)
            .setCurrencyCode(paymentForm.invoice.currency)
            .build();

    WalletFragmentInitParams initParams = WalletFragmentInitParams.newBuilder()
            .setMaskedWalletRequest(maskedWalletRequest)
            .setMaskedWalletRequestCode(LOAD_MASKED_WALLET_REQUEST_CODE)
            .build();

    walletFragment.initialize(initParams);
    androidPayContainer.setVisibility(View.VISIBLE);
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(ObjectAnimator.ofFloat(androidPayContainer, "alpha", 0.0f, 1.0f));
    animatorSet.setInterpolator(new DecelerateInterpolator());
    animatorSet.setDuration(180);
    animatorSet.start();
}
 
Example 10
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 11
Source File: PaymentFormActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private void showAndroidPay() {
    if (getParentActivity() == null || androidPayContainer == null) {
        return;
    }

    WalletFragmentOptions.Builder optionsBuilder = WalletFragmentOptions.newBuilder();
    optionsBuilder.setEnvironment(paymentForm.invoice.test ? WalletConstants.ENVIRONMENT_TEST : WalletConstants.ENVIRONMENT_PRODUCTION);
    optionsBuilder.setMode(WalletFragmentMode.BUY_BUTTON);

    WalletFragmentStyle walletFragmentStyle;
    if (androidPayPublicKey != null) {
        androidPayContainer.setBackgroundColor(androidPayBackgroundColor);
        walletFragmentStyle = new WalletFragmentStyle()
                .setBuyButtonText(WalletFragmentStyle.BuyButtonText.BUY_WITH)
                .setBuyButtonAppearance(androidPayBlackTheme ? WalletFragmentStyle.BuyButtonAppearance.ANDROID_PAY_LIGHT_WITH_BORDER : WalletFragmentStyle.BuyButtonAppearance.ANDROID_PAY_DARK)
                .setBuyButtonWidth(WalletFragmentStyle.Dimension.MATCH_PARENT);
    } else {
        walletFragmentStyle = new WalletFragmentStyle()
                .setBuyButtonText(WalletFragmentStyle.BuyButtonText.LOGO_ONLY)
                .setBuyButtonAppearance(WalletFragmentStyle.BuyButtonAppearance.ANDROID_PAY_LIGHT_WITH_BORDER)
                .setBuyButtonWidth(WalletFragmentStyle.Dimension.WRAP_CONTENT);
    }

    optionsBuilder.setFragmentStyle(walletFragmentStyle);
    WalletFragment walletFragment = WalletFragment.newInstance(optionsBuilder.build());
    FragmentManager fragmentManager = getParentActivity().getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    fragmentTransaction.replace(fragment_container_id, walletFragment);
    fragmentTransaction.commit();

    ArrayList<TLRPC.TL_labeledPrice> arrayList = new ArrayList<>(paymentForm.invoice.prices);
    if (shippingOption != null) {
        arrayList.addAll(shippingOption.prices);
    }
    totalPriceDecimal = getTotalPriceDecimalString(arrayList);

    PaymentMethodTokenizationParameters parameters;
    if (androidPayPublicKey != null) {
        parameters = PaymentMethodTokenizationParameters.newBuilder()
                .setPaymentMethodTokenizationType(PaymentMethodTokenizationType.NETWORK_TOKEN)
                .addParameter("publicKey", androidPayPublicKey)
                .build();
    } else {
        parameters = PaymentMethodTokenizationParameters.newBuilder()
                .setPaymentMethodTokenizationType(PaymentMethodTokenizationType.PAYMENT_GATEWAY)
                .addParameter("gateway", "stripe")
                .addParameter("stripe:publishableKey", stripeApiKey)
                .addParameter("stripe:version", StripeApiHandler.VERSION)
                .build();
    }

    MaskedWalletRequest maskedWalletRequest = MaskedWalletRequest.newBuilder()
            .setPaymentMethodTokenizationParameters(parameters)
            .setEstimatedTotalPrice(totalPriceDecimal)
            .setCurrencyCode(paymentForm.invoice.currency)
            .build();

    WalletFragmentInitParams initParams = WalletFragmentInitParams.newBuilder()
            .setMaskedWalletRequest(maskedWalletRequest)
            .setMaskedWalletRequestCode(LOAD_MASKED_WALLET_REQUEST_CODE)
            .build();

    walletFragment.initialize(initParams);
    androidPayContainer.setVisibility(View.VISIBLE);
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(ObjectAnimator.ofFloat(androidPayContainer, "alpha", 0.0f, 1.0f));
    animatorSet.setInterpolator(new DecelerateInterpolator());
    animatorSet.setDuration(180);
    animatorSet.start();
}
 
Example 12
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);
        }
    }
}