2016-11-13 6 views
0

私は現在Braintree Paymentを使用しています。私のiOSを使用してダッシュボードで支払いを成功させることができるImは、クライアント(iOS)に返信しようとしています。返品はすぐに ""、事前に助けてくれてありがとう。Braintree Paymentsからヘッダレスポンスを取得する方法

私の現在の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"に設定しているので、Webページを返さない場合は、 "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

"$ processed_result ="の例をjson serializeすることができますか? – pprevalon

関連する問題