Handles the response received from the server after payment

@param array $request Data from $_REQUEST
@return Response
@throws \opus\payment\Exception
502623
public function handleResponse(array $request)
    {
        foreach ($this->paymentAdapters as $adapter) {
            $response = new Response($request, $adapter);
            if ($adapter->enabled && $adapter->canHandlePaymentResponse($response)) {
                $adapter->handlePaymentResponse($response);

                $transaction = new Transaction();
                $adapter->loadTransactionFromResponse($response, $transaction);
                $response->setTransaction($transaction);
                return $response;
            }
        }
        throw new Exception("No adapters found that could handle the payment response");
    }
958297
public function handle($request)
    {
        $entity = $this->repository()->findById($request->getId());

        $this->authorize($request, $entity);

        $items = $this->getProperty($entity, $this->field());

        $replace = new ArrayCollection(array_map(
            function($raw) use ($entity) {
                return $this->getRelatedEntity($raw);
            },
            $request->getData()
        ));

        foreach ($items as $key => $item) {
            if (!$replace->contains($item)) {
                $items->remove($key);
            }
        }

        foreach ($replace as $item) {
            if (!$items->contains($item)) {
                $items->add($item);
            }
        }

        $this->setProperty($entity, $this->field(), $items);

        $this->repository()->getEntityManager()->flush($entity);

        return (
            new RelatedCollectionAction(
                $this->repository(),
                $this->mappedBy(),
                $this->related(),
                $this->transformer()
            )
        )->dispatch($request);
    }
178020
public function execute($request)
    {
        RequestNotSupportedException::assertSupports($this, $request);

        /** @var PaymentInterface $payment */
        $payment = $request->getSource();

        $details = ArrayObject::ensureArrayObject($payment->getDetails());
        $details[PayBoxRequestParams::PBX_TOTAL] = $payment->getTotalAmount();
        //TODO : dynamise currency code.
        $details[PayBoxRequestParams::PBX_DEVISE] = '978';
        $details[PayBoxRequestParams::PBX_CMD] = $payment->getNumber();
        $details[PayBoxRequestParams::PBX_PORTEUR] = $payment->getClientEmail();
        $token = $request->getToken();
        $details[PayBoxRequestParams::PBX_EFFECTUE] = $token->getTargetUrl();
        $details[PayBoxRequestParams::PBX_ANNULE] = $token->getTargetUrl();
        $details[PayBoxRequestParams::PBX_REFUSE] = $token->getTargetUrl();
        $dateTime = date("c");
        $details[PayBoxRequestParams::PBX_TIME] = $dateTime;

        $request->setResult((array) $details);
    }
654434
public function toResponse($request)
    {
        return tap(response()->json(
            $this->wrap(
                $this->resource->resolve($request),
                array_merge_recursive(
                    $this->paginationInformation($request),
                    $this->resource->with($request),
                    $this->resource->additional
                )
            ),
            $this->calculateStatus()
        ), function ($response) use ($request) {
            $response->original = $this->resource->resource->pluck('resource');

            $this->resource->withResponse($request, $response);
        });
    }
18593
public function execute($request): void
    {
        RequestNotSupportedException::assertSupports($this, $request);

        /** @var SyliusPaymentInterface $payment */
        $payment = $request->getModel();

        /** @var OrderInterface $order */
        $order = $payment->getOrder();

        $this->gateway->execute($status = new GetStatus($payment));
        if ($status->isNew()) {
            try {
                $this->gateway->execute($convert = new Convert($payment, 'array', $request->getToken()));
                $payment->setDetails($convert->getResult());
            } catch (RequestNotSupportedException $e) {
                $totalAmount = $order->getTotal();
                $payumPayment = new PayumPayment();
                $payumPayment->setNumber($order->getNumber());
                $payumPayment->setTotalAmount($totalAmount);
                $payumPayment->setCurrencyCode($order->getCurrencyCode());
                $payumPayment->setClientEmail($order->getCustomer()->getEmail());
                $payumPayment->setClientId($order->getCustomer()->getId());
                $payumPayment->setDescription($this->paymentDescriptionProvider->getPaymentDescription($payment));
                $payumPayment->setDetails($payment->getDetails());

                $this->gateway->execute($convert = new Convert($payumPayment, 'array', $request->getToken()));
                $payment->setDetails($convert->getResult());
            }
        }

        $details = ArrayObject::ensureArrayObject($payment->getDetails());

        try {
            $request->setModel($details);
            $this->gateway->execute($request);
        } finally {
            $payment->setDetails((array) $details);
        }
    }
1308837
public function execute($request)
    {
        RequestNotSupportedException::assertSupports($this, $request);

        $model = ArrayObject::ensureArrayObject($request->getModel());

        // invalidate:
        // - we process only replied and notified payments
        if (!isset($model['state']) ||
            !in_array(
                $model['state'],
                array(
                    StateInterface::STATE_REPLIED,
                    StateInterface::STATE_NOTIFIED,
                    StateInterface::STATE_CONFIRMED,
                )
            )
        ) {
            // return;
        }

        $httpRequest = new GetHttpRequest;
        $this->gateway->execute($httpRequest);

        if ($httpRequest->method != 'POST') {
            return;
        }

        $status = Api::STATUS_OK;
        $model['state'] = StateInterface::STATE_NOTIFIED;
        $notification = $httpRequest->request;
        $redirectUrl = $model['afterUrl'];
        // check signature hash
        
        if ($this->api->tamperingDetected((array) $notification, (array) $model->toUnsafeArray())) {
            $status = Api::STATUS_INVALID;
            $statusDetails = "Tampering detected. Wrong hash.";
        } else {
            if ($notification['Status'] == Api::STATUS_OK) {
                $model['state'] = StateInterface::STATE_CONFIRMED;
            } elseif ($notification['Status'] == Api::STATUS_PENDING) {
                $model['state'] = StateInterface::STATE_REPLIED;
            } else {
                $model['state'] = StateInterface::STATE_ERROR;
            }

            $statusDetails = 'Transaction processed';

            if ($notification['Status'] == Api::STATUS_ERROR
                && isset($notification['Vendor'])
                && isset($notification['VendorTxCode'])
                && isset($notification['StatusDetail'])
            ) {
                $status = Api::STATUS_ERROR;
                $statusDetails = 'Status of ERROR is seen, together with your Vendor, VendorTxCode and the StatusDetail.';
            }

        }

        $model['notification'] = (array) $notification;
        $model->replace(
            $model->toUnsafeArray()
        );

        $params = array(
            'Status' => $status,
            'StatusDetails' => $statusDetails,
            'RedirectURL' => $redirectUrl,
            );

        throw new NotifyResponse($params);
    }
283556
public function execute($request)
    {
        RequestNotSupportedException::assertSupports($this, $request);

        /** @var PaymentInterface $payment */
        $payment = $request->getSource();

        $details = ArrayObject::ensureArrayObject($payment->getDetails());

        $details['MerchantTradeNo'] = $payment->getNumber();
        $details['TotalAmount'] = $payment->getTotalAmount();
        $details['TradeDesc'] = $payment->getDescription();

        $request->setResult((array) $details);
    }
1241426
public function handle(Request $request)
	{
		// execute response
		$response = $this->next($request);

		// check for presence of callback param
		// if we have one lets replace response content with a function executing the 
		// current response content
		if ($callback = $request->getVar('callback', null))
		{
			$response->headers->set('content-type', 'application/javascript');
			$response->setContent(sprintf('%s(%s);', $callback, $response->getContent()));
		}

		// return response
		return $response;
	}
1198739
public function execute($request)
    {
        RequestNotSupportedException::assertSupports($this, $request);

        /** @var PaymentInterface $payment */
        $payment = $request->getSource();

        /** @var OrderInterface $order */
        $params = [
            'payment_id' => $payment->getNumber(),
            'payment_amount' => $payment->getTotalAmount(),
            'payment_currency' => $payment->getCurrencyCode(),
            'project_id' => $this->api['projectId'],
            'customer_id' => $payment->getClientId(),
        ];
        $request->setResult($params);
    }
1322127
public function callback($request)
    {
        $this->extend('onBeforeCallback');
        
        $data = $this->request->postVars();
        $status = "error";
        $order_id = 0;
        $payment_id = 0;

        $error_url = Controller::join_links(
            Director::absoluteBaseURL(),
            Payment_Controller::config()->url_segment,
            'complete',
            'error'
        );

        // Check if CallBack data exists and install id matches the saved ID
        if (isset($data) && isset($data['custom']) && isset($data['payment_status'])) {
            $order_id = $data['custom'];
            $paypal_request = 'cmd=_notify-validate';
            $final_response = "";
            
            // If the transaction ID is set, keep it
            if (array_key_exists("txn_id", $data)) {
                $payment_id = $data["txn_id"];
            }
            
            $listener = new PaypalIPN();
            
            if (Director::isDev()) {
                $listener->useSandbox();
            }

            try {
                $verified = $listener->verifyIPN();
            } catch (Exception $e) {
                error_log("Unable to verify IPN: " . $e->getMessage());
                return $this->httpError(500);
            }

            if ($verified) {
                // IPN response was "VERIFIED"
                switch ($data['payment_status']) {
                    case 'Canceled_Reversal':
                        $status = "canceled";
                        break;
                    case 'Completed':
                        $status = "paid";
                        break;
                    case 'Denied':
                        $status = "failed";
                        break;
                    case 'Expired':
                        $status = "failed";
                        break;
                    case 'Failed':
                        $status = "failed";
                        break;
                    case 'Pending':
                        $status = "pending";
                        break;
                    case 'Processed':
                        $status = "pending";
                        break;
                    case 'Refunded':
                        $status = "refunded";
                        break;
                    case 'Reversed':
                        $status = "canceled";
                        break;
                    case 'Voided':
                        $status = "canceled";
                        break;
                }
            } else {
                error_log("Invalid payment status");
                return $this->httpError(500);
            }
        } else {
            error_log("No payment details set");
            return $this->httpError(500);
        }
        
        $payment_data = ArrayData::array_to_object(array(
            "OrderID" => $order_id,
            "PaymentProvider" => "PayPal",
            "PaymentID" => $payment_id,
            "Status" => $status,
            "GatewayData" => $data
        ));
        
        $this->setPaymentData($payment_data);
        
        $this->extend('onAfterCallback');
        
        return $this->httpError(200);
    }
883881
public function handle(Request $request)
    {
        if (!$this->booted) {
            $this->bootstrap();
        }

        $this->request = $request;
        $response = new Response();
        return($response);
    }
825053
public function execute($request)
    {
        RequestNotSupportedException::assertSupports($this, $request);

        $model = ArrayObject::ensureArrayObject($request->getModel());
        $request = $model->get('request');
        $signature = $request['signature'];
        unset($request['signature']);

        $mySignature = Signer::sign($request, $this->api['secretKey']);
        if ($mySignature !== $signature) {
            $this->logger->critical('Ecommpay payment signature is invalid');
            throw new BadRequestHttpException();
        }
    }
799375
public function handle($request)
    {
        $entity = $this->repository()->findById($request->getId());
        $this->authorize($request, $entity);

        foreach ($request->getData() as $raw) {
            $item = $this->getRelatedEntity($raw);
            $this->addRelationItem($entity, $this->field(), $item);
        }

        $this->repository()->getEntityManager()->flush($entity);

        return (
            new RelatedCollectionAction(
                $this->repository(),
                $this->mappedBy(),
                $this->related(),
                $this->transformer()
            )
        )->dispatch($request)->setStatusCode(RestResponse::HTTP_CREATED);
    }
1134705
public function handle(Request $request)
	{
		$response = $this->next($request);

		// If CLI then we have to gather all query, post and header values
		// into params for Oauth_Provider's constructor.
		$params = array();

		if ($this->app->runningInConsole())
		{
			$queryvars = $this->app['request']->get('queryvars');
			$postvars  = $this->app['request']->get('postdata');

			if (!empty($queryvars))
			{
				foreach ($queryvars as $key => $value)
				{
					if (isset($queryvars[$key]))
					{
						$params[$key] = $queryvars[$key];
					}
					else if (isset($postvars[$key]))
					{
						$params[$key] = $postvars[$key];
					}
				}
			}

			if (!empty($postvars))
			{
				foreach ($postvars as $key => $value)
				{
					if (isset($queryvars[$key]))
					{
						$params[$key] = $queryvars[$key];
					}
					else if (isset($postvars[$key]))
					{
						$params[$key] = $postvars[$key];
					}
				}
			}

			if (empty($params))
			{
				return false;
			}
		}

		$this->app['authn'] = $this->app['auth']->authenticate($params);

		$this->app['request']->setVar('validApiKey', !empty($this->app['authn']['consumer_key']));

		return $response;
	}
1261442
public function handleClientRequest($request)
    {
        $this->client_data->path = $request->server['path_info'];
        $route = explode('/', $request->server['path_info']);
        $count = count($route);
        if ($count == 2) {
            $this->client_data->controller_name = $route[$count - 1] ?? null;
            $this->client_data->method_name = null;
            return;
        }
        $this->client_data->method_name = $route[$count - 1] ?? null;
        unset($route[$count - 1]);
        unset($route[0]);
        $this->client_data->controller_name = implode("\\", $route);
    }
1286806
public function handle(Request $request) : Response
	{
		if ($result = $this->handleContext($request, $this->rootContext)) {
			return $result;
		}
		
		if ($defaultHandler = $this->rootContext->getDefault()) {
			return $this->resultToResponse(
				call_user_func($defaultHandler, $request, null)
			);
		}
		
		throw new Exception('No matching route found. Set a default handler on root context to cover this case.');
	}
976047
public function handle(Request $request)
	{
		// execute response
		$response = $this->next($request);

		// only do on json data
		if (!$response->isJson())
		{
			return $response;
		}

		// get the response content and json decode
		$content = json_decode($response->getContent());

		// get date keys from response options
		$this->dateKeys = array_merge(
			$this->dateKeys,
			$response->getTransformKeys('dates')
		);

		// make sure to handle array different then a single object
		if (is_array($content))
		{
			// loop through each item in array and covert dates
			foreach ($content as $key => $value)
			{
				$content[$key] = $this->convertDateKeysInObjects($value);
			}
		}
		else
		{
			// convert single object dates
			$content = $this->convertDateKeysInObjects($content);
		}

		// set the response content to modified content
		$response->setContent(json_encode($content));

		// return response
		return $response;
	}