发送经身份验证的客户信息
要对客户档案进行身份验证,您的后端服务器必须进行两个独立的 API 调用,我们建议并行运行以获得更好的性能:
-
createCart:生成 Zonos 购物车。如需详细指导,请参阅自定义集成文档中的设置 Zonos Checkout 部分。 -
checkoutCustomerProfileAuthenticate:提交并验证客户的信息。
mutation checkoutCustomerProfileAuthenticate($input: CheckoutCustomerProfileAuthenticateInput!) { checkoutCustomerProfileAuthenticate(input: $input) { email customerId organizationId name phone locations { administrativeArea countryCode locality line1 line2 postalCode } oneTimePassword }}验证客户会话时,请确保您在请求中传递的 customerId 与正确的档案相匹配,以在结账时显示准确的客户信息。请注意,创建购物车时,不应在元数据中包含 customerId,因为它将被覆盖。
客户通过身份验证并下单后,在通过订单查询检索订单详情时,customerId 将在 order.references 中可用,允许您将订单与正确的客户相关联。
使用客户档案创建购物车
调用这两个变更后,您将获得以下内容:
-
来自
createCart变更的cartId以生成购物车。 -
来自
checkoutCustomerProfileAuthenticate变更的oneTimePassword,用于客户身份验证。
您可以在 Zonos.init 函数中的 createCartId 回调中传递这两个值,以在 Checkout 中加载所提供的客户档案信息。
Zonos.init({ ... checkoutSettings: { ... createCartId: async () => { const result = await fetch( 'https://api.merchant.com/api/get-cart-info', { body: JSON.stringify(payload), method: 'POST', }, ); const json = await result.json(); return { cartId: json.cartId, customerAuthenticationToken: json.customerProfileAuthenticate ?.checkoutCustomerProfileAuthenticate.oneTimePassword || '', }; } },}管理客户档案
第一次提交客户信息时,Zonos 将存储提供的客户信息。付款方式将安全地存储在 Stripe 中。每次传递新的地址或付款方式详情时,它们将被添加到客户的档案中。
地址和付款方式只能被添加——现有的无法编辑或删除。客户的姓名、邮箱和电话可以通过 checkoutCustomerUpsert 进行更新。
在没有购物者的情况下创建或更新档案
checkoutCustomerProfileAuthenticate 需要购物者在场,因为它会为该结账会话签发一次性密码。当您想在结账之外创建或更新档案时——例如提前加载您的客户列表、从您自己的系统同步档案变更,或在客户首次下单前附加免税信息——请改用 checkoutCustomerUpsert。
mutation checkoutCustomerUpsert($input: CheckoutCustomerProfileInput!) { checkoutCustomerUpsert(input: $input) { customerId email name phone locations { administrativeArea countryCode line1 line2 locality postalCode } }}档案通过 customerId 进行匹配,因此重复调用会更新同一个档案,而不会创建重复项。您可以安全地按计划对整个客户列表运行此操作。
关于更新如何生效,有三点需要了解:
- 省略的字段保持不变。 仅发送
name只会更新姓名,邮箱和电话保持原样。 - 值无法被清空。 发送空值与省略该字段效果相同,因此一旦设置了姓名、邮箱或电话,就无法将其移除。
- 地址仅会被添加。 档案中已存在的地址不会被重复添加,请求中未包含的地址也不会被移除。
客户档案
将重复购物者信息预加载到 Zonos Checkout 中。客户档案通过允许拥有帐户的客户预加载其地址和付款详情,简化了您的结账体验。
此功能当前仅适用于自定义 API 集成。该功能尚未可供使用 Checkout 插件的商家使用。
如果您向经销商、政府机构或非营利组织销售商品,还可以将其免税证书同步到客户档案。