Example #1
0
 /**
  * Removes saved credit card
  */
 public function initContent()
 {
     $this->display_column_left = false;
     parent::initContent();
     $cc = new DotpayCreditCard(Tools::getValue('card_id'));
     if ($cc->id != NULL) {
         $cc->delete();
         die('OK');
     } else {
         die('Card not found');
     }
 }
Example #2
0
 /**
  * Displays a page with saved credit cards
  */
 public function initContent()
 {
     $this->display_column_left = false;
     parent::initContent();
     $this->context->smarty->assign(array('cards' => DotpayCreditCard::getAllCardsForCustomer($this->context->customer->id), 'onRemoveMessage' => $this->module->l('Do you want to deregister a saved card'), 'onDoneMessage' => $this->module->l('The card was deregistered'), 'onFailureMessage' => $this->module->l('An error occurred while deregistering the card'), 'removeUrl' => $this->context->link->getModuleLink($this->module->name, 'ocremove')));
     $this->setTemplate("ocmanage.tpl");
 }
Example #3
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');
 }
Example #4
0
 /**
  * Uninstalling module
  * @return bool
  */
 public function uninstall()
 {
     return DotpayCreditCard::drop() && $this->removeDotpayFee() && parent::uninstall();
 }
Example #5
0
 /**
  * Executed when credit card is prepared in One Click method
  * @param array $params Needed params
  * @return boolean
  */
 protected function onPrepareOneClick($params)
 {
     $cc = new DotpayCreditCard();
     $cc->order_id = $params['order'];
     $cc->customer_id = $params['customer'];
     $cc->register_date = date('d-m-Y');
     return $cc->save();
 }
Example #6
0
 /**
  * 
  * @param int|null $id Credit card object id
  */
 public function __construct($id = null)
 {
     parent::__construct($id);
     $this->register_date = DotpayCreditCard::reverseDate($this->register_date);
     $this->card_brand = new DotpayCardBrand($this->brand);
 }