Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paytm sdk ios integration to open Paytm payment form?

Tags:

ios

xcode7

paytm

Integrated Paytm sdk 2.1 in iOS (Xcode 7) and configured to make payment .

I have a form in which amount and other fields need to filled then there is a button for Payment .

Here is code which i am using :

 //Step 1: Create a default merchant config object
    PGMerchantConfiguration *mc = [PGMerchantConfiguration defaultConfiguration];

    //Step 2: If you have your own checksum generation and validation url set this here. Otherwise use the default Paytm urls
    mc.checksumGenerationURL = @"generate checksum url";
    mc.checksumValidationURL =   @"checksum validation url";


    //Step 3: Create the order with whatever params you want to add. But make sure that you include the merchant mandatory params
    NSMutableDictionary *orderDict = [NSMutableDictionary new];
    //Merchant configuration in the order object
    orderDict[@"MID"] = @"abc1111"; 
    orderDict[@"CHANNEL_ID"] = @"WAP";
    orderDict[@"INDUSTRY_TYPE_ID"] = @"Education";
    orderDict[@"WEBSITE"] = @"companyname";
    //Order configuration in the order object
    orderDict[@"TXN_AMOUNT"] = @"100";
    orderDict[@"ORDER_ID"] = [Feepayment generateOrderIDWithPrefix:@"111"];
    orderDict[@"REQUEST_TYPE"] = @"DEFAULT";
    orderDict[@"CUST_ID"] = @"abc7777";

    PGOrder *order = [PGOrder orderWithParams:orderDict];

    //Step 4: Choose the PG server. In your production build dont call selectServerDialog. Just create a instance of the
    //PGTransactionViewController and set the serverType to eServerTypeProduction


    [PGServerEnvironment selectServerDialog:self.view completionHandler:^(ServerType type)
     {
         PGTransactionViewController *txnController = [[PGTransactionViewController alloc] initTransactionForOrder:order];

         //show title var
         UIView *mNavBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,44)];
         mNavBar.backgroundColor = [UIColor grayColor];
         txnController.topBar = mNavBar;

         //Cancel button
         UIButton *mCancelButton = [[UIButton alloc] initWithFrame:CGRectMake(5, 2, 70, 40)];
         [mCancelButton setTitle:@"Cancel" forState:UIControlStateNormal];
         mCancelButton.titleLabel.textColor = PURPLE_COLOR;
         [mCancelButton setFont:[UIFont fontWithName:@"Helvetica-Bold" size:15.0]];
         txnController.cancelButton = mCancelButton;


         //add title
         UILabel *mTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2 - 10, 1, 100, 50)];
         [mTitleLabel setText:@"Payment"];
         [mTitleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:15.0]];
         mTitleLabel.textColor = [UIColor whiteColor];
         [mNavBar addSubview:mTitleLabel];

         if (type!=eServerTypeNone) {
             txnController.serverType = type;
             txnController.merchant = mc;
             txnController.loggingEnabled = YES;
             txnController.sendAllChecksumResponseParamsToPG = YES;
             txnController.delegate = self;
             [self showController:txnController];
         }

     }];

//show controller method
-(void)showController:(PGTransactionViewController *)controller {
    if (self.navigationController != nil)
        [self.navigationController pushViewController:controller animated:YES];
    else
        [self presentViewController:controller animated:YES
                         completion:^{

                         }];
}
//remove controller
-(void)removeController:(PGTransactionViewController *)controller {
    if (self.navigationController != nil)
        [self.navigationController popViewControllerAnimated:YES];
    else
        [controller dismissViewControllerAnimated:YES
                                       completion:^{
                                       }];
}
#pragma mark PGTransactionViewController delegate

- (void)didSucceedTransaction:(PGTransactionViewController *)controller
                     response:(NSDictionary *)response {
    DEBUGLOG(@"ViewController::didSucceedTransactionresponse= %@", response);
    NSString *title = [NSString stringWithFormat:@"Your order  was completed successfully. \n %@", response[@"ORDERID"]];
    [[[UIAlertView alloc] initWithTitle:title message:[response description] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
    [self removeController:controller];
}

- (void)didFailTransaction:(PGTransactionViewController *)controller error:(NSError *)error response:(NSDictionary *)response {
    DEBUGLOG(@"ViewController::didFailTransaction error = %@ response= %@", error, response);
    if (response)
    {
        [[[UIAlertView alloc] initWithTitle:error.localizedDescription message:[response description] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
    }
    else if (error)
    {
        [[[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
    }
    [self removeController:controller];
}

- (void)didCancelTransaction:(PGTransactionViewController *)controller error:(NSError*)error response:(NSDictionary *)response {
    DEBUGLOG(@"ViewController::didCancelTransaction error = %@ response= %@", error, response);
    NSString *msg = nil;
    if (!error) msg = [NSString stringWithFormat:@"Successful"];
    else msg = [NSString stringWithFormat:@"UnSuccessful"];

    [[[UIAlertView alloc] initWithTitle:@"Transaction Cancel" message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
    [self removeController:controller];
}

- (void)didFinishCASTransaction:(PGTransactionViewController *)controller response:(NSDictionary *)response {
    DEBUGLOG(@"ViewController::didFinishCASTransaction:response = %@", response);


}

Here is screenshot while using staging directly showing this page : enter image description here

*Note - Actually i am trying for staging not for production .

When i execute then it doesnt showing Paytm feepayment form instead it showing orderid and amount with transaction id dirctly .

How to open Paytm payment form when user enter fee amount in the form then it should calcualte the amount with extraa tax and then clicking on Fee payment button it should open PAYTM PAYMENT FORM.

PLEASE HELP ME TO SOLVE THIS PROBLEM ( I HAVE GO THROUGH THE PAYTM SDK DOC STEP BY STEP BUT DINT ABLE TO FIND IT ). THANKS.

Important : **As far as checksumGenerationURL and checksumValidationURL is concerned , we need to create it . Initially i tried to use from Paytm but it dint work so finally our server team did it , this is most important point for Integrating Paytm

like image 223
Shobhakar Tiwari Avatar asked Oct 19 '22 15:10

Shobhakar Tiwari


1 Answers

Finally , Solved by testing it on the Production and its working fine . As far as Staging server is concerned i guess there is hard coded information is in the sdk so hope in the next version of PGSDK we could test it on Staging too.

Thanks .

@Pradeep k ... thank you very much for all your valuable support .

like image 81
Shobhakar Tiwari Avatar answered Oct 21 '22 05:10

Shobhakar Tiwari