PayPal APIs_ Up and Running_ A Developer's Guide - Michael Balderas [43]
ENV_LIVE
ENV_SANDBOX
ENV_NONE
del: Your delegate function that receives device tokens (required).
getPayButtonWithTarget method
If your payment implementation is in a mobile application, you can get a button from the MEC library. The getPayButtonWithTarget method returns a UIButton for use on your mobile application screen, and it provides a target: parameter that allows you to specify which UIViewController receives the callbacks. Table 5-3 outlines the parameters for getPayButtonWithTarget.
Table 5-3. getPayButtonWithTarget method
Parameter Description
target: The UIViewController that is the delegate for callbacks (required).
action: Your method that responds to the PayPal button click (required).
buttonType: The size and appearance of the PayPal button (required). Allowable values are:
BUTTON_152x33
BUTTON_194x37
BUTTON_278x43
BUTTON_294x43
getInstance method
You can use the getInstance method to specify and access the library’s runtime properties. This can be used for debugging purposes as well as to verify that your payment is working properly. Table 5-4 outlines the parameters for getInstance.
Table 5-4. getInstance method
Parameter Description
lang The locale code for the label of the PayPal button. By default, the library uses the locale of the device.
errorMessage If the library fails to acquire a valid device token, the error message provides more details about the failure.
paymentsEnabled If your attempt to fetch a device token succeeded, the value of this property is TRUE .
MEC Localization Support
MEC supports numerous locales, which can be specified after you initialize the library. By default it will determine the local of the user’s device, and if it does not support the device’s locale, it will fall back on en_US. You specify the locale with the lang property of the PayPal object. This should be set after initializing the library and before you make the call to getPayButtonWithTarget() to get a localized button. Table 5-5 lists the supported localizations.
Table 5-5. Supported localizations
Country or region Supported locale codes
Argentina es_AR
Brazil pt_BR
Australia en_AU
Belgium en_BE, nl_BR, fr_BE
Canada en_CA, fr_CA
France fr_FR, en_FR
Germany de_DE, en_DE
Hong Kong zh_HK, en_HK
India en_IN
Italy it_IT
Japan ja_JP, en_JP
Mexico es_MX, en_MX
Netherlands nl_NL, en_NL
Poland pl_PL, en_PL
Singapore en_SG
Spain es_ES, en_ES
Switzerland de_CH, en_CH, fr_CH
Taiwan zh_TW, en_TW
United States en_US
Sample MEC Code
Example 5-1. PayPal.h #import typedef enum PayPalEnvironment { ENV_LIVE, ENV_SANDBOX, ENV_NONE, } PayPalEnvironment; typedef enum PayPalButtonType { BUTTON_118x24, BUTTON_152x33, BUTTON_194x37, BUTTON_278x43, BUTTON_294x43, BUTTON_TYPE_COUNT, }PayPalButtonType; @protocol DeviceReferenceTokenDelegate @required - (void)receivedDeviceReferenceToken:(NSString *)token; - (void)couldNotFetchDeviceReferenceToken; //Check the errorMessage property to see what //the problem was. @end @interface PayPal : NSObject @private BOOL initialized;//Determines if the initialization call has finished and the PayPal //object is initialized. BOOL paymentsEnabled; NSString *appID; NSString *lang; PayPalEnvironment environment; NSString *errorMessage; NSMutableArray *payButtons; id } @property (nonatomic, retain) NSString *lang; @property (nonatomic, retain) NSString *errorMessage; @property (nonatomic, retain) NSMutableArray *payButtons; @property (nonatomic, readonly) NSString *appID; @property (nonatomic, readonly) BOOL initialized; @property (nonatomic, readonly) BOOL paymentsEnabled; @property (nonatomic,
The MEC library includes a library header file, PayPal.h, for your mobile application or mobile web code. The contents of PayPal.h are shown in Example 5-1. You can access features of the MEC library using the "PayPal : NSObject