简体   繁体   English

将条带支付(JS和PHP)与自定义数量(JS变量)集成

[英]Integrating stripe payments (JS and PHP) with a custom amount (JS variable)

I've been trying to figure this out for days with no luck. 我一直试图弄清楚这几天没有运气。 I'm trying to implement Stripe Payments Checkout into my website. 我正在尝试将Stripe Payments Checkout实施到我的网站中。 The payment amount is on the payments page as a JS variable. 付款金额在付款页面上作为JS变量。 I was able to get Basic Checkout working, but apparently that can't use a custom amount, or send any data to the PHP processing page (email, and some order attributes). 我能够使Basic Checkout工作,但显然不能使用自定义金额,或将任何数据发送到PHP处理页面(电子邮件和一些订单属性)。 I've been trying to use the Custom Checkout but I can't figure it out. 我一直在尝试使用Custom Checkout,但我无法理解。 Any help? 有帮助吗?

So far I have this in config.php: 到目前为止,我在config.php中有这个:

<?php
require_once('vendor/autoload.php');

$stripe = array(
"secret_key"      => "MY SECRET KEY IS HERE",
"publishable_key" => "MY PUBLISHED KEY IS HERE"
);

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

and this is in a file called process.php: 这是一个名为process.php的文件:

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

$token  = $_POST['stripeToken'];
$input = $_POST["totalprice"];
$customer = \Stripe\Customer::create(array(
  'email' => 'customer@example.com',
  'source'  => $token
));

$charge = \Stripe\Charge::create(array(
  'customer' => $customer->id,
  'amount'   => $input,
  'currency' => 'usd'
));

echo $input;
?>

And in the initial PHP file I have: 在我最初的PHP文件中:

<?php require_once('./config.php'); ?>
<form action="process.php" method="POST">
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="MY PUBLIC TEST KEY IS HERE"
data-amount= amt * 100
data-name="Test Name"
data-description="Widget"
data-image="/img/logo.jpg"
data-locale="auto"
>
<form type=hidden name="totalprice" value=amt*100 action="process.php" method="POST">
</script>
</form>    

With that said though, I've had a bunch of other code I've tried before that hasn't worked, so this current code probably should be scrapped. 尽管如此,我还有一堆其他代码,我之前尝试过但没有用,所以这个当前的代码可能应该被废弃。 I'd really appreciate any help I can get! 我真的很感激我能得到任何帮助!

Well, following is the sample code of Custom Integration. 那么,以下是自定义集成的示例代码。

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

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

<script>
var handler = StripeCheckout.configure({
  key: 'pk_test_6pRNASCoBOKtIshFeQd4XMUh',
  image: 'https://stripe.com/img/documentation/checkout/marketplace.png',
  locale: 'auto',
  token: function(token) {
    // You can access the token ID with `token.id`.
    // Get the token ID to your server-side code for use.
  }
});

document.getElementById('customButton').addEventListener('click', function(e) {
  // Open Checkout with further options:
  handler.open({
    name: 'Stripe.com',
    description: '2 widgets',
    zipCode: true,
    amount: 2000
  });
  e.preventDefault();
});

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

The source code is given on this page 源代码在此页面上给出

So is that what you are looking for? 那你在找什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM