[英]Capture Paypal Payment in android
I have authorized Paypal amount using PayPalPayment.PAYMENT_INTENT_AUTHORIZE
intent in PaymentActivity
now i have authorizationId but how to capture this amount now? 我已经使用PayPalPayment.PAYMENT_INTENT_AUTHORIZE
意图在PaymentActivity
授权Paypal金额现在我有授权PaymentActivity
但现在如何捕获这个金额?
Code to start PaymentActivity
用于启动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 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.");
}
}
Now I have authorization id in authId now i want to capture this amount. 现在我在authId中有授权ID,现在我想捕获这个数量。 Can I do this within my app without any server side work. 我是否可以在我的应用程序中执行此操作而无需任何服
2.Set the Authorization type to Basic Auth and then set the client_id into the Username field and secret into the Password field. 2.将Authorization类型设置为Basic Auth,然后将client_id设置为Username字段,将secret设置为Password字段。
3.Set the Body to x-www-form-urlencoded and then set grant_type in the key field and client_credentials in the value field. 3.将Body设置为x-www-form-urlencoded,然后在key字段中设置grant_type,在value字段中设置client_credentials。
In response to above you will get an access token. 作为对上述的回应,您将获得访问令牌。
Now make GET request to https://api.sandbox.paypal.com/v1/payments/payment/PAY-5YK922393D847794YKER7MUI with Headers, Content-Type -- application/json" and Authorization -- Bearer accessToken_you_get_in_above_call .(PAY-5YK922393D847794YKER7MUI this is your payment id) 现在使用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 this是您的付款ID)
In response of above you will get an object as "state": "approved", if it is approved means your payment has been successfully done. 如上所述,您将获得一个“州”对象:“已批准”,如果已获批准则表示您的付款已成功完成。
Note:- In the first response you will get an access token, but this token is valid for only few seconds , so you have to get another access token if it is expired. 注意: - 在第一个响应中,您将获得一个访问令牌,但此令牌仅在几秒钟内有效,因此如果它已过期,您必须获得另一个访问令牌。
For more details refer:- https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/ https://developer.paypal.com/docs/integration/direct/make-your-first-call/ 有关详细信息,请参阅: - https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/ https://developer.paypal.com/docs/integration/direct/make-你先呼叫/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.