php - Stripe 结账 - PHP

标签 php stripe-payments checkout

我已经设法让 Stripe Checkout 使用 PHP 工作。但我想摆脱最初的 Stripe Button,它通常显示“继续付款”或“用卡付款”。我只是想链接我网站上的按钮以直接转到结帐弹出窗口。我想知道这是否可能?我在下面包含了 php 文件和相关的 html 代码。

index.php

<?php require_once('config.php'); ?>

<form action="charge.php" method="post">
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="<?php echo $stripe['publishable_key']; ?>"
data-name="The Boffins"
data-amount="25000" 
data-currency="GBP"
data-description="Social Package"
data-image="images/Gentleman.gif"
data-label="Proceed to Payment"
data-panel-label="Only">
</script>
</form>

charge.php

<?php
require_once('config.php');

$token  = $_POST['stripeToken'];

$customer = \Stripe\Customer::create(array(
  'email' => 'customer@example.com',
  'card'  => $token
));

$charge = \Stripe\Charge::create(array(
  'customer' => $customer->id,
  'amount'   => 25000, //amount in pennies
  'currency' => 'gbp'
));

echo 'Successfully charged £250! We will be in touch shortly.';

config.php

require_once('vendor/stripe-php-3.1.0/init.php');

$stripe = array(
 "secret_key"      => "sk_live_XXXXXXXXXXXX",
 "publishable_key" => "pk_live_YYYYYYYYYYYY"
);

\Stripe\Stripe::setApiKey($stripe['secret_key']);

html:

<a class="button price-button one-off-m" href="index.php">£250 /<span class="one-off"></a>

最佳答案

Per stripe 的文档:

<script src="https://checkout.stripe.com/checkout.js"></script>

<button id="customButton">Purchase</button>

<script>
    var handler = StripeCheckout.configure({
    key: 'pk_test_4asasasasasasa',
    image: '/img/documentation/checkout/marketplace.png',
    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
       handler.open({
       name: 'name',
       description: '2 widgets',
       amount: 2000
        });
   e.preventDefault();
  });

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

关于php - Stripe 结账 - PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31965437/

相关文章:

php - 带有 Redux 框架的动态样式表

PHP MYSQL 限制错误

php - "Extend"用户使用 Laravel 收银员订阅 Stripe?

stripe-payments - 从 Stripe charge API 获取 Stripe Checkout 产品 SKU

ruby-on-rails - 如何使用带有 rails 的自定义形式的 stripe v2 进行充电?

php - 如何以编程方式为每个购物车项目设置动态折扣?

php - 删除 WooCommerce Checkout 中一些基于虚拟产品的 Hook 功能

ruby-on-rails - 如何从 Spree 的结帐流程中删除注册的第一步?

php - elasticsearch php多个名称

php - 通过 Google Places API 解析地址