Used to check for browser translation.
用于检测浏览器翻译。
ブラウザの翻訳を検出する
API 参考

支付货币


支付货币 API 允许你管理应用程序接受支付的各种货币。每种货币都与特定的支付方式相关联,并定义了其名称、符号和小数精度等属性。

这是一个核心资源,会被其他对象(例如价格)引用。

支付货币对象#

PaymentCurrency 对象包含有关受支持货币的详细信息。

Attribute

Type

Description

id

string

货币对象的唯一标识符。

payment_method_id

string

此货币关联的支付方式的 ID。

active

boolean

此货币是否处于活动状态且可用于支付。

livemode

boolean

如果对象存在于生产模式中,则为 true;如果存在于测试模式中,则为 false

locked

boolean

如果为 true,则无法修改此货币。

is_base_currency

boolean

指示这是否是相关支付方式的基础货币。

name

string

货币的全名(例如,“Ethereum”)。

description

string

货币的描述。

logo

string

货币图片或徽标的 URL。

symbol

string

货币符号(例如,“ETH”)。

decimal

number

货币支持的小数位数。

maximum_precision

number

小数点后的最大位数。

minimum_payment_amount

string

单次支付所需的最小金额,以字符串形式表示。

maximum_payment_amount

string

单次支付允许的最大金额,以字符串形式表示。

contract

string

基于代币的货币的合约地址(如果适用)。

type

string

货币类型。可以是 'standard''credit'

vault_config

object

货币金库的配置。包含 enableddeposit_thresholdwithdraw_thresholdbuffer_threshold

metadata

Record<string, any>

可以附加到对象的一组键值对。

created_at

Date

创建货币时的时间戳。

updated_at

Date

货币最后更新的时间戳。

创建货币#

创建你的应用程序可以接受的新支付货币。

参数

Name

Type

Description

name

string

必填。 货币的全名。

payment_method_id

string

必填。 此货币所属支付方式的 ID。

symbol

string

必填。 货币的符号。

logo

string

必填。 货币徽标的 URL。

description

string

货币的可选描述。

decimal

number

小数位数。默认为 18

type

string

货币类型。可以是 standardcredit。默认为 standard

active

boolean

货币是否处于活动状态。默认为 true

minimum_payment_amount

string

最小支付金额。默认为 '0'

maximum_payment_amount

string

最大支付金额。默认为一个非常大的数字字符串。

contract

string

基于代币的货币的合约地址。

示例

import payment from '@blocklet/payment-js';

async function createCurrency() {
try {
const currency = await payment.paymentCurrencies.create({
name: 'ArcBlock Token',
symbol: 'ABT',
logo: 'https://www.arcblock.io/images/abt-logo.png',
description: 'The native token of the ArcBlock platform.',
payment_method_id: 'pm_xxxxxxxxxxxx',
decimal: 18,
type: 'standard'
});
console.log('已创建货币:', currency);
} catch (error) {
console.error('创建货币时出错:', error);
}
}

createCurrency();

响应示例

{
"id": "curr_1234567890",
"payment_method_id": "pm_xxxxxxxxxxxx",
"active": true,
"livemode": false,
"locked": false,
"is_base_currency": false,
"name": "ArcBlock Token",
"description": "The native token of the ArcBlock platform.",
"logo": "https://www.arcblock.io/images/abt-logo.png",
"symbol": "ABT",
"decimal": 18,
"maximum_precision": 8,
"minimum_payment_amount": "0",
"maximum_payment_amount": "10000000000000000000000000000",
"contract": null,
"metadata": {},
"created_at": "2023-10-27T10:00:00.000Z",
"updated_at": "2023-10-27T10:00:00.000Z",
"vault_config": null,
"type": "standard"
}

检索货币#

检索现有支付货币的详细信息。

参数

Name

Type

Description

id

string

必填。 要检索的货币的唯一标识符。

示例

import payment from '@blocklet/payment-js';

async function getCurrency(currencyId) {
try {
const currency = await payment.paymentCurrencies.retrieve(currencyId);
console.log('已检索货币:', currency.name);
} catch (error) {
console.error('检索货币时出错:', error);
}
}

getCurrency('curr_1234567890');

响应示例

{
"id": "curr_1234567890",
"payment_method_id": "pm_xxxxxxxxxxxx",
"active": true,
"livemode": false,
"locked": false,
"is_base_currency": false,
"name": "ArcBlock Token",
"description": "The native token of the ArcBlock platform.",
"logo": "https://www.arcblock.io/images/abt-logo.png",
"symbol": "ABT",
"decimal": 18,
"maximum_precision": 8,
"minimum_payment_amount": "0",
"maximum_payment_amount": "10000000000000000000000000000",
"contract": null,
"metadata": {},
"created_at": "2023-10-27T10:00:00.000Z",
"updated_at": "2023-10-27T10:00:00.000Z",
"vault_config": null,
"type": "standard"
}

更新货币#

通过设置传入参数的值来更新指定的支付货币。任何未提供的参数将保持不变。

参数

第一个参数是要更新的货币的 id。第二个参数是包含要更新字段的对象。

Name

Type

Description

name

string

货币的全名。

description

string

货币的描述。

logo

string

货币徽标的 URL。

active

boolean

货币是否处于活动状态。

minimum_payment_amount

string

最小支付金额。

maximum_payment_amount

string

最大支付金额。

metadata

Record<string, any>

要与货币一同存储的一组键值对。

示例

import payment from '@blocklet/payment-js';

async function updateCurrency(currencyId) {
try {
const currency = await payment.paymentCurrencies.update(currencyId, {
description: 'An updated description for the native token of ArcBlock.'
});
console.log('已更新货币:', currency.description);
} catch (error) {
console.error('更新货币时出错:', error);
}
}

updateCurrency('curr_1234567890');

响应示例

{
"id": "curr_1234567890",
"payment_method_id": "pm_xxxxxxxxxxxx",
"active": true,
"livemode": false,
"locked": false,
"is_base_currency": false,
"name": "ArcBlock Token",
"description": "An updated description for the native token of ArcBlock.",
"logo": "https://www.arcblock.io/images/abt-logo.png",
"symbol": "ABT",
"decimal": 18,
"maximum_precision": 8,
"minimum_payment_amount": "0",
"maximum_payment_amount": "10000000000000000000000000000",
"contract": null,
"metadata": {},
"created_at": "2023-10-27T10:00:00.000Z",
"updated_at": "2023-10-27T11:00:00.000Z",
"vault_config": null,
"type": "standard"
}

列出货币#

返回你的支付货币列表。货币按创建日期排序返回,最新创建的货币排在最前面。

参数

Name

Type

Description

page

number

分页的页码。默认为 1

pageSize

number

每页的项目数。默认为 20

order

string or string[]

结果的排序顺序。示例:['created_at', 'DESC']

示例

import payment from '@blocklet/payment-js';

async function listCurrencies() {
try {
const currencyList = await payment.paymentCurrencies.list({ pageSize: 5 });
console.log(`找到 ${currencyList.length} 种货币:`);
currencyList.forEach(currency => {
console.log(`- ${currency.name} (${currency.symbol})`);
});
} catch (error) {
console.error('列出货币时出错:', error);
}
}

listCurrencies();

响应示例

list 方法返回一个 PaymentCurrency 对象数组。

[
{
"id": "curr_1234567890",
"name": "ArcBlock Token",
"symbol": "ABT",
"active": true,
"livemode": false,
"logo": "https://www.arcblock.io/images/abt-logo.png"
},
{
"id": "curr_abcdefghij",
"name": "Ethereum",
"symbol": "ETH",
"active": true,
"livemode": false,
"logo": "https://example.com/eth_logo.png"
}
]

现在你已经了解如何管理货币,可以探索如何管理它们关联的支付方式或如何在价格中使用它们。