2016-11-13 67 views
0

我目前使用Braintree付款。我能够使用我的iOS在仪表板中创建成功的付款问题是我正在尝试返回客户端(iOS)的回复,现在它返回“”,感谢您提前给予帮助。如何从Braintree付款获得标题回复php

我当前的PHP

<?php 
require_once("../includes/braintree_init.php"); 

//$amount = $_POST["amount"]; 
//$nonce = $_POST["payment_method_nonce"]; 
$nonce = "fake-valid-nonce"; 
$amount = "10"; 

$result = Braintree\Transaction::sale([ 
    'amount' => $amount, 
    'paymentMethodNonce' => $nonce 
]); 

我的客户

URLSession.shared.dataTask(with: request as URLRequest) { (data, response, error) -> Void in 
      // TODO: Handle success or failure 
      let responseData = String(data: data!, encoding: String.Encoding.utf8) 
      // Log the response in console 
      print(responseData); 

      // Display the result in an alert view 
      DispatchQueue.main.async(execute: { 
       let alertResponse = UIAlertController(title: "Result", message: "\(responseData)", preferredStyle: UIAlertControllerStyle.alert) 

       // add an action to the alert (button) 
       alertResponse.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)) 

       // show the alert 
       self.present(alertResponse, animated: true, completion: nil) 

      }) 

      } .resume() 

回答

1

全面披露:我在布伦特里工作。如果您有任何其他问题,请随时联系support

请记住,PHP代码在响应中返回任何内容之前会在您的服务器上进行评估。在这种情况下,Braintree\Transaction::sale呼叫评估正确,并将结果保存到您的$result变量中。然而,没有其他的事情发生,你没有回报你的请求者。

要返回响应,您可以简单地打印出来。请注意,PHP默认使用Content-Type头设置为“text/html”,所以如果你不想返回一个网页,你可能会想把它改成“application/json”之类的东西,或者其他什么是最适合你的。

$result = Braintree\Transaction::sale([ 
    'amount' => $amount, 
    'paymentMethodNonce' => $nonce 
]); 

$processed_result = // you could serialize the result here, into JSON, for example 
header('Content-Type: application/json'); 
print $processed_result; 
+0

你能给我一个json序列化的例子为“$ processed_result =” – pprevalon