Skip to main content
本页列出 Payment Element 的全部公开属性、方法、事件和取值。接入步骤见 Element 集成。

初始化

new WaffoSDK(clientApiKey, options)

sdk.createElements(sessionId, options?)

返回 Elements。sessionId 为空时抛出 SDK_INVALID_SESSION_ID。

Elements

同一个 session 下所有组件的集合。

create 的 type

分组和支付方式不能混在同一个数组里。

create 的 options

confirmPayment

elements.confirmPayment(element?, options?) 以下情况会 reject:

PaymentElement

CustomPaymentElement

在 PaymentElement 的基础上增加:

事件

ElementState

phase 取值

phase 为 ready 或 error 时才可以调用 confirmPayment()。

ElementPayMethod

RequiredField

组件只校验必填和选项取值,不提供邮箱、手机号等格式校验,你可以在前端自行补充。

ElementError

PaymentResult

confirmPayment() 的返回值和 payment 事件的载荷。 用 'sessionType' in data 区分订阅和订单。

PaymentOrderData

PaymentSubscriptionData

Appearance

createElements 的 appearance 和 updateAppearance() 的参数。

AppearanceVariables

所有字段均可选。颜色使用 CSS 颜色值,尺寸使用带单位的字符串(如 8px)。
Apple Pay、Google Pay 按钮由厂商渲染,只有黑白两种样式,不受 colorPrimaryForeground、buttonVariant 和 rules 影响。

SpacingConfig

variables.spacing,组件内的间距:
取值为非负的 px、rem 或 em,其他值按默认值处理。

AppearanceRules

appearance.rules,用 CSS 声明单独调整某类组件的样式,写法参考 Stripe Appearance API。键是下表的选择器,值是一组 CSS 声明,可以写成对象(属性名用驼峰或连字符均可),也可以写成 CSS 声明字符串:
基础选择器的规则不会覆盖组件自带的报错、禁用和选中样式;要改这些状态,请用对应的状态选择器。 输入框的高度、内边距、字重和字号都可以用 .Input 调整;height 不能直接写,可以用上下 padding 调整高度。
  • 属性:任意 CSS 属性,但不能改布局或可见性:position、top / right / bottom / left、inset*、z-index、display、visibility、content、width / height(含 min- / max-,.PayMethodLogo 除外)、margin*、float、clear、overflow*、transform*、translate、rotate、scale、clip*、mask*、pointer-events、all,以及自定义属性(--*)。
  • 值:数字、单位、颜色、关键字,以及 rgb()、rgba()、hsl()、hsla()、calc()、min()、max()、clamp()。可以用 var(--colorText) 引用颜色变量,或用 rgb(var(--colorText) / 0.06) 加透明度。可引用的变量:colorPrimary、colorPrimaryForeground、colorBackground、colorCard、colorText、colorTextSecondary、colorTextTertiary、colorBorder、colorDanger。
  • 不能写:url() 等其他函数、引号、!important,以及值里的 ;、{、}。
不符合要求的声明会被忽略,组件会在浏览器控制台输出被忽略的内容和原因([appearance] rules …)。

ElementLayout

只影响非卡支付方式按钮的排列;卡表单和需要填写信息的支付方式始终整行展示。 容器较窄时,点击即跳转的支付方式按钮文字不换行、放不下时显示省略号,按钮宽度不足 96px 时只显示图标;Apple Pay、Google Pay 按钮有钱包方要求的最小宽度。

错误码

由 SDK 定义,在浏览器中由 SDK 或组件代为抛出,不会由接口返回。