public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result) { $user = $invoice->getUser(); $a = new Am_Paysystem_Action_Redirect($this->host()); $vars = array('TransactionType' => 'SALE', 'ServiceID' => $this->getConfig('ServiceID'), 'PaymentID' => $invoice->public_id, 'OrderNumber' => $invoice->public_id, 'PaymentDesc' => $invoice->getLineDescription(), 'MerchantReturnURL' => $this->getPluginUrl('thanks'), 'Amount' => $invoice->first_total, 'CurrencyCode' => $invoice->currency, 'CustIP' => $request->getClientIp(), 'CustName' => $user->getName(), 'CustEmail' => $user->email, 'CustPhone' => $user->phone, 'MerchantName' => $this->getDi()->config->get('site_title'), 'PageTimeout' => '3600'); $a->HashValue = hash('sha256', $this->getConfig('password') . $vars['ServiceID'] . $vars['PaymentID'] . $vars['MerchantReturnURL'] . $vars['Amount'] . $vars['CurrencyCode'] . $vars['CustIP'] . $vars['PageTimeout']); foreach ($vars as $k => $v) { $a->{$k} = $v; } $result->setAction($a); }
/** * Compare request IP with configured in plugin * and raise exception if that is wrong * @param mixed $ip string will be parsed using this format: $ip1_start [- $ip1_end][\n$ip2_start [- $ip2_end]] etc... * Array should have this format: array( array('start1', 'stop1'), single_ip, array('start2', 'stop2')) * also it may automatically check for hostname belonging to subdomain like * .worldpay.com */ public function _checkIp($ip) { $got = $this->request->getClientIp(false); if (!is_array($ip)) { $expected = array(); foreach (split("\n", $ip) as $l) { if (strpos($l, "-") !== false) { list($k, $v) = split("-", $l); $expected[] = array(trim($k), trim($v)); } else { $expected[] = trim($l); } } } else { $expected = $ip; } $expected = array_filter($expected); if (empty($expected)) { throw new Am_Exception_InputError("{$this->plugin->getId()} configuration error. Expected IP address array is empty!"); } $found = false; $hostname = null; foreach ($expected as $v) { if (is_array($v)) { if (ip2long($got) >= ip2long($v[0]) && ip2long($got) <= ip2long($v[1])) { $found = true; break; } } else { if ($got == $v) { $found = true; break; } if ($v[0] == '.') { if (!$hostname) { $hostname = gethostbyaddr($got); } if (preg_match($x = '|' . preg_quote($v) . '$|', $hostname)) { $found = true; break; } } } } if (!$found) { throw new Am_Exception_Paysystem_TransactionSource("{$this->plugin->getId()} post comes from unknown IP [{$got}]"); } }
public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result) { $xml = new SimpleXMLElement('<request/>'); $transactiondetails = $xml->addChild('transactiondetails'); $transactiondetails->addChild('merchantcode', $this->getConfig('merchantid')); $transactiondetails->addChild('merchantpwd', $this->getConfig('merchantpwd')); $transactiondetails->addChild('trackid', $invoice->public_id); $transactiondetails->addChild('customerip', $request->getClientIp()); $transactiondetails->addChild('udf1', $invoice->public_id); $transactiondetails->addChild('customerid', $invoice->getLogin()); $paymentdetails = $xml->addChild('paymentdetails'); $paymentdetails->addChild('paysource', 'enets'); $paymentdetails->addChild('amount', $invoice->first_total); $paymentdetails->addChild('currency', $invoice->currency); $paymentdetails->addChild('actioncode', 1); $notificationurls = $xml->addChild('notificationurls'); $notificationurls->addChild('successurl', $this->getReturnUrl()); $notificationurls->addChild('failurl', $this->getCancelUrl()); $shippingdetails = $xml->addChild('shippingdetails'); foreach (array('ship_address' => $invoice->getStreet(), 'ship_email' => $invoice->getEmail(), 'ship_postal' => $invoice->getZip(), 'ship_address2' => $invoice->getStreet1(), 'ship_city' => $invoice->getCity(), 'ship_state' => $invoice->getState(), 'ship_phone' => $invoice->getPhone(), 'ship_country' => $invoice->getCountry()) as $k => $v) { $shippingdetails->addChild($k, $v); } $req = new Am_HttpRequest($this->getConfig('gatewayurl'), Am_HttpRequest::METHOD_POST); $req->setHeader('Content-type: text/xml; charset=utf-8')->setHeader('Connection:close')->setBody($xml->asXML()); $response = $req->send(); $resxml = @simplexml_load_string($response->getBody()); if (!$resxml instanceof SimpleXMLElement) { throw new Am_Exception_InputError('Incorrect Gateway response received!'); } if ($paymenturl = (string) $resxml->transactionresponse->paymenturl) { $a = new Am_Paysystem_Action_Redirect($paymenturl); $result->setAction($a); } else { throw new Am_Exception_InputError('Incorrect Gateway response received! Got: ' . (string) $resxml->responsedesc); } }
function checkExternalLogin(Am_Request $request) { // Check cookies if ($this->getDi()->config->get('protect.php_include.remember_login', false) && !is_null($request->getCookie('amember_ru')) && !is_null($request->getCookie('amember_rp'))) { $this->setFromCookie(true); $authResult = $this->login($request->getCookie('amember_ru'), $request->getCookie('amember_rp'), $request->getClientIp(), false); $this->setFromCookie(false); if ($authResult->isValid()) { return $authResult; } } /// Check plugins login; $e = new Am_Event_AuthCheckLoggedIn(); $this->getDi()->hook->call($e); if ($e->isSuccess()) { $errorResult = $this->checkUser($e->getUser(), $request->getClientIp()); if ($errorResult) { return; } $this->setUser($e->getUser(), $request->getClientIp()); $this->onSuccess(); return new Am_Auth_Result(Am_Auth_Result::SUCCESS); } }
public function directAction(Am_Request $request, Zend_Controller_Response_Http $response, array $invokeArgs) { $actionName = $request->getActionName(); if ($actionName == 'ipn') { if (!in_array($request->getClientIp(), $this->ips)) { throw new Am_Exception_InputError("Request not handled - ip is not allowed"); } if ($request->get('art') == 'request') { $shopid = $request->get('shopid'); if (!$shopid) { throw new Am_Exception_InputError("Parameter shopid wasn't received"); } $invoice = Am_Di::getInstance()->invoiceTable->findFirstByPublicId($shopid); if (!$invoice) { throw new Am_Exception_InputError("No invoice found"); } $params = array(); $params['nachname'] = $invoice->getLastName(); $params['vorname'] = $invoice->getFirstName(); $params['strasse'] = $invoice->getStreet(); $params['plz'] = $invoice->getZip(); $params['ort'] = $invoice->getCity(); $params['land'] = $invoice->getUser()->country; $params['email'] = $invoice->getEmail(); $params['betrag'] = $invoice->first_total * 100; $params['compain_id'] = ''; $params['ipadresse'] = $invoice->getUser()->remote_addr; if ($invoice->second_period) { $aboanlage = 1; $abopreis = $invoice->second_total * 100; preg_match("/[\\d]+/", $invoice->second_period, $days); if ($days[0] <= 365 && $days[0] >= 30) { $abozeit = $days[0]; } preg_match("/[\\d]+/", $invoice->first_period, $days); if ($days[0] <= 365 && $days[0] >= 3) { $abonext = $days[0]; } $params['aboanlage'] = $aboanlage; $params['abopreis'] = $abopreis; $params['abozeit'] = $abozeit; $params['abonext'] = $abonext; } $params['cur'] = strtolower($invoice->currency); $message = ''; foreach ($params as $p) { $message .= $p . ";"; } echo utf8_decode($message); return; } //Getting invoice for providing a redirect-URL with the result confirmation $shopid = $request->get('shopid'); $this->invoice = Am_Di::getInstance()->invoiceTable->findFirstByPublicId($shopid); $invoiceLog = $this->_logDirectAction($request, $response, $invokeArgs); $transaction = $this->createTransaction($request, $response, $invokeArgs); if (!$this->invoice) { throw new Am_Exception_InputError("Request not handled - Request's parameter shopid is incorrect"); } if (!$transaction) { throw new Am_Exception_InputError("Request not handled - createTransaction() returned null"); } $transaction->setInvoiceLog($invoiceLog); try { $transaction->process(); } catch (Exception $e) { echo "OK;" . $this->getCancelUrl() . "?shopid=" . $this->invoice->public_id; if ($invoiceLog) { $invoiceLog->add($e); } throw $e; } echo "OK;" . $this->getReturnUrl() . "?shopid=" . $this->invoice->public_id; if ($invoiceLog) { $invoiceLog->setProcessed(); } } else { return parent::directAction($request, $response, $invokeArgs); } }