/**
  * @param Request $http
  * @throws CheckoutException
  */
 public function processRequest(Request $http)
 {
     try {
         $response = \WebToPay::checkResponse($http->all(), array('projectid' => $this->projectId, 'sign_password' => $this->signPassword));
         if ($response['test'] !== '0') {
             //throw new CheckoutException('Testing, real payment was not made');
         }
         if ($response['type'] !== 'macro') {
             throw new CheckoutException('Only macro payment callbacks are accepted');
         }
         if ($response['orderid'] != $this->request->transaction) {
             throw new CheckoutException('Incorrect transaction');
         }
         if ($response['amount'] != $this->request->amount * 100) {
             throw new CheckoutException('Incorrect amount');
         }
         if ($response['currency'] != $this->request->currency) {
             throw new CheckoutException('Incorrect currency');
         }
         if ($this->request->status == TransactionData::PAID) {
             throw new CheckoutException('Transaction already done.');
         }
         TransactionData::update($this->request->transaction, ['date_paid' => time(), 'status' => TransactionData::PAID, 'gateway_response' => $response]);
         Callback::call($this->request);
         echo 'OK';
     } catch (CheckoutException $e) {
         throw new CheckoutException('Gateway got error', 500, $e);
     }
 }
 function process_button()
 {
     global $order;
     $last_order_id = tep_db_query("select orders_id from " . TABLE_ORDERS . " order by orders_id desc limit 1");
     $result = tep_db_fetch_array($last_order_id);
     $this->orderID = $result['orders_id'] + 1;
     $acceptURL = tep_href_link(FILENAME_CHECKOUT_PROCESS, 'referer=mokejimai', 'SSL');
     $cancelURL = tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL');
     $callbackURL = tep_href_link('mokejimai_validation.php', '', 'SSL', false, false, true);
     $acceptURL = str_replace('&', '&', $acceptURL);
     $cancelURL = str_replace('&', '&', $cancelURL);
     $callbackURL = str_replace('&', '&', $callbackURL);
     try {
         $request = WebToPay::buildRequest(array('projectid' => $this->projectID, 'sign_password' => $this->projectPass, 'orderid' => $this->orderID, 'amount' => intval(number_format($order->info['total'], 2, '', '')), 'currency' => $order->info['currency'], 'lang' => substr($_SESSION['language'], 0, 2) !== 'lt' ? 'ENG' : 'LTU', 'accepturl' => $acceptURL, 'cancelurl' => $cancelURL, 'callbackurl' => $callbackURL, 'country' => 'LT', 'logo' => '', 'p_firstname' => $order->customer['firstname'], 'p_lastname' => $order->customer['lastname'], 'p_email' => $order->customer['email_address'], 'p_street' => $order->customer['street_address'], 'p_city' => $order->customer['city'], 'p_state' => $order->customer['state'], 'p_zip' => $order->customer['postcode'], 'p_countrycode' => $order->customer['country']['iso_code_2'], 'test' => $this->testMode));
     } catch (WebToPayException $e) {
         echo get_class($e) . ': ' . $e->getMessage();
     }
     $html = '';
     if ($request) {
         foreach ($request as $key => $value) {
             $html .= tep_draw_hidden_field($key, $value);
         }
     }
     return $html;
 }
예제 #3
0
 function payseraReturn($data)
 {
     print_r($data);
     try {
         $response = WebToPay::checkResponse($data, array('projectid' => 74747, 'sign_password' => 'a4a8a31750a23de2da88ef6a491dfd5c'));
         print_r($response);
         $orderId = $response['orderid'];
         $totamt = $response['amount'];
         $currency = $response['currency'];
         if ($response['status'] == 1) {
             $invoice_num = $response['invoiceno'];
             // get the invoice number from the post variable
             $return['success'] = true;
             $return['invoice_num'] = $invoice_num;
         } else {
             $return['success'] = false;
         }
         //print_r($return);exit;
         return $return;
     } catch (Exception $e) {
         echo get_class($e) . ': ' . $e->getMessage();
     }
 }
<?php

require 'includes/application_top.php';
require DIR_WS_MODULES . 'payment/libwebtopay/WebToPay.php';
$query = tep_db_query("SELECT configuration_value FROM " . TABLE_CONFIGURATION . " WHERE `configuration_key` = 'MODULE_PAYMENT_PAYSERA_PROJECT_ID'");
$data = tep_db_fetch_array($query);
$projectID = $data['configuration_value'];
$query = tep_db_query("SELECT configuration_value FROM " . TABLE_CONFIGURATION . " WHERE `configuration_key` = 'MODULE_PAYMENT_PAYSERA_PROJECT_PASS'");
$data = tep_db_fetch_array($query);
$projectPass = $data['configuration_value'];
try {
    WebToPay::toggleSS2(true);
    $response = WebToPay::checkResponse($_REQUEST, array('projectid' => $projectID, 'sign_password' => $projectPass));
    if ($response['status'] == 1) {
        $orderID = $response['orderid'];
        $query = tep_db_query("SELECT `value` FROM " . TABLE_ORDERS_TOTAL . " WHERE orders_id = '" . $orderID . "'");
        $amount = tep_db_fetch_array($query);
        $query = tep_db_query("SELECT `currency` FROM " . TABLE_ORDERS . " WHERE orders_id = '" . $orderID . "'");
        $currency = tep_db_fetch_array($query);
        $Order = array('currency' => $currency['currency'], 'total' => $amount['value']);
        if ($response['amount'] < intval(number_format($Order['total'], 2, '', ''))) {
            exit('Bad amount!');
        }
        if ($Order['currency'] != $response['currency']) {
            exit('Bad currency!');
        }
        tep_db_query('UPDATE ' . TABLE_ORDERS . ' SET orders_status = 2 WHERE orders_id = ' . $orderID);
        tep_db_query('UPDATE ' . TABLE_ORDERS_STATUS_HISTORY . ' SET orders_status_id = 2 WHERE orders_status_history_id = ' . $orderID);
        exit('OK');
    }
} catch (Exception $e) {
<?php

require_once 'includes/helpers.php';
require_once 'includes/config.php';
require_once '../src/includes.php';
$post = removeQuotes($_POST);
$id = $post['id'];
if (!isset($shopItems[$id])) {
    redirect_to(get_address());
}
$item = $shopItems[$id];
$amount = $item['price'];
$currency = $item['currency'];
// get payment methods available for this project with min/max amounts in specified currency
$methods = WebToPay::getPaymentMethodList($config['projectid'], $currency)->filterForAmount($amount, $currency)->setDefaultLanguage('en');
// set default language for titles (default: lt)
echo template('paymentMethod.html', array('methods' => $methods, 'post' => $post));
예제 #6
0
 /**
  * Checks and validates response from WebToPay server.
  *
  * This function accepts both mikro and makro responses.
  *
  * First parameter usualy should by $_GET array.
  *
  * Description about response can be found here:
  * makro: https://www.mokejimai.lt/makro_specifikacija.html
  * mikro: https://www.mokejimai.lt/mikro_mokejimu_specifikacija_SMS.html
  *
  * If response is not correct, WebToPayException will be raised.
  *
  * @param array     $response       Response array.
  * @param array     $user_data
  * @return array
  */
 public static function checkResponse($response, $user_data = array())
 {
     self::$verified = false;
     $response = self::getPrefixed($response, self::PREFIX);
     // *get* response type (makro|mikro)
     list($type, $specs) = self::getSpecsForResponse($response);
     try {
         // *check* response
         $version = explode('.', self::VERSION);
         $version = $version[0] . '.' . $version[1];
         if ('makro' == $type && $response['version'] != $version) {
             throw new WebToPayException(self::_('Incompatible library and response versions: ' . 'libwebtopay %s, response %s', self::VERSION, $response['version']), WebToPayException::E_INVALID);
         }
         if ('makro' == $type && $response['projectid'] != $user_data['projectid']) {
             throw new WebToPayException(self::_('Bad projectid: ' . 'libwebtopay %s, response %s', self::VERSION, $response['version']), WebToPayException::E_INVALID);
         }
         if ('makro' == $type) {
             self::$verified = 'RESPONSE VERSION ' . $response['version'] . ' OK';
         }
         $orderid = 'makro' == $type ? $response['orderid'] : $response['id'];
         $password = $user_data['sign_password'];
         // *check* SS2
         if (self::useSS2()) {
             $cert = 'public.key';
             if (self::checkResponseCert($response, $cert)) {
                 self::$verified = 'SS2 public.key';
             }
         } else {
             if (self::checkSS1v2($response, $password)) {
                 self::$verified = 'SS1v2';
             }
         }
         // *check* status
         if ('makro' == $type && $response['status'] != '1') {
             throw new WebToPayException(self::_('Returned transaction status is %d, successful status ' . 'should be 1.', $response['status']), WebToPayException::E_STATUS);
         }
     } catch (WebToPayException $e) {
         if (isset($user_data['log'])) {
             self::log('ERR', self::responseToLog($type, $response) . ' (' . get_class($e) . ': ' . $e->getMessage() . ')', $user_data['log']);
         }
         throw $e;
     }
     if (isset($user_data['log'])) {
         self::log('OK', self::responseToLog($type, $response), $user_data['log']);
     }
     return $response;
 }
 /**
  * Exception should be thrown if order id is not given
  *
  * @expectedException WebToPayException
  */
 public function testBuildRepeatRequestWithoutProjectId()
 {
     WebToPay::buildRepeatRequest(array('sign_password' => 'asdfghjkl', 'projectid' => '123'));
 }
예제 #8
0
 /**
  *
  *
  * @param array $request
  *
  */
 function payment_callback($request)
 {
     global $woocommerce;
     try {
         $response = WebToPay::checkResponse($_REQUEST, array('projectid' => $this->projectid, 'sign_password' => $this->password));
         if ($response['status'] == 1) {
             $order = new WC_Order($response['orderid']);
             if (intval(number_format($order->get_total(), 2, '', '')) > $response['amount']) {
                 if ($this->log) {
                     $this->log->add('paysera', 'Order #' . $order->id . ' Amounts do no match. ' . (intval(number_format($order->get_total(), 2, '', '')) . '!=' . $response['amount']));
                 }
                 throw new Exception('Amounts do not match');
             }
             if (get_woocommerce_currency() != $response['currency']) {
                 if ($this->log) {
                     $this->log->add('paysera', 'Order #' . $order->id . ' Currencies do not match. ' . get_woocommerce_currency() . '!=' . $response['currency']);
                 }
                 throw new Exception('Currencies do not match');
             }
             if ($order->status !== 'completed') {
                 if ($this->log) {
                     $this->log->add('paysera', 'Order #' . $order->id . ' Callback payment completed.');
                 }
                 $order->add_order_note(__('Callback payment completed', 'woocomerce'));
                 $order->payment_complete();
             }
         }
         echo 'OK';
     } catch (Exception $e) {
         $msg = get_class($e) . ': ' . $e->getMessage();
         if ($this->log) {
             $this->log->add('paysera', $msg);
         }
         echo $msg;
     }
     exit;
 }
예제 #9
0
<?php

require_once 'includes/helpers.php';
require_once 'includes/config.php';
require_once '../src/includes.php';
$get = removeQuotes($_GET);
try {
    $parsedData = WebToPay::validateAndParseData($get, $config['projectid'], $config['sign_password']);
} catch (WebToPayException $e) {
    $parsedData = 'Error: ' . $e->getMessage();
}
$data = load_data();
$data['sms'][] = array('_GET' => $get, 'parsedData' => $parsedData);
save_data($data);
예제 #10
0
            } else {
                $error = t("ERROR: api returns empty");
            }
        } catch (WebToPayException $e) {
            $error = t("ERROR: Something went wrong") . ". " . $e;
        }
    } else {
        try {
            dump($amount_to_pay);
            $params_request = array('projectid' => $projectid, 'sign_password' => $password, 'orderid' => $payment_ref, 'amount' => $amount_to_pay * 100, 'currency' => $currency, 'country' => $country, 'accepturl' => $accepturl, 'cancelurl' => $cancel_url, 'callbackurl' => $callback, 'test' => $mode, 'lang' => $lang);
            if ($mode == 2) {
                unset($params_request['test']);
            }
            /*dump($params_request);
              die();*/
            $request = WebToPay::redirectToPayment($params_request);
        } catch (WebToPayException $e) {
            $error = t("ERROR: Something went wrong") . ". " . $e;
        }
    }
} else {
    $error = t("ERROR: Something went wrong");
}
if (!empty($error)) {
    ?>
	<p class="uk-text-danger"><?php 
    echo $error;
    ?>
</p>
	<?php 
}
예제 #11
0
 public function actionIndex()
 {
     $db_ext = new DbExt();
     $error = '';
     $package_id = isset($_GET['package_id']) ? $_GET['package_id'] : '';
     $amount_to_pay = 0;
     $back_url = Yii::app()->request->baseUrl . "/merchant/purchasesms";
     $payment_ref = Yii::app()->functions->generateCode() . "TT" . Yii::app()->functions->getLastIncrement('{{sms_package_trans}}');
     $package_id = isset($_GET['package_id']) ? $_GET['package_id'] : '';
     $merchant_id = Yii::app()->functions->getMerchantID();
     if ($res = Yii::app()->functions->getSMSPackagesById($package_id)) {
         $amount_to_pay = $res['price'];
         if ($res['promo_price'] > 0) {
             $amount_to_pay = $res['promo_price'];
         }
         $amount_to_pay = is_numeric($amount_to_pay) ? normalPrettyPrice($amount_to_pay) : '';
         $payment_description .= isset($res['title']) ? $res['title'] : '';
         /*dump($payment_description);
         		dump($amount_to_pay);
         		dump($payment_ref);*/
         $amount_to_pay = number_format($amount_to_pay, 2, '.', '');
         $cancel_url = Yii::app()->getBaseUrl(true) . "/merchant/purchasesms";
         $accepturl = Yii::app()->getBaseUrl(true) . "/merchant/pysinit/?type=purchaseSMScredit&package_id=" . $package_id . "&mode=accept&mtid={$merchant_id}";
         $callback = Yii::app()->getBaseUrl(true) . "/paysera/?type=purchaseSMScredit&package_id=" . $package_id . "&mode=callback&mtid={$merchant_id}";
         $country = Yii::app()->functions->getOptionAdmin('admin_paysera_country');
         $mode = Yii::app()->functions->getOptionAdmin('admin_paysera_mode');
         $lang = Yii::app()->functions->getOptionAdmin('admin_paysera_lang');
         $currency = Yii::app()->functions->adminCurrencyCode();
         $projectid = Yii::app()->functions->getOptionAdmin('admin_paysera_project_id');
         $password = Yii::app()->functions->getOptionAdmin('admin_paysera_password');
         if (isset($_GET['mode'])) {
             if ($_GET['mode'] == "accept") {
                 $payment_code = Yii::app()->functions->paymentCode("paysera");
                 $params = array('merchant_id' => $_GET['mtid'], 'sms_package_id' => $package_id, 'payment_type' => $payment_code, 'package_price' => $amount_to_pay, 'sms_limit' => isset($res['sms_limit']) ? $res['sms_limit'] : '', 'date_created' => date('c'), 'ip_address' => $_SERVER['REMOTE_ADDR'], 'payment_gateway_response' => json_encode($_GET));
                 $db_ext->insertData("{{sms_package_trans}}", $params);
                 header('Location: ' . Yii::app()->request->baseUrl . "/merchant/smsReceipt/id/" . Yii::app()->db->getLastInsertID());
                 die;
             }
             try {
                 $response = WebToPay::checkResponse($_GET, array('projectid' => $projectid, 'sign_password' => $password));
                 if (is_array($response) && count($response) >= 1) {
                     if ($response['status'] == 0) {
                         die("payment has no been executed");
                     }
                     if ($response['status'] == 3) {
                         die("additional payment information");
                     }
                     $stmt = "SELECT * FROM\r\n\t\t            \t{{sms_package_trans}}\r\n\t\t            \tWHERE\r\n\t\t            \tmerchant_id ='" . $_GET['mtid'] . "'\r\n\t\t            \tAND\r\n\t\t            \tsms_package_id='" . $_GET['package_id'] . "'\r\n\t\t            \tORDER BY id DESC\r\n\t\t            \tLIMIT 0,1\r\n\t\t            \t";
                     if ($res2 = $db_ext->rst($stmt)) {
                         $current_id = $res2[0]['id'];
                         $params_update = array('status' => "paid");
                         $db_ext->updateData("{{sms_package_trans}}", $params_update, 'id', $current_id);
                     }
                     echo 'OK';
                     die;
                 } else {
                     $error = t("ERROR: api returns empty");
                 }
             } catch (WebToPayException $e) {
                 $error = t("ERROR: Something went wrong") . ". " . $e;
             }
         } else {
             echo 'init';
         }
     } else {
         $error = Yii::t("default", "Failed. Cannot process payment");
     }
     if (!empty($error)) {
         //$this->render('error',array('message'=>$error));
         echo $error;
     }
     //$this->createLogs('');
 }
 function validateOrder($orderID)
 {
     if (ltrim($_GET[WebToPay::PREFIX . 'orderid'], "0") != $orderID) {
         exit('Order ID mismatch!');
     }
     global $application;
     $msg =& $application->getInstance('MessageResources', "payment-module-wtp-messages", "AdminZone");
     $moduleData = $this->getSettings();
     $query = new DB_Select();
     $query->addSelectTable('order_prices');
     $query->addSelectField('*');
     $query->WhereValue('order_id', DB_EQ, $orderID);
     $Order = $application->db->getDB_Result($query);
     try {
         WebToPay::toggleSS2(true);
         $response = WebToPay::checkResponse($_GET, array('projectid' => $moduleData['MODULE_METHOD_ID'], 'sign_password' => $moduleData['MODULE_METHOD_PASS']));
     } catch (Exception $e) {
         exit(get_class($e) . ': ' . $e->getMessage());
     }
     if (intval(number_format($Order[0]['order_total'], 2, '', '')) > $_GET[WebToPay::PREFIX . 'amount']) {
         exit('Bad amount!');
     } else {
         if ($Order[0]['currency_code'] != $_GET[WebToPay::PREFIX . 'currency']) {
             exit('Bad currency!');
         } else {
             modApiFunc("Checkout", "UpdatePaymentStatusInDB", $orderID, 2, 'Payment accepted.');
             exit('OK');
         }
     }
 }
예제 #13
0
<?php

require_once 'includes/helpers.php';
require_once 'includes/config.php';
require_once '../src/includes.php';
$post = removeQuotes($_POST);
$id = $post['id'];
if (!isset($shopItems[$id])) {
    redirect_to(get_address());
}
$item = $shopItems[$id];
$data = load_data();
$orderid = isset($data['orderid']) ? $data['orderid'] + 1 : 1;
$order = array('amount' => $item['price'], 'currency' => $item['currency'], 'orderid' => $orderid);
$data['orderid'] = $orderid;
$data['orders'][$orderid] = array('item' => $item, 'status' => 'new', 'additionalData' => $post);
save_data($data);
// this method builds request and sends Location header for redirecting to payment site
// as an alternative, you can use WebToPay::buildRequest and make auto-post form
WebToPay::redirectToPayment(array_merge($post, $config, $order));