/** * 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; } } }
function resendPostback() { if ($this->plugin->getConfig('resend_postback')) { $urls = $this->plugin->getConfig('resend_postback_urls'); $urls = explode("\n", $urls); $urls = array_filter(array_map('trim', $urls)); foreach ($urls as $url) { try { $tm = microtime(true); $this->log->add("Resending postback to [{$url}]"); if ($url == $this->plugin->getPluginUrl('ipn')) { throw new Am_Exception_Configuration("DO NOT CONFIGURE RESENDING IPN TO ITSELF!"); } $req = new Am_HttpRequest($url); $req->setConfig('connect_timeout', 1000); $req->setConfig('timeout', 2000); $method = strtoupper($this->request->getMethod()); $req->setMethod($method); if ($method == 'POST') { foreach ($this->request->getPost() as $k => $v) { $req->addPostParameter($k, $v); } } else { $arr = $this->request->getQuery(); $req->setUrl($req->getUrl() . '?' . http_build_query($arr)); } $req->send(); $tm = sprintf('%.3f', microtime(true) - $tm); $this->log->add("Postback resent succesfully ({$tm} sec)"); } catch (Exception $e) { $tm = sprintf('%.3f', microtime(true) - $tm); $this->log->add("Cannot resend postback ({$tm} sec)"); $this->log->add($e); } } } }
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; }
/** @return HTTP_Request2_Response */ public function _sendRequest(Am_HttpRequest $request) { $request->addPostParameter('x_login', $this->getConfig('login')); $request->addPostParameter('x_tran_key', $this->getConfig('tkey')); $request->addPostParameter('x_Delim_Data', "True"); $request->addPostParameter('x_Delim_Char', "|"); $request->addPostParameter('x_Version', "3.1"); $request->addPostParameter('x_method', "ECHECK"); if ($this->getConfig('test_mode')) { $request->addPostParameter("x_test_request", "TRUE"); $request->setUrl(self::SANDBOX_URL); } else { $request->setUrl(self::LIVE_URL); } $request->setMethod(Am_HttpRequest::METHOD_POST); return $request; }