diff --git a/src/Plugin/Payment/Method/PaymentMethodBase.php b/src/Plugin/Payment/Method/PaymentMethodBase.php index 81e2f90..eba0025 100644 --- a/src/Plugin/Payment/Method/PaymentMethodBase.php +++ b/src/Plugin/Payment/Method/PaymentMethodBase.php @@ -240,6 +240,7 @@ abstract class PaymentMethodBase extends PluginBase implements ContainerFactoryP // @todo invoke Rules event. $this->payment->setPaymentStatus($this->paymentStatusManager->createInstance('payment_pending')); $this->doExecutePayment(); + $this->getPayment()->save(); return $this->getPaymentExecutionResult(); } @@ -247,7 +248,10 @@ abstract class PaymentMethodBase extends PluginBase implements ContainerFactoryP /** * Performs the actual payment execution. */ - abstract protected function doExecutePayment(); + protected function doExecutePayment() { + // This method is empty so child classes can override it and provide their + // own implementation. + } /** * {@inheritdoc} diff --git a/src/Response/RedirectResponse.php b/src/Response/RedirectResponse.php deleted file mode 100644 index f908260..0000000 --- a/src/Response/RedirectResponse.php +++ /dev/null @@ -1,28 +0,0 @@ -response = new SymfonyRedirectResponse($url->toString()); - $this->url = $url; - } - -} diff --git a/src/Response/Response.php b/src/Response/Response.php index 5f2d966..3d6c496 100644 --- a/src/Response/Response.php +++ b/src/Response/Response.php @@ -8,6 +8,7 @@ namespace Drupal\payment\Response; use Drupal\Core\Url; +use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Response as SymfonyResponse; /** @@ -51,6 +52,10 @@ class Response implements ResponseInterface { * {@inheritdoc} */ public function getResponse() { + if (!$this->response) { + $this->response = new RedirectResponse($this->url->toString()); + } + return $this->response; } diff --git a/tests/src/Unit/Response/RedirectResponseUnitTest.php b/tests/src/Unit/Response/RedirectResponseUnitTest.php deleted file mode 100644 index 91a908f..0000000 --- a/tests/src/Unit/Response/RedirectResponseUnitTest.php +++ /dev/null @@ -1,74 +0,0 @@ -randomMachineName(); - - $url_generator = $this->getMock('\Drupal\Core\Routing\UrlGeneratorInterface'); - $url_generator->expects($this->atLeastOnce()) - ->method('generateFromRoute') - ->with($route_name) - ->willReturn($this->randomMachineName()); - - $container = new ContainerBuilder(); - $container->set('url_generator', $url_generator); - - \Drupal::setContainer($container); - - $this->redirectUrl = new Url($route_name); - - $this->response = new RedirectResponse($this->redirectUrl); - } - - /** - * @covers ::getRedirectUrl - */ - function testGetRedirectUrl() { - $this->assertSame($this->redirectUrl, $this->response->getRedirectUrl()); - } - - /** - * @covers ::getResponse - */ - function testGetResponse() { - $this->assertInstanceOf('\Symfony\Component\HttpFoundation\RedirectResponse', $this->response->getResponse()); - } - -} diff --git a/tests/src/Unit/Response/ResponseUnitTest.php b/tests/src/Unit/Response/ResponseUnitTest.php index 6dc9c3b..c114de7 100644 --- a/tests/src/Unit/Response/ResponseUnitTest.php +++ b/tests/src/Unit/Response/ResponseUnitTest.php @@ -41,12 +41,21 @@ class ResponseUnitTest extends UnitTestCase { protected $response; /** + * The route name to test with. + * + * @var string + */ + protected $routeName; + + /** * {@inheritdoc} * * @covers ::__construct */ public function setUp() { - $this->redirectUrl = new Url($this->randomMachineName()); + $this->routeName = $this->randomMachineName(); + + $this->redirectUrl = new Url($this->routeName); $this->symfonyResponse = $this->getMockBuilder('\Symfony\Component\HttpFoundation\Response') ->disableOriginalConstructor() @@ -69,4 +78,24 @@ class ResponseUnitTest extends UnitTestCase { $this->assertSame($this->symfonyResponse, $this->response->getResponse()); } + /** + * @covers ::getResponse + */ + function testGetResponseWithoutResponse() { + $url_generator = $this->getMock('\Drupal\Core\Routing\UrlGeneratorInterface'); + $url_generator->expects($this->atLeastOnce()) + ->method('generateFromRoute') + ->with($this->routeName) + ->willReturn($this->randomMachineName()); + + $container = new ContainerBuilder(); + $container->set('url_generator', $url_generator); + + \Drupal::setContainer($container); + + $this->response = new Response($this->redirectUrl); + + $this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $this->response->getResponse()); + } + }