【问题标题】:Capture Paypal Payment in android在 android 中捕获 Paypal 付款
【发布时间】:2017-01-02 06:46:01
【问题描述】:

我已经在PaymentActivity 中使用PayPalPayment.PAYMENT_INTENT_AUTHORIZE 意图授权了Paypal 金额,现在我有authorizationId 但现在如何获取这笔金额?

代码开始PaymentActivity

PayPalPayment thingToBuy = getStuffToBuy(PayPalPayment.PAYMENT_INTENT_AUTHORIZE);

        /*
         * See getStuffToBuy(..) for examples of some available payment options.
         */

        Intent intent = new Intent(SampleActivity.this, PaymentActivity.class);

        // send the same configuration for restart resiliency
        intent.putExtra(PayPalService.EXTRA_PAYPAL_CONFIGURATION, config);

        intent.putExtra(PaymentActivity.EXTRA_PAYMENT, thingToBuy);

        startActivityForResult(intent, REQUEST_CODE_PAYMENT);

onActivityResult

    if (requestCode == REQUEST_CODE_PAYMENT) {
        if (resultCode == Activity.RESULT_OK) {
            PaymentConfirmation confirm =
                    data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
            ProofOfPayment proof = confirm.getProofOfPayment();
            PayPalPayment payment = confirm.getPayment();
            payment.enablePayPalShippingAddressesRetrieval(true);
            JSONObject object = proof.toJSONObject();
            String authID = "";

            try {
                authID = object.getString("authorization_id");
            } catch (JSONException e) {
                e.printStackTrace();
            }

            if (confirm != null) {
                try {
                    Log.i(TAG, confirm.toJSONObject().toString(4));
                    Log.i(TAG, confirm.getPayment().toJSONObject().toString(4));
                    /**
                     *  TODO: send 'confirm' (and possibly confirm.getPayment() to your server for verification
                     * or consent completion.
                     * See https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/
                     * for more details.
                     *
                     * For sample mobile backend interactions, see
                     * https://github.com/paypal/rest-api-sdk-python/tree/master/samples/mobile_backend
                     */
                    displayResultText(authID);


                } catch (JSONException e) {
                    Log.e(TAG, "an extremely unlikely failure occurred: ", e);
                }
            }
        } else if (resultCode == Activity.RESULT_CANCELED) {
            Log.i(TAG, "The user canceled.");
        } else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
            Log.i(
                    TAG,
                    "An invalid Payment or PayPalConfiguration was submitted. Please see the docs.");
        }
    }

现在我在 authId 中有授权 ID,现在我想获取这个金额。我可以在我的应用程序中执行此操作而无需任何服务器端工作吗?

【问题讨论】:

  • 您是使用一次性付款还是未来付款
  • 我正在使用singlePayment
  • 您是否收到任何 id 以响应 "id":"PAY-564191241M8701234KL57LXI" 并且您也有访问令牌
  • 是的,我得到了 id 和授权 ID,但没有访问令牌

标签: android paypal


【解决方案1】:
  1. https://api.sandbox.paypal.com/v1/oauth2/token发帖请求

2.将Authorization type设置为Basic Auth,然后将client_id设置为Username字段,将secret设置为Password字段。

3.将Body设置为x-www-form-urlencoded,然后在key字段设置grant_type,在value字段设置client_credentials。

响应上述内容,您将获得一个访问令牌。

现在向 https://api.sandbox.paypal.com/v1/payments/payment/PAY-5YK922393D847794YKER7MUI 发出 GET 请求,带有标头、Content-Type -- application/json" 和 Authorization -- Bearer accessToken_you_get_in_above_call 。(PAY-5YK922393D847794YKER7MUI 这是您的付款 ID)

在上面的响应中,你会得到一个“state”的对象:“approved”,如果它被批准意味着你的支付已经成功完成。

注意:- 在第一个响应中,您将获得一个访问令牌,但此令牌仅在几秒钟内有效,因此如果它已过期,您必须获得另一个访问令牌。

更多详情请参考:-https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/https://developer.paypal.com/docs/integration/direct/make-your-first-call/

【讨论】:

  • 你能提供这个 api 调用的代码吗?我在 api 调用中有一些问题
  • 我得到了批准的状态,但它给了我授权的付款细节,但我想获取授权的付款,我正在谈论身份验证和捕获
  • 当您调用上述 api 时,您将收到一个包含交易的响应:金额和货币价值符合您的预期。已完成的销售(在related_resources 中,带有“state”:“completed”)。
猜你喜欢
  • 2013-04-11
  • 2021-08-31
  • 2016-12-12
  • 2012-10-12
  • 2013-08-04
  • 2016-03-07
  • 2015-11-11
  • 2016-04-24
  • 2013-03-24
相关资源
最近更新 更多