thephpleague / omnipay-stripe

Stripe driver for the Omnipay PHP payment processing library
MIT License
184 stars 167 forks source link

set Stripe api version seems to be ignored #135

Closed sfarkas1988 closed 4 years ago

sfarkas1988 commented 5 years ago

I'm trying to use the newest api version for stripe with your code base. I couldn't find a way on how to set the apiVersion within your code. What I did is I called the following method before calling any API method:

\Stripe\Stripe::setApiVersion("2019-05-16"); More infos: https://stripe.com/docs/api/versioning

But in the response header i.e of the authorize method, I get this:

stripe-version: 2018-09-24

Setting the apiVersion explicitly would be great.

Update:

\Omnipay\Stripe\Message\AbstractRequest::getHeaders is not setting the value as needed in this api doc: https://stripe.com/docs/api/versioning?lang=curl

I even couldn't find a way to set the version.

domis86 commented 5 years ago

@sfarkas1988 you can resolve your problem using Guzzle like this:

    App\Payment\StripeService:
        arguments:
            $omnipayHttpClient: '@app.payment.omnipay_stripe_http_client'

    app.payment.omnipay_stripe_http_client:
        class: Omnipay\Common\Http\Client
        public: true
        arguments:
            $httpClient: '@app.payment.stripe_guzzle_client'

    app.payment.stripe_guzzle_client:
        class: Http\Adapter\Guzzle6\Client
        public: true
        factory: ['Http\Adapter\Guzzle6\Client', 'createWithConfig']
        arguments:
            $config:
                headers:
                    Stripe-Version: '%stripe_api_version%'
                    User-Agent: 'MyAppHttpClient/%server_hostname% Env/%kernel.environment% PHP/%php_version%'
                http_errors: false

^ You need to set stripe_api_version parameter in container (for example in parameters.yml or ".env" etc)

Maybe such solution should be mentioned in docs?

sfarkas1988 commented 5 years ago

Ok, thx for the solution, but it should definitely be done much easier. In my view direclty here: \Omnipay\Stripe\Message\AbstractRequest::getHeaders

kwarcu commented 5 years ago

For anyone looking for walk around that can be made directly in code:

$paymentIntentsGateway = Omnipay::create(
    'Stripe\PaymentIntents',
    new \Omnipay\Common\Http\Client(
        \Http\Adapter\Guzzle6\Client::createWithConfig(
            [
                'headers' => [
                    'Stripe-Version' => '2019-05-16',
                ],
            ]
        )
    )
);

I also want to agree with sfarkas1988 - this should be doable via omnipay gateway or request configuration.

Ezyweb-uk commented 5 years ago

I too would like to set the Stripe-Version in Omnipay to be able to check API version compatibility before switching the version in the Stripe control panel.

sfarkas1988 commented 5 years ago

@Ezyweb-uk see this pull request https://github.com/thephpleague/omnipay-stripe/pull/136

Ezyweb-uk commented 5 years ago

@sfarkas1988 many thanks!