FLUX-SE / PayumStripe

Payum Stripe gateways (with SCA support)
MIT License
28 stars 15 forks source link

Is this compatible with PayumBundle ? #4

Closed jimiero closed 4 years ago

jimiero commented 4 years ago

Hello,

Is your plugin compatible with https://github.com/Payum/PayumBundle? I see they don't have any Stripe with sca currently, if yes, do you have some more detailed documentation?

Prometee commented 4 years ago

Hi @jimiero,

This library can be use with payum/payum-bundle check the bundle related to this library if you want to use it : https://github.com/Prometee/PayumStripeCheckoutSessionBundle. payum/payum-bundle is just an helper for payum/payum to ease the integration with symfony.

Also into payum/payum there is multiple packages, there is for example payum/core and payum/stripe. This last package payum/stripe is not well updated and is not allowing (right now) to use "Stripe Checkout Session". That's why I decided to make my own implementation of Stripe gateways and right now there is only one gateway available "Stripe Checkout Session" supporting :

I'm also wanting to support "Stripe JS" shortly.

jimiero commented 4 years ago

@Prometee I see you have a min php version set to 7.3, is this on purpose?

Prometee commented 4 years ago

@jimiero it's just because 7.2 will fall into "end of life" in the end of the year, but I think the requirement could removed if tests are ok then.

jimiero commented 4 years ago

I'll try to test https://github.com/Prometee/PayumStripeCheckoutSessionBundle will keep you updated, hopefully the documentation you have will help me the read the finish line :)

Thanks for your work btw!

Prometee commented 4 years ago

Thanks 😉 Don't hesitate to post another issue if doc is not enough, the Payum doc is not very useful sometime so maybe I could help fill in the blank.

Prometee commented 4 years ago

@jimiero I just test the removing of php minimum version requirement and add php 7.2 to the travis build, it could work with php 7.2 if you need to. https://travis-ci.org/github/Prometee/PayumStripe/builds/680706058

jimiero commented 4 years ago

Thanks,

I just made a quick test, not sure If I did it correctly, here is my webhook setting

Screen Shot 2020-04-28 at 10 03 35 PM

And the test payment seems went fine, hurray! :) spend almost 2 days searching for sca solution for Stripe.

Prometee commented 4 years ago

I updated the README on the bundle : https://github.com/Prometee/PayumStripeCheckoutSessionBundle

The url you set for the webhook won't work because it's a local one and also because I think you are using symfony and this Notify url already exists, check my updated README on the bundle to get what is wrong ;)

This bundle will work even if the webhook is not set, but for production env you will need it. If you want to capture webhook events en your local dev env you can install stripe cli and then execute :

stripe login #only needed every 90days
stripe listen --events checkout.session.completed,payment_intent.canceled \
    --forward-to https://my-local.com/payment/notify/unsafe/stripe_checkout_session

Replace the --forward-to argument value with the right one you need.

Doing this you won't have to create

jimiero commented 4 years ago

Thanks the update, would it be possible to update the composer php version to ^7.2 as I have some others packages which require 7.2 :(

Or somehow to not force having php7.3 installed

Regards

Prometee commented 4 years ago

@jimiero I just publish a new release with php min version removed and other stuff : https://github.com/Prometee/PayumStripe/releases/tag/v1.1.1

jimiero commented 4 years ago

Thanks! I'll give a try and let you know how it goes.

jimiero commented 4 years ago

Hello @Prometee I just tried to make a live payment with success, but here is an error in the logs, probably related with webhooks:

request.CRITICAL:` Uncaught PHP Exception Payum\Core\Exception\RequestNotSupportedException:
"Request ResolveWebhookEvent is not supported.
Make sure the gateway supports the requests and there is an action which supports this request (The method returns true).
There may be a bug, so look for a related issue on the issue tracker."
at vendor/payum/payum/src/Payum/Core/Exception/RequestNotSupportedException.php line 57 
{"exception":"[object] (Payum\\Core\\Exception\\RequestNotSupportedException(code: 0): Request ResolveWebhookEvent is not supported.
Make sure the gateway supports the requests and there is an action which supports this request (The method returns true).
There may be a bug, so look for a related issue on the issue tracker.
at vendor/payum/payum/src/Payum/Core/Exception/RequestNotSupportedException.php:57)"} []
Prometee commented 4 years ago

This means that an webhook event has been catched but no handler is there to consume it. Do you restrict the webhook key to the 2 events required ?

jimiero commented 4 years ago

Yes, this is the setting for the webhook

Screen Shot 2020-04-30 at 11 30 38 AM

( i replaced my domain in the image )

and 'stripe' is how I named the gateway

Prometee commented 4 years ago

Are you sure that your gateway is named "stripe" ?

jimiero commented 4 years ago

yes, but maybe I'm wrong

stripe:
            factory: stripe_checkout_session
            publishable_key: '%publishable_key%'
            secret_key: '%stripe_secret_key%'
            webhook_secret_keys: ['my-webhook-key']
Prometee commented 4 years ago

Your gateway name is stripe so your webhook url is ok. Can you check the logs of you Stripe account and check the failed webhook call or check the webhook logs ?

jimiero commented 4 years ago

What to look exactly for, the webhook says

<?xml version="1.0"?>

https://tools.ietf.org/html/rfc2616#section-10An error occurred500Internal Server Error

which is caused by that error I get on my site, the one mentioned about

Prometee commented 4 years ago

I was talking about the Stripe logs on the Stripe website.

Edit your Stripe webhook and then you will see "Webhook attempts" list

jimiero commented 4 years ago

here it is

 "id": "evt_1GdXdPHQU2SYnXWXN9RYVMXV",
  "object": "event",
  "api_version": "2019-03-14",
  "created": 1588234843,
  "data": {
    "object": {
      "id": "cs_live_wbNF1RyQtoTnPhvE1IdXJvKYDdoZ6U9gRwx6prUkrw4arNXXXXXX",
      "object": "checkout.session",
      "billing_address_collection": null,
      "cancel_url": "https://www.domain.com/payment/capture/GXpq7nhhqRVfp3jzBC9XiJr4PX0_M9HcpS1RKcY5G50",
      "client_reference_id": null,
      "customer": "cus_HBvXXXXXVpGaH",
      "customer_email": "email@gmail.com",
      "display_items": [
        {
          "amount": 595,
          "currency": "eur",
          "custom": {
            "description": null,
            "images": null,
            "name": "Payment on Domain.com"
          },
          "quantity": 1,
          "type": "custom"
        }
      ],
      "livemode": true,
      "locale": null,
      "metadata": {
        "token_hash": "r4p5ZrBwqHmmvjs4vIWQefuBenJ9sk0T4Zjw-XXXXX"
      },
      "mode": "payment",
      "payment_intent": "pi_1GdXcfHQU2SYnXWXgYXXXXX",
      "payment_method_types": [
        "card"
      ],
      "setup_intent": null,
      "shipping": null,
      "shipping_address_collection": null,
      "submit_type": null,
      "subscription": null,
      "success_url": "https://www.domain.com/payment/capture/GXpq7nhhqRVfp3jzBC9XiJr4PX0_M9HcpS1RKcY5G50"
    }
  },
  "livemode": true,
  "pending_webhooks": 1,
  "request": {
    "id": null,
    "idempotency_key": null
  },
  "type": "checkout.session.completed"
}
Prometee commented 4 years ago

All seems to be OK, so the log you show here is affected to the same webhook key you set in the config right ? Because the error can only happen when the webhook content (this json you pasted) can't be identified by a signature checking using the webhook key and this json.

jimiero commented 4 years ago

Yes it is.

Prometee commented 4 years ago

It could be the fact that the required STRIPE_SIGNATURE header is not accessible, are you using a proxy between Stripe and your server ?

This is how the webhook signature is checked : https://stripe.com/docs/webhooks/signatures

Prometee commented 4 years ago

In this library the signature header is retrieved by this method

jimiero commented 4 years ago

Not using a proxy, not sure what I can do.

Does this failing event brakes the sca of Stripe?

Prometee commented 4 years ago

Not it won't affect at all the SCA flow, but the webhook is here to make a double check of the payment status.

Prometee commented 4 years ago

@jimiero I push some updates to get more info about your signature error, if you want to get more details about it, add this line to your composer.json (section require) :

"prometee/payum-stripe": "dev-master",

Run a new test payment and then you will get more info on the reason of why the webhook can't be verified.

jimiero commented 4 years ago

phew thanks @Prometee that helped, ended up finding that the server time was not synced to an online time clock server.

Fixing the server time, solved the issue and webhook succeeded!

Appreciate your assitance!

Prometee commented 4 years ago

@jimiero Perfect ! Thanks you too for bringing those cases. I will add some notes in the doc about it and the other signature issues which could happen too.