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

add webhook validation utility methods #46

Open
criskell opened this issue Jul 15, 2023 · 5 comments
Open

add webhook validation utility methods #46

criskell opened this issue Jul 15, 2023 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@criskell
Copy link
Contributor

Example usage

$client->webhooks()->isChargeCompletedPayloadValid($payload) // true or false
$client->webhooks()->isTransactionReceivedPayloadValid($payload) // true or false

@criskell criskell added the enhancement New feature or request label Jul 15, 2023
@criskell criskell self-assigned this Jul 15, 2023
@sibelius
Copy link
Member

Not sure we should expose this in the user land

Not sure our users needs to use this

This could be an implementation detail of our e-commerce integration

@criskell
Copy link
Contributor Author

criskell commented Jul 15, 2023

my mentor thought it was good that payload validations are inside the php-sdk instead of in the ecommerce integrations

if users decide to use only one endpoint to receive webhooks, they need a way to distinguish event types:

if ($event === "OPENPIX:TRANSACTION_RECEIVED") {}
// vs
if ($client->webhooks()->isTransactionReceivedPayloadValid($payload)) {}

this way we can avoid "pure strings" and move validation of payloads into php-sdk instead of ecommerce integrations

in my opinion, if we assume that all the payload sent by the api is valid in case the signature is correct, I believe that there is no need for payload validation

and to distinguish the types of webhooks avoiding "pure strings" we can just add constants in the webhooks resource:

use OpenPix\PhpSdk\Resources\Webhooks;

if ($event === "OPENPIX:TRANSACTION_RECEIVED") {}
// vs
if ($payload["event"] === Webhooks::TRANSACTION_RECEIVED_EVENT) {}

@sibelius
Copy link
Member

Expose const on the sdk as well

@edumaciel10
Copy link
Contributor

Expose const on the sdk as well

It's better the sdk handle this complexity than the user handles this. I prefer to use an method to validate it, instead of only some variable!

@edumaciel10
Copy link
Contributor

Example usage

$client->webhooks()->isChargeCompletedPayloadValid($payload) // true or false $client->webhooks()->isTransactionReceivedPayloadValid($payload) // true or false

Remove valid suffix is better, isChargeCompletedPayload

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants