HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers95/rentman.io/app/Komma/Shop/Payment/Clients/MultiSafepay/Object/Core.php
<?php

namespace App\Komma\Shop\Payment\Clients\MultiSafepay\Object;

use App\Komma\Shop\Payment\Clients\MultiSafepay\Client;

class Core
{
    protected $mspapi;

    public $result;

    public function __construct(Client $mspapi)
    {
        $this->mspapi = $mspapi;
    }

    public function post($body, $endpoint = 'orders')
    {
        $this->result = $this->processRequest('POST', $endpoint, $body);

        return $this->result;
    }

    public function patch($body, $endpoint = '')
    {
        $this->result = $this->processRequest('PATCH', $endpoint, $body);

        return $this->result;
    }

    public function getResult()
    {
        return $this->result;
    }

    public function get($endpoint, $id, $body = [], $query_string = false)
    {
        if (! $query_string) {
            $url = "{$endpoint}/{$id}";
        } else {
            $url = "{$endpoint}?{$query_string}";
        }

        $this->result = $this->processRequest('GET', $url, $body);

        return $this->result;
    }

    protected function processRequest($http_method, $api_method, $http_body = null)
    {
        $body = $this->mspapi->processAPIRequest($http_method, $api_method, $http_body);
        if (! ($object = @json_decode($body))) {
            throw new \Exception("'{$body}'.");
        }

        if (! empty($object->error_code)) {
            $exception = new \Exception("{$object->error_code}: {$object->error_info}.");
            throw $exception;
        }

        return $object;
    }
}