【问题标题】:How to create a Stripe Invoice for a connect account on a shared customer如何为共享客户的连接帐户创建条纹发票
【发布时间】:2019-12-25 15:42:39
【问题描述】:

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

connect 帐户向客户提供服务,现在将向客户开具付款发票 - 我正在使用 Stripe Invoice 功能。

但是,即使在按照示例将连接帐户与客户帐户关联之后,我仍然收到错误“没有这样的客户: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;
        }

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

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

谢谢

【问题讨论】:

    标签: asp.net-mvc stripe-payments


    【解决方案1】:

    在登录并使用 Stripe Support 发出问题后,他们为我提供了答案。

    要解决此问题,请连接帐户

    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);
    

    希望这对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 2017-12-03
      • 1970-01-01
      • 2022-06-10
      • 1970-01-01
      • 2018-09-30
      • 2019-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多