PHP code example of pactivasign / pactivasign-laravel

1. Go to this page and download the library: Download pactivasign/pactivasign-laravel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pactivasign / pactivasign-laravel example snippets


use PactivaSign\Laravel\Facades\PactivaSign;

$document = PactivaSign::documents()->upload('NDA', fopen(storage_path('nda.pdf'), 'rb'), 'nda.pdf');

$envelope = PactivaSign::envelopes()->create([
    'name' => 'NDA with Acme',
    'documentIds' => [$document->id],
    'signers' => [['email' => $customer->email, 'name' => $customer->name]],
    'externalId' => "order-{$order->id}",
], idempotencyKey: "order-{$order->id}-nda");

   Route::pactivaSignWebhooks();                      // POST /pactivasign/webhook
   

   $subscription = PactivaSign::webhookSubscriptions()->create([
       'url' => route('pactivasign.webhook'),
       'eventTypes' => ['envelope.completed', 'envelope.declined', 'recipient.signed'],
   ]);
   // PACTIVASIGN_WEBHOOK_SECRET = $subscription->secret
   

   use PactivaSign\Laravel\Events\EnvelopeCompleted;
   use PactivaSign\Laravel\Facades\PactivaSign;

   Event::listen(function (EnvelopeCompleted $completed) {
       if ($completed->isStale()) {
           return;                                    // a newer event for this envelope was already received
       }
       PactivaSign::envelopes()
           ->downloadSigned($completed->envelopeId())
           ->saveTo(storage_path("contracts/{$completed->envelopeId()}.pdf"));
   });
   

use PactivaSign\Laravel\Facades\PactivaSign;
use PactivaSign\Laravel\Testing\PactivaSignFake;
use PactivaSign\Laravel\Testing\RecordedRequest;

$fake = PactivaSign::fake([
    'POST /api/v1/envelopes' => $envelopeJson,          // returned as the response's data
    'GET /api/v1/envelopes/*' => fn (RecordedRequest $request) => [...],
]);

// ... run the code under test ...

$fake->assertSent(fn (RecordedRequest $r) => $r->is('POST /api/v1/envelopes') && $r->json()['name'] === 'NDA');
$fake->assertNotSent('DELETE *');

// Post a signed webhook to your route:
[$body, $server] = PactivaSignFake::webhook(['type' => 'envelope.completed', 'data' => ['envelopeId' => $id]]);
$this->call('POST', '/pactivasign/webhook', server: $server, content: $body)->assertOk();
bash
composer vendor:publish --tag=pactivasign-config        # optional: config/pactivasign.php
bash
php artisan pactivasign:keys
bash
php artisan pactivasign:test
bash
   php artisan vendor:publish --tag=pactivasign-migrations
   php artisan migrate