Code Monkey home page Code Monkey logo

paypal-ios-sdk's Introduction


iOS 7 Pre-Release

Check out the 1.3.0-beta pre-release for iOS 7 support and UI enhancements.


PayPal iOS SDK

The PayPal iOS SDK provides a software library that makes it easy for iOS developers to accept both credit cards and PayPal directly within native mobile apps.

For an introduction, see the PayPal Mobile SDK Overview.

Screen shots of the iOS SDK UI

Table of Contents

Overview

  • The PayPal iOS SDK...
    1. Takes care of the UI to gather payment information from the user.
    2. Coordinates payment with PayPal.
    3. Returns to you a proof of payment.
  • Your code...
    1. Receives proof of payment from the PayPal iOS SDK.
    2. Sends proof of payment to your servers for verification.
    3. Provides the user their goods or services.

Integration

Requirements

  • Xcode 4.5+ and iOS SDK 6.0+
  • iOS 5.0+ target deployment
  • armv7 and armv7s devices and the simulator (not armv6)
  • iPhone and iPad of all sizes and resolutions

Initial Setup

  1. Clone or download the SDK, which consists of header files, license acknowledgements, release notes, and a static library. It also includes a sample app.
  2. Add the PayPalMobile directory (containing several .h files and libPayPalMobile.a) to your Xcode project. We recommend checking "Copy items..." and selecting "Create groups...".
  3. In your project's Build Settings, add -lc++ -ObjC to Other Linker Flags.
  4. In your project's Build Phases, link your project with these libraries. Weak linking for iOS versions back to 5.0 is supported.
  • AVFoundation.framework
  • AudioToolbox.framework
  • CoreMedia.framework
  • CoreVideo.framework
  • libxml2.dylib
  • MessageUI.framework
  • MobileCoreServices.framework
  • OpenGLES.framework
  • QuartzCore.framework
  • Security.framework
  • SystemConfiguration.framework
  • UIKit.framework
  1. Add the open source license acknowledgments from acknowledgments.md to your app's acknowledgments.

Credentials

Take note of these two identifiers:

  • clientId: Available on the PayPal developer site.
  • receiverEmail: The email address on the PayPal account used to obtain the above clientId.

Sample Code

  1. Create a class (most likely a subclass of UIViewController) that conforms to PayPalPaymentDelegate.

    // SomeViewController.h
    #import "PayPalMobile.h"
    
    @interface SomeViewController : UIViewController<PayPalPaymentDelegate>
    // ...
    @end
  2. In your implementation, create a PayPalPayment with an amount, a currency code, and a description.

    // SomeViewController.m
    
    - (IBAction)pay {
    
      // Create a PayPalPayment
      PayPalPayment *payment = [[PayPalPayment alloc] init];
      payment.amount = [[NSDecimalNumber alloc] initWithString:@"39.95"];
      payment.currencyCode = @"USD";
      payment.shortDescription = @"Awesome saws";
    
      // Check whether payment is processable.
      if (!payment.processable) {
        // If, for example, the amount was negative or the shortDescription was empty, then
        // this payment would not be processable. You would want to handle that here.
      }
    
      // continued below...
  3. Create and display a PayPalPaymentViewController with the payment and your credentials (see above).

    Tip: Providing a payerId enables an improved experience for returning users. If you have a customer identifier that is not hardware- or device-based, such as an email address or a unique user ID in your system, you should provide it as a payerId; otherwise, pass nil.

      // ...continued from above
    
      // Start out working with the test environment! When you are ready, remove this line to switch to live.
      [PayPalPaymentViewController setEnvironment:PayPalEnvironmentNoNetwork];
    
      // Provide a payerId that uniquely identifies a user within the scope of your system,
      // such as an email address or user ID.
      NSString *aPayerId = @"[email protected]";
    
      // Create a PayPalPaymentViewController with the credentials and payerId, the PayPalPayment
      // from the previous step, and a PayPalPaymentDelegate to handle the results.
      PayPalPaymentViewController *paymentViewController;
      paymentViewController = [[PayPalPaymentViewController alloc] initWithClientId:@"YOUR_CLIENT_ID"
                                                                      receiverEmail:@"YOUR_PAYPAL_EMAIL_ADDRESS"
                                                                            payerId:aPayerId
                                                                            payment:payment
                                                                           delegate:self];
    
      // Present the PayPalPaymentViewController.
      [self presentViewController:paymentViewController animated:YES completion:nil];
    }
  4. Write delegate methods to receive either the completed payment or a cancellation. These delegate methods are responsible for dismissing the modal view controller.

    // SomeViewController.m
    
    #pragma mark - PayPalPaymentDelegate methods
    
    - (void)payPalPaymentDidComplete:(PayPalPayment *)completedPayment {
      // Payment was processed successfully; send to server for verification and fulfillment.
      [self verifyCompletedPayment:completedPayment];
    
      // Dismiss the PayPalPaymentViewController.
      [self dismissViewControllerAnimated:YES completion:nil];
    }
    
    - (void)payPalPaymentDidCancel {
      // The payment was canceled; dismiss the PayPalPaymentViewController.
      [self dismissViewControllerAnimated:YES completion:nil];
    }
  5. Send the proof of payment to your servers for verification, as well as any other processing required for your business, such as fulfillment.

    Tip: At this point, the payment has been completed, and the user has been charged. If you can't reach your server, it is important that you save the proof of payment and try again later.

    // SomeViewController.m
    
    - (void)verifyCompletedPayment:(PayPalPayment *)completedPayment {
      // Send the entire confirmation dictionary
      NSData *confirmation = [NSJSONSerialization dataWithJSONObject:completedPayment.confirmation
                                                             options:0
                                                               error:nil];
    
      // Send confirmation to your server; your server should verify the proof of payment
      // and give the user their goods or services. If the server is not reachable, save
      // the confirmation and try again later.
    }
  6. Optional: Add a preconnect to PayPal's servers.

    We recommend doing the preconnect when you first display the view controller from which your users will initiate payment. (Do not preconnect significantly earlier than that, as the connection has a limited lifetime.)

    // SomeViewController.m
    
    - (void)viewWillAppear:(BOOL)animated {
      [super viewWillAppear:animated];
    
      // Start out working with the test environment! When you are ready, remove this line to switch to live.
      [PayPalPaymentViewController setEnvironment:PayPalEnvironmentNoNetwork];
      [PayPalPaymentViewController prepareForPaymentUsingClientId:@"YOUR_CLIENT_ID"];
    }

Testing

During development and testing, use +setEnvironment: to avoid moving real money around. See the header files for more information.

International Support

Localizations

The SDK has built-in translations for many languages and locales. See the header files for a complete list.

Currencies

The SDK supports multiple currencies. See the REST API country and currency documentation for a complete, up-to-date list.

Note that currency support differs for credit card versus PayPal payments. Unless you disable credit card acceptance (via the PayPalPaymentViewController.hideCreditCardButton property), we recommend limiting transactions to currencies supported by both payment types. Currently these are: USD, GBP, CAD, EUR, JPY.

If your app initiates a transaction with a currency that turns out to be unsupported for the user's selected payment type, then the SDK will display an error to the user and write a message to the console log.

Hints & Tips

  • Avoid fraud! Be sure to verify the proof of payment.
  • Mobile networks are unreliable. Save the proof of payment to make sure it eventually reaches your server.
  • The header files are thoroughly documented; refer to them as needed for extra details about any given property or parameter.

Older Libraries

PayPal is replacing the Mobile Payments Libraries (MPL) with the PayPal iOS/Android SDK. The PayPal iOS/Android SDK is currently available in the US, with more country support coming soon. US developers should upgrade now for more features and a better mobile experience. Non-US developers can continue to use MPL for the time being. Issues related to MPL should be filed in the sdk-packages repo.

Developers with existing Express Checkout integrations or who want additional features such as authorization and capture, may wish to use Mobile Express Checkout in a webview.

paypal-ios-sdk's People

Contributors

burnto avatar josharian avatar

Watchers

James Cloos avatar Jignesh Fadadu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.