/**
  * {@inheritDoc}
  */
 public function execute($request)
 {
     RequestNotSupportedException::assertSupports($this, $request);
     $details = ArrayObject::ensureArrayObject($request->getModel());
     if ($details['_status'] || $details['_captureCompleted']) {
         return;
     }
     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['notifyUrl']) && $request->getToken() && $this->tokenFactory) {
         $notifyToken = $this->tokenFactory->createNotifyToken($request->getToken()->getGatewayName(), $request->getToken()->getDetails());
         $details['notifyUrl'] = $notifyToken->getTargetUrl();
     }
     if (false == $details['clientIp']) {
         $this->gateway->execute($httpRequest = new GetHttpRequest());
         $details['clientIp'] = $httpRequest->clientIp;
     }
     if ($details['_completeCaptureRequired'] && method_exists($this->omnipayGateway, 'completePurchase')) {
         if (false == $details['_captureCompleted']) {
             $response = $this->omnipayGateway->completePurchase($details->toUnsafeArray())->send();
             $details['_captureCompleted'] = true;
         }
     } else {
         $response = $this->omnipayGateway->purchase($details->toUnsafeArray())->send();
         $details['transactionReference'] = $response->getTransactionReference();
     }
     /** @var \Omnipay\Common\Message\AbstractResponse $response */
     if (false == $response instanceof \Omnipay\Common\Message\AbstractResponse) {
         throw new \LogicException('The bridge supports only responses which extends AbstractResponse. Their ResponseInterface is useless.');
     }
     if ($response->isRedirect()) {
         /** @var \Omnipay\Common\Message\AbstractResponse|\Omnipay\Common\Message\RedirectResponseInterface $response */
         if (false == $response instanceof \Omnipay\Common\Message\RedirectResponseInterface) {
             throw new \LogicException('The omnipay\'s tells its response is redirect but the response instance is not RedirectResponseInterface.');
         }
         $details['_completeCaptureRequired'] = 1;
         if ($response->getRedirectMethod() == 'POST') {
             throw new HttpPostRedirect($response->getRedirectUrl(), $response->getRedirectData());
         } else {
             throw new HttpRedirect($response->getRedirectUrl());
         }
     }
     $data = $response->getData();
     if (is_array($data)) {
         $details->replace($data);
     } else {
         $details['_data'] = $data;
     }
     $details['_reference'] = $response->getTransactionReference();
     $details['_status'] = $response->isSuccessful() ? 'captured' : 'failed';
     $details['_status_code'] = $response->getCode();
     $details['_status_message'] = $response->isSuccessful() ? '' : $response->getMessage();
 }
Example #2
0
 /**
  * {@inheritDoc}
  *
  * @param Update $request
  */
 public function execute($request)
 {
     RequestNotSupportedException::assertSupports($this, $request);
     $details = ArrayObject::ensureArrayObject($request->getModel());
     $klarna = $this->getKlarna();
     try {
         $this->gateway->execute(new PopulateKlarnaFromDetails($details, $klarna));
         $details['updated'] = $klarna->update($details['rno']);
     } catch (\KlarnaException $e) {
         $this->populateDetailsWithError($details, $e, $request);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function execute($request)
 {
     /** @var $request SetExpressCheckout */
     RequestNotSupportedException::assertSupports($this, $request);
     $this->gateway->execute($httpRequest = new GetHttpRequest());
     if ('POST' == $httpRequest->method && false == empty($httpRequest->request['confirm'])) {
         return;
     }
     $renderTemplate = new RenderTemplate($this->templateName, array('model' => ArrayObject::ensureArrayObject($request->getModel()), 'firstModel' => $request->getFirstModel()));
     $this->gateway->execute($renderTemplate);
     throw new HttpResponse($renderTemplate->getResult());
 }
Example #4
0
 /**
  * {@inheritDoc}
  *
  * @param CreditPart $request
  */
 public function execute($request)
 {
     RequestNotSupportedException::assertSupports($this, $request);
     $details = ArrayObject::ensureArrayObject($request->getModel());
     $details->validateNotEmpty(array('invoice_number'));
     $klarna = $this->getKlarna();
     try {
         $this->gateway->execute(new PopulateKlarnaFromDetails($details, $klarna));
         $details['refund_invoice_number'] = $klarna->creditPart($details['invoice_number']);
     } catch (\KlarnaException $e) {
         $this->populateDetailsWithError($details, $e, $request);
     }
 }
Example #5
0
 /**
  * @param string           $name
  * @param GatewayInterface $gateway
  */
 protected function addStorageToGateway($name, GatewayInterface $gateway)
 {
     /** @var Gateway $gateway */
     if (false == $gateway instanceof Gateway) {
         return;
     }
     if (isset($this->initializedStorageExtensions[$name])) {
         return;
     }
     foreach ($this->getStorages() as $storage) {
         $gateway->addExtension(new StorageExtension($storage));
     }
     $this->initializedStorageExtensions[$name] = true;
 }
 /**
  * {@inheritDoc}
  *
  * @param ActivateReservation $request
  */
 public function execute($request)
 {
     RequestNotSupportedException::assertSupports($this, $request);
     $details = ArrayObject::ensureArrayObject($request->getModel());
     $klarna = $this->getKlarna();
     try {
         $this->gateway->execute(new PopulateKlarnaFromDetails($details, $klarna));
         $result = $klarna->activateReservation($details['pno'], $details['rno'], $details['gender'], $details['ocr'], $details['activate_reservation_flags'] ?: \KlarnaFlags::NO_FLAG);
         $details['risk_status'] = $result[0];
         $details['invoice_number'] = $result[1];
     } catch (\KlarnaException $e) {
         $this->populateDetailsWithError($details, $e, $request);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function execute($request)
 {
     /** @var $request DoCapture */
     RequestNotSupportedException::assertSupports($this, $request);
     $model = ArrayObject::ensureArrayObject($request->getModel());
     $paymentRequestN = $request->getPaymentRequestN();
     $fields = new ArrayObject([]);
     foreach ($this->getPaymentRequestNFields() as $field) {
         $fields[$field] = $model['PAYMENTREQUEST_' . $paymentRequestN . '_' . $field];
     }
     $fields['AUTHORIZATIONID'] = $fields['TRANSACTIONID'];
     $fields->validateNotEmpty(['AMT', 'COMPLETETYPE', 'AUTHORIZATIONID']);
     $this->api->doCapture((array) $fields);
     $this->gateway->execute(new GetTransactionDetails($model, $paymentRequestN));
 }
 /**
  * {@inheritDoc}
  */
 public function execute($request)
 {
     RequestNotSupportedException::assertSupports($this, $request);
     $details = ArrayObject::ensureArrayObject($request->getModel());
     if ($details['_status']) {
         return;
     }
     if (false == $details['returnUrl'] && $request->getToken()) {
         $details['returnUrl'] = $request->getToken()->getTargetUrl();
     }
     if (false == $details['cancelUrl'] && $request->getToken()) {
         $details['cancelUrl'] = $request->getToken()->getTargetUrl();
     }
     if (false == $details['clientIp']) {
         $this->gateway->execute($httpRequest = new GetHttpRequest());
         $details['clientIp'] = $httpRequest->clientIp;
     }
     if (isset($details['_completeCaptureRequired'])) {
         $response = $this->omnipayGateway->completePurchase($details->toUnsafeArray())->send();
         unset($details['_completeCaptureRequired']);
     } else {
         $response = $this->omnipayGateway->purchase($details->toUnsafeArray())->send();
     }
     if ($response->isRedirect()) {
         $details['_completeCaptureRequired'] = 1;
         if ($response->getRedirectMethod() == 'POST') {
             throw new HttpPostRedirect($response->getRedirectUrl(), $response->getRedirectData());
         } else {
             throw new HttpRedirect($response->getRedirectUrl());
         }
     }
     $details['_reference'] = $response->getTransactionReference();
     $details['_status'] = $response->isSuccessful() ? 'captured' : 'failed';
     $details['_status_code'] = $response->getCode();
     $details['_status_message'] = $response->isSuccessful() ? '' : $response->getMessage();
 }
Example #9
0
 /**
  * @param GatewayInterface $gateway
  * @param ArrayObject $model
  */
 protected function createCustomer(GatewayInterface $gateway, ArrayObject $model)
 {
     if ($model['customer']) {
         return;
     }
     if (false == ($model['card'] && is_string($model['card']))) {
         return;
     }
     $local = $model->getArray('local');
     if (false == $local['save_card']) {
         return;
     }
     $customer = $local->getArray('customer');
     $customer['card'] = $model['card'];
     $gateway->execute(new CreateCustomer($customer));
     $local['customer'] = $customer->toUnsafeArray();
     $model['local'] = $local->toUnsafeArray();
     unset($model['card']);
     if ($customer['id']) {
         $model['customer'] = $customer['id'];
     } else {
         $model['status'] = Constants::STATUS_FAILED;
     }
 }
Example #10
0
 function it_must_not_dispatch_pre_and_post_payment_state_changed_if_state_not_changed(Request $request, ProcessContextInterface $context, GatewayInterface $gateway, EventDispatcherInterface $eventDispatcher)
 {
     $context->getRequest()->willReturn($request);
     $order = new Order();
     $paymentModel = new Payment();
     $paymentModel->setState(Payment::STATE_COMPLETED);
     $paymentModel->setOrder($order);
     $order->addPayment($paymentModel);
     $gateway->execute(Argument::type(GetStatus::class))->will(function ($args) use($order, $paymentModel) {
         $args[0]->markCaptured();
         $args[0]->setModel($paymentModel);
     });
     $eventDispatcher->dispatch(SyliusCheckoutEvents::PURCHASE_INITIALIZE, Argument::type(GenericEvent::class))->shouldBeCalled();
     $eventDispatcher->dispatch(SyliusCheckoutEvents::PURCHASE_PRE_COMPLETE, Argument::type(GenericEvent::class))->shouldBeCalled();
     $eventDispatcher->dispatch(SyliusCheckoutEvents::PURCHASE_COMPLETE, Argument::type(PurchaseCompleteEvent::class))->shouldBeCalled();
     $this->forwardAction($context)->shouldReturnAnInstanceOf(ActionResult::class);
 }