This repository contains a lightweight PHP integration that pulls amoCRM deal/contact data and renders .docx documents (orders, acts, etc.) using PhpWord templates. Everything (OAuth, API requests, template filling) runs inside a shared-hosting friendly project without background workers or queues.
- amoCRM OAuth flow handled via
oauth.php, refresh logic built intoapi/generate.php. - PhpWord
TemplateProcessorreplaces all placeholders insidetemplates/*.docx. - Prefill cache (
api/prefill.php) stores the last list of products per deal to speed up repeat document creation. - Filesystem layout suits FTP/shared hosting: generated docs live in
documents/, cached data indata/, logs inlogs/.
api/— HTTP endpoints that talk to amoCRM and produce docs or cached payloads.public/— small UI to trigger generation (ui.html,app.js,main.css).src/— reusable helpers (builders, formatters) tested with PHPUnit.templates/—.docxWord templates with placeholders.documents/,logs/,data/— writable directories for runtime artifacts.tests/— PHPUnit suite (smoke + pure logic tests).
- PHP 7.4+ with
curl,intl,mbstring,zip. - Composer (system or local
composer.phar). - Writable directories:
documents/,logs/,data/,data/cache/.
- Edit
config/config.php: fill amoCRMclient_id,client_secret,redirect_uri,base_domain, paths if you deploy outside repo root, and optionallyhmac_secret. - Run the amoCRM auth flow (
oauth.php?code=...) to createconfig/token.json. - Ensure
public/app.jspoints to your domain (update theAPIconstant if necessary). - Verify that
public/ui.html?lead_id=<ID>opens and hits your API endpoints.
- Upload the repo to hosting, keep
config/,documents/,logs/,data/out of public reach or tighten web-server rules. - Serve the UI from
public/or linkui.htmlinside your amoCRM widget withlead_idquery arg. POST /api/generate.phpexpectslead_id,template,discount,products[]; it downloads deal/contact details, fills the template, saves.docxtodocuments/and posts a note back to amoCRM.GET /api/prefill.php?lead_id=returns cached payload so the UI can restore the previous basket.
Install dependencies and run PHPUnit (commands below are for Windows PowerShell; on Linux/macOS drop the .\ prefix).
composer install
.\vendor\bin\phpunitFor more detailed documentation (setup walkthrough, API examples, template placeholders) see docs/README_en.md.
Для более подробной документации см. docs/README_ru.md.