-3

I am using curl for get data from third party,I am sending parameters in json ,Now i want to send dynamic value instead of static,So i want to cocatenate php variable in json but its not working,How can i do this ? I tried to send paramete with "json_encode" but not worked for me, here is my code

CURLOPT_POSTFIELDS => "{\"amount\":1,\"currency\":\"KWD\",\"threeDSecure\":true,\"save_card\":false,\"description\":\"Test Description\",\"statement_descriptor\":\"Sample\",\"metadata\":{\"udf1\":\"test 1\",\"udf2\":\"test 2\"},\"reference\":{\"transaction\":\"txn_0001\",\"order\":\"ord_0001\"},\"receipt\":{\"email\":true,\"sms\":true},\"customer\":{\"first_name\":\"test\",\"middle_name\":\"test\",\"last_name\":\"test\",\"email\":\"abc@xyz.com\",\"phone\":{\"country_code\":\"965\",\"number\":\"50000000\"}},\"source\":{\"id\":\"src_all\"},\"post\":{\"url\":\"http:xxxxxxxxxxx/payment_gateway/data.php\"},\"redirect\":{\"url\":\"http://xxxxxxxx/success.php\"}}",
amit
  • 1
  • 1
  • 18
  • 28
  • That is not code. It's a string, or at the best an half array statement with a string. – Andreas Apr 27 '19 at 05:04
  • Possible duplicate of [Serializing PHP object to JSON](https://stackoverflow.com/questions/6836592/serializing-php-object-to-json) – Keivan Esbati Apr 27 '19 at 05:34

1 Answers1

0

send array and set content type JSON in your curl request. Also please edit the question and show full curl code.

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
Ravi
  • 163
  • 2
  • 11