事务所 SDK
一个 JavaScript / TypeScript SDK 用于以结构化和类型安全的方式与 Firmhouse GraphQL API 交互.
Firmhouse SDK的设计是为了通过提供完全打入的接口和以有条理的方式处理出错,使开发者更容易与Firmhouse API互动.
特征
- 用 TypeScript 完全打入了 SDK,所以不需要担心字段名称和类型.
- 以自动补全和类型提示提供平滑的IDE体验.
- 以结构化的方式处理错误 .
- 支持 Storefront 和 Write 访问符并基于访问类型限制操作.
- 给予您在回复中包含/排除相关资源的选项,而不写入杂乱的 GraphQL 查询 .
- 支持采用贴现码并计算贴现车总数.
- 提供订阅、订购产品和额外字段的帮助.
- 提供嵌入式的 Adyen 取出, 这样您就可以在自己的存储前端进行支付步骤, 而不是重定向到主机支付页面 .
安装
npm install @firmhouse/firmhouse-sdk
文档
你可以找到SDK的文档 这里。 。 。 .
使用量
import { Access, FirmhouseClient } from '@firmhouse/firmhouse-sdk';
import { assignSubscriptionUtils, calculateCartTotals, mapExtraFieldsByFieldId } from '@firmhouse/firmhouse-sdk/utils';
const apiToken = 'YOUR_PROJECT_ACCESS_TOKEN';
const client = new FirmhouseClient({
apiToken,
});
const { results: products } = await client.products.fetchAll();
const { results: plans } = await client.plans.fetchAll();
const product = await client.products.fetchById('123');
const cartToken = await client.carts.createCartToken();
await client.carts.addProduct(cartToken, {
productId: products[0].id,
quantity: 2,
});
// Apply a discount code and calculate the discounted cart totals.
await client.carts.applyDiscountCode(cartToken, 'WELCOME10');
const cart = await client.carts.get(cartToken, {
appliedPromotions: {
includeRelations: {
promotion: true,
discountCode: true,
},
},
});
const {
payNowSubtotalCents, // Signup amount before discount.
payNowDiscountCents, // Discount applied at signup.
payNowTotalCents, // Signup amount after discount.
monthlySubtotalCents, // Monthly amount before discount.
monthlyDiscountCents, // Discount applied each month.
monthlyTotalCents, // Monthly amount after discount.
} = calculateCartTotals(cart);
await client.carts.removeDiscountCode(cartToken);
const writeAccessApiToken = 'YOUR_PROJECT_ACCESS_TOKEN_WITH_WRITE_ACCESS';
const writeAccessClient = new FirmhouseClient({
apiToken: writeAccessApiToken,
accessType: Access.write,
});
const project = await writeAccessClient.projects.getCurrent({
extraFields: true,
promotions: true,
taxRates: true,
});
const invoices = await writeAccessClient.invoices.fetchAll();
await client.selfServiceCenterToken.create('[email protected]', 'https://myapp.com/ssc/token-login');
const selfServiceCenterLoginToken = 'TOKEN_RECEIVED_FROM_THE_LOGIN_LINK';
const subscription = await writeAccessClient.subscriptions.getBySelfServiceCenterLoginToken(selfServiceCenterLoginToken);
const subscriptionWithUtils = assignSubscriptionUtils(subscription);
const upcomingOrderDate = subscriptionWithUtils.getClosestUpcomingOrderDate();
const upcomingOrderProducts = subscriptionWithUtils.getClosestUpcomingOrderOrderedProducts();
const extraFieldsById = mapExtraFieldsByFieldId(subscription.extraFields);
const extraFieldAnswer = extraFieldsById['EXTRA_FIELD_ID'];
calculateCartTotals 多次使用最大活动升级
晋级是存在的;晋级不堆叠. 贴现额在
小计,不包括运费.
内嵌 Adyen 报到
Adyen 工程可以在您的商店前端实现支付步骤 阿迪恩网络
下潜 改为
发送客户到主机支付页面. client.payments 返回浏览器安全
会话配置,帮助者将其转换为 Drop-in期望的选项.
安装 @adyen/adyen-web 自己; SDK 不依赖它.
import { AdyenCheckout, Dropin } from '@adyen/adyen-web';
import { buildAdyenCheckoutOptions, buildAdyenDropinOptions, resolveAdyenCheckoutEntry } from '@firmhouse/firmhouse-sdk/utils';
const entry = resolveAdyenCheckoutEntry(new URLSearchParams(window.location.search));
let paymentToken = sessionStorage.getItem(`paymentToken:${cartToken}`);
// The customer is back from a redirect, so the payment is already with Adyen.
if (entry.mode === 'redirect' && paymentToken) {
const status = await client.payments.waitForCheckoutStatus(cartToken, paymentToken);
if (status.paymentStatus === 'PAID' && status.successUrl) {
window.location.assign(status.successUrl);
return;
}
// The payment was refused or expired. It is reopened, so Drop-in can be mounted again.
}
if (!paymentToken) {
// `payment` is null when the checkout has nothing to pay for.
const { payment } = await client.carts.createSubscription(cartToken, 'https://myshop.com/checkout', 'https://myshop.com/thanks');
if (!payment) return;
paymentToken = payment.token;
sessionStorage.setItem(`paymentToken:${cartToken}`, paymentToken);
}
const session = await client.payments.createAdyenSession(cartToken, paymentToken);
const checkout = await AdyenCheckout(buildAdyenCheckoutOptions(session));
new Dropin(checkout, buildAdyenDropinOptions(session)).mount('#dropin-container');
IDEAL、Ban Contact和3D安全挑战等支付方法将客户带到
另一页,Adyen 返回到您的报到 sessionId 财务报告和审定财务报表
redirectResult 查询参数. resolveAdyenCheckoutEntry 检测到 读取
重定向返回时,先确定结果:
经常在客户回来之前登陆的网游, 无法创建会话
已经支付的款项.
保持支付符从 createSubscription 某处能活过转机,
例如 sessionStorage。不要在重定向返回时再次完成推车:一旦
支付, createSubscription 不再返回它,所以没有标志
读取结果.
要比 Webhook 更快地向浏览器报告结果,你可以将结果交给 当支付尚未打开时, 结果返回 Adyen :
const checkout = await AdyenCheckout(buildAdyenCheckoutOptions(session, entry));
checkout.submitDetails({ details: { redirectResult: entry.redirectResult } });
请求同一付款的会话再次返回仍在运行的会话, 所以重新装入取出页面 使客户保持同样的付款, 和拒绝 付款可以重新审理.
全体 client.payments 方法需要存储前置访问符和订阅符
检查. buildAdyenDropinOptions 映射卡片、 PayPal 和 Google 付费设置
,因此,需要持卡人姓名等设置适用于您的退出
无需硬编码
会话存储支付方法。 将您的演示文稿选项合并到结果中
样式 Drop- in.