機能
- License Key Validation: Dodo Payments API に対して license key を検証します。
- License Key Activation: activation limit が設定された key に対して、instance name を指定して license key をアクティベートします。
- Environment Support: test mode と live mode の両方に設定できます。
- TypeScript Support: error handling を備えた完全に型付けされた実装です。
始め方
始める前に、Figmaデスクトップアプリと、ライセンスキーを発行するDodo Payments productが必要です。1
Create Base Plugin
Figmaのplugin quickstart guideを使用して、独自のFigmaプラグインプロジェクトを作成します。Figmaは
manifest.jsonファイルを含むscaffoldを生成します。2
Clone the Example Implementation
dodopayments-figma repositoryをcloneします。cloneした
manifest.jsonで、nameとidを、生成したプラグインのmanifest.jsonの値に置き換えます。このサンプルを統合の出発点として使用します。3
Install Dependencies
プロジェクトのrootで、次を実行します。
4
Configure Environment
src/ui/api.tsでAPI_MODEを設定します。API_MODEはAPI hostを選択します。test_modeの場合はhttps://test.dodopayments.com、live_modeの場合はhttps://live.dodopayments.comです。5
Customize Components
src/ui/components/のプラグインコンポーネントをニーズに合わせてカスタマイズします。- 有効なライセンスキーを持つユーザーに機能を提供するよう、
Authenticated.tsxを更新します。 - デザインに合わせて
LicenseKeyInput.tsxをカスタマイズします。
Authenticated.tsxに、プラグインのプレミアム機能を追加します。プラグインは、ライセンスキーが検証または有効化された後にのみ、この機能を表示します。Configuration
1
Configure Network Access
この例では、すべての license key リクエストを
https://dodo-payments-proxy.aagarwal9782.workers.dev の CORS proxy 経由で送信し、manifest.json ではその proxy にのみネットワークアクセスを許可しています。proxy は利用できないため、Dodo Payments API を直接呼び出してください。API は、null にある plugin UI の origin を含め、任意の origin からの cross-origin requests を受け付けます。manifest.json で、proxy domain を Dodo Payments API hosts に置き換えます。src/ui/api.ts で、validateLicenseKey と activateLicenseKey にある fetch(proxyReq) を fetch(req) に置き換え、各リクエストが API に直接送信されるようにします。これにより、plugin で Dodo Payments API を使用して license key の検証とアクティベーションを行えるようになります。2
Configure API Mode
src/ui/api.ts で、API mode を設定します。開発
1
Import Plugin
Figma desktop app に plugin をインポートします。
- design file を開きます。
- Figma menu を開き、Plugins を選択します。
- Development で Import new plugin from manifest… を選択し、次に project root にある
manifest.jsonfile を選択します。
dist/ にある built files から plugin を読み込むため、plugin を実行する前に development server を起動するか、npm run build を実行してください。Figma は plugin code を local files から読み込むため、plugin をローカルで開発およびテストするには Figma desktop app が必要です。
2
Start Development Server
source code を変更すると、plugin は自動的に rebuild されます。
Build Commands
project には次の npm scripts が含まれています。License Key Integration
example implementation では、plugin のロックを解除する前に license key をチェックします。各ステップはカスタマイズできます。- User Input: ユーザーが plugin UI に license key を入力します。
- Validation: デフォルトでは、plugin は Validate License(
POST /licenses/validate)で key を検証します。 - Activation: license key に activation limit がある場合は、
src/ui/components/Unauthenticated.tsxのneedsActivationをtrueに設定します。すると plugin は key を検証する代わりに Activate License(POST /licenses/activate)で key をアクティベートし、instance にFigma Pluginという名前を付けます。 - Access Control: 有効な key の場合、plugin は
figma.clientStorageで key を保存し、Authenticated.tsxを表示します。次回 plugin を開いたときに、保存された key を再度検証します。
公開
plugin の準備が整ったら、次の手順を実行します。- production 用に build します:
npm run build - test mode と live mode の両方で十分にテストします。
- Figma’s plugin publishing guidelines に従います。
- Figma Community を通じて plugin を review に提出します。