jsonString = $jsonString; $this->marketPlace = $this->jsonString['marketPlace'] ?? null;; $this->secretKey = $this->jsonString['secretKey'] ?? null; $this->request_url = $this->jsonString['domain'] ?? null; $this->items_receipt = []; $this->items_receipt2 = []; $this->message = []; } public function addItemToReceipt(string $text, int $quantity, float $price, float $amount) { $this->items_receipt[] = [ "text" => $text, "quantity" => $quantity, "price" => $price, "amount" => $amount, "tax" => "vat110", "type" => "full_prepayment", "object" => "commodity", "unit" => "шт." ]; } public function processPayment() { $sum = 0; foreach ($this->items_receipt as $item) { $sum += $item['amount']; } $receipt_info = []; $this->message = [ "marketPlace"=> $this->jsonString['marketPlace'], "orderId"=> $this->jsonString['orderId'], "partialRefund"=> $this->jsonString['partialRefund'], "refundSum"=>$sum ]; $receipt_info["fdReceipt"] = ["taxSystem" => "", "items" => $this->items_receipt]; $receipt_info["data"] = $receipt_info; // $array1 = $jsonString; // $this->message = array_merge($this->message + $receipt_info); // $resultArray = array_merge($array1, $this->message); // print_r($resultArray); $messageTxt = json_encode($this->message); $signature = hash('sha256', $messageTxt.$this->secretKey); $ch = curl_init(); curl_setopt_array($ch, [ CURLOPT_URL => "https://" .$this->request_url. "/merchantApi/refundPayment", CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $messageTxt, CURLOPT_HTTPHEADER => [ "Signature: $signature", "Content-Type: application/json" ] ]); $res = curl_exec($ch); curl_close($ch); return $res; } } ?>