나을 통과하려고 일부는 인수에 컬 하지만 나는 내가 사용하는 경우 테스트 데이터의(간단한 문자열),나를 얻을 수 있는 결과(payId 및 payUrl)그러나 내가 사용하는 경우 변수 테스트 데이터,나는 아무것도 얻을 수 없다.
는 가장 좋은 방법은 무엇인 문제를 해결하의 이 유형은 문제가? 그것은 내용을 컬 그래서 내가 만드는 이 기능을 기반으로 기사에 나는 여기에 있습니다.
예를 들면,나는 대체"이름"$클라이언트 이름,나이 없에서 반환합니다.
function generatePayment($sendId, $clientCPF, $clientName, $clientEmail, $clientCep, $clientPhone, $amount){
// CONFIG
$urlCallBack = "http://192.168.0.79/sistema/admin/shipList.php?transactionStatus=success";
$urlError = "http://192.168.0.79/sistema/admin/shipList.php?transactionStatus=failed";
$debug = true;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'urlhere');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\n\t\"reference\": \"my-order-ref-0001\",\n\t\"client\": {\n \t\"cpf\": \"43164853858\",\n \t\"name\": \"John Doe\",\n \t\"email\": \"[email protected]\",\n \t\"birthdate\": \"1982-01-14\",\n \t\"cep\": \"18053190\",\n \t\"phone\": \"15987452584\"\n\t},\n\t\"items\": [\n \t{\n \t\"reference\": \"my-item-ref-0001\",\n \t\"description\": \"Apple iMac 21.5-inch\",\n \t\"quantity\": \"1\",\n \t\"amount\": 149900\n \t},\n \t{\n \t\"reference\": \"my-item-ref-0002\",\n \t\"description\": \"Apple iPhone 11 Pro\",\n \t\"quantity\": 1,\n \t\"amount\": 99900\n \t}\n\t],\n \"coupon\": {\n \"code\": \"10DESCONTO\",\n \"value\": 1000,\n \"issuer\": \"merchant_api\"\n },\n\t\"shipping\": {\n \"amount\": 1000\n\t},\n\t\"redirect\": {\n \t \"success\": \"https://example.com/sp_callback?success\",\n \t \"failed\": \"https://example.com/sp_callback?failed\"\n\t}\n}");
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: Bearer '.$_POST['token'];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
} else {
if ($debug){
echo "<BR><BR><BR> DATA PASSED TO FUNCTION <BR>";
echo "<br>sendId ===> ".$sendId;
echo "<br>clientCPF ===> ".$clientCPF;
echo "<br>clientName ===> ".$clientName;
echo "<br>clientEmail ===> ".$clientEmail;
echo "<br>clientCep ===> ".$clientCep;
echo "<br>clientPhone ===> ".$clientPhone;
echo "<br>amount ===> ".$amount;
$decode = json_decode($result,true);
echo "<BR><BR> DATA RECEIVED FROM API <BR>";
echo '<br> payId generated by API ==> '.$payId = $decode['data']['order_id'];
echo '<br> PayURL generated by API ==>'.$payUrl = $decode['data']['url_checkout'];
} else {
$decode = json_decode($result,true);
$transactionId = $decode['data']['order_id'];
$payUrl = $decode['data']['url_checkout'];
$_SESSION['transactionUrl'] = $decode['data']['url_checkout'];
$_SESSION['transactionId'] = $transactionId;
$_SESSION['sendId'] = $sendId;
}
}
curl_close($ch);
// END GENERATE PAYMENT
}
어떤 도움을 평가하는 방법에 대한 문제를 해결합니다.
업데이트 코드를 사용하여 JSON
//INITIALIZE
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://sandbox.splipay.com/api/orders');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
// POST
$post = array(
"items" => array (
"description" => "Test",
"quantity" => 1,
"amount" => 10
),
"redirect" => array (
"success" => "www.success",
"failed" => "www.success"
)
);
$post = json_encode($post);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
// HEADERS
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: Bearer '.$_POST['token'];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
//EXECUTE
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
} else {
$arr = json_decode($result);
echo "<br><br>Return from VAR_DUMP";
var_dump ($arr);
echo "<BR><BR>INFO RETURN<BR>";
$info = curl_getinfo($ch);
var_dump ($info);
// $_POST['token'] = $arr['access_token'];
}
curl_close($ch);
따라 문서,이러한 값만 내가 전달해야 API 그리고 나는 다음과 같은 응답(예):
{ "success":true, "data":{ "order_id":57, "url_checkout":"https://sandbox.splipay.com/payment/4openRe7Az/kzPdyP7bQr?expires=1583164527&signature=e1caae419137903f930f5a5b3d4c72608a61c0fdd36c70803d4a92c15556a4c5" } }