2016-02-27 54 views
1

此代码有望使用MassPay在PayPal中进行支付。它失败了,我没有收到贝宝的回应,告诉我发生了什么。有人能指出我正确的方向吗?斯威夫特PayPal MassPay邮寄呼叫失败。任何人都可以指向正确的方向

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" : "[email protected]", 
    "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") 
    } 

    } 
+0

它是如何失败?你会得到什么样的反应(即使你认为它没有意义)? –

+0

response可选( {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

+0

data:可选(<41434b3d 4661696c 75726526 4c5f4552 524f5243 4f444530 3d383130 3032264c 5f53484f 52544d4 5 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

回答

0

从我的应用程序工作MassPay侦错码至贝宝与SWIFT

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&[email protected]" 

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

    }