Beispiel #1
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');
 }
Beispiel #2
0
 /**
  * Updating module
  * @return bool
  */
 public function update()
 {
     if (!$this->setDefaultConfig() or !$this->registerHook('payment') or !$this->registerHook('paymentReturn') or !$this->registerHook('header') or !$this->registerHook('backOfficeHeader') or !$this->registerHook('displayPaymentEU') or !$this->registerHook('displayOrderDetail') or !$this->registerHook('displayCustomerAccount') or !$this->registerHook('displayShoppingCart') or !$this->registerHook('displayAdminOrder') or !$this->registerHook('displayAdminOrder') or !$this->addDotpayNewStatus() or !$this->addDotpayWaitingRefundStatus() or !$this->addDotpayFailedRefundStatus() or !$this->addDotpayTotalRefundStatus() or !$this->addDotpayPartialRefundStatus() or !$this->addReturnTab() or !DotpayInstruction::create() or !DotpayCreditCard::create() or !DotpayCardBrand::create()) {
         return false;
     }
     return true;
 }