-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #73 Webhooks final fix (Zales0123)
This PR was merged into the main branch. Discussion ---------- So, the problem with webhooks was the (highly possible, as tests on production shown) possibility to handle the payment by webhook **and** synchronously at the same time. Because Payum jumps between different URLs and is not because of that _transactional_, it was impossible to wrap both webhook and synchronous logic in a transaction. So, after many trials and failures, I've come up with an implementation that marks the payment as already handled by one of these processes and uses the lock to control access to the service that marks the payment. As a result, depending on which process starts first (synchronous or asynchronous), the first would pass, marking a payment as being processed, while the latter would see the information the payment is already handled by the other process. As far as I understand, we have only 2 places in the code where the payment processing can start: `WebhookAction` and `PrepareAssertAction` - that's why I've put the locking logic into them. I've also added a lot of logging to make it easier to test on prod 🚀 This PR requires a lot of testing (on the prod environment!), to see if there are any other places where it fails 🖖 Commits ------- 6d70332 Webhooks final fix 7e044d5 Minor fixes b8cd71c Bump lock version 5ebd51f Handle it properly on capture b439488 Fix tests and coding standards
- Loading branch information
Showing
29 changed files
with
345 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
framework: | ||
lock: ~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
|
||
return static function (ContainerConfigurator $containerConfigurator) { | ||
$containerConfigurator->extension('monolog', [ | ||
'channels' => ['saferpay'], | ||
'handlers' => [ | ||
'main' => [ | ||
'type' => 'stream', | ||
'path' => '%kernel.logs_dir%/%kernel.environment%.log', | ||
'level' => 'debug', | ||
'channels' => ['!event', '!doctrine'], | ||
], | ||
'saferpay' => [ | ||
'type' => 'stream', | ||
'path' => '%kernel.logs_dir%/saferpay.log', | ||
'level' => 'debug', | ||
'channels' => ['saferpay'], | ||
], | ||
], | ||
]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,13 +57,14 @@ function it_creates_body_for_authorize_request( | |
$payment->getCurrencyCode()->willReturn('CHF'); | ||
$order->getNumber()->willReturn('000000001'); | ||
$order->getCustomer()->willReturn($customer); | ||
$order->getTokenValue()->willReturn('TOKEN'); | ||
$customer->getEmail()->willReturn('[email protected]'); | ||
|
||
$token->getAfterUrl()->willReturn('https://example.com/after'); | ||
|
||
$tokenProvider->provideForWebhook($payment, 'commerce_weavers_sylius_saferpay_webhook')->willReturn($webhookToken); | ||
$webhookToken->getHash()->willReturn('webhook_hash'); | ||
$webhookRouteGenerator->generate('webhook_hash')->willReturn('https://example.com/webhook'); | ||
$webhookRouteGenerator->generate('webhook_hash', 'TOKEN')->willReturn('https://example.com/webhook'); | ||
|
||
$this->createForAuthorize($payment, $token)->shouldReturn([ | ||
'RequestHeader' => [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.