deegitalbe / laravel-trustup-io-sign
签名URL构建器。
v2.1.0
2024-03-14 14:30 UTC
Requires
Requires (Dev)
- orchestra/testbench: ^7.0
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-09-14 15:32:53 UTC
README
先决条件
此包使用 deegitalbe/server-authorization
包来验证请求。请参考其文档,确保其在项目中正确配置。
安装
composer require deegitalbe/laravel-trustup-io-sign
发布配置
php artisan vendor:publish --provider="Deegitalbe\TrustupIoSign\Providers\TrustupIoSignServiceProvider" --tag="config"
🛠️ config.
提供所有需要关联关系的模型。
"models" => [ YourModel::class, ]
用法
/** getTrustupIoSignUrl(?string $callback = null, ?string $webhook = null): string */ $yourmodel->getTrustupIoSignUrl();
🛠️ 默认安装 BelongsTo 关联。
所有必要的方法都已定义。默认模型类型标识符设置为 uuid。
<?php namespace App\Models; use Deegitalbe\TrustupIoSign\Contracts\Models\BelongsToTrustupIoSignedDocumentRelatedModelContract; use Deegitalbe\TrustupIoSign\Models\DefaultTrustupIoSignedDocumentRelatedModel; class Ticket implements BelongsToTrustupIoSignedDocumentRelatedModelContract { use BelongsToTrustupIoSignedDocumentRelatedModel; public function getTrustupIoSignOriginalPdfUrl(): string { return 'https://eforms.com/download/2019/08/Service-Contract-Template.pdf'; } public function getTrustupIoSignCallbackUrl(): string { return 'https://www.google.com'; } }
🛠️ 默认安装 HasMany 关联。
所有必要的方法都已定义。默认模型类型标识符设置为 uuid。
<?php namespace App\Models; use Deegitalbe\TrustupIoSign\Contracts\Models\HasManyTrustupIoSignedDocumentRelatedModelContract; use Deegitalbe\TrustupIoSign\Models\HasManyTrustupIoSignedDocumentRelatedModel; class Ticket implements HasManyTrustupIoSignedDocumentRelatedModelContract { use HasManyTrustupIoSignedDocumentRelatedModel; protected $casts = [ "trustup_io_signed_document_uuids" => 'collection' ]; public function getTrustupIoSignOriginalPdfUrl(): string { return 'https://eforms.com/download/2019/08/Service-Contract-Template.pdf'; } public function getTrustupIoSignCallbackUrl(): string { return 'https://www.google.com'; } }
🛠️ 常用特性。
both belongsTo 和 HasMany 特性实现了 IsTrustupIoSignedDocumentRelatedModel。您可以根据自己的需求自由覆盖它。
<?php namespace Deegitalbe\TrustupIoSign\Models; use Illuminate\Support\Str; use Deegitalbe\TrustupIoSign\Services\SignUrlService; use Deegitalbe\TrustupIoSign\Facades\TrustupIoSignFacade; trait IsTrustupIoSignedDocumentRelatedModel { protected string $trustupIoSignCallback; protected string $trustupIoSignWebhook; /** * Getting model identifier */ public function getTrustupIoSignModelId(): string { /** @var Model $this */ return $this->uuid ?? $this->id; } /** * Getting model type for media.trustup.io */ public function getTrustupIoSignModelType(): string { /** @var Model $this */ return Str::slug(str_replace('\\', '-', $this->getMorphClass())); } public function getTrustupIoSignAppKey(): string { return TrustupIoSignFacade::getConfig("app_key"); } public function getTrustupIoSignWebHookUrl(): string { // use this adress for locale container 'trustup-io-ticketing/webhooks/trustup-io-sign/signed-document/stored'. return route("webhooks.trustup-io-sign.signed-document.stored"); } public function getTrustupIoSignUrl(?string $callback = null, ?string $webhook = null): string { /** @var SignUrlService */ $signUrlService = app()->make(SignUrlService::class); if ($callback) $this->setTrustupIoSignCallback($callback); if ($webhook) $this->setTrustupIoSignWebhook($webhook); return $signUrlService->generateUrl($this); } protected function setTrustupIoSignCallback(string $callback): self { $this->trustupIoSignCallback = $callback; return $this; } protected function setTrustupIoSignWebhook($webhook): self { $this->trustupIoSignWebhook = $webhook; return $this; } }
⚡⚡ 迁移 BelongsTo 特性。
默认列设置为 trustup_io_signed_document_uuid,类型为 string
,但您可以自由覆盖它。
<?php namespace Deegitalbe\TrustupIoSign\Services\Traits; use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; trait BelongsToTrustupioSignedDocumentRelatedMigrations { public function addSignedDocumentColumn(string $model, string $column = 'trustup_io_signed_document_uuid'): void { Schema::table($model, function (Blueprint $table) use ($column) { $table->string($column)->nullable(); }); } public function removeSignedDocumentColumn(string $table, string $column = 'trustup_io_signed_document_uuid'): void { Schema::table($table, function (Blueprint $table) use ($column) { $table->dropColumn($column); }); } }
⚡⚡ 迁移 HasMany 特性。
默认列设置为 trustup_io_signed_document_uuids,类型为 json
,但您可以自由覆盖它。注意:记得在模型中将它转换为集合!!!
<?php namespace Deegitalbe\TrustupIoSign\Services\Traits; use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; trait HasManyTrustupioSignedDocumentRelatedMigrations { public function addSignedDocumentColumn(string $model, string $column = 'trustup_io_signed_document_uuids'): void { Schema::table($model, function (Blueprint $table) use ($column) { $table->json($column)->nullable(); }); } public function removeSignedDocumentColumn(string $table, string $column = 'trustup_io_signed_document_uuids'): void { Schema::table($table, function (Blueprint $table) use ($column) { $table->dropColumn($column); }); } }
Webhook 数据结构
{ "id": 43, "uuid": "6dcc41ca-b3b3-4027-9a52-190c249f0606", "ip": "192.168.240.8", "timezone": null, "latitude": null, "longitude": null, "modelId": "44b1f149-5dd8-494c-a7ec-52edeb666c18", "modelType": "ticket", "appKey": "trustup-io-ticketing", "documentUuid": "e0f26d6a-206f-4ed1-b244-e41e7a4f33f1", "signedAt": "2023-03-16T16:35:17.000000Z", "document": { "app_key": "trustup-io-sign", "collection": "files", "conversions": [], "custom_properties": { "width": null, "height": null }, "id": 349, "model_id": "6dcc41ca-b3b3-4027-9a52-190c249f0606", "model_type": "signeddocument", "uuid": "e0f26d6a-206f-4ed1-b244-e41e7a4f33f1", "url": "https://media.trustup.io.test/storage/e0f26d6a-206f-4ed1-b244-e41e7a4f33f1/lGlUXJYi.pdf", "optimized": { "url": "https://media.trustup.io.test/storage/e0f26d6a-206f-4ed1-b244-e41e7a4f33f1/lGlUXJYi.pdf", "name": "original", "width": null, "height": null }, "width": null, "height": null, "name": "lGlUXJYi.pdf" } }