跳至主要内容

Agreement Deduction API

HTTP Request

POST /v5/bybitpay/agreement/pay

Execute automatic deduction from user's account using a signed agreement. This is the core API for agreement payment.


Request Parameters

ParameterTypeRequiredDescription
merchant_idstringYesMerchant ID
user_idstringYesPlatform user ID
agreement_typestringYesSign type: CYCLE / NON_CYCLE / SINGLE
agreement_nostringYesPlatform agreement number
out_trade_nostringYesMerchant order number (unique)
scene_codestringYesScene code - Supports 17 scenarios including TAXI, PARKING, SUBSCRIPTION, FOOD, ENTERTAINMENT, EDUCATION, etc.
amountobjectYesDeduction amount
amount.totalstringYesAmount (minimum unit)
amount.currencystringYesCurrency code
amount.currency_typestringYesFIAT or CRYPTO
amount.chainstringNoChain network (required for crypto)
amount.chain_addressstringNoChain address (required for dynamic on-chain settlement)
order_infoobjectYesOrder information
order_info.order_titlestringYesOrder title (displayed to user)
order_info.order_descstringNoOrder description
order_info.goods_namestringNoGoods name
order_info.goods_idstringNoGoods ID
order_info.goods_categorystringNoGoods category
scene_infoobjectNoScene information
scene_info.device_idstringNoDevice ID
scene_info.device_ipstringNoDevice IP
scene_info.locationobjectNoLocation information
scene_info.location.latitudestringNoLatitude
scene_info.location.longitudestringNoLongitude
scene_info.location.addressstringNoDetailed address
notify_urlstringYesDeduction result webhook URL
risk_infoobjectNoRisk control information
risk_info.user_ipstringNoUser IP address
risk_info.device_fingerprintstringNoDevice fingerprint
risk_info.user_agentstringNoUser agent string

Response Parameters

ParameterTypeDescription
retCodeintResponse code
retMsgstringResponse message
resultobjectResponse data
result.order_nostringPlatform order number
result.trade_nostringPlatform trade number
result.out_trade_nostringMerchant order number
result.statusstringTransaction status: PROCESSING / SUCCESS / FAILED / TIMEOUT
result.amountobjectRequested amount
result.crypto_paymentobjectActual crypto payment info (for fiat orders)
result.crypto_payment.currencystringCryptocurrency (e.g., USDT)
result.crypto_payment.amountstringCryptocurrency amount
result.crypto_payment.chainstringChain network
result.crypto_payment.exchange_ratestringExchange rate
result.crypto_payment.rate_timestringRate lock time
result.pay_timestringPayment time (on success)
result.failure_reasonstringFailure reason (on failure)

Request Examples

Cryptocurrency Order

POST /v5/bybitpay/agreement/pay HTTP/1.1
Host: api2.bybit.com
Content-Type: application/json
X-BAPI-API-KEY: xxxxxxxxxxxxxxxxxx
X-BAPI-TIMESTAMP: 1736233200000
X-BAPI-SIGN: {signature}
X-BAPI-RECV-WINDOW: 5000

{
"merchant_id": "M123456789",
"user_id": "U_123456789",
"agreement_type": "CYCLE",
"agreement_no": "AGR202601070001",
"out_trade_no": "ORDER20260107001",
"scene_code": "SUBSCRIPTION",
"amount": {
"total": "2350",
"currency": "USDT",
"currency_type": "CRYPTO",
"chain": "TRC20"
},
"order_info": {
"order_title": "Monthly subscription - January 2026",
"order_desc": "Premium membership",
"goods_name": "Premium Plan",
"goods_id": "PREMIUM_001"
},
"notify_url": "https://merchant.com/notify/pay"
}

Fiat Currency Order

POST /v5/bybitpay/agreement/pay HTTP/1.1
Host: api2.bybit.com
Content-Type: application/json
X-BAPI-API-KEY: xxxxxxxxxxxxxxxxxx
X-BAPI-TIMESTAMP: 1736233200000
X-BAPI-SIGN: {signature}
X-BAPI-RECV-WINDOW: 5000

{
"merchant_id": "M123456789",
"user_id": "U_123456789",
"agreement_type": "CYCLE",
"agreement_no": "AGR202601070001",
"out_trade_no": "ORDER20260107002",
"scene_code": "TAXI",
"amount": {
"total": "10000",
"currency": "USD",
"currency_type": "FIAT"
},
"order_info": {
"order_title": "Ride fare",
"order_desc": "Trip from A to B"
},
"scene_info": {
"device_id": "DEVICE_001",
"device_ip": "192.168.1.1",
"location": {
"latitude": "39.9042",
"longitude": "116.4074",
"address": "Beijing, China"
}
},
"risk_info": {
"user_ip": "203.0.113.45",
"device_fingerprint": "fp_abc123xyz"
},
"notify_url": "https://merchant.com/notify/pay"
}

Response Examples

Crypto Order Success

{
"retCode": 20000,
"retMsg": "Success",
"result": {
"order_no": "ORD202601070001",
"trade_no": "PAY202601070001",
"out_trade_no": "ORDER20260107001",
"status": "SUCCESS",
"amount": {
"total": "2350",
"currency": "USDT",
"currency_type": "CRYPTO",
"chain": "TRC20"
},
"pay_time": "2026-01-07T10:30:00Z"
}
}

Fiat Order Success (with Crypto Payment)

{
"retCode": 20000,
"retMsg": "Success",
"result": {
"order_no": "ORD202601070002",
"trade_no": "PAY202601070002",
"out_trade_no": "ORDER20260107002",
"status": "SUCCESS",
"amount": {
"total": "10000",
"currency": "USD",
"currency_type": "FIAT"
},
"crypto_payment": {
"currency": "USDT",
"amount": "10005.50",
"chain": "TRC20",
"exchange_rate": "1.00055",
"rate_time": "2026-01-07T10:29:55Z"
},
"pay_time": "2026-01-07T10:30:00Z"
}
}

Processing Status

{
"retCode": 20000,
"retMsg": "Success",
"result": {
"order_no": "ORD202601070003",
"trade_no": "PAY202601070003",
"out_trade_no": "ORDER20260107003",
"status": "PROCESSING",
"amount": {
"total": "5000",
"currency": "USDT",
"currency_type": "CRYPTO",
"chain": "TRC20"
}
}
}

Deduction Failed

{
"retCode": 20000,
"retMsg": "Success",
"result": {
"order_no": "ORD202601070004",
"trade_no": "PAY202601070004",
"out_trade_no": "ORDER20260107004",
"status": "FAILED",
"amount": {
"total": "5000",
"currency": "USDT",
"currency_type": "CRYPTO",
"chain": "TRC20"
},
"failure_reason": "BALANCE_NOT_ENOUGH"
}
}

Verification Steps

Platform performs the following checks before executing deduction:

  1. Agreement Validity: Agreement must be in SIGNED status
  2. Single Limit Check: Amount does not exceed single transaction limit
  3. Period Limit Check: Cumulative amount does not exceed period limit
  4. Balance Check: User account has sufficient balance
  5. Risk Check: Transaction passes risk control rules

Notes

  1. Idempotency: Same out_trade_no returns result of first request
  2. Async Processing: PROCESSING status requires waiting for webhook or query
  3. Timeout Handling: Set 30-second timeout, query if timeout occurs
  4. Fiat Orders: User pays with cryptocurrency; crypto_payment shows actual payment details