sepay-cli

module
v0.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: Apache-2.0

README

Tiếng Việt · English

sepay-cli

CI Release npm Go Reference License OpenSSF Scorecard

SePay là công ty hạ tầng Open Banking hàng đầu tại Việt Nam, cung cấp API ngân hàng và tự động hoá dòng tiền cho doanh nghiệp, từ thu tiền, đối soát, thông báo đến xuất hoá đơn. Tạo tài khoản tại my.sepay.vn/register, rồi bật Test mode (sandbox) cho công ty. Sandbox miễn phí và không đụng đến tiền thật.

sepay là công cụ dòng lệnh của SePay. Đăng nhập, xem giao dịch, tạo webhook và nhận webhook ngay trên localhost, tạo đơn hàng thanh toán hosted checkout, và giả lập toàn bộ các bước đó trên sandbox.

sepay <command> <subcommand> [flags]

Cài đặt

Kênh Lệnh
Homebrew (macOS, Linux) brew install sepayvn/sepay-cli/sepay
Scoop (Windows) scoop bucket add sepay https://github.com/sepayvn/scoop-sepay-cli rồi scoop install sepay/sepay
Script (macOS, Linux) curl -fsSL https://get.sepay.vn/sepay-cli-install.sh | sh
Script (Windows, PowerShell) irm https://get.sepay.vn/sepay-cli-install.ps1 | iex
npm npm i -g sepay-cli
Go go install github.com/sepayvn/sepay-cli/cmd/sepay@latest
Tải thủ công archive cho từng nền tảng ở GitHub Releases

Script cài đặt kiểm tra SHA-256 của archive với checksums.txt, và kiểm tra thêm chữ ký cosign của checksums.txt khi máy có cosign; SEPAY_REQUIRE_SIGNATURE=1 từ chối cài khi không có cosign. SEPAY_VERSION (hoặc --version) chọn phiên bản, SEPAY_INSTALL_DIR (hoặc --dir) chọn thư mục cài (mặc định $HOME/.local/bin).

Khi thư mục cài chưa có trong PATH, script thêm một khối có dấu mốc (# >>> sepay-cli PATH >>> … # <<< sepay-cli PATH <<<) vào cuối file khởi động của shell bạn dùng ($SHELL): ~/.zshrc (zsh, trong $ZDOTDIR nếu có đặt), với bash trên macOS là file có trước tiên trong ~/.bash_profile, ~/.bash_login, ~/.profile (chưa có file nào thì ~/.bash_profile), ~/.bashrc (bash trên Linux), ~/.config/fish/conf.d/sepay.fish (fish, trong $XDG_CONFIG_HOME nếu có đặt), ~/.profile (sh, dash, ksh). Với shell khác (tcsh, nushell…), hoặc khi có --dir mà không có $HOME, script chỉ nhắc bạn tự thêm thư mục vào PATH (không có cả $HOME lẫn --dir thì script không cài). Chạy lại script không ghi trùng. Script không đổi được PATH của terminal đang mở: mở terminal mới, hoặc chạy dòng export PATH=… mà script in ra. SEPAY_NO_MODIFY_PATH=1 (hoặc --no-modify-path) để giữ nguyên các file đó; script chỉ in dòng export để bạn tự thêm. Gỡ cài đặt: xoá file sepay trong thư mục cài và xoá khối có dấu mốc (với fish là file sepay.fish).

Script PowerShell (Windows PowerShell 5.1 trở lên) kiểm tra y như vậy và nhận cùng các biến môi trường, đặt trước lệnh: $env:SEPAY_VERSION = '0.2.0'; irm … | iex. Mặc định cài vào %LOCALAPPDATA%\Programs\sepay và thêm thư mục đó vào PATH của user (không cần quyền admin); SEPAY_NO_MODIFY_PATH=1 để giữ nguyên PATH.

Ghim phiên bản trong một project Node:

npm install --save-dev sepay-cli@<version>
npx sepay-cli version
npx sepay-cli@next version                    # bản release candidate mới nhất

Các gói nền tảng của npm nằm dưới org @sepayjsc (@sepayjsc/cli-*). @sepayjsc là npm org của Công ty CP SePay (SePay JSC); mã nguồn ở github.com/sepayvn.

Xác minh bản tải về

Mỗi GitHub Release có checksums.txt, chữ ký checksums.txt.sig và chứng chỉ checksums.txt.pem. Tải chúng về cùng thư mục với archive, rồi:

cosign verify-blob checksums.txt \
  --signature checksums.txt.sig \
  --certificate checksums.txt.pem \
  --certificate-identity-regexp '^https://github\.com/sepayvn/sepay-cli/\.github/workflows/release\.yml@refs/(heads/main|tags/v.*)$' \
  --certificate-oidc-issuer https://token.actions.githubusercontent.com
sha256sum -c --ignore-missing checksums.txt      # macOS: shasum -a 256 -c --ignore-missing checksums.txt
gh attestation verify sepay_<version>_linux_amd64.tar.gz -R sepayvn/sepay-cli

Lệnh đầu chứng minh checksums.txt do workflow release của repo này ký. Lệnh thứ hai chứng minh archive khớp file đó. Lệnh cuối kiểm tra build provenance: archive được build từ commit và workflow nào.

Cập nhật
npm install -g sepay-cli@latest      # cài toàn cục bằng npm
npm install -D sepay-cli@latest      # ghim trong project (hoặc để Dependabot / Renovate mở PR)
brew upgrade sepay                   # Homebrew
scoop update sepay                   # Scoop
go install github.com/sepayvn/sepay-cli/cmd/sepay@latest
sepay update                         # cài bằng script hoặc giải nén archive

sepay update (hoặc sepay upgrade) tải bản mới nhất từ GitHub Releases cho đúng hệ điều hành và kiến trúc, kiểm SHA-256 với checksums.txt (và chữ ký nếu máy có cosign; SEPAY_REQUIRE_SIGNATURE=1 từ chối cập nhật khi không có cosign), chạy thử binary mới rồi mới thay binary đang dùng. Lệnh hỏi y/N trước khi thay; --yes bỏ câu hỏi, và khi không có terminal thì bắt buộc phải có --yes. --version 0.2.0 cài đúng bản đó, --check chỉ báo có bản mới hay không (kèm --json cho script). Nếu sepay được cài bằng npm, Homebrew, Scoop hay go install, lệnh không tự thay mà in lệnh cập nhật của công cụ đó và thoát với mã 1.

Mỗi ngày một lần, khi bạn chạy lệnh trên terminal, CLI kiểm tra xem đã có bản mới chưa và bản đang dùng có bị ngừng hỗ trợ (bị thu hồi hoặc có lỗ hổng) không, rồi in một dòng thông báo ngắn ra stderr sau khi lệnh chạy xong, kèm lệnh cập nhật hợp với cách bạn đã cài. Thông báo không tự cài gì, và không hiện khi chạy trong CI, khi dùng --json, hoặc khi đặt SEPAY_NO_UPDATE_NOTIFIER=1.

Bắt đầu

sepay login          # mở trình duyệt để xác nhận một mã dùng một lần
sepay auth status    # tài khoản và công ty bạn đang dùng

Token được lưu trong keychain của hệ điều hành. Trên máy không có keychain dùng được (server, máy truy cập qua SSH), CLI tự lưu token vào một file chỉ tài khoản của bạn đọc được và in cảnh báo màu vàng; bạn không cần làm gì thêm. Muốn lưu vào file ngay từ đầu: sepay login --insecure-storage. Máy không có trình duyệt: sepay login --with-token.

Mọi lệnh mặc định chạy trên sandbox. Thêm --env production để làm việc với dữ liệu thật.

Lệnh sửa dữ liệu trên production

Mọi lệnh sửa dữ liệu trên production chỉ chạy khi bạn tự xác nhận trên terminal của mình. AI không tự xác nhận thay bạn: gặp lệnh này, AI đưa lệnh để bạn tự chạy.

  • Lệnh phải có --env production ngay trên dòng lệnh; default_env: production không tính.
  • Có terminal: CLI hỏi [y/N], mặc định là Không.
  • Không có terminal (agent, pipe, CI): lệnh dừng với mã thoát 2 và câu ask the user to run this command in their own terminal. Script bạn tự viết chạy được khi lệnh có --env production, id của tài nguyên được sửa và --yes; lệnh tạo mới (không có id) chỉ chạy trên terminal.
  • --dry-run in request sẽ gửi và giá trị trước / sau, không gửi lệnh ghi nào. Lệnh vẫn gửi các request đọc nó cần, nên trên production token phải có scope read: webhook update, webhook delete và bank-account update đọc tài nguyên đó, webhook create và update đọc các tài khoản ngân hàng nhận webhook, paycode update đọc danh sách pay code, webhook replay đọc giao dịch và lần gửi gần nhất. paycode create và sepay api --dry-run không gửi gì, kể cả GET.

Danh sách lệnh áp luật này: sepay --map=json --env production, các lệnh có confirms: terminal. Agent không tự thêm --env production hay --yes cho các lệnh này. Chi tiết: https://developer.sepay.vn/vi/agents/cli/quy-uoc-chung#lenh-sua-du-lieu-tren-production

Trên production, CLI chỉ đọc đơn Cổng thanh toán (pg order list, pg order get) và hóa đơn điện tử (einvoice invoice list, einvoice invoice get); các lệnh pg, einvoice, bankhub, sandbox còn lại chỉ chạy trên sandbox.

Nhận webhook đầu tiên trên localhost

Không cần URL công khai, không cần tunnel.

# Handler của bạn đang chạy ở localhost:3000

sepay sandbox init --with-va --with-webhook-listen        # tạo tài khoản sandbox + webhook
sepay webhook listen --forward localhost:3000 --print     # chuyển sự kiện về handler (chỉ sandbox)

# Mở terminal thứ hai: tạo một giao dịch
sepay bank-account list                                   # ghi lại xid
sepay sandbox simulate payment_in --bank-account <ba_xid> --amount 50000 --code ABC123

Mỗi sự kiện mang đúng body và các header chữ ký mà SePay gửi, nên handler chạy đúng luồng thật, kể cả bước tự kiểm tra chữ ký. webhook listen chỉ chạy trên sandbox: với --env production CLI dừng với mã thoát 2, và server trả 404 cho mọi lần gọi listen trên production. Trên production, xem lần gửi bằng sepay webhook logs. Kiểm tra handler phản hồi đúng: sepay webhook test --forward localhost:3000 --amount 50000.

Các lệnh

Lệnh Chức năng
login, logout Đăng nhập, đăng xuất
auth status, switch, refresh, sessions, revoke, token
transaction Xem danh sách và chi tiết giao dịch
bank-account Quản lý tài khoản ngân hàng
webhook Tạo, sửa, xem log, replay; listen, test chỉ trên sandbox
va Quản lý tài khoản ảo (VA)
paycode Tiền tố mã thanh toán
pg Đơn hàng và merchant của Cổng thanh toán (Payment Gateway); production chỉ order list, order get
bankhub Công ty, tài khoản và link token của Bank Hub
einvoice Hóa đơn điện tử; production chỉ invoice list, invoice get
apikey API key sandbox. API key production tạo và thu hồi trên my.sepay.vn, CLI không quản lý
quota Hạn mức gói và mức sử dụng; production có thêm số hóa đơn điện tử còn lại
sandbox init, seed, simulate, reset (chỉ trên sandbox)
api Gọi bất kỳ endpoint nào của SePay API bằng token đã lưu
config Cấu hình CLI
completion Sinh script tự hoàn thành lệnh cho shell
version Phiên bản và thông tin build

sepay --help liệt kê toàn bộ. sepay --map=paths in mọi lệnh; --map=json kèm thêm metadata cho máy đọc.

Flag dùng chung

Flag Ý nghĩa
--env sandbox|production Môi trường, mặc định sandbox
--json, -o json|yaml Output cho máy đọc, không màu; mọi lệnh đọc dữ liệu đều hỗ trợ
-p, --profile Tài khoản cần dùng, khi đang đăng nhập nhiều tài khoản
-y, --yes Bỏ bước xác nhận (script, CI). Với lệnh ghi production (confirms: terminal trong sepay --map=json --env production), --yes chỉ được nhận khi lệnh có thêm --env production và nêu id tài nguyên được ghi
--no-input Không bao giờ hỏi; thiếu giá trị thì báo lỗi
--idempotency-key Chạy lại một lệnh ghi bị gián đoạn mà không thực hiện hai lần
-v, --verbose Log gỡ lỗi; token luôn được che

Biến môi trường: SEPAY_PROFILE, SEPAY_CONFIG_DIR, SEPAY_NO_UPDATE_NOTIFIER, SEPAY_LANG, NO_COLOR. Chi tiết: sepay help environment.

Mã thoát

Mã Ý nghĩa
0 Thành công
1 Lỗi phía server, lỗi mạng, hoặc dữ liệu bị từ chối; đọc error_code trước khi chạy lại
2 Sai flag, sai tham số, lệnh không tồn tại, hoặc lệnh sửa dữ liệu production cần bạn tự chạy trên terminal
3 Lệnh có trong CLI nhưng chưa có backend; đừng chạy lại
4 Chưa đăng nhập: sepay login
5 Token thiếu quyền (scope) cần thiết: sepay login --scopes <scope>
6 Handler trên máy bạn không nhận sự kiện (webhook test)
8 Tài khoản hoặc công ty của bạn không được phép làm việc này
130 Bị ngắt: Ctrl+C hoặc Esc khi đang hỏi, hoặc tín hiệu dừng

Lỗi in ra stderr, kết quả in ra stdout. Khi dùng --json, lỗi cũng ở dạng JSON, kèm error_code và exit_code. Danh sách đầy đủ: sepay help exit-codes.

Tự hoàn thành lệnh (shell completion)

Cài bằng Homebrew thì script bash, zsh, fish đã có sẵn. Cài từ gói release hoặc npm thì ghi script ra file một lần; shell nạp từ file nên sepay không chạy mỗi lần mở shell.

# Bash (cần gói bash-completion)
mkdir -p ~/.local/share/bash-completion/completions
sepay completion bash > ~/.local/share/bash-completion/completions/sepay

# Zsh (rồi thêm fpath+=~/.zfunc vào ~/.zshrc, trước compinit)
mkdir -p ~/.zfunc
sepay completion zsh > ~/.zfunc/_sepay

# Fish
sepay completion fish > ~/.config/fish/completions/sepay.fish

# PowerShell (thêm dòng này vào $PROFILE)
sepay completion powershell | Out-String | Invoke-Expression

Tài liệu

Hướng dẫn theo tác vụ, body của webhook và IPN, tài liệu API: developer.sepay.vn/vi/agents/cli.

Ngay trong terminal, sepay help <topic> in các topic environment, errors, exit-codes và glossary đúng với phiên bản đang chạy.

Go API

Module này là một CLI, không phải thư viện. Các package dưới pkg/ theo bố cục của cli/cli và không có cam kết tương thích nào giữa các phiên bản.

Đóng góp

CONTRIBUTING.md. Báo cáo lỗ hổng bảo mật: SECURITY.md.

Giấy phép

Apache-2.0 © SePay JSC.

Directories

Path Synopsis
cmd
sepay command
Command sepay is the SePay CLI entry point.
Command sepay is the SePay CLI entry point.
internal
agent
Package agent detects the AI coding agent that launched the CLI, so the server can log which writes an agent ran.
Package agent detects the AI coding agent that launched the CLI, so the server can log which writes an agent ran.
api
Package api is the SePay API v2 HTTP client.
Package api is the SePay API v2 HTTP client.
auth
Package auth implements the OAuth2 device-authorization-grant client (RFC 8628).
Package auth implements the OAuth2 device-authorization-grant client (RFC 8628).
bankhub
Package bankhub is the Bank Hub v1 HTTP client, authenticated with a broker-minted product credential.
Package bankhub is the Bank Hub v1 HTTP client, authenticated with a broker-minted product credential.
build
Package build holds version info injected via -ldflags.
Package build holds version info injected via -ldflags.
config
Package config reads and writes the sepay config (config.yml).
Package config reads and writes the sepay config (config.yml).
einvoice
Package einvoice is the E-Invoice v1 HTTP client, authenticated with a broker-minted product credential.
Package einvoice is the E-Invoice v1 HTTP client, authenticated with a broker-minted product credential.
envvar
Package envvar reads the CLI's on/off environment switches.
Package envvar reads the CLI's on/off environment switches.
forward
Package forward replays a webhook event verbatim, headers included, to a local handler.
Package forward replays a webhook event verbatim, headers included, to a local handler.
golden
Package golden compares test output with testdata/<name>.golden; -update rewrites the files.
Package golden compares test output with testdata/<name>.golden; -update rewrites the files.
keychain
Package keychain bounds every OS keychain call, so a secret service that never answers counts as unavailable instead of hanging.
Package keychain bounds every OS keychain call, so a secret service that never answers counts as unavailable instead of hanging.
listen
Package listen streams one SePay delivery channel over SSE and replays each delivery to a local HTTP handler.
Package listen streams one SePay delivery channel over SSE and replays each delivery to a local HTTP handler.
locale
Package locale picks the language of the few screens the CLI translates.
Package locale picks the language of the few screens the CLI translates.
pg
Package pg is the Payment Gateway v1 HTTP client, authenticated with a broker-minted product credential.
Package pg is the Payment Gateway v1 HTTP client, authenticated with a broker-minted product credential.
product
Package product brokers and caches product-native credentials (PG, eInvoice, Bank Hub).
Package product brokers and caches product-native credentials (PG, eInvoice, Bank Hub).
prompt
Package prompt draws the interactive questions the CLI asks on a terminal.
Package prompt draws the interactive questions the CLI asks on a terminal.
sse
Package sse subscribes to the SePay webhook hub over Server-Sent Events.
Package sse subscribes to the SePay webhook hub over Server-Sent Events.
update
Package update notifies, at most once a day, of a newer or deprecated release, and replaces a self-managed binary with a release from GitHub Releases on request.
Package update notifies, at most once a day, of a newer or deprecated release, and replaces a self-managed binary with a release from GitHub Releases on request.
pkg
cmd/api
Package api implements "sepay api", an authenticated raw passthrough to the public SePay API.
Package api implements "sepay api", an authenticated raw passthrough to the public SePay API.
cmd/apikey
Package apikey implements "sepay apikey".
Package apikey implements "sepay apikey".
cmd/auth
Package auth implements "sepay auth" and the root "login"/"logout" aliases.
Package auth implements "sepay auth" and the root "login"/"logout" aliases.
cmd/bankaccount
Package bankaccount implements "sepay bank-account".
Package bankaccount implements "sepay bank-account".
cmd/bankhub
Package bankhub implements "sepay bankhub", the Bank Hub server API.
Package bankhub implements "sepay bankhub", the Bank Hub server API.
cmd/completion
Package completion implements "sepay completion".
Package completion implements "sepay completion".
cmd/config
Package config implements "sepay config" (persistent CLI settings).
Package config implements "sepay config" (persistent CLI settings).
cmd/einvoice
Package einvoice implements "sepay einvoice".
Package einvoice implements "sepay einvoice".
cmd/paycode
Package paycode implements "sepay paycode" (list, update, create).
Package paycode implements "sepay paycode" (list, update, create).
cmd/pg
Package pg implements "sepay pg" (Payment Gateway).
Package pg implements "sepay pg" (Payment Gateway).
cmd/quota
Package quota implements "sepay quota".
Package quota implements "sepay quota".
cmd/root
Package root builds the top-level "sepay" command and its global flags.
Package root builds the top-level "sepay" command and its global flags.
cmd/sandbox
Package sandbox implements "sepay sandbox", the sandbox-only utilities.
Package sandbox implements "sepay sandbox", the sandbox-only utilities.
cmd/transaction
Package transaction implements "sepay transaction".
Package transaction implements "sepay transaction".
cmd/update
Package update implements "sepay update".
Package update implements "sepay update".
cmd/va
Package va implements "sepay va".
Package va implements "sepay va".
cmd/version
Package version implements "sepay version".
Package version implements "sepay version".
cmd/webhook
Package webhook implements "sepay webhook" and its verbs (listen, test, list, get, create, update, delete, logs, replay).
Package webhook implements "sepay webhook" and its verbs (listen, test, list, get, create, update, delete, logs, replay).
cmdutil
Package cmdutil provides the shared Factory and error types used by every command.
Package cmdutil provides the shared Factory and error types used by every command.
cmdutil/prompttest
Package prompttest scripts the answers to a command's interactive prompts in tests.
Package prompttest scripts the answers to a command's interactive prompts in tests.
iostreams
Package iostreams bundles a command's streams and TTY/color state.
Package iostreams bundles a command's streams and TTY/color state.
jsonfmt
Package jsonfmt renders output as an aligned table or JSON/YAML.
Package jsonfmt renders output as an aligned table or JSON/YAML.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL