/** * 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'); }
/** * Returns hidden fields for OneClick register card * @return type */ public function getHiddenFieldsOneClickRegister() { $hiddenFields = $this->getHiddenFieldsOneClick(); $cc = DotpayCreditCard::getCreditCardByOrder($this->parent->getLastOrderNumber()); $hash = $cc !== NULL ? $cc->hash : NULL; $hiddenFields['credit_card_store'] = 1; $hiddenFields['credit_card_customer_id'] = $hash; return $hiddenFields; }