/** * Action entry Login/Register page */ public function actionEntry() { $message = ''; // Check if was logged if (HelperCommon::getStore('account')) { $this->redirect($this->integrationType, 'basket'); } // Check if form was submitted if (count(filter_input_array(INPUT_POST))) { HelperCommon::clearStore('account'); $rules = array('email' => array(array('notEmpty'), array('maxLength', array(255)), array('email')), 'password' => array(array('notEmpty'), array('maxLength', array(255)))); $data = array('email' => filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL), 'password' => filter_input(INPUT_POST, 'password')); $errors = $this->validate($rules, $data); $hMessage = new HelperMessage(); $message = $hMessage->getAllMessages($errors, array('email' => 'Email', 'password' => 'Password')); // Check if login was failed if (!$errors) { $password = md5($this->sagepayConfig->getCustomerPasswordSalt() . filter_input(INPUT_POST, 'password')); $customerId = $this->checkCustomer(filter_input(INPUT_POST, 'email'), $password); if (!$customerId !== 0) { HelperCommon::setStore('account', array('email' => filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL), 'password' => $password, 'id' => $customerId)); $this->redirect($this->integrationType, 'basket'); } else { $this->error = true; $message = 'Login failed'; } } else { $this->error = true; $message = "Sorry, the following problems were found: " . $message; } } $current = array('email' => '', 'password' => ''); if (filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL)) { $current['email'] = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL); } // render entry tpl $view = new HelperView('server-and-direct/entry'); $view->setData(array('env' => $this->sagepayConfig->getEnv(), 'vendorName' => $this->sagepayConfig->getVendorName(), 'integrationType' => false, 'controller' => $this->integrationType, 'current' => $current, 'error' => $this->error, 'message' => $message)); $view->render(); }
/** * Save customer details to session * * @param SagepayCustomerDetails $customerDetails * @param string $type * @param string $storeKey */ protected function saveCustomerDetails(SagepayCustomerDetails $customerDetails, $type, $storeKey) { $rawdetails = HelperCommon::getStore($storeKey) ? HelperCommon::getStore($storeKey) : array(); $details = array_merge($rawdetails, $this->customerDetailsToArray($customerDetails, $type)); HelperCommon::setStore($storeKey, $details); }
/** * Action register page for direct payment */ public function actionRegister() { $api = $this->buildApi(); $card = HelperCommon::getStore('card'); $siteFqdn = $this->sagepayConfig->getSiteFqdn(); // Check cardType if ($card['cardType'] == 'PAYPAL') { $api->setIntegrationMethod(SAGEPAY_PAYPAL); $this->sagepayConfig->setPaypalCallbackUrl(url('direct/paypal-response', $siteFqdn)); } $account = HelperCommon::getStore('account'); $api->setPaneValues($card + $account); $api->setVpsDirectUrl($this->purchaseUrl); $response = $api->createRequest(); $data = $api->getData(); $data += $response; // Insert in database $payment = new ModelPayment(); $payment->insert($data); // Redirect $vtxQuery = array('vtx' => $data['VendorTxCode']); if ($response['Status'] == SAGEPAY_REMOTE_STATUS_PAYPAL_REDIRECT) { header('Location: ' . $response['PayPalRedirectURL']); exit; } else { if ($response['Status'] == "3DAUTH") { $threeDSecure = array('MD' => $response['MD'], 'ACSURL' => $response['ACSURL'], 'PaReq' => $response['PAReq'], 'TermUrl' => url(array('direct', 'three-d-secure-result'), $siteFqdn) . '?' . SagepayUtil::arrayToQueryString($vtxQuery)); HelperCommon::setStore('3DAUTH', $threeDSecure); $this->redirect('direct', 'three-d-secure', $vtxQuery); } else { if (in_array($response['Status'], array(SAGEPAY_REMOTE_STATUS_OK, SAGEPAY_REMOTE_STATUS_REGISTERED))) { if ($data['TxType'] == SAGEPAY_REMOTE_STATUS_PAYMENT) { $surcharge = isset($response['Surcharge']) ? floatval($response['Surcharge']) : 0.0; $paymentTx = array('CapturedAmount' => floatval($data['Amount']) + $surcharge, 'Amount' => floatval($data['Amount']) + $surcharge); $payment->update($data['VendorTxCode'], $paymentTx); } $this->redirect('direct', 'success', $vtxQuery); } } } $this->redirect('direct', 'failure', $vtxQuery); }
/** * Action register page for server payment */ public function actionRegister() { $profile = HelperCommon::getStore(self::SESSION_KEY_PROFILE); $this->sagepayConfig->setServerProfile($profile); $api = $this->buildApi(); $api->setVpsServerUrl($this->purchaseUrl); $result = $api->createRequest(); if ($result['Status'] != SAGEPAY_REMOTE_STATUS_OK) { $this->redirect('server', 'confirm', array('error' => base64_encode($result['StatusDetail']))); } $data = array_merge($api->getData(), $result); // Insert Payment in db $payment = new ModelPayment(); $payment->insert($data); // Clear all session not products HelperCommon::clearStore(array('sagepay_server_profile', 'isDeliverySame', 'details', 'extra', 'VendorTxCode')); if ($profile == SAGEPAY_SERVER_PROFILE_LOW) { HelperCommon::setStore('txData', $result); $this->redirect('server', 'low-profile'); } header('Location: ' . $result['NextURL']); exit; }