tags:

views:

69

answers:

1
-(IBAction)btnsendPressed:(id)sender {

NSString *soapMessage =  [NSString stringWithFormat:
@"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" 
"<SOAP-ENV:Envelope xmlns:xsi= \"http://www.w3.org/2001/XMLSchema-instance\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"&gt;\n"
"<SOAP-ENV:Header>\n" 
"<RequesterCredentials xmlns=\"urn:ebay:api:PayPalAPI\">\n" 
"<Credentials xmlns=\"urn:ebay:apis:eBLBaseComponents\">\n" 
"<Username>usename</Username>\n" 
"<Password>password</Password>\n" 
"<Signature/>\n"     
"<Subject/>\n" 
"</Credentials>\n" 
"</RequesterCredentials>\n" 
"</SOAP-ENV:Header>\n" 
"<SOAP-ENV:Body>\n" 
"<specific_api_name_Req xmlns=\"urn:ebay:api:PayPalAPI\">\n" 
"<specific_api_name_Request>\n" 
"<Version xmlns=urn:ebay:apis:eBLBaseComponents”>service_version</Version>\n" 
"<required_or_optional_fields xsi:type=”some_type_here”>\n"                 
"</required_or_optional_fields>\n" 
"</specific_api_name_Request>\n" 
"</specific_api_name_Req>\n" 
"</SOAP-ENV:Body>\n" 
                          "</SOAP-ENV:Envelope>\n"];


NSLog(@"Soap message===%@",soapMessage);


NSString *userName=@"username",*password=@"password",*signature=@"An5ns1Kso7MWUdW4ErQKJJJ4qi4-AvSLyYM19iIOP72wn9xVsLJ6OHVv",*returnCallURL=@"https://api-3t.sandbox.paypal.com/nvp";
float donationAmount = 0.50;

NSString *parameterString = [NSString stringWithFormat:@"https://api-3t.sandbox.paypal.com/nvp?USER=%@&amp;PWD=%@&amp;SIGNATURE=%@&amp;VERSION=57.0&amp;METHOD=SetMobileCheckout&amp;AMT=%.2f&amp;CURRENCYCODE=USD&amp;DESC=%@", userName, password, signature, donationAmount, @"Some Charge"];

NSLog(parameterString);

parameterString=[parameterString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"After encoding %@",parameterString);


NSURL *url = [NSURL URLWithString:parameterString];  

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];

NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL: url ];

NSHTTPURLResponse *response = nil;

NSError *error = [[NSError alloc] init];
NSData *responseData = [NSURLConnection sendSynchronousRequest: theRequest
                                             returningResponse:&response
                                                        error : &error];


NSLog(@"Response code= %d", [response statusCode] );
NSLog(@"Content-type : @", [[response allHeaderFields] objectForKey: @"Content-type"]);

if([response statusCode] >=200 && [response statusCode ] <300)
    NSLog( @"connection established  1");

NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMessage length]];

[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue: @"https://api-3t.sandbox.paypal.com/nvp" forHTTPHeaderField:@"SOAPAction"];

[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];

if( theConnection )
{
    webData = [[NSMutableData data] retain];
    // NSLog( @"connection established");
    //NSLog( webData);
}
else
{
    NSLog(@"theConnection is NULL");
}



}
+1  A: 

@Ankit

Try to follow this link . I believe it would help you.

It's very simple to understand. The link has very simple flow & easy variable names

http://helpmesolve.blogspot.com/

sugar