2012

PayPal Mobile Express Checkout Library Developer Guide and Reference January 2011 17
- (UIButton *)getPayButtonWithTarget:(NSObject const *)target
andAction:(SEL)action andButtonType:(PayPalButtonType)inButtonType;
@end
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.
The sample application implements the fetchDeviceReferenceTokenWithAppID() method
in the same class that serves as the device-token delegate, Order2ViewController.
if (!tokenFetchAttempted) {
// Set this switch to FALSE when you initialize the class.
tokenFetchAttempted = TRUE;
// Fetch the device token just before you
// display the page with the PayPal button.
[[PayPal getInstance] fetchDeviceReferenceTokenWithAppID:@"APP-
yourAppID" withDelegate:self];
return;
The class serves as its own delegate, so it implements the following methods of the
DeviceReferenceTokenDelegate protocol.
- (void)receivedDeviceReferenceToken:(NSString *)token {
// Stash the device token somewhere to use later.
[ECNetworkHandler sharedInstance].deviceReferenceToken = token;
}
- (void)couldNotFetchDeviceReferenceToken {
// Record the errorMessage that tells what went wrong.
NSLog(@"DEVICE REFERENCE TOKEN ERROR: %@", [PayPal
getInstance].errorMessage);
[ECNetworkHandler sharedInstance].deviceReferenceToken = @"";
}
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 getPayButtonWithTarget()
method. In the following example, the payWithPayPal() method is you own method that the
system calls when the buyers click the PayPal button.