出现条带错误,即使添加了卡,该客户也没有附加的付款来源

时间:2019-10-27 13:38:59

标签: go stripe-payments

我正在尝试使用stripe-go在测试环境中创建订阅,但始终收到This customer has no attached payment source的错误。我明确添加了付款方式,将其附加到客户上,甚至将其设置为默认付款方式,但仍然不断收到该错误。这是我的来源

customerParams := &stripe.CustomerParams{Email: &request.Email}

newCustomer, _ := a.stripeClient.Customers.New(customerParams)


params := &stripe.PaymentMethodParams{
    Type: stripe.String(string(stripe.PaymentMethodTypeCard)),
    Card: &stripe.PaymentMethodCardParams{
        Number:   stripe.String("4242424242424242"),
        ExpMonth: stripe.String("10"),
        ExpYear:  stripe.String("2020"),
        CVC:      stripe.String("123"),
    },
}

p, _ := a.stripeClient.PaymentMethods.New(params)

paymentAttachParams := &stripe.PaymentMethodAttachParams{ Customer: &newCustomer.ID}

a.stripeClient.PaymentMethods.Attach(p.ID, paymentAttachParams)

updateCustomerParams := &stripe.CustomerParams{}
updateCustomerParams.AddMetadata("invoice_settings.default_payment_method", p.ID)
a.stripeClient.Customers.Update(
    newCustomer.ID,
    updateCustomerParams,
)

invoiceParams := &stripe.InvoiceItemParams{
    Customer:    &newCustomer.ID,
    Currency:    stripe.String(string(stripe.CurrencyUSD)),
    Description: stripe.String("One-time setup fee"),
    Amount:      stripe.Int64(100),
}

a.stripeClient.InvoiceItems.New(invoiceParams)

subscriptionParams := &stripe.SubscriptionParams{
    Customer: &newCustomer.ID,
    Items: []*stripe.SubscriptionItemsParams{
        {
            Plan: stripe.String("plan_xxxx"),
        },
    },
}

s, err := a.stripeClient.Subscriptions.New(subscriptionParams)

我还试图与订阅一起增加一次性安装费,但我认为这应该不是问题。

0 个答案:

没有答案