Create new pogseguro payment session data

@param $response
438690
private function makeSession($response)
    {
        $this->session()->setData([
            'pagseguro_payment' => ['payment_link' => $response->getPaymentLink(),
                'payment_type'  => strtolower(Boleto::class),
                'order_id'      => $this->lastRealOrderId(),
            ]
        ]);
    }
1322969
protected function _httpAuthenticate(Varien_Object $response)
    {
        $result = array(
            'authentication' => false,
            'message' => ''
        );

        $this->fixCgiHttpAuthentication(); //add cgi support
        $internalMerchantAccount = $this->_getConfigData('merchantAccount');
        $username = $this->_getConfigData('notification_username');
        $password = Mage::helper('core')->decrypt($this->_getConfigData('notification_password'));
        $submitedMerchantAccount = $response->getData('merchantAccountCode');

        if (empty($submitedMerchantAccount) && empty($internalMerchantAccount)) {
            if (strtolower(
                substr(
                    $response->getData('pspReference'), 0,
                    17
                )
            ) == "testnotification_" || strtolower(
                substr(
                    $response->getData('pspReference'), 0,
                    5
                )
            ) == "test_") {
                Mage::log(
                    'Notification test failed: merchantAccountCode is empty in magento settings', Zend_Log::DEBUG,
                    "adyen_notification.log", true
                );
                $result['message'] = 'merchantAccountCode is empty in magento settings';
            }

            return $result;
        }

        // validate username and password
        if ((!isset($_SERVER['PHP_AUTH_USER']) && !isset($_SERVER['PHP_AUTH_PW']))) {
            if (strtolower(
                substr(
                    $response->getData('pspReference'), 0,
                    17
                )
            ) == "testnotification_" || strtolower(
                substr(
                    $response->getData('pspReference'), 0,
                    5
                )
            ) == "test_") {
                Mage::log(
                    'Authentication failed: PHP_AUTH_USER and PHP_AUTH_PW are empty. See Adyen Magento manual CGI mode',
                    Zend_Log::DEBUG, "adyen_notification.log", true
                );
                $result['message'] = 'Authentication failed: PHP_AUTH_USER and PHP_AUTH_PW are empty. See Adyen Magento manual CGI mode';
            }

            return $result;
        }

        $accountCmp = !$this->_getConfigData('multiple_merchants')
            ? strcmp($submitedMerchantAccount, $internalMerchantAccount)
            : 0;
        $usernameCmp = strcmp($_SERVER['PHP_AUTH_USER'], $username);
        $passwordCmp = strcmp($_SERVER['PHP_AUTH_PW'], $password);
        if ($accountCmp === 0 && $usernameCmp === 0 && $passwordCmp === 0) {
            $result['authentication'] = true;
            return $result;
        }

        // If notification is test check if fields are correct if not return error
        if (strtolower(
            substr(
                $response->getData('pspReference'), 0,
                17
            )
        ) == "testnotification_" || strtolower(
            substr(
                $response->getData('pspReference'), 0,
                5
            )
        ) == "test_") {
            if ($accountCmp != 0) {
                $result['message'] = "MerchantAccount in notification is not the same as in Magento settings and Allow multiple merchants option is not enabled";
            } elseif ($usernameCmp != 0 || $passwordCmp != 0) {
                $result['message'] = "username (PHP_AUTH_USER) and/or password (PHP_AUTH_PW) are not the same as Magento settings";
            }

            Mage::log($result['message'], Zend_Log::DEBUG, "adyen_notification.log", true);
        }

        return $result;
    }
935061
protected function createPayment($response)
    {
        $payment = oxNew(\OxidEsales\PayPalModule\Model\OrderPayment::class);
        $payment->setDate($this->getDate());
        $payment->setTransactionId($response->getTransactionId());
        $payment->setCorrelationId($response->getCorrelationId());
        $payment->setAction('capture');
        $payment->setStatus($response->getPaymentStatus());
        $payment->setAmount($response->getCapturedAmount());
        $payment->setCurrency($response->getCurrency());

        return $payment;
    }
748808
protected function _modifyAfterCreate($response, $request) {
        if (!$this->_methodFailed($response)) {
            // figure out model name (request.method)
            $methodParts = explode('.', $request['method']);
            $modelClass  = Garp_Content_Api::modelAliasToClass(array_shift($methodParts));
            $model = new $modelClass();
            // combine primary keys to query params
            $primaryKey = array_values((array)$model->info(Zend_Db_Table::PRIMARY));
            $primaryKeyValues = array_values((array)$response['result']);
            $query = array();
            foreach ($primaryKey as $i => $key) {
                $query[$key] = $primaryKeyValues[$i];
            }
            // find the newly inserted rows
            $man = new Garp_Content_Manager(get_class($model));
            $rows = $man->fetch(array('query' => $query));
            $response['result'] = array(
                'rows' => $rows
            );
        }
        return $response;
    }
840598
function process_response($request, $response)
    {
        if (! isset($request->user) || $request->user->isAnonymous()) {
            return $response;
        }
        if ($request->user_space->touched) {
            if ($request->user_space->id > 0) {
                $request->user_space->update();
            } else {
                $request->user_space->create();
            }
        }
        return $response;
    }
1193608
public static function createFromJson(array $response)
    {
        $meta       = array_key_exists('meta', $response)       ? $response['meta']       : ['code' => 200];
        $data       = array_key_exists('data', $response)       ? $response['data']       : $response;
        $pagination = array_key_exists('pagination', $response) ? $response['pagination'] : [];

        return new static($meta, $data, $pagination);
    }
97913
private function buildResponse($event, $response) {
        $success = !$response->hasErrors();
        $duplicate = ($response->code == 409);
        $statusCode = $response->code;
        $errorMessage = null;
        if ($response->code == 401) {
            $errorMessage = 'Unauthorised. Please check your Project Id and API Key';
        }
        if ($response->body != null && $response->body->errorMessage != null) {
            $errorMessage = $response->body->errorMessage;
        }
        return new Response($success, $duplicate, $statusCode, $errorMessage, $event);
    }
1366178
protected function populate(stdClass $response)
    {
        $customer = clone $this;
        $customer->data = new stdClass();
        $customer->data->id = $this->getIfSet('id', $response);
        $customer->data->ownId = $this->getIfSet('ownId', $response);
        $customer->data->fullname = $this->getIfSet('fullname', $response);
        $customer->data->email = $this->getIfSet('email', $response);
        $customer->data->phone = new stdClass();

        $phone = $this->getIfSet('phone', $response);

        $customer->data->phone->countryCode = $this->getIfSet('countryCode', $phone);
        $customer->data->phone->areaCode = $this->getIfSet('areaCode', $phone);
        $customer->data->phone->number = $this->getIfSet('number', $phone);
        $customer->data->birthDate = $this->getIfSet('birthDate', $response);
        $customer->data->taxDocument = new stdClass();
        $customer->data->taxDocument->type = $this->getIfSet('type', $this->getIfSet('taxDocument', $response));
        $customer->data->taxDocument->number = $this->getIfSet('number', $this->getIfSet('taxDocument', $response));
        $customer->data->addresses = [];
        $customer->data->shippingAddress = $this->getIfSet('shippingAddress', $response);
        $customer->data->billingAddress = $this->getIfSet('billingAddress', $response);
        $customer->data->fundingInstrument = $this->getIfSet('fundingInstrument', $response);

        $customer->data->_links = $this->getIfSet('_links', $response);

        return $customer;
    }
700649
public function makeSingle(Response $response)
    {
        if (!$response->getSuccess()) {
            return null;
        }

        $result = $this->getResultFromResponse($response);

        return $result[0] ?? null;
    }
774961
private function _createOffer(array $response)
    {
        $model = new Offer();
        $model->setId($response['id']);
        $model->setName($response['name']);
        $model->setAmount($response['amount']);
        $model->setCurrency($response['currency']);
        $model->setInterval($response['interval']);
        $model->setTrialPeriodDays($response['trial_period_days']);
        $model->setCreatedAt($response['created_at']);
        $model->setUpdatedAt($response['updated_at']);
        $model->setSubscriptionCount($response['subscription_count']['active'], $response['subscription_count']['inactive']);
        $model->setAppId($response['app_id']);
        return $model;
    }
1288129
public static function create(DmmResponse $response)
    {
        $data = $response->getDecodedBody();

        $code = isset($data['status']) ? $data['status'] : null;
        $message = isset($data['message']) ? $data['message'] : 'Unknown error from API.';

        // All others
        return new static($response, new DmmOtherException($message, $code));
    }
616575
public function makeSingle(Response $response)
    {
        if (!$response->getSuccess()) {
            return null;
        }

        $result = [];
        $data   = $response->getData();
        foreach ($data as $type => $items) {
            switch ($type) {
                case 'attributes':
                    $result[$type] = (new FacetAttributesMapper())->createObject($items);
                    break;
                case 'priceRange':
                    $result[$type] = $items;
                    break;
                case 'factorValues':
                    $mapper        = new FactorValuesMapper();
                    $result[$type] = $this->createList($mapper, $items);
                    break;
                case 'functionalNames' :
                    $mapper = new FunctionalNamesMapper();
                    $result[$type] = $this->createList($mapper, $items);
                    break;
                case 'brands' :
                    $mapper = new BrandsMapper();
                    $result[$type] = $this->createList($mapper, $items);
                    break;
                case 'productGroups' :
                    $mapper = new ProductGroupsMapper();
                    $result[$type] = $this->createList($mapper, $items);
                    break;

            }
        }

        return $result;
    }
739253
public function modifyResponse(Request $request, Response $response)
    {
        if ($this->isCollect() === false) {
            return;
        }

        // if ($this -> created) {
        //     return;
        // }

        $app = $this->app;


        if ($app->runningInConsole() || !$this->isEnabled() || $this->isMyselfRequest()) {
            return $response;
        }

        // Show the Http Response Exception, when available
        if (isset($response->exception)) {
            $this->addThrowable($response->exception);
        }

        /**---------------------------------------------------------
         *   Display config settings
         *---------------------------------------------------------*/

        if ($this->shouldCollect('config', false)) {
            try {
                $configCollector = new ConfigCollector();
                $configCollector->setData($app['config']->all());
                $this->addCollector($configCollector);
            } catch (\Exception $e) {
                $this->addThrowable(
                    new Exception(
                        'Cannot add ConfigCollector to SongshenzongLog: ' . $e->getMessage(),
                        $e->getCode(),
                        $e
                    )
                );
            }
        }


        if ($this->app->bound(SessionManager::class)) {

            /** @var \Illuminate\Session\SessionManager $sessionManager */
            $sessionManager = $app->make(SessionManager::class);
            $httpDriver     = new SymfonyHttpDriver($sessionManager, $response);
            $this->setHttpDriver($httpDriver);

            if ($this->shouldCollect('session') && !$this->hasCollector('session')) {
                try {
                    $this->addCollector(new SessionCollector($sessionManager));
                } catch (\Exception $e) {
                    $this->addThrowable(
                        new Exception(
                            'Cannot add SessionCollector to SongshenzongLog: ' . $e->getMessage(),
                            $e->getCode(),
                            $e
                        )
                    );
                }
            }
        } else {
            $sessionManager = null;
        }


        /**---------------------------------------------------------
         *   Only one can be enabled.
         *---------------------------------------------------------*/
        if ($this->shouldCollect('request', true) && !$this->hasCollector('request')) {
            try {
                $this->addCollector(new RequestCollector($request, $response, $sessionManager));
            } catch (\Exception $e) {
                $this->addThrowable(
                    new Exception(
                        'Cannot add RequestCollector to SongshenzongLog: ' . $e->getMessage(),
                        $e->getCode(),
                        $e
                    )
                );
            }
        }


        /**---------------------------------------------------------
         *   Just collect + store data
         *---------------------------------------------------------*/
        try {
            $this->collect();
        } catch (\Exception $e) {
            $app['log']->error('Songshenzong exception: ' . $e->getMessage());
        }


        return $response;
    }
908248
public function createAction(Request $request)
    {
        $entity = new Contract();
        $form = $this->createCreateForm($entity);
        $planForm = $this->createForm(new PlanType(), new Plan(), array(
            'action' => $this->generateUrl('ecommerce_plan_new'),
            'method' => 'POST',
        ));
        
        $form->handleRequest($request);

        if ($form->isValid()) {
            
            //check payment method
            $data = $form->getNormData();
            print_r($data);die();
            
            $em = $this->getDoctrine()->getManager();
            
            
            
            $agreement = $entity->getAgreement();
            $agreement->setContract($entity);
            $agreement->setStatus('Created');
            
            
            try {
                $em->persist($entity);
                $em->persist($entity->getAgreement());
                $em->flush();
              
            } catch (\Exception $exc) {
                $this->get('session')->getFlashBag()->add('danger', 'contract.duplicated');
            }
            
           
            
            //paypal workflow
            $checkoutManager = $this->get('checkout_manager');
            //create agreement paypal
            $creditCard = $form->getNormData()->getAgreement()->getCreditCard();
            $cc = array(
                "number" => $creditCard['cardNo'],
                "type" => $creditCard['cardType'],
                "expire_month" => $creditCard['expirationDate']->format('m'),
                "expire_year" =>  $creditCard['expirationDate']->format('Y'),
                "cvv2" =>  $creditCard['CVV'],
                "first_name" => $creditCard['firstname'],
                "last_name" => $creditCard['lastname']
            );  
            $payPalAgreement = $checkoutManager->createPaypalAgreement($entity->getAgreement(), $cc);

            if($entity->getAgreement()->getPaymentMethod() == 'paypal'){
                $this->get('session')->getFlashBag()->add('success', 'contract.created.approval');
                $transactions = $entity->getAgreement()->getTransactions();
                return $this->redirect($this->generateUrl('ecommerce_transaction_show', array('id' => $transactions->last()->getId())));

            }else {
                $this->get('session')->getFlashBag()->add('success', 'contract.created');
            }

            return $this->redirect($this->generateUrl('ecommerce_contract_show', array('id' => $entity->getId())));

        }

        return array(
            'entity' => $entity,
            'form'   => $form->createView(),
            'planForm' => $planForm->createView(),
        );
    }
960976
private function _createTransaction(array $response)
    {
        $model = new Transaction();
        $model->setId($response['id']);
        $model->setAmount($response['amount']);
        $model->setOriginAmount($response['origin_amount']);
        $model->setStatus($response['status']);
        $model->setDescription($response['description']);
        $model->setLivemode($response['livemode']);
        $model->setRefunds($this->_handleRecursive($response['refunds'], 'refund'));
        $model->setCurrency($response['currency']);
        $model->setCreatedAt($response['created_at']);
        $model->setUpdatedAt($response['updated_at']);
        $model->setResponseCode($response['response_code']);
        $model->setShortId($response['short_id']);
        $model->setInvoices($response['invoices']);
        $model->setPayment($this->_convertResponseToModel($response['payment'], "payment"));
        $model->setClient($this->_convertResponseToModel($response['client'], "client"));
        $model->setPreauthorization($this->_convertResponseToModel($response['preauthorization'], "preauthorization"));
        $model->setFees($response['fees']);
        $model->setAppId($response['app_id']);

        if (isset($response[Transaction::RESPONSE_FIELD_SHIPPING_ADDRESS])) {
            $model->setShippingAddress(
                $this->_convertResponseToModel(
                    $response[Transaction::RESPONSE_FIELD_SHIPPING_ADDRESS],
                    AbstractAddress::TYPE_SHIPPING
                )
            );
        }

        if (isset($response[Transaction::RESPONSE_FIELD_BILLING_ADDRESS])) {
            $model->setBillingAddress(
                $this->_convertResponseToModel(
                    $response[Transaction::RESPONSE_FIELD_BILLING_ADDRESS],
                    AbstractAddress::TYPE_BILLING
                )
            );
        }

        if (isset($response[Transaction::RESPONSE_FIELD_ITEMS])) {
            $model->setItems($this->_handleRecursive($response[Transaction::RESPONSE_FIELD_ITEMS], 'item'));
        }

        return $model;
    }
853772
public function handleResponse($response) {

        // No filter has been applied to this request.
        // Standard request, instantiate a single object.
        if(empty($this->filter)) {
            return $this->instantiateEntity($response);
        }

        // Filter applied.
        // Instantiate an object for each result returned.
        else {
            return array_map(function ($object) {
                return $this->instantiateEntity($object);
            }, $response->data);
        }

    }
468866
function process_response($request, $response)
    {
        if (! $request->user->isAnonymous()) {
            $request->session->setData($this->session_key, $request->user->id);
        }
        return $response;
    }