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\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();