为什么 Stripe API 在实时网站上不起作用? [英] Why Stripe API is not working on live website?

查看:28
本文介绍了为什么 Stripe API 在实时网站上不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Stripe 在一个小网站上处理一些付款.

I'm trying to use Stripe to handle some payments on a little website.

在本地,一切正常:我所有的测试都很好.问题出在实时网站上:我可以得到一个令牌(来自 javascript),但 php 端的 \Stripe\Charge::create 有问题,我不知道为什么.

In local, everything works great : all my tests are good. The problem is in live website : I can get a token (from javascript) but the \Stripe\Charge::create in the php side is buggy and I can't figure out why.

这里有一些信息:

# Making Stripe works
require_once(dirname(__FILE__).'/stripe/init.php');

# Set API Key (Both Live and Test keys don't work)
\Stripe\Stripe::setApiKey("sk_test_****");

# Trying to charge
# $token is defined from the $_POST and works great ($amount and $metas are fine too)

try {
    $charge = \Stripe\Charge::create(
        array(
            'amount' => $amount,
            'currency' => 'eur',
            'source' => $token,
            'metadata' => $metas
        )
    );

    // Blabla
} catch(\Stripe\Error\Card $e) {
    // Catching card error
} catch (\Stripe\Error\RateLimit $e) {
    // Catching RateLimit API error
} catch (\Stripe\Error\InvalidRequest $e) {
    // Catching invalid request (missing param or else)
} catch (\Stripe\Error\Authentication $e) {
    // Catching fail authentification from API KEY for example
} catch (\Stripe\Error\ApiConnection $e) {
    // Catching fail APIConnection
    // The error seems related to this because the catch is done here !
} catch (\Stripe\Error\Base $e) {
    // Catching base error
} catch (Exception $e) {
    // Catching other errors
}

在本地它工作得很好,但在实时服务器上,它在 \Stripe\Error\ApiConnection 上捕获了一个错误(一段时间后),没有真实信息.

On local it works great, but on live server it catches an error (after a while) on the \Stripe\Error\ApiConnection with no real informations.

#$e contains :
"httpStatus":null,
"httpBody":null,
"jsonBody":null,
"httpHeaders":null,
"requestId":null,
"stripeCode":null

这不是一个很好的迹象.

Which is not a very good sign.

除了刚开始的令牌部分(效果很好)之外,我的 Stripe 仪表板日志中没有关于此充电试验的任何内容.Stripe 似乎从未收到过请求.

Except for the gettin' token part (which works great) I have nothing in my Stripe's Dashboard's Logs about this Charge Trial. It looks like Stripe never receive the request.

我尝试从我的服务器 ping api.stripe.com,效果很好.

I tryied to ping api.stripe.com from my server, it works great.

本地和实时站点上的代码相同,条带键可以很好地复制/粘贴(它适用于本地,所以......).

Code on local and live sites are the same, stripe keys are well copy/pasted (it works on local, so...).

我的 Stripe 帐户已通过验证,因此我可以使用实时密钥(但实时密钥和测试密钥都无法像我说的那样工作).

My Stripe's account is validate so I can use Live Keys (but both live and test keys are not working like I said).

API 是最新的.

我不知道还能在哪里搜索:​​我联系了 Stripe 的支持人员,我仍在等待答复.

I don't know where else to search : I contacted the Stripe's support and I'm still waiting for an answer.

感谢您的兴趣...

推荐答案

因此,在与 @YvesLeBorg(感谢老兄)进行了一次 looong 交谈并进行了大量研究之后,我终于能够通过将其添加到我的iptables 的规则文件:

So, after a looong talk with @YvesLeBorg (thanks man) and a lot of researchs, I was finally able to make all this work by adding this to my iptables'rules file :

iptables -I OUTPUT -o eth0 -d 0.0.0.0/0 -j ACCEPT
iptables -I INPUT -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT

据我所知,它允许任何本地来源的流量.如您所见,我在这些方面不是很专业,所以如果有人认为这是错误的(即使它是唯一使所有这些有效的东西),请告诉我.

From what I understood, it allows any locally originating traffic. As you can see, I'm not very expert in those things so if someone thinks it's wrong (even if it's the only thing that made all this works), please tell me.

这篇关于为什么 Stripe API 在实时网站上不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆