Wednesday, February 17, 2010

Sample Paypal Integration Code

- (void)sendPayPalRequestPOST{

NSString *parameterString = [NSString stringWithFormat:@"USER=usernamehere"

"&PWD=passwordhere"

"&SIGNATURE=signaturekeyhere"

"&METHOD=DoDirectPayment"

"&CREDITCARDTYPE=%@"

"&ACCT=%@"

"&EXPDATE=%@"

"&CVV2=256"

"&AMT=%@"

"&FIRSTNAME=%@"

"&LASTNAME=%@"

"&STREET=%@"

"&CITY=%@"

"&STATE=%@"

"&COUNTRY=%@"

"&ZIP=%@"

"&COUNTRYCODE=US"

"&PAYMENTACTION=Sale"

"&VERSION=2.3",

txtCreditCardType.text,txtAccountNumber.text,txtExpireDate.text,txtTotalAmount.text,txtFirstName.text,txtLastName.text,txtStreet.text,txtCity.text,txtState.text,txtCountry.text,txtZip.text];

NSURL *url = [NSURL URLWithString:@"https://api-3t.sandbox.paypal.com/nvp"];

NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];

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

[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];

[theRequest setHTTPMethod:@"POST"];

[theRequest setHTTPBody: [parameterString dataUsingEncoding:NSUTF8StringEncoding]];


NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];


if(theConnection){

webData = [[NSMutableData data] retain];

}else{

}

}


4 comments:

  1. how secure is this to send credentials over wifi?

    ReplyDelete
  2. Hi,

    I need paypal integration in iPhone for buying product. Can you help me?

    ReplyDelete