Esempio n. 1
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. 2
0
 /** @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;
 }
Esempio n. 3
0
 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);
             }
         }
     }
 }
Esempio n. 4
0
<?php

require_once dirname(__FILE__) . '/bootstrap.php';
@set_time_limit(3600);
$req = new Am_HttpRequest();
$req->setConfig('connect_timeout', 120);
$req->setConfig('timeout', 3600);
$req->setUrl(Am_Di::getInstance()->config->get('root_url') . '/cron');
$resp = $req->send();