Skip to end of metadata
Go to start of metadata


Paypal  has been one of the most popular payment gateway  over the internet since long time. But may be due to not so developer friendly documentation , it's always hard to get started  integrating paypal for payment into mobile application. Here I will present step step process to integrate paypal in iOS application in sandbox environment.


Step 1:  Create paypal account  and paypal app

  • In order to use paypal payment into your application , you need to have account in paypal developer account. So first create your account at if you don't have already.
  • After that you need to navigate to dashboard tab. 
  • Now  create new application by clicking create app and type in your application name of your choice.

  • On creating application you will be provided with client id and secret key which you can later use in the iOS project. Along with this you can also see sandbox account something like * . Which means on creating application in paypal , it automatically create two account one for business id (prefix with facilitator) and another for buyer id(prefix with buyer).   All of the transaction made via  your application get deposited to this account. You can use buyer account  to make purchases  into your application using paypal. Or later, you may create both of them from account tab in the dashboard. 

  • To use these account , we need to first change the password of each account.  To do so , navigate to account section, click on the account of which you want to change the password and then navigate to profile.
  • You can even load the fund to the particular account to be  used in sandbox mode.

Step 2: Setup Paypal SDK


  • Now we are ready to setup paypal sdk in our application. First download the paypal sdk from or if you are using cocoa pod in your application then, add following text into Podfile

pod 'PayPal-iOS-SDK', '~> 2.11'

  • In the AppDelegate add following lines of code,

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    //paypal config    

        [PayPalMobile initializeWithClientIdsForEnvironments:@{PayPalEnvironmentProduction@"production_client_id",

                                                               PayPalEnvironmentSandbox :     @"sandbox_client_id"}];


  • In the view controller  from where you want to trigger payment action add following code

    -(void) configPaypalPayment{


        _environment = PayPalEnvironmentSandbox;

        [PayPalMobile preconnectWithEnvironment:_environment];



        // Set up payPalConfig

        _payPalConfig = [[PayPalConfiguration alloc] init];

        _payPalConfig.acceptCreditCards = YES;

        _payPalConfig.merchantName = @"Andmine";

        _payPalConfig.merchantPrivacyPolicyURL = [NSURL URLWithString:@""];

        _payPalConfig.merchantUserAgreementURL = [NSURL URLWithString:@""];

        _payPalConfig.languageOrLocale = [NSLocale preferredLanguages][0];

        _payPalConfig.payPalShippingAddressOption = PayPalShippingAddressOptionNone;




        [super viewDidLoad];

        NSLog(@"  %f", self.paymentVCBottomSpace.constant);

        [self configPaypalPayment];


    - (IBAction)paypalClicked:(id)sender {


        // Optional: include multiple items

        PayPalItem *item1 = [PayPalItem itemWithName:@"Premium chat service"


                                           withPrice:[NSDecimalNumber decimalNumberWithString:@"100"]



        NSArray *items = @[item1];

        NSDecimalNumber *subtotal = [PayPalItem totalPriceForItems:items];


        // Optional: include payment details

        NSDecimalNumber *shipping = [[NSDecimalNumber alloc] initWithString:@"0"];

        NSDecimalNumber *tax = [[NSDecimalNumber alloc] initWithString:@"0"];

        PayPalPaymentDetails *paymentDetails = [PayPalPaymentDetails paymentDetailsWithSubtotal:subtotal




        NSDecimalNumber *total = [[subtotal decimalNumberByAdding:shipping] decimalNumberByAdding:tax];


        PayPalPayment *payment = [[PayPalPayment alloc] init];

        payment.amount = total;

        payment.currencyCode = @"AUD";

        payment.shortDescription = @"Unlock Premium chat service.";

        payment.items = items;  // if not including multiple items, then leave payment.items as nil

        payment.paymentDetails = paymentDetails; // if not including payment details, then leave payment.paymentDetails as nil


        if (!payment.processable) {

            // This particular payment will always be processable. If, for

            // example, the amount was negative or the shortDescription was

            // empty, this payment wouldn't be processable, and you'd want

            // to handle that here.





        PayPalPaymentViewController *paymentViewController = [[PayPalPaymentViewController alloc] initWithPayment:payment



        [self presentViewController:paymentViewController animated:YES completion:nil];


  • Boom , that's it.  you have integrated the paypal payment gateway into your iOS application.  You will be presented with following payment screens via paypal SDKs.

Step 3: Checking Payment conformation

Now you may be wondering how to conform whether payment is made and application owner received the payment.  

  • For buyer,   use the buyer email  and password to login sandbox account.







  • No labels