Exemplo n.º 1
0
 /**
  * Display payment instruction for cash or transfer payments
  */
 public function initContent()
 {
     $this->display_column_left = false;
     parent::initContent();
     $errorMessage = NULL;
     if (Tools::getValue('order_id')) {
         $this->context->cart = Cart::getCartByOrderId(Tools::getValue('order_id'));
         $this->initPersonalData();
     }
     $channel = $this->context->cookie->dotpay_channel;
     unset($this->context->cookie->dotpay_channel);
     DotpayRegisterOrder::init($this);
     $payment = DotpayRegisterOrder::create($channel);
     if ($payment === NULL) {
         $instruction = DotpayInstruction::getByOrderId(Tools::getValue('order_id'));
         if (!empty($instruction) && $instruction->id == NULL) {
             $this->context->smarty->assign(array('isOk' => false));
         }
     } else {
         if (isset($payment['instruction']) && isset($payment['operation'])) {
             if ($this->api->isChannelInGroup($payment['operation']['payment_method']['channel_id'], array(DotpayApi::cashGroup))) {
                 $isCash = true;
             } else {
                 $isCash = false;
             }
             $instruction = new DotpayInstruction();
             $instruction->amount = $payment['instruction']['amount'];
             $instruction->currency = $payment['instruction']['currency'];
             $instruction->number = $payment['operation']['number'];
             $instruction->hash = DotpayInstruction::gethashFromPayment($payment);
             $instruction->is_cash = $isCash;
             $instruction->order_id = Tools::getValue('order_id');
             $instruction->channel = $payment['operation']['payment_method']['channel_id'];
             if (isset($payment['instruction']['recipient'])) {
                 $instruction->bank_account = $payment['instruction']['recipient']['bank_account_number'];
             }
             try {
                 $instruction->save();
             } catch (Exception $e) {
                 $this->context->smarty->assign(array('errorMessage' => $this->module->l("Unable to save instructions." . $e->getMessage())));
             }
         }
     }
     if (!empty($instruction) && $instruction->id != NULL) {
         if ($instruction->is_cash) {
             $template = 'cash.tpl';
             $address = $instruction->getPdfUrl($this->config->getDotpayTargetUrl());
             $bankImage = '';
         } else {
             $template = 'transfer.tpl';
             $address = $instruction->getBankPage($this->config->getDotpayTargetUrl());
         }
         $chData = $this->api->getChannelData($instruction->channel);
         $channelImage = $chData['logo'];
         $this->context->smarty->assign(array('meta_title' => $this->module->l('Complete payment'), 'isOk' => true, 'amount' => $instruction->amount, 'currency' => $instruction->currency, 'title' => $instruction->number, 'address' => $address, 'bankAccount' => $instruction->bank_account, 'recipient' => DotpayInstruction::DOTPAY_NAME, 'street' => DotpayInstruction::DOTPAY_STREET, 'city' => DotpayInstruction::DOTPAY_CITY, 'template' => './confirm/' . $template, 'channelImage' => $channelImage));
     }
     $this->setTemplate("confirm.tpl");
 }
Exemplo n.º 2
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');
 }
Exemplo n.º 3
0
 /**
  * Returns a rendered template with Dotpay area on order details
  * @param array $params Details of current order
  * @return string
  */
 public function hookDisplayOrderDetail($params)
 {
     if (!$this->config->isDotpayRenewEn()) {
         return '';
     }
     $order = new Order(Tools::getValue('id_order'));
     $instruction = DotpayInstruction::getByOrderId($order->id);
     $context = Context::getContext();
     $context->cookie->dotpay_channel = $instruction->channel;
     if ($order->module == 'dotpay') {
         $this->smarty->assign(array('isRenew' => $order->current_state == $this->config->getDotpayNewStatusId(), 'paymentUrl' => $this->context->link->getModuleLink('dotpay', 'payment', array('order_id' => $order->id)), 'isInstruction' => $instruction->id != NULL, 'instructionUrl' => $this->context->link->getModuleLink('dotpay', 'confirm', array('order_id' => $order->id))));
         return $this->display(__FILE__, 'renew.tpl');
     }
 }