/**
  * @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);
     }
 }
예제 #2
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) {
예제 #4
0
 public function isIpnValid($data, Payment_Invoice $invoice)
 {
     $ipn = $data['get'];
     try {
         WebToPay::checkResponse($ipn, array('projectid' => $this->getParam('projectid'), 'sign_password' => $this->getParam('sign_password')));
         $this->setOutput('OK');
         return true;
     } catch (WebToPayException $e) {
         error_log($e->getMessage());
         $this->setOutput('ERR');
         return false;
     }
 }
예제 #5
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;
 }
예제 #6
0
    	dump($amount_to_pay);
    	dump($payment_ref);*/
    $cancel_url = Yii::app()->getBaseUrl(true) . "/store/merchantSignup/Do/step3/token/{$my_token}/gateway/pys" . $extra_params;
    $accepturl = Yii::app()->getBaseUrl(true) . "/store/merchantSignup/Do/step3b/token/{$my_token}/gateway/pys/mode/accept" . $extra_params;
    $callback = Yii::app()->getBaseUrl(true) . "/store/merchantSignup/Do/step3b/token/{$my_token}/gateway/pys/mode/callback" . $extra_params;
    $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'])) {
        /*echo 'here mode';
        		dump($_GET);*/
        try {
            $response = WebToPay::checkResponse($_GET, array('projectid' => $projectid, 'sign_password' => $password));
            //dump($response);
            if (is_array($response) && count($response) >= 1) {
                if ($response['status'] == 0) {
                    ?>
<p class="uk-text-danger"><?php 
                    echo t("payment has no been executed");
                    ?>
</p><?php 
                    return;
                }
                if ($response['status'] == 3) {
                    ?>
<p class="uk-text-danger"><?php 
                    echo t("additional payment information");
                    ?>
예제 #7
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');
         }
     }
 }