Php 如何使用Ajax设置有效的可发布密钥条纹
我正在使用带签出的Php 如何使用Ajax设置有效的可发布密钥条纹,php,jquery,ajax,stripe-payments,payment-gateway,Php,Jquery,Ajax,Stripe Payments,Payment Gateway,我正在使用带签出的条带,但当我想支付时,返回此错误 您没有设置有效的可发布密钥。使用可发布密钥调用Stripe.setPublishableKey()。 我有3个文件(config.php-stripeIPN.php和htmlwhere is按钮) config.php require_once "stripe-php-master/init.php"; $stripeDetails = array( "secretKey" => "sk_test_xxx", "pu
条带
,但当我想支付时,返回此错误
您没有设置有效的可发布密钥。使用可发布密钥调用Stripe.setPublishableKey()。
我有3个文件(config.php
-stripeIPN.php
和html
where is按钮)
config.php
require_once "stripe-php-master/init.php";
$stripeDetails = array(
"secretKey" => "sk_test_xxx",
"publishableKey" => "pk_test_xxx"
);
\Stripe\Stripe::setApiKey($stripeDetails['secretKey']);
$pubkey = json_encode($stripeDetails['publishableKey']);
return $pubkey;
require_once "config.php";
\Stripe\Stripe::setVerifySslCerts(false);
$token = $_POST['stripeToken'];
$charge = \Stripe\Charge::create(array(
"amount" => 100,
"currency" => "eur",
"description" => "",
"source" => $token
));
stripeIPN.php
require_once "stripe-php-master/init.php";
$stripeDetails = array(
"secretKey" => "sk_test_xxx",
"publishableKey" => "pk_test_xxx"
);
\Stripe\Stripe::setApiKey($stripeDetails['secretKey']);
$pubkey = json_encode($stripeDetails['publishableKey']);
return $pubkey;
require_once "config.php";
\Stripe\Stripe::setVerifySslCerts(false);
$token = $_POST['stripeToken'];
$charge = \Stripe\Charge::create(array(
"amount" => 100,
"currency" => "eur",
"description" => "",
"source" => $token
));
html
<script src="https://js.stripe.com/v3/"></script>
<div id="button-stripe-vab">
<form action="stripeIPN.php" method="POST">
<script id="stripe-link"
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key=""
data-amount=""
data-name=""
data-description=""
data-image="image.png"
data-locale="auto"
data-label="Pay with card">
</script>
</form>
</div>
我知道我的代码很好,因为ajax可以工作,而对于firebug,我知道在ajax拥有我的可发布键之后,数据键
,但是为什么stripe按钮返回错误呢?
我有一个疑问:可能条带按钮(所以DOM)是在执行ajax之前创建的吗
非常感谢请尝试以下内容:-
var pubKey = "Your_key_here";
$.ajax({
type: "POST",
url: "config.php",
dataType:"json",
data: { data_key: pubKey }
success: function (result) { //se funziona
var pubkey = JSON.parse(JSON.stringify(result));
}
});
您正在成功响应中使用数据密钥。你的目标是什么?当你想使用它时?@ripa我对ajax不是很在行……你说我不应该在成功响应中使用数据键?我想用ajax@ripaajax已经准备好了eventok-明白了。检查我的答案。我是posting@ripa谢谢,我正在等待,我认为你写的东西没有意义……如果我必须把我的公钥带回.js文件,那么我应该直接在html中写。我认为您不理解我的问题…这是唯一的格式-如何在ajax文件中传递值。你可以用谷歌搜索。如果你不想这样,那你就得换个角度思考。不是ajax。试用期