条纹付款:获取错误,因为客户cus _*****没有带ID ID的链接卡_*****

Sre*_*ree 41 javascript php payment jquery stripe-payments

在测试模式下,当我创建新客户并尝试付款时,我收到此错误.

客户cus_7Zz2BCnybIZLGw没有ID为tok_17Kp8GAwLkQPB7OqrrM73VVI的链接卡

我使用卡号:4242424242424242 exp_month:12 exp_year 2016

回复是,

Array
(
    [charge_status] => 
    [error_info] => Array
        (
            [type] => invalid_request_error
            [message] => Customer cus_7Zz2BCnybIZLGw does not have a linked card with ID tok_17Kp8GAwLkQPB7OqrrM73VVI.
            [param] => card
            [code] => missing
        )

    [message] => Customer cus_7Zz2BCnybIZLGw does not have a linked card with ID tok_17Kp8GAwLkQPB7OqrrM73VVI.
)
Run Code Online (Sandbox Code Playgroud)

输入费用数据是,

 $customer = Stripe_Customer::create(array(
      'account_balance' => 100,
      'source' => $token,
      'email' => strip_tags(trim($email))
    )
  );

$customer_id = $customer->id;

$charge   = array(
                'card'          => 4242424242424242, 
                'amount'        => 100, 
                'currency'      => 'cad', 
                'receipt_email' => test@test.com,
                'description'   => 'my payment',
                'customer'      => $customer_id
              );
Run Code Online (Sandbox Code Playgroud)

Ywa*_*ain 87

创建费用有三种不同的方式:

  • source仅使用参数.在这种情况下,source需要是令牌 ID(由CheckoutStripe.js创建),即以tok_或开头的字符串src_.

  • customer仅使用参数.在这种情况下,customer需要是客户 ID,即以字母开头的字符串cus_.将收取客户的默认付款来源.

  • 同时与customersource参数.在这种情况下,customer需要像上一种情况一样是客户ID,但source应该是已经附加到客户的支付来源的ID.付款来源可以是(ID开头card_),银行帐户(ID开头ba_)或来源(ID开头src_).

在您的情况下,您将在source参数中传递令牌ID以及参数中的客户ID customer.

如果这是新卡,您应首先使用令牌在客户上创建卡,然后使用卡ID创建费用.如果该卡已经为该客户保存,则您不需要再次收集卡信息(因此根本不需要创建令牌).

  • @emkman:我想您每次都可以使用Apple Pay创建新令牌,将令牌附加到现有客户对象,使用客户对象创建费用,然后从Apple Pay令牌中删除该卡.这样,您就可以使用Apple Pay对每笔交易进行身份验证,并在客户对象上保留收费历史记录. (2认同)
  • @IonicBurger OP在“ customer”参数中提供了一个客户ID,在“ source”参数中提供了一个令牌ID。同时提供“客户”和“来源”参数时,“来源”必须是卡ID。如果`source`是一个令牌ID,则不应该传递`customer`参数。 (2认同)

小智 7

这段代码对我有帮助。它也可能对你有帮助。

Stripe\Stripe::setApiKey(env('STRIPE_SECRET'));

$customer = \Stripe\Customer::create([
    'name' => 'Jenny Rosen',
    'email' => 'jenyy@hotmail.co.us',
    'address' => [
        'line1' => '510 Townsend St',
        'postal_code' => '98140',
        'city' => 'San Francisco',
        'state' => 'CA',
        'country' => 'US',
    ],
]);

\Stripe\Customer::createSource(
    $customer->id,
    ['source' => $request->stripeToken]
);

Stripe\Charge::create ([
    "customer" => $customer->id,
    "amount" => 100 * 100,
    "currency" => "usd",
    "description" => "Test payment from stripe.test." , 
]);
Run Code Online (Sandbox Code Playgroud)