gpt4 book ai didi

php - 在 laravel 项目 Stripe\Exception\ApiConnectionException 上连接 strip api 时出错

转载 作者:行者123 更新时间:2023-12-03 08:39:42 24 4
gpt4 key购买 nike

我必须将 Stripe api 连接到我的 laravel 项目,但是在启动该过程时,我遇到了以下错误消息:Unexpected error communicating with Stripe. If this problem persists, let us know at support@stripe.com. (Network error [errno 92]: HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1)) .我在 stackoverflow 上发现一个人有同样的错误,答案是将 TLS 1.0 升级到 TLS 1.2。我试过here但什么也没发生。我还运行了可达性测试here , 最后在进行任何 Stripe API 调用之前禁用 HTTP/2,如下 $curl = new \Stripe\HttpClient\CurlClient(); $curl->setEnableHttp2(false); \Stripe\ApiRequestor::setHttpClient($curl); .请我不知道该怎么做更多。
结帐.js:

Stripe.setPublishableKey('pk_test_51H3t5vAzmeZmoL9jwK8YCeFMxvDnuC6FsV0Rg0XvMejoZziTbS6SMQlAIkOjLj68lGqkE57Yu46jF51zg6HrnyBK00Yg8Iyy45');

var $form = $('#checkout-form');

$form.submit(function(event) {
$('#charge-error').addClass('hidden');
$form.find('button').prop('disabled', true);

Stripe.card.createToken({
number: $('#card-number').val(),
cvc: $('#card-cvc').val(),
exp_month: $('#card-expiry-month').val(),
exp_year: $('#card-expiry-year').val(),
name: $('#card-name').val()
}, stripeResponseHandler);
return false;
});

function stripeResponseHandler(status, response) {
if (response.error) {
$('#charge-error').removeClass('hidden');
$('#charge-error').text(response.error.message);
$form.find('button').prop('disalbed', false);
} else {// Token was created!

// Get the token ID:
var token = response.id;
// Insert the token into the form so it gets submitted to the server:
$form.append($('<input type="hidden" name="stripeToken" />').val(token));

// Submit the form:
$form.get(0).submit();
}
}
Controller .php:
public function postCheckout(Request $request)
{
$curl = new \Stripe\HttpClient\CurlClient();
$curl->setEnableHttp2(false);
\Stripe\ApiRequestor::setHttpClient($curl);

//require_once("vendor/autoload.php");
//require_once("/path/to/stripe-php/init.php");



if (!Session::has('cart')) {
return redirect()->route('shoppingCart');
}
$oldCart = Session::get('cart');
$cart = new Cart($oldCart);



Stripe::setApiKey('sk_test_?????
');
try {
Charge::create(array(
"amount" => $cart->totalPrice * 100,
"currency" => "usd",
"source" => $request->input('stripeToken'), // obtained with Stripe.js
"description" => "My First Test Charge"
));

} catch (\Exeption $e) {
return redirect()->route('checkout')->with('error', $e->getMessage());
}

Session::forget('cart');
return redirect()->route('home')->with('succes', 'Successfully purchaised!');
}

}
checkout.blade.php:
<span>
<h4>Total (USD)</h4>
</span>
<strong>${{ $total }}</strong>
</li>
</ul>
<div id="charge-error" class="alert alert-danger {{ !Session::has('error') ? 'hidden' : '' }} "> {{ Session::get('error') }}
</div>

最佳答案

经过长时间的研究,解决方案强制使用 HTTP/1.1:

$curl = new \Stripe\HttpClient\CurlClient([CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1]);
$curl->setEnableHttp2(false);
\Stripe\ApiRequestor::setHttpClient($curl);

关于php - 在 laravel 项目 Stripe\Exception\ApiConnectionException 上连接 strip api 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62886114/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com