AgentKit
Tài liệuBộ kitTham chiếu CLIỨng dụng Desktop

Skill

Tích hợp thanh toán an toàn với ak:payment-integration

Triển khai checkout và webhook SePay, PayFS, Polar, Stripe, Creem, Dodo Payments, Lemon Squeezy, Paddle hoặc PayPal với credential, idempotency, financial side effect cùng bằng chứng go-live rõ ràng.

Dùng ak:payment-integration để thiết kế hoặc triển khai payment flow với SePay, PayFS, Polar, Stripe, Creem, Dodo Payments, Lemon Squeezy, Paddle hoặc PayPal. Skill bao quát checkout, subscription, usage/credit billing, license key, VietQR và bank transfer, signed webhook, order nhận biết provider, refund cùng xử lý event bền vững. Skill hữu ích nhất khi provider và business outcome đã rõ.

Chọn ak:payment-integration cho công việc provider

Dùng ak:payment-integration khi

  • Bạn cần SePay hoặc PayFS cho VND, bank transfer hoặc VietQR.
  • Bạn cần Polar, Creem, Dodo Payments, Lemon Squeezy hoặc Paddle cho checkout merchant-of-record của SaaS/digital product, subscription, usage billing hoặc license key.
  • Bạn cần guidance Stripe Checkout, Billing, Payment Element hoặc Connect.
  • Bạn cần checkout ví/thẻ PayPal hoặc subscription, nơi bạn vẫn là merchant of record.
  • Bạn cần order model hợp nhất hoặc webhook processing idempotent giữa nhiều provider.

Chọn workflow khác khi

  • Việc chọn provider, trách nhiệm thuế, merchant-of-record policy, refund policy hoặc liability chưa thống nhất. Giải quyết quyết định product và legal trước implementation.
  • Task chỉ là database design. Dùng ak:databases với payment contract.
  • Bạn cần backend implementation tổng quát rộng hơn thanh toán. Dùng ak:cook và nêu Skill này như specialist guidance.
  • Bạn cần đảm bảo tài chính, pháp lý, PCI hoặc kế toán. Hãy dùng human review đủ chuyên môn; Skill này không cung cấp đảm bảo đó.

Chuẩn bị payment contract và sandbox

Trước khi bắt đầu:

  • Hoàn thành Làm quen và xác nhận Engineer Kit đã được cài cho runtime cùng scope hiện tại.
  • Xác định provider SDK và API version đã cài, framework, database, order schema, authentication, queue, deployment host cùng test tool.
  • Xác định currency, cách lưu smallest unit, product/price, tax, discount, trial, fulfillment, cancellation, refund, dispute cùng reconciliation rule.
  • Dùng sandbox account, test product, test payment method, webhook endpoint cô lập cùng customer data giả lập. PayFS không có sandbox; coi mọi call PayFS là live và gate tương ứng.
  • Giữ provider secret key cùng webhook signing secret (ví dụ SEPAY_SECRET_KEY, PAYFS_WEBHOOK_SECRET, POLAR_ACCESS_TOKEN và POLAR_WEBHOOK_SECRET, Stripe secret/signing key, CREEM_API_KEY và CREEM_WEBHOOK_SECRET, DODO_PAYMENTS_API_KEY và DODO_PAYMENTS_WEBHOOK_KEY, LEMONSQUEEZY_API_KEY và LEMONSQUEEZY_WEBHOOK_SECRET, PADDLE_WEBHOOK_SECRET, cùng PAYPAL_CLIENT_ID/PAYPAL_CLIENT_SECRET với PAYPAL_WEBHOOK_ID riêng) và customer data ngoài prompt, log, client bundle, command history cùng Git.
  • Nêu rõ có cho phép cài package, gọi provider API, đổi dashboard, mở public tunnel, ghi database, gửi email, refund hay deploy không.

Fee, limit, payment method được hỗ trợ, API version cùng compliance requirement của provider thay đổi theo thời gian. Xác nhận trong tài liệu provider hiện tại trước quyết định tài chính hoặc production.

RuntimeCách gọiRanh giới khả dụng
Claude Code/ak:payment-integration ...Có thể triển khai và test bằng project tool khả dụng; truy cập provider vẫn cần credential cùng quyền rõ ràng.
Cursor/ak:payment-integration ...Dùng slash syntax đã được người dùng xác minh; parity rộng hơn về Agent, Hook và external tool chưa được thiết lập.
Codex$ak:payment-integration ...Dùng native Skill discovery; Hook được chuyển đổi một phần và provider/network tool tùy session.

Xem Runtime adapter để hiểu khác biệt theo từng component.

Chọn provider

ProviderPhù hợp nhất cho
SePayThị trường Việt Nam, VND, bank transfer, VietQR/NAPAS
PayFSWebhook xác nhận bank transfer Việt Nam (MB/ACB/OCB trực tiếp; ngân hàng khác qua NAPAS cho doanh nghiệp), gói tháng cố định, không qua gateway, không có sandbox
PolarSaaS toàn cầu, subscription, benefit tự động (giao GitHub/Discord)
StripeThanh toán enterprise, nền tảng Connect, checkout tùy biến
CreemMerchant of record cho SaaS/software, license key, chỉ USD/EUR, API đơn giản
Dodo PaymentsMerchant of record cho SaaS/AI/digital product, usage/credit billing, license key, Standard Webhooks
Lemon SqueezyStore Lemon Squeezy hiện có; merchant of record cho digital product/SaaS. Thuộc sở hữu Stripe và ở chế độ bảo trì; cân nhắc Stripe Managed Payments cho build mới
PaddleMerchant of record cho SaaS/AI/digital product, hơn 30 currency, checkout Paddle.js, subscription nhiều item
PayPalCheckout ví/thẻ toàn cầu, subscription; không phải merchant of record (bạn tự chịu thuế), không có VND

Chạy Skill

Argument shape được khai báo là [provider] [task]. Nêu một provider hoặc ranh giới multi-provider có chủ đích, rồi mô tả contract về tiền, order, webhook, test cùng publication.

/ak:payment-integration "stripe Add a sandbox subscription checkout to the existing SaaS app. Reuse its order schema and auth, pin the installed API version, verify webhook signatures on the raw body, deduplicate events, test renewal and failure paths, and do not create live products, charge cards, refund, or deploy."
InputCần gồm
Commercial contractProvider, product, price ID, currency, tax/MoR role, trial, entitlement, refund cùng dispute policy
Data contractInternal order ID, provider ID, amount/currency gốc, status mapping, event ledger cùng audit retention
Webhook contractEndpoint, raw-body access, signature scheme, event ID, retry, queue behavior, idempotency cùng reconciliation
Quyền hạnSandbox hay live account, API mutation được phép, tunnel, database write, notification, refund cùng deployment
Bằng chứngTest tập trung, provider test event, order transition, duplicate delivery, failure recovery, log cùng reconciliation output

Quan sát các giai đoạn thanh toán

  1. Lần chạy xác minh ranh giới provider. Skill xác nhận SDK/API version, environment, checkout product, currency, legal ownership cùng integration point thực tế của project.
  2. Lần chạy lập bản đồ order state machine. Internal/provider identifier, amount, currency, subscription, refund, entitlement, license key cùng terminal state luôn rõ ràng.
  3. Lần chạy tạo checkout ở server. Thao tác dùng secret key nằm sau server endpoint đã xác thực; client chỉ nhận value an toàn.
  4. Lần chạy xử lý webhook trước fulfillment. Skill xác minh raw request thật bằng scheme signature riêng của provider (HMAC cho SePay, PayFS, Polar, Creem, Lemon Squeezy và Paddle; Standard Webhooks cho Dodo Payments; CRC32 kết hợp xác minh chứng chỉ RSA cho PayPal), từ chối delivery không hợp lệ, ghi unique event và bảo đảm processing idempotent trước khi đổi access hay money state.
  5. Lần chạy xác minh retry và reconciliation. Event trùng, trễ, sai thứ tự, lỗi, refunded, renewed, canceled cùng unknown được kiểm tra trên sandbox contract, hoặc trên ranh giới live của PayFS khi đó là provider.
  6. Lần chạy báo cáo gap go-live. Tệp đổi, credential cần có, provider object, test, monitoring, dashboard step thủ công cùng financial hoặc deployment action chưa duyệt được liệt kê.

Giữ tiền và external service dưới quyền duyệt

Một API call thành công có thể đổi tiền hoặc access

Live checkout, subscription change, refund, benefit grant, bank event, product edit cùng webhook replay có thể ảnh hưởng customer và financial record. Quyền sandbox không bao hàm quyền production, và PayFS hoàn toàn không có sandbox.

  • Dùng secret ở server và cơ chế constant-time hoặc SDK signature verification do provider khuyến nghị. Không coi redirect hay client success page là xác nhận thanh toán.
  • Giữ fulfillment cùng entitlement change idempotent. Lưu provider event ID và đủ bằng chứng cho replay cùng reconciliation. Webhook ID của PayPal không được gửi kèm payload; lưu nó tách biệt với các webhook secret ở trên và cấp cho verifier.
  • Public tunnel tool đưa local endpoint ra internet. Xác nhận endpoint, authentication, payload logging cùng kế hoạch shutdown trước.
  • Checkout helper đi kèm tạo configuration; nó không hoàn tất provider checkout. Output Polar nhúng access token vào lệnh cURL được hiển thị, vì vậy đừng dùng live token trong interactive output hoặc shell history.
  • Các webhook verifier theo provider đi kèm (SePay, PayFS, Polar, Creem, Dodo Payments, Lemon Squeezy, Paddle, PayPal) tự tạo hoặc kiểm tra signature cho payload test cục bộ; chúng không chứng minh real incoming delivery. OAuth mode của helper SePay chỉ kiểm tra có Bearer token, không kiểm tra token hợp lệ, còn PayFS còn yêu cầu khớp header X-Client-API-Key. Dùng provider SDK hoặc verifier đạt chuẩn production cho endpoint thật.
  • Commit, product publication, live webhook registration, refund execution, rollout cùng deployment cần phê duyệt riêng.

Xác minh kết quả

Kết quả hoàn tất nên cung cấp:

  • Checkout cùng order-state contract, gồm amount unit, currency, provider ID, customer mapping, license key nếu provider phát hành, cùng fulfillment boundary.
  • Chính xác tệp đổi, package, tên environment variable, schema hay migration artifact, queue cùng provider object mà không có secret value.
  • Bằng chứng test cho checkout creation, invalid input, signature failure, duplicate delivery, retry, out-of-order event, renewal, cancellation, refund cùng unknown-event handling khi áp dụng.
  • Log hoặc persisted event evidence hỗ trợ audit, replay cùng reconciliation mà không lưu payment data nhạy cảm quá mức.
  • Go-live checklist bao gồm provider configuration, secret rotation, endpoint TLS, monitoring, alerting, backup, rollback, support cùng phê duyệt.

Xử lý sự cố hoặc tiếp tục

Triệu chứngBước tiếp theo an toàn
Webhook signature thất bạiGiữ exact raw byte cùng header an toàn, xác nhận thứ tự parser và environment secret, rồi replay provider-generated test event.
Provider retry event đã thành côngKiểm tra response timing/status cùng durable idempotency record; đừng chặn retry bằng cách acknowledge payload chưa xác minh.
Order và provider state không khớpDừng automated fulfillment, so provider ID cùng event history, reconcile trong report có giới hạn rồi duyệt corrective mutation riêng.
Test chạm live accountDừng, revoke hoặc rotate credential bị lộ, kiểm tra object và charge đã tạo, chỉ tiếp tục với sandbox identity đã xác minh, hoặc với phê duyệt ranh giới live rõ ràng cho PayFS.
Helper đi kèm báo successChỉ coi đó là local format validation; xác minh handler thật bằng provider test event cùng application persistence.
Runtime không nhận diện SkillXác nhận target cùng scope, mở session mới, rồi làm theo Runtime không tìm thấy Skill hoặc Agent.

Tiếp tục với ak:databases cho order ledger, ak:test cho verification độc lập hoặc Tổng quan Engineer Kit cho delivery được điều phối.

Biết các giới hạn hiện tại

  • Reference là snapshot provider, không phải live contract. API, SDK, price, fee, limit, payment method, tax handling cùng store policy hiện tại cần được xác minh với provider.
  • Skill không cung cấp PCI scope determination, tư vấn pháp lý/thuế/kế toán, fraud underwriting, bảo đảm bank reconciliation hay production credential.
  • Helper test đi kèm kiểm tra JavaScript utility cục bộ, không kiểm tra provider network behavior, real webhook delivery, database transaction, financial accuracy, dispute hay production failover.
  • Lemon Squeezy thuộc sở hữu Stripe và ở chế độ bảo trì; reference JS SDK của nó đã cũ, và build mới nên so sánh với Stripe Managed Payments trước khi chọn.
  • Ví dụ multi-provider là pattern; currency conversion, refund, discount, commission cùng entitlement rule phải khớp business ledger hiện tại.