1

this code is expected to do a Payout in PayPal using MassPay. It fails and I don't get a response from PayPal that tells me what is going on. Can somebody point me in the right direction?

    let postsEndpoint: String = "https://api-3t.sandbox.paypal.com/nvp"
    var postsUrlRequest = NSMutableURLRequest(URL: NSURL(string: postsEndpoint)!)

    postsUrlRequest.HTTPMethod = "POST"

    let paymentDict = ["USER" : "example.mydomain.com",
    "PWD" : "PQDBVQXJYH4***",
    "SIGNATURE" : "A9pEq0L3-2vjFoem1ajRi-b-0nWBAkujmPM.O5dJ9u-m7Vf***",
    "METHOD" : "MassPay",
    "VERSION" : "93",
    "RECEIVERTYPE" : "EmailAddress",
    "CURRENCYCODE" : "USD",
    "EMAILSUBJECT" : "First payment test form swift",
    "L_AMT0" : 1.25,
    "L_EMAIL0" : "exampla@gmail.com",
    "L_NOTE0" : "first test from swift",
    "L_UNIQUEID0" : "KS1946-3"]

    let newPost: NSDictionary = paymentDict


    do {
      let jsonPost = try NSJSONSerialization.dataWithJSONObject(newPost, options: [])
      postsUrlRequest.HTTPBody = jsonPost
      let config = NSURLSessionConfiguration.defaultSessionConfiguration()
      let session = NSURLSession(configuration: config)

      let createTask = session.dataTaskWithRequest(postsUrlRequest, completionHandler: {
        (data, response, error) in
        guard let responseData = data else {
          print("Error: did not receive data")
          return
        }
        guard error == nil else {



      })
      createTask.resume()
    } catch {
      print("Error: cannot create JSON from post")
    }

  }
lguerra10
  • 249
  • 3
  • 5
  • How does it fail? What response are you getting (even if you think it's meaningless)? – Drew Angell Feb 27 '16 at 03:24
  • response Optional( { URL: https://api-3t.sandbox.paypal.com/nvp } { status code: 200, headers { Connection = close; "Content-Length" = 146; "Content-Type" = "text/plain; charset=utf-8"; Date = "Sat, 27 Feb 2016 12:31:39 GMT"; "HTTP_X_PP_AZ_LOCATOR" = "sandbox.slc"; "Paypal-Debug-Id" = 9bbe9ff381c86; Server = Apache; "Set-Cookie" = "X-PP-SILOVER=name%3DSANDBOX3.API.1%26silo_version%3D1880%26app%3Dappdispatcher_apit%26TIME%3D731369814; domain=.paypal.com; path=/; Secure; HttpOnly, X-PP-SILOVER"; } }) – lguerra10 Feb 27 '16 at 12:33
  • data: Optional(<41434b3d 4661696c 75726526 4c5f4552 524f5243 4f444530 3d383130 3032264c 5f53484f 52544d45 53534147 45303d55 6e737065 63696669 65642532 304d6574 686f6426 4c5f4c4f 4e474d45 53534147 45303d4d 6574686f 64253230 53706563 69666965 64253230 69732532 306e6f74 25323053 7570706f 72746564 264c5f53 45564552 49545943 4f444530 3d457272 6f72>) – lguerra10 Feb 27 '16 at 12:34

1 Answers1

0

working code for MassPay post to PayPal with swift from my App

func payPalMassPayOutMessage() {

    let postsEndpoint: String = "https://api-3t.sandbox.paypal.com/nvp"
    let postsUrlRequest = NSMutableURLRequest(URL: NSURL(string: postsEndpoint)!)
    postsUrlRequest.HTTPMethod = "POST"

    let paymentString = "USER=alex***.mydomain&PWD=PQDBVQXJYH4****&SIGNATURE=A9pEq0L3-2vjFoem1ajRi-b-0nWBAkujmPM.O5dJ9u-m7VfmkDJg****&METHOD=MassPay&VERSION=93&RECEIVERTYPE=EmailAddress&CURRENCYCODE=USD&EMAILSUBJECT=First payment test form swift&L_AMT0=1.25&L_EMAIL0=lguerra10@gmail.com"

        do {

          postsUrlRequest.HTTPBody = paymentString.dataUsingEncoding(NSUTF8StringEncoding)

      let config = NSURLSessionConfiguration.defaultSessionConfiguration()
      let session = NSURLSession(configuration: config)

      let createTask = session.dataTaskWithRequest(postsUrlRequest, completionHandler: {
        (data, response, error) in
        guard let responseData = data else {
          print("Error: did not receive data")
          return
        }
        guard error == nil else {
          print("error calling post ")
          print(error)
          return
        }



        guard let dataSring = NSString(data: data!, encoding: NSUTF8StringEncoding) else {
          print("error parse dataString ")
          return
        }
        print("response data \(dataSring)")

    })
      createTask.resume()
    } catch {
      print("Error: cannot encode paymentString")
    }

  }
lguerra10
  • 249
  • 3
  • 5