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/ZelfVerkopen/zelfverkopen.nl/app/KommaApp/Icepay/Api/DataModel.php
<?php


namespace App\KommaApp\Icepay\Api;

use Illuminate\Contracts\Support\Arrayable;

/**
 * Class DataModel
 *
 * Success or error data
 *
 * @package App\KommaApp\Icepay\Api
 */
class DataModel implements Arrayable
{
    /** @var string $status Contains the status of the payment. You can expect one of the following string values as defined in the Payment Status class*/
    private $status;

    /** @var string $statusCode A description of the status. */
    private $statusCode;

    /** @var string $merchant This is the merchant ID that is part of your API Key.*/
    private $merchant;

    /** @var string $orderId This is the order ID generated by ICEPAY. You can safely ignore this*/
    private $orderId;

    /** @var string This is the ICEPAY transaction ID. Please mention this value when you ever contact ICEPAY support regarding a payment */
    private $paymentId;

    /** @var string $reference This is the reference of the payment that you may have set using the SetReference on the icepay class. */
    private $reference;

    /** @var string $transactionID This is the transaction ID generated by the issuer. */
    private $transactionID;

    /** @var int $paymentFailsCount */
    private $paymentFailsCount;

    public function __construct(array $data)
    {
        $this->status = (isset($data['status'])) ? $data['status'] : '';
        $this->statusCode = (isset($data['statusCode'])) ? $data['statusCode'] : '';
        $this->merchant = (isset($data['merchant'])) ? $data['merchant'] : '';
        $this->orderId = (isset($data['orderID'])) ? $this->payByMailOrderIdToZelfverkopenOrderId($data['orderID']) : '';
        $this->paymentId = (isset($data['paymentID'])) ? $data['paymentID'] : '';
        $this->reference = (isset($data['reference'])) ? $data['reference'] : '';
        $this->transactionID = (isset($data['transactionID'])) ? $data['transactionID'] : '';

        \Log::debug('Data\'s order id = '.$data['orderID']);
        \Log::debug('Fails count: '.$this->getPaymentFailsFromPayByMailOrderId($data['orderID']));
        $this->paymentFailsCount = $this->getPaymentFailsFromPayByMailOrderId($data['orderID']);
    }

    /**
     * @return string
     */
    public function getStatus(): string
    {
        return strtoupper($this->status);
    }

    /**
     * @param string $status
     * @return DataModel
     */
    public function setStatus(string $status): DataModel
    {
        $this->status = $status;
        return $this;
    }

    /**
     * @return string
     */
    public function getStatusCode(): string
    {
        return $this->statusCode;
    }

    /**
     * @param string $statusCode
     * @return DataModel
     */
    public function setStatusCode(string $statusCode): DataModel
    {
        $this->statusCode = $statusCode;
        return $this;
    }

    /**
     * @return string
     */
    public function getMerchant(): string
    {
        return $this->merchant;
    }

    /**
     * @param string $merchant
     * @return DataModel
     */
    public function setMerchant(string $merchant): DataModel
    {
        $this->merchant = $merchant;
        return $this;
    }

    /**
     * @return string
     */
    public function getOrderId(): string
    {
        return $this->orderId;
    }

    /**
     * @param string $orderId
     * @return DataModel
     */
    public function setOrderId(string $orderId): DataModel
    {
        $this->orderId = $orderId;
        return $this;
    }

    /**
     * @return string
     */
    public function getPaymentId(): string
    {
        return $this->paymentId;
    }

    /**
     * @param string $paymentId
     * @return DataModel
     */
    public function setPaymentId(string $paymentId): DataModel
    {
        $this->paymentId = $paymentId;
        return $this;
    }

    /**
     * @return string
     */
    public function getReference(): string
    {
        return $this->reference;
    }

    /**
     * @param string $reference
     * @return DataModel
     */
    public function setReference(string $reference): DataModel
    {
        $this->reference = $reference;
        return $this;
    }

    /**
     * @return string
     */
    public function getTransactionID(): string
    {
        return $this->transactionID;
    }

    /**
     * @param string $transactionID
     * @return DataModel
     */
    public function setTransactionID(string $transactionID): DataModel
    {
        $this->transactionID = $transactionID;
        return $this;
    }

    /**
     * @return int
     */
    public function getPaymentFailsCount(): int
    {
        return $this->paymentFailsCount;
    }

    /**
     * @param int $paymentFailsCount
     * @return DataModel
     */
    public function setPaymentFailsCount(int $paymentFailsCount): DataModel
    {
        $this->paymentFailsCount = $paymentFailsCount;
        return $this;
    }

    /**
     * Get the instance as an array.
     *
     * @return array
     */
    public function toArray()
    {
        return [
            'status' => $this->status,
            'statusCode' => $this->statusCode,
            'merchant' => $this->merchant,
            'orderId' => $this->orderId,
            'paymentId' => $this->paymentId,
            'reference' => $this->reference,
            'transactionID  ' => $this->transactionID,
        ];
    }

    private function getPaymentFailsFromPayByMailOrderId(string $payByMailOrderId)
    {
        if(substr($payByMailOrderId, 0, 5) === 'ZELF-') $payByMailOrderId = substr($payByMailOrderId, 5);

        if(strpos($payByMailOrderId, '-') === false) {
            return 0;
        } else {
            $parts = explode('-', $payByMailOrderId);
            return intval(end($parts));
        }
    }

    private function payByMailOrderIdToZelfverkopenOrderId(string $payByMailOrderId) {
        if(substr($payByMailOrderId, -1) == "-") $payByMailOrderId = substr($payByMailOrderId, 0, -1); //Dirty bugfix for a bug in the Icepay system. Removes dash at the end

        if(substr($payByMailOrderId, 0, 5) === 'ZELF-') return $payByMailOrderId;

        if(strpos($payByMailOrderId, '-') === false)
        {
            return 'ZELF-'.$payByMailOrderId;
        } else {
            $parts = explode('-', $payByMailOrderId);
            $orderId = array_shift($parts);
            return 'ZELF-'.$orderId;
        }
    }
}