Stripe Checkout - PHP



我已经设法让Stripe Checkout使用PHP工作。但我想去掉最初的条纹按钮,它通常会显示"继续付款"。或者"用卡支付"。我只是想链接我的网站上的按钮直接到Checkout弹出。我想知道这是否可能?我在下面包含了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 = StripeCustomer::create(array(
  'email' => 'customer@example.com',
  'card'  => $token
));
$charge = StripeCharge::create(array(
  'customer' => $customer->id,
  'amount'   => 25000, //amount in pennies
  'currency' => 'gbp'
));
echo 'Successfully charged £250! We will be in touch shortly.';

config。

require_once('vendor/stripe-php-3.1.0/init.php');
$stripe = array(
 "secret_key"      => "sk_live_XXXXXXXXXXXX",
 "publishable_key" => "pk_live_YYYYYYYYYYYY"
);
StripeStripe::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>

最新更新