Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 刷卡结账_Php_Jquery_Stripe Payments - Fatal编程技术网

Php 刷卡结账

Php 刷卡结账,php,jquery,stripe-payments,Php,Jquery,Stripe Payments,我有一个非常好用的代码 <input class="form-control" type="number" id="custom-donation-amount" placeholder="50.00" min="0" value="50" step="10.00"/> <script src="https://checkout.stripe.com/checkout.js"></script> <button id=

我有一个非常好用的代码

<input class="form-control"
   type="number"
   id="custom-donation-amount"
   placeholder="50.00"
   min="0"
   value="50"
   step="10.00"/>
<script src="https://checkout.stripe.com/checkout.js"></script>
<button id="customButton" class="pay-button"> 
    <h4 class="donate-text button">Donate by
    <img src="http://#/testing/credit-card.png" ></h4>
</button>

<script>
  var handler = StripeCheckout.configure({
key: 'pk_test_mytestingkey',
image: '',
locale: 'auto',
token: function(token) {
  // Use the token to create the charge with a server-side script.
  // You can access the token ID with `token.id`
}
  });

 $('#customButton').on('click', function(e) {
// Open Checkout with further options
 var amount = $("#custom-donation-amount").val() * 100;
handler.open({
  name: 'Testing',
  description: 'Testing',
  amount: amount
});
e.preventDefault();
});

 // Close Checkout on page navigation
 $(window).on('popstate', function() {
    handler.close();
  });
 </script> 

我的问题:在没有
方法post或
操作的情况下,如何使用以下代码对卡进行充电。。。?它使用javascript来捕获令牌。但我不知道如何将该令牌发送到charge.php文件。。。基本上,我如何获取条带标记并启动API调用?如何启动API调用

正如您所说,您需要生成一个条带标记并进行表单发布。没有有效的代币,您不能刷卡

以下是关于如何使用Stripe创建自定义表单的指南,包括如何生成令牌:

一种更简单的方法是简单地嵌入其随时可用的签出:


您的服务器上应该有一个charge.php文件,并使用$.post将令牌发送到php

// make sure you have the right path to charge.php
// pass the token to the php file with POST, your php is expecting $_POST['stripeToken']
    token: function(token) {
        // Use the token to create the charge with a server-side script.
        // You can access the token ID with `token.id
        $.post( "charge.php", { stripeToken: token.id})
           // check if it worked
          .done(function( data ) {
            console.log( "Card charged: " + data );
          });
    }
在charge.php文件中,确保安装了


如果您正在使用mamp。
stripes API不再支持旧版本的MAMP

问题是将签出与自定义集成一起使用,这样我就可以拥有自己的自定义按钮。我已经开始使用这些基本的脚本运行了。但是我在哪里运行这个脚本呢?在@JonathanSafa包围的输入之后,charge.php是一个单独的文件。这个脚本将在您的token:function(token)中。哦,这更有意义。但是,现在我的charge.php文件中存在什么?@JonathanSafa“存在”是什么意思?不确定是否理解您的问题。对不起,我应该在“charge.php”文件中放什么脚本?
// make sure you have the right path to charge.php
// pass the token to the php file with POST, your php is expecting $_POST['stripeToken']
    token: function(token) {
        // Use the token to create the charge with a server-side script.
        // You can access the token ID with `token.id
        $.post( "charge.php", { stripeToken: token.id})
           // check if it worked
          .done(function( data ) {
            console.log( "Card charged: " + data );
          });
    }
<?
// composer require stripe/stripe-php
require 'vendor/autoload.php';
// Set your secret key: remember to change this to your live secret key in production
// See your keys here https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey("sk_test_mykey");

// Get the credit card details submitted by the form
$token = $_POST['stripeToken'];

// Create the charge on Stripe's servers - this will charge the user's card
try {
  $charge = \Stripe\Charge::create(array(
    "amount" => 1000, // amount in cents, again
    "currency" => "usd",
    "source" => $token,
    "description" => "Example charge"
    ));
} catch(\Stripe\Error\Card $e) {
  // The card has been declined
}
?>