Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to integrate PAYPAL for future payment

    • 0
    • 2
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.20k
    Comment on it

    Hello Readers

    To integrate PayPal in an ios application for future payment , the following steps need to be followed:

    Step 1: Download the PayPal ios sdk from the link given below: [https://github.com/paypal/PayPal-iOS-SDK][1]

    Step 2 : Import the "PayPalMobile.h" header file in the ViewController and implement the delegate methods.

    In the appdelegate file add the following line of code in

       - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
    [PayPalMobile initializeWithClientIdsForEnvironments:@{ PayPalEnvironmentSandbox : ClientId}];
    

    where Client id is obtained from the app created on PayPal developer(developer.paypal.com).

    Step 3: Send the authorization code recieved to your server for further processing:

    - (void)payPalFuturePaymentViewController:(PayPalFuturePaymentViewController *)futurePaymentViewController
                    didAuthorizeFuturePayment:(NSDictionary *)futurePaymentAuthorization {
        NSLog(@"PayPal Future Payment Authorization Success!");
    
        [self sendFuturePaymentAuthorizationToServer:futurePaymentAuthorization];
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    
    - (void)payPalFuturePaymentDidCancel:(PayPalFuturePaymentViewController *)futurePaymentViewController {
        NSLog(@"PayPal Future Payment Authorization Canceled");
           [self dismissViewControllerAnimated:YES completion:nil];
    }
    
    - (void)sendFuturePaymentAuthorizationToServer:(NSDictionary *)authorization {
        // TODO: Send authorization to server
        NSLog(@"Here is your authorization:\n\n%@\n\nSend this to your server to complete future payment setup.", authorization);
        NSDictionary *temp =[authorization objectForKey:@"response"];
        NSString *authcode =[temp objectForKey:@"code"];
        metaid=[PayPalMobile clientMetadataID];
    
        NSDictionary *dict;
           // Send the authorization code, client metaid , id of the person paying and the person recieving payment and other required parameter
        [self serverHitForAuthentication:dict];
    }
    

    Step 4: :Save the refresh token received from the server.(In Utility file)

    [Utility saveRefreshToken: refreshToken]

    Step 5: If you have the refresh token and you again make any payment , there is no need to send the authorization code and no need to re enter the username and password again.

    NSString *token = [Utility getRefreshToken];
    
        if(token.length >0)
            {
               // Send the client metaid and id of the person sending and recieving payment and any other required parameter in the dictionary.
               [self serverHitForAuthentication:dict];
            }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: