1

i done search tutorial for send post json with curl .. but for this value i cant find in here.. and my question how to convert to array post json in value if like this, and this my value post json

   {
      "payment_type": "bca_klikpay",
      "transaction_details": {
        "order_id": "orderid-01",
        "gross_amount": 11000
      },
      "item_details": [
        {
          "id": "1",
          "price": 11000,
          "quantity": 1,
          "name": "Mobil "
        }
      ],
      "customer_details":{
        "first_name": "John",
        "last_name": "Baker",
        "email": "john.baker@email.com",
        "phone": "08123456789"
      },
      "bca_klikpay": {
        "description": "Pembelian Barang"
      }
    }

i done try to php array like this but still error

$item = array('id' => 'id1', 'price' => 11000, 'quantity' => 1 , 'name' => 'Mobil');

$data2 =array('payment_type' => 'bca_klikpay', 
'transaction_details' => array('order_id' => 'orderid-01', 'gross_amount' => 11000),
'item_details' => array([$item]),
'customer_details'=> array('first_name' => 'john',
'last_name' => 'baker', 'email' => 'john.baker@email.com', 'phone' => 08123456789),
'bca_klikpay' => array('description' => 'Pembelian Barang'));

maybe someone can help me.. and sory for my bad english

thanks

yagami cell
  • 147
  • 12

1 Answers1

0

There is the following error - the phone number has to be string, not number, so it would look like this 'phone' => '08123456789', because numbers cannot begin with 0.

Beside this, there is the following issue - You should not set item_details like this, but rather 'item_details' => [$item]. You do not need 2 nested arrays, just one. (array() is equal to []. They are practically the same in your use case. So you are doing something like array(array($item)), which is wrong)

What else, you have to do a $json = json_encode($data2); at the end and it will return what you want it to.

Martin Dimitrov
  • 1,304
  • 1
  • 11
  • 25
  • thanks for reply.. i done use $json = json_encode($data2); , but i have problem in value post json "item_details": [ { "id": "1", "price": 11000, "quantity": 1, "name": "Mobil " } ], .. in there before array and after array get the symbol [ and ] so.. how to convert in array if in value get symbol [ ] – yagami cell Feb 01 '21 at 12:19
  • @yagamicell can you edit your question and put in an expected output of item_details. How do you want it to look? – Martin Dimitrov Feb 01 '21 at 12:24