%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/html/klinisol/klinisol-api/app/Services/
Upload File :
Create Path :
Current File : /var/www/html/klinisol/klinisol-api/app/Services/ESign.php

<?php

namespace App\Services;


use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Http;

class ESign
{
    /**
     * @var string
     */
    private $baseUrl;
    /**
     * @var Http;
     */
    private $client;
    /**
     * @var string
     */
    private $accountId;

    public function __construct()
    {
        $username = env('DOCUSIGN_USERNAME');
        $password = env('DOCUSIGN_PASSWORD');
        $integration = env('DOCUSIGN_INTEGRATOR_KEY');

        $this->baseUrl = env('DOCUSIGN_BASE_URL');
        $this->accountId = env('DOCUSIGN_ACCOUNT_ID');
        $this->client = Http::withHeaders([
            'X-DocuSign-Authentication' => "{\"Username\":\"$username\", \"Password\": \"$password\" ,\"IntegratorKey\": \"$integration\"}",
        ]);
    }

    /**
     * @return mixed
     * @throws Exception
     */
    public function getTemplates()
    {
        $response = $this->client->get("$this->baseUrl/accounts/$this->accountId/templates");
        if ($response->successful()) {
            $response = json_decode($response->body());
            $result = [];
            if ($response->envelopeTemplates) {
                foreach ($response->envelopeTemplates as $template) {
                    array_push($result, [
                        "id"   => $template->templateId,
                        "name" => $template->name,
                    ]);
                }
            }

            return $response->envelopeTemplates;
        }
        throw new Exception('');
    }

    /**
     * @param $id
     * @return JsonResponse
     * @throws Exception
     */
    public function getTemplate($id)
    {
        $response = $this->client->get("$this->baseUrl/accounts/$this->accountId/templates/$id?include=documents");
        if ($response->successful()) {
            $res = json_decode($response->body());
            return $res->documents[0]->documentBase64;
        }
        throw new Exception('');
    }

    public function createEnvelopes($data)
    {
        $response = $this->client->post("$this->baseUrl/accounts/$this->accountId/envelopes", $data);
        if ($response->successful()) {
            return json_decode($response->body());
        }
        throw new Exception($response->body());
    }
}

Zerion Mini Shell 1.0