2012
PayPal Mobile Express Checkout Library Developer Guide and Reference January 2011 13
Sample Code
The sample code in this section comes from sample application code included with the download
of Mobile Express Checkout Library. Get the download of the library from x.com/mobile.
Fetching the Device Token
Regardless where you place the PayPal button, you must fetch a device token from the library by
calling fetchDeviceReferenceTokenWithAppID(). If you place the PayPal button in your
mobile application, fetch a device token just before you get the PayPal button. If you place the
PayPal button on your mobile website, fetch a device token before you open a web view of your
mobile checkout pages.
PayPal.fetchDeviceReferenceTokenWithAppID(this, appID, server, new
ResultDelegate());
The ResultDelegate class implements PayPalListener, so it implements the following methods of
the PayPalListener interface.
@Override
public void couldNotFetchDeviceReferenceToken() {
//Initialization failed and we didn't get a token
Pizza._deviceReferenceToken = null;
}
@Override
public void receivedDeviceReferenceToken(String token) {
//Initialization was successful
Pizza._deviceReferenceToken = token;
}
You mobile application can proceed with a null device token.
Placing the PayPal Button in Your Mobile Application
To place the PayPal button in your mobile application, call the getCheckoutButton() method.
You can set an OnClickListener for the CheckoutButton to capture clicks on it.
Redirecting Buyers to PayPal
Whether you place the PayPal button in your mobile application or on your mobile website, use
the same redirect to PayPal.
https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout-mobile
&drt=valueFromFetchDeviceReferenceTokenWithAppID&token=valueFromSetExpr
essCheckoutResponse