/** * {@inheritDoc} */ public function execute($request) { /** @var $request Capture */ RequestNotSupportedException::assertSupports($this, $request); $details = ArrayObject::ensureArrayObject($request->getModel()); $details->validateNotEmpty('PAYMENTREQUEST_0_PAYMENTACTION'); $details->defaults(array('AUTHORIZE_TOKEN_USERACTION' => Api::USERACTION_COMMIT)); $this->gateway->execute($httpRequest = new GetHttpRequest()); if (isset($httpRequest->query['cancelled'])) { $details['CANCELLED'] = true; return; } if (false == $details['TOKEN']) { if (false == $details['RETURNURL'] && $request->getToken()) { $details['RETURNURL'] = $request->getToken()->getTargetUrl(); } if (false == $details['CANCELURL'] && $request->getToken()) { $details['CANCELURL'] = $request->getToken()->getTargetUrl(); } if (empty($details['PAYMENTREQUEST_0_NOTIFYURL']) && $request->getToken() && $this->tokenFactory) { $notifyToken = $this->tokenFactory->createNotifyToken($request->getToken()->getGatewayName(), $request->getToken()->getDetails()); $details['PAYMENTREQUEST_0_NOTIFYURL'] = $notifyToken->getTargetUrl(); } if ($details['CANCELURL']) { $cancelUrl = Url::createFromUrl($details['CANCELURL']); $query = $cancelUrl->getQuery(); $query->modify(['cancelled' => 1]); $cancelUrl->setQuery($query); $details['CANCELURL'] = (string) $cancelUrl; } $this->gateway->execute(new SetExpressCheckout($details)); if ($details['L_ERRORCODE0']) { return; } } $this->gateway->execute(new Sync($details)); if ($details['PAYERID'] && Api::CHECKOUTSTATUS_PAYMENT_ACTION_NOT_INITIATED == $details['CHECKOUTSTATUS'] && $details['PAYMENTREQUEST_0_AMT'] > 0) { if (Api::USERACTION_COMMIT !== $details['AUTHORIZE_TOKEN_USERACTION']) { $confirmOrder = new ConfirmOrder($request->getFirstModel()); $confirmOrder->setModel($request->getModel()); $this->gateway->execute($confirmOrder); } $this->gateway->execute(new DoExpressCheckoutPayment($details)); } if (false == $details['PAYERID']) { $this->gateway->execute(new AuthorizeToken($details)); } $this->gateway->execute(new Sync($details)); }
/** * @test */ public function shouldGiveControllBackIfHttpRequestPostWithConfirm() { $firstModel = new \stdClass(); $model = new \ArrayObject(['foo' => 'fooVal', 'bar' => 'barVal']); $gatewayMock = $this->createGatewayMock(); $gatewayMock->expects($this->once())->method('execute')->with($this->isInstanceOf(GetHttpRequest::class))->willReturnCallback(function (GetHttpRequest $request) { $request->method = 'POST'; $request->request = ['confirm' => 1]; }); $request = new ConfirmOrder($firstModel); $request->setModel($model); $this->action->setGateway($gatewayMock); $this->action->execute($request); }