我对wordpress开发相当陌生,我正在尝试将一个条带签出表单包含到我从头开发的自定义页面中。我按照stripe的文档介绍了如何做到这一点:[https://stripe.com/docs/payments/accept-a-payment-charges]这是我的html页面
<?php
/* Template Name: Custom Checkout Page */
/**
* Page template
*
* @package mytheme
*/
//exit if accessed directly
if (! defined(\'ABSPATH\')){
exit;
}
get_header();
?>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</head>
<body>
<form action="https://www.example.com/wp-content/themes/{my_theme}/charge.php" method="post "id="payment-form" name="payment-form">
<div class="form-group">
<label for="stripecn">Card Number *</label>
<div id="stripecn">
<!-- A Stripe Element will be inserted here. -->
</div><span class="glyphicon glyphicon-credit-card" style="font-size: 20px;"></span>
</div>
<div class="row">
<div class="col-md-6">
<label for="stripexpd">
Expiry Date
</label>
<div id="stripexpd">
<!-- A Stripe Element will be inserted here. -->
</div>
</div>
<div class="col-md-6">
<label for="stripecc">
Card Code (CVC)
</label>
<div id="stripecc">
<!-- A Stripe Element will be inserted here. -->
</div>
</div>
</div>
<div id="card-errors" role="alert"></div>
<div class="form-group" id="buttonHolder">
<button class="form-control btn btn-primary btn-lg">Submit Stripe Payment</button>
</div>
</form>
<script src="https://js.stripe.com/v3/"></script>
<script src="https://www.example.com/wp-content/themes/mytheme/includes/client.js"></script>
</body>
接下来是我的客户。js公司:
// Set your publishable key: remember to change this to your live publishable key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
var stripe = Stripe(\'pk_test_asjdfmykeyhereu129123j\');
var elements = stripe.elements();
// Create an instance of the card Element.
var card = elements.create(\'cardNumber\', {
classes : {
base: "form-control",
invalid:"error"
}
});
var cardexp = elements.create(\'cardExpiry\', {
classes : {
base: "form-control",
invalid:"error"
}
});
var cardcvc = elements.create(\'cardCvc\', {
classes : {
base: "form-control",
invalid:"error"
}
});
// Add an instance of the card Element into the `card-element` <div>.
card.mount(\'#stripecn\');
cardexp.mount(\'#stripexpd\');
cardcvc.mount(\'#stripecc\');
// Create a token or display an error when the form is submitted.
var form = document.getElementById(\'payment-form\');
form.addEventListener(\'submit\', function(event) {
event.preventDefault();
stripe.createToken(card).then(function(result) {
if (result.error) {
// Inform the customer that there was an error.
var errorElement = document.getElementById(\'card-errors\');
errorElement.textContent = result.error.message;
} else {
// Send the token to your server.
stripeTokenHandler(result.token);
}
});
});
function stripeTokenHandler(token) {
// Insert the token ID into the form so it gets submitted to the server
var form = document.getElementById(\'payment-form\');
var hiddenInput = document.createElement(\'input\');
hiddenInput.setAttribute(\'type\', \'hidden\');
hiddenInput.setAttribute(\'name\', \'stripeToken\');
hiddenInput.setAttribute(\'value\', token.id);
form.appendChild(hiddenInput);
// Submit the form
form.submit();
}
现在由我负责。php文件:
<?php
require \'vendor/autoload.php\';
// Set your secret key. Remember to switch to your live secret key in production.
// See your keys here: https://dashboard.stripe.com/account/apikeys
\\Stripe\\Stripe::setApiKey(
\'sk_test_9823jMysecretkey0123j\'
);
// Token is created using Stripe Checkout or Elements!
// Get the payment token ID submitted by the form:
$token = $_POST[\'stripeToken\'];
$charge = \\Stripe\\Charge::create([
\'amount\' => 999,
\'currency\' => \'usd\',
\'description\' => \'Example charge\',
\'source\' => $token,
]);
我还将stripe php库上载到了themes\\u文件夹->;插件->;供应商/
现在,当我进行测试交易时,表单提交并进入一个空白页面,但在我的stripe仪表板上没有进行测试付款。当我检查wordpress服务器是否有错误时,我得到的是:
2021/04/08 02:03:05[错误]81674#81674:*206783 FastCGI发送指令:“错误”;PHP消息:PHP通知:未定义索引:stripeToken in/www/sitefolder/public/wp-content/themes/theme/charge。phpon第12PHP行消息:PHP致命错误:Uncaught(状态400)(Requestreq\\u xxlp0z05padss)必须提供源或客户。加入/www/sitefolder/public/wp-content/themes/theme/plugin/vendor/stripe/stripe-php/lib/Exception/apierroexception。phpon第38行“;从上游读取响应标头时,客户端:my。ip。地址,服务器:示例。com,请求:“;获取/wp内容/主题/主题/费用。php?stripeToken=tok\\u 1IdnD2BVqVZ2ueLqOCdmo6NvHTTP/1.0“;,上游:“;fastcgi://unix:/var/run/php7.3-fpm mysite。袜子:“,”;,主机:“;www.example。com“;,推荐人:;http://example.com/";