在没有 JS 的情况下执行 Stripe 事务以检索令牌

Perform a Stripe transaction without JS to retrieve token

我正在尝试在不使用 Javascript 的情况下执行条带化交易。可能是 cURL,但我无法使用 v2 api.

找出 header
<form action="" method="POST" id="payment-form">
  <span class="payment-errors"></span>

  <div class="form-row">
    <label>
      <span>Card Number</span>
      <input type="text" size="20" data-stripe="number"/>
    </label>
  </div>

  <div class="form-row">
    <label>
      <span>CVC</span>
      <input type="text" size="4" data-stripe="cvc"/>
    </label>
  </div>

  <div class="form-row">
    <label>
      <span>Expiration (MM/YYYY)</span>
      <input type="text" size="2" data-stripe="exp-month"/>
    </label>
    <span> / </span>
    <input type="text" size="4" data-stripe="exp-year"/>
  </div>

  <button type="submit">Submit Payment</button>
</form>



<?php
require '../stripe-php/init.php';

//this next line is very wrong
$post = 'client_secret=['sk_07C5ukIdqx'].'&grant_type=authorization_code&code='.$_GET['code'];
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $system['stipe']['token_url']);
curl_setopt($ch,CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);

$decode = json_decode($result);

\Stripe\Stripe::setApiKey("my_secret");
\Stripe\Charge::create(array(
    "amount" => 500,
    "currency" => "usd",
    "source" => $decode[2], // I am totally guessing the value will be in element #2
   "description" => "Charge for test@example.com"
 ));
?>

我的大部分问题是获取令牌。所有的条纹文档只使用 stripe.js 而我没有使用 javascript.

如何在不使用 Javascript 的情况下将条带令牌放入 PHP 变量中,以便我可以将其用于基本交易?

使用 stripe.js 时,Stripe 不要求您的服务器符合 PCI 标准。

如果您有接受信用卡数据的 Web 表单,您希望卡片令牌由 Stripe 创建。信用卡信息绝不会通过网络发送到您的服务器。这就是为什么您的代码中的表单字段没有 name 属性(不提交无名称字段)。 这是好事。

如果坚持不使用stripe.js,API docs on creating a charge明确说明

the source you provide must either be a token, like the ones returned by Stripe.js, or a associative array containing a user's credit card details

'amount'   => 200, // .00,
'currency' => 'usd',
'source'   => [
    'object'    => 'card',
    'number'    => '...'
    'exp_month' => '...',
    'exp_year'  => '...',
    'cvc'       => '...',
]

删除 stripe.js,在您的表单上放置一些 name 属性,并使用 Charge::create() 方法而不使用所有前面的 curl 内容。

我必须提一下,如果我不清楚使信用卡处理变得非常简单的 API 的基础知识,我会 非常 担心有多少我让信用卡数据接触我的服务器,从而使自己面临潜在的诉讼。