示例#1
0
 public function request($method = null)
 {
     $outputArray = array();
     $curl = curl_init();
     $method = strtolower($method);
     $opts = array();
     // conditions from Checkout and CurlBase
     $opts[CURLOPT_TIMEOUT] = (int) $this->condArray["DEFAULT_TIMEOUT"];
     $opts[CURLOPT_CONNECTTIMEOUT] = (int) $this->condArray['DEFAULT_CONNECT_TIMEOUT'];
     $opts[CURLOPT_URL] = (string) Helper::setToUtf8($this->absurl);
     $opts[CURLOPT_RETURNTRANSFER] = (bool) true;
     $opts[CURLOPT_POST] = (bool) true;
     $opts[CURLOPT_SSL_VERIFYPEER] = false;
     $opts[CURLOPT_HTTPHEADER] = array('Content-Type: application/json', 'Authorization: ' . $this->condArray["apiKey"]);
     $opts[CURLOPT_POSTFIELDS] = Helper::encode($this->dataset, $prefix = 'json');
     curl_setopt_array($curl, $opts);
     $respones = curl_exec($curl);
     if ($respones === false) {
         $errno = curl_errno($curl);
         $message = curl_error($curl);
         curl_close($curl);
         $this->handleCurlError($this->absurl, $errno, $message);
     }
     $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
     curl_close($curl);
     $outputArray = array('respons' => $respones, 'status' => $status, 'inputOpts' => $opts);
     return count($outputArray) > 0 ? $outputArray : null;
 }
示例#2
0
 public function setLog($arg, $func, $name = null)
 {
     if (!is_null($name)) {
         // if is defined
         $name1 = Helper::getClassName($name);
     } else {
         $name1 = 'error';
     }
     $logger = new Logger($func);
     $logger->pushHandler(new StreamHandler($this->path . "/{$name1}.log", Logger::DEBUG));
     return $logger->addInfo(json_encode($arg));
 }
/*Needed for loading the classes inside src*/
function autoload($className)
{
    $className = ltrim($className, '\\');
    $fileName = '';
    $namespace = '';
    if ($lastNsPos = strrpos($className, '\\')) {
        $namespace = substr($className, 0, $lastNsPos);
        $className = substr($className, $lastNsPos + 1);
        $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
    }
    $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
    require $fileName;
}
spl_autoload_register('autoload');
$setup = ["apiKey" => (string) "NNq7Rcnb8y8jGTsU", "stage" => (bool) true, "DEFAULT_TIMEOUT" => (int) 30];
$transactionData = array('subscriptions' => array(array('amount' => '100', 'currency' => 'SEK', 'startsAt' => '2016-01-01', 'interval' => ' MONTHLY'), array('amount' => '200', 'currency' => 'SEK', 'startsAt' => '2016-01-01', 'interval' => ' MONTHLY')), 'country' => 'SE', 'merchantId' => 'paylevo');
try {
    \Sweetpay\CheckoutCond::setCondition($setup);
} catch (Exception $e) {
    $input = array('line' => __LINE__, 'path' => __FILE__);
    \Sweetpay\Helper::errorMessage($e, $input);
    var_dump(\Sweetpay\CheckoutCond::getApiKey());
}
try {
    $Check = new \Sweetpay\CheckOut($transactionData);
    var_dump($Check->getOutput());
} catch (Exception $e) {
    $input = array('line' => __LINE__, 'path' => __FILE__);
    \Sweetpay\Helper::errorMessage($e, $input);
}