csob / paymentgateway

English documentation of the ČSOB Payment Gateway that offers an API for credit card payments, Apple Pay, Google Pay, mallpay and ČSOB Payment Button.
https://platbakartou.csob.cz/platebni-brana
GNU General Public License v3.0
121 stars 68 forks source link

ios request error for csob payment #44

Closed TestWebplanex closed 8 years ago

TestWebplanex commented 9 years ago

Payment Init url, "https://iapi.iplatebnibrana.csob.cz/api/v1/payment/init"

here is my request : {"description":"PrintPix APP order 431","totalAmount":7.99,"dttm":"20150910144150","merchantId":"A1050uj4XS","payMethod":"card","merchantData":"\/\/5PAHIAZABlAHIAIABvAGYAIAAxACAAcABoAG8AdABvAHMA","cart":[{"quantity":1,"amount":7.99,"name":"Order of photos","description":"PrintPix - photos printing"}],"payOperation":"payment","orderNo":"431","returnMethod":"POST","signature":"Fl5VC\/qWyuu3JhhpQ01BuxVLWAgkiUDYO4jgZS2UNsC+Gqd6WDP\/VeV1bZp9WfOYv33RHq2f8+1VNMmEOTHVcP0PwOleaGy\/ysjV7isf+sldogrIMimCVdyuWLXgn5ZOlFtmNOvOkqPVWOhkT2NDSVzfTwIZG1ge7MyQNffVut\/Vlff1X9uhzciU843xJ1ZLyBis1XMKLyECxZs24pnX4uKHLgchBlpOOqhQFbQGJSiHyKZRtN9OT4nMuQfxxdaT12k0+6EWzunlItsJSpntsGdBBv4CPHLnxqj+ELtgrbgwciEhvxMQkX+1zO6r8iJe2bs9PALuIaKRE9ISMhNrEA==","closePayment":"true","language":"EN","currency":"USD","returnUrl":"https:\/\/www.print-pix.eu\/functions\/csob_return_payment\/"}

Getting response from server : Error: Request failed: bad request (400)

Thanks Bhupendra

ratajskym commented 9 years ago

I can see these two records and it seems ok to me.

10th 2015, 10:51:48.838 - paymentInit - success 10th 2015, 10:52:02.838 - paymentProcess - success

TestWebplanex commented 9 years ago

@ratajskym: Thanks for reply Can you give me all code for this solution ? which method use for request. i am using blow code please check and guide me

  1. Type

    NSURL baseUrl = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.platebnibrana.csob.cz/api/v1/payment/init"]]; AFHTTPRequestOperationManager manager = [[AFHTTPRequestOperationManager alloc]initWithBaseURL:baseUrl]; manager.responseSerializer = [AFJSONResponseSerializer serializer]; manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"application/json"];

    [manager POST:@"" parameters:dic success:^(AFHTTPRequestOperation operation, id responseObject) { [FunctionManager hideLoadingView:self.view appDelegate:appDelegate viewController:self]; [self setPaymentButtonAfterPayment]; [FunctionManager showMessage:nil withMessage:@"Payment Confirmation info received from CSOB" withDelegage:self]; } failure:^(AFHTTPRequestOperation operation, NSError *error) { [FunctionManager showMessage:@"" withMessage:[error localizedDescription] withDelegage:nil]; [FunctionManager hideLoadingView:self.view appDelegate:appDelegate viewController:self];

    }];

Error message:

Error Domain=AFNetworkingErrorDomain Code=-1011 "Request failed: unsupported media type (415)" UserInfo=0x7ffca51918c0 {AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x7ffca275ed40> { URL: https://api.platebnibrana.csob.cz/api/v1/payment/init/ } { status code: 415, headers { "Cache-Control" = "no-cache, no-store, must-revalidate"; Connection = "keep-alive"; "Content-Type" = "application/json"; Date = "Mon, 14 Sep 2015 09:27:25 GMT"; Expires = 0; Pragma = "no-cache"; Server = nginx; "Transfer-Encoding" = Identity; } }, NSLocalizedDescription=Request failed: unsupported media type (415), NSErrorFailingURLKey=https://api.platebnibrana.csob.cz/api/v1/payment/init/} /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

  1. Type

    NSURL baseUrl = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.platebnibrana.csob.cz/api/v1/payment/init"]]; AFHTTPRequestOperationManager manager = [[AFHTTPRequestOperationManager alloc]initWithBaseURL:baseUrl]; manager.responseSerializer = [AFJSONResponseSerializer serializer]; manager.responseSerializer.acceptableContentTypes = [manager.responseSerializer.acceptableContentTypes setByAddingObject:@"application/json"];

[manager POST:@"" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
    [FunctionManager hideLoadingView:self.view appDelegate:appDelegate viewController:self];
    [self setPaymentButtonAfterPayment];
    [FunctionManager showMessage:nil withMessage:@"Payment Confirmation info received from CSOB" withDelegage:self];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    [FunctionManager showMessage:@"" withMessage:[error localizedDescription] withDelegage:nil];
    [FunctionManager hideLoadingView:self.view appDelegate:appDelegate viewController:self];

}];

NSURL *baseURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.platebnibrana.csob.cz/api/v1/payment/init"]];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil];
NSString *strJSON = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:baseURL
                                                       cachePolicy:NSURLRequestReloadIgnoringCacheData  timeoutInterval:10];

[request setHTTPMethod:@"POST"];
[request setValue: @"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody: [strJSON dataUsingEncoding:NSUTF8StringEncoding]];

NSLog(@"%@",strJSON);

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.responseSerializer = [AFJSONResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", [error localizedDescription]);
}];

[operation start];

Error message:

Error: Request failed: bad request (400)

ratajskym commented 9 years ago

You can find code for the solution here

TestWebplanex commented 9 years ago

Hi Ratajskym,

I have checked code but it's example of php or java and it's working for android but it is not working for ios. can you help me for ios code.

Here is my final request: {"description":"PrintPix APP order 488","totalAmount":799,"dttm":"20150915150316","merchantId":"A1050uj4XS","payMethod":"card","merchantData":"\/\/5PAHIAZABlAHIAIABvAGYAIAAxACAAcABoAG8AdABvAHMA","cart":[{"amount":799,"quantity":1,"description":"PrintPix - photos printing","name":"Order of photos"}],"payOperation":"payment","orderNo":"488","returnMethod":"POST","signature":"VZkJurjbMVA9h0tj6jLW9I91s8XocVKogEIpyDJMhhFNBEY8d2Qav4Dw1demc3FvbA2eV0Y5D\/ulv3SUwbU3T2Grv5ig569MDjhLoHVBTVY6tzaSybrusHrvXlbcVepZaNn8mApsv3T2h57IQpl\/2Sj4+TsuPnrpZr9frBMgSqBEnCYISWameRVj3Tky0wTFJ+DqsaHWYxylVlJLRufnnyBOjm8WxeoiwDOkFGd1IohIAKLceCcDfctJn6nRE7ewmUlVmInraFL7EaioXMbHkpIp5O3rWfSp7+AASAj43C7\/g\/1US\/Y+PtXcVZBh6wGeUaC2SQP6Kr6Im5HsCV0wLw==","closePayment":true,"language":"EN","currency":"USD","returnUrl":"https:\/\/www.print-pix.eu\/functions\/csob_return_payment\/"}

Here is my code : NSURL baseURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.platebnibrana.csob.cz/api/v1/payment/init"]]; NSData jsonData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil]; NSString *strJSON = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:baseURL
                                                       cachePolicy:NSURLRequestReloadIgnoringCacheData  timeoutInterval:10];

[request setHTTPMethod:@"POST"];
//[request setValue:@"Basic YXZhbXI6YXZhbTMzcg==" forHTTPHeaderField:@"Authorization"];
[request setValue: @"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody: [strJSON dataUsingEncoding:NSUTF8StringEncoding]];

NSLog(@"%@",strJSON);

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
operation.responseSerializer = [AFJSONResponseSerializer serializer];
[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
    [FunctionManager hideLoadingView:self.view appDelegate:appDelegate viewController:self];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    [FunctionManager hideLoadingView:self.view appDelegate:appDelegate viewController:self];
    [FunctionManager showMessage:@"" withMessage:[error localizedDescription] withDelegage:nil];

}];
ratajskym commented 9 years ago

Sorry, we don`t have example for ios

MarekPavlik commented 9 years ago

Hello Ratajskym, I am associate of TestWebplanex. Our apps are dependent to the CSOB payment gateway and we need to solve the issue asap please. Android apps communicate seamlessly, but iOS return errors. I already contacted CSOB support, they refered me to you. Hereafter are requests and responses of iOS app, could you please go through? Thanks

1st :

Post request in api :

{"OrderDetails":{"Items":"1cr-1003 $1,778","SSID":"","StreetAddress":"120 Scudder","CustomerID":"319098","City":"Copiague","InvoiceNumber":"13009","Status":"","PNREF":"","OrderDateTime":"2015-21-09","State":"NY","CustomerName":"Khang","geolocation":{"longitude":"0.000000","latitude":"0.000000"},"AuthNumber":"","Zip":"11726-","DeviceID":"AE0EA4A8-53D8-4504-86E9-8DAC585AD5A4","Amount":"1778"}}

Response :

Printing description of error: Error Domain=AFNetworkingErrorDomain Code=-1011 "Request failed: not found (404)" UserInfo=0x7f0a9530 {NSErrorFailingURLKey=https://slingshot.getdishout.com/SlingshotServices/SlingshotServices.svc/ProcessOrder/?, NSLocalizedDescription=Request failed: not found (404), NSUnderlyingError=0x7f0a8ad0 "Request failed: unacceptable content-type: text/html", AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x7f0a7e30> { URL: https://slingshot.getdishout.com/SlingshotServices/SlingshotServices.svc/ProcessOrder/? } { status code: 404, headers { "Content-Length" = 1763; "Content-Type" = "text/html; charset=UTF-8"; Date = "Mon, 21 Sep 2015 06:02:07 GMT"; Server = "Microsoft-IIS/7.5"; "X-Powered-By" = "ASP.NET"; } }}

2nd :

Requets:

{"OrderDetails":{"StreetAddress":"120 Scudder","CustomerName":"Khang","CustomerID":"319098","Zip":"11726-","InvoiceNumber":"13009","Amount":"1778","City":"Copiague","OrderDateTime":"2015-21-09","DeviceID":"AE0EA4A8-53D8-4504-86E9-8DAC585AD5A4","State":"NY","Items":"1cr-1003 $1,778"}}

Response:

Printing description of error: Error Domain=AFNetworkingErrorDomain Code=-1011 "Request failed: not found (404)" UserInfo=0x7b8a90a0 {NSErrorFailingURLKey=https://slingshot.getdishout.com/SlingshotServices/SlingshotServices.svc/ProcessOrder/?, NSLocalizedDescription=Request failed: not found (404), NSUnderlyingError=0x7e4987f0 "Request failed: unacceptable content-type: text/html", AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x7e498410> { URL: https://slingshot.getdishout.com/SlingshotServices/SlingshotServices.svc/ProcessOrder/? } { status code: 404, headers { "Content-Length" = 1763; "Content-Type" = "text/html; charset=UTF-8"; Date = "Mon, 21 Sep 2015 06:09:59 GMT"; Server = "Microsoft-IIS/7.5"; "X-Powered-By" = "ASP.NET"; } }}

ratajskym commented 9 years ago

@MarekPavlik your post request in api seems to be faraway from specification

MarekPavlik commented 9 years ago

I am sorry, I put here data from wrong file. Hereunder are the requests. Thank you

Post request in api :

{"description":"PrintPix APP order 560","totalAmount":822,"dttm":"20151001161951","merchantId":"A1050uj4XS","payMethod":"card","merchantData":"T3JkZXIgb2YgMSBwaG90b3M=","cart":[{"amount":822,"quantity":1,"description":"PrintPix - photos printing","name":"Order of photos"}],"payOperation":"payment","orderNo":"560","returnMethod":"POST","signature":"jqM4ipA4MIsFlQudIzun0hKDBfD6FIx8V80W4PhZJCY6WDZ+zzOauCHXxrQaUCWTZVXtE6u6YdQKpxT6vkjRt8kxjtFGLlPkL8SzslRhUISThIKBGvV5U+JIkwB7SDOiH3bXB3v3CPS9NUJ+CLioJiDreYPGRPaaFnqftShji0WZ1iXLOzY4ffKmDXAIEp35wpgk9ZcKmcAjd1SCw1\/\/xX3o3crBDtodxWzB6NvG7i4asctmv4q4a7mULBZZx8ttmsAs1gOtx\/jQ4JjBbD494PqyWXQskQx\/HxLaU05yvYAfLnIFrQey+x+FAVsVkM74nepbnPh9QzFb0E0v88gjyw==","closePayment":true,"language":"EN","currency":"USD","returnUrl":"https:\/\/www.print-pix.eu\/functions\/csob_return_payment\/"}

Response:

Printing description of error: Error Domain=AFNetworkingErrorDomain Code=-1011 "Request failed: bad request (400)" UserInfo=0x7fcbd4e71180 {AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0x7fcbd24d1d30> { URL: https://api.platebnibrana.csob.cz/api/v1/payment/init } { status code: 400, headers { "Cache-Control" = "no-cache, no-store, must-revalidate"; Connection = "keep-alive"; "Content-Length" = 0; Date = "Thu, 01 Oct 2015 10:54:15 GMT"; Expires = 0; Pragma = "no-cache"; Server = nginx; } }, NSLocalizedDescription=Request failed: bad request (400), NSErrorFailingURLKey=https://api.platebnibrana.csob.cz/api/v1/payment/init}

MarekPavlik commented 9 years ago

Hello, Mr. Ratajsky, could you please go through the code and if possible recognise where might be the problem?

Thanks so much

ratajskym commented 9 years ago

You are sending your requests to production environment but anonymous merchant is for test env.