resultCode; } /** * XML без атрибутов — для мерчанта без кассового сервиса. */ public function toXml(): CallbackResponse { return CallbackResponse::xml( MntResponseXml::build( accountId: $this->accountId, transactionId: $this->transactionId, resultCode: $this->resultCode, amount: $this->amount, signature: $this->sign(), cms: $this->cms, ), ); } /** * JSON с чеком — для мерчанта с подключённой кассой. */ public function toJson(Receipt $receipt): CallbackResponse { if (!$receipt->matchesAmount($this->amount)) { throw new InvalidArgumentException('Сумма позиций чека не совпадает с суммой заказа.'); } return CallbackResponse::json(JsonNumber::encode([ 'id' => $this->accountId, 'transactionId' => $this->transactionId, 'amount' => JsonNumber::placeholder($this->amount), 'signature' => $this->sign(), 'resultCode' => (string) $this->resultCode->value, 'description' => $this->resultCode->description(), 'cms' => $this->cms, 'receipt' => $receipt->toCheckReceipt(), ])); } private function sign(): string { return $this->signature->forResponse($this->resultCode, $this->accountId, $this->transactionId); } }