在Android中捕获Paypal付款

时间:2017-01-02 06:46:02

标签: android paypal

我已经PayPalPayment.PAYMENT_INTENT_AUTHORIZE使用PaymentActivity意图授权Paypal金额现在我有授权ID但是现在如何获取此金额?

启动代码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现在我想捕获这个数量。我可以在我的应用程序中执行此操作而无需任何服务器端工作。

1 个答案:

答案 0 :(得分:0)

  1. https://api.sandbox.paypal.com/v1/oauth2/token
  2. 发帖请求

    2.将授权类型设置为Basic Auth,然后将client_id设置为Username字段,将secret设置为Password字段。

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

    作为对上述的回应,您将获得一个访问令牌。

    现在使用Headers,Content-Type - application / json“和授权 - Bearer accessToken_you_get_in_above_call向https://api.sandbox.paypal.com/v1/payments/payment/PAY-5YK922393D847794YKER7MUI发出GET请求。(PAY-5YK922393D847794YKER7MUI这是您的付款ID)

    如上所述,您将获得一个“州”对象:“已批准”,如果已获批准则表示您的付款已成功完成。

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

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