Developer's Guide
Mobile Payments Library Developer Guide and Reference – Android OS Edition July 2011 17
Activity.RESULT_OK
This result is returned when a PayPal payment succeeds. The pay key is available in the Intent
data as PayPalActivity.EXTRA_PAY_KEY. The code to get the pay key as a string is:
data.getStringExtra(PayPalActivity.EXTRA_PAY_KEY).
Activity.RESULT_CANCELED
This result is returned if the buyer cancels the payment during checkout.
paymentCanceled();
PayPalActivity.RESULT_FAILURE
This result is returned if the payment fails for any reason other than a buyer who cancels the
payment during checkout. The error id and the buyer-friendly error message are available from
the Intent data as PayPalActivity.EXTRA_ERROR_ID and
PayPalActivity.EXTRA_ERROR_MESSAGE.
Example code on handling the response is:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent
data) {
switch(resultCode) {
case Activity.RESULT_OK:
//The payment succeeded
String payKey =
data.getStringExtra(PayPalActivity.EXTRA_PAY_KEY);
//Tell the user their payment succeeded
break;
case Activity.RESULT_CANCELED:
//The payment was canceled
//Tell the user their payment was canceled
break;
case PayPalActivity.RESULT_FAILURE:
//The payment failed -- we get the error from the
EXTRA_ERROR_ID and EXTRA_ERROR_MESSAGE
String errorID =
data.getStringExtra(PayPalActivity.EXTRA_ERROR_ID);
String errorMessage =
data.getStringExtra(PayPalActivity.EXTRA_ERROR_MESSAGE);
//Tell the user their payment was failed.
}
}
For a list of error types, see “Enumerated Values in the Mobile Payments Library” on page 24.