/** * {@inheritDoc} */ public function getData() { $data = $this->refund->toArray(); $data['payment_id'] = $this->paymentId; if (false === empty($this->emsUrl)) { $data['ems_url'] = $this->emsUrl; } return $data; }
/** * {@inheritDoc} */ public function buildResponse(stdClass $response) { if (!isset($response->refund)) { throw new Syspay_Merchant_UnexpectedResponseException('Unable to retrieve "refund" data from response', $response); } $refund = Syspay_Merchant_Entity_Refund::buildFromResponse($response->refund); return $refund; }
/** * {@inheritDoc} */ public function buildResponse(stdClass $response) { if (!isset($response->refunds) || !is_array($response->refunds)) { throw new Syspay_Merchant_UnexpectedResponseException('Unable to retrieve "refunds" data from response', $response); } $refunds = array(); foreach ($response->refunds as $r) { $refund = Syspay_Merchant_Entity_Refund::buildFromResponse($r); array_push($refunds, $refund); } return $refunds; }
/** * Return the entity linked to the EMS call received * @return mixed One of the Syspay_Merchant_Entity classes depending on the event received * @throws Syspay_Merchant_EMSException If something went wrong while parsing the request */ public function getEvent() { if (!$this->skipAuthCheck) { $this->checkChecksum(); } $content = $this->getContent(); if (!isset($content->type)) { throw new Syspay_Merchant_EMSException('Unable to get event type', Syspay_Merchant_EMSException::CODE_INVALID_CONTENT); } if (!isset($content->data)) { throw new Syspay_Merchant_EMSException('Unable to get data from content', Syspay_Merchant_EMSException::CODE_INVALID_CONTENT); } switch ($content->type) { case 'payment': if (!isset($content->data->payment)) { throw new Syspay_Merchant_EMSException('Payment event received with no payment data', Syspay_Merchant_EMSException::CODE_INVALID_CONTENT); } return Syspay_Merchant_Entity_Payment::buildFromResponse($content->data->payment); break; case 'refund': if (!isset($content->data->refund)) { throw new Syspay_Merchant_EMSException('Refund event received with no refund data', Syspay_Merchant_EMSException::CODE_INVALID_CONTENT); } return Syspay_Merchant_Entity_Refund::buildFromResponse($content->data->refund); break; case 'chargeback': if (!isset($content->data->chargeback)) { throw new Syspay_Merchant_EMSException('Chargeback event received with no chargeback data', Syspay_Merchant_EMSException::CODE_INVALID_CONTENT); } return Syspay_Merchant_Entity_Chargeback::buildFromResponse($content->data->chargeback); break; case 'billing_agreement': if (!isset($content->data->billing_agreement)) { throw new Syspay_Merchant_EMSException('Billing agreement event received with no billing_agreement data', Syspay_Merchant_EMSException::CODE_INVALID_CONTENT); } return Syspay_Merchant_Entity_BillingAgreement::buildFromResponse($content->data->billing_agreement); break; case 'subscription': if (!isset($content->data->subscription)) { throw new Syspay_Merchant_EMSException('Subscription event received with no subscription data', Syspay_Merchant_EMSException::CODE_INVALID_CONTENT); } return Syspay_Merchant_Entity_Subscription::buildFromResponse($content->data->subscription); default: throw new Syspay_Merchant_EMSException('Unknown type: ' . $content->type, Syspay_Merchant_EMSException::CODE_INVALID_CONTENT); } }
public static function processAdminForms($order, $id) { if (Configuration::get('SYSPAY_MODE') == 0) { $mode = Syspay_Merchant_Client::BASE_URL_SANDBOX; $mid = Configuration::get('SYSPAY_TEST_MID'); $pass = Configuration::get('SYSPAY_TEST_SHA1_PRIVATE'); } else { $mode = Syspay_Merchant_Client::BASE_URL_PROD; $mid = Configuration::get('SYSPAY_LIVE_MID'); $pass = Configuration::get('SYSPAY_LIVE_SHA1_PRIVATE'); } $client = new Syspay_Merchant_Client($mid, $pass, $mode); $info_request = new Syspay_Merchant_PaymentInfoRequest($id); try { $payment = $client->request($info_request); } catch (Syspay_Merchant_RequestException $s) { return false; } catch (Syspay_Merchant_UnexpectedResponseException $s) { return false; } if (!$payment) { return false; } if (Tools::getValue('sp_cancel_payment') == 2) { if (version_compare(_PS_VERSION_, '1.5', '<')) { $current_state = $order->getCurrentState(); } else { $current_state = $order->getCurrentOrderState()->id; } if ($current_state == Configuration::get('PS_OS_SYSPAY_AUTHORIZED') && $payment->getStatus() == 'AUTHORIZED') { $void_request = new Syspay_Merchant_VoidRequest(); $void_request->setPaymentId($id); // Returned to you on the initial payment request $client->request($void_request); if (version_compare(_PS_VERSION_, '1.5', '<')) { Tools::redirectAdmin(AdminController::$currentIndex . '&vieworder&id_order=' . $order->id . '&token=' . Tools::getAdminTokenLite('AdminOrders')); } else { Tools::redirectAdmin(Context::getContext()->link->getAdminLink('AdminOrders', true) . '&vieworder&id_order=' . $order->id); } } } if (Tools::getValue('refund_form') == 2) { $ids_syspay_refund = Db::getInstance()->executeS(' SELECT sr.id_syspay_refund FROM ' . _DB_PREFIX_ . 'syspay_refund sr WHERE sr.id_order=' . $order->id); $original_payment = Db::getInstance()->getValue(' SELECT sp.id_syspay_payment FROM ' . _DB_PREFIX_ . 'syspay_payment sp LEFT JOIN ' . _DB_PREFIX_ . 'orders o ON o.id_cart=sp.id_cart WHERE o.id_order=' . $order->id); $payment_ir = new Syspay_Merchant_PaymentInfoRequest($original_payment); try { $payment_info = $client->request($payment_ir); } catch (Syspay_Merchant_RequestException $s) { return false; } catch (Syspay_Merchant_UnexpectedResponseException $s) { return false; } if (!$payment_info) { return false; } $total_paid = $payment_info->getAmount(); $total_paid = $total_paid / 100; $total = 0; foreach ($ids_syspay_refund as $id) { $refund_ir = new Syspay_Merchant_RefundInfoRequest($id['id_syspay_refund']); $refund_info = $client->request($refund_ir); if (!$refund_info) { return false; } $amount = $refund_info->getAmount(); $amount = $amount / 100; $total += $amount; } $val = Tools::getValue('refund_value'); if ($val == '') { return false; } $val = str_replace(',', '.', $val); $val = number_format($val, 2, '.', ''); $refund_value = $val * 100; if ($val + $total > $total_paid) { return false; } $refund = new Syspay_Merchant_Entity_Refund(); $refund->setReference(count($ids_syspay_refund) . $payment->getReference()); // Your own reference for this refund $refund->setAmount($refund_value); // The amount to refund in *cents* $refund->setCurrency($payment->getCurrency()); // The currency of the refund. It must match the one of the original payment $refund->setDescription(Tools::getValue('refund_reason')); // An optional description for this refund $refund_request = new Syspay_Merchant_RefundRequest(); $refund_request->setPaymentId($original_payment); // The payment id to refund $website = SyspayTools::getWebsite(true, false); $refund_request->setEmsUrl($website . _MODULE_DIR_ . 'syspay/ems.php'); $refund_request->setRefund($refund); try { $refund = $client->request($refund_request); } catch (Syspay_Merchant_RequestException $s) { return false; } catch (Syspay_Merchant_UnexpectedResponseException $s) { return false; } if (version_compare(_PS_VERSION_, '1.5', '<')) { Tools::redirectAdmin(AdminController::$currentIndex . '&vieworder&id_order=' . $order->id . '&token=' . Tools::getAdminTokenLite('AdminOrders')); } else { Tools::redirectAdmin(Context::getContext()->link->getAdminLink('AdminOrders', true) . '&vieworder&id_order=' . $order->id); } } }