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

The following examples show how to use org.telegram.tgnet.TLRPC#TL_dataJSON . 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: VoIPService.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onControllerPreRelease(){
	if(needSendDebugLog){
		String debugLog=controller.getDebugLog();
		TLRPC.TL_phone_saveCallDebug req=new TLRPC.TL_phone_saveCallDebug();
		req.debug=new TLRPC.TL_dataJSON();
		req.debug.data=debugLog;
		req.peer=new TLRPC.TL_inputPhoneCall();
		req.peer.access_hash=call.access_hash;
		req.peer.id=call.id;
		ConnectionsManager.getInstance(currentAccount).sendRequest(req, new RequestDelegate(){
			@Override
			public void run(TLObject response, TLRPC.TL_error error){
                   if (BuildVars.LOGS_ENABLED) {
                       FileLog.d("Sent debug logs, response=" + response);
                   }
			}
		});
	}
}
 
Example 2
Source File: VoIPService.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onControllerPreRelease(){
	if(needSendDebugLog){
		String debugLog=controller.getDebugLog();
		TLRPC.TL_phone_saveCallDebug req=new TLRPC.TL_phone_saveCallDebug();
		req.debug=new TLRPC.TL_dataJSON();
		req.debug.data=debugLog;
		req.peer=new TLRPC.TL_inputPhoneCall();
		req.peer.access_hash=call.access_hash;
		req.peer.id=call.id;
		ConnectionsManager.getInstance(currentAccount).sendRequest(req, new RequestDelegate(){
			@Override
			public void run(TLObject response, TLRPC.TL_error error){
                   if (BuildVars.LOGS_ENABLED) {
                       FileLog.d("Sent debug logs, response=" + response);
                   }
			}
		});
	}
}
 
Example 3
Source File: VoIPService.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onTgVoipStop(TgVoip.FinalState finalState) {
	if (needRateCall || forceRating || finalState.isRatingSuggested) {
		startRatingActivity();
		needRateCall = false;
	}
	if (needSendDebugLog && finalState.debugLog != null) {
		TLRPC.TL_phone_saveCallDebug req = new TLRPC.TL_phone_saveCallDebug();
		req.debug = new TLRPC.TL_dataJSON();
		req.debug.data = finalState.debugLog;
		req.peer = new TLRPC.TL_inputPhoneCall();
		req.peer.access_hash = call.access_hash;
		req.peer.id = call.id;
		ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
			if (BuildVars.LOGS_ENABLED) {
				FileLog.d("Sent debug logs, response = " + response);
			}
		});
		needSendDebugLog = false;
	}
}
 
Example 4
Source File: VoIPService.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onTgVoipStop(TgVoip.FinalState finalState) {
	if (needRateCall || forceRating || finalState.isRatingSuggested) {
		startRatingActivity();
		needRateCall = false;
	}
	if (needSendDebugLog && finalState.debugLog != null) {
		TLRPC.TL_phone_saveCallDebug req = new TLRPC.TL_phone_saveCallDebug();
		req.debug = new TLRPC.TL_dataJSON();
		req.debug.data = finalState.debugLog;
		req.peer = new TLRPC.TL_inputPhoneCall();
		req.peer.access_hash = call.access_hash;
		req.peer.id = call.id;
		ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
			if (BuildVars.LOGS_ENABLED) {
				FileLog.d("Sent debug logs, response = " + response);
			}
		});
		needSendDebugLog = false;
	}
}
 
Example 5
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 6
Source File: PaymentFormActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private void sendData() {
    if (canceled) {
        return;
    }
    showEditDoneProgress(false, true);
    final TLRPC.TL_payments_sendPaymentForm req = new TLRPC.TL_payments_sendPaymentForm();
    req.msg_id = messageObject.getId();
    if (UserConfig.getInstance(currentAccount).tmpPassword != null && paymentForm.saved_credentials != null) {
        req.credentials = new TLRPC.TL_inputPaymentCredentialsSaved();
        req.credentials.id = paymentForm.saved_credentials.id;
        req.credentials.tmp_password = UserConfig.getInstance(currentAccount).tmpPassword.tmp_password;
    } else if (androidPayCredentials != null) {
        req.credentials = androidPayCredentials;
    } else {
        req.credentials = new TLRPC.TL_inputPaymentCredentials();
        req.credentials.save = saveCardInfo;
        req.credentials.data = new TLRPC.TL_dataJSON();
        req.credentials.data.data = paymentJson;
    }
    if (requestedInfo != null && requestedInfo.id != null) {
        req.requested_info_id = requestedInfo.id;
        req.flags |= 1;
    }
    if (shippingOption != null) {
        req.shipping_option_id = shippingOption.id;
        req.flags |= 2;
    }
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
        if (response != null) {
            if (response instanceof TLRPC.TL_payments_paymentResult) {
                MessagesController.getInstance(currentAccount).processUpdates(((TLRPC.TL_payments_paymentResult) response).updates, false);
                AndroidUtilities.runOnUIThread(this::goToNextStep);
            } else if (response instanceof TLRPC.TL_payments_paymentVerficationNeeded) {
                AndroidUtilities.runOnUIThread(() -> {
                    NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.paymentFinished);
                    setDonePressed(false);
                    webView.setVisibility(View.VISIBLE);
                    webviewLoading = true;
                    showEditDoneProgress(true, true);
                    progressView.setVisibility(View.VISIBLE);
                    doneItem.setEnabled(false);
                    doneItem.getImageView().setVisibility(View.INVISIBLE);
                    webView.loadUrl(((TLRPC.TL_payments_paymentVerficationNeeded) response).url);
                });
            }
        } else {
            AndroidUtilities.runOnUIThread(() -> {
                AlertsCreator.processError(currentAccount, error, PaymentFormActivity.this, req);
                setDonePressed(false);
                showEditDoneProgress(false, false);
            });
        }
    }, ConnectionsManager.RequestFlagFailOnServerErrors);
}
 
Example 7
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 8
Source File: PaymentFormActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private void sendData() {
    if (canceled) {
        return;
    }
    showEditDoneProgress(false, true);
    final TLRPC.TL_payments_sendPaymentForm req = new TLRPC.TL_payments_sendPaymentForm();
    req.msg_id = messageObject.getId();
    if (UserConfig.getInstance(currentAccount).tmpPassword != null && paymentForm.saved_credentials != null) {
        req.credentials = new TLRPC.TL_inputPaymentCredentialsSaved();
        req.credentials.id = paymentForm.saved_credentials.id;
        req.credentials.tmp_password = UserConfig.getInstance(currentAccount).tmpPassword.tmp_password;
    } else if (androidPayCredentials != null) {
        req.credentials = androidPayCredentials;
    } else {
        req.credentials = new TLRPC.TL_inputPaymentCredentials();
        req.credentials.save = saveCardInfo;
        req.credentials.data = new TLRPC.TL_dataJSON();
        req.credentials.data.data = paymentJson;
    }
    if (requestedInfo != null && requestedInfo.id != null) {
        req.requested_info_id = requestedInfo.id;
        req.flags |= 1;
    }
    if (shippingOption != null) {
        req.shipping_option_id = shippingOption.id;
        req.flags |= 2;
    }
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
        if (response != null) {
            if (response instanceof TLRPC.TL_payments_paymentResult) {
                MessagesController.getInstance(currentAccount).processUpdates(((TLRPC.TL_payments_paymentResult) response).updates, false);
                AndroidUtilities.runOnUIThread(this::goToNextStep);
            } else if (response instanceof TLRPC.TL_payments_paymentVerficationNeeded) {
                AndroidUtilities.runOnUIThread(() -> {
                    NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.paymentFinished);
                    setDonePressed(false);
                    webView.setVisibility(View.VISIBLE);
                    webviewLoading = true;
                    showEditDoneProgress(true, true);
                    progressView.setVisibility(View.VISIBLE);
                    doneItem.setEnabled(false);
                    doneItem.getImageView().setVisibility(View.INVISIBLE);
                    webView.loadUrl(((TLRPC.TL_payments_paymentVerficationNeeded) response).url);
                });
            }
        } else {
            AndroidUtilities.runOnUIThread(() -> {
                AlertsCreator.processError(currentAccount, error, PaymentFormActivity.this, req);
                setDonePressed(false);
                showEditDoneProgress(false, false);
            });
        }
    }, ConnectionsManager.RequestFlagFailOnServerErrors);
}
 
Example 9
Source File: PaymentFormActivity.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
private void sendData() {
    if (canceled) {
        return;
    }
    showEditDoneProgress(false, true);
    final TLRPC.TL_payments_sendPaymentForm req = new TLRPC.TL_payments_sendPaymentForm();
    req.msg_id = messageObject.getId();
    if (UserConfig.getInstance(currentAccount).tmpPassword != null && paymentForm.saved_credentials != null) {
        req.credentials = new TLRPC.TL_inputPaymentCredentialsSaved();
        req.credentials.id = paymentForm.saved_credentials.id;
        req.credentials.tmp_password = UserConfig.getInstance(currentAccount).tmpPassword.tmp_password;
    } else if (androidPayCredentials != null) {
        req.credentials = androidPayCredentials;
    } else {
        req.credentials = new TLRPC.TL_inputPaymentCredentials();
        req.credentials.save = saveCardInfo;
        req.credentials.data = new TLRPC.TL_dataJSON();
        req.credentials.data.data = paymentJson;
    }
    if (requestedInfo != null && requestedInfo.id != null) {
        req.requested_info_id = requestedInfo.id;
        req.flags |= 1;
    }
    if (shippingOption != null) {
        req.shipping_option_id = shippingOption.id;
        req.flags |= 2;
    }
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
        if (response != null) {
            if (response instanceof TLRPC.TL_payments_paymentResult) {
                MessagesController.getInstance(currentAccount).processUpdates(((TLRPC.TL_payments_paymentResult) response).updates, false);
                AndroidUtilities.runOnUIThread(this::goToNextStep);
            } else if (response instanceof TLRPC.TL_payments_paymentVerificationNeeded) {
                AndroidUtilities.runOnUIThread(() -> {
                    NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.paymentFinished);
                    setDonePressed(false);
                    webviewLoading = true;
                    showEditDoneProgress(true, true);
                    if (progressView != null) {
                        progressView.setVisibility(View.VISIBLE);
                    }
                    if (doneItem != null) {
                        doneItem.setEnabled(false);
                        doneItem.getContentView().setVisibility(View.INVISIBLE);
                    }
                    if (webView != null) {
                        webView.setVisibility(View.VISIBLE);
                        webView.loadUrl(webViewUrl = ((TLRPC.TL_payments_paymentVerificationNeeded) response).url);
                    }
                });
            }
        } else {
            AndroidUtilities.runOnUIThread(() -> {
                AlertsCreator.processError(currentAccount, error, PaymentFormActivity.this, req);
                setDonePressed(false);
                showEditDoneProgress(false, false);
            });
        }
    }, ConnectionsManager.RequestFlagFailOnServerErrors);
}
 
Example 10
Source File: PaymentFormActivity.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private void sendData() {
    if (canceled) {
        return;
    }
    showEditDoneProgress(false, true);
    final TLRPC.TL_payments_sendPaymentForm req = new TLRPC.TL_payments_sendPaymentForm();
    req.msg_id = messageObject.getId();
    if (UserConfig.getInstance(currentAccount).tmpPassword != null && paymentForm.saved_credentials != null) {
        req.credentials = new TLRPC.TL_inputPaymentCredentialsSaved();
        req.credentials.id = paymentForm.saved_credentials.id;
        req.credentials.tmp_password = UserConfig.getInstance(currentAccount).tmpPassword.tmp_password;
    } else if (androidPayCredentials != null) {
        req.credentials = androidPayCredentials;
    } else {
        req.credentials = new TLRPC.TL_inputPaymentCredentials();
        req.credentials.save = saveCardInfo;
        req.credentials.data = new TLRPC.TL_dataJSON();
        req.credentials.data.data = paymentJson;
    }
    if (requestedInfo != null && requestedInfo.id != null) {
        req.requested_info_id = requestedInfo.id;
        req.flags |= 1;
    }
    if (shippingOption != null) {
        req.shipping_option_id = shippingOption.id;
        req.flags |= 2;
    }
    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
        if (response != null) {
            if (response instanceof TLRPC.TL_payments_paymentResult) {
                MessagesController.getInstance(currentAccount).processUpdates(((TLRPC.TL_payments_paymentResult) response).updates, false);
                AndroidUtilities.runOnUIThread(this::goToNextStep);
            } else if (response instanceof TLRPC.TL_payments_paymentVerificationNeeded) {
                AndroidUtilities.runOnUIThread(() -> {
                    NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.paymentFinished);
                    setDonePressed(false);
                    webviewLoading = true;
                    showEditDoneProgress(true, true);
                    if (progressView != null) {
                        progressView.setVisibility(View.VISIBLE);
                    }
                    if (doneItem != null) {
                        doneItem.setEnabled(false);
                        doneItem.getContentView().setVisibility(View.INVISIBLE);
                    }
                    if (webView != null) {
                        webView.setVisibility(View.VISIBLE);
                        webView.loadUrl(webViewUrl = ((TLRPC.TL_payments_paymentVerificationNeeded) response).url);
                    }
                });
            }
        } else {
            AndroidUtilities.runOnUIThread(() -> {
                AlertsCreator.processError(currentAccount, error, PaymentFormActivity.this, req);
                setDonePressed(false);
                showEditDoneProgress(false, false);
            });
        }
    }, ConnectionsManager.RequestFlagFailOnServerErrors);
}