尽管附加了付款详细信息,但条带付款不完整?

Posted

技术标签:

【中文标题】尽管附加了付款详细信息,但条带付款不完整?【英文标题】:Stripe payment incomplete despite payment details being attached? 【发布时间】:2021-12-31 03:59:57 【问题描述】:

使用测试数据,我可以创建客户并附加付款方式,但我的所有订阅都处于这种状态。这是我目前创建订阅的代码:

// StripeCreateSubscription create a new subscription with fixed price for user
func StripeCreateSubscription(w http.ResponseWriter, r *http.Request) 
    if r.Method != "POST" 
        SendResponse(w, utils.MakeError("you can only POST to the stripe create customer route"), http.StatusMethodNotAllowed)
        return
    

    // Decode the JSON payload
    type requestPayload struct 
        PaymentMethodID string `json:"paymentMethodId"`
        PriceID         string `json:"priceId"`
    

    var payload requestPayload
    if err := json.NewDecoder(r.Body).Decode(&payload); err != nil 
        sendSystemError(w, fmt.Errorf("decode request payload: %v", err))
        return
    

    // Get the user from the context of who made the request
    uid := r.Context().Value("user_id").(int)

    u := models.User
    if err := u.FindByID(uid); err != nil 
        sendSystemError(w, fmt.Errorf("find user by id: %v", err))
        return
    
    if u.StripeCustomerID == "" 
        sendSystemError(w, errors.New("no customer for the user"))
        return
    

    // Attach the payment method to the customer
    paymentParams := &stripe.PaymentMethodAttachParams
        Customer: stripe.String(u.StripeCustomerID),
    

    pm, err := paymentmethod.Attach(
        payload.PaymentMethodID,
        paymentParams,
    )

    if err != nil 
        sendSystemError(w, fmt.Errorf("attaching payment method failed: %v", err))
    

    // Check if the user has any active subscriptions, and cancel the others if they're adding one.
    listParams := &stripe.SubscriptionListParams
        Customer: u.StripeCustomerID,
        Status:   "all",
    
    listParams.AddExpand("data.default_payment_method")

    iter := sub.List(listParams)
    subscriptions := iter.SubscriptionList().Data
    if len(subscriptions) > 0 
        Log.Info(fmt.Sprintf("%v subscriptions found for %v. Cancelling...", len(subscriptions), u.Username))
        for i := 0; i < len(subscriptions); i++ 
            if subscriptions[i].Status != "canceled" && subscriptions[i].Status != "incomplete_expired" 
                Log.Info(fmt.Sprintf("Cancelling %v. Status %v", subscriptions[i].ID, subscriptions[i].Status))
                subscription, err := sub.Cancel(subscriptions[i].ID, nil)
                if err != nil 
                    sendSystemError(w, fmt.Errorf("cancel subscription: %v", err))
                    return
                
                Log.Info(fmt.Sprintf("Cancelled %v", subscription.ID))
            
        
        Log.Info("Old subscriptions cancelled.")
        time.Sleep(5 * time.Second)
    

    // Create subscription
    subscriptionParams := &stripe.SubscriptionParams
        Customer: stripe.String(u.StripeCustomerID),
        Items: []*stripe.SubscriptionItemsParams
            
                Price: stripe.String(payload.PriceID),
            ,
        ,
        PaymentBehavior:      stripe.String("default_incomplete"),
        DefaultPaymentMethod: stripe.String(payload.PaymentMethodID),
    
    subscriptionParams.AddExpand("latest_invoice.payment_intent")
    newSub, err := sub.New(subscriptionParams)
    if err != nil 
        sendSystemError(w, fmt.Errorf("new subscription: %v", err))
        return
    

    // If everything looks good, then send some info back to the user
    output := map[string]interface
        "subscriptionId": newSub.ID,
        "clientSecret":   newSub.LatestInvoice.PaymentIntent.ClientSecret,
    
    SendResponse(w, output, 200)

我需要做什么才能让我的订阅完成付款?

【问题讨论】:

【参考方案1】:

使用default_incomplete(如fixed-price subscription guide 所示)在您创建订阅时明确保持初始发票无人尝试。要完成设置,您需要从应用程序的客户端使用该客户端密码 confirm the payment with the Payment Element(或 with the Card Element)。您似乎已经将client_secret 发回了,您在使用它吗?

【讨论】:

以上是关于尽管附加了付款详细信息,但条带付款不完整?的主要内容,如果未能解决你的问题,请参考以下文章

客户未在 wix 网站上输入付款方式的条带错误

使用附加卡对客户进行条带化,但没有默认付款方式

条纹结帐后如何生成收据页面

存储客户付款详细信息 - PCI 合规性

如何保存用户卡详细信息并稍后在 PayPal 中付款?

嗨,我通过 paypal omnipay 发送卡详细信息。付款显示成功但未出现在贝宝中