如何为共享客户的连接账户创建条纹发票



我已经在我的 Stripe 平台账户上成功创建了一个客户。现在,我想从我的一个连接帐户为该客户创建发票。

Connect 账户向客户交付了服务,现在将向客户开具付款发票 - 我正在使用 Stripe 发票功能。

但是,即使在以下示例将连接帐户与客户帐户相关联之后,我也会收到错误"没有此类客户:cus_XXXX"。

我已按照 https://stripe.com/docs/connect/shared-customers#making-tokens 为我的平台客户创建了一个令牌,然后使用该令牌创建了连接帐户客户,如 https://lorenzosfarra.com/2017/09/19/stripe-shared-customers/所示,但仍然收到相同的错误消息。 即使看起来连接帐户引用已成功创建 - 由于没有返回任何错误,因此找不到生成的客户 ID。

这是我的创建发票方法

public static async Task<string> CreateCustomerInvoice(string secretKey, string customerId, TenantBillHeaderModel billHeader)
{
StripeConfiguration.ApiKey = secretKey;
var fees = await Database.GetAdminFees();
var salesTax = await Database.GetCountrySalesTax(13);// Hardcoded for launch
var billLines = await Database.GetTenantBillDetailForHeaderId(billHeader.TenantBillHeaderId);
var stripeContact = await Database.GetStripeContact(UserInfo.Instance.Organisation.OrganisationId);
InvoiceItemCreateOptions invoiceItemOptions = null;
// Find Fee Percentage
var tFee = billHeader.GrossAmount * (fees.FirstOrDefault(f => f.AdminFeeId == (int)Persistence.Enums.AdminFeeEnum.ConnectCut)).Percentage / 100;
// Create token so that customer can be shared with Connect account - See https://stripe.com/docs/connect/shared-customers
var customerTokenId = await CreateCustomerToken(secretKey, customerId, stripeContact.StripeConnectToken);
//Associates customer with connect account so that it is shared with platform account
var connectCustId = await CreateCustomerInConnectAccount(secretKey, customerTokenId, stripeContact.StripeConnectToken);
foreach (var l in billLines)
{
invoiceItemOptions = new InvoiceItemCreateOptions
{
Quantity = l.Quantity,
UnitAmount = Convert.ToInt64(l.Amount * 100), // Converting to cents for Stripe
Currency = "aud", // Hardcoded for launch
CustomerId = connectCustId,
Description = l.Name + " (" + l.Description + ")",
TaxRates = new List<string> {
salesTax.StripeTaxRateId
},
};
var itemService = new InvoiceItemService();
InvoiceItem invoiceItem = await itemService.CreateAsync(invoiceItemOptions);
}
var invoiceOptions = new InvoiceCreateOptions
{
CustomerId = connectCustId,
AutoAdvance = false, // do not auto-finalize this draft after ~1 hour
CollectionMethod = "send_invoice", // Stripe will progress the a send state. However it will not email as this is trurned off in portal https://stripe.com/docs/billing/invoices/customizing
ApplicationFeeAmount = Convert.ToInt64(tFee),
Description = "Invoice for Advizr Bill: " + billHeader.BillNumber,
DueDate = billHeader.DueDate
};
var service = new InvoiceService();
Invoice invoice = await service.CreateAsync(invoiceOptions);
return invoice.Id;
}

在这里我创建一个客户令牌

public static async Task<string> CreateCustomerToken(string secretKey, string customerId, string stripeContactId)
{
StripeConfiguration.ApiKey = secretKey;
RequestOptions requestOptions = null;
var options = new TokenCreateOptions
{
CustomerId = customerId,
};
if (stripeContactId != null)
{
requestOptions = new RequestOptions
{
StripeAccount = stripeContactId
};
}
var service = new TokenService();
Token token = await service.CreateAsync(options, requestOptions);
return token.Id;
}

在这里,我创建/将客户与连接帐户关联

public static async Task<string> CreateCustomerInConnectAccount(string secretKey, string customerToken, string connectAccount)
{
StripeConfiguration.ApiKey = secretKey;
var options = new CustomerCreateOptions
{
Source = customerToken
};
var requestOptions = new RequestOptions
{
StripeAccount = connectAccount
};
var service = new CustomerService();
Customer customer = await service.CreateAsync(options, requestOptions);
return customer.Id;
}

有关如何为共享客户创建发票(存在于平台帐户中并与连接帐户关联(的任何指导将不胜感激。

然后,客户将支付发票,我将在扣除申请费后使用目的地支付连接帐户。

谢谢

在登录并遇到 Stripe 支持问题后,他们为我提供了答案。

要解决此问题,连接帐户

var requestOptions = new RequestOptions
{
StripeAccount = stripeContact.StripeConnectToken
};

必须在创建发票行项时提供

var itemService = new InvoiceItemService();
InvoiceItem invoiceItem = await itemService.CreateAsync(invoiceItemOptions, requestOptions);

以及创建发票时。

var service = new InvoiceService();
Invoice invoice = await service.CreateAsync(invoiceOptions, requestOptions);

希望这对某人有所帮助。

最新更新