首页 文章

如何使用Stripe.com为客户的特定卡充电

提问于
浏览
26

客户对象可以在Stripe.com中拥有许多卡 . 你如何收取现有的卡?

我已经尝试了一些东西,但条纹api由于某种原因borks什么时候得到一个旧的客户令牌和一个新的卡令牌,而不是只是在该客户上创建一张新卡 . 所以我走了检索所有客户卡的路线,然后通过单选按钮选择一个,然后将所选卡的令牌提交到收费中

charge = Stripe::Charge.create(
        :amount => "#{@subscription.price}",
        :currency => "usd",
        :card => params[:existing_card_id],
        :description => "Subscription for #{current_user.email}"
      )

但我得到了错误

Stripe::InvalidRequestError: Invalid token id: card_24j3i2390s9df

2 回答

  • 8

    我想通了 .

    使用现有的卡令牌,您还必须发送客户令牌

    charge = Stripe::Charge.create(
            :amount => "#{@subscription.price}",
            :currency => "usd",
            :customer => current_user.stripe_customer_id,
            :card => params[:existing_card_id],
            :description => "Subscription for #{current_user.email}"
          )
    
  • 41

    这个答案有助于我在PHP中应用相同的解决方案,以便为默认信用卡以外的特定信用卡客户收费 . 这些碎片:

    JSON:

    {
      "charge": {
        "amount":122,
        "currency":"usd",
        "customer":"cus_7hVsgytCc79BL7",
        "card":"card_17SENFJ4sx1xVfmD8skoSjNs"
      }
    }
    

    PHP

    $item = $params->request->getJsonRawBody();
        $new_charge = \Stripe\Charge::create(array(
          "amount" => $this->ConvertAmount($item->charge->amount),
          "currency" => $item->charge->currency,
          "customer" => $item->charge->customer,
          "card" => $item->charge->card
        ));
        return $new_charge;
    

相关问题