我目前使用Braintree Payment。我能够使用我的iOS在仪表板中创建一个成功的付款,问题是我试图返回回客户端(iOS)的响应,现在它是返回",提前感谢您的帮助。
我当前的php
<?php
require_once("../includes/braintree_init.php");
//$amount = $_POST["amount"];
//$nonce = $_POST["payment_method_nonce"];
$nonce = "fake-valid-nonce";
$amount = "10";
$result = BraintreeTransaction::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()
全面披露:我在Braintree工作。如果您还有任何问题,请联系技术支持。
请记住,PHP代码是在服务器上计算的,然后才能在响应中返回任何内容。在这种情况下,BraintreeTransaction::sale
调用计算正确,结果保存到$result
变量中。但是,没有其他任何事情发生,并且您不返回任何内容给请求者。
要返回响应,只需将其打印出来即可。请注意,PHP默认使用的内容类型头设置为"text/html",所以如果你不想返回一个网页,你可能会想把它改成"application/json",或者任何最适合你的东西。
$result = BraintreeTransaction::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;