dthhlf1777 2019-08-19 08:20
浏览 4

使用客户来源时,条纹收费失败

I'm trying to charge a customer with one of the stored credit cards. I'm passing the customer id in the request and I'm getting the customer info from Stripe just fine. The problem is when trying to make the charge to one of the customer sources the library returns an error Must provide source or customer. I checked the sc.Sources.Data[1] (its hardcoded here just for this example) and it has an actual cutsomer source. Can anyone tell me what I'm doing wrong?

EDIT: If I use a tok_1212321 token it works fine, but I don't find a way to retrieve the token id from stripe, only the cliente sources.

stripe.Key = os.Getenv("STRIPE_KEY")
sc, _ := stripeCustomer(request)

params := &stripe.ChargeParams{
    Amount:      stripe.Int64(int64(order.total * 100)),
    Currency:    stripe.String(string(stripe.CurrencyUSD)),
    Description: stripe.String("Order Number " + order.ID),
}

params.SetSource(sc.Sources.Data[1])

if _, err := charge.New(params); err != nil {
    return nil, err
}
  • 写回答

1条回答 默认 最新

  • dow5001 2019-08-19 08:48
    关注

    OK, so what I was missing is the Customer id. When doing a Charge both IDs have to be given.

    params := &stripe.ChargeParams{
        Amount:      stripe.Int64(int64(order.total * 100)),
        Currency:    stripe.String(string(stripe.CurrencyUSD)),
        Description: stripe.String("Order Number " + order.ID),
        Customer:    stripe.String(sc.ID),
    }
    
    params.SetSource(sc.Sources.Data[1].ID)
    
    if _, err := charge.New(params); err != nil {
        return nil, err
    }
    

    This code makes it work.

    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序