Beispiel #1
0
 /**
  * Create request without checking conditions
  * @param array $data
  * @return boolean
  */
 private static function createRequest($data)
 {
     try {
         $curl = new DotpayCurl();
         $curl->addOption(CURLOPT_URL, self::$config->getDotpayTargetUrl() . self::$target)->addOption(CURLOPT_SSL_VERIFYPEER, TRUE)->addOption(CURLOPT_SSL_VERIFYHOST, 2)->addOption(CURLOPT_RETURNTRANSFER, 1)->addOption(CURLOPT_TIMEOUT, 100)->addOption(CURLOPT_USERPWD, self::$config->getDotpayApiUsername() . ':' . self::$config->getDotpayApiPassword())->addOption(CURLOPT_POST, 1)->addOption(CURLOPT_POSTFIELDS, $data)->addOption(CURLOPT_HTTPHEADER, array('Accept: application/json; indent=4', 'content-type: application/json'));
         $resultJson = $curl->exec();
         $resultStatus = $curl->getInfo();
     } catch (Exception $exc) {
         $resultJson = false;
     }
     if ($curl) {
         $curl->close();
     }
     if (false !== $resultJson && $resultStatus['http_code'] == 201) {
         return json_decode($resultJson, true);
     }
     return false;
 }
Beispiel #2
0
 public static function getLatestVersion()
 {
     $url = self::$githubUrl . '/repos/dotpay/PrestaShop/releases/latest';
     $curl = new DotpayCurl();
     $curl->addOption(CURLOPT_URL, $url);
     self::setCurlOption($curl);
     $response = json_decode($curl->exec());
     $version = NULL;
     $url = '';
     if ($response instanceof \stdClass) {
         if (isset($response->tag_name)) {
             $version = str_replace('v', '', $response->tag_name);
             if (isset($response->html_url)) {
                 $url = $response->assets[0]->browser_download_url;
             }
         }
     }
     return array('version' => $version, 'url' => $url);
 }
Beispiel #3
0
 /**
  * Makes a return payment and returns infos about a result of this operation
  * @param string $username
  * @param string $password
  * @param string $payment
  * @param float $amount
  * @param type $control
  * @param type $description
  * @return type
  */
 public function makeReturnMoney($username, $password, $payment, $amount, $control, $description)
 {
     $url = $this->_baseurl . $this->getDotPaymentApi() . 'payments/' . $payment . '/refund/';
     $data = array('amount' => str_replace(',', '.', $amount), 'description' => $description, 'control' => $control);
     $curl = new DotpayCurl();
     $curl->addOption(CURLOPT_URL, $url)->addOption(CURLOPT_USERPWD, $username . ':' . $password)->addOption(CURLOPT_POST, 1)->addOption(CURLOPT_POSTFIELDS, json_encode($data))->addOption(CURLOPT_SSL_VERIFYPEER, TRUE)->addOption(CURLOPT_SSL_VERIFYHOST, 2)->addOption(CURLOPT_RETURNTRANSFER, 1)->addOption(CURLOPT_TIMEOUT, 100)->addOption(CURLOPT_HTTPHEADER, array('Accept: application/json; indent=4', 'content-type: application/json'));
     $resp = json_decode($curl->exec(), true);
     return $curl->getInfo() + $resp;
 }
Beispiel #4
0
 /**
  * Checks if seller account is right
  * @param type $sellerId
  * @return boolean
  */
 public function checkSellerId($sellerId)
 {
     if (empty($sellerId)) {
         return false;
     }
     $dotpayUrl = $this->config->getDotpayTargetUrl();
     $curlUrl = "{$dotpayUrl}payment_api/channels/?id={$sellerId}";
     try {
         $curl = new DotpayCurl();
         $curl->addOption(CURLOPT_SSL_VERIFYPEER, false)->addOption(CURLOPT_HEADER, false)->addOption(CURLOPT_URL, $curlUrl)->addOption(CURLOPT_REFERER, $curlUrl)->addOption(CURLOPT_RETURNTRANSFER, true);
         $resultJson = $curl->exec();
     } catch (Exception $exc) {
         $resultJson = false;
     }
     if ($curl) {
         $curl->close();
     }
     $result = json_decode($resultJson, true);
     return !(isset($result['error_code']) && $result['error_code'] == 'UNKNOWN_ACCOUNT');
 }
Beispiel #5
0
 /**
  * Returns string with channels data JSON from Dotpay server
  * @return string|boolean
  */
 private function getApiChannelsFromServer($pv = false)
 {
     $dotpayUrl = $this->config->getDotpayTargetUrl();
     $paymentCurrency = $this->parent->getDotCurrency();
     if ($pv) {
         $dotpayId = $this->config->getDotpayPvId();
     } else {
         $dotpayId = $this->config->getDotpayId();
     }
     $orderAmount = $this->parent->getDotAmount();
     $dotpayLang = $this->parent->getDotLang();
     $curlUrl = "{$dotpayUrl}payment_api/channels/";
     $curlUrl .= "?currency={$paymentCurrency}";
     $curlUrl .= "&id={$dotpayId}";
     $curlUrl .= "&amount={$orderAmount}";
     $curlUrl .= "&lang={$dotpayLang}";
     try {
         $curl = new DotpayCurl();
         $curl->addOption(CURLOPT_SSL_VERIFYPEER, false)->addOption(CURLOPT_HEADER, false)->addOption(CURLOPT_URL, $curlUrl)->addOption(CURLOPT_REFERER, $curlUrl)->addOption(CURLOPT_RETURNTRANSFER, true);
         $resultJson = $curl->exec();
     } catch (Exception $exc) {
         $resultJson = false;
     }
     if ($curl) {
         $curl->close();
     }
     return json_decode($resultJson, true);
 }