Why Stripe API is not working on live website?

走远了吗. 提交于 2019-12-22 14:14:15

问题


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

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.

Here's some infos :

# 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
}

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.

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.

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...).

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 is up-to-date.

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

Thx for your interest...


回答1:


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.



来源:https://stackoverflow.com/questions/49083151/why-stripe-api-is-not-working-on-live-website

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!