android - 在 android 中捕获 Paypal 付款

标签 android paypal

我已经在 PaymentActivity 中使用 PayPalPayment.PAYMENT_INTENT_AUTHORIZE Intent 授权了 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);

关于 Activity 结果

    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,现在我想获取这个金额。我可以在我的应用程序中执行此操作而无需任何服务器端工作吗?

最佳答案

  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。

作为对上述内容的回应,您将获得一个访问 token 。

现在向 https://api.sandbox.paypal.com/v1/payments/payment/PAY-5YK922393D847794YKER7MUI 发出 GET 请求带有 header 、内容类型 -- application/json"和授权 -- Bearer accessToken_you_get_in_above_call 。(PAY-5YK922393D847794YKER7MUI 这是您的付款 ID)

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

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

有关详细信息,请参阅:- https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/ https://developer.paypal.com/docs/integration/direct/make-your-first-call/

关于android - 在 android 中捕获 Paypal 付款,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41422439/

相关文章:

用于任意字符串的 Android 选择器小部件

java - AudioManager 在 setMode(MODE_IN_COMMUNICATION) 中引入延迟

paypal - Braintree 替代品或任何好的嵌入式结帐?

paypal - 使用 Pay Pal v0.51 的 FireFox 安全警告

paypal-sandbox - Paypal 沙盒快速结帐 session 已过期

java - 滑出菜单android java

android - IntelliJ Idea Android 项目包括 apk 中未被监视的文件

java - 如何在android中创建可变数量的textviews

javascript - 使用嵌入式灯箱的 Paypal 预付款

paypal - 未返回发票字段