PayU integracja - curl

PayU integracja - curl
M2
  • Rejestracja:ponad 7 lat
  • Ostatnio:około rok
  • Postów:362
0

Cześć, mam taki kod

Kopiuj
 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ć

Kopiuj
 curl_setopt($ch, CURLOPT_POSTFIELDS, $data)

myślałem o czymś takim

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

json_encode($data)

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

bearek
  • Rejestracja:prawie 5 lat
  • Ostatnio:ponad rok
  • Postów:85
2

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

Kopiuj
$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);

Zarejestruj się i dołącz do największej społeczności programistów w Polsce.

Otrzymaj wsparcie, dziel się wiedzą i rozwijaj swoje umiejętności z najlepszymi.