Reputation: 113
I integrated PayPal Mobile Payments into my Application. That was no big deal. I have it set up that when a customer makes a purchase from my app the details are are posted to my server. No big deal either. But, for the life of me, I cannot get the PayPal transaction details. I see the details in the LogCat but No matter what I try I cannot grab anything. I know it has to be simple but I have been sitting here and every attempt is fruitless. I can get some of the details but not all. Any help would be appreciated. I didn't do anything Dramatic to the Code Posted on the PayPal developer site yet until I fully get the grasp of their SDK but here it is.
protected void onActivityResult (int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);
if (confirm != null) {
try {
Log.i("paymentExample", confirm.toJSONObject().toString(4));
// TODO: send 'confirm' to your server for verification.
// see https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/
// for more details.
//String PAYMENT_CONFIRMATION = confirm.toJSONObject().getJSONObject("pay_key").toString();
// Log.d("PAYMENT CONFIRMATION KEY::", PAYMENT_CONFIRMATION) ;
new Update_CloseLines().execute();
} catch (JSONException e) {
Log.e("paymentExample", "an extremely unlikely failure occurred: ", e);
}
}
}
else if (resultCode == Activity.RESULT_CANCELED) {
Log.i("paymentExample", "The user canceled.");
}
else if (resultCode == PaymentActivity.RESULT_PAYMENT_INVALID) {
Log.i("paymentExample", "An invalid payment was submitted. Please see the docs.");
}
}
Here is the logcat.
08-26 13:04:01.780: I/paymentExample(830): {
08-26 13:04:01.780: I/paymentExample(830): "payment": {
08-26 13:04:01.780: I/paymentExample(830): "short_description": "Nite Rider Hollow",
08-26 13:04:01.780: I/paymentExample(830): "amount": "1.01",
08-26 13:04:01.780: I/paymentExample(830): "currency_code": "USD"
08-26 13:04:01.780: I/paymentExample(830): },
08-26 13:04:01.780: I/paymentExample(830): "client": {
08-26 13:04:01.780: I/paymentExample(830): "platform": "Android",
08-26 13:04:01.780: I/paymentExample(830): "paypal_sdk_version": "1.0.3",
08-26 13:04:01.780: I/paymentExample(830): "product_name": "PayPal Android SDK; ",
08-26 13:04:01.780: I/paymentExample(830): "environment": "live"
08-26 13:04:01.780: I/paymentExample(830): },
08-26 13:04:01.780: I/paymentExample(830): "proof_of_payment": {
08-26 13:04:01.780: I/paymentExample(830): "adaptive_payment": {
08-26 13:04:01.780: I/paymentExample(830): "timestamp": "2013-08-26T18:03:55+0000",
08-26 13:04:01.780: I/paymentExample(830): "payment_exec_status": "COMPLETED",
08-26 13:04:01.780: I/paymentExample(830): "app_id": "APP-XXXXXXXXXXXXXXXX",
08-26 13:04:01.780: I/paymentExample(830): "pay_key": "AP-XXXXXXXXXXXXXXXXXX"
08-26 13:04:01.780: I/paymentExample(830): }
08-26 13:04:01.780: I/paymentExample(830): }
08-26 13:04:01.780: I/paymentExample(830): }
08-26 13:04:01.780: E/paymentExample(830): an extremely unlikely failure occurred:
08-26 13:04:01.780: E/paymentExample(830): org.json.JSONException: No value for pay_key
08-26 13:04:01.780: E/paymentExample(830): at org.json.JSONObject.get(JSONObject.java:354)
08-26 13:04:01.780: E/paymentExample(830): at org.json.JSONObject.getJSONObject(JSONObject.java:569)
08-26 13:04:01.780: E/paymentExample(830): at com.example.shopper.ConfirmCheckOut.onActivityResult(ConfirmCheckOut.java:480)
08-26 13:04:01.780: E/paymentExample(830): at android.app.Activity.dispatchActivityResult(Activity.java:5390)
08-26 13:04:01.780: E/paymentExample(830): at android.app.ActivityThread.deliverResults(ActivityThread.java:3178)
08-26 13:04:01.780: E/paymentExample(830): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3225)
08-26 13:04:01.780: E/paymentExample(830): at android.app.ActivityThread.access$1100(ActivityThread.java:140)
08-26 13:04:01.780: E/paymentExample(830): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1275)
08-26 13:04:01.780: E/paymentExample(830): at android.os.Handler.dispatchMessage(Handler.java:99)
08-26 13:04:01.780: E/paymentExample(830): at android.os.Looper.loop(Looper.java:137)
08-26 13:04:01.780: E/paymentExample(830): at android.app.ActivityThread.main(ActivityThread.java:4898)
08-26 13:04:01.780: E/paymentExample(830): at java.lang.reflect.Method.invokeNative(Native Method)
08-26 13:04:01.780: E/paymentExample(830): at java.lang.reflect.Method.invoke(Method.java:511)
08-26 13:04:01.780: E/paymentExample(830): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
08-26 13:04:01.780: E/paymentExample(830): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
08-26 13:04:01.780: E/paymentExample(830): at dalvik.system.NativeStart.main(Native Method)
08-26 13:04:01.850: E/SpannableStringBuilder(830): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
08-26 13:04:01.850: E/SpannableStringBuilder(830): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
If I could, I would like to grab the pay_key.
Unlikely ERROR:
08-26 14:13:27.115: E/paymentExample(13971): an extremely unlikely failure occurred:
08-26 14:13:27.115: E/paymentExample(13971): org.json.JSONException: Value AP-6S9448074V032801M at pay_key of type java.lang.String cannot be converted to JSONObject
08-26 14:13:27.115: E/paymentExample(13971): at org.json.JSON.typeMismatch(JSON.java:100)
08-26 14:13:27.115: E/paymentExample(13971): at org.json.JSONObject.getJSONObject(JSONObject.java:573)
08-26 14:13:27.115: E/paymentExample(13971): at com.example.shopper.ConfirmCheckOut.onActivityResult(ConfirmCheckOut.java:480)
08-26 14:13:27.115: E/paymentExample(13971): at android.app.Activity.dispatchActivityResult(Activity.java:5390)
08-26 14:13:27.115: E/paymentExample(13971): at android.app.ActivityThread.deliverResults(ActivityThread.java:3178)
08-26 14:13:27.115: E/paymentExample(13971): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3225)
08-26 14:13:27.115: E/paymentExample(13971): at android.app.ActivityThread.access$1100(ActivityThread.java:140)
08-26 14:13:27.115: E/paymentExample(13971): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1275)
08-26 14:13:27.115: E/paymentExample(13971): at android.os.Handler.dispatchMessage(Handler.java:99)
08-26 14:13:27.115: E/paymentExample(13971): at android.os.Looper.loop(Looper.java:137)
08-26 14:13:27.115: E/paymentExample(13971): at android.app.ActivityThread.main(ActivityThread.java:4898)
08-26 14:13:27.115: E/paymentExample(13971): at java.lang.reflect.Method.invokeNative(Native Method)
08-26 14:13:27.115: E/paymentExample(13971): at java.lang.reflect.Method.invoke(Method.java:511)
08-26 14:13:27.115: E/paymentExample(13971): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
08-26 14:13:27.115: E/paymentExample(13971): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
08-26 14:13:27.115: E/paymentExample(13971): at dalvik.system.NativeStart.main(Native Method)
Upvotes: 1
Views: 2541
Reputation: 2850
For production applications, you'll really want send the whole confirmation JSON to your server. There it can be parsed and the pay_key
or payment_id
can be used to get transaction details by querying the proper API. (See https://developer.paypal.com)
The security context given to a mobile device is more restrictive since the app will get installed on devices outside your control.
See https://developer.paypal.com/webapps/developer/docs/integration/mobile/verify-mobile-payment/ for a more detailed explanation.
Upvotes: 2