1

此代码预计将使用 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")
    }

  }
4

1 回答 1

0

使用我的应用程序中的 swift 将 MassPay 的工作代码发布到 PayPal

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

  }
于 2016-02-27T17:02:45.757 回答