示例#1
0
 /**
  * Preparing hidden form with payment data before sending it to Dotpay
  */
 public function initContent()
 {
     parent::initContent();
     $this->display_column_left = false;
     $this->display_header = false;
     $this->display_footer = false;
     $cartId = 0;
     if (Tools::getValue('order_id') == false) {
         $cartId = $this->context->cart->id;
         $exAmount = $this->api->getExtrachargeAmount(true);
         if ($exAmount > 0 && !$this->isExVPinCart()) {
             $productId = $this->config->getDotpayExchVPid();
             if ($productId != 0) {
                 $product = new Product($productId, true);
                 $product->price = $exAmount;
                 $product->save();
                 $product->flushPriceCache();
                 $this->context->cart->updateQty(1, $product->id);
                 $this->context->cart->update();
                 $this->context->cart->getPackageList(true);
             }
         }
         $discAmount = $this->api->getDiscountAmount();
         if ($discAmount > 0) {
             $discount = new CartRule($this->config->getDotpayDiscountId());
             $discount->reduction_amount = $this->api->getDiscountAmount();
             $discount->reduction_currency = $this->context->cart->id_currency;
             $discount->reduction_tax = 1;
             $discount->update();
             $this->context->cart->addCartRule($discount->id);
             $this->context->cart->update();
             $this->context->cart->getPackageList(true);
         }
         $result = $this->module->validateOrder($this->context->cart->id, (int) $this->config->getDotpayNewStatusId(), $this->getDotAmount(), $this->module->displayName, NULL, array(), NULL, false, $this->customer->secure_key);
     } else {
         $this->context->cart = Cart::getCartByOrderId(Tools::getValue('order_id'));
         $this->initPersonalData();
         $cartId = $this->context->cart->id;
     }
     $this->api->onPrepareAction(Tools::getValue('dotpay_type'), array('order' => Order::getOrderByCartId($cartId), 'customer' => $this->context->customer->id));
     $sa = new DotpaySellerApi($this->config->getDotpaySellerApiUrl());
     if ($this->config->isDotpayDispInstruction() && $this->config->isApiConfigOk() && $this->api->isChannelInGroup(Tools::getValue('channel'), array(DotpayApi::cashGroup, DotpayApi::transfersGroup)) && $sa->isAccountRight($this->config->getDotpayApiUsername(), $this->config->getDotpayApiPassword(), $this->config->getDotpayApiVersion())) {
         $this->context->cookie->dotpay_channel = Tools::getValue('channel');
         Tools::redirect($this->context->link->getModuleLink($this->module->name, 'confirm', array('order_id' => Order::getOrderByCartId($cartId))));
         die;
     }
     $this->context->smarty->assign(array('hiddenForm' => $this->api->getHiddenForm()));
     $cookie = new Cookie('lastOrder');
     $cookie->orderId = Order::getOrderByCartId($cartId);
     $cookie->write();
     $this->setTemplate("preparing.tpl");
 }
 /**
  * Confirms requesting a refund
  */
 public function displayAjax()
 {
     $order = new Order(Tools::getValue('order'));
     $payments = OrderPayment::getByOrderId(Tools::getValue('order'));
     $sumOfPayments = 0.0;
     foreach ($payments as $payment) {
         if ($payment->payment_method == $this->module->displayName) {
             $sumOfPayments += (double) $payment->amount;
         }
     }
     if (abs($sumOfPayments) < 0.01) {
         $sumOfPayments = 0.0;
     }
     $sa = new DotpaySellerApi($this->config->getDotpaySellerApiUrl());
     $payment = $sa->getPaymentByNumber($this->config->getDotpayApiUsername(), $this->config->getDotpayApiPassword(), Tools::getValue('payment'));
     if (isset($payment->payment_method)) {
         $channel = $payment->payment_method->channel_id;
         unset($payment->payment_method);
         $payment->channel_id = $channel;
     }
     $payment->sum_of_payments = $sumOfPayments;
     $payment->return_description = $this->l('Refund of order:') . ' ' . $order->reference;
     die(json_encode($payment));
 }
示例#3
0
 /**
  * Check, if order id from control field is completed
  * @param int $control Order id from control field
  * @return boolean
  */
 private static function checkIfCompletedControlExist($control, $channel)
 {
     $api = new DotpaySellerApi(self::$config->getDotpaySellerApiUrl());
     $payments = $api->getPaymentByOrderId(self::$config->getDotpayApiUsername(), self::$config->getDotpayApiPassword(), $control);
     foreach ($payments as $payment) {
         $onePayment = $api->getPaymentByNumber(self::$config->getDotpayApiUsername(), self::$config->getDotpayApiPassword(), $payment->number);
         if ($onePayment->control == $control && $onePayment->payment_method->channel_id == $channel && $payment->status == 'completed') {
             return true;
         }
     }
     return false;
 }
示例#4
0
 /**
  * Function which is used to making payments
  */
 private function makePayment()
 {
     $id = $this->api->isSelectedPvChannel() ? $this->config->getDotpayPvId() : $this->config->getDotpayId();
     if (Tools::getValue('id') != $id) {
         die("PrestaShop - ERROR ID");
     }
     $order = new Order((int) $this->getDotControl(Tools::getValue('control')));
     $currency = new Currency($order->id_currency);
     $receivedCurrency = $this->api->getOperationCurrency();
     $orderCurrency = $currency->iso_code;
     if ($receivedCurrency != $orderCurrency) {
         die('PrestaShop - NO MATCH OR WRONG CURRENCY - ' . $receivedCurrency . ' <> ' . $orderCurrency);
     }
     $receivedAmount = floatval($this->api->getTotalAmount());
     $orderAmount = Tools::displayPrice($order->total_paid, $currency, false);
     $orderAmount = floatval($this->getCorrectAmount(preg_replace("/[^-0-9\\.]/", "", str_replace(',', '.', $orderAmount))));
     if ($receivedAmount != $orderAmount) {
         die('PrestaShop - NO MATCH OR WRONG AMOUNT - ' . $receivedAmount . ' <> ' . $orderAmount);
     }
     $newOrderState = $this->api->getNewOrderState();
     if ($newOrderState === NULL) {
         die('PrestaShop - WRONG TRANSACTION STATUS');
     }
     $cc = DotpayCreditCard::getCreditCardByOrder($order->id);
     if ($cc !== NULL && $cc->id !== NULL && $cc->card_id == NULL) {
         $sellerApi = new DotpaySellerApi($this->config->getDotpaySellerApiUrl());
         $ccInfo = $sellerApi->getCreditCardInfo($this->config->getDotpayApiUsername(), $this->config->getDotpayApiPassword(), $this->api->getOperationNumber());
         $cc->brand = $ccInfo->brand->name;
         $cc->mask = $ccInfo->masked_number;
         $cc->card_id = $ccInfo->id;
         $cc->save();
         $brand = new DotpayCardBrand($ccInfo->brand->name);
         $brand->name = $ccInfo->brand->name;
         $brand->image = $ccInfo->brand->logo;
         $brand->save();
     }
     $history = new OrderHistory();
     $history->id_order = $order->id;
     $lastOrderState = OrderHistory::getLastOrderState($history->id_order);
     if ($lastOrderState->id != $newOrderState) {
         $history->changeIdOrderState($newOrderState, $history->id_order);
         $history->addWithemail(true);
         if ($newOrderState == _PS_OS_PAYMENT_) {
             $payments = OrderPayment::getByOrderId($order->id);
             if (count($payments)) {
                 $payments[0]->transaction_id = $this->api->getOperationNumber();
                 $payments[0]->payment_method = $this->module->displayName;
                 $payments[0]->update();
             }
             $instruction = DotpayInstruction::getByOrderId($order->id);
             if ($instruction !== NULL) {
                 $instruction->delete();
             }
         }
     } else {
         if ($lastOrderState->id == $newOrderState && $newOrderState == _PS_OS_PAYMENT_) {
             die('PrestaShop - ORDER IS ALERADY PAID');
         }
     }
     die('OK');
 }
示例#5
0
文件: dotpay.php 项目: dotpay/dotpay
 /**
  * Returns HTML for module settings
  * @return string
  */
 public function getContent()
 {
     $this->saveConfiguration();
     $sellerApi = new DotpaySellerApi($this->config->getDotpaySellerApiUrl());
     $version = DotpayGithubApi::getLatestVersion();
     $this->context->smarty->assign(array('regMessEn' => $this->config->isDotpayTestMode() || !$this->config->isAccountConfigOk(), 'targetForUrlc' => $this->context->link->getModuleLink('dotpay', 'callback', array('ajax' => '1'), $this->isSSLEnabled()), 'moduleMainDir' => $this->_path, 'testMode' => $this->config->isDotpayTestMode(), 'oldVersion' => !version_compare(_PS_VERSION_, "1.6.0.1", ">="), 'badPhpVersion' => !version_compare(PHP_VERSION, "5.4", ">="), 'confOK' => $this->config->isAccountConfigOk() && $this->config->isDotpayEnabled(), 'moduleVersion' => $this->version, 'apiVersion' => $this->config->getDotpayApiVersion(), 'phpVersion' => PHP_VERSION, 'minorPhpVersion' => '5.4', 'badNewIdMessage' => $this->l('Incorrect ID (required 6 digits)'), 'badOldIdMessage' => $this->l('Incorrect ID (5 digits maximum)'), 'badNewPinMessage' => $this->l('Incorrect PIN (minimum 16 and maximum 32 alphanumeric characters)'), 'badOldPinMessage' => $this->l('Incorrect PIN (0 or 16 alphanumeric characters)'), 'valueLowerThanZero' => $this->l('The value must be greater than zero.'), 'testSellerId' => $this->api->checkSellerId($this->config->getDotpayId()), 'testApiAccount' => $sellerApi->isAccountRight($this->config->getDotpayApiUsername(), $this->config->getDotpayApiPassword(), $this->config->getDotpayApiVersion()), 'urlWithNewVersion' => $version['url'], 'obsoletePlugin' => version_compare($version['version'], $this->version, '>'), 'canNotCheckPlugin' => $version['version'] === NULL));
     $template = $this->context->smarty->fetch($this->local_path . 'views/templates/admin/configure.tpl');
     return $template . $this->renderForm();
 }