![](/img/trans.png)
[英]How to cancel a customer's subscription in Stripe.net - they update too often
[英]How to create a Stripe Invoice for a connect account on a shared customer
我已經在我的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);
希望這對某人有幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.