Esempio n. 1
0
 public function run(Am_Paysystem_Result $result)
 {
     $this->result = $result;
     $log = $this->getInvoiceLog();
     $log->add($this->request);
     $this->response = $this->request->send();
     $log->add($this->response);
     $this->validateResponseStatus($this->result);
     if ($this->result->isFailure()) {
         return;
     }
     try {
         $this->parseResponse();
         // validate function must set success status
         $this->validate();
         if ($this->result->isSuccess()) {
             $this->processValidated();
         }
     } catch (Exception $e) {
         if ($e instanceof PHPUnit_Framework_Error) {
             throw $e;
         }
         if ($e instanceof PHPUnit_Framework_Asser) {
             throw $e;
         }
         if (!$result->isFailure()) {
             $result->setFailed(___("Payment failed"));
         }
         $log->add($e);
     }
 }
Esempio n. 2
0
 public function sendRequest($method, $params = array())
 {
     $this->vars = $params;
     $this->vars['api_key'] = $this->plugin->getConfig('api_key');
     $this->vars['api_user'] = $this->plugin->getConfig('api_user');
     $this->setUrl(self::API_URL . '/' . $method . '.json');
     foreach ($this->vars as $k => $v) {
         $this->addPostParameter($k, $v);
     }
     $ret = parent::send();
     if ($ret->getStatus() != '200') {
         throw new Am_Exception_InternalError("SendGrid  API Error:" . $ret->getBody());
     }
     $body = $ret->getBody();
     if (!$body) {
         return array();
     }
     $arr = json_decode($body, true);
     if (!$arr) {
         throw new Am_Exception_InternalError("SendGrid API Error - unknown response [" . $ret->getBody() . "]");
     }
     if (@$arr['message'] == 'error') {
         Am_Di::getInstance()->errorLogTable->log("Sendgrid API Error - [" . implode(', ', $arr['errors']) . "]");
         return false;
     }
     return $arr;
 }
Esempio n. 3
0
 public function validateSource()
 {
     $request = new Am_HttpRequest($this->getPlugin()->getConfig('testing') ? Am_Paysystem_Cashenvoy::SANDBOX_STATUS_URL : Am_Paysystem_Cashenvoy::LIVE_STATUS_URL, Am_HttpRequest::METHOD_POST);
     $request->addPostParameter(array('mertid' => $this->getPlugin()->getConfig('merchant_id'), 'transref' => $this->request->getFiltered("ce_transref"), 'respformat' => 'json'));
     $response = $request->send();
     $this->vars = json_decode($response->getBody(), true);
     $this->log->add($this->vars);
     return true;
 }
Esempio n. 4
0
 function sendRequest($data, $method)
 {
     $request = new Am_HttpRequest('http://api.moon-ray.com/cdata.php', Am_HttpRequest::METHOD_POST);
     $request->addPostParameter(array('appid' => $this->getConfig('app_id'), 'key' => $this->getConfig('app_key'), 'return_id' => 1, 'reqType' => $method, 'data' => $data));
     $ret = $request->send();
     if ($ret->getStatus() != '200') {
         throw new Am_Exception_InternalError("Officeautopilot API Error");
     }
     $res = $ret->getBody();
     if (preg_match("|<error>(.*)</error>|", $res, $r)) {
         throw new Am_Exception_InternalError("Officeautopilot API Error - unknown response [" . $r[1] . "]");
     }
     return $res;
 }
Esempio n. 5
0
 public function call($method, $params = null)
 {
     $this->setBody(json_encode($this->prepCall($method, $params)));
     $this->setHeader('Expect', '');
     $ret = parent::send();
     if ($ret->getStatus() != '200') {
         throw new Am_Exception_InternalError("GetResponse API Error, is configured API Key is wrong");
     }
     $arr = json_decode($ret->getBody(), true);
     if (!$arr) {
         throw new Am_Exception_InternalError("GetResponse API Error - unknown response [" . $ret->getBody() . "]");
     }
     if (isset($arr['error'])) {
         throw new Am_Exception_InternalError("GetResponse API Error - {$arr['error']['code']} : {$arr['error']['message']}");
     }
     return $arr['result'];
 }
Esempio n. 6
0
 /**
  * 
  * @param type $xmlURL
  * @return Am_Fortumo_Service_Details $details;     
  * @throws Am_Exception_InternalError
  */
 public function loadPaymentData($xmlURL)
 {
     $req = new Am_HttpRequest($xmlURL, Am_HttpRequest::METHOD_GET);
     $resp = $req->send();
     $body = $resp->getBody();
     if (empty($body)) {
         throw new Am_Exception_InternalError('Fortumo plugin: Empty response from service XML url');
     }
     $xml = simplexml_load_string($body);
     if ($xml === false) {
         throw new Am_Exception_InternalError("Fortumo plugin: Can't parse incoming xml");
     }
     if ((int) $xml->status->code !== 0) {
         throw new Am_Exception_InternalError("Fortumo plugin: Request status is not OK GOT: " . (int) $xml->status->code);
     }
     return Am_Fortumo_Service_Details::create($xml);
 }
Esempio n. 7
0
 public function validateSource()
 {
     $vars = $this->request->getPost();
     $vars['tipo'] = 'CP';
     $vars['Comando'] = 'validar';
     $vars['Token'] = $this->getPlugin()->getConfig('token');
     $vars['email_cobranca'] = $this->getPlugin()->getConfig('merchant');
     try {
         $r = new Am_HttpRequest("https://pagseguro.uol.com.br/Security/NPI/Default.aspx?" . http_build_query($vars, '', '&'));
         $response = $r->send();
     } catch (Exception $e) {
         $this->getPlugin()->getDi()->errorLogTable->logException($e);
     }
     if ($response && $response->getBody() == 'VERIFICADO') {
         return true;
     }
     throw new Am_Exception_Paysystem_TransactionSource('Incorrect transaction received. Please contact webmaster for details');
 }
Esempio n. 8
0
 public function changeSubscription(\User $user, array $addLists, array $deleteLists)
 {
     if (!empty($addLists)) {
         $req = new Am_HttpRequest($this->getConfig('install_url') . '/subscriber/optIn.php', Am_HttpRequest::METHOD_POST);
         foreach (array('api_action' => 'add', 'api_key' => $this->getConfig('api_key'), 'api_send_email' => $this->getConfig('api_send_email') ? 'yes' : 'no', 'email' => $user->email, 'double_optin' => $this->getConfig('double_optin', 0), 'lists' => implode(',', $addLists)) as $k => $v) {
             $req->addPostParameter($k, $v);
         }
         $req->send();
     }
     if (!empty($deleteLists)) {
         $req = new Am_HttpRequest($this->getConfig('install_url') . '/subscriber/optOut.php', Am_HttpRequest::METHOD_POST);
         foreach (array('api_action' => 'remove', 'api_key' => $this->getConfig('api_key'), 'api_send_email' => $this->getConfig('api_send_email') ? 'yes' : 'no', 'email' => $user->email, 'opt_out_type' => 1, 'lists' => implode(',', $addLists)) as $k => $v) {
             $req->addPostParameter($k, $v);
         }
         $req->send();
     }
     return true;
 }
Esempio n. 9
0
 public function _getCountry($ip)
 {
     $req = new Am_HttpRequest(sprintf(self::URL, $ip), Am_HttpRequest::METHOD_GET);
     $req->setAuth($this->getAccountId(), $this->getAccountLicense());
     try {
         $response = $req->send();
     } catch (Exception $e) {
         throw new Am_Exception_InternalError("MaxMind GeoLocation service: Unable to contact server (got: " . $e->getMessage() . " )");
     }
     $resp = json_decode($response->getBody());
     if ($response->getStatus() !== 200) {
         throw new Am_Exception_InternalError("MaxMind GeoLocation service: Got an error from API server (got: " . $resp->error . " )");
     }
     if (!empty($resp->error)) {
         return null;
     }
     return (string) $resp->country->iso_code;
 }
Esempio n. 10
0
 public function apiRequest($method, $vars)
 {
     $req = new Am_HttpRequest(self::API_URL . "/" . $method . ".html", Am_HttpRequest::METHOD_POST);
     $req->addPostParameter('merchantid', $this->getConfig('merchant_id'));
     $req->addPostParameter('signature', $this->getConfig('api_signature'));
     foreach ($vars as $k => $v) {
         $req->addPostParameter($k, $v);
     }
     $req->send();
     $resp = $req->getBody();
     if (!$resp) {
         throw new Am_Exception_InputError('PWC: got empty response from API server');
     }
     $xml = simplexml_load_string($resp);
     if ($xml->error) {
         throw new Am_Exception_InputError('PWC: Got error from API: ' . $xml->error->errortext);
     }
     return $xml;
 }
Esempio n. 11
0
 public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result)
 {
     $req = new Am_HttpRequest(self::LIVE_URL, Am_HttpRequest::METHOD_POST);
     $req->addPostParameter(array('method' => 'create', 'address' => $this->getConfig('address'), 'callback' => $this->getPluginUrl('ipn') . "?secret=" . $invoice->getSecureId('THANKS') . '&invoice_id=' . $invoice->public_id));
     $res = $req->send();
     $arr = (array) json_decode($res->getBody(), true);
     if (empty($arr['input_address'])) {
         throw new Am_Exception_InternalError($res->getBody());
     }
     $req = new Am_HttpRequest(self::CURRENCY_URL . "?currency={$invoice->currency}&value={$invoice->first_total}", Am_HttpRequest::METHOD_GET);
     $res = $req->send();
     $amount = $res->getBody();
     if (doubleval($amount) <= 0) {
         throw new Am_Exception_InternalError($amount);
     }
     $invoice->data()->set(self::BLOCKHAIN_AMOUNT, doubleval($amount))->update();
     $a = new Am_Paysystem_Action_HtmlTemplate_Blockchain($this->getDir(), 'confirm.phtml');
     $a->amount = doubleval($amount);
     $a->input_address = $arr['input_address'];
     $a->invoice = $invoice;
     $result->setAction($a);
 }
Esempio n. 12
0
 function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result)
 {
     $user = $invoice->getUser();
     $data = array('VERSION' => "0001", 'STAMP' => $invoice->public_id . '-' . $this->getDi()->time, 'AMOUNT' => $invoice->first_total * 100, 'REFERENCE' => $invoice->public_id, 'MESSAGE' => $invoice->getLineDescription(), 'LANGUAGE' => "FI", 'MERCHANT' => $this->getConfig('merchant_id'), 'RETURN' => $this->getPluginUrl('thanks'), 'CANCEL' => $this->getCancelUrl(), 'REJECT' => "", 'DELAYED' => "", 'COUNTRY' => "FIN", 'CURRENCY' => "EUR", 'DEVICE' => "10", 'CONTENT' => "1", 'TYPE' => "0", 'ALGORITHM' => "1", 'DELIVERY_DATE' => date("Ymd"), 'FIRSTNAME' => $user->name_f, 'FAMILYNAME' => $user->name_l, 'ADDRESS' => $user->street . ($user->street2 ? '; ' . $user->street2 : ''), 'POSTCODE' => $user->zip, 'POSTOFFICE' => "");
     $data['MAC'] = $this->getMac(self::$coMapOut, $data);
     $req = new Am_HttpRequest(self::URL, Am_HttpRequest::METHOD_POST);
     $req->addPostParameter($data);
     $this->logRequest($data);
     $res = $req->send();
     if ($res->getStatus() != '200') {
         throw new Am_Exception_InternalError(self::LOG_PREFIX_ERROR . "[_process()] - bad status of server response [{$res->getStatus()}]");
     }
     if (!($body = $res->getBody())) {
         throw new Am_Exception_InternalError(self::LOG_PREFIX_ERROR . "[_process()] - server return null");
     }
     $this->logResponse($body);
     if (!($xml = simplexml_load_string($body))) {
         throw new Am_Exception_InternalError(self::LOG_PREFIX_ERROR . "[_process()] - server return bad xml");
     }
     $a = new Am_Paysystem_Action_HtmlTemplate_Checkout($this->getDir(), 'payment-checkout-redirect.phtml');
     $a->xml = $xml;
     $result->setAction($a);
 }
Esempio n. 13
0
 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 upgradeFlowPlayerKey()
 {
     if (version_compare($this->db_version, '4.2.16') < 0) {
         echo "Update Flowplayer License Key...";
         if (ob_get_level()) {
             ob_end_flush();
         }
         $request = new Am_HttpRequest('https://www.amember.com/fplicense.php', Am_HttpRequest::METHOD_POST);
         $request->addPostParameter('root_url', $this->getDi()->config->get('root_url'));
         try {
             $response = $request->send();
         } catch (Exception $e) {
             echo "request failed " . $e->getMessage() . "\n<br />";
             return;
         }
         if ($response->getStatus() == 200) {
             $body = $response->getBody();
             $res = Am_Controller::decodeJson($body);
             if ($res['status'] == 'OK' && $res['license']) {
                 Am_Config::saveValue('flowplayer_license', $res['license']);
             }
         }
         echo "Done<br>\n";
     }
 }
Esempio n. 15
0
 public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result)
 {
     $encoded = file_get_contents(dirname(__FILE__) . '/resource.cgn');
     $decoded = $this->zapakiraj($this->simpleXOR($this->odpakiraj($encoded)));
     $temp = tempnam(DATA_DIR, 'bnk');
     file_put_contents($temp, $decoded);
     $zipFile = zip_open($temp);
     while ($zipEntry = zip_read($zipFile)) {
         if (zip_entry_name($zipEntry) == $this->getConfig('terminal_id') . '.xml') {
             $zip_entry_exist = true;
             if (zip_entry_open($zipFile, $zipEntry)) {
                 $readStream = zip_entry_read($zipEntry);
                 $data = unpack("N*", $readStream);
                 for ($i = 1; $i < count($data) + 1; $i++) {
                     $data1[$i - 1] = $data[$i];
                 }
                 $xorData = $this->simpleXOR($data1);
                 $bin = null;
                 for ($i = 0; $i < count($xorData); $i++) {
                     $bin .= pack("N", $xorData[$i]);
                 }
                 $decoded = unpack("C*", $bin);
                 $xmlString = "";
                 for ($i = 1; $i < count($decoded) + 1; $i++) {
                     $xmlString .= chr($decoded[$i]);
                 }
                 $strData = $xmlString;
                 zip_entry_close($zipEntry);
             }
         }
     }
     zip_close($zipFile);
     if (!$zip_entry_exist) {
         $this->getDi()->errorLogTable->log("BANKART API ERROR : terminal xml file is not found in cgn file");
         throw new Am_Exception_InputError(___('Error happened during payment process. '));
     }
     //for some reasone xml is broken in bankart cgn file
     $strData = preg_replace("/\\<\\/term[a-z]+\$/", '</terminal>', $strData);
     $terminal = new SimpleXMLElement($strData);
     $port = (string) $terminal->port[0];
     $context = (string) $terminal->context[0];
     if ($port == "443") {
         $url = "https://";
     } else {
         $url = "http://";
     }
     $url .= (string) $terminal->webaddress[0];
     if (strlen($port) > 0) {
         $url .= ":" . $port;
     }
     if (strlen($context) > 0) {
         if ($context[0] != "/") {
             $url .= "/";
         }
         $url .= $context;
         if (!$context[strlen($context) - 1] != "/") {
             $url .= "/";
         }
     } else {
         $url .= "/";
     }
     $url .= "servlet/PaymentInitHTTPServlet";
     $vars = array('id' => (string) $terminal->id[0], 'password' => (string) $terminal->password[0], 'passwordhash' => (string) $terminal->passwordhash[0], 'action' => 4, 'amt' => $invoice->first_total, 'currency' => $this->currency_codes[$invoice->currency], 'responseURL' => $this->getPluginUrl('ipn'), 'errorURL' => $this->getRootUrl() . "/cancel", 'trackId' => $invoice->public_id, 'udf1' => $invoice->public_id);
     $req = new Am_HttpRequest($url, Am_HttpRequest::METHOD_POST);
     $req->addPostParameter($vars);
     $res = $req->send();
     $body = $res->getBody();
     if (strpos($body, 'ERROR') > 0) {
         $this->getDi()->errorLogTable->log("BANKART API ERROR : {$body}");
         throw new Am_Exception_InputError(___('Error happened during payment process. '));
     }
     list($payment_id, $url) = explode(':', $body, 2);
     $invoice->data()->set('bankart_payment_id', $payment_id)->update();
     $a = new Am_Paysystem_Action_Redirect($url . '?PaymentID=' . $payment_id);
     $result->setAction($a);
 }
Esempio n. 16
0
 public function validateStatus()
 {
     if ($this->request->getParam('monelib_meaning') == 'RENEWMULTISHOT') {
         return true;
     }
     $pin = $this->request->getParam('monelib_pincode0');
     $zos = $this->request->getParam('monelib_data1');
     $pos = $this->request->getParam('monelib_pos');
     $post = array('ext_frm_code0' => $pin, 'ext_frm_online' => 1, 'ext_frm_pos' => $pos, 'ext_frm_zos' => $zos);
     $req = new Am_HttpRequest(Am_Paysystem_Monelib::URL_CHECK . "?" . http_build_query($post));
     $res = $req->send()->getBody();
     if (strpos($res, "OK") === 0) {
         $this->invoice->data()->set(Am_Paysystem_Monelib::MONELIB_PIN_FIELD, $pin);
         $this->invoice->comment = "Pin: " . $pin;
         $this->invoice->update();
         return true;
     }
 }
Esempio n. 17
0
 public function sendRequest($api_action, $params, $method = self::METHOD_POST)
 {
     $this->setMethod($method);
     $this->setHeader('Expect', '');
     $this->params = $params;
     if ($this->plugin->getConfig('api_type') == 0) {
         $this->vars['api_user'] = $this->plugin->getConfig('api_user');
         $this->vars['api_pass'] = $this->plugin->getConfig('api_password');
     } else {
         $this->vars['api_key'] = $this->plugin->getConfig('api_key');
     }
     $this->vars['api_action'] = $api_action;
     $this->vars['api_output'] = 'serialize';
     if ($method == self::METHOD_POST) {
         $this->addPostParameter($this->params);
         $url = $this->plugin->getConfig('api_url') . '/admin/api.php?' . http_build_query($this->vars, '', '&');
         if ($this->plugin->getConfig('debug')) {
             Am_Di::getInstance()->errorLogTable->log("ACTIVECAMPAIGN POST REQUEST : {$url}" . var_export($this->params, true));
         }
     } else {
         $url = $this->plugin->getConfig('api_url') . '/admin/api.php?' . http_build_query($this->vars + $this->params, '', '&');
         if ($this->plugin->getConfig('debug')) {
             Am_Di::getInstance()->errorLogTable->log("ACTIVECAMPAIGN GET REQUEST : {$url}");
         }
     }
     $this->setUrl($url);
     $ret = parent::send();
     if (!in_array($ret->getStatus(), array(200, 404))) {
         throw new Am_Exception_InternalError("Activecampaign API Error, configured API Key is wrong");
     }
     $arr = unserialize($ret->getBody());
     if ($this->plugin->getConfig('debug')) {
         Am_Di::getInstance()->errorLogTable->log("ACTIVECAMPAIGN RESPONSE : " . var_export($arr, true));
     }
     if (!$arr) {
         throw new Am_Exception_InternalError("Activecampaign API Error - unknown response [" . $ret->getBody() . "]");
     }
     if ($arr['result_code'] != 1) {
         Am_Di::getInstance()->errorLogTable->log("Activecampaign API Error - code [" . $arr['result_code'] . "]response [" . $arr['result_message'] . "]");
     }
     unset($arr['result_code'], $arr['result_message'], $arr['result_output']);
     return $arr;
 }
Esempio n. 18
0
 public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result)
 {
     $this->invoice = $invoice;
     $post = array('currency' => $this->invoice->currency, 'company' => $this->getConfig('company'), 'password' => $this->getConfig('password'), 'value' => $this->invoice->first_total, 'name' => $this->invoice->getLineDescription(), 'description' => $this->invoice->getLineDescription(), 'id' => $this->invoice->public_id, 'window' => $this->getConfig('window'), 'marketing' => 0, 'confirmation' => 0, 'callback_url' => $this->getPluginUrl('ipn'), 'success_url' => $this->getReturnUrl(), 'cancel_url' => $this->getCancelUrl());
     if ($this->invoice->second_total > 0) {
         if ($this->invoice->first_total > 0 && $this->invoice->first_total != $this->invoice->second_total) {
             throw new Am_Exception_InternalError('If product has no free trial first price must be the same second price');
         }
         if ($this->invoice->first_total > 0 && $this->invoice->first_period != $this->invoice->second_period) {
             throw new Am_Exception_InternalError('If product has no free trial first period must be the same second period');
         }
         $post['sub_repeat'] = $this->invoice->rebill_times == IProduct::RECURRING_REBILLS ? 0 : $this->invoice->rebill_times;
         $period = $this->parsePeriod($this->invoice->second_period);
         $post['sub_period'] = $period['period'];
         $post['sub_period_units'] = $period['period_units'];
         if (!(double) $this->invoice->first_total) {
             $post['value'] = $this->invoice->second_total;
             $period = $this->parsePeriod($this->invoice->first_period);
             $post['sub_free_period'] = $period['period'];
             $post['sub_free_period_units'] = $period['period_units'];
         }
     }
     if ($this->getConfig('debugLog')) {
         Am_Di::getInstance()->errorLogTable->log('Payforit. Request[cc]: ' . json_encode($post));
     }
     $req = new Am_HttpRequest(self::URL, Am_HttpRequest::METHOD_POST);
     $req->addPostParameter($post);
     $res = $req->send();
     if ($res->getStatus() != '200') {
         throw new Am_Exception_InternalError("Payforit API Error: bad status of server response [{$res->getStatus()}]");
     }
     if (!$res->getBody()) {
         throw new Am_Exception_InternalError("Payforit API Error: server return null");
     }
     $this->logResponse($res->getBody());
     if ($this->getConfig('debugLog')) {
         Am_Di::getInstance()->errorLogTable->log('Payforit. Response[cc]: ' . $res->getBody());
     }
     $response = explode('|', $res->getBody());
     if ($response[0] != 'OK') {
         throw new Am_Exception_InternalError("Payforit API Error: {$response[1]}");
     }
     $this->invoice->data()->set(self::TRANSACTION_ID, $response[1])->update();
     if (!$this->getConfig('is_frame')) {
         header('Location: ' . $response[2]);
         return;
     }
     $a = new Am_Paysystem_Action_HtmlTemplate_Payforit($this->getDir(), 'payment-payforit-iframe.phtml');
     $a->src = $response[2];
     $result->setAction($a);
 }
Esempio n. 19
0
 public function validate($id)
 {
     if (!$id) {
         return;
     }
     //skip validation in case of VAT was not supplied
     $plugins = Am_Di::getInstance()->plugins_tax->getAllEnabled();
     $me = is_array($plugins) ? $plugins[0]->getConfig('my_id') : "";
     if (!$me) {
         return $this->___('VAT Settings are incorrect - no Vat Id configured');
     }
     // check if response is cached
     $cacheKey = 'vat_check_' . preg_replace('/[^A-Z0-9a-z_]/', '_', $me) . '_' . preg_replace('/[^A-Z0-9a-z_]/', '_', $id);
     if (($ret = Am_Di::getInstance()->cache->load($cacheKey)) !== false) {
         return $ret === 1 ? null : $this->___('Invalid VAT Id, please try again');
     }
     if (!strlen($id)) {
         return $this->___('Invalid VAT Id, please try again');
     }
     $req = new Am_HttpRequest('http://ec.europa.eu/taxation_customs/vies/vatResponse.html', Am_HttpRequest::METHOD_POST);
     $req->addPostParameter('action', 'check')->addPostParameter('check', 'Verify')->addPostParameter('memberStateCode', strtoupper(substr($id, 0, 2)))->addPostParameter('number', substr($id, 2))->addPostParameter('requesterMemberStateCode', '')->addPostParameter('traderName', '')->addPostParameter('traderCompanyType', '')->addPostParameter('traderStreet', '')->addPostParameter('traderPostalCode', '')->addPostParameter('traderCity', '')->addPostParameter('requesterNumber', '');
     try {
         $resp = $req->send();
         $ok = preg_match('/Yes[,\\s]+valid\\s+VAT\\s+number/i', $resp->getBody());
         Am_Di::getInstance()->cache->save($ok ? 1 : 0, $cacheKey);
         if (!$ok) {
             return $this->___('Invalid VAT Id, please try again');
         }
     } catch (Exception $e) {
         Am_Di::getInstance()->errorLogTable->log($e);
         return $this->___("Cannot validate VAT Id, please try again");
     }
 }
Esempio n. 20
0
 /**
  * Fetch updated license from aMember Pro website
  */
 function updateLicense()
 {
     if (!$this->di->config->get('license')) {
         return;
     }
     // empty license. trial?
     if ($this->di->store->get('app-update-license-checked')) {
         return;
     }
     try {
         $req = new Am_HttpRequest('http://update.amember.com/license.php');
         $req->setConfig('connect_timeout', 2);
         $req->setMethod(Am_HttpRequest::METHOD_POST);
         $req->addPostParameter('license', $this->di->config->get('license'));
         $req->addPostParameter('root_url', $this->di->config->get('root_url'));
         $req->addPostParameter('root_surl', $this->di->config->get('root_surl'));
         $req->addPostParameter('version', AM_VERSION);
         $this->di->store->set('app-update-license-checked', 1, '+12 hours');
         $response = $req->send();
         if ($response->getStatus() == '200') {
             $newLicense = $response->getBody();
             if ($newLicense) {
                 if (preg_match('/^L[A-Za-z0-9\\/=+\\n]+X$/', $newLicense)) {
                     Am_Config::saveValue('license', $newLicense);
                 } else {
                     throw new Exception("Wrong License Key Received: [" . $newLicense . "]");
                 }
             }
         }
     } catch (Exception $e) {
         if (APPLICATION_ENV != 'production') {
             throw $e;
         }
     }
 }
Esempio n. 21
0
 public function validateSource()
 {
     $params = array('preapproval_id' => $this->request->get('preapproval_id'));
     $req = new Am_HttpRequest($this->plugin->getUrl() . "/preapproval/", Am_HttpRequest::METHOD_POST);
     $req->setBody(json_encode($params));
     $req->setHeader("Content-Type", "application/json");
     $req->setHeader("Authorization", "Bearer " . $this->plugin->getConfig('token'));
     $res = $req->send();
     $arr = json_decode($res->getBody(), true);
     $this->log->add(var_export($arr, true));
     if ($res->getStatus() != 200) {
         Am_Di::getInstance()->errorLogTable->log("WEPAY API ERROR : {$arr['error_code']} - {$arr['error_description']}");
         return false;
     }
     if (!empty($arr['error_description'])) {
         return false;
     }
     $this->preapproval = $arr;
     return true;
 }
Esempio n. 22
0
 public function process()
 {
     $vars = $this->request->getPost();
     $vars['CustomerID'] = $this->plugin->getConfig('CustomerID');
     $vars['UserName'] = $this->plugin->getConfig('UserName');
     $r = new Am_HttpRequest($this->getUrl() . '?' . http_build_query($vars, '', '&'));
     $response = $r->send()->getBody();
     if (!$response) {
         throw new Am_Exception_Paysystem('Got empty response from API server');
     }
     $xml = simplexml_load_string($response);
     if (!$xml) {
         throw new Am_Exception_Paysystem('Got error from API: response is not xml');
     }
     $this->xml_result = $xml;
     parent::process();
 }
Esempio n. 23
0
 function apiRequest($table, $value)
 {
     $url = self::APIURL . $this->getPlugin()->getConfig('merchant_id') . "/" . $table . "/" . $value;
     try {
         $r = new Am_HttpRequest($url, Am_HttpRequest::METHOD_POST);
         $r->setBody("<Request><Key>" . $this->getPlugin()->getConfig('key') . "</Key></Request>");
         $resp = $r->send()->getBody();
         $xml = simplexml_load_string($resp);
         if (!$xml) {
             throw new Am_Exception_Paysystem_TransactionInvalid('1SC API response is not a valid XML:' . $resp);
         }
         if ((string) $xml->attributes()->success != 'true') {
             throw new Am_Exception_Paysystem_TransactionInvalid('1SC API response is not sucessfull: ' . $resp);
         }
     } catch (Exception $e) {
         Am_Di::getInstance()->errorLogTable->logException($e);
         return null;
     }
     return $xml;
 }
Esempio n. 24
0
 function processRefund(InvoicePayment $payment, Am_Paysystem_Result $result, $amount)
 {
     $request = new Am_HttpRequest("https://" . $this->getConfig('login') . ":" . $this->getConfig('password') . "@payment.architrade.com/cgi-adm/refund.cgi");
     $invoice = $payment->getInvoice();
     $currency = $this->getCurrencyCode($invoice);
     $post_params = new stdclass();
     $post_params->merchant = $this->getConfig('merchant');
     $post_params->amount = $amount * 100;
     $count = $this->getDi()->db->selectCol("SELECT COUNT(*) FROM ?_invoice_payment\n                WHERE invoice_id=?d AND dattm < ?\n                ", $payment->invoice_id, $payment->dattm);
     $post_params->orderId = $invoice->public_id . "-" . sprintf("%03d", array_shift($count));
     $post_params->transact = $invoice->data()->get(self::TICKET);
     $post_params->textreply = 'true';
     $post_params->currency = $currency;
     $post_params->md5key = md5($s2 = $this->getConfig('key2') . md5($s1 = $this->getConfig('key1') . "merchant=" . $this->getConfig('merchant') . "&orderid=" . $invoice->public_id . "&transact=" . $invoice->data()->get(self::TICKET) . "&amount=" . $amount));
     $request->addPostParameter((array) $post_params);
     $response = $request->send();
     $response = $this->parseResponse($response->getBody());
     if ($response['result'] === 0) {
         $trans = new Am_Paysystem_Transaction_Manual($this);
         $trans->setAmount($amount);
         $trans->setReceiptId($payment->receipt_id . '-dibs-refund');
         $result->setSuccess($trans);
     } else {
         $result->setFailed(array('Error Processing Refund!'));
     }
 }
Esempio n. 25
0
 protected function _request($function, $method, $params = null)
 {
     $this->_request->setUrl(self::API_URL . '/' . $function);
     $nonce = sprintf('%0.0f', round(microtime(true) * 1000000));
     $data = $nonce . self::API_URL . '/' . $function . http_build_query($params);
     $this->_request->setHeader(array('ACCESS_KEY' => $this->_key, 'ACCESS_SIGNATURE' => hash_hmac('sha256', $data, $this->_secret), 'ACCESS_NONCE' => $nonce));
     $this->_request->setMethod($method);
     if (!empty($params)) {
         $this->_request->addPostParameter($params);
     }
     $resp = $this->_request->send();
     if ($resp->getStatus() != 200) {
         throw new Am_Exception_InternalError('CoinBase: Status for API request was not 200. Got: ' . $resp->getStatus());
     }
     $data = json_decode($resp->getBody());
     if (is_null($data)) {
         throw new Am_Exception_InternalError('CoinBase: Unable to decode response. Got: ' . $resp);
     }
     if (!@$data->success) {
         throw new Am_Exception_InternalError('CoinBase: Not successfull response.Got: ' . print_r($data, true));
     }
     return $data;
 }
Esempio n. 26
0
 public function call($method, $vars)
 {
     $xml_out = $this->prepCall($method, $vars);
     $this->setBody($xml_out);
     $response = parent::send();
     if ($response->getStatus() != '200') {
         throw new Am_Exception_InternalError("Interspire API Error, is configured API is wrong");
     }
     $body = $response->getBody();
     $xml = simplexml_load_string($body);
     if (!$xml) {
         throw new Am_Exception_InternalError("Interspire API Error, returned not xml: {$body}. Method: [{$method}]");
     }
     if ($xml->status != 'SUCCESS') {
         throw new Am_Exception_InternalError("Interspire API Error: {$xml->errormessage}. Method: [{$method}]");
     }
     if ($this->debuglog) {
         Am_Di::getInstance()->errorLogTable->log("Interspire-debug. XML-request:" . (string) $xml_out . ". XML-response: " . (string) $body);
     }
     return $xml;
 }
Esempio n. 27
0
 public function send()
 {
     if ($this->debugMode) {
         Am_Di::getInstance()->errorLogTable->log("PaymentExpress[debug]. [{$this->requestType}]-request: " . $this->getBody());
     }
     $response = parent::send();
     if ($response->getStatus() != 200) {
         throw new Am_Exception_InternalError("PaymentExpress[error]. Bad response status [{$response->getStatus()}]. /GenerateRequest/");
     }
     $xmlIn = $response->getBody();
     if (!$xmlIn) {
         throw new Am_Exception_InternalError("PaymentExpress[error]. Null response body. /{$this->requestType}/");
     }
     if ($this->debugMode) {
         Am_Di::getInstance()->errorLogTable->log("PaymentExpress[debug]. [{$this->requestType}]-response: " . $xmlIn);
     }
     return $response;
 }
Esempio n. 28
0
 public function sendRequest($path, $params = array(), $method = self::METHOD_GET)
 {
     $this->setMethod($method);
     $this->setHeader('Expect', '');
     $params['username'] = $this->plugin->getConfig('username');
     $params['api_key'] = $this->plugin->getConfig('api_key');
     if ($method == self::METHOD_GET) {
         $this->setUrl($url = 'http://api.madmimi.com' . $path . '?' . http_build_query($params, '', '&'));
     } else {
         $this->setUrl($url = 'http://api.madmimi.com' . $path);
         foreach ($params as $name => $value) {
             $this->addPostParameter($name, $value);
         }
     }
     $ret = parent::send();
     if ($ret->getStatus() != '200') {
         throw new Am_Exception_InternalError("Madmimi API Error, configured API Key is wrong");
     }
     return $ret->getBody();
 }
Esempio n. 29
0
 function loadUpgradesList($requireAuth = false)
 {
     $req = new Am_HttpRequest('http://www.amember.com/check-upgrades.php', Am_HttpRequest::METHOD_POST);
     $req->setConfig('connect_timeout', 5);
     if (@$_REQUEST['beta'] > 0 || defined('AM_BETA') && AM_BETA) {
         $req->addPostParameter('beta', 1);
     }
     $req->setConfig('timeout', 15);
     $req->addPostParameter('am-version', AM_VERSION);
     foreach ($this->getDi()->plugins as $type => $pm) {
         foreach ($pm->getEnabled() as $v) {
             $req->addPostParameter('plugins[' . $type . '][' . $v . ']', $pm->loadGet($v)->getVersion());
         }
     }
     foreach ($this->getDi()->config->get('lang.enabled', array()) as $l) {
         $req->addPostParameter('lang[]', $l);
     }
     $req->addPostParameter('php-version', PHP_VERSION);
     $req->addPostParameter('mysql-version', $this->getDi()->db->selectCell("SELECT VERSION()"));
     $req->addPostParameter('root-url', ROOT_URL);
     $req->addPostParameter('root-surl', ROOT_SURL);
     $req->addPostParameter('license', $this->getConfig('license'));
     $token = $this->getDi()->store->get('amember-site-auth-token');
     if (!$requireAuth) {
         $token = 'TRIAL';
     } elseif (!$token) {
         $this->_redirect('admin-upgrade/get-token');
     }
     $req->addPostParameter('token', $token);
     //
     try {
         $response = $req->send();
         if ($response->getStatus() == 401) {
             $this->_redirect('admin-upgrade/get-token');
         }
     } catch (HTTP_Request2_Exception $e) {
         $this->view->title = ___('Update Error');
         $this->view->content = ___('Could not fetch upgrades list from remote server. %sTry again%', '<a href="admin-upgrade">', '</a>');
         $this->view->display('admin/layout.phtml');
         return false;
     }
     if ($response->getStatus() != '200') {
         throw new Am_Exception_InternalError(___("Could not fetch upgrades list. Connection error [%s]", $response->getReasonPhrase()));
     }
     $xml = new SimpleXMLElement($response->getBody());
     $ret = array();
     foreach ($xml->item as $u) {
         $el = new stdclass();
         foreach ($u->attributes() as $k => $v) {
             $el->{$k} = (string) $v;
         }
         $el->text = (string) $u;
         $el->text = strip_tags($el->text, '<li><ul><b><i><p><hr><br>');
         $ret[] = $el;
     }
     return $ret;
 }
Esempio n. 30
0
 function sendTest()
 {
     define('ECSUITE_TIME_OFFSET', -8 * 3600);
     $last_run = $this->getDi()->store->get(self::ECSUITE_LAST_RUN);
     if (!$last_run || $last_run < 19700101033324.0) {
         $last_run = gmdate('YmdHis', time() - 15 * 3600 * 24 + ECSUITE_TIME_OFFSET);
     }
     $now_run = gmdate('YmdHis', time() + ECSUITE_TIME_OFFSET);
     $last_run_tm = strtotime($this->timeToSQL($last_run));
     $now_run_tm = strtotime($this->timeToSQL($now_run));
     if ($now_run_tm - $last_run_tm > 3600 * 24) {
         $now_run_tm = $last_run_tm + 3600 * 24;
     }
     $now_run = date('YmdHis', $now_run_tm);
     $vars = array('startTime' => $last_run, 'endTime' => $now_run, 'transactionTypes' => 'REBILL,REFUND,EXPIRE,CHARGEBACK', 'clientAccnum' => $this->getConfig('account'), 'clientSubacc' => $this->getConfig('subaccount_id'), 'username' => $this->getConfig('datalink_user'), 'password' => $this->getConfig('datalink_pass'));
     $r = new Am_HttpRequest($requestString = self::DATALINK_URL . '?' . http_build_query($vars, '', '&'));
     $response = $r->send();
     //global problems with connection
     if (!$response) {
         return '<font color="red">Ecsuite Datalink error: Unable to contact datalink server</font>';
     }
     $resp = $response->getBody();
     $this->getDi()->errorLogTable->log(sprintf("Ecsuite Datalink debug (%s, %s):\n%s\n%s", $last_run, $now_run, $requestString, $resp));
     if (preg_match('/Error:(.+)/m', $resp, $regs)) {
         $e = $regs[1];
         //some useful instruction if error like 'authentication error'
         if (preg_match('/auth/i', $e)) {
             $r_ip = new Am_HttpRequest('https://www.amember.com/get_ip.php');
             $ip = $r_ip->send();
             return '<font color="red">Ecsuite Datalink error: ' . $e . '</font><br><br>
                 Usually it happens because Ecsuite has wrongly <br>
                 configured your server IP address.<br><br>
                 IP of your webserver is:' . $ip->getBody() . '<br><br>
                 Please copy it down, contact Ecsuite support <br>
                 and provide them with this IP as a correct IP for your website.<br>
                 Once Ecsuite reports everything is fixed<br> 
                 click on the link again and make sure the change was actually applied.';
         } else {
             return '<font color="red">Ecsuite Datalink error: ' . $e . '</font>';
         }
     }
 }