{"action":"created","issue":{"url":"https://api.github.com/repos/Payum/Payum/issues/528","repository_url":"https://api.github.com/repos/Payum/Payum","labels_url":"https://api.github.com/repos/Payum/Payum/issues/528/labels{/name}","comments_url":"https://api.github.com/repos/Payum/Payum/issues/528/comments","events_url":"https://api.github.com/repos/Payum/Payum/issues/528/events","html_url":"https://github.com/Payum/Payum/issues/528","id":149496237,"number":528,"title":"StorageExtension is not safe with multiple Gateways","user":{"login":"davidfuhr","id":446054,"avatar_url":"https://avatars.githubusercontent.com/u/446054?v=3","gravatar_id":"","url":"https://api.github.com/users/davidfuhr","html_url":"https://github.com/davidfuhr","followers_url":"https://api.github.com/users/davidfuhr/followers","following_url":"https://api.github.com/users/davidfuhr/following{/other_user}","gists_url":"https://api.github.com/users/davidfuhr/gists{/gist_id}","starred_url":"https://api.github.com/users/davidfuhr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidfuhr/subscriptions","organizations_url":"https://api.github.com/users/davidfuhr/orgs","repos_url":"https://api.github.com/users/davidfuhr/repos","events_url":"https://api.github.com/users/davidfuhr/events{/privacy}","received_events_url":"https://api.github.com/users/davidfuhr/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2016-04-19T15:29:28Z","updated_at":"2016-04-30T20:31:29Z","closed_at":null,"body":"There is only one `StorageExtension` instance per Model which is used in all Gateway instances. The `StorageExtension` keeps the Action Stack Level internally but this only works reliable when used with only one Gateway Instance. This leads to very unexpected behaviour.\r\n\r\nExample\r\n\r\n```php\r\n<?php\r\n//example.php\r\n\r\nrequire __DIR__ . '/vendor/autoload.php';\r\n\r\nuse Payum\\Core\\PayumBuilder;\r\nuse Payum\\Core\\Payum;\r\nuse Payum\\Core\\Model\\Payment;\r\n\r\n$paymentClass = Payment::class;\r\n\r\n/** @var Payum $payum */\r\n$payum = (new PayumBuilder())\r\n    ->addDefaultStorages()\r\n    ->addGateway('aGateway', [\r\n        'factory' => 'offline',\r\n    ])\r\n    ->addGateway('bGateway', [\r\n        'factory' => 'offline',\r\n    ])\r\n    ->getPayum()\r\n;\r\n\r\nheader('Content-Type: text/plain');\r\n\r\nfunction getStorageExtension($gateway)\r\n{\r\n    $r = new ReflectionObject($gateway);\r\n    $p = $r->getProperty('extensions');\r\n    $p->setAccessible(true);\r\n    foreach ($p->getValue($gateway) as $extension) {\r\n        if ($extension instanceof \\Payum\\Core\\Extension\\StorageExtension) {\r\n            return $extension;\r\n        }\r\n    }\r\n}\r\n\r\n$aGateway = $payum->getGateway('aGateway');\r\n$aStorageExtension = getStorageExtension($aGateway);\r\n\r\n$bGateway = $payum->getGateway('bGateway');\r\n$bStorageExtension = getStorageExtension($bGateway);\r\n\r\nvar_dump($aStorageExtension === $bStorageExtension);\r\n// true\r\n```"},"comment":{"url":"https://api.github.com/repos/Payum/Payum/issues/comments/215993098","html_url":"https://github.com/Payum/Payum/issues/528#issuecomment-215993098","issue_url":"https://api.github.com/repos/Payum/Payum/issues/528","id":215993098,"user":{"login":"davidfuhr","id":446054,"avatar_url":"https://avatars.githubusercontent.com/u/446054?v=3","gravatar_id":"","url":"https://api.github.com/users/davidfuhr","html_url":"https://github.com/davidfuhr","followers_url":"https://api.github.com/users/davidfuhr/followers","following_url":"https://api.github.com/users/davidfuhr/following{/other_user}","gists_url":"https://api.github.com/users/davidfuhr/gists{/gist_id}","starred_url":"https://api.github.com/users/davidfuhr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidfuhr/subscriptions","organizations_url":"https://api.github.com/users/davidfuhr/orgs","repos_url":"https://api.github.com/users/davidfuhr/repos","events_url":"https://api.github.com/users/davidfuhr/events{/privacy}","received_events_url":"https://api.github.com/users/davidfuhr/received_events","type":"User","site_admin":false},"created_at":"2016-04-30T20:31:29Z","updated_at":"2016-04-30T20:31:29Z","body":"For my use case it was be solved with #529 because I had two instances of the same gateway name.\r\n\r\nBut it might still be an issue if you trigger `bGateway` in the `postExecute` of `aGateway`. Then after the execution of `bGateway` the storage extension will update all scheduled moduels and changes from `aGateway` will not be persisted anymore because all scheduled models already got persisted."}}