支付按钮

Commerce Kit 目前处于测试阶段。API 可能会在正式发布前发生变动。关于 Commerce Kit 的更多信息,请参阅Commerce Kit 文档

来自 Commerce KitPaymentButton 组件,提供了完整的支付界面——开箱即用地处理钱包连接、代币选择、交易处理和 UI 状态。

安装

pnpm add @solana-commerce/kit

基本用法

import { PaymentButton } from "@solana-commerce/kit";
function Checkout() {
return (
<PaymentButton
config={{
merchant: { name: "My Store", wallet: "your-wallet-address" },
mode: "buyNow"
}}
paymentConfig={{
products: [{ id: "item-1", name: "Coffee", price: 5.0, quantity: 1 }]
}}
onPaymentSuccess={(signature) => {
console.log("Payment confirmed:", signature);
}}
/>
);
}

欢迎访问 Commerce Kit Playground 配置和测试该组件。

打赏按钮

打赏按钮打赏按钮

支付弹窗

支付弹窗支付弹窗

Solana Pay 二维码弹窗

Solana Pay 二维码弹窗Solana Pay 二维码弹窗

支付模式

mode 选项决定了按钮的行为:

模式描述
buyNow单一商品购买,金额固定
cart购物车,支持多商品
tip用户自定义金额(捐赠/打赏)

配置

必填配置

属性类型描述
merchant.namestring结账时显示的商户名称
merchant.walletstring用于接收付款的 Solana 钱包地址
mode'buyNow' | 'cart' | 'tip'支付流程类型

可选配置

属性类型描述
network'mainnet' | 'devnet'Solana 网络(默认值:'mainnet'
rpcUrlstring自定义 RPC 节点
allowedMintsstring[]通过 mint 地址限制可接受的代币
showQRboolean启用二维码支付选项
themeThemeConfig外观自定义(颜色、圆角等)

支付配置

对于 buyNowcart 模式,请通过 paymentConfig 提供产品:

paymentConfig={{
products: [
{ id: '1', name: 'T-Shirt', price: 25, quantity: 2 },
{ id: '2', name: 'Hoodie', price: 45, quantity: 1 }
]
}}

事件回调

回调函数参数描述
onPaymentSuccess(signature: string)交易已在链上确认
onPaymentError(error: Error)支付在任意阶段失败
onPaymentStart()支付流程已启动
onCancel()用户已取消支付

自定义触发器

用你自己的元素替换默认按钮:

<PaymentButton
config={{
merchant: { name: "Shop", wallet: "address" },
mode: "buyNow"
}}
paymentConfig={{
products: [{ id: "1", name: "Product", price: 10, quantity: 1 }]
}}
>
<button className="my-custom-button">Pay with Solana</button>
</PaymentButton>

Is this page helpful?

Table of Contents

Edit Page

管理者

©️ 2026 Solana 基金会版权所有
取得联系