当前位置: 首页>>代码示例>>Java>>正文


Java PaymentConfirmation.toJSONObject方法代码示例

本文整理汇总了Java中com.paypal.android.sdk.payments.PaymentConfirmation.toJSONObject方法的典型用法代码示例。如果您正苦于以下问题:Java PaymentConfirmation.toJSONObject方法的具体用法?Java PaymentConfirmation.toJSONObject怎么用?Java PaymentConfirmation.toJSONObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.paypal.android.sdk.payments.PaymentConfirmation的用法示例。


在下文中一共展示了PaymentConfirmation.toJSONObject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onActivityResult

import com.paypal.android.sdk.payments.PaymentConfirmation; //导入方法依赖的package包/类
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    //If the result is from paypal
    if (requestCode == PAYPAL_REQUEST_CODE) {

        if (resultCode == Activity.RESULT_OK) {

            //If the result is OK i.e. user has not canceled the payment
            //Getting the payment confirmation
            PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);

            //if confirmation is not null
            if (confirm != null) {
                try {
                    //Getting the payment details
                    JSONObject paypalDetailsJson = confirm.toJSONObject();
                    JSONObject paypalResponseJson = paypalDetailsJson.getJSONObject("response");

                    Payment payment = new Payment();
                    payment.setPaymentId(paypalResponseJson.getString("id"));
                    payment.setAmount(view.getPaymentAmount());
                    payment.setTimestamp(System.currentTimeMillis());

                    //Sending payment info on Firebase
                    //Registering an payment on server
                    model.savePaymentInfo(payment);

                    showLog("PAYPAL: SUCCESS");
                    showLog("PAYPAL: state -> " + paypalResponseJson.getString("state"));
                    showLog("PAYPAL: id -> " + paypalResponseJson.getString("id"));

                    //Show dialog <Payment Success>
                    new InfoDialogCustom()
                            .create(getContext(), getContext().getString(R.string.payment_success_title_info),
                                    getContext().getString(R.string.payment_success_description_info))
                            .setOnOkClickedListener(new IDialogInfoOkClickedListener() {
                                @Override
                                public void onOkClick() {

                                    view.clearPaymentAmount();
                                    view.setBtnPayEnabled(true);
                                }
                            })
                            .show(600);

                } catch (JSONException e) {
                    showLog("an extremely unlikely failure occurred: " + e);
                }
            }
        } else if (resultCode == Activity.RESULT_CANCELED) {
            showLog("The user canceled.");
        } else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
            showLog("An invalid Payment or PayPalConfiguration was submitted. Please see the docs.");
        }
    }
}
 
开发者ID:pedromassango,项目名称:Programmers,代码行数:57,代码来源:Presenter.java

示例2: onResumeFragments

import com.paypal.android.sdk.payments.PaymentConfirmation; //导入方法依赖的package包/类
@Override
protected void onResumeFragments() {
	super.onResumeFragments();
	// Process a PaymentResult from onActivityResult
	if (paymentResult != null) {
		int resultCode = paymentResult.resultCode;
		PaymentConfirmation confirm = paymentResult.confirmation;
		paymentResult = null;
		if (resultCode == Activity.RESULT_OK && confirm != null) {
			if (selectedPriceId == null) {
				MessageDialog.show(R.string.shop_activity_missingprice,
						this);
				return;
			}

			JSONObject paymentJson = confirm.toJSONObject();
			// Save Payment, so that payment can be verified later.
			Account account = new Account(accountName,
					Constants.ACCOUNT_TYPE);
			AccountManager accountManager = AccountManager.get(this);
			SyncUtils.savePayment(account, accountManager, paymentJson,
					selectedPriceId);

			SyncUtils.startPaymentVerification();
			// Start Timer to verify Payment if Verification could not be
			// done now.
			PaymentVerificationService
					.startVerificationTimer(getApplicationContext());

			// Send Confirmation to server
			boolean verifStarted = false;
			try {
				String jsonData = paymentJson.toString(1);
				VerifyPaymentProgressDialog progressDialog = VerifyPaymentProgressDialog
						.newInstance(selectedPriceId, jsonData, accountName);
				progressDialog.show(this.getSupportFragmentManager(),
						"VerifyPaymentProgressDialog");
				if (Log.isLoggable(TAG, Log.DEBUG)) {
					Log.d(TAG, "PaymentConfirmation: " + jsonData);
				}
				verifStarted = true;
			} catch (JSONException e) {
				MessageDialog.show(R.string.shop_activity_invalidsyntax,
						this);
				Log.e(TAG, "Failed to convert Payment to JSON.", e);
				SyncUtils.savePayment(account, accountManager, null, null);
			} finally {
				if (!verifStarted) {
					SyncUtils.stopPaymentVerification();
				}
			}
		} else if (resultCode == Activity.RESULT_CANCELED) {
			Log.i(TAG, "The user canceled the payment-flow");
		} else if (resultCode == PaymentActivity.RESULT_PAYMENT_INVALID) {
			MessageDialog.show(R.string.shop_activity_invalidpayment, this);
			Log.i(TAG, "An invalid payment was submitted.");
		} else {
			MessageDialog.show(R.string.shop_activity_invalidpayment, this);
			Log.e(TAG, "PaymentResult is unknown. Result:" + resultCode
					+ " Confirmation:" + confirm);
		}
	}
	getSupportLoaderManager().initLoader(LOADID_PRICES, null, this);
	View progressBar = findViewById(R.id.progressBar);
	View reloadBtn = findViewById(R.id.reloadBtn);
	reloadBtn.setVisibility(View.GONE);
	progressBar.setVisibility(View.VISIBLE);
	getListView().setEmptyView(progressBar);

	// Show a Message from a delayed Verification
	String msg = getIntent().getStringExtra(PARM_MSG);
	if (msg != null) {
		MessageDialog.show(msg, this);
		getIntent().removeExtra(PARM_MSG);
	}
}
 
开发者ID:mgrieder,项目名称:ntsync-android,代码行数:77,代码来源:ShopActivity.java


注:本文中的com.paypal.android.sdk.payments.PaymentConfirmation.toJSONObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。