PayPal provides a Mobile Express Checkout (MEC) library for iOS, available for download from https://www.x.com/co...obile/mobile_ec. This MEC library supports two different programming flows: it can be called either directly from your mobile application or via a PayPal button on your mobile website.
MEC Mobile Application Integration
MEC can be integrated into your mobile application, allowing you to start and end the payment process with screens inside your application. The MEC checkout pages themselves are contained inside a web view. The steps for doing so are as follows:
1. Acquire a device token from the MEC library before rendering the payment screen with the PayPal Button. Include a pointer to the method you delegate for handling the device token.
2. Acquire a PayPal payment button from the Library and render it on your mobile application screen. Include a pointer to the method you delegate for handling the button-click event.
3. When your customer clicks the PayPal button, it will initialize your delegated method to do the following:
- Call a routine on your mobile web server for passing the payment information.
- Your mobile web server will then send a
SetExpressCheckoutrequest with the payment information to PayPal.
- Pass the checkout token returned from
SetExpressCheckoutback to your mobile application.
- Open a web view redirecting the customer’s browser to PayPal with the
Mobilecommand, using the device token and the checkout token as URL parameters. For example:
https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout-mobile &drt=valueFromMobileExpressCheckoutLibrary&token=valueFromSetExpressCheckoutResponse
- Watch the web view for a redirect call from PayPal to either your return or cancel URLs.
- If PayPal redirects the web view to your return URL, call surrogate routines on your mobile web server that send
GetExpressCheckoutDetailsandDoExpressCheckoutPaymentrequests to PayPal to complete the payment.
MEC Mobile Website Integration
MEC can be integrated directly with your mobile website, allowing you to start and end the payment process with pages on your site. The steps for doing so are as follows:
- Acquire a device token from the MEC library before rendering the web view of your MEC implementation. Include a pointer to the method you delegate for handling the device token.
- Launch a web view of the web page or routine on your mobile server that initiates your checkout process. Include the device token as a URL parameter, as well as the item details in the shopping cart.
- Watch the web view for a redirect from your mobile web server that contains a call to a known URL, signaling the checkout process is complete.
MEC Library Methods
MEC contains three methods:
fetchDeviceReferenceTokenWithAppID, getPayButtonWithTarget, and getInstance. Let’s look at each in depth.fetchDeviceReferenceTokenWithAppID method
The
fetchDeviceReferenceTokenWithAppID method returns a device token for use with the transaction. Use the del parameter to specify your delegate function that receives device tokens. Device tokens have a 45-minute expiration time limit, and are passed as the &drt parameter on the URL when you redirect the mobile browser to PayPal.The MEC library uses the PayPal production servers by default to get device tokens. During your development process, use the env parameter to fetch device tokens from the sandbox. Be sure to fetch the device token just before you get the PayPal button. When you fetch the device token, the library determines whether the buyer stays logged in on the device. If the buyer is already logged into PayPal, the library will display the buyer’s name above the button when it renders. The table below outlines the parameters for
fetchDeviceReferenceTokenWithAppID.| Parameter | Description |
inAppId: | The PayPal Application ID from X.com (required). For the sandbox environment, use APP-80W284485P519543T. |
env: | Indicates which PayPal servers the library uses (optional). Allowable values are:
|
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. The table below outlines the parameters for getPayButtonWithTarget.| 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:
|
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. The table below outlines the parameters for getInstance.| 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. |
A full example of using the MEC library for an online pizza delivery service application can be found in the library download at https://www.x.com/co...obile/mobile_ec.
Does your web application provide users with a convenient way to complete transactions? This book introduces you to PayPal’s APIs with instruction and resources for integrating this popular payment solution in different application environments, including mobile. By the end of this book, you'll have a clear understanding of what PayPal is and how you can get the most out of its powerful features for your particular payment situation.




Help








