Duffer Derek

Current Path : /var/www/invoice-sync.bitkit.dk/httpdocs/app/Http/Service/Economic/
Upload File :
Current File : /var/www/invoice-sync.bitkit.dk/httpdocs/app/Http/Service/Economic/EconomicCreditNoteSync.php

<?php

namespace App\Http\Service\Economic;

use App\Exceptions\DownloadFailedException;
use App\Exceptions\PodioAttributeNotFoundException;
use App\Exceptions\PodioItemCreationFailedException;
use App\Exceptions\PodioItemUpdateFailedException;
use App\Http\Interfaces\Invoice\EconomicCreditNoteSyncInterface;
use App\Http\Modules\ApiWrapper\PodioApi;
use App\Http\Modules\DataFormatter\ToPodio\CreditNote as ToPodioCreditNote;
use Illuminate\Support\Facades\Log;

class EconomicCreditNoteSync implements EconomicCreditNoteSyncInterface
{
    /**
     *
     * @var PodioApi
     */
    protected $podioApi;

    public function __construct()
    {
        $this->podioApi = new PodioApi();
    }

    /**
     * @param $creditNote
     * @param $invoiceItemId
     * @return array
     * @throws DownloadFailedException
     * @throws PodioAttributeNotFoundException
     * @throws PodioItemCreationFailedException
     */
    public function podioCreateAttribute($creditNote,$invoiceItemId): array
    {
        $toPodio = new ToPodioCreditNote($creditNote);
        return $toPodio->getData($invoiceItemId);
    }

    /**
     * @param $creditNote
     * @param $invoiceItemId
     * @return mixed
     * @throws DownloadFailedException
     * @throws PodioAttributeNotFoundException
     * @throws PodioItemCreationFailedException
     */
    public function processCreditNoteSync($creditNote,$invoiceItemId)
    {
        if (!empty($creditNote)) {
            $attributes = $this->podioCreateAttribute($creditNote,$invoiceItemId);
        }
        $options = ['silent' => true, 'hook' => false];
        if (empty($attributes)) {
            throw new PodioAttributeNotFoundException('No attributes Provided');
        }
        $response = $this->podioApi->podioItemCreate(config('podio.app_auth.invoice.app_id'), $attributes, $options);
        if ($response == null) {
            throw new PodioItemCreationFailedException('Failed to create invoice item in podio');
        }
        return $response;
    }
}

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists