Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Integrate App Payments Quickly and Seamlessly with PayPal’s Mobile Libraries

12 Jul 2010 1  
This article shows you how easy it is to process and track mobile payments with PayPal.

This article is in the Product Showcase section for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers.

(First in a series)

As new smartphones become increasingly powerful, network data speeds continue to improve, and the number of mobile applications grows, one hurdle has remained: incorporating a smooth and secure payment process for buyers. With ten years of experience managing online payments, PayPal saw that developers needed a way to seamlessly incorporate the payment process into their apps instead of forcing buyers to login to PayPal.com to complete a transaction. Buyers also needed reassurance that their payment information remained secure when conducting transactions on a mobile device.

PayPal’s new offerings make it possible for you to integrate mobile commerce payments into your apps with just a few lines of code. Merchants and customers get an easy-to-use interface that cleanly displays transaction information, supported on the backend by PayPal’s robust infrastructure. Everyone gets a speedy and trustworthy purchase process that can lead to increased sales.

This article shows you how easy it is to process and track mobile payments with PayPal. It covers the basic process from testing to launch, using the iPhone OS as an example (PayPal supports the other major smartphone OS’s, of course). It also introduces you to the variety of free resources available on the PayPal X Developer Network[^].

Register and Get a Verified Account

Your first step to developing and launching your app is to register on the PayPal X Developer Network[^], and set up your own verified PayPal Business Account. Your next stop should be the Dev Tools[^] home page where you’ll find links to all the adaptive APIs by function (Facilitate Payments, Manage Accounts, Information and Reporting), making it easy to find the best payment solution for your situation.

In the Dev Tools drop-down menu you’ll also find links to the other key resources on x.com, such as the Forums [^], training modules[^], SDKs and downloads[^], code samples[^], and more.

You’ll also want to register for the PayPal Sandbox[^] so that you can test payment email notifications later on. The sandbox lets you test your app, including setting up test accounts, managing API credentials for your test accounts, and testing an Instant Payment Notification (IPN) simulator.

Key Steps to Using the Mobile Libraries in Your App

PayPal offers mobile libraries for both the iPhone and Android operating systems. Both are available for download[^]. The developer packages include the library, the technical document, a Getting Started guide, and a sample pizza ordering and payment app that integrates the library.

The key steps to integrating the mobile library into your app for testing include:

  • Get a test PayPalApplicationID.
    You need to use a test PayPalApplicationID in order to make and receive payment requests in the PayPal Sandbox environment. The test PayPalApplicationID is APP-80W284485P519543T.
  • Confirm Set Up for PayPal Sandbox Test Accounts.
    You should have already set up test accounts in the Sandbox[^] to test the various payment transactions in your app.
  • Add the PayPal Mobile Payments Library into your project.
  • Include the header files in your project.
  • Implement the initializeWithAppID method.
    This initializes the library and sets the environment to Live, Sandbox or Demo.
  • Implement the getPayButton method.
    This generates whichever one of the seven button sizes you chose along with onClick functionality.
  • Implement the payWithPayPal method.
    Pressing the PayPal button initiates the checkout call, including whatever payment parameters were selected. You can also choose a number of optional criteria for shipping, tax, languages, and type of payments (hard goods, services, donations, person-to-person payments).
  • Add a delegate to handle the response returned by the library.
    The handler will call one of three types (paymentSuccess, paymentCancel, paymentFailed) based on the result.

This sample code from an iPhone OS app shows how these some of the key methods mentioned above are called:

- (void)viewDidLoad {
    //other viewDidLoad code
    [PayPal initializeWithAppID:@"APP-80W284485P519543T" forEnvironment:ENV_SANDBOX];
    UIButton *button = [[PayPal getInstance] getPayButton:self  buttonType:BUTTON_278x43           
                                            startCheckOut:@selector(payWithPayPal) PaymentType:HARD_GOODS
                                                withLeft:10 withTop:352];
    [self.view addSubview:button];
}
 
-(void)payWithPayPal {
    PayPal *pp = [PayPal getInstance];
    [pp EnableShipping];
    PayPalMEPPayment *payment =[[PayPalMEPPayment alloc] init];
    payment.paymentCurrency=@"USD";
    payment.paymentAmount=[NSString stringWithString:@"5.0"];
    payment.itemDesc = [NSString stringWithFormat:@"Photo Print (%@)", photoId];
    payment.recipient = @“recipient@paypal.com”;
    payment.taxAmount = [NSString stringWithString:@"0.5"];
    payment.shippingAmount = [NSString stringWithString:@"0.41"] ;
    payment.merchantName = @“MerchantName";
    [pp Checkout:payment];
    [payment release];
}

How the Mobile Checkout API Process Works

Now let’s look at how the Mobile Checkout API process will work for the buyers using your mobile app. The basic flow for buyers is a condensed version of the PayPal Web site experience:

  • At checkout time, the buyer selects a “Pay with PayPal” option. This calls the SetMobileCheckout API to start the transaction. SetMobileCheckout can be called using either PayPal SOAP Web Services or the PayPal Name-Value Pair (NVP) API. The SetMobileCheckoutRequest contains the following details:
    • Shopping cart information, including billing, tax, and shipping amounts and currencies
    • PayPal flow information, including Return URL and Cancel URL
  • The PayPal server receives the API call and returns a response containing a transaction token which then invisibly redirects the buyer to a PayPal URL with the token appended.
  • The buyer logs in to their PayPal account and selects the funding source. (If the option is activated, buyers can be offered the option to create a PIN to make the checkout process faster for future transactions.)
  • PayPal then seamlessly redirects the buyer to a merchant-supplied return URL where the buyer confirms the transaction, if needed.
  • The merchant site then calls the DoMobileCheckoutPayment API to complete transaction. Buyers see the order confirmation page.

Despite all the behind-the-scenes activity listed above, the buyer just sees two brief PayPal screens. See below for a sequence of mobile screen shots illustrating the pizza ordering checkout process as contained in the sample pizza app included in the developer packages for the iPhone OS and Android OS:

mep-1.jpgmep-2.jpgmep-3.jpg

To see another example of a finished application with seamless PayPal functionality, take a look at a sample travel application[^]. Its live interactivity will give you a hands-on look at how the payment process can be integrated.

For some of the other key resources on these processes, see:

Completing Your App and Going Live

You’re almost there. Now that you’ve successfully tested your app in the PayPal Sandbox it is time to launch your app.

  • Create and configure your live PayPal account.
    Log in to PayPal, click the Profile subtab, and ensure that the settings for Seller Preferences match your Sandbox settings or are otherwise appropriate for live use.
  • Get live API credentials.
    Log in to PayPal, click the Profile subtab, click on API Access and Request API Credentials to request a signature or certificate.
  • Configure Third-Party Authorization.
    If you are making API calls on behalf of a merchant, replicate the third-party authentication that you set up in the PayPal Sandbox on your live account.
  • Create an SDK API Profile (if applicable).
    If your application uses the PayPal SDK, you must create an API Profile object containing the live account details. This includes specifying the "environment" field as "live," as well as including your live API Username, API Password, and the path to your production API Certificate.
  • Update Firewalls with PayPal IP Addresses.
    If applicable, add PayPal's IP addresses to any list of trusted IP addresses required by your firewall or other network devices. A current list of PayPal IP addresses can be found in step #5 of the Go Live Checklist[^].
  • To receive a valid PayPalApplicationID, submit your app to PayPal.
    Before PayPal can test your application, you will need to add PayPal's device UDID (396ea30899bb294607270258115a8eb9c929c021). Then log in at the PayPal Developer Network[^] and submit your app under the My Apps tab. PayPal usually reviews submitted apps within one business day. When it’s approved, you will receive a valid PayPalApplicationID.
  • Finalize the app, go live and start making money.
    Update the test PayPalApplicationID with the new one you received from PayPal, point the “environment” field to “live” (if you have not already done so), and you are ready to launch your app into the world.

The PayPal X Developer Network helps you make the most of your apps. Whether you are developing mobile payments apps or Web apps, it offers plenty of resources to save you time and help you start making money. Register today[^].

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here