Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用Ajax设置有效的可发布密钥条纹_Php_Jquery_Ajax_Stripe Payments_Payment Gateway - Fatal编程技术网

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。试用期