1

Working on Xcode 7.1, Swift 2.0

I work on Swift and currently trying to integrate PayU Money payment into iOS App (following this documentation).

I find it difficult to understand completion block and more the documentation is all in objective C. Can someone help me resolve this issue?

I am not a pro in programming so just wanted to make sure that I am doing the write thing.

Here is my code:

import UIKit


class ViewController: UIViewController {

var paymentParamForPassing = PayUModelPaymentParams()
var webServiceResponse: PayUWebServiceResponse = PayUWebServiceResponse()
var createRequest: PayUCreateRequest = PayUCreateRequest()



override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.



    paymentParamForPassing.key = "0MQaQP"
     paymentParamForPassing.transactionID = "Ywism0Q9XC88qvy";
     paymentParamForPassing.amount =  "10.0"
     paymentParamForPassing.productInfo =  "Nokia";
     paymentParamForPassing.firstName =  "Ram";
     paymentParamForPassing.email =  "email testsdk1.com";
     paymentParamForPassing.userCredentials =  "ra:ra";
     paymentParamForPassing.phoneNumber =  "1111111111";
     paymentParamForPassing.SURL =  "https://payu.herokuapp.com/ios_success";
     paymentParamForPassing.FURL =  "https://payu.herokuapp.com/ios_failure";
     paymentParamForPassing.udf1 =  "u1";
     paymentParamForPassing.udf2 =  "u2";
     paymentParamForPassing.udf3 =  "u3";
     paymentParamForPassing.udf4 =  "u4";
     paymentParamForPassing.udf5 =  "u5";
     paymentParamForPassing.environment = ENVIRONMENT_MOBILETEST
     paymentParamForPassing.offerKey =  "offertest 1411";

     paymentParamForPassing.hashes.paymentHash =  "ade84bf6dd9da35d0aab50a5bf61d6272ab0fc488b361b65c66745054aacf1900e3c60b5022d2114bae7360174ebcb3cd7185a5d472e5c99701e5e7e1eccec34";
     paymentParamForPassing.hashes.paymentRelatedDetailsHash =  "915299224c80eff0eb2407b945a5087556292f58baca25fd05a0bceb6826aa9eb531810001dd4b4677dd928dd60d39eecf843b2189f213f9bb82c5a9483e3aac";
     paymentParamForPassing.hashes.VASForMobileSDKHash =  "5c0314c2781876f7e0a53676b0d08e1457dafe904d2d15d948626b57409538d51093eef4f15c792b1b9651be7b5659efdd45926e43a1145d68cea094687011ca";
     paymentParamForPassing.hashes.deleteUserCardHash =  "03e10e892005755f91061121036fb1b10f46202b4138d182f153c5de5c7fd44930ed94b32fac230e59bac1e4ca123aca3297e4b9d25024bf13237db9721fec1a";
     paymentParamForPassing.hashes.offerHash =  "1e99fdb59bd91c1a85624104c0fcfae34d7fcb850dd17a0b75e7efe49857d15fdefc47dd0d86ca34cbc3a8b580839aea6341a573e4e60dc1ddcf7ecc32bf9cae";


}

I am getting the following warning at "createRequest..." line inside the paymentButtonPressed below

I am getting the following error

Cannot convert value of type '(NSMutableURLRequest, String, NSError?) -> ()' to expected argument type 'completionBlockForCreateRequestWithPaymentParam!'

@IBAction func paymentButtonPressed(sender: AnyObject) {
    createRequest.createRequestWithPaymentParam(paymentParamForPassing, forPaymentType: PAYMENT_PG_PAYU_MONEY, withCompletionBlock: {(request: NSMutableURLRequest, postParam: String, error: NSError?) in

        if error == nil {
            print("Success")
        }
        else {
            print("Fail")
        }

    })

}




override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

Anyone know what I am doing wrong?

Charles A.
  • 10,685
  • 1
  • 42
  • 39
Vicky Arora
  • 501
  • 2
  • 7
  • 20

2 Answers2

0

The signature of the completion block mismatches with the declaration in PayUCreateRequest class.

you used the following code:

withCompletionBlock:

 {(request: NSMutableURLRequest, postParam: String, error: NSError?)

The Error is of type NSString. You might use following line instead.

withCompletionBlock:

{(request: NSMutableURLRequest, postParam: String, error: String)

I hope it might help you.

AndiGeeky
  • 11,266
  • 6
  • 50
  • 66
Ganesh
  • 101
  • 1
  • 11
  • @Vicky Arora: Can you please tell me the exact way on how you integrated the PayU_iOS_CoreSDK in swift 2.0. – Ganesh Nov 23 '15 at 04:24
  • @Vicky Arora: Can you please tell me the exact way on how you integrated the PayU_iOS_CoreSDK in swift 2.0. I am trying to integrate the library in dummy proj. It doesn't compile. Also I tried to import "PayU_iOS_CoreSDK.h" in PayUDemo-Bridging-Header.h. It gave me error : 'PayU_iOS_CoreSDK.h' file not found. – Ganesh Nov 23 '15 at 04:33
  • @Ganesh Yes, I tried that. Its not working. Sorry should have mentioned that in the post. – Vicky Arora Nov 23 '15 at 10:02
  • Integration was simple, you just have to use the bridging header to use the ObjectiveC code in swift. Once you are done with that, it should work. – Vicky Arora Nov 23 '15 at 10:03
  • @Vicky Arora: Do I need to have the valid paymentParamForPassing parameters? Where can I create the test account. – Ganesh Nov 25 '15 at 04:24
  • Well, I am still having issues and that is the reason I am here on SO. Do you know why I am still getting the error? For test account you have to register your business with PayUMoney. Have to provide them your official company name, Pan card, canceled cheque, bank account and business account details. – Vicky Arora Nov 25 '15 at 06:08
  • But can't we have the test account in development phase. – Ganesh Nov 25 '15 at 06:18
  • @Ganesh I think I know what problem you are facing. I faced the same thing while integrating the SDK. I think it took me time to figure that out and have to dig a big. I will update it here once I figure that out. But anyways, lets get connected if you want to discuss more on PayU Money integration credentials. I can be reached on the email in my profile. – Vicky Arora Nov 25 '15 at 17:33
0

I worked on this. You can use this. This resolves the error.

createRequest.createRequestWithPaymentParam(paymentParamForPassing,forPaymentType: PAYMENT_PG_PAYU_MONNEY , withCompletionBlock: {(request, postParam , error) in
        if error == nil {
            print("Success")
        }
        else
        {
            print("Error data : \(error.debugDescription)")
            print("Failure")
        }
    })
Vicky Arora
  • 501
  • 2
  • 7
  • 20
Ganesh
  • 101
  • 1
  • 11
  • Sorry, I don't know how to format the code on stack overflow. – Ganesh Nov 25 '15 at 06:17
  • This works with all the dummy values. But gives the error as "Invalid payment method" on calling the above method. Do try and let me know. – Ganesh Nov 25 '15 at 06:20