2016-11-13 4 views
0

현재 Braintree Payment를 사용 중입니다. 임 iOS를 사용하여 대시 보드에서 결제를 성공적으로 수행 할 수있게 된 것은 클라이언트 (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는 기본적으로 "text/html"로 설정된 Content-Type 헤더를 사용하므로 웹 페이지를 반환하지 않으려면 "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