From 0ef4220b0cafda74ff8b3f61a0651e56689f9a48 Mon Sep 17 00:00:00 2001 From: Glauber Silva Date: Fri, 10 Jan 2025 16:05:44 -0300 Subject: [PATCH 1/4] refactor: simplify OffSiteGatewayWebhookNotificationHandler class --- src/OffSiteGateway/Gateway/OffSiteGateway.php | 1 - ...fSiteGatewayWebhookNotificationHandler.php | 32 +++++++++++++------ .../OffSiteGatewayServiceProvider.php | 10 ------ 3 files changed, 23 insertions(+), 20 deletions(-) rename src/OffSiteGateway/{Webhooks => Gateway}/OffSiteGatewayWebhookNotificationHandler.php (71%) diff --git a/src/OffSiteGateway/Gateway/OffSiteGateway.php b/src/OffSiteGateway/Gateway/OffSiteGateway.php index 94f2dd5..277e494 100644 --- a/src/OffSiteGateway/Gateway/OffSiteGateway.php +++ b/src/OffSiteGateway/Gateway/OffSiteGateway.php @@ -14,7 +14,6 @@ use Give\Framework\Support\Facades\Scripts\ScriptAsset; use GiveAddon\OffSiteGateway\DataTransferObjects\OffSiteGatewayPayment; use GiveAddon\OffSiteGateway\DataTransferObjects\OffSiteGatewayWebhookNotification; -use GiveAddon\OffSiteGateway\Webhooks\OffSiteGatewayWebhookNotificationHandler; /** * @since 1.0.0 diff --git a/src/OffSiteGateway/Webhooks/OffSiteGatewayWebhookNotificationHandler.php b/src/OffSiteGateway/Gateway/OffSiteGatewayWebhookNotificationHandler.php similarity index 71% rename from src/OffSiteGateway/Webhooks/OffSiteGatewayWebhookNotificationHandler.php rename to src/OffSiteGateway/Gateway/OffSiteGatewayWebhookNotificationHandler.php index 65b4671..c743988 100644 --- a/src/OffSiteGateway/Webhooks/OffSiteGatewayWebhookNotificationHandler.php +++ b/src/OffSiteGateway/Gateway/OffSiteGatewayWebhookNotificationHandler.php @@ -1,10 +1,9 @@ gatewayPaymentStatus)) { case 'complete': - AsBackgroundJobs::enqueueAsyncAction( - 'givewp_' . OffSiteGateway::id() . '_event_donation_completed', - [$webhookNotification->gatewayPaymentId], - 'ADDON_TEXTDOMAIN' + // Handling completed transactions... + OffSiteGateway::webhookEvents()->setDonationStatus( + DonationStatus::COMPLETE(), + $webhookNotification->gatewayPaymentId ); /** @@ -71,10 +70,25 @@ public function __invoke(OffSiteGatewayWebhookNotification $webhookNotification) setDonationStatus( + DonationStatus::FAILED(), + $webhookNotification->gatewayPaymentId + ); break; case 'cancelled': - // Handle cancelled transactions here... + // Handling cancelled transactions... + OffSiteGateway::webhookEvents()->setDonationStatus( + DonationStatus::CANCELLED(), + $webhookNotification->gatewayPaymentId + ); + break; + case 'refunded': + // Handling refunded transactions... + OffSiteGateway::webhookEvents()->setDonationStatus( + DonationStatus::REFUNDED(), + $webhookNotification->gatewayPaymentId + ); break; default: break; diff --git a/src/OffSiteGateway/OffSiteGatewayServiceProvider.php b/src/OffSiteGateway/OffSiteGatewayServiceProvider.php index 8e951ce..44e0aaf 100644 --- a/src/OffSiteGateway/OffSiteGatewayServiceProvider.php +++ b/src/OffSiteGateway/OffSiteGatewayServiceProvider.php @@ -4,7 +4,6 @@ use Exception; use Give\Framework\PaymentGateways\PaymentGatewayRegister; -use Give\Framework\PaymentGateways\Webhooks\EventHandlers\DonationCompleted; use Give\Helpers\Hooks; use Give\ServiceProviders\ServiceProvider; use GiveAddon\OffSiteGateway\Gateway\OffSiteCheckoutPageSimulation; @@ -37,15 +36,6 @@ function (PaymentGatewayRegister $registrar) { } ); - /** - * We are using the DonationCompleted event handler class provided by Give Core to process the - * async background event which is created on the OffSiteGatewayWebhookNotificationHandler class. - * - * A full list of event handler classes can be found on the following link: - * @see https://github.com/impress-org/givewp/tree/develop/src/Framework/PaymentGateways/Webhooks/EventHandlers - */ - Hooks::addAction('givewp_' . OffSiteGateway::id() . '_event_donation_completed', DonationCompleted::class); - /** * IMPORTANT: remember to remove this hook when removing the OffSiteCheckoutPageSimulation class from your real-world gateway integration. */ From 254897aebd4fa5d1c0a1ed44831bf70e9594ba90 Mon Sep 17 00:00:00 2001 From: Glauber Silva Date: Fri, 10 Jan 2025 17:00:53 -0300 Subject: [PATCH 2/4] chore: update branch on git workflow temporally --- .github/workflows/unit-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index f703b22..f24adda 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -11,4 +11,4 @@ jobs: uses: impress-org/givewp-github-actions/.github/workflows/addon-tests.yml@master with: addon_slug: ADDON_ID - givewp_branch: develop + givewp_branch: fun/gateway-webhook-events-api From 6ef2317f4bc896601296bce9857464b0fb612996 Mon Sep 17 00:00:00 2001 From: Glauber Silva Date: Fri, 10 Jan 2025 18:28:26 -0300 Subject: [PATCH 3/4] chore: update composer.lock --- composer.lock | 88 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 59 insertions(+), 29 deletions(-) diff --git a/composer.lock b/composer.lock index 008f129..32daf50 100644 --- a/composer.lock +++ b/composer.lock @@ -295,28 +295,28 @@ }, { "name": "phpcompatibility/phpcompatibility-paragonie", - "version": "1.3.2", + "version": "1.3.3", "source": { "type": "git", "url": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie.git", - "reference": "bba5a9dfec7fcfbd679cfaf611d86b4d3759da26" + "reference": "293975b465e0e709b571cbf0c957c6c0a7b9a2ac" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityParagonie/zipball/bba5a9dfec7fcfbd679cfaf611d86b4d3759da26", - "reference": "bba5a9dfec7fcfbd679cfaf611d86b4d3759da26", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityParagonie/zipball/293975b465e0e709b571cbf0c957c6c0a7b9a2ac", + "reference": "293975b465e0e709b571cbf0c957c6c0a7b9a2ac", "shasum": "" }, "require": { "phpcompatibility/php-compatibility": "^9.0" }, "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.7", + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", "paragonie/random_compat": "dev-master", "paragonie/sodium_compat": "dev-master" }, "suggest": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", + "dealerdirect/phpcodesniffer-composer-installer": "^1.0 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." }, "type": "phpcodesniffer-standard", @@ -346,22 +346,37 @@ ], "support": { "issues": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie/issues", + "security": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie/security/policy", "source": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie" }, - "time": "2022-10-25T01:46:02+00:00" + "funding": [ + { + "url": "https://github.com/PHPCompatibility", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2024-04-24T21:30:46+00:00" }, { "name": "phpcompatibility/phpcompatibility-wp", - "version": "2.1.4", + "version": "2.1.5", "source": { "type": "git", "url": "https://github.com/PHPCompatibility/PHPCompatibilityWP.git", - "reference": "b6c1e3ee1c35de6c41a511d5eb9bd03e447480a5" + "reference": "01c1ff2704a58e46f0cb1ca9d06aee07b3589082" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityWP/zipball/b6c1e3ee1c35de6c41a511d5eb9bd03e447480a5", - "reference": "b6c1e3ee1c35de6c41a511d5eb9bd03e447480a5", + "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityWP/zipball/01c1ff2704a58e46f0cb1ca9d06aee07b3589082", + "reference": "01c1ff2704a58e46f0cb1ca9d06aee07b3589082", "shasum": "" }, "require": { @@ -369,10 +384,10 @@ "phpcompatibility/phpcompatibility-paragonie": "^1.0" }, "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.7" + "dealerdirect/phpcodesniffer-composer-installer": "^1.0" }, "suggest": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", + "dealerdirect/phpcodesniffer-composer-installer": "^1.0 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." }, "type": "phpcodesniffer-standard", @@ -401,9 +416,24 @@ ], "support": { "issues": "https://github.com/PHPCompatibility/PHPCompatibilityWP/issues", + "security": "https://github.com/PHPCompatibility/PHPCompatibilityWP/security/policy", "source": "https://github.com/PHPCompatibility/PHPCompatibilityWP" }, - "time": "2022-10-24T09:00:36+00:00" + "funding": [ + { + "url": "https://github.com/PHPCompatibility", + "type": "github" + }, + { + "url": "https://github.com/jrfnl", + "type": "github" + }, + { + "url": "https://opencollective.com/php_codesniffer", + "type": "open_collective" + } + ], + "time": "2024-04-24T21:37:59+00:00" }, { "name": "phpdocumentor/reflection-common", @@ -1619,16 +1649,16 @@ }, { "name": "squizlabs/php_codesniffer", - "version": "3.9.1", + "version": "3.11.2", "source": { "type": "git", "url": "https://github.com/PHPCSStandards/PHP_CodeSniffer.git", - "reference": "267a4405fff1d9c847134db3a3c92f1ab7f77909" + "reference": "1368f4a58c3c52114b86b1abe8f4098869cb0079" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/267a4405fff1d9c847134db3a3c92f1ab7f77909", - "reference": "267a4405fff1d9c847134db3a3c92f1ab7f77909", + "url": "https://api.github.com/repos/PHPCSStandards/PHP_CodeSniffer/zipball/1368f4a58c3c52114b86b1abe8f4098869cb0079", + "reference": "1368f4a58c3c52114b86b1abe8f4098869cb0079", "shasum": "" }, "require": { @@ -1695,7 +1725,7 @@ "type": "open_collective" } ], - "time": "2024-03-31T21:03:09+00:00" + "time": "2024-12-11T16:04:26+00:00" }, { "name": "symfony/polyfill-ctype", @@ -1719,12 +1749,12 @@ }, "type": "library", "extra": { + "thanks": { + "url": "https://github.com/symfony/polyfill", + "name": "symfony/polyfill" + }, "branch-alias": { "dev-main": "1.19-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" } }, "autoload": { @@ -1940,16 +1970,16 @@ }, { "name": "yoast/phpunit-polyfills", - "version": "1.1.1", + "version": "1.1.3", "source": { "type": "git", "url": "https://github.com/Yoast/PHPUnit-Polyfills.git", - "reference": "a0f7d708794a738f328d7b6c94380fd1d6c40446" + "reference": "0b31ce834facf03b8b44b6587e65b3cf1d7cfb94" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Yoast/PHPUnit-Polyfills/zipball/a0f7d708794a738f328d7b6c94380fd1d6c40446", - "reference": "a0f7d708794a738f328d7b6c94380fd1d6c40446", + "url": "https://api.github.com/repos/Yoast/PHPUnit-Polyfills/zipball/0b31ce834facf03b8b44b6587e65b3cf1d7cfb94", + "reference": "0b31ce834facf03b8b44b6587e65b3cf1d7cfb94", "shasum": "" }, "require": { @@ -1964,7 +1994,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "2.x-dev" + "dev-main": "3.x-dev" } }, "autoload": { @@ -1999,7 +2029,7 @@ "security": "https://github.com/Yoast/PHPUnit-Polyfills/security/policy", "source": "https://github.com/Yoast/PHPUnit-Polyfills" }, - "time": "2024-04-05T16:01:51+00:00" + "time": "2025-01-08T16:58:34+00:00" } ], "aliases": [], From 1d4d520c422f22019933378141141a0c7ba0c016 Mon Sep 17 00:00:00 2001 From: Glauber Silva Date: Fri, 10 Jan 2025 18:40:31 -0300 Subject: [PATCH 4/4] chore: rollback givewp branch to develop --- .github/workflows/unit-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index f24adda..f703b22 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -11,4 +11,4 @@ jobs: uses: impress-org/givewp-github-actions/.github/workflows/addon-tests.yml@master with: addon_slug: ADDON_ID - givewp_branch: fun/gateway-webhook-events-api + givewp_branch: develop