如何通过Xero API为发票配置在线支付选项?
可以通过Xero API设置在线支付选项
要在API创建的发票中开启在线支付(比如绑定Stripe),你需要在请求的invoiceData里添加OnlineInvoice对象,指定启用在线支付并关联对应的支付服务ID。
关键修改步骤:
添加OnlineInvoice字段
在你的invoiceData对象中加入以下结构:"OnlineInvoice": { "EnableOnlinePayment": true, "PaymentServiceID": "你的Stripe支付服务ID" }EnableOnlinePayment设为true即可开启在线支付选项PaymentServiceID是你在Xero后台配置的Stripe支付服务的唯一ID,可通过调用Xero的PaymentServicesAPI获取(路径:https://api.xero.com/api.xro/2.0/PaymentServices)
修改后的完整代码
把上述字段整合到你的Google Apps Script代码中,修改后的invoiceData如下:var invoiceData = { "Type": "ACCREC", "BrandingThemeID": data.branding, "Contact": { "Name": data.clientName }, "Date": new Date(data.issueDate).toISOString().slice(0, 10), "DueDate": new Date(data.dueDate).toISOString().slice(0, 10), "Reference": data.clientReference, "LineItems": [ { "ItemCode": data.item, "Quantity": data.quantity, "UnitAmount": data.amount, } ], // 新增在线支付配置 "OnlineInvoice": { "EnableOnlinePayment": true, "PaymentServiceID": "替换为你的支付服务ID" } };
注意事项
- 确保你的Xero账户已经配置好对应的支付服务(比如Stripe),否则
PaymentServiceID无效 - 调用
PaymentServicesAPI时需要使用和创建发票相同的授权头信息,返回结果中每个支付服务会包含其PaymentServiceID
内容的提问来源于stack exchange,提问作者Rafa Guillermo
相关产品推荐
相关产品推荐

