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

feat: handle radom webhook events #2640

Merged
merged 23 commits into from
Sep 11, 2024
Merged

feat: handle radom webhook events #2640

merged 23 commits into from
Sep 11, 2024

Conversation

clD11
Copy link
Contributor

@clD11 clD11 commented Aug 9, 2024

Summary

This PR adds support for radom webhook events. Namely

Event Type Action Order State
newSubscription New Paid
subscriptionPayment Renewals Paid
subscriptionCancelled, subscriptionExpired Canceled Canceled

Things to note:

resolves #2642

Type of Change

  • Product feature
  • Bug fix
  • Performance improvement
  • Refactor
  • Other

Tested Environments

  • Development
  • Staging
  • Production

Before Requesting Review

  • Does your code build cleanly without any errors or warnings?
  • Have you used auto closing keywords?
  • Have you added tests for new functionality?
  • Have validated query efficiency for new database queries?
  • Have documented new functionality in README or in comments?
  • Have you squashed all intermediate commits?
  • Is there a clear title that explains what the PR does?
  • Have you used intuitive function, variable and other naming?
  • Have you requested security and/or privacy review if needed
  • Have you performed a self review of this PR?

Manual Test Plan

Copy link

@bcaller bcaller left a comment

Choose a reason for hiding this comment

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

All looks fine except the commented line.

services/skus/radom/event.go Outdated Show resolved Hide resolved
Copy link
Member

@kdenhartog kdenhartog left a comment

Choose a reason for hiding this comment

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

few questions to just make sure we're not accidentally introducing issues, but overall I think this looks good.

Noting that privacy policy updates still needed, but I spoke with @mattmcalister and we're going to handle that before enabling the flag

services/skus/service.go Outdated Show resolved Hide resolved
services/skus/service.go Show resolved Hide resolved
services/skus/service.go Outdated Show resolved Hide resolved
@clD11 clD11 changed the title Draft - feat: handle radom webhook events feat: handle radom webhook events Aug 13, 2024
Copy link
Member

@kdenhartog kdenhartog left a comment

Choose a reason for hiding this comment

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

Meant to approve this earlier. This Lgtm for privacy and security

@clD11 clD11 marked this pull request as ready for review August 19, 2024 15:55
@clD11 clD11 self-assigned this Aug 19, 2024
@clD11 clD11 requested a review from pavelbrm August 19, 2024 15:56
Copy link
Contributor

@pavelbrm pavelbrm left a comment

Choose a reason for hiding this comment

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

Great work on this one!

Not approved yet because left some questions around naming and error handling, as well as some of the logic regarding expiry time.

services/skus/controllers.go Outdated Show resolved Hide resolved
Comment on lines 1223 to 1226
if err := svc.processRadomEvent(ctx, event); err != nil {
l.Err(err).Msg("failed to process radom event")

return handlers.WrapError(model.ErrSomethingWentWrong, "something went wrong", http.StatusInternalServerError)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

question (blocking): Do we want to respond to any error with a 500? There could be legitimate reasons for this to not return an error to the 3rd-party. Please take a look at handleWebhookPlayStoreH, handleWebhookAppStoreH, and handleStripeWebhook which handle errors returned from the business logic.

Copy link
Contributor

Choose a reason for hiding this comment

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

@clD11 This is an open important question.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the mobile handlers i.e. handleWebhookPlayStoreH and handleWebhookAppStoreH things are quite different with regards to the order i.e. in many cases we will not have an order due to not linking however this should never be the case for Radom.

Also looking at the other handlers its not clear how model.ErrNoRowsChangedOrderPayHistory can ever be thrown. Unless I am missing something the current code will either insert or throw a unique constraint violation so model.ErrNoRowsChangedOrderPayHistory will never been returned. Whats puzzling is how this is working for the other handlers with regards to duplicates and I see we are setting the paid at timestamp to the time we process the message rather than the actual paid at time hence it always inserts a new row even for duplicates, this will not be the case for Radom as it uses the actual paid at time which will be consistent.

Lets take this one 'offline' and discuss how we want to handle the events as there are a couple of things we might want to address here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, let's discuss it offline.

The main point I've made in/by the comment is that responding with a 500 in all possible errors here is not necessarily good enough. Maybe some granularity, if possible, is good.

services/skus/radom/event.go Outdated Show resolved Hide resolved
services/skus/radom/event.go Outdated Show resolved Hide resolved
services/skus/radom/event.go Outdated Show resolved Hide resolved
services/skus/service.go Outdated Show resolved Hide resolved
services/skus/service.go Show resolved Hide resolved
services/skus/service.go Outdated Show resolved Hide resolved
services/skus/service.go Outdated Show resolved Hide resolved
}
}

func TestService_processRadomEventTx(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: At some point, it would be nice to see more test cases covering some of the important branches of the method. Currently it covers only the happy path, which does not guarantee the expected behaviour under error conditions.

nit: Above and below, the variable for service should hold a pointer as that's what Service usually is, and that's how it's declared in other places. I know that Go will properly handle this when calling the method, however, visually, when reading the code, the inconsistency is noticeable and distracting – there is this urge to fix it.

Copy link
Contributor

@pavelbrm pavelbrm left a comment

Choose a reason for hiding this comment

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

Great work, thank you for the discussions in comments.

@clD11 clD11 merged commit 72ecf54 into pwb-01 Sep 11, 2024
3 checks passed
@clD11 clD11 deleted the pwb-02 branch September 11, 2024 18:50
clD11 added a commit that referenced this pull request Sep 11, 2024
* feat: add radom checkout session integration for new orders

* test: add no metadata test order item req

* style: add new line to slice init in radom gateway

* fix: set radom authorization header without bearer prefix

* fix: rectify skus model tests after rebase

* refactor: rename method createRadomSessID to createRadomSession

* refactor: address comments

* fix imports
* update gateway to pointer
* update radom checkout session request to pointer
* rename order items to line items function
* add radom product id getter on metadata

* refactor: remove unused variable emptyCreateCheckoutSessionResp

* refactor: remove unnecessary convert to UTC

* refactor: sort imports

* refactor: remove unused func mustDecimalFromString

* feat: handle radom webhook events (#2640)

* feat: add radom checkout session integration for new orders

* fix: rectify skus model tests after rebase

* refactor: address comments

* fix imports
* update gateway to pointer
* update radom checkout session request to pointer
* rename order items to line items function
* add radom product id getter on metadata

* feat: add radom checkout session integration for new orders

* feat: handle radom webhook events

* test: remove duplicate test and fix pointer after rebase

* feat: set radom webhook verification key

* refactor: use pointers for radom events

* refactor: fix import order skus controller

* refactor: simplify radom event processing checks

* style: fix parse apostrophe

* refactor: use pointer for radom subscription response

* refactor: remove call to error when calling err on logging

* refactor: use index directly on radom mdata

* refactor: make radom action error naming less generic

* refactor: use pointer for service in test

* refactor: sort imports in radom.go

* refactor: update radom empty payments error message

* style: return from func call opposed to explicit return nil

* refactor: use string in radom get subscription

* refactor: add on conflict do nothing to order history insert statement

* refactor: rename radom event to radom notification

* test: remove duplicate test after rebase
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants