コード例 #1
0
ファイル: bitpay.php プロジェクト: kleetus/prestashop-plugin
 public function execPayment($cart)
 {
     // Create invoice
     $currency = Currency::getCurrencyInstance((int) $cart->id_currency);
     $options = $_POST;
     $options['transactionSpeed'] = Configuration::get('bitpay_TXSPEED');
     $options['currency'] = $currency->iso_code;
     $total = $cart->getOrderTotal(true);
     $options['notificationURL'] = (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://') . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ . 'modules/' . $this->name . '/ipn.php';
     if (_PS_VERSION_ <= '1.5') {
         $options['redirectURL'] = (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://') . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ . 'order-confirmation.php?id_cart=' . $cart->id . '&id_module=' . $this->id . '&id_order=' . $this->currentOrder;
     } else {
         $options['redirectURL'] = Context::getContext()->link->getModuleLink('bitpay', 'validation');
     }
     $options['posData'] = '{"cart_id": "' . $cart->id . '"';
     $options['posData'] .= ', "hash": "' . crypt($cart->id, Configuration::get('bitpay_APIKEY')) . '"';
     $this->key = $this->context->customer->secure_key;
     $options['posData'] .= ', "key": "' . $this->key . '"}';
     $options['orderID'] = $cart->id;
     $options['price'] = $total;
     $options['fullNotifications'] = true;
     $postOptions = array('orderID', 'itemDesc', 'itemCode', 'notificationEmail', 'notificationURL', 'redirectURL', 'posData', 'price', 'currency', 'physical', 'fullNotifications', 'transactionSpeed', 'buyerName', 'buyerAddress1', 'buyerAddress2', 'buyerCity', 'buyerState', 'buyerZip', 'buyerEmail', 'buyerPhone');
     foreach ($postOptions as $o) {
         if (array_key_exists($o, $options)) {
             $post[$o] = $options[$o];
         }
     }
     if (function_exists('json_encode')) {
         $post = json_encode($post);
     } else {
         $post = rmJSONencode($post);
     }
     // Call BitPay
     $curl = curl_init($this->apiurl . '/api/invoice/');
     $length = 0;
     if ($post) {
         curl_setopt($curl, CURLOPT_POST, 1);
         curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
         $length = strlen($post);
     }
     $uname = base64_encode(Configuration::get('bitpay_APIKEY'));
     $header = array('Content-Type: application/json', 'Content-Length: ' . $length, 'Authorization: Basic ' . $uname, 'X-BitPay-Plugin-Info: prestashop0.4');
     curl_setopt($curl, CURLINFO_HEADER_OUT, true);
     curl_setopt($curl, CURLOPT_PORT, $this->sslport);
     curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
     curl_setopt($curl, CURLOPT_TIMEOUT, 10);
     curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $this->verifypeer);
     // verify certificate (1)
     curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, $this->verifyhost);
     // check existence of CN and verify that it matches hostname (2)
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
     curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
     $responseString = curl_exec($curl);
     if (!$responseString) {
         $response = curl_error($curl);
         die(Tools::displayError("Error: no data returned from API server!"));
     } else {
         if (function_exists('json_decode')) {
             $response = json_decode($responseString, true);
         } else {
             $response = rmJSONdecode($responseString);
         }
     }
     curl_close($curl);
     if (isset($response['error'])) {
         bplog($response['error']);
         die(Tools::displayError("Error occurred! (" . $response['error']['type'] . " - " . $response['error']['message'] . ")"));
     } else {
         if (!$response['url']) {
             die(Tools::displayError("Error: Response did not include invoice url!"));
         } else {
             header('Location:  ' . $response['url']);
         }
     }
 }
コード例 #2
0
ファイル: ipn.php プロジェクト: Tinklit/prestashop-plugin
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
// called by notification_url
include_once dirname(__FILE__) . '/../../config/config.inc.php';
include_once dirname(__FILE__) . '/../../header.php';
include_once dirname(__FILE__) . '/tinklit.php';
$handle = fopen('php://input', 'r');
$jsonInput = fgets($handle);
if (function_exists('json_decode')) {
    $decoded = json_decode($jsonInput, true);
} else {
    $decoded = rmJSONdecode($jsonInput);
}
fclose($handle);
// remember, item_code is cart id
$order = (int) Order::getOrderByCartId((int) $decoded['item_code']);
$tinklit = new tinklit();
if (in_array($decoded['status'], array('payed'))) {
    if ($order == 0) {
        p("order is 0");
        $customer_securekey = $decoded['order_id'];
        $tinklit->validateOrder($decoded['item_code'], Configuration::get('PS_OS_PAYMENT'), $decoded['price'], $tinklit->displayName, null, array(), null, false, $customer_securekey);
    } else {
        if (empty(Context::getContext()->link)) {
            Context::getContext()->link = new Link();
        }
        // workaround a prestashop bug so email is sent
コード例 #3
0
ファイル: ipn.php プロジェクト: kleetus/prestashop-plugin
 */
include dirname(__FILE__) . '/../../config/config.inc.php';
include dirname(__FILE__) . '/../../header.php';
include dirname(__FILE__) . '/bitpay.php';
$handle = fopen('php://input', 'r');
$jsonInput = fgets($handle);
if (function_exists('json_decode')) {
    $decoded = json_decode($jsonInput, true);
} else {
    $decoded = rmJSONdecode($jsonInput);
}
fclose($handle);
if (function_exists('json_decode')) {
    $posData = json_decode($decoded['posData']);
} else {
    $posData = rmJSONdecode($decoded['posData']);
}
$order = (int) Order::getOrderByCartId($posData->cart_id);
if ($posData->hash == crypt($posData->cart_id, Configuration::get('bitpay_APIKEY'))) {
    $bitpay = new bitpay();
    if (in_array($decoded['status'], array('paid', 'confirmed', 'complete'))) {
        if ($order == 0) {
            $key = $posData->key;
            $bitpay->validateOrder($posData->cart_id, Configuration::get('PS_OS_PAYMENT'), $decoded['price'], $bitpay->displayName, null, array(), null, false, $key);
        } else {
            if (empty(Context::getContext()->link)) {
                Context::getContext()->link = new Link();
            }
            // workaround a prestashop bug so email is sent
            $key = $posData->key;
            $order = new Order((int) Order::getOrderByCartId($posData->cart_id));
コード例 #4
0
ファイル: tinklit.php プロジェクト: Tinklit/prestashop-plugin
 public function execPayment($cart)
 {
     // Create invoice
     $currency = Currency::getCurrencyInstance((int) $cart->id_currency);
     $options = $_POST;
     $clientid = Configuration::get('tinklit_CLIENTID');
     $token = Configuration::get('tinklit_TOKEN');
     $options['currency'] = $currency->iso_code;
     // only EUR at the moment
     $total = $cart->getOrderTotal(true);
     $options['notification_url'] = (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://') . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ . 'modules/' . $this->name . '/ipn.php';
     if (_PS_VERSION_ <= '1.5') {
         $options['redirect_url'] = (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://') . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ . 'order-confirmation.php?id_cart=' . $cart->id . '&id_module=' . $this->id . '&id_order=' . $this->currentOrder;
     } else {
         $options['redirect_url'] = Context::getContext()->link->getModuleLink('tinklit', 'validation');
     }
     // item_code will provide cart id
     // order_id will provide customer secure_key
     $options['item_code'] = $cart->id;
     $options['order_id'] = $this->context->customer->secure_key;
     $options['price'] = $total;
     // send these to invoice API
     $postOptions = array('item_code', 'order_id', 'notification_url', 'redirect_url', 'price', 'currency');
     foreach ($postOptions as $o) {
         if (array_key_exists($o, $options)) {
             $post[$o] = $options[$o];
         }
     }
     if (function_exists('json_encode')) {
         $post = json_encode($post);
     } else {
         $post = rmJSONencode($post);
     }
     // Call Tinklit
     $curl = curl_init($this->apiurl . '/v1/invoices');
     //$curl = curl_init('https://api-staging.tinkl.it/v1/invoices');
     $length = 0;
     if ($post) {
         curl_setopt($curl, CURLOPT_POST, 1);
         curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
         $length = strlen($post);
     }
     $header = array('Content-Type: application/json', 'Content-Length: ' . $length, 'X-Tinklit-Plugin-Info: ' . $this->name . '_' . $this->version, 'X-CLIENT-ID: ' . $clientid, 'X-AUTH-TOKEN: ' . $token);
     curl_setopt($curl, CURLINFO_HEADER_OUT, true);
     curl_setopt($curl, CURLOPT_PORT, $this->sslport);
     curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
     curl_setopt($curl, CURLOPT_TIMEOUT, 10);
     curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, $this->verifypeer);
     // verify certificate (1)
     curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, $this->verifyhost);
     // check existence of CN and verify that it matches hostname (2)
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
     curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
     $responseString = curl_exec($curl);
     if (!$responseString) {
         $response = curl_error($curl);
         p("Error: ");
         p($response);
         p($this->apiurl);
         die(Tools::displayError("Error: no data returned from tinklit API server!"));
     } else {
         if (function_exists('json_decode')) {
             $response = json_decode($responseString, true);
         } else {
             $response = rmJSONdecode($responseString);
         }
     }
     curl_close($curl);
     if (isset($response['error'])) {
         bplog($response['error']);
         die(Tools::displayError("Error occurred! (" . $response['error']['type'] . " - " . $response['error']['message'] . ")"));
     } else {
         if (!$response['url']) {
             die(Tools::displayError("Error: Response did not include invoice url!"));
         } else {
             header('Location:  ' . $response['url']);
         }
     }
 }