Swift PayPal MassPay邮局调用失败。任何人都可以指出我正确的方向

时间:2016-02-27 02:24:56

标签: json swift paypal masspay

此代码预计会使用MassPay在PayPal中执行付款。它失败了,我没有得到PayPal的回复,告诉我发生了什么。有人能指出我正确的方向吗?

    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")
    }

  }

1 个答案:

答案 0 :(得分:0)

使用swift从我的应用程序发送到PayPal的MassPay工作代码

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")
    }

  }