PayU integracja - curl

0

Cześć, mam taki kod

 curl_setopt($ch, CURLOPT_POSTFIELDS, "{
        \"notifyUrl\": \"https://your.eshop.com/notify\",
        \"customerIp\": \"127.0.0.1\",
        \"merchantPosId\": \"300746\",
        \"description\": \"$this->description\",
        \"currencyCode\": \"$this->currency\",
        \"totalAmount\": \"$totalAmount\",
        \"products\": [
    {
      \"name\": \"Wireless mouse\",
      \"unitPrice\": \"15000\",
      \"quantity\": \"1\"
    },
    {
      \"name\": \"HDMI cable\",
      \"unitPrice\": \"6000\",
      \"quantity\": \"1\"
    }
  ]

i tutaj są podstawowe dane które wymaga PayU, mam pytanie jak przerobić ten kod abym mógł całość przypisać do zmiennej i zrobić

 curl_setopt($ch, CURLOPT_POSTFIELDS, $data)

myślałem o czymś takim

$data = [
'customerIp' => '127.0.0.1',
]

json_encode($data)

jednak wtedy występuje błąd składni

2

Warto się nauczyć pracować z JSON-em:

$data = [
    'notifyUrl' => 'https://your.eshop.com/notify',
    'customerIp' => '127.0.0.1',
    'merchantPosId' => '300746',
    'description' => $this->description,
    'currencyCode' => $this->currency,
    'totalAmount' => $totalAmount,
    'products' => [
        [
            'name' => 'Wireless mouse',
            'unitPrice' => 15000,
            'quantity' => 1,
        ],
        [
            'name' => 'HDMI cable',
            'unitPrice' => 6000,
            'quantity' => 1,
        ],
    ]
];

$json = json_encode($data);

curl_setopt($ch, CURLOPT_POSTFIELDS, $json);

1 użytkowników online, w tym zalogowanych: 0, gości: 1