客户没有带 ID 的链接源

Customer does not have linked source with id

我在查看条带测试交易时不断收到以下错误:

{
  "error": {
    "type": "invalid_request_error",
    "message": "Customer cus_9tW8Cf0Xvm9lRv does not have a linked source with ID tok_19Zj5rAANnhOmz4ex3ri2jtW.",
    "param": "source",
    "code": "missing"
  }
}

我的swift调用api的代码如下:

    @IBAction func payButtonWasPressed() {
        stripeCard = STPCardParams()

        let expirationDate = self.cardExpiryTextField.text!.components(separatedBy: "/")
        let expMonth = UInt(expirationDate[0])
        let expYear = UInt(expirationDate[1])

        stripeCard.number = self.cardNumberTextField.text
        stripeCard.cvc = self.cardCVVTextField.text
        stripeCard.expMonth = expMonth!
        stripeCard.expYear = expYear!

        STPAPIClient.shared().createToken(withCard: stripeCard, completion: { (token, error) -> Void in

            if error != nil {
                self.handleError(error! as NSError)
                return
            } 

            self.chargeUsingToken(token!)
        })
    }

    func handleError(_ error: NSError) {
        UIAlertView(title: "Please Try Again",
                    message: error.localizedDescription,
                    delegate: nil,
                    cancelButtonTitle: "OK").show()

    }

    func chargeUsingToken(_ token: STPToken) {

        let URL = "https://splitterstripeserver.herokuapp.com/charge"
        let params = ["source": token.tokenId,
                      "stripe_token": token.tokenId,
                      "amount": total] as [String : Any]

        let manager = AFHTTPSessionManager()
        manager.post(URL, parameters: params, success: { (operation, responseObject) -> Void in

            if let response = responseObject as? [String: String] {
                UIAlertView(title: response["status"],
                    message: response["message"],
                    delegate: nil,
                    cancelButtonTitle: "OK").show()
            }

        }) { (operation, error) -> Void in
            self.handleError(error as NSError)
        }
    }

我正在使用 stripe github

上的示例后端

在我的应用程序上,我收到一个弹出窗口,提示请求失败:需要付款 (402)。我尝试了很多不同的东西,但似乎无法获得成功的回应。我看不出我做错了什么,需要一双新的眼睛。任何帮助都会很棒。谢谢

使用 Stripe Checkout or Stripe.js, you send it to your server where you use it to create a customer via the API. That card becomes "saved" with that customer and you can then charge it in the future. If you want to add another card to the same customer you would use the Create Card API 创建卡片标记后,传递新标记并添加该卡片。

创建charge时,您在customer参数中传递客户ID(cus_XXX)以向默认卡收费。如果您想对特定的卡收费,您可以在 source 参数中与客户一起传递卡 ID (card_YYY)。

目前,您正在尝试传递不受支持的客户 ID 和卡令牌。您需要先将该卡保存在客户身上,然后如上所述在 source 参数中传递新卡 ID。