Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] payment_stripe: support webhooks #69809

Conversation

simongoffin
Copy link
Contributor

Allow configuring a webhook in Stripe to send s2s notifications to Odoo
when a Checkout payment is completed. Note that SetupIntent and
PaymentIntent events are not listened to, since they are handled 'live'
with the customer actively present; the main use case for Stripe
webhooks is a Checkout session that gets interrupted before the customer
is redirected to Odoo (e.g. network loss, browser crash, closing the
tab, etc.).

The webhook should be configured to send its events to
<base_url>/payment/stripe/webhook and should only subscribe to
checkout.session.completed events to avoid spamming the Odoo server with
useless notifications.

opw-2488452
opw-2451463
opw-2449738

BACKPORT of commit: dc4f6ad

Should not be merged beyond 14.0 (14.0 excluded)

@robodoo
Copy link
Contributor

robodoo commented Apr 26, 2021

@C3POdoo C3POdoo added the OE the report is linked to a support ticket (opw-...) label Apr 26, 2021
Copy link
Contributor

@nle-odoo nle-odoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think test should work (testing it with --test-tags payment_stripe_checkout_webhook --stop-after-init) with these changes:

https://gist.github.com/nle-odoo/532d4c81a6122997531543e349be1426

to run the test in 14.0 or 12.0 in local, I also needed to use MockRequest (https://gist.github.com/nle-odoo/532d4c81a6122997531543e349be1426/ab003672a3d684312bde78658574c4fffc7cecfc) but it seems to work without that on runbot.

@nle-odoo nle-odoo force-pushed the 12.0-payment_stripe-checkout-webhook-backport branch from ec9c3c0 to 859ecd0 Compare April 27, 2021 13:49
@simongoffin
Copy link
Contributor Author

Hello @AntoineVDV

What do you think about it?

@AntoineVDV
Copy link
Contributor

Hello @AntoineVDV

What do you think about it?

Hello, it's in my review pipe but I can't have a look at it right now. Tomorrow at best :|

Copy link
Contributor

@AntoineVDV AntoineVDV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is a backport of an already tested feature, I only made a quick review without thorough testing but I found nothing to worry about.

Side note: I think that you should set yourself as the author of the commit since it's not an exact backport of dc4f6ad.

<base_url>/payment/stripe/webhook and should only subscribe to
checkout.session.completed events to avoid spamming the Odoo server with
useless notifications.""",
'depends': ['payment', 'payment_stripe', 'payment_stripe_sca'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'depends': ['payment', 'payment_stripe', 'payment_stripe_sca'],
'depends': ['payment_stripe', 'payment_stripe_sca'],

payment_stripe already depends on payment but it's not a big deal in this case.

@nle-odoo
Copy link
Contributor

nle-odoo commented May 3, 2021

Side note: I think that you should set yourself as the author of the commit since it's not an exact backport of dc4f6ad.

it is being backported by aho, sig just created the PR for his work :

https://www.odoo.com/web?debug#id=2449738&model=project.task

@simongoffin simongoffin force-pushed the 12.0-payment_stripe-checkout-webhook-backport branch from 859ecd0 to b2730ed Compare May 3, 2021 15:18
@simongoffin simongoffin requested a review from mart-e May 3, 2021 15:20
@simongoffin
Copy link
Contributor Author

Hello @mart-e Is is possible to have the security review?

Copy link
Contributor

@mart-e mart-e left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it's a new module, it needs a new .pot file and update of the .tx/config file

_inherit = 'payment.acquirer'

stripe_webhook_secret = fields.Char(
string='Stripe Webhook Secret', groups='base.group_user',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

base.group_user ? is there a reason to allow employee and not only admin?


@http.route('/payment/stripe/webhook', type='json', auth='public', csrf=False)
def stripe_webhook(self, **kwargs):
data = json.loads(request.httprequest.data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

controller type is already json


stripe_object = data.get('data', {}).get('object')
if not stripe_object:
raise ValidationError('Stripe Webhook data does not conform to the expected API.')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something displayed to user? If so it needs to be translated

'AUTHORIZATION': 'Bearer %s' % self.sudo().stripe_secret_key,
'Stripe-Version': '2019-05-16', # SetupIntent need a specific version
}
resp = requests.request(method, url, data=data, headers=headers)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing timeout

except HTTPError:
_logger.error(resp.text)
stripe_error = resp.json().get('error', {}).get('message', '')
error_msg = " " + (_("Stripe gave us the following info about the problem: '%s'", stripe_error))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the notation _("foo %s", bar) for translations was introduced in 14.0

<field name="arch" type="xml">
<xpath expr='//group[@name="acquirer"]' position='after'>
<group attrs="{'invisible': [('provider', '!=', 'stripe')]}">
<field name="stripe_webhook_secret" password="True"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we are modifying the groups attribute in python, need to add one here too

@simongoffin simongoffin force-pushed the 12.0-payment_stripe-checkout-webhook-backport branch 2 times, most recently from 8438e69 to 3173f11 Compare May 6, 2021 14:02
@mart-e
Copy link
Contributor

mart-e commented May 10, 2021

@robodoo override=ci/security
Reason: proper use of hmac, request without injectable content with a fixed url

Allow configuring a webhook in Stripe to send s2s notifications to Odoo
when a Checkout payment is completed. Note that SetupIntent and
PaymentIntent events are not listened to, since they are handled 'live'
with the customer actively present; the main use case for Stripe
webhooks is a Checkout session that gets interrupted before the customer
is redirected to Odoo (e.g. network loss, browser crash, closing the
tab, etc.).

The webhook should be configured to send its events to
<base_url>/payment/stripe/webhook and should only subscribe to
checkout.session.completed events to avoid spamming the Odoo server with
useless notifications.

opw-2488452
opw-2451463
opw-2449738

BACKPORT of commit: dc4f6ad

Should not be merged beyond 14.0 (14.0 excluded)
@simongoffin simongoffin force-pushed the 12.0-payment_stripe-checkout-webhook-backport branch from 3173f11 to a1ff4dc Compare May 10, 2021 09:22
@simongoffin
Copy link
Contributor Author

robodoo r+

robodoo pushed a commit that referenced this pull request Jun 1, 2021
Allow configuring a webhook in Stripe to send s2s notifications to Odoo
when a Checkout payment is completed. Note that SetupIntent and
PaymentIntent events are not listened to, since they are handled 'live'
with the customer actively present; the main use case for Stripe
webhooks is a Checkout session that gets interrupted before the customer
is redirected to Odoo (e.g. network loss, browser crash, closing the
tab, etc.).

The webhook should be configured to send its events to
<base_url>/payment/stripe/webhook and should only subscribe to
checkout.session.completed events to avoid spamming the Odoo server with
useless notifications.

opw-2488452
opw-2451463
opw-2449738

BACKPORT of commit: dc4f6ad

Should not be merged beyond 14.0 (14.0 excluded)

closes #69809

Signed-off-by: Simon Goffin (sig) <sig@openerp.com>
@robodoo robodoo closed this Jun 1, 2021
@robodoo robodoo temporarily deployed to merge June 1, 2021 08:16 Inactive
@fw-bot
Copy link
Contributor

fw-bot commented Jun 5, 2021

This pull request has forward-port PRs awaiting action (not merged or closed): #71558

1 similar comment
@fw-bot
Copy link
Contributor

fw-bot commented Jun 6, 2021

This pull request has forward-port PRs awaiting action (not merged or closed): #71558

@fw-bot
Copy link
Contributor

fw-bot commented Jun 7, 2021

This pull request has forward-port PRs awaiting action (not merged or closed): #71558

3 similar comments
@fw-bot
Copy link
Contributor

fw-bot commented Jun 8, 2021

This pull request has forward-port PRs awaiting action (not merged or closed): #71558

@fw-bot
Copy link
Contributor

fw-bot commented Jun 9, 2021

This pull request has forward-port PRs awaiting action (not merged or closed): #71558

@fw-bot
Copy link
Contributor

fw-bot commented Jun 10, 2021

This pull request has forward-port PRs awaiting action (not merged or closed): #71558

@mart-e
Copy link
Contributor

mart-e commented Jun 10, 2021

@simongoffin don't forget your forward ports

@wtaferner
Copy link
Contributor

Wow, I did not recognize that soo many people collaborated on this showstopper 😝
#71933 is helping out...

@fw-bot
Copy link
Contributor

fw-bot commented Jun 11, 2021

This pull request has forward-port PRs awaiting action (not merged or closed): #71558

1 similar comment
@fw-bot
Copy link
Contributor

fw-bot commented Jun 13, 2021

This pull request has forward-port PRs awaiting action (not merged or closed): #71558

@fw-bot fw-bot deleted the 12.0-payment_stripe-checkout-webhook-backport branch June 15, 2021 08:46
@fw-bot
Copy link
Contributor

fw-bot commented Jun 21, 2021

This pull request has forward-port PRs awaiting action (not merged or closed): #71558

kzhekov pushed a commit to odoo-dev/odoo that referenced this pull request Jun 28, 2021
Allow configuring a webhook in Stripe to send s2s notifications to Odoo
when a Checkout payment is completed. Note that SetupIntent and
PaymentIntent events are not listened to, since they are handled 'live'
with the customer actively present; the main use case for Stripe
webhooks is a Checkout session that gets interrupted before the customer
is redirected to Odoo (e.g. network loss, browser crash, closing the
tab, etc.).

The webhook should be configured to send its events to
<base_url>/payment/stripe/webhook and should only subscribe to
checkout.session.completed events to avoid spamming the Odoo server with
useless notifications.

opw-2488452
opw-2451463
opw-2449738

BACKPORT of commit: dc4f6ad

Should not be merged beyond 14.0 (14.0 excluded)

closes odoo#69809

Signed-off-by: Simon Goffin (sig) <sig@openerp.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OE the report is linked to a support ticket (opw-...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants