Shiv Pogra
Shiv Pogra

Reputation: 93

Objective-C macOS how to use PayPal getBalance NVP API?

I want to get PayPal account balance in my macOS app but still I have not found any solution.

getBalance NVP/SOAP Method

Below is my code:

NSString *targetUrl = @"https://api-3t.paypal.com/nvp";
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
//Make an NSDictionary that would be converted to an NSData object sent over as JSON with the request body
[request setHTTPMethod:@"POST"];
[request setURL:[NSURL URLWithString:targetUrl]];
NSString *postLength = [NSString stringWithFormat:@"application/x-www-form-urlencoded"];
[request setValue:postLength forHTTPHeaderField:@"Content-Type"];
NSString *postString = @"USER=*******************&PWD=**************&SIGNATURE= **********************&VERSION=101&METHOD=GetBalance&RETURNALLCURRENCIES=1";
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"request:%@",request.HTTPBody);
[[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:
  ^(NSData * _Nullable data,
    NSURLResponse * _Nullable response,
    NSError * _Nullable error) {
       NSLog(@"getPaypalBalance:response:%@",[data class]);
      NSString* newStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
      NSLog(@"newStr:%@",newStr);

      if (error) {
          NSLog(@"getPaypalBalance:error:%@",error);
          completionBlock(nil,error);
      }else{
      }
  }] resume];

Upvotes: 0

Views: 59

Answers (0)

Related Questions