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