/** * 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)); }
/** * 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; }