diff --git a/DIEGIMAS.txt b/DIEGIMAS.txt index 75ffb61..c87f104 100644 --- a/DIEGIMAS.txt +++ b/DIEGIMAS.txt @@ -8,4 +8,4 @@ Diegimas Kontaktai -Kilus klausimams prasome kreiptis i pagalba@mokejimai.lt \ No newline at end of file +Kilus klausimams prasome kreiptis i pagalba@paysera.lt diff --git a/README.md b/README.md index 4aef993..b154452 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,20 @@ plugin-opencart =============== -Paysera.com payment gateway plugin for OpenCart +Paysera.com payment gateway plugin for OpenCart 2.2 Requirements ------------ -- OpenCart +- OpenCart 2.2 Installation ------------ 1. Download this repository as zip and extract "admin,catalog,system" folders into opencart main directory. -2. In admin panel active payment method and enter webtopay.com / mokejimai.lt ID code, password and etc. -3. IMPORTANT! Go to System->Localisation->Currencies and insert Lithuanian litas currency. Currency may be disabled. -4. Make sure libwebtopay directory is writable and cache.php file is writable. +3. In admin panel active payment method and enter paysera.com project ID code, password and etc. +4. IMPORTANT! Go to System->Localisation->Currencies and insert euro currency. Currency may be disabled. +5. Make sure libwebtopay directory is writable and cache.php file is writable. Contacts -------- diff --git a/README.txt b/README.txt index 9befc1d..cb49dbf 100644 --- a/README.txt +++ b/README.txt @@ -2,8 +2,8 @@ Installation 1. BACKUP ALL FILES[optional]. 2. Copy files to Open Cart directory. -3. In admin panel active payment method and enter webtopay.com / mokejimai.lt ID code, password and etc. -4. IMPORTANT! Go to System->Localisation->Currencies and insert Lithuanian litas currency. Currency may be disabled. +3. In admin panel active payment method and enter paysera.com project ID code, password and etc. +4. IMPORTANT! Go to System->Localisation->Currencies and insert euro currency. Currency may be disabled. 5. Make sure libwebtopay directory is writable and cache.php file is writable. Contacts diff --git a/admin/controller/payment/paysera.php b/admin/controller/payment/paysera.php old mode 100644 new mode 100755 index 536eb93..2a3c9d4 --- a/admin/controller/payment/paysera.php +++ b/admin/controller/payment/paysera.php @@ -1,11 +1,15 @@ load->language('payment/paysera'); + $this->language->load('payment/paysera'); + $this->document->setTitle($this->language->get('heading_title')); $this->load->model('setting/setting'); if ($this->request->server['REQUEST_METHOD'] == 'POST') { @@ -13,155 +17,168 @@ public function index() { $this->load->model('setting/setting'); $this->model_setting_setting->editSetting('paysera', $this->request->post); $this->session->data['success'] = $this->language->get('text_success'); - $this->redirect(HTTPS_SERVER . 'index.php?route=extension/payment&token=' . $this->session->data['token']); + $this->response->redirect($this->url->link('extension/payment', 'token=' . $this->session->data['token'], 'SSL')); } } - $this->data['heading_title'] = $this->language->get('heading_title'); + $data['heading_title'] = $this->language->get('heading_title'); - $this->data['text_enabled'] = $this->language->get('text_enabled'); - $this->data['text_disabled'] = $this->language->get('text_disabled'); - $this->data['text_all_zones'] = $this->language->get('text_all_zones'); - $this->data['text_none'] = $this->language->get('text_none'); - $this->data['text_yes'] = $this->language->get('text_yes'); - $this->data['text_no'] = $this->language->get('text_no'); - $this->data['text_on'] = $this->language->get('text_on'); - $this->data['text_off'] = $this->language->get('text_off'); + $data['text_edit'] = $this->language->get('text_edit'); + $data['text_enabled'] = $this->language->get('text_enabled'); + $data['text_disabled'] = $this->language->get('text_disabled'); + $data['text_all_zones'] = $this->language->get('text_all_zones'); + $data['text_none'] = $this->language->get('text_none'); + $data['text_yes'] = $this->language->get('text_yes'); + $data['text_no'] = $this->language->get('text_no'); + $data['text_on'] = $this->language->get('text_on'); + $data['text_off'] = $this->language->get('text_off'); - $this->data['entry_project'] = $this->language->get('entry_project'); - $this->data['entry_sign'] = $this->language->get('entry_sign'); - $this->data['entry_lang'] = $this->language->get('entry_lang'); - $this->data['entry_test'] = $this->language->get('entry_test'); - $this->data['entry_order_status'] = $this->language->get('entry_order_status'); - $this->data['entry_geo_zone'] = $this->language->get('entry_geo_zone'); - $this->data['entry_status'] = $this->language->get('entry_status'); - $this->data['entry_default_payments'] = $this->language->get('entry_payment_lang'); - $this->data['entry_display_payments'] = $this->language->get('entry_paymentlist'); - $this->data['entry_sort_order'] = $this->language->get('entry_sort_order'); + $data['entry_project'] = $this->language->get('entry_project'); + $data['entry_sign'] = $this->language->get('entry_sign'); + $data['entry_lang'] = $this->language->get('entry_lang'); + $data['help_lang'] = $this->language->get('help_lang'); + $data['entry_test'] = $this->language->get('entry_test'); + $data['entry_new_order_status'] = $this->language->get('entry_new_order_status'); + $data['entry_order_status'] = $this->language->get('entry_order_status'); + $data['entry_geo_zone'] = $this->language->get('entry_geo_zone'); + $data['entry_status'] = $this->language->get('entry_status'); + $data['entry_default_payments'] = $this->language->get('entry_payment_lang'); + $data['entry_display_payments'] = $this->language->get('entry_paymentlist'); + $data['entry_sort_order'] = $this->language->get('entry_sort_order'); - $this->data['help_callback'] = $this->language->get('help_callback'); + $data['help_callback'] = $this->language->get('help_callback'); - $this->data['button_save'] = $this->language->get('button_save'); - $this->data['button_cancel'] = $this->language->get('button_cancel'); + $data['button_save'] = $this->language->get('button_save'); + $data['button_cancel'] = $this->language->get('button_cancel'); - $this->data['tab_general'] = $this->language->get('tab_general'); + $data['tab_general'] = $this->language->get('tab_general'); if (!isset($this->error['warning'])) $this->error['warning'] = ''; - $this->data['error_warning'] = $this->error['warning']; + $data['error_warning'] = $this->error['warning']; if (!isset($this->error['project'])) $this->error['project'] = ''; - $this->data['error_project'] = $this->error['project']; + $data['error_project'] = $this->error['project']; if (!isset($this->error['sign'])) $this->error['sign'] = ''; - $this->data['error_sign'] = $this->error['sign']; + $data['error_sign'] = $this->error['sign']; if (!isset($this->error['lang'])) $this->error['lang'] = ''; - $this->data['error_lang'] = $this->error['lang']; + $data['error_lang'] = $this->error['lang']; - $this->document->breadcrumbs = array(); + $data['breadcrumbs'] = array(); - $this->document->breadcrumbs[] = array( - 'href' => HTTPS_SERVER . 'index.php?route=common/home', - 'text' => $this->language->get('text_home'), - 'separator' => FALSE - ); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_home'), + 'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], 'SSL') + ); - $this->document->breadcrumbs[] = array( - 'href' => HTTPS_SERVER . 'index.php?route=extension/payment', - 'text' => $this->language->get('text_payment'), - 'separator' => ' :: ' - ); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('text_payment'), + 'href' => $this->url->link('extension/payment', 'token=' . $this->session->data['token'], 'SSL') + ); - $this->document->breadcrumbs[] = array( - 'href' => HTTPS_SERVER . 'index.php?route=payment/paysera', - 'text' => $this->language->get('heading_title'), - 'separator' => ' :: ' - ); + $data['breadcrumbs'][] = array( + 'text' => $this->language->get('heading_title'), + 'href' => $this->url->link('payment/paysera', 'token=' . $this->session->data['token'], 'SSL') + ); // $this->data['action'] = $this->url->link('payment/paysera', 'token=' . $this->session->data['token'], 'SSL'); // // $this->data['cancel'] = $this->url->link('extension/payment', 'token=' . $this->session->data['token'], 'SSL'); - $this->data['action'] = HTTPS_SERVER . 'index.php?route=payment/paysera&token=' . $this->session->data['token']; +// $data['action'] = HTTPS_SERVER . 'index.php?route=payment/paysera&token=' . $this->session->data['token']; + + $data['action'] = $this->url->link('payment/paysera', 'token=' . $this->session->data['token'], 'SSL'); - $this->data['cancel'] = HTTPS_SERVER . 'index.php?route=extension/payment&token=' . $this->session->data['token']; + $data['cancel'] = HTTPS_SERVER . 'index.php?route=extension/payment&token=' . $this->session->data['token']; if (isset($this->request->post['paysera_project'])) { - $this->data['paysera_project'] = $this->request->post['paysera_project']; + $data['paysera_project'] = $this->request->post['paysera_project']; } else { - $this->data['paysera_project'] = $this->config->get('paysera_project'); + $data['paysera_project'] = $this->config->get('paysera_project'); } if (isset($this->request->post['paysera_sign'])) { - $this->data['paysera_sign'] = $this->request->post['paysera_sign']; + $data['paysera_sign'] = $this->request->post['paysera_sign']; } else { - $this->data['paysera_sign'] = $this->config->get('paysera_sign'); + $data['paysera_sign'] = $this->config->get('paysera_sign'); } if (isset($this->request->post['paysera_lang'])) { - $this->data['paysera_lang'] = $this->request->post['paysera_lang']; + $data['paysera_lang'] = $this->request->post['paysera_lang']; } else { - $this->data['paysera_lang'] = $this->config->get('paysera_lang'); + $data['paysera_lang'] = $this->config->get('paysera_lang'); } - $this->data['callback'] = HTTP_CATALOG . 'index.php?route=payment/paysera/callback'; + $data['callback'] = HTTP_CATALOG . 'index.php?route=payment/paysera/callback'; if (isset($this->request->post['paysera_test'])) { - $this->data['paysera_test'] = $this->request->post['paysera_test']; + $data['paysera_test'] = $this->request->post['paysera_test']; } else { - $this->data['paysera_test'] = $this->config->get('paysera_test'); + $data['paysera_test'] = $this->config->get('paysera_test'); } if (isset($this->request->post['paysera_order_status_id'])) { - $this->data['paysera_order_status_id'] = $this->request->post['paysera_order_status_id']; + $data['paysera_order_status_id'] = $this->request->post['paysera_order_status_id']; + } else { + $data['paysera_order_status_id'] = $this->config->get('paysera_order_status_id'); + } + + if (isset($this->request->post['paysera_new_order_status_id'])) { + $data['paysera_new_order_status_id'] = $this->request->post['paysera_new_order_status_id']; } else { - $this->data['paysera_order_status_id'] = $this->config->get('paysera_order_status_id'); + $data['paysera_new_order_status_id'] = $this->config->get('paysera_new_order_status_id'); } - if (isset($this->request->post['display_payments_list'])) { - $this->data['display_payments_list'] = $this->request->post['display_payments_list']; + if (isset($this->request->post['paysera_display_payments_list'])) { + $data['paysera_display_payments_list'] = $this->request->post['paysera_display_payments_list']; } else { - $this->data['display_payments_list'] = $this->config->get('display_payments_list'); + $data['paysera_display_payments_list'] = $this->config->get('paysera_display_payments_list'); } $this->load->model('localisation/order_status'); - $this->data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); //here + $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses(); //here - $this->data['payment_countries'] = $this->getCountries(); + $data['payment_countries'] = $this->getCountries(); if (isset($this->request->post['paysera_geo_zone_id'])) { - $this->data['paysera_geo_zone_id'] = $this->request->post['paysera_geo_zone_id']; + $data['paysera_geo_zone_id'] = $this->request->post['paysera_geo_zone_id']; } else { - $this->data['paysera_geo_zone_id'] = $this->config->get('paysera_geo_zone_id'); + $data['paysera_geo_zone_id'] = $this->config->get('paysera_geo_zone_id'); } if (isset($this->request->post['default_payment_country'])) { - $this->data['default_payment_country'] = $this->request->post['default_payment_country']; + $data['default_payment_country'] = $this->request->post['default_payment_country']; } else { - $this->data['default_payment_country'] = $this->config->get('default_payment_country'); + $data['default_payment_country'] = $this->config->get('default_payment_country'); } $this->load->model('localisation/geo_zone'); - $this->data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); + $data['geo_zones'] = $this->model_localisation_geo_zone->getGeoZones(); if (isset($this->request->post['paysera_status'])) { - $this->data['paysera_status'] = $this->request->post['paysera_status']; + $data['paysera_status'] = $this->request->post['paysera_status']; } else { - $this->data['paysera_status'] = $this->config->get('paysera_status'); + $data['paysera_status'] = $this->config->get('paysera_status'); } if (isset($this->request->post['paysera_sort_order'])) { - $this->data['paysera_sort_order'] = $this->request->post['paysera_sort_order']; + $data['paysera_sort_order'] = $this->request->post['paysera_sort_order']; } else { - $this->data['paysera_sort_order'] = $this->config->get('paysera_sort_order'); + $data['paysera_sort_order'] = $this->config->get('paysera_sort_order'); } $this->template = 'payment/paysera.tpl'; - $this->children = array( + /*$this->children = array( 'common/header', 'common/footer' - ); + );*/ + $data['header'] = $this->load->controller('common/header'); + $data['column_left'] = $this->load->controller('common/column_left'); + $data['footer'] = $this->load->controller('common/footer'); - $this->response->setOutput($this->render(TRUE), $this->config->get('config_compression')); + + $this->response->setOutput($this->load->view($this->template, $data)); + //$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression')); } @@ -170,23 +187,20 @@ private function validate() { $this->error['warning'] = $this->language->get('error_permission'); } - if (!@$this->request->post['paysera_project']) { + if (!$this->request->post['paysera_project']) { $this->error['project'] = $this->language->get('error_project'); } - if (!@$this->request->post['paysera_sign']) { + if (!$this->request->post['paysera_sign']) { $this->error['sign'] = $this->language->get('error_sign'); } - if (!@$this->request->post['paysera_lang']) { - $this->error['lang'] = $this->language->get('error_lang'); - } + if (!$this->request->post['paysera_lang']) { + $this->error['lang'] = $this->language->get('error_lang'); + } - if (!$this->error) { - return true; - } else { - return false; - } + + return !$this->error; } private function getCountries() { diff --git a/admin/language/english/payment/paysera.php b/admin/language/english/payment/paysera.php old mode 100644 new mode 100755 index 25885eb..9a85a66 --- a/admin/language/english/payment/paysera.php +++ b/admin/language/english/payment/paysera.php @@ -11,8 +11,11 @@ // Entry $_['entry_project'] = 'Project ID:'; $_['entry_sign'] = 'Signature password:'; -$_['entry_lang'] = 'Language (LIT, ENG, RUS):'; +$_['entry_lang'] = 'Language:'; +$_['help_lang'] = 'LIT, ENG, RUS'; $_['entry_test'] = 'Test Mode:'; +$_['text_edit'] = 'Edit Paysera'; +$_['entry_new_order_status'] = 'New Order Status:'; $_['entry_order_status'] = 'Order Status after payment:'; $_['entry_payment_lang'] = 'Default country of payment methods:'; $_['entry_geo_zone'] = 'Geo Zone:'; diff --git a/admin/language/lithuanian/payment/paysera.php b/admin/language/lithuanian/payment/paysera.php old mode 100644 new mode 100755 index 748b4e0..7be5969 --- a/admin/language/lithuanian/payment/paysera.php +++ b/admin/language/lithuanian/payment/paysera.php @@ -7,12 +7,15 @@ $_['text_success'] = 'Success: You have modified Paysera account details!'; $_['text_on'] = 'Įjungtas'; $_['text_off'] = 'Išjungtas'; +$_['text_edit'] = 'Redaguoti Paysera'; // Entry $_['entry_project'] = 'Projekto ID:'; $_['entry_sign'] = 'Slaptažodis:'; -$_['entry_lang'] = 'Kalba (LIT, ENG, RUS):'; +$_['entry_lang'] = 'Kalba:'; +$_['help_lang'] = 'LIT, ENG, RUS:'; $_['entry_test'] = 'Testinis režimas:'; +$_['entry_new_order_status'] = 'Naujo užsakymo statusas:'; $_['entry_order_status'] = 'Užsakymo statusas po mokėjimo:'; $_['entry_payment_lang'] = 'Pirminė mokėjimo būdų šalis:'; $_['entry_geo_zone'] = 'Geo zona:'; diff --git a/admin/view/template/payment/paysera.tpl b/admin/view/template/payment/paysera.tpl old mode 100644 new mode 100755 index 26a99b0..23dc110 --- a/admin/view/template/payment/paysera.tpl +++ b/admin/view/template/payment/paysera.tpl @@ -1,144 +1,185 @@ - +
-
-
-

-
- - +
+ -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*
- - - -
* -
- - - -
* -
- - - -
- -
- -
- -
- -
- -
- -
- -
+ +
+ +
+ +
+ +
+
+

+
+ + + + + + + + +
+ +
+ +
+ + +
+ +
+
+ + +
+ +
+ + +
+ +
+
+ + +
+ +
+ + +
+ +
+
+ + +
+ +
+ +
+
+ + +
+ +
+ +
+
+ + +
+ +
+ +
+
+ + +
+ +
+ +
+
+ + +
+ +
+ +
+
+ + +
+ +
+ +
+
+ + +
+ +
+ +
+
-
- -
+
+
diff --git a/catalog/controller/payment/paysera.php b/catalog/controller/payment/paysera.php old mode 100644 new mode 100755 index 57de090..86c9efc --- a/catalog/controller/payment/paysera.php +++ b/catalog/controller/payment/paysera.php @@ -1,185 +1,221 @@ -data['action'] = HTTPS_SERVER . 'index.php?route=payment/paysera/confirm'; - $this->data['button_confirm'] = $this->language->get('button_confirm'); - $this->data['button_back'] = $this->language->get('button_back'); - - $this->language->load('payment/paysera'); - $this->data['text_chosen'] = $this->language->get('text_chosen'); - $this->data['text_paycountry'] = $this->language->get('text_paycountry'); - - $this->data['default_country'] = $this->config->get('default_payment_country'); - $this->data['display_payments'] = $this->config->get('display_payments_list'); - - - if ($this->request->get['route'] != 'checkout/guest/confirm') { - $this->data['back'] = HTTPS_SERVER . 'index.php?route=checkout/payment'; - } else { - $this->data['back'] = HTTPS_SERVER . 'index.php?route=checkout/guest'; - } - - $this->id = 'payment'; - - if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/paysera.tpl')) { - $this->template = $this->config->get('config_template') . '/template/payment/paysera.tpl'; - } else { - $this->template = 'default/template/payment/paysera.tpl'; - } - - $this->render(); - } - - public function confirm() { - - $this->load->model('checkout/order'); - $order = $this->model_checkout_order->getOrder($this->session->data['order_id']); - $this->load->library('encryption'); - $language = $this->config->get('paysera_lang'); - - if (!isset($_SERVER['HTTPS'])) { - $_SERVER['HTTPS'] = false; - } - - try { - $request = WebToPay::buildRequest(array( - 'projectid' => $this->config->get('paysera_project'), - 'sign_password' => $this->config->get('paysera_sign'), - - 'orderid' => $order['order_id'], - 'amount' => intval(number_format($order['total'] * $this->currency->getvalue($order['currency_code']), 2, '', '')), //ceil($order['total'] * $this->currency->getvalue($order['currency_code']) * 100) - 'currency' => $order['currency_code'], - 'lang' => $language, - - 'accepturl' => HTTPS_SERVER . 'index.php?route=payment/paysera/accept', - 'cancelurl' => HTTPS_SERVER . 'index.php?route=checkout/checkout', - 'callbackurl' => HTTPS_SERVER . 'index.php?route=payment/paysera/callback', - 'payment' => (isset($_REQUEST['payment'])) ? $_REQUEST['payment'] : '', - 'country' => $order['payment_iso_code_2'], - - 'logo' => '', - 'p_firstname' => $order['payment_firstname'], - 'p_lastname' => $order['payment_lastname'], - 'p_email' => $order['email'], - 'p_street' => $order['payment_address_1'] . ' ' . $order['payment_address_2'], - 'p_city' => $order['payment_city'], - 'p_state' => '', - 'p_zip' => $order['payment_postcode'], - 'p_countrycode' => $order['payment_iso_code_2'], - 'test' => ($this->config->get('paysera_test') != 0 ? 1 : 0), - )); - } catch (WebToPayException $e) { - exit($e->getMessage()); - } - - $this->load->model('checkout/order'); - $this->model_checkout_order->confirm($order['order_id'], 1); - - $this->data['request'] = $request; - $this->data['requestUrl'] = WebToPay::PAY_URL; - - $this->template = 'default/template/payment/paysera_redirect.tpl'; - $this->response->setOutput($this->render(TRUE)); - } - - public function getPaymentList() { - - $this->load->model('checkout/order'); - $order = $this->model_checkout_order->getOrder($this->session->data['order_id']); - $amount = ceil($order['total'] * $this->currency->getvalue($order['currency_code']) * 100); - - $language = $this->language->get('code'); - $projectId = $this->config->get('paysera_project'); - - $methods = WebToPay::getPaymentMethodList($projectId, $order['currency_code']) - ->filterForAmount($amount, $order['currency_code']) - ->setDefaultLanguage($language); - - return $methods->getCountries(); - } - - public function accept() { - if (isset($this->session->data['token'])) { - $this->redirect(HTTPS_SERVER . 'index.php?route=checkout/success&token=' . $this->session->data['token']); - } else { - $this->redirect(HTTPS_SERVER . 'index.php?route=checkout/success'); - } - } - - public function cancel() { - $this->language->load('payment/paysera'); - - $this->data['title'] = sprintf($this->language->get('heading_title'), $this->config->get('config_store')); - - if (@$this->request->server['HTTPS'] != 'on') { - $this->data['base'] = HTTP_SERVER; - } else { - $this->data['base'] = HTTPS_SERVER; - } - - $this->data['charset'] = $this->language->get('charset'); - $this->data['language'] = $this->language->get('code'); - $this->data['direction'] = $this->language->get('direction'); - - $this->data['heading_title'] = sprintf($this->language->get('heading_title'), $this->config->get('config_store')); - - $this->data['text_response'] = $this->language->get('text_response'); - $this->data['text_success'] = $this->language->get('text_success'); - $this->data['text_success_wait'] = sprintf($this->language->get('text_success_wait'), HTTPS_SERVER . 'index.php?route=checkout/success'); - $this->data['text_failure'] = $this->language->get('text_failure'); - $this->data['text_failure_wait'] = sprintf($this->language->get('text_failure_wait'), HTTPS_SERVER . 'index.php?route=checkout/payment'); - - $this->data['button_continue'] = $this->language->get('button_continue'); - - $this->data['continue'] = HTTPS_SERVER . 'index.php?route=checkout/payment'; - - $this->template = $this->config->get('config_template') . 'payment/paysera_failure.tpl'; - - $this->render(); - } - - public function callback() { - - $project_id = $this->config->get('paysera_project'); - $sign_password = $this->config->get('paysera_sign'); - $this->load->model('checkout/order'); - - try { - $response = WebToPay::validateAndParseData($_REQUEST, $project_id, $sign_password); - - if ($response['status'] == 1) { - $orderId = isset($response['orderid']) ? $response['orderid'] : null; - - $order = $this->model_checkout_order->getOrder($orderId); - - $amount = intval(number_format($order['total'] * $this->currency->getvalue($order['currency_code']), 2, '', '')); - - if (empty($order)) { - throw new Exception('Order with this ID not found'); - } - - if ($response['amount'] < $amount) { - throw new Exception('Bad amount: ' . $response['amount'] . ', expected: ' . ceil($order['total'] * 100)); - } - - if ($response['currency'] != $order['currency_code']) { - throw new Exception('Bad currency: ' . $response['currency'] . ', expected: ' . $order['currency_code']); - } - - - $message = ''; - $this->model_checkout_order->update($orderId, $this->config->get('paysera_order_status_id'), $message, FALSE); - - exit('OK'); - } - exit('OK'); - } catch (Exception $e) { - exit(get_class($e) . ': ' . $e->getMessage()); - } - } -} +url->link('payment/paysera/confirm', '', 'SSL'); + $data['button_confirm'] = $this->language->get('button_confirm'); + $data['button_back'] = $this->language->get('button_back'); + + $this->language->load('payment/paysera'); + $data['text_chosen'] = $this->language->get('text_chosen'); + $data['text_paycountry'] = $this->language->get('text_paycountry'); + + $data['default_country'] = $this->config->get('default_payment_country'); + $data['paysera_display_payments'] = $this->config->get('paysera_display_payments_list'); + + + if ($this->request->get['route'] != 'checkout/guest/confirm') { + $data['back'] = HTTPS_SERVER . 'index.php?route=checkout/payment'; + } else { + $data['back'] = HTTPS_SERVER . 'index.php?route=checkout/guest'; + } + $data['projectId'] = $this->config->get('paysera_project'); + $data['payment_country'] = $this->session->data['payment_address']['iso_code_2']; + $this->id = 'payment'; + + //countries + $this->load->model('checkout/order'); + $order = $this->model_checkout_order->getOrder($this->session->data['order_id']); + $amount = ceil($order['total'] * $this->currency->getvalue($order['currency_code']) * 100); + + $language = $this->language->get('code'); + $projectId = $this->config->get('paysera_project'); + + $methods = WebToPay::getPaymentMethodList($projectId, $order['currency_code']) + ->filterForAmount($amount, $order['currency_code']) + ->setDefaultLanguage($language); + $data['evp_countries'] = $methods->getCountries(); + //end countries + + + if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/paysera.tpl')) { + return $this->load->view($this->config->get('config_template') . '/template/payment/paysera.tpl', $data); + } else { + return $this->load->view('payment/paysera.tpl', $data); + } + + + } + + public function confirm() { + + error_reporting(E_ALL); + ini_set('display_errors', 1); + + $this->load->model('checkout/order'); + $order = $this->model_checkout_order->getOrder($this->session->data['order_id']); + $this->load->library('encryption'); + $language = $this->config->get('paysera_lang'); + + if (!isset($_SERVER['HTTPS'])) { + $_SERVER['HTTPS'] = false; + } + + $info = array( + 'projectid' => $this->config->get('paysera_project'), + 'sign_password' => $this->config->get('paysera_sign'), + + 'orderid' => $order['order_id'], + 'amount' => intval(number_format($order['total'] * $this->currency->getvalue($order['currency_code']), 2, '', '')), //ceil($order['total'] * $this->currency->getvalue($order['currency_code']) * 100) + 'currency' => $order['currency_code'], + 'lang' => $language, + + 'accepturl' => HTTPS_SERVER . 'index.php?route=payment/paysera/accept', + 'cancelurl' => HTTPS_SERVER . 'index.php?route=payment/paysera/cancel', + 'callbackurl' => HTTPS_SERVER . 'index.php?route=payment/paysera/callback', + 'payment' => (isset($_REQUEST['payment'])) ? $_REQUEST['payment'] : '', + 'country' => $order['payment_iso_code_2'], + + 'logo' => '', + 'p_firstname' => $order['payment_firstname'], + 'p_lastname' => $order['payment_lastname'], + 'p_email' => $order['email'], + 'p_street' => $order['payment_address_1'] . ' ' . $order['payment_address_2'], + 'p_city' => $order['payment_city'], + 'p_state' => '', + 'p_zip' => $order['payment_postcode'], + 'p_countrycode' => $order['payment_iso_code_2'], + 'test' => ($this->config->get('paysera_test') != 0 ? 1 : 0), + ); + + try { + $request = WebToPay::redirectToPayment($info); + } catch (WebToPayException $e) { + exit($e->getMessage()); + } + $this->load->model('checkout/order'); + //$this->model_checkout_order->confirm($order['order_id'], 1); + + + + + + $data['request'] = $request; + // $data['countries'] = $countries; + $data['requestUrl'] = WebToPay::PAY_URL; + + + if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/payment/paysera_redirect.tpl')) { + return $this->load->view($this->config->get('config_template') . '/template/payment/paysera_redirect.tpl', $data); + } else { + return $this->load->view('payment/paysera_redirect.tpl', $data); + } + + + + // print_r($request); + //$this->response->setOutput($this->render(TRUE)); + } + + private function getPaymentList() { + + $this->load->model('checkout/order'); + $order = $this->model_checkout_order->getOrder($this->session->data['order_id']); + $amount = ceil($order['total'] * $this->currency->getvalue($order['currency_code']) * 100); +print_r($order); + $language = $this->language->get('code'); + $projectId = $this->config->get('paysera_project'); +echo "| $projectId |"; + $methods = WebToPay::getPaymentMethodList($projectId, $order['currency_code']) + ->filterForAmount($amount, $order['currency_code']) + ->setDefaultLanguage($language); + + return $methods->getCountries(); } + + public function accept() { + if (isset($this->session->data['token'])) { + $this->response->redirect(HTTPS_SERVER . 'index.php?route=checkout/success&token=' . $this->session->data['token']); + } else { + $this->response->redirect(HTTPS_SERVER . 'index.php?route=checkout/success'); + } + } + + public function cancel() { + $this->language->load('payment/paysera'); + + $data['title'] = sprintf($this->language->get('heading_title'), $this->config->get('config_store')); + + if(isset($this->request->server['HTTPS']) and $this->request->server['HTTPS'] == 'on') { + $data['base'] = HTTPS_SERVER; + } else { + $data['base'] = HTTP_SERVER; + } + + $data['charset'] = $this->language->get('charset'); + $data['language'] = $this->language->get('code'); + $data['direction'] = $this->language->get('direction'); + + $data['heading_title'] = sprintf($this->language->get('heading_title'), $this->config->get('config_store')); + + $data['text_response'] = $this->language->get('text_response'); + $data['text_success'] = $this->language->get('text_success'); + $data['text_success_wait'] = sprintf($this->language->get('text_success_wait'), $this->data['base'] . 'index.php?route=checkout/success'); + $data['text_failure'] = $this->language->get('text_failure'); + $data['text_failure_wait'] = sprintf($this->language->get('text_failure_wait'), $this->data['base'] . 'index.php?route=checkout/cart'); + + $data['button_continue'] = $this->language->get('button_continue'); + + $data['continue'] = $data['base'] . 'index.php?route=checkout/cart'; + + $this->template = $this->config->get('config_template') . '/template/payment/paysera_failure.tpl'; + + $this->response->setOutput($this->load->view('payment/paysera_failure.tpl', $data)); + } + + public function callback() { + + $project_id = $this->config->get('paysera_project'); + $sign_password = $this->config->get('paysera_sign'); + $this->load->model('checkout/order'); + + try { + $response = WebToPay::validateAndParseData($_REQUEST, $project_id, $sign_password); + + if ($response['status'] == 1) { + $orderId = isset($response['orderid']) ? $response['orderid'] : null; + + $order = $this->model_checkout_order->getOrder($orderId); + + $amount = intval(number_format($order['total'] * $this->currency->getvalue($order['currency_code']), 2, '', '')); + + if (empty($order)) { + throw new Exception('Order with this ID not found'); + } + + if ($response['amount'] < $amount) { + throw new Exception('Bad amount: ' . $response['amount'] . ', expected: ' . ceil($order['total'] * 100)); + } + + if ($response['currency'] != $order['currency_code']) { + throw new Exception('Bad currency: ' . $response['currency'] . ', expected: ' . $order['currency_code']); + } + + + $message = ''; + + $this->model_checkout_order->addOrderHistory($orderId, $this->config->get('config_order_status_id')); + //$this->model_checkout_order->update($orderId, $this->config->get('paysera_order_status_id'), $message, FALSE); + + exit('OK'); + } + exit('OK'); + } catch (Exception $e) { + exit(get_class($e) . ': ' . $e->getMessage()); + } + } +} diff --git a/catalog/language/english/payment/paysera.php b/catalog/language/english/payment/paysera.php old mode 100644 new mode 100755 index 03c0ff3..65fb7b0 --- a/catalog/language/english/payment/paysera.php +++ b/catalog/language/english/payment/paysera.php @@ -1,7 +1,7 @@ Please wait...
If you are not automatically re-directed in 10 seconds, please click here.'; + // Entry $_['entry_project'] = 'Project ID:'; @@ -27,7 +31,7 @@ // Pay Method Select $_['text_paycountry'] = 'Select payment country'; -$_['text_chosen'] = 'You chose to pay via Paysera.com'; +$_['text_chosen'] = 'You chose to pay via Paysera'; // Error diff --git a/catalog/language/lithuanian/payment/paysera.php b/catalog/language/lithuanian/payment/paysera.php old mode 100644 new mode 100755 index 9fa31df..ed211aa --- a/catalog/language/lithuanian/payment/paysera.php +++ b/catalog/language/lithuanian/payment/paysera.php @@ -1,7 +1,7 @@ Prašau palaukti...
' + . 'Jeigu Jūs nebūsite nukreipti į kitą puslapį per 10 sekundžių, paspauskite čia.'; + // Entry $_['entry_project'] = 'Project ID:'; @@ -27,7 +32,7 @@ // Pay Method Select $_['text_paycountry'] = 'Mokėjimo šalis'; -$_['text_chosen'] = 'Pasirinkote atsiskaitymą per mokėjimai.lt sistemą'; +$_['text_chosen'] = 'Pasirinkote atsiskaitymą per Paysera sistemą'; // Error @@ -35,4 +40,3 @@ $_['error_project'] = 'Reikia nurodyti projeto ID!'; $_['error_sign'] = 'Reikia nurodyti projekto slaptažodį!'; $_['error_lang'] = 'Lang code Required!'; - diff --git a/catalog/model/payment/paysera.php b/catalog/model/payment/paysera.php old mode 100644 new mode 100755 index 0a123ca..16cfc17 --- a/catalog/model/payment/paysera.php +++ b/catalog/model/payment/paysera.php @@ -24,6 +24,7 @@ public function getMethod($address) { $method_data = array( 'code' => 'paysera', 'title' => $this->language->get('text_title'), + 'terms' => '', 'sort_order' => $this->config->get('paysera_sort_order') ); } diff --git a/catalog/view/theme/default/template/payment/paysera.tpl b/catalog/view/theme/default/template/payment/paysera.tpl old mode 100644 new mode 100755 index 9bcf501..3478359 --- a/catalog/view/theme/default/template/payment/paysera.tpl +++ b/catalog/view/theme/default/template/payment/paysera.tpl @@ -2,6 +2,8 @@ .w2p-table { width: 100%; + margin-top: 10px; + margin-left: 25px; } .w2p-table img { @@ -34,73 +36,96 @@ }); }); +
- - + - + + - + - + + + + + + +
- - Mokejimai - - +

- + + + getCode() == $country_iso){ ?> + + + + +
- -
- getPaymentList() as $country): ?> - - getGroups() as $group): ?> - - - - getPaymentMethods() as $paymentMethod): ?> - getLogoUrl()): ?> - - - - - - - -
getTitle(); ?>
- - - <?php echo $paymentMethod->getTitle(); ?> -
+ +
+ + + getGroups() as $group): ?> + + + + getPaymentMethods() as $paymentMethod): ?> + getLogoUrl()): ?> + + + + + + - +
getTitle(); ?>
+ + + <?php echo $paymentMethod->getTitle(); ?> +
+ +
- - - - -
- - - -
+
+ + +
+ + + + + +
diff --git a/catalog/view/theme/default/template/payment/paysera_failure.tpl b/catalog/view/theme/default/template/payment/paysera_failure.tpl old mode 100644 new mode 100755 diff --git a/catalog/view/theme/default/template/payment/paysera_redirect.tpl b/catalog/view/theme/default/template/payment/paysera_redirect.tpl old mode 100644 new mode 100755 diff --git a/catalog/view/theme/default/template/payment/paysera_success.tpl b/catalog/view/theme/default/template/payment/paysera_success.tpl old mode 100644 new mode 100755 diff --git a/system/library/vendor/autoload.php b/system/library/vendor/autoload.php deleted file mode 100644 index acbbd6b..0000000 --- a/system/library/vendor/autoload.php +++ /dev/null @@ -1,7 +0,0 @@ - - * Jordi Boggiano - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Composer\Autoload; - -/** - * ClassLoader implements a PSR-0 class loader - * - * See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md - * - * $loader = new \Composer\Autoload\ClassLoader(); - * - * // register classes with namespaces - * $loader->add('Symfony\Component', __DIR__.'/component'); - * $loader->add('Symfony', __DIR__.'/framework'); - * - * // activate the autoloader - * $loader->register(); - * - * // to enable searching the include path (eg. for PEAR packages) - * $loader->setUseIncludePath(true); - * - * In this example, if you try to use a class in the Symfony\Component - * namespace or one of its children (Symfony\Component\Console for instance), - * the autoloader will first look for the class under the component/ - * directory, and it will then fallback to the framework/ directory if not - * found before giving up. - * - * This class is loosely based on the Symfony UniversalClassLoader. - * - * @author Fabien Potencier - * @author Jordi Boggiano - */ -class ClassLoader -{ - private $prefixes = array(); - private $fallbackDirs = array(); - private $useIncludePath = false; - private $classMap = array(); - - public function getPrefixes() - { - return call_user_func_array('array_merge', $this->prefixes); - } - - public function getFallbackDirs() - { - return $this->fallbackDirs; - } - - public function getClassMap() - { - return $this->classMap; - } - - /** - * @param array $classMap Class to filename map - */ - public function addClassMap(array $classMap) - { - if ($this->classMap) { - $this->classMap = array_merge($this->classMap, $classMap); - } else { - $this->classMap = $classMap; - } - } - - /** - * Registers a set of classes, merging with any others previously set. - * - * @param string $prefix The classes prefix - * @param array|string $paths The location(s) of the classes - * @param bool $prepend Prepend the location(s) - */ - public function add($prefix, $paths, $prepend = false) - { - if (!$prefix) { - if ($prepend) { - $this->fallbackDirs = array_merge( - (array) $paths, - $this->fallbackDirs - ); - } else { - $this->fallbackDirs = array_merge( - $this->fallbackDirs, - (array) $paths - ); - } - - return; - } - - $first = $prefix[0]; - if (!isset($this->prefixes[$first][$prefix])) { - $this->prefixes[$first][$prefix] = (array) $paths; - - return; - } - if ($prepend) { - $this->prefixes[$first][$prefix] = array_merge( - (array) $paths, - $this->prefixes[$first][$prefix] - ); - } else { - $this->prefixes[$first][$prefix] = array_merge( - $this->prefixes[$first][$prefix], - (array) $paths - ); - } - } - - /** - * Registers a set of classes, replacing any others previously set. - * - * @param string $prefix The classes prefix - * @param array|string $paths The location(s) of the classes - */ - public function set($prefix, $paths) - { - if (!$prefix) { - $this->fallbackDirs = (array) $paths; - - return; - } - $this->prefixes[substr($prefix, 0, 1)][$prefix] = (array) $paths; - } - - /** - * Turns on searching the include path for class files. - * - * @param bool $useIncludePath - */ - public function setUseIncludePath($useIncludePath) - { - $this->useIncludePath = $useIncludePath; - } - - /** - * Can be used to check if the autoloader uses the include path to check - * for classes. - * - * @return bool - */ - public function getUseIncludePath() - { - return $this->useIncludePath; - } - - /** - * Registers this instance as an autoloader. - * - * @param bool $prepend Whether to prepend the autoloader or not - */ - public function register($prepend = false) - { - spl_autoload_register(array($this, 'loadClass'), true, $prepend); - } - - /** - * Unregisters this instance as an autoloader. - */ - public function unregister() - { - spl_autoload_unregister(array($this, 'loadClass')); - } - - /** - * Loads the given class or interface. - * - * @param string $class The name of the class - * @return bool|null True if loaded, null otherwise - */ - public function loadClass($class) - { - if ($file = $this->findFile($class)) { - include $file; - - return true; - } - } - - /** - * Finds the path to the file where the class is defined. - * - * @param string $class The name of the class - * - * @return string|false The path if found, false otherwise - */ - public function findFile($class) - { - // work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731 - if ('\\' == $class[0]) { - $class = substr($class, 1); - } - - if (isset($this->classMap[$class])) { - return $this->classMap[$class]; - } - - if (false !== $pos = strrpos($class, '\\')) { - // namespaced class name - $classPath = strtr(substr($class, 0, $pos), '\\', DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; - $className = substr($class, $pos + 1); - } else { - // PEAR-like class name - $classPath = null; - $className = $class; - } - - $classPath .= strtr($className, '_', DIRECTORY_SEPARATOR) . '.php'; - - $first = $class[0]; - if (isset($this->prefixes[$first])) { - foreach ($this->prefixes[$first] as $prefix => $dirs) { - if (0 === strpos($class, $prefix)) { - foreach ($dirs as $dir) { - if (file_exists($dir . DIRECTORY_SEPARATOR . $classPath)) { - return $dir . DIRECTORY_SEPARATOR . $classPath; - } - } - } - } - } - - foreach ($this->fallbackDirs as $dir) { - if (file_exists($dir . DIRECTORY_SEPARATOR . $classPath)) { - return $dir . DIRECTORY_SEPARATOR . $classPath; - } - } - - if ($this->useIncludePath && $file = stream_resolve_include_path($classPath)) { - return $file; - } - - return $this->classMap[$class] = false; - } -} diff --git a/system/library/vendor/composer/autoload_classmap.php b/system/library/vendor/composer/autoload_classmap.php deleted file mode 100644 index b46a4ea..0000000 --- a/system/library/vendor/composer/autoload_classmap.php +++ /dev/null @@ -1,28 +0,0 @@ - $vendorDir . '/webtopay/libwebtopay/src/WebToPay.php', - 'WebToPayException' => $vendorDir . '/webtopay/libwebtopay/src/WebToPayException.php', - 'WebToPay_CallbackValidator' => $vendorDir . '/webtopay/libwebtopay/src/WebToPay/CallbackValidator.php', - 'WebToPay_Exception_Callback' => $vendorDir . '/webtopay/libwebtopay/src/WebToPay/Exception/Callback.php', - 'WebToPay_Exception_Configuration' => $vendorDir . '/webtopay/libwebtopay/src/WebToPay/Exception/Configuration.php', - 'WebToPay_Exception_Validation' => $vendorDir . '/webtopay/libwebtopay/src/WebToPay/Exception/Validation.php', - 'WebToPay_Factory' => $vendorDir . '/webtopay/libwebtopay/src/WebToPay/Factory.php', - 'WebToPay_PaymentMethod' => $vendorDir . '/webtopay/libwebtopay/src/WebToPay/PaymentMethod.php', - 'WebToPay_PaymentMethodCountry' => $vendorDir . '/webtopay/libwebtopay/src/WebToPay/PaymentMethodCountry.php', - 'WebToPay_PaymentMethodGroup' => $vendorDir . '/webtopay/libwebtopay/src/WebToPay/PaymentMethodGroup.php', - 'WebToPay_PaymentMethodList' => $vendorDir . '/webtopay/libwebtopay/src/WebToPay/PaymentMethodList.php', - 'WebToPay_PaymentMethodListProvider' => $vendorDir . '/webtopay/libwebtopay/src/WebToPay/PaymentMethodListProvider.php', - 'WebToPay_RequestBuilder' => $vendorDir . '/webtopay/libwebtopay/src/WebToPay/RequestBuilder.php', - 'WebToPay_Sign_SS1SignChecker' => $vendorDir . '/webtopay/libwebtopay/src/WebToPay/Sign/SS1SignChecker.php', - 'WebToPay_Sign_SS2SignChecker' => $vendorDir . '/webtopay/libwebtopay/src/WebToPay/Sign/SS2SignChecker.php', - 'WebToPay_Sign_SignCheckerInterface' => $vendorDir . '/webtopay/libwebtopay/src/WebToPay/Sign/SignCheckerInterface.php', - 'WebToPay_SmsAnswerSender' => $vendorDir . '/webtopay/libwebtopay/src/WebToPay/SmsAnswerSender.php', - 'WebToPay_Util' => $vendorDir . '/webtopay/libwebtopay/src/WebToPay/Util.php', - 'WebToPay_WebClient' => $vendorDir . '/webtopay/libwebtopay/src/WebToPay/WebClient.php', -); diff --git a/system/library/vendor/composer/autoload_namespaces.php b/system/library/vendor/composer/autoload_namespaces.php deleted file mode 100644 index 7b9d516..0000000 --- a/system/library/vendor/composer/autoload_namespaces.php +++ /dev/null @@ -1,9 +0,0 @@ - $path) { - $loader->set($namespace, $path); - } - - $classMap = require __DIR__ . '/autoload_classmap.php'; - if ($classMap) { - $loader->addClassMap($classMap); - } - - $loader->register(true); - - return $loader; - } -} diff --git a/system/library/vendor/composer/installed.json b/system/library/vendor/composer/installed.json deleted file mode 100644 index 5d9a5cc..0000000 --- a/system/library/vendor/composer/installed.json +++ /dev/null @@ -1,37 +0,0 @@ -[ - { - "name": "webtopay/libwebtopay", - "version": "dev-default", - "version_normalized": "9999999-dev", - "source": { - "type": "hg", - "url": "https://bitbucket.org/webtopay/libwebtopay", - "reference": "tip" - }, - "dist": { - "type": "zip", - "url": "https://bitbucket.org/webtopay/libwebtopay/get/tip.zip", - "reference": "tip", - "shasum": "" - }, - "time": "2013-05-15 09:33:15", - "type": "library", - "installation-source": "source", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "LGPL-3.0" - ], - "authors": [ - { - "name": "EVP International", - "homepage": "http://www.webtopay.com/" - } - ], - "description": "PHP Library for WebToPay provided services" - } -] diff --git a/system/library/vendor/webtopay/libwebtopay/.hgignore b/system/library/vendor/webtopay/libwebtopay/.hgignore deleted file mode 100644 index dfd15be..0000000 --- a/system/library/vendor/webtopay/libwebtopay/.hgignore +++ /dev/null @@ -1,25 +0,0 @@ -syntax: regexp -^demo/var/(?!__empty__).* - -syntax: glob -*.swp - -# Stuff from text editors and IDE's -(^|/)tags$ -^\.cache$ -^\.settings$ -^\.project$ -syntax: regexp -^\.project$ -syntax: regexp -^\.hgignore$ -syntax: regexp -\.hgignore$ -syntax: regexp -^\.project$ -syntax: regexp -^demo_shop/var/data\.php$ -syntax: regexp -^\.buildpath$ -syntax: regexp -^\.settings$ \ No newline at end of file diff --git a/system/library/vendor/webtopay/libwebtopay/.hgtags b/system/library/vendor/webtopay/libwebtopay/.hgtags deleted file mode 100644 index e705d88..0000000 --- a/system/library/vendor/webtopay/libwebtopay/.hgtags +++ /dev/null @@ -1,9 +0,0 @@ -4c30c7337fbb643138ab92ada95053803a75525a 1.2.1 -7bd54ef0282ae192f708265d710588bfe512c579 1.2.2 -ba6bffed693f2a836aebd5bc5ba35fecf31f696d 1.2.3 -be45e46f64085c9c12beb9ad88c1bd4933db5bb0 1.2.4 -be45e46f64085c9c12beb9ad88c1bd4933db5bb0 1.2.4 -b914d3c0fe137afa0c6a405ff4084d1e3fdb24fe 1.2.4 -7777c1f942afc29808110183ee40ebcd0a63f365 1.3.0 -2656b3069d0d28427e7b675ab1587a8bae924b3c 1.2.5 -a9937e0358d3336896db1d6637f2455387e6a29d 1.2.5 diff --git a/system/library/vendor/webtopay/libwebtopay/COPYING b/system/library/vendor/webtopay/libwebtopay/COPYING deleted file mode 100644 index cca7fc2..0000000 --- a/system/library/vendor/webtopay/libwebtopay/COPYING +++ /dev/null @@ -1,165 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. diff --git a/system/library/vendor/webtopay/libwebtopay/README b/system/library/vendor/webtopay/libwebtopay/README deleted file mode 100644 index ae1140c..0000000 --- a/system/library/vendor/webtopay/libwebtopay/README +++ /dev/null @@ -1,151 +0,0 @@ -This is WebToPay library package. - -Requirements -============ - -You must have PHP version 5.0 or higher - - -Installing -========== - -Easiest way to use library is to include merged all-in-one file. -It is located in base libwebtopay directory, "WebToPay.php". -In this case you only need this one file. -Example: - - -Alternatively, you can use files in the "src" folder. -Either set-up autoloader or include file "includes.php" in "src" directory. -Example: - - -Testing -======= - - $ cd /path/to/libwebtopay - $ phpunit - - -Demo -=============== - -demo_shop is a simple example how you can integrate library to your project. -It also shows how to get payment methods available for your project and specific amount. - -Demo needs write permissions to folder /var to function properly. -If you want to test demo online, also change parameters in includes/config.php file to your project's. -If you are testing offline, demos will still work, but webtopay.com will be unable to send callback to your site - -you can login to your account and copy-and-paste the callback link in your browser in that case. - - -Version history -=============== - -Version 1.6 - 2012-04-12 - - * refactored WebToPay class to separate non-static classes - * changed request signing and callback processing - now using base64 encoding - * removed some public WebToPay methods - -Version 1.5 - 2012-02-08 - - * added API for getting available payment methods - * refactored old example and added another one - -Version 1.5 - 2011-10-13 - - * updated SS1 to SS1 v2 (SS1 obsolete and not available in 1.5) - * force to use SS2 if OpenSSL available - * added time_limit parameter - -Version 1.4 - 2011-07-01 - - * added WebToPay::getPaymentUrl() - -Version 1.4 - 2011-06-15 - - * WebToPay::getXML() fix - -Version 1.4 - 2011-05-30 - - * small refactoring - -Version 1.4 - 2011-05-26 - - * added methods which enables user to download payment method list - -Version 1.4 - 2011-03-28 - - * added 'RequestID' - -Version 1.3.2 - 2010-08-18 - - * country validation fix - -Version 1.3.1 - 2010-08-16 - - * projectid is required in checkResponse() in 1.3.1 version - -Version 1.3 - 2010-06-14 - - * 'sign' parameter now supports utf-8 - * WebToPay::buildRepeatRequest() added - * more unit-tests added - -Version 1.2.5 - 2010-06-14 - - * removed response checking by parameters specifications, now response is - checked only against SS1/SS2 security checks - - -Version 1.2.4 - 2010-05-20 - - * 0x14 error code added - * sign is required - -Version 1.2.3 - 2010-05-13 - - * OpenSSL verification fixes to work correctly with different OpenSSL versions - * PHP5 syntax fixes: non-static method changed to static as they should be - * demo fixes to handle correctly magic quotes - -Version 1.2.2 - 2010-05-11 - - * ignore third version number when comparing version numbers - * checks for openssl library version, use SS2 only with 0.9.8 and greather version of openssl - * demo response url fix - -Version 1.2.1 - 2010-05-10 - - * orderid, amount and currency are not required in checkResponse() - * orderid no longer is restricted to only digits, now characters ar accepted - * posibility to toggle SS2 checking - * improved unit testing - -Version 1.2 - 2010-04-14 - - * introduced library versioning - * mikro payments support - -Version 1.1 - 2010-04-14 - - * merchantid is deprecated, projectid should be used instead - * SS1 checking added - -Version 1.0 - 2010-01-21 - - * Initial release - diff --git a/system/library/vendor/webtopay/libwebtopay/WebToPay.php b/system/library/vendor/webtopay/libwebtopay/WebToPay.php old mode 100644 new mode 100755 index 4c6ae0b..13af3aa --- a/system/library/vendor/webtopay/libwebtopay/WebToPay.php +++ b/system/library/vendor/webtopay/libwebtopay/WebToPay.php @@ -40,17 +40,22 @@ class WebToPay { /** * Server URL where all requests should go. */ - const PAY_URL = 'https://www.mokejimai.lt/pay/'; + const PAY_URL = 'https://www.paysera.com/pay/'; + + /** + * Server URL where all non-lithuanian language requests should go. + */ + const PAYSERA_PAY_URL = 'https://www.paysera.com/pay/'; /** * Server URL where we can get XML with payment method data. */ - const XML_URL = 'https://www.mokejimai.lt/new/api/paymentMethods/'; + const XML_URL = 'https://www.paysera.com/new/api/paymentMethods/'; /** * SMS answer url. */ - const SMS_ANSWER_URL = 'https://www.mokejimai.lt/psms/respond/'; + const SMS_ANSWER_URL = 'https://www.paysera.com/psms/respond/'; /** * Builds request data array. @@ -59,7 +64,7 @@ class WebToPay { * array or raises WebToPayException on failure. * * Possible keys: - * https://www.mokejimai.lt/makro_specifikacija.html + * https://www.paysera.com/makro_specifikacija.html * * @param array $data Information about current payment request * @@ -86,7 +91,7 @@ public static function buildRequest($data) { * Builds request and redirects user to payment window with generated request data * * Possible array keys are described here: - * https://www.mokejimai.lt/makro_specifikacija.html + * https://www.paysera.com/makro_specifikacija.html * * @param array $data Information about current payment request. * @param boolean $exit if true, exits after sending Location header; default false @@ -94,9 +99,18 @@ public static function buildRequest($data) { * @throws WebToPayException on data validation error */ public static function redirectToPayment($data, $exit = false) { - $request = self::buildRequest($data); - $url = self::PAY_URL . '?' . http_build_query($request); - $url = preg_replace('/[\r\n]+/is', '', $url); + if (!isset($data['sign_password']) || !isset($data['projectid'])) { + throw new WebToPayException('sign_password or projectid is not provided'); + } + $password = $data['sign_password']; + $projectId = $data['projectid']; + unset($data['sign_password']); + unset($data['projectid']); + + $factory = new WebToPay_Factory(array('projectId' => $projectId, 'password' => $password)); + $url = $factory->getRequestBuilder() + ->buildRequestUrlFromData($data); + if (headers_sent()) { echo ''; } else { @@ -120,7 +134,7 @@ public static function redirectToPayment($data, $exit = false) { * * Method accepts single parameter $data of array type. All possible array * keys are described here: - * https://www.mokejimai.lt/makro_specifikacija.html + * https://www.paysera.com/makro_specifikacija.html * * @param array $data Information about current payment request * @@ -148,11 +162,9 @@ public static function buildRepeatRequest($data) { * @return string $url */ public static function getPaymentUrl($language = 'LIT') { - $url = self::PAY_URL; - if ($language != 'LIT') { - $url = str_replace('mokejimai.lt', 'webtopay.com', $url); - } - return $url; + return (in_array($language, array('lt', 'lit', 'LIT'))) + ? self::PAY_URL + : self::PAYSERA_PAY_URL; } /** @@ -163,8 +175,8 @@ public static function getPaymentUrl($language = 'LIT') { * First parameter usualy should be $_GET array. * * Description about response can be found here: - * makro: https://www.mokejimai.lt/makro_specifikacija.html - * mikro: https://www.mokejimai.lt/mikro_mokejimu_specifikacija_SMS.html + * makro: https://www.paysera.com/makro_specifikacija.html + * mikro: https://www.paysera.com/mikro_mokejimu_specifikacija_SMS.html * * If response is not correct, WebToPayException will be raised. * @@ -265,7 +277,7 @@ public static function smsAnswer($userData) { * * @throws WebToPayException */ - public static function getPaymentMethodList($projectId, $currency = 'LTL') { + public static function getPaymentMethodList($projectId, $currency = 'EUR') { $factory = new WebToPay_Factory(array('projectId' => $projectId)); return $factory->getPaymentMethodListProvider()->getPaymentMethodList($currency); } @@ -391,47 +403,153 @@ public function getField() { } /** - * Payment method configuration for some country + * Parses and validates callbacks */ -class WebToPay_PaymentMethodCountry { +class WebToPay_CallbackValidator { + /** - * @var string + * @var WebToPay_Sign_SignCheckerInterface */ - protected $countryCode; + protected $signer; /** - * Holds available payment types for this country + * @var WebToPay_Util + */ + protected $util; + + /** + * @var integer + */ + protected $projectId; + + /** + * Constructs object * - * @var WebToPay_PaymentMethodGroup[] + * @param integer $projectId + * @param WebToPay_Sign_SignCheckerInterface $signer + * @param WebToPay_Util $util */ - protected $groups; + public function __construct($projectId, WebToPay_Sign_SignCheckerInterface $signer, WebToPay_Util $util) { + $this->signer = $signer; + $this->util = $util; + $this->projectId = $projectId; + } /** - * Default language for titles + * Parses callback parameters from query parameters and checks if sign is correct. + * Request has parameter "data", which is signed and holds all callback parameters + * + * @param array $requestData + * + * @return array Parsed callback parameters + * + * @throws WebToPayException + * @throws WebToPay_Exception_Callback + */ + public function validateAndParseData(array $requestData) { + if (!$this->signer->checkSign($requestData)) { + throw new WebToPay_Exception_Callback('Invalid sign parameters, check $_GET length limit'); + } + + if (!isset($requestData['data'])) { + throw new WebToPay_Exception_Callback('"data" parameter not found'); + } + $data = $requestData['data']; + + $queryString = $this->util->decodeSafeUrlBase64($data); + $request = $this->util->parseHttpQuery($queryString); + + if (!isset($request['projectid'])) { + throw new WebToPay_Exception_Callback( + 'Project ID not provided in callback', + WebToPayException::E_INVALID + ); + } + + if ((string) $request['projectid'] !== (string) $this->projectId) { + throw new WebToPay_Exception_Callback( + sprintf('Bad projectid: %s, should be: %s', $request['projectid'], $this->projectId), + WebToPayException::E_INVALID + ); + } + + if (!isset($request['type']) || !in_array($request['type'], array('micro', 'macro'))) { + $micro = ( + isset($request['to']) + && isset($request['from']) + && isset($request['sms']) + ); + $request['type'] = $micro ? 'micro' : 'macro'; + } + + return $request; + } + + /** + * Checks data to have all the same parameters provided in expected array + * + * @param array $data + * @param array $expected + * + * @throws WebToPayException + */ + public function checkExpectedFields(array $data, array $expected) { + foreach ($expected as $key => $value) { + $passedValue = isset($data[$key]) ? $data[$key] : null; + if ($passedValue != $value) { + throw new WebToPayException( + sprintf('Field %s is not as expected (expected %s, got %s)', $key, $value, $passedValue) + ); + } + } + } +} + +/** + * Wrapper class to group payment methods. Each country can have several payment method groups, each of them + * have one or more payment methods. + */ +class WebToPay_PaymentMethodGroup { + /** + * Some unique (in the scope of country) key for this group * * @var string */ - protected $defaultLanguage; + protected $groupKey; /** - * Translations array for this country. Holds associative array of country title by language codes. + * Translations array for this group. Holds associative array of group title by country codes. * * @var array */ - protected $titleTranslations; + protected $translations; + + /** + * Holds actual payment methods + * + * @var WebToPay_PaymentMethod[] + */ + protected $paymentMethods; + + /** + * Default language for titles + * + * @var string + */ + protected $defaultLanguage; /** * Constructs object * - * @param string $countryCode - * @param array $titleTranslations + * @param string $groupKey + * @param array $translations * @param string $defaultLanguage */ - public function __construct($countryCode, $titleTranslations, $defaultLanguage = 'lt') { - $this->countryCode = $countryCode; + public function __construct($groupKey, array $translations = array(), $defaultLanguage = 'lt') { + $this->groupKey = $groupKey; + $this->translations = $translations; $this->defaultLanguage = $defaultLanguage; - $this->titleTranslations = $titleTranslations; - $this->groups = array(); + $this->paymentMethods = array(); } /** @@ -440,16 +558,25 @@ public function __construct($countryCode, $titleTranslations, $defaultLanguage = * * @param string $language * - * @return WebToPay_PaymentMethodCountry + * @return WebToPay_PaymentMethodGroup */ public function setDefaultLanguage($language) { $this->defaultLanguage = $language; - foreach ($this->groups as $group) { - $group->setDefaultLanguage($language); + foreach ($this->paymentMethods as $paymentMethod) { + $paymentMethod->setDefaultLanguage($language); } return $this; } + /** + * Gets default language for titles + * + * @return string + */ + public function getDefaultLanguage() { + return $this->defaultLanguage; + } + /** * Gets title of the group. Tries to get title in specified language. If it is not found or if language is not * specified, uses default language, given to constructor. @@ -459,96 +586,74 @@ public function setDefaultLanguage($language) { * @return string */ public function getTitle($languageCode = null) { - if ($languageCode !== null && isset($this->titleTranslations[$languageCode])) { - return $this->titleTranslations[$languageCode]; - } elseif (isset($this->titleTranslations[$this->defaultLanguage])) { - return $this->titleTranslations[$this->defaultLanguage]; + if ($languageCode !== null && isset($this->translations[$languageCode])) { + return $this->translations[$languageCode]; + } elseif (isset($this->translations[$this->defaultLanguage])) { + return $this->translations[$this->defaultLanguage]; } else { - return $this->countryCode; + return $this->groupKey; } } /** - * Gets default language for titles + * Returns group key * * @return string */ - public function getDefaultLanguage() { - return $this->defaultLanguage; + public function getKey() { + return $this->groupKey; } /** - * Gets country code + * Returns available payment methods for this group * - * @return string + * @return WebToPay_PaymentMethod[] */ - public function getCode() { - return $this->countryCode; + public function getPaymentMethods() { + return $this->paymentMethods; } - /** - * Adds new group to payment methods for this country. - * If some other group was registered earlier with same key, overwrites it. - * Returns given group - * - * @param WebToPay_PaymentMethodGroup $group - * - * @return WebToPay_PaymentMethodGroup - */ - public function addGroup(WebToPay_PaymentMethodGroup $group) { - return $this->groups[$group->getKey()] = $group; - } /** - * Gets group object with specified group key. If no group with such key is found, returns null. + * Adds new payment method for this group. + * If some other payment method with specified key was registered earlier, overwrites it. + * Returns given payment method * - * @param string $groupKey + * @param WebToPay_PaymentMethod $paymentMethod * - * @return null|WebToPay_PaymentMethodGroup + * @return WebToPay_PaymentMethod */ - public function getGroup($groupKey) { - return isset($this->groups[$groupKey]) ? $this->groups[$groupKey] : null; + public function addPaymentMethod(WebToPay_PaymentMethod $paymentMethod) { + return $this->paymentMethods[$paymentMethod->getKey()] = $paymentMethod; } /** - * Returns payment method groups registered for this country. + * Gets payment method object with key. If no payment method with such key is found, returns null. * - * @return WebToPay_PaymentMethodGroup[] - */ - public function getGroups() { - return $this->groups; - } - - /** - * Gets payment methods in all groups + * @param string $key * - * @return WebToPay_PaymentMethod[] + * @return null|WebToPay_PaymentMethod */ - public function getPaymentMethods() { - $paymentMethods = array(); - foreach ($this->groups as $group) { - $paymentMethods = array_merge($paymentMethods, $group->getPaymentMethods()); - } - return $paymentMethods; + public function getPaymentMethod($key) { + return isset($this->paymentMethods[$key]) ? $this->paymentMethods[$key] : null; } /** - * Returns new country instance with only those payment methods, which are available for provided amount. + * Returns new group instance with only those payment methods, which are available for provided amount. * * @param integer $amount * @param string $currency * - * @return WebToPay_PaymentMethodCountry + * @return WebToPay_PaymentMethodGroup */ public function filterForAmount($amount, $currency) { - $country = new WebToPay_PaymentMethodCountry($this->countryCode, $this->titleTranslations, $this->defaultLanguage); - foreach ($this->getGroups() as $group) { - $group = $group->filterForAmount($amount, $currency); - if (!$group->isEmpty()) { - $country->addGroup($group); + $group = new WebToPay_PaymentMethodGroup($this->groupKey, $this->translations, $this->defaultLanguage); + foreach ($this->getPaymentMethods() as $paymentMethod) { + if ($paymentMethod->isAvailableForAmount($amount, $currency)) { + $group->addPaymentMethod($paymentMethod); } } - return $country; + return $group; } /** @@ -556,251 +661,234 @@ public function filterForAmount($amount, $currency) { * * @param boolean $isIban * - * @return WebToPay_PaymentMethodCountry + * @return WebToPay_PaymentMethodGroup */ public function filterForIban($isIban = true) { - $country = new WebToPay_PaymentMethodCountry($this->countryCode, $this->titleTranslations, $this->defaultLanguage); - foreach ($this->getGroups() as $group) { - $group = $group->filterForIban($isIban); - if (!$group->isEmpty()) { - $country->addGroup($group); + $group = new WebToPay_PaymentMethodGroup($this->groupKey, $this->translations, $this->defaultLanguage); + foreach ($this->getPaymentMethods() as $paymentMethod) { + if ($paymentMethod->isIban() == $isIban) { + $group->addPaymentMethod($paymentMethod); } } - return $country; + return $group; } /** - * Returns whether this country has no groups + * Returns whether this group has no payment methods * * @return boolean */ public function isEmpty() { - return count($this->groups) === 0; + return count($this->paymentMethods) === 0; } /** - * Loads groups from given XML node + * Loads payment methods from given XML node * - * @param SimpleXMLElement $countryNode + * @param SimpleXMLElement $groupNode */ - public function fromXmlNode($countryNode) { - foreach ($countryNode->payment_group as $groupNode) { - $key = (string) $groupNode->attributes()->key; + public function fromXmlNode($groupNode) { + foreach ($groupNode->payment_type as $paymentTypeNode) { + $key = (string) $paymentTypeNode->attributes()->key; $titleTranslations = array(); - foreach ($groupNode->title as $titleNode) { + foreach ($paymentTypeNode->title as $titleNode) { $titleTranslations[(string) $titleNode->attributes()->language] = (string) $titleNode; } - $this->addGroup($this->createGroup($key, $titleTranslations))->fromXmlNode($groupNode); + $logoTranslations = array(); + foreach ($paymentTypeNode->logo_url as $logoNode) { + if ((string) $logoNode !== '') { + $logoTranslations[(string) $logoNode->attributes()->language] = (string) $logoNode; + } + } + $minAmount = null; + $maxAmount = null; + $currency = null; + $isIban = false; + $baseCurrency = null; + if (isset($paymentTypeNode->min)) { + $minAmount = (int) $paymentTypeNode->min->attributes()->amount; + $currency = (string) $paymentTypeNode->min->attributes()->currency; + } + if (isset($paymentTypeNode->max)) { + $maxAmount = (int) $paymentTypeNode->max->attributes()->amount; + $currency = (string) $paymentTypeNode->max->attributes()->currency; + } + + if (isset($paymentTypeNode->is_iban)) { + $isIban = (int) $paymentTypeNode->is_iban; + } + if (isset($paymentTypeNode->base_currency)) { + $baseCurrency = (string) $paymentTypeNode->base_currency; + } + $this->addPaymentMethod($this->createPaymentMethod( + $key, $minAmount, $maxAmount, $currency, $logoTranslations, $titleTranslations, $isIban, $baseCurrency + )); } } /** - * Method to create new group instances. Overwrite if you have to use some other group subtype. + * Method to create new payment method instances. Overwrite if you have to use some other subclass. * - * @param string $groupKey - * @param array $translations + * @param string $key + * @param integer $minAmount + * @param integer $maxAmount + * @param string $currency + * @param array $logoList + * @param array $titleTranslations + * @param bool $isIban + * @param null $baseCurrency * - * @return WebToPay_PaymentMethodGroup + * @return WebToPay_PaymentMethod */ - protected function createGroup($groupKey, array $translations = array()) { - return new WebToPay_PaymentMethodGroup($groupKey, $translations, $this->defaultLanguage); + protected function createPaymentMethod( + $key, $minAmount, $maxAmount, $currency, array $logoList = array(), array $titleTranslations = array(), + $isIban = false, $baseCurrency = null + ) { + return new WebToPay_PaymentMethod( + $key, $minAmount, $maxAmount, $currency, $logoList, $titleTranslations, $this->defaultLanguage, + $isIban, $baseCurrency + ); } } /** - * Builds and signs requests + * Loads data about payment methods and constructs payment method list object from that data + * You need SimpleXML support to use this feature */ -class WebToPay_RequestBuilder { +class WebToPay_PaymentMethodListProvider { /** - * @var string + * @var integer */ - protected $projectPassword; + protected $projectId; /** - * @var WebToPay_Util + * @var WebToPay_WebClient */ - protected $util; + protected $webClient; /** - * @var integer + * Holds constructed method lists by currency + * + * @var WebToPay_PaymentMethodList[] */ - protected $projectId; + protected $methodListCache = array(); /** - * Constructs object + * Builds various request URLs * - * @param integer $projectId - * @param string $projectPassword - * @param WebToPay_Util $util + * @var WebToPay_UrlBuilder $urlBuilder */ - public function __construct($projectId, $projectPassword, WebToPay_Util $util) { - $this->projectId = $projectId; - $this->projectPassword = $projectPassword; - $this->util = $util; - } + protected $urlBuilder; /** - * Builds request data array. - * - * This method checks all given data and generates correct request data - * array or raises WebToPayException on failure. - * - * @param array $data information about current payment request + * Constructs object * - * @return array + * @param integer $projectId + * @param WebToPay_WebClient $webClient + * @param WebToPay_UrlBuilder $urlBuilder * - * @throws WebToPayException + * @throws WebToPayException if SimpleXML is not available */ - public function buildRequest($data) { - $this->validateRequest($data, self::getRequestSpec()); - $data['version'] = WebToPay::VERSION; - $data['projectid'] = $this->projectId; - unset($data['repeat_request']); - return $this->createRequest($data); + public function __construct( + $projectId, + WebToPay_WebClient $webClient, + WebToPay_UrlBuilder $urlBuilder + ) + { + $this->projectId = $projectId; + $this->webClient = $webClient; + $this->urlBuilder = $urlBuilder; + + if (!function_exists('simplexml_load_string')) { + throw new WebToPayException('You have to install libxml to use payment methods API'); + } } /** - * Builds repeat request data array. - * - * This method checks all given data and generates correct request data - * array or raises WebToPayException on failure. + * Gets payment method list for specified currency * - * @param string $orderId order id of repeated request + * @param string $currency * - * @return array + * @return WebToPay_PaymentMethodList * * @throws WebToPayException */ - public function buildRepeatRequest($orderId) { - $data['orderid'] = $orderId; - $data['version'] = WebToPay::VERSION; - $data['projectid'] = $this->projectId; - $data['repeat_request'] = '1'; - return $this->createRequest($data); + public function getPaymentMethodList($currency) { + if (!isset($this->methodListCache[$currency])) { + $xmlAsString = $this->webClient->get($this->urlBuilder->buildForPaymentsMethodList($this->projectId, $currency)); + $useInternalErrors = libxml_use_internal_errors(false); + $rootNode = simplexml_load_string($xmlAsString); + libxml_clear_errors(); + libxml_use_internal_errors($useInternalErrors); + if (!$rootNode) { + throw new WebToPayException('Unable to load XML from remote server'); + } + $methodList = new WebToPay_PaymentMethodList($this->projectId, $currency); + $methodList->fromXmlNode($rootNode); + $this->methodListCache[$currency] = $methodList; + } + return $this->methodListCache[$currency]; } +} - /** - * Checks data to be valid by passed specification - * - * @param array $data - * @param array $specs - * - * @throws WebToPay_Exception_Validation - */ - protected function validateRequest($data, $specs) { - foreach ($specs as $spec) { - list($name, $maxlen, $required, $regexp) = $spec; - if ($required && !isset($data[$name])) { - throw new WebToPay_Exception_Validation( - sprintf("'%s' is required but missing.", $name), - WebToPayException::E_MISSING, - $name - ); - } +/** + * Raised on error in callback + */ +class WebToPay_Exception_Callback extends WebToPayException { - if (!empty($data[$name])) { - if ($maxlen && strlen($data[$name]) > $maxlen) { - throw new WebToPay_Exception_Validation(sprintf( - "'%s' value is too long (%d), %d characters allowed.", - $name, - strlen($data[$name]), - $maxlen - ), WebToPayException::E_MAXLEN, $name); - } +} - if ($regexp !== '' && !preg_match($regexp, $data[$name])) { - throw new WebToPay_Exception_Validation( - sprintf("'%s' value '%s' is invalid.", $name, $data[$name]), - WebToPayException::E_REGEXP, - $name - ); - } - } +/** + * Raised if configuration is incorrect + */ +class WebToPay_Exception_Configuration extends WebToPayException { + +} + + +/** + * Raised on validation error in passed data when building the request + */ +class WebToPay_Exception_Validation extends WebToPayException { + + public function __construct($message, $code = 0, $field = null, Exception $previousException = null) { + parent::__construct($message, $code, $previousException); + if ($field) { + $this->setField($field); } } +} +/** + * Class to hold information about payment method + */ +class WebToPay_PaymentMethod { /** - * Makes request data array from parameters, also generates signature + * Assigned key for this payment method * - * @param array $request + * @var string + */ + protected $key; + + /** + * Logo url list by language. Usually logo is same for all languages, but exceptions exist * - * @return array + * @var array */ - protected function createRequest(array $request) { - $data = $this->util->encodeSafeUrlBase64(http_build_query($request)); - return array( - 'data' => $data, - 'sign' => md5($data . $this->projectPassword), - ); - } + protected $logoList; /** - * Returns specification of fields for request. + * Title list by language * - * Array structure: - * name – request item name - * maxlen – max allowed value for item - * required – is this item is required - * regexp – regexp to test item value + * @var array + */ + protected $titleTranslations; + + /** + * Default language to use for titles * - * @return array - */ - protected static function getRequestSpec() { - return array( - array('orderid', 40, true, ''), - array('accepturl', 255, true, ''), - array('cancelurl', 255, true, ''), - array('callbackurl', 255, true, ''), - array('lang', 3, false, '/^[a-z]{3}$/i'), - array('amount', 11, false, '/^\d+$/'), - array('currency', 3, false, '/^[a-z]{3}$/i'), - array('payment', 20, false, ''), - array('country', 2, false, '/^[a-z_]{2}$/i'), - array('paytext', 255, false, ''), - array('p_firstname', 255, false, ''), - array('p_lastname', 255, false, ''), - array('p_email', 255, false, ''), - array('p_street', 255, false, ''), - array('p_city', 255, false, ''), - array('p_state', 20, false, ''), - array('p_zip', 20, false, ''), - array('p_countrycode', 2, false, '/^[a-z]{2}$/i'), - array('test', 1, false, '/^[01]$/'), - array('time_limit', 19, false, '/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/'), - ); - } -} - -/** - * Class to hold information about payment method - */ -class WebToPay_PaymentMethod { - /** - * Assigned key for this payment method - * - * @var string - */ - protected $key; - - /** - * Logo url list by language. Usually logo is same for all languages, but exceptions exist - * - * @var array - */ - protected $logoList; - - /** - * Title list by language - * - * @var array - */ - protected $titleTranslations; - - /** - * Default language to use for titles - * - * @var string + * @var string */ protected $defaultLanguage; @@ -990,109 +1078,6 @@ public function getBaseCurrency() } -/** - * Parses and validates callbacks - */ -class WebToPay_CallbackValidator { - - /** - * @var WebToPay_Sign_SignCheckerInterface - */ - protected $signer; - - /** - * @var WebToPay_Util - */ - protected $util; - - /** - * @var integer - */ - protected $projectId; - - /** - * Constructs object - * - * @param integer $projectId - * @param WebToPay_Sign_SignCheckerInterface $signer - * @param WebToPay_Util $util - */ - public function __construct($projectId, WebToPay_Sign_SignCheckerInterface $signer, WebToPay_Util $util) { - $this->signer = $signer; - $this->util = $util; - $this->projectId = $projectId; - } - - /** - * Parses callback parameters from query parameters and checks if sign is correct. - * Request has parameter "data", which is signed and holds all callback parameters - * - * @param array $requestData - * - * @return array Parsed callback parameters - * - * @throws WebToPayException - * @throws WebToPay_Exception_Callback - */ - public function validateAndParseData(array $requestData) { - if (!$this->signer->checkSign($requestData)) { - throw new WebToPay_Exception_Callback('Invalid sign parameters, check $_GET length limit'); - } - - if (!isset($requestData['data'])) { - throw new WebToPay_Exception_Callback('"data" parameter not found'); - } - $data = $requestData['data']; - - $queryString = $this->util->decodeSafeUrlBase64($data); - $request = $this->util->parseHttpQuery($queryString); - - if (!isset($request['projectid'])) { - throw new WebToPay_Exception_Callback( - 'Project ID not provided in callback', - WebToPayException::E_INVALID - ); - } - - if ((string) $request['projectid'] !== (string) $this->projectId) { - throw new WebToPay_Exception_Callback( - sprintf('Bad projectid: %s, should be: %s', $request['projectid'], $this->projectId), - WebToPayException::E_INVALID - ); - } - - if (!isset($request['type']) || !in_array($request['type'], array('micro', 'macro'))) { - $micro = ( - isset($request['to']) - && isset($request['from']) - && isset($request['sms']) - ); - $request['type'] = $micro ? 'micro' : 'macro'; - } - - return $request; - } - - /** - * Checks data to have all the same parameters provided in expected array - * - * @param array $data - * @param array $expected - * - * @throws WebToPayException - */ - public function checkExpectedFields(array $data, array $expected) { - foreach ($expected as $key => $value) { - $passedValue = isset($data[$key]) ? $data[$key] : null; - if ($passedValue != $value) { - throw new WebToPayException( - sprintf('Field %s is not as expected (expected %s, got %s)', $key, $value, $passedValue) - ); - } - } - } -} - /** * Utility class */ @@ -1159,50 +1144,58 @@ protected function stripSlashesRecursively($data) { } /** - * Wrapper class to group payment methods. Each country can have several payment method groups, each of them - * have one or more payment methods. + * Class with all information about available payment methods for some project, optionally filtered by some amount. */ -class WebToPay_PaymentMethodGroup { +class WebToPay_PaymentMethodList { /** - * Some unique (in the scope of country) key for this group + * Holds available payment countries * - * @var string + * @var WebToPay_PaymentMethodCountry[] */ - protected $groupKey; + protected $countries; /** - * Translations array for this group. Holds associative array of group title by country codes. + * Default language for titles * - * @var array + * @var string */ - protected $translations; + protected $defaultLanguage; /** - * Holds actual payment methods + * Project ID, to which this method list is valid * - * @var WebToPay_PaymentMethod[] + * @var integer */ - protected $paymentMethods; + protected $projectId; /** - * Default language for titles + * Currency for min and max amounts in this list * * @var string */ - protected $defaultLanguage; + protected $currency; + + /** + * If this list is filtered for some amount, this field defines it + * + * @var integer + */ + protected $amount; /** * Constructs object * - * @param string $groupKey - * @param array $translations - * @param string $defaultLanguage + * @param integer $projectId + * @param string $currency currency for min and max amounts in this list + * @param string $defaultLanguage + * @param integer $amount null if this list is not filtered by amount */ - public function __construct($groupKey, array $translations = array(), $defaultLanguage = 'lt') { - $this->groupKey = $groupKey; - $this->translations = $translations; + public function __construct($projectId, $currency, $defaultLanguage = 'lt', $amount = null) { + $this->projectId = $projectId; + $this->countries = array(); $this->defaultLanguage = $defaultLanguage; - $this->paymentMethods = array(); + $this->currency = $currency; + $this->amount = $amount; } /** @@ -1211,12 +1204,12 @@ public function __construct($groupKey, array $translations = array(), $defaultLa * * @param string $language * - * @return WebToPay_PaymentMethodGroup + * @return WebToPay_PaymentMethodList */ public function setDefaultLanguage($language) { $this->defaultLanguage = $language; - foreach ($this->paymentMethods as $paymentMethod) { - $paymentMethod->setDefaultLanguage($language); + foreach ($this->countries as $country) { + $country->setDefaultLanguage($language); } return $this; } @@ -1231,189 +1224,138 @@ public function getDefaultLanguage() { } /** - * Gets title of the group. Tries to get title in specified language. If it is not found or if language is not - * specified, uses default language, given to constructor. - * - * @param string [Optional] $languageCode + * Gets project ID for this payment method list * - * @return string + * @return integer */ - public function getTitle($languageCode = null) { - if ($languageCode !== null && isset($this->translations[$languageCode])) { - return $this->translations[$languageCode]; - } elseif (isset($this->translations[$this->defaultLanguage])) { - return $this->translations[$this->defaultLanguage]; - } else { - return $this->groupKey; - } + public function getProjectId() { + return $this->projectId; } /** - * Returns group key + * Gets currency for min and max amounts in this list * * @return string */ - public function getKey() { - return $this->groupKey; + public function getCurrency() { + return $this->currency; } /** - * Returns available payment methods for this group + * Gets whether this list is already filtered for some amount * - * @return WebToPay_PaymentMethod[] + * @return boolean */ - public function getPaymentMethods() { - return $this->paymentMethods; + public function isFiltered() { + return $this->amount !== null; } - /** - * Adds new payment method for this group. - * If some other payment method with specified key was registered earlier, overwrites it. - * Returns given payment method - * - * @param WebToPay_PaymentMethod $paymentMethod + * Returns available countries * - * @return WebToPay_PaymentMethod + * @return WebToPay_PaymentMethodCountry[] */ - public function addPaymentMethod(WebToPay_PaymentMethod $paymentMethod) { - return $this->paymentMethods[$paymentMethod->getKey()] = $paymentMethod; + public function getCountries() { + return $this->countries; } /** - * Gets payment method object with key. If no payment method with such key is found, returns null. + * Adds new country to payment methods. If some other country with same code was registered earlier, overwrites it. + * Returns added country instance * - * @param string $key + * @param WebToPay_PaymentMethodCountry $country * - * @return null|WebToPay_PaymentMethod + * @return WebToPay_PaymentMethodCountry */ - public function getPaymentMethod($key) { - return isset($this->paymentMethods[$key]) ? $this->paymentMethods[$key] : null; + public function addCountry(WebToPay_PaymentMethodCountry $country) { + return $this->countries[$country->getCode()] = $country; } /** - * Returns new group instance with only those payment methods, which are available for provided amount. + * Gets country object with specified country code. If no country with such country code is found, returns null. * - * @param integer $amount - * @param string $currency + * @param string $countryCode * - * @return WebToPay_PaymentMethodGroup + * @return null|WebToPay_PaymentMethodCountry */ - public function filterForAmount($amount, $currency) { - $group = new WebToPay_PaymentMethodGroup($this->groupKey, $this->translations, $this->defaultLanguage); - foreach ($this->getPaymentMethods() as $paymentMethod) { - if ($paymentMethod->isAvailableForAmount($amount, $currency)) { - $group->addPaymentMethod($paymentMethod); - } - } - return $group; + public function getCountry($countryCode) { + return isset($this->countries[$countryCode]) ? $this->countries[$countryCode] : null; } /** - * Returns new country instance with only those payment methods, which are returns or not iban number after payment + * Returns new payment method list instance with only those payment methods, which are available for provided + * amount. + * Returns itself, if list is already filtered and filter amount matches the given one. * - * @param boolean $isIban + * @param integer $amount + * @param string $currency * - * @return WebToPay_PaymentMethodGroup + * @return WebToPay_PaymentMethodList + * + * @throws WebToPayException if this list is already filtered and not for provided amount */ - public function filterForIban($isIban = true) { - $group = new WebToPay_PaymentMethodGroup($this->groupKey, $this->translations, $this->defaultLanguage); - foreach ($this->getPaymentMethods() as $paymentMethod) { - if ($paymentMethod->isIban() == $isIban) { - $group->addPaymentMethod($paymentMethod); + public function filterForAmount($amount, $currency) { + if ($currency !== $this->currency) { + throw new WebToPayException( + 'Currencies do not match. Given currency: ' . $currency . ', currency in list: ' . $this->currency + ); + } + if ($this->isFiltered()) { + if ($this->amount === $amount) { + return $this; + } else { + throw new WebToPayException('This list is already filtered, use unfiltered list instead'); + } + } else { + $list = new WebToPay_PaymentMethodList($this->projectId, $currency, $this->defaultLanguage, $amount); + foreach ($this->getCountries() as $country) { + $country = $country->filterForAmount($amount, $currency); + if (!$country->isEmpty()) { + $list->addCountry($country); + } } + return $list; } - return $group; - } - - /** - * Returns whether this group has no payment methods - * - * @return boolean - */ - public function isEmpty() { - return count($this->paymentMethods) === 0; } /** - * Loads payment methods from given XML node + * Loads countries from given XML node * - * @param SimpleXMLElement $groupNode + * @param SimpleXMLElement $xmlNode */ - public function fromXmlNode($groupNode) { - foreach ($groupNode->payment_type as $paymentTypeNode) { - $key = (string) $paymentTypeNode->attributes()->key; + public function fromXmlNode($xmlNode) { + foreach ($xmlNode->country as $countryNode) { $titleTranslations = array(); - foreach ($paymentTypeNode->title as $titleNode) { + foreach ($countryNode->title as $titleNode) { $titleTranslations[(string) $titleNode->attributes()->language] = (string) $titleNode; } - $logoTranslations = array(); - foreach ($paymentTypeNode->logo_url as $logoNode) { - if ((string) $logoNode !== '') { - $logoTranslations[(string) $logoNode->attributes()->language] = (string) $logoNode; - } - } - $minAmount = null; - $maxAmount = null; - $currency = null; - $isIban = false; - $baseCurrency = null; - if (isset($paymentTypeNode->min)) { - $minAmount = (int) $paymentTypeNode->min->attributes()->amount; - $currency = (string) $paymentTypeNode->min->attributes()->currency; - } - if (isset($paymentTypeNode->max)) { - $maxAmount = (int) $paymentTypeNode->max->attributes()->amount; - $currency = (string) $paymentTypeNode->max->attributes()->currency; - } - - if (isset($paymentTypeNode->is_iban)) { - $isIban = (int) $paymentTypeNode->is_iban; - } - if (isset($paymentTypeNode->base_currency)) { - $baseCurrency = (string) $paymentTypeNode->base_currency; - } - $this->addPaymentMethod($this->createPaymentMethod( - $key, $minAmount, $maxAmount, $currency, $logoTranslations, $titleTranslations, $isIban, $baseCurrency - )); + $this->addCountry($this->createCountry((string) $countryNode->attributes()->code, $titleTranslations)) + ->fromXmlNode($countryNode); } } /** - * Method to create new payment method instances. Overwrite if you have to use some other subclass. + * Method to create new country instances. Overwrite if you have to use some other country subtype. * - * @param string $key - * @param integer $minAmount - * @param integer $maxAmount - * @param string $currency - * @param array $logoList - * @param array $titleTranslations - * @param bool $isIban - * @param null $baseCurrency + * @param string $countryCode + * @param array $titleTranslations * - * @return WebToPay_PaymentMethod + * @return WebToPay_PaymentMethodCountry */ - protected function createPaymentMethod( - $key, $minAmount, $maxAmount, $currency, array $logoList = array(), array $titleTranslations = array(), - $isIban = false, $baseCurrency = null - ) { - return new WebToPay_PaymentMethod( - $key, $minAmount, $maxAmount, $currency, $logoList, $titleTranslations, $this->defaultLanguage, - $isIban, $baseCurrency - ); + protected function createCountry($countryCode, array $titleTranslations = array()) { + return new WebToPay_PaymentMethodCountry($countryCode, $titleTranslations, $this->defaultLanguage); } } /** - * Loads data about payment methods and constructs payment method list object from that data - * You need SimpleXML support to use this feature + * Sends answer to SMS payment if it was not provided with response to callback */ -class WebToPay_PaymentMethodListProvider { +class WebToPay_SmsAnswerSender { /** - * @var integer + * @var string */ - protected $projectId; + protected $password; /** * @var WebToPay_WebClient @@ -1421,330 +1363,359 @@ class WebToPay_PaymentMethodListProvider { protected $webClient; /** - * Holds constructed method lists by currency - * - * @var WebToPay_PaymentMethodList[] + * @var WebToPay_UrlBuilder $urlBuilder */ - protected $methodListCache = array(); + protected $urlBuilder; /** * Constructs object * - * @param integer $projectId + * @param string $password * @param WebToPay_WebClient $webClient - * - * @throws WebToPayException if SimpleXML is not available + * @param WebToPay_UrlBuilder $urlBuilder */ - public function __construct($projectId, WebToPay_WebClient $webClient) { - $this->projectId = $projectId; + public function __construct( + $password, + WebToPay_WebClient $webClient, + WebToPay_UrlBuilder $urlBuilder + ) { + $this->password = $password; $this->webClient = $webClient; - if (!function_exists('simplexml_load_string')) { - throw new WebToPayException('You have to install libxml to use payment methods API'); - } + $this->urlBuilder = $urlBuilder; } /** - * Gets payment method list for specified currency - * - * @param string $currency + * Sends answer by sms ID get from callback. Answer can be send only if it was not provided + * when responding to callback * - * @return WebToPay_PaymentMethodList + * @param integer $smsId + * @param string $text * * @throws WebToPayException */ - public function getPaymentMethodList($currency) { - if (!isset($this->methodListCache[$currency])) { - $xmlAsString = $this->webClient->get(WebToPay::XML_URL . $this->projectId . '/currency:' . $currency); - $useInternalErrors = libxml_use_internal_errors(false); - $rootNode = simplexml_load_string($xmlAsString); - libxml_clear_errors(); - libxml_use_internal_errors($useInternalErrors); - if (!$rootNode) { - throw new WebToPayException('Unable to load XML from remote server'); - } - $methodList = new WebToPay_PaymentMethodList($this->projectId, $currency); - $methodList->fromXmlNode($rootNode); - $this->methodListCache[$currency] = $methodList; + public function sendAnswer($smsId, $text) { + $content = $this->webClient->get($this->urlBuilder->buildForSmsAnswer(), array( + 'id' => $smsId, + 'msg' => $text, + 'transaction' => md5($this->password . '|' . $smsId), + )); + if (strpos($content, 'OK') !== 0) { + throw new WebToPayException( + sprintf('Error: %s', $content), + WebToPayException::E_SMS_ANSWER + ); } - return $this->methodListCache[$currency]; } } + /** - * Class with all information about available payment methods for some project, optionally filtered by some amount. + * Creates objects. Also caches to avoid creating several instances of same objects */ -class WebToPay_PaymentMethodList { +class WebToPay_Factory { + + const ENV_PRODUCTION = 'production'; + const ENV_SANDBOX = 'sandbox'; + /** - * Holds available payment countries - * - * @var WebToPay_PaymentMethodCountry[] + * @var array */ - protected $countries; + protected static $defaultConfiguration = array( + 'routes' => array( + self::ENV_PRODUCTION => array( + 'publicKey' => 'http://www.paysera.com/download/public.key', + 'payment' => 'https://www.paysera.com/pay/', + 'paymentMethodList' => 'https://www.paysera.com/new/api/paymentMethods/', + 'smsAnswer' => 'https://www.paysera.com/psms/respond/', + ), + self::ENV_SANDBOX => array( + 'publicKey' => 'http://sandbox.paysera.com/download/public.key', + 'payment' => 'https://sandbox.paysera.com/pay/', + 'paymentMethodList' => 'https://sandbox.paysera.com/new/api/paymentMethods/', + 'smsAnswer' => 'https://sandbox.paysera.com/psms/respond/', + ), + ) + ); /** - * Default language for titles - * * @var string */ - protected $defaultLanguage; + protected $environment; /** - * Project ID, to which this method list is valid - * - * @var integer + * @var array */ - protected $projectId; + protected $configuration; /** - * Currency for min and max amounts in this list - * - * @var string + * @var WebToPay_WebClient */ - protected $currency; + protected $webClient = null; /** - * If this list is filtered for some amount, this field defines it - * - * @var integer + * @var WebToPay_CallbackValidator */ - protected $amount; + protected $callbackValidator = null; /** - * Constructs object - * - * @param integer $projectId - * @param string $currency currency for min and max amounts in this list - * @param string $defaultLanguage - * @param integer $amount null if this list is not filtered by amount + * @var WebToPay_RequestBuilder */ - public function __construct($projectId, $currency, $defaultLanguage = 'lt', $amount = null) { - $this->projectId = $projectId; - $this->countries = array(); - $this->defaultLanguage = $defaultLanguage; - $this->currency = $currency; - $this->amount = $amount; - } + protected $requestBuilder = null; /** - * Sets default language for titles. - * Returns itself for fluent interface - * - * @param string $language - * - * @return WebToPay_PaymentMethodList + * @var WebToPay_Sign_SignCheckerInterface */ - public function setDefaultLanguage($language) { - $this->defaultLanguage = $language; - foreach ($this->countries as $country) { - $country->setDefaultLanguage($language); - } - return $this; - } + protected $signer = null; /** - * Gets default language for titles + * @var WebToPay_SmsAnswerSender + */ + protected $smsAnswerSender = null; + + /** + * @var WebToPay_PaymentMethodListProvider + */ + protected $paymentMethodListProvider = null; + + /** + * @var WebToPay_Util + */ + protected $util = null; + + /** + * @var WebToPay_UrlBuilder + */ + protected $urlBuilder = null; + + + /** + * Constructs object. + * Configuration keys: projectId, password + * They are required only when some object being created needs them, + * if they are not found at that moment - exception is thrown * - * @return string + * @param array $configuration */ - public function getDefaultLanguage() { - return $this->defaultLanguage; + public function __construct(array $configuration = array()) { + + $this->configuration = array_merge(self::$defaultConfiguration, $configuration); + $this->environment = self::ENV_PRODUCTION; } /** - * Gets project ID for this payment method list + * If passed true the factory will use sandbox when constructing URLs * - * @return integer + * @param $enableSandbox + * @return self */ - public function getProjectId() { - return $this->projectId; + public function useSandbox($enableSandbox) + { + if ($enableSandbox) { + $this->environment = self::ENV_SANDBOX; + } else { + $this->environment = self::ENV_PRODUCTION; + } + return $this; } /** - * Gets currency for min and max amounts in this list + * Creates or gets callback validator instance * - * @return string + * @return WebToPay_CallbackValidator + * + * @throws WebToPay_Exception_Configuration */ - public function getCurrency() { - return $this->currency; + public function getCallbackValidator() { + if ($this->callbackValidator === null) { + if (!isset($this->configuration['projectId'])) { + throw new WebToPay_Exception_Configuration('You have to provide project ID'); + } + $this->callbackValidator = new WebToPay_CallbackValidator( + $this->configuration['projectId'], + $this->getSigner(), + $this->getUtil() + ); + } + return $this->callbackValidator; } /** - * Gets whether this list is already filtered for some amount + * Creates or gets request builder instance * - * @return boolean + * @throws WebToPay_Exception_Configuration + * + * @return WebToPay_RequestBuilder */ - public function isFiltered() { - return $this->amount !== null; + public function getRequestBuilder() { + if ($this->requestBuilder === null) { + if (!isset($this->configuration['password'])) { + throw new WebToPay_Exception_Configuration('You have to provide project password to sign request'); + } + if (!isset($this->configuration['projectId'])) { + throw new WebToPay_Exception_Configuration('You have to provide project ID'); + } + $this->requestBuilder = new WebToPay_RequestBuilder( + $this->configuration['projectId'], + $this->configuration['password'], + $this->getUtil(), + $this->getUrlBuilder() + ); + } + return $this->requestBuilder; } /** - * Returns available countries - * - * @return WebToPay_PaymentMethodCountry[] + * @return WebToPay_UrlBuilder */ - public function getCountries() { - return $this->countries; + public function getUrlBuilder() { + if ($this->urlBuilder === null) { + $this->urlBuilder = new WebToPay_UrlBuilder( + $this->configuration, + $this->environment + ); + } + return $this->urlBuilder; } /** - * Adds new country to payment methods. If some other country with same code was registered earlier, overwrites it. - * Returns added country instance + * Creates or gets SMS answer sender instance * - * @param WebToPay_PaymentMethodCountry $country + * @throws WebToPay_Exception_Configuration * - * @return WebToPay_PaymentMethodCountry + * @return WebToPay_SmsAnswerSender */ - public function addCountry(WebToPay_PaymentMethodCountry $country) { - return $this->countries[$country->getCode()] = $country; + public function getSmsAnswerSender() { + if ($this->smsAnswerSender === null) { + if (!isset($this->configuration['password'])) { + throw new WebToPay_Exception_Configuration('You have to provide project password'); + } + $this->smsAnswerSender = new WebToPay_SmsAnswerSender( + $this->configuration['password'], + $this->getWebClient(), + $this->getUrlBuilder() + ); + } + return $this->smsAnswerSender; } /** - * Gets country object with specified country code. If no country with such country code is found, returns null. + * Creates or gets payment list provider instance * - * @param string $countryCode + * @throws WebToPay_Exception_Configuration * - * @return null|WebToPay_PaymentMethodCountry + * @return WebToPay_PaymentMethodListProvider */ - public function getCountry($countryCode) { - return isset($this->countries[$countryCode]) ? $this->countries[$countryCode] : null; + public function getPaymentMethodListProvider() { + if ($this->paymentMethodListProvider === null) { + if (!isset($this->configuration['projectId'])) { + throw new WebToPay_Exception_Configuration('You have to provide project ID'); + } + $this->paymentMethodListProvider = new WebToPay_PaymentMethodListProvider( + $this->configuration['projectId'], + $this->getWebClient(), + $this->getUrlBuilder() + + ); + } + return $this->paymentMethodListProvider; } /** - * Returns new payment method list instance with only those payment methods, which are available for provided - * amount. - * Returns itself, if list is already filtered and filter amount matches the given one. + * Creates or gets signer instance. Chooses SS2 signer if openssl functions are available, SS1 in other case * - * @param integer $amount - * @param string $currency + * @throws WebToPay_Exception_Configuration * - * @return WebToPay_PaymentMethodList + * @return WebToPay_Sign_SignCheckerInterface * - * @throws WebToPayException if this list is already filtered and not for provided amount + * @throws WebToPayException */ - public function filterForAmount($amount, $currency) { - if ($currency !== $this->currency) { - throw new WebToPayException( - 'Currencies do not match. Given currency: ' . $currency . ', currency in list: ' . $this->currency - ); - } - if ($this->isFiltered()) { - if ($this->amount === $amount) { - return $this; + protected function getSigner() { + if ($this->signer === null) { + if (function_exists('openssl_pkey_get_public')) { + $webClient = $this->getWebClient(); + $publicKey = $webClient->get($this->getUrlBuilder()->buildForPublicKey()); + if (!$publicKey) { + throw new WebToPayException('Cannot download public key from WebToPay website'); + } + $this->signer = new WebToPay_Sign_SS2SignChecker($publicKey, $this->getUtil()); } else { - throw new WebToPayException('This list is already filtered, use unfiltered list instead'); - } - } else { - $list = new WebToPay_PaymentMethodList($this->projectId, $currency, $this->defaultLanguage, $amount); - foreach ($this->getCountries() as $country) { - $country = $country->filterForAmount($amount, $currency); - if (!$country->isEmpty()) { - $list->addCountry($country); + if (!isset($this->configuration['password'])) { + throw new WebToPay_Exception_Configuration( + 'You have to provide project password if OpenSSL is unavailable' + ); } + $this->signer = new WebToPay_Sign_SS1SignChecker($this->configuration['password']); } - return $list; } + return $this->signer; } /** - * Loads countries from given XML node + * Creates or gets web client instance * - * @param SimpleXMLElement $xmlNode + * @throws WebToPay_Exception_Configuration + * + * @return WebToPay_WebClient */ - public function fromXmlNode($xmlNode) { - foreach ($xmlNode->country as $countryNode) { - $titleTranslations = array(); - foreach ($countryNode->title as $titleNode) { - $titleTranslations[(string) $titleNode->attributes()->language] = (string) $titleNode; - } - $this->addCountry($this->createCountry((string) $countryNode->attributes()->code, $titleTranslations)) - ->fromXmlNode($countryNode); + protected function getWebClient() { + if ($this->webClient === null) { + $this->webClient = new WebToPay_WebClient(); } + return $this->webClient; } /** - * Method to create new country instances. Overwrite if you have to use some other country subtype. + * Creates or gets util instance * - * @param string $countryCode - * @param array $titleTranslations + * @throws WebToPay_Exception_Configuration * - * @return WebToPay_PaymentMethodCountry + * @return WebToPay_Util */ - protected function createCountry($countryCode, array $titleTranslations = array()) { - return new WebToPay_PaymentMethodCountry($countryCode, $titleTranslations, $this->defaultLanguage); + protected function getUtil() { + if ($this->util === null) { + $this->util = new WebToPay_Util(); + } + return $this->util; } } + /** - * Simple web client + * Sign checker which checks SS1 signature. SS1 does not depend on SSL functions */ -class WebToPay_WebClient { +class WebToPay_Sign_SS1SignChecker implements WebToPay_Sign_SignCheckerInterface { /** - * Gets page contents by specified URI. Adds query data if provided to the URI - * Ignores status code of the response and header fields + * @var string + */ + protected $projectPassword; + + /** + * Constructs object * - * @param string $uri - * @param array $queryData + * @param string $projectPassword + */ + public function __construct($projectPassword) { + $this->projectPassword = $projectPassword; + } + + /** + * Check for SS1, which is not depend on openssl functions. * - * @return string + * @param array $request * - * @throws WebToPayException + * @return boolean + * + * @throws WebToPay_Exception_Callback */ - public function get($uri, array $queryData = array()) { - if (count($queryData) > 0) { - $uri .= strpos($uri, '?') === false ? '?' : '&'; - $uri .= http_build_query($queryData); - } - $url = parse_url($uri); - if ('https' == $url['scheme']) { - $host = 'ssl://'.$url['host']; - $port = 443; - } else { - $host = $url['host']; - $port = 80; + public function checkSign(array $request) { + if (!isset($request['data']) || !isset($request['ss1'])) { + throw new WebToPay_Exception_Callback('Not enough parameters in callback. Possible version mismatch'); } - $fp = fsockopen($host, $port, $errno, $errstr, 30); - if (!$fp) { - throw new WebToPayException(sprintf('Cannot connect to %s', $uri), WebToPayException::E_INVALID); - } - - if(isset($url['query'])) { - $data = $url['path'].'?'.$url['query']; - } else { - $data = $url['path']; - } - - $out = "GET " . $data . " HTTP/1.0\r\n"; - $out .= "Host: ".$url['host']."\r\n"; - $out .= "Connection: Close\r\n\r\n"; - - $content = ''; - - fwrite($fp, $out); - while (!feof($fp)) $content .= fgets($fp, 8192); - fclose($fp); - - list($header, $content) = explode("\r\n\r\n", $content, 2); - - return trim($content); - } -} - -/** - * Interface for sign checker - */ -interface WebToPay_Sign_SignCheckerInterface { - - /** - * Checks whether request is signed properly - * - * @param array $request - * - * @return boolean - */ - public function checkSign(array $request); -} + return md5($request['data'] . $this->projectPassword) === $request['ss1']; + } +} /** * Checks SS2 signature. Depends on SSL functions @@ -1793,318 +1764,594 @@ public function checkSign(array $request) { } /** - * Sign checker which checks SS1 signature. SS1 does not depend on SSL functions + * Interface for sign checker */ -class WebToPay_Sign_SS1SignChecker implements WebToPay_Sign_SignCheckerInterface { +interface WebToPay_Sign_SignCheckerInterface { + + /** + * Checks whether request is signed properly + * + * @param array $request + * + * @return boolean + */ + public function checkSign(array $request); +} + +/** + * Simple web client + */ +class WebToPay_WebClient { + + /** + * Gets page contents by specified URI. Adds query data if provided to the URI + * Ignores status code of the response and header fields + * + * @param string $uri + * @param array $queryData + * + * @return string + * + * @throws WebToPayException + */ + public function get($uri, array $queryData = array()) { + if (count($queryData) > 0) { + $uri .= strpos($uri, '?') === false ? '?' : '&'; + $uri .= http_build_query($queryData); + } + $url = parse_url($uri); + if ('https' == $url['scheme']) { + $host = 'ssl://'.$url['host']; + $port = 443; + } else { + $host = $url['host']; + $port = 80; + } + + $fp = fsockopen($host, $port, $errno, $errstr, 30); + if (!$fp) { + throw new WebToPayException(sprintf('Cannot connect to %s', $uri), WebToPayException::E_INVALID); + } + + if(isset($url['query'])) { + $data = $url['path'].'?'.$url['query']; + } else { + $data = $url['path']; + } + + $out = "GET " . $data . " HTTP/1.0\r\n"; + $out .= "Host: ".$url['host']."\r\n"; + $out .= "Connection: Close\r\n\r\n"; + + $content = ''; + + fwrite($fp, $out); + while (!feof($fp)) $content .= fgets($fp, 8192); + fclose($fp); + list($header, $content) = explode("\r\n\r\n", $content, 2); + + return trim($content); + } +} + +/** + * Payment method configuration for some country + */ +class WebToPay_PaymentMethodCountry { /** * @var string */ - protected $projectPassword; + protected $countryCode; + + /** + * Holds available payment types for this country + * + * @var WebToPay_PaymentMethodGroup[] + */ + protected $groups; + + /** + * Default language for titles + * + * @var string + */ + protected $defaultLanguage; + + /** + * Translations array for this country. Holds associative array of country title by language codes. + * + * @var array + */ + protected $titleTranslations; /** * Constructs object * - * @param string $projectPassword + * @param string $countryCode + * @param array $titleTranslations + * @param string $defaultLanguage */ - public function __construct($projectPassword) { - $this->projectPassword = $projectPassword; + public function __construct($countryCode, $titleTranslations, $defaultLanguage = 'lt') { + $this->countryCode = $countryCode; + $this->defaultLanguage = $defaultLanguage; + $this->titleTranslations = $titleTranslations; + $this->groups = array(); } /** - * Check for SS1, which is not depend on openssl functions. + * Sets default language for titles. + * Returns itself for fluent interface * - * @param array $request + * @param string $language * - * @return boolean + * @return WebToPay_PaymentMethodCountry + */ + public function setDefaultLanguage($language) { + $this->defaultLanguage = $language; + foreach ($this->groups as $group) { + $group->setDefaultLanguage($language); + } + return $this; + } + + /** + * Gets title of the group. Tries to get title in specified language. If it is not found or if language is not + * specified, uses default language, given to constructor. * - * @throws WebToPay_Exception_Callback + * @param string [Optional] $languageCode + * + * @return string */ - public function checkSign(array $request) { - if (!isset($request['data']) || !isset($request['ss1'])) { - throw new WebToPay_Exception_Callback('Not enough parameters in callback. Possible version mismatch'); + public function getTitle($languageCode = null) { + if ($languageCode !== null && isset($this->titleTranslations[$languageCode])) { + return $this->titleTranslations[$languageCode]; + } elseif (isset($this->titleTranslations[$this->defaultLanguage])) { + return $this->titleTranslations[$this->defaultLanguage]; + } else { + return $this->countryCode; } + } - return md5($request['data'] . $this->projectPassword) === $request['ss1']; + /** + * Gets default language for titles + * + * @return string + */ + public function getDefaultLanguage() { + return $this->defaultLanguage; } -} -/** - * Sends answer to SMS payment if it was not provided with response to callback - */ -class WebToPay_SmsAnswerSender { + /** + * Gets country code + * + * @return string + */ + public function getCode() { + return $this->countryCode; + } /** - * @var string + * Adds new group to payment methods for this country. + * If some other group was registered earlier with same key, overwrites it. + * Returns given group + * + * @param WebToPay_PaymentMethodGroup $group + * + * @return WebToPay_PaymentMethodGroup */ - protected $password; + public function addGroup(WebToPay_PaymentMethodGroup $group) { + return $this->groups[$group->getKey()] = $group; + } /** - * @var WebToPay_WebClient + * Gets group object with specified group key. If no group with such key is found, returns null. + * + * @param string $groupKey + * + * @return null|WebToPay_PaymentMethodGroup */ - protected $webClient; + public function getGroup($groupKey) { + return isset($this->groups[$groupKey]) ? $this->groups[$groupKey] : null; + } /** - * Constructs object + * Returns payment method groups registered for this country. * - * @param string $password - * @param WebToPay_WebClient $webClient + * @return WebToPay_PaymentMethodGroup[] */ - public function __construct($password, WebToPay_WebClient $webClient) { - $this->password = $password; - $this->webClient = $webClient; + public function getGroups() { + return $this->groups; } /** - * Sends answer by sms ID get from callback. Answer can be send only if it was not provided - * when responding to callback + * Gets payment methods in all groups * - * @param integer $smsId - * @param string $text + * @return WebToPay_PaymentMethod[] + */ + public function getPaymentMethods() { + $paymentMethods = array(); + foreach ($this->groups as $group) { + $paymentMethods = array_merge($paymentMethods, $group->getPaymentMethods()); + } + return $paymentMethods; + } + + /** + * Returns new country instance with only those payment methods, which are available for provided amount. * - * @throws WebToPayException + * @param integer $amount + * @param string $currency + * + * @return WebToPay_PaymentMethodCountry */ - public function sendAnswer($smsId, $text) { - $content = $this->webClient->get(WebToPay::SMS_ANSWER_URL, array( - 'id' => $smsId, - 'msg' => $text, - 'transaction' => md5($this->password . '|' . $smsId), - )); - if (strpos($content, 'OK') !== 0) { - throw new WebToPayException( - sprintf('Error: %s', $content), - WebToPayException::E_SMS_ANSWER - ); + public function filterForAmount($amount, $currency) { + $country = new WebToPay_PaymentMethodCountry($this->countryCode, $this->titleTranslations, $this->defaultLanguage); + foreach ($this->getGroups() as $group) { + $group = $group->filterForAmount($amount, $currency); + if (!$group->isEmpty()) { + $country->addGroup($group); + } } + return $country; } -} + /** + * Returns new country instance with only those payment methods, which are returns or not iban number after payment + * + * @param boolean $isIban + * + * @return WebToPay_PaymentMethodCountry + */ + public function filterForIban($isIban = true) { + $country = new WebToPay_PaymentMethodCountry($this->countryCode, $this->titleTranslations, $this->defaultLanguage); + foreach ($this->getGroups() as $group) { + $group = $group->filterForIban($isIban); + if (!$group->isEmpty()) { + $country->addGroup($group); + } + } + return $country; + } -/** - * Raised on validation error in passed data when building the request - */ -class WebToPay_Exception_Validation extends WebToPayException { + /** + * Returns whether this country has no groups + * + * @return boolean + */ + public function isEmpty() { + return count($this->groups) === 0; + } - public function __construct($message, $code = 0, $field = null, Exception $previousException = null) { - parent::__construct($message, $code, $previousException); - if ($field) { - $this->setField($field); + /** + * Loads groups from given XML node + * + * @param SimpleXMLElement $countryNode + */ + public function fromXmlNode($countryNode) { + foreach ($countryNode->payment_group as $groupNode) { + $key = (string) $groupNode->attributes()->key; + $titleTranslations = array(); + foreach ($groupNode->title as $titleNode) { + $titleTranslations[(string) $titleNode->attributes()->language] = (string) $titleNode; + } + $this->addGroup($this->createGroup($key, $titleTranslations))->fromXmlNode($groupNode); } } + + /** + * Method to create new group instances. Overwrite if you have to use some other group subtype. + * + * @param string $groupKey + * @param array $translations + * + * @return WebToPay_PaymentMethodGroup + */ + protected function createGroup($groupKey, array $translations = array()) { + return new WebToPay_PaymentMethodGroup($groupKey, $translations, $this->defaultLanguage); + } } + /** - * Raised on error in callback + * Used to build a complete request URL. + * + * Class WebToPay_UrlBuilder */ -class WebToPay_Exception_Callback extends WebToPayException { +class WebToPay_UrlBuilder { -} + const PLACEHOLDER_KEY = '[domain]'; -/** - * Raised if configuration is incorrect - */ -class WebToPay_Exception_Configuration extends WebToPayException { + /** + * @var array + */ + protected $configuration = array(); -} + /** + * @var string + */ + protected $environment; + /** + * @var array + */ + protected $environmentSettings; -/** - * Creates objects. Also caches to avoid creating several instances of same objects - */ -class WebToPay_Factory { + /** + * @param array $configuration + * @param string $environment + */ + function __construct($configuration, $environment) + { + $this->configuration = $configuration; + $this->environment = $environment; + $this->environmentSettings = $this->configuration['routes'][$this->environment]; + } + + /** + * Builds a complete request URL based on the provided parameters + * + * @param $request + * @param null $language + * @return string + */ + public function buildForRequest($request, $language = null) { + return $this->createUrlFromRequestAndLanguage($request); + } + + /** + * Builds a complete URL for payment list API + * + * @param int $projectId + * @param string $currency + * @return string + */ + public function buildForPaymentsMethodList($projectId, $currency) { + $route = $this->environmentSettings['paymentMethodList']; + return $route . $projectId . '/currency:' . $currency; + } /** - * @var array + * Builds a complete URL for Sms Answer + * + * @return string */ - protected $configuration; + public function buildForSmsAnswer() { + $route = $this->environmentSettings['smsAnswer']; + return $route; + } /** - * @var WebToPay_WebClient + * Build the url to the public key + * + * @return string */ - protected $webClient = null; + public function buildForPublicKey() { + $route = $this->environmentSettings['publicKey']; + return $route; + } /** - * @var WebToPay_CallbackValidator + * Creates an URL from the request and data provided. + * + * @param array $request + * @return string */ - protected $callbackValidator = null; + protected function createUrlFromRequestAndLanguage($request) { + $url = $this->getPaymentUrl() . '?' . http_build_query($request); + return preg_replace('/[\r\n]+/is', '', $url); + } /** - * @var WebToPay_RequestBuilder + * Returns payment url. Argument is same as lang parameter in request data + * + * @return string $url */ - protected $requestBuilder = null; + protected function getPaymentUrl() { + $route = $this->environmentSettings['payment']; + return $route; + } +} + + +/** + * Builds and signs requests + */ +class WebToPay_RequestBuilder { /** - * @var WebToPay_Sign_SignCheckerInterface + * @var string */ - protected $signer = null; + protected $projectPassword; /** - * @var WebToPay_SmsAnswerSender + * @var WebToPay_Util */ - protected $smsAnswerSender = null; + protected $util; /** - * @var WebToPay_PaymentMethodListProvider + * @var integer */ - protected $paymentMethodListProvider = null; + protected $projectId; + /** - * @var WebToPay_Util + * @var WebToPay_UrlBuilder $urlBuilder */ - protected $util = null; + protected $urlBuilder; /** - * Constructs object. - * Configuration keys: projectId, password - * They are required only when some object being created needs them, - * if they are not found at that moment - exception is thrown + * Constructs object * - * @param array $configuration + * @param integer $projectId + * @param string $projectPassword + * @param WebToPay_Util $util + * @param WebToPay_UrlBuilder $urlBuilder */ - public function __construct(array $configuration = array()) { - $this->configuration = $configuration; + public function __construct( + $projectId, + $projectPassword, + WebToPay_Util $util, + WebToPay_UrlBuilder $urlBuilder + ) + { + $this->projectId = $projectId; + $this->projectPassword = $projectPassword; + $this->util = $util; + $this->urlBuilder = $urlBuilder; } /** - * Creates or gets callback validator instance + * Builds request data array. * - * @return WebToPay_CallbackValidator + * This method checks all given data and generates correct request data + * array or raises WebToPayException on failure. * - * @throws WebToPay_Exception_Configuration + * @param array $data information about current payment request + * + * @return array + * + * @throws WebToPayException */ - public function getCallbackValidator() { - if ($this->callbackValidator === null) { - if (!isset($this->configuration['projectId'])) { - throw new WebToPay_Exception_Configuration('You have to provide project ID'); - } - $this->callbackValidator = new WebToPay_CallbackValidator( - $this->configuration['projectId'], - $this->getSigner(), - $this->getUtil() - ); - } - return $this->callbackValidator; + public function buildRequest($data) { + $this->validateRequest($data, self::getRequestSpec()); + $data['version'] = WebToPay::VERSION; + $data['projectid'] = $this->projectId; + unset($data['repeat_request']); + return $this->createRequest($data); } /** - * Creates or gets request builder instance - * - * @throws WebToPay_Exception_Configuration + * Builds the full request url (including the protocol and the domain) * - * @return WebToPay_RequestBuilder + * @param array $data + * @return string */ - public function getRequestBuilder() { - if ($this->requestBuilder === null) { - if (!isset($this->configuration['password'])) { - throw new WebToPay_Exception_Configuration('You have to provide project password to sign request'); - } - if (!isset($this->configuration['projectId'])) { - throw new WebToPay_Exception_Configuration('You have to provide project ID'); - } - $this->requestBuilder = new WebToPay_RequestBuilder( - $this->configuration['projectId'], - $this->configuration['password'], - $this->getUtil() - ); - } - return $this->requestBuilder; + public function buildRequestUrlFromData($data) { + $language = isset($data['lang']) ? $data['lang'] : null; + $request = $this->buildRequest($data); + return $this->urlBuilder->buildForRequest($request, $language); } /** - * Creates or gets SMS answer sender instance + * Builds repeat request data array. * - * @throws WebToPay_Exception_Configuration + * This method checks all given data and generates correct request data + * array or raises WebToPayException on failure. * - * @return WebToPay_SmsAnswerSender + * @param string $orderId order id of repeated request + * + * @return array + * + * @throws WebToPayException */ - public function getSmsAnswerSender() { - if ($this->smsAnswerSender === null) { - if (!isset($this->configuration['password'])) { - throw new WebToPay_Exception_Configuration('You have to provide project password'); - } - $this->smsAnswerSender = new WebToPay_SmsAnswerSender( - $this->configuration['password'], - $this->getWebClient() - ); - } - return $this->smsAnswerSender; + public function buildRepeatRequest($orderId) { + $data['orderid'] = $orderId; + $data['version'] = WebToPay::VERSION; + $data['projectid'] = $this->projectId; + $data['repeat_request'] = '1'; + return $this->createRequest($data); } /** - * Creates or gets payment list provider instance - * - * @throws WebToPay_Exception_Configuration + * Builds the full request url for a repeated request (including the protocol and the domain) * - * @return WebToPay_PaymentMethodListProvider + * @param string $orderId order id of repeated request + * @return string */ - public function getPaymentMethodListProvider() { - if ($this->paymentMethodListProvider === null) { - if (!isset($this->configuration['projectId'])) { - throw new WebToPay_Exception_Configuration('You have to provide project ID'); - } - $this->paymentMethodListProvider = new WebToPay_PaymentMethodListProvider( - $this->configuration['projectId'], - $this->getWebClient() - ); - } - return $this->paymentMethodListProvider; + public function buildRepeatRequestUrlFromOrderId($orderId) { + $request = $this->buildRepeatRequest($orderId); + return $this->urlBuilder->buildForRequest($request); } /** - * Creates or gets signer instance. Chooses SS2 signer if openssl functions are available, SS1 in other case - * - * @throws WebToPay_Exception_Configuration + * Checks data to be valid by passed specification * - * @return WebToPay_Sign_SignCheckerInterface + * @param array $data + * @param array $specs * - * @throws WebToPayException + * @throws WebToPay_Exception_Validation */ - protected function getSigner() { - if ($this->signer === null) { - if (function_exists('openssl_pkey_get_public')) { - $webClient = $this->getWebClient(); - $publicKey = $webClient->get('http://downloads.webtopay.com/download/public.key'); - if (!$publicKey) { - throw new WebToPayException('Cannot download public key from WebToPay website'); + protected function validateRequest($data, $specs) { + foreach ($specs as $spec) { + list($name, $maxlen, $required, $regexp) = $spec; + if ($required && !isset($data[$name])) { + throw new WebToPay_Exception_Validation( + sprintf("'%s' is required but missing.", $name), + WebToPayException::E_MISSING, + $name + ); + } + + if (!empty($data[$name])) { + if ($maxlen && strlen($data[$name]) > $maxlen) { + throw new WebToPay_Exception_Validation(sprintf( + "'%s' value is too long (%d), %d characters allowed.", + $name, + strlen($data[$name]), + $maxlen + ), WebToPayException::E_MAXLEN, $name); } - $this->signer = new WebToPay_Sign_SS2SignChecker($publicKey, $this->getUtil()); - } else { - if (!isset($this->configuration['password'])) { - throw new WebToPay_Exception_Configuration( - 'You have to provide project password if OpenSSL is unavailable' + + if ($regexp !== '' && !preg_match($regexp, $data[$name])) { + throw new WebToPay_Exception_Validation( + sprintf("'%s' value '%s' is invalid.", $name, $data[$name]), + WebToPayException::E_REGEXP, + $name ); } - $this->signer = new WebToPay_Sign_SS1SignChecker($this->configuration['password']); } } - return $this->signer; } /** - * Creates or gets web client instance + * Makes request data array from parameters, also generates signature * - * @throws WebToPay_Exception_Configuration + * @param array $request * - * @return WebToPay_WebClient + * @return array */ - protected function getWebClient() { - if ($this->webClient === null) { - $this->webClient = new WebToPay_WebClient(); - } - return $this->webClient; + protected function createRequest(array $request) { + $data = $this->util->encodeSafeUrlBase64(http_build_query($request)); + return array( + 'data' => $data, + 'sign' => md5($data . $this->projectPassword), + ); } /** - * Creates or gets util instance + * Returns specification of fields for request. * - * @throws WebToPay_Exception_Configuration + * Array structure: + * name – request item name + * maxlen – max allowed value for item + * required – is this item is required + * regexp – regexp to test item value * - * @return WebToPay_Util + * @return array */ - protected function getUtil() { - if ($this->util === null) { - $this->util = new WebToPay_Util(); - } - return $this->util; + protected static function getRequestSpec() { + return array( + array('orderid', 40, true, ''), + array('accepturl', 255, true, ''), + array('cancelurl', 255, true, ''), + array('callbackurl', 255, true, ''), + array('lang', 3, false, '/^[a-z]{3}$/i'), + array('amount', 11, false, '/^\d+$/'), + array('currency', 3, false, '/^[a-z]{3}$/i'), + array('payment', 20, false, ''), + array('country', 2, false, '/^[a-z_]{2}$/i'), + array('paytext', 255, false, ''), + array('p_firstname', 255, false, ''), + array('p_lastname', 255, false, ''), + array('p_email', 255, false, ''), + array('p_street', 255, false, ''), + array('p_city', 255, false, ''), + array('p_state', 20, false, ''), + array('p_zip', 20, false, ''), + array('p_countrycode', 2, false, '/^[a-z]{2}$/i'), + array('test', 1, false, '/^[01]$/'), + array('time_limit', 19, false, '/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/'), + ); } } diff --git a/system/library/vendor/webtopay/libwebtopay/build.sh b/system/library/vendor/webtopay/libwebtopay/build.sh deleted file mode 100644 index e9c410a..0000000 --- a/system/library/vendor/webtopay/libwebtopay/build.sh +++ /dev/null @@ -1,2 +0,0 @@ -cd build -php phing-2.4.12.phar diff --git a/system/library/vendor/webtopay/libwebtopay/build/build.xml b/system/library/vendor/webtopay/libwebtopay/build/build.xml deleted file mode 100644 index d0e19e9..0000000 --- a/system/library/vendor/webtopay/libwebtopay/build/build.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - - - <?php -/* - * This file is autogenerated, DO NOT EDIT - */ - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/system/library/vendor/webtopay/libwebtopay/build/phing-2.4.12.phar b/system/library/vendor/webtopay/libwebtopay/build/phing-2.4.12.phar deleted file mode 100644 index c50bfbd..0000000 Binary files a/system/library/vendor/webtopay/libwebtopay/build/phing-2.4.12.phar and /dev/null differ diff --git a/system/library/vendor/webtopay/libwebtopay/composer.json b/system/library/vendor/webtopay/libwebtopay/composer.json deleted file mode 100644 index 1399eb4..0000000 --- a/system/library/vendor/webtopay/libwebtopay/composer.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "webtopay/libwebtopay", - "description": "PHP Library for WebToPay provided services", - "version": "1.6", - "license": "LGPL-3.0", - "authors": [ - { - "name": "EVP International", - "homepage": "http://www.webtopay.com/" - } - ], - "autoload": { - "classmap": ["src/"] - } -} \ No newline at end of file diff --git a/system/library/vendor/webtopay/libwebtopay/demo_shop/buy.php b/system/library/vendor/webtopay/libwebtopay/demo_shop/buy.php deleted file mode 100644 index 4650376..0000000 --- a/system/library/vendor/webtopay/libwebtopay/demo_shop/buy.php +++ /dev/null @@ -1,16 +0,0 @@ - $item, - 'id' => $id, -)); - diff --git a/system/library/vendor/webtopay/libwebtopay/demo_shop/includes/config.php b/system/library/vendor/webtopay/libwebtopay/demo_shop/includes/config.php deleted file mode 100644 index 410f948..0000000 --- a/system/library/vendor/webtopay/libwebtopay/demo_shop/includes/config.php +++ /dev/null @@ -1,28 +0,0 @@ - '73cdb059d0f29f275a34b370f8e4f900', // your password - 'projectid' => 6028, // your project id - - 'test' => 1, // disable in production - 'accepturl' => get_address('response.php?answer=accept'), - 'cancelurl' => get_address('response.php?answer=cancel'), - 'callbackurl' => get_address('response.php?answer=callback'), -); - -$shopItems = array( // just sample shop items; unrelated to WebToPay library - array( - 'title' => 'Item A', - 'price' => 100, - 'currency' => 'LTL', - ), - array( - 'title' => 'Item B', - 'price' => 2000, - 'currency' => 'EUR', - ), - array( - 'title' => 'Item C', - 'price' => 4990, - 'currency' => 'LTL', - ), -); \ No newline at end of file diff --git a/system/library/vendor/webtopay/libwebtopay/demo_shop/includes/helpers.php b/system/library/vendor/webtopay/libwebtopay/demo_shop/includes/helpers.php deleted file mode 100644 index 43d1ebc..0000000 --- a/system/library/vendor/webtopay/libwebtopay/demo_shop/includes/helpers.php +++ /dev/null @@ -1,65 +0,0 @@ - $shopItems, -)); - diff --git a/system/library/vendor/webtopay/libwebtopay/demo_shop/orders.php b/system/library/vendor/webtopay/libwebtopay/demo_shop/orders.php deleted file mode 100644 index 799be50..0000000 --- a/system/library/vendor/webtopay/libwebtopay/demo_shop/orders.php +++ /dev/null @@ -1,11 +0,0 @@ - isset($data['orders']) ? $data['orders'] : array(), - 'sms' => isset($data['sms']) ? $data['sms'] : array() -)); \ No newline at end of file diff --git a/system/library/vendor/webtopay/libwebtopay/demo_shop/paymentMethod.php b/system/library/vendor/webtopay/libwebtopay/demo_shop/paymentMethod.php deleted file mode 100644 index c30ad64..0000000 --- a/system/library/vendor/webtopay/libwebtopay/demo_shop/paymentMethod.php +++ /dev/null @@ -1,26 +0,0 @@ -filterForAmount($amount, $currency) // filter: leave only those, which are available for this sum - ->setDefaultLanguage('en'); // set default language for titles (default: lt) - - -echo template('paymentMethod.html', array( - 'methods' => $methods, - 'post' => $post, -)); diff --git a/system/library/vendor/webtopay/libwebtopay/demo_shop/request.php b/system/library/vendor/webtopay/libwebtopay/demo_shop/request.php deleted file mode 100644 index 8844352..0000000 --- a/system/library/vendor/webtopay/libwebtopay/demo_shop/request.php +++ /dev/null @@ -1,33 +0,0 @@ - $item['price'], - 'currency' => $item['currency'], - 'orderid' => $orderid, -); - -$data['orderid'] = $orderid; -$data['orders'][$orderid] = array('item' => $item, 'status' => 'new', 'additionalData' => $post); -save_data($data); - -// this method builds request and sends Location header for redirecting to payment site -// as an alternative, you can use WebToPay::buildRequest and make auto-post form -WebToPay::redirectToPayment(array_merge( - $post, - $config, - $order -)); \ No newline at end of file diff --git a/system/library/vendor/webtopay/libwebtopay/demo_shop/response.php b/system/library/vendor/webtopay/libwebtopay/demo_shop/response.php deleted file mode 100644 index 776b939..0000000 --- a/system/library/vendor/webtopay/libwebtopay/demo_shop/response.php +++ /dev/null @@ -1,66 +0,0 @@ -getMessage(); - } -} else if ('accept' == $answer) { - try { - $response = WebToPay::validateAndParseData($get, $config['projectid'], $config['sign_password']); - if ($response['status'] == 1 || $response['status'] == 2) { - // You can start providing services when you get confirmation with accept url - // Be sure to check if this order is not yet confirmed - user can refresh page anytime - // status 2 means that payment has been got but it's not yet confirmed - // @todo: get order by $response['orderid'], validate test (!), amount and currency - echo 'Your payment has been got successfuly, it will be confirmed shortly
'; - } - } catch (Exception $e) { - echo 'Your payment is not yet confirmed, system error
'; - } - echo template('Thank you for buying
Orders'); -} else { - echo template('
Payment rejected.
'); -} - diff --git a/system/library/vendor/webtopay/libwebtopay/demo_shop/sms.php b/system/library/vendor/webtopay/libwebtopay/demo_shop/sms.php deleted file mode 100644 index 927f2d4..0000000 --- a/system/library/vendor/webtopay/libwebtopay/demo_shop/sms.php +++ /dev/null @@ -1,20 +0,0 @@ -getMessage(); -} - -$data = load_data(); -$data['sms'][] = array( - '_GET' => $get, - 'parsedData' => $parsedData, -); -save_data($data); \ No newline at end of file diff --git a/system/library/vendor/webtopay/libwebtopay/demo_shop/style.css b/system/library/vendor/webtopay/libwebtopay/demo_shop/style.css deleted file mode 100644 index 8b0d851..0000000 --- a/system/library/vendor/webtopay/libwebtopay/demo_shop/style.css +++ /dev/null @@ -1,33 +0,0 @@ -form { - margin: 30px; -} -h2 { - margin-top: 50px; -} -h3 { - color: #333; -} -label { - font-weight: bold; - display: block; - margin-bottom: 10px; - width: 500px; -} -label input { - width: 300px; - float: right; -} -label input.radio { - width: auto; - float: none; -} -input[type=submit] { - margin: 16px 0; - font-weight: bold; - font-size: 120%; -} -div.error { - border: 2px solid #F00; - padding: 8px; - margin: 16px 0; -} diff --git a/system/library/vendor/webtopay/libwebtopay/demo_shop/templates/base.html.php b/system/library/vendor/webtopay/libwebtopay/demo_shop/templates/base.html.php deleted file mode 100644 index cd59d77..0000000 --- a/system/library/vendor/webtopay/libwebtopay/demo_shop/templates/base.html.php +++ /dev/null @@ -1,12 +0,0 @@ - - - - - libwebtopay demo - - - - - - - diff --git a/system/library/vendor/webtopay/libwebtopay/demo_shop/templates/buy.html.php b/system/library/vendor/webtopay/libwebtopay/demo_shop/templates/buy.html.php deleted file mode 100644 index 7923232..0000000 --- a/system/library/vendor/webtopay/libwebtopay/demo_shop/templates/buy.html.php +++ /dev/null @@ -1,16 +0,0 @@ -

Buy item

- -

-Price:
- -
- - - - - - - - - -
diff --git a/system/library/vendor/webtopay/libwebtopay/demo_shop/templates/list.html.php b/system/library/vendor/webtopay/libwebtopay/demo_shop/templates/list.html.php deleted file mode 100644 index 2f84122..0000000 --- a/system/library/vendor/webtopay/libwebtopay/demo_shop/templates/list.html.php +++ /dev/null @@ -1,7 +0,0 @@ -

Shop items

- - $item): ?> -

- Price:
- Buy - \ No newline at end of file diff --git a/system/library/vendor/webtopay/libwebtopay/demo_shop/templates/orders.html.php b/system/library/vendor/webtopay/libwebtopay/demo_shop/templates/orders.html.php deleted file mode 100644 index f1585f2..0000000 --- a/system/library/vendor/webtopay/libwebtopay/demo_shop/templates/orders.html.php +++ /dev/null @@ -1,44 +0,0 @@ -

Orders

- - $order): ?> -

- Price:
- Status:
- Additional parameters:
    - $value): ?> -
  • - -
- - Server response:
    - $value): ?> -
  • - -
- - - Additional server response:
    - $value): ?> -
  • - -
- - - -

SMS log

- - Request:
    - $value): ?> -
  • - -
- - Data:
    - $value): ?> -
  • - -
- - Data:
- - \ No newline at end of file diff --git a/system/library/vendor/webtopay/libwebtopay/demo_shop/templates/paymentMethod.html.php b/system/library/vendor/webtopay/libwebtopay/demo_shop/templates/paymentMethod.html.php deleted file mode 100644 index 4d8a685..0000000 --- a/system/library/vendor/webtopay/libwebtopay/demo_shop/templates/paymentMethod.html.php +++ /dev/null @@ -1,23 +0,0 @@ -

Select payment method

-
- getCountries() as $country): ?> -

getTitle()); ?>

- getGroups() as $group): ?> -

getTitle()); ?>

- getPaymentMethods() as $paymentMethod): ?> - getLogoUrl()): ?> - - - - - - - $value): ?> - - - -
diff --git a/system/library/vendor/webtopay/libwebtopay/demo_shop/var/__empty__ b/system/library/vendor/webtopay/libwebtopay/demo_shop/var/__empty__ deleted file mode 100644 index e69de29..0000000 diff --git a/system/library/vendor/webtopay/libwebtopay/phpunit.xml b/system/library/vendor/webtopay/libwebtopay/phpunit.xml deleted file mode 100644 index 1818668..0000000 --- a/system/library/vendor/webtopay/libwebtopay/phpunit.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - tests - - - - diff --git a/system/library/vendor/webtopay/libwebtopay/src/WebToPay.php b/system/library/vendor/webtopay/libwebtopay/src/WebToPay.php deleted file mode 100644 index c2f0001..0000000 --- a/system/library/vendor/webtopay/libwebtopay/src/WebToPay.php +++ /dev/null @@ -1,303 +0,0 @@ -. - * - * @package WebToPay - * @author EVP International - * @license http://www.gnu.org/licenses/lgpl.html - * @version 1.6 - * @link http://www.webtopay.com/ - */ - - -/** - * Contains static methods for most used scenarios. - */ -class WebToPay { - - /** - * WebToPay Library version. - */ - const VERSION = '1.6'; - - /** - * Server URL where all requests should go. - */ - const PAY_URL = 'https://www.mokejimai.lt/pay/'; - - /** - * Server URL where we can get XML with payment method data. - */ - const XML_URL = 'https://www.mokejimai.lt/new/api/paymentMethods/'; - - /** - * SMS answer url. - */ - const SMS_ANSWER_URL = 'https://www.mokejimai.lt/psms/respond/'; - - /** - * Builds request data array. - * - * This method checks all given data and generates correct request data - * array or raises WebToPayException on failure. - * - * Possible keys: - * https://www.mokejimai.lt/makro_specifikacija.html - * - * @param array $data Information about current payment request - * - * @return array - * - * @throws WebToPayException on data validation error - */ - public static function buildRequest($data) { - if (!isset($data['sign_password']) || !isset($data['projectid'])) { - throw new WebToPayException('sign_password or projectid is not provided'); - } - $password = $data['sign_password']; - $projectId = $data['projectid']; - unset($data['sign_password']); - unset($data['projectid']); - - $factory = new WebToPay_Factory(array('projectId' => $projectId, 'password' => $password)); - $requestBuilder = $factory->getRequestBuilder(); - return $requestBuilder->buildRequest($data); - } - - - /** - * Builds request and redirects user to payment window with generated request data - * - * Possible array keys are described here: - * https://www.mokejimai.lt/makro_specifikacija.html - * - * @param array $data Information about current payment request. - * @param boolean $exit if true, exits after sending Location header; default false - * - * @throws WebToPayException on data validation error - */ - public static function redirectToPayment($data, $exit = false) { - $request = self::buildRequest($data); - $url = self::PAY_URL . '?' . http_build_query($request); - $url = preg_replace('/[\r\n]+/is', '', $url); - if (headers_sent()) { - echo ''; - } else { - header("Location: $url", true); - } - printf( - 'Redirecting to %s. Please wait.', - htmlentities($url, ENT_QUOTES, 'UTF-8'), - htmlentities($url, ENT_QUOTES, 'UTF-8') - ); - if ($exit) { - exit(); - } - } - - /** - * Builds repeat request data array. - * - * This method checks all given data and generates correct request data - * array or raises WebToPayException on failure. - * - * Method accepts single parameter $data of array type. All possible array - * keys are described here: - * https://www.mokejimai.lt/makro_specifikacija.html - * - * @param array $data Information about current payment request - * - * @return array - * - * @throws WebToPayException on data validation error - */ - public static function buildRepeatRequest($data) { - if (!isset($data['sign_password']) || !isset($data['projectid']) || !isset($data['orderid'])) { - throw new WebToPayException('sign_password, projectid or orderid is not provided'); - } - $password = $data['sign_password']; - $projectId = $data['projectid']; - $orderId = $data['orderid']; - - $factory = new WebToPay_Factory(array('projectId' => $projectId, 'password' => $password)); - $requestBuilder = $factory->getRequestBuilder(); - return $requestBuilder->buildRepeatRequest($orderId); - } - - /** - * Returns payment url. Argument is same as lang parameter in request data - * - * @param string $language - * @return string $url - */ - public static function getPaymentUrl($language = 'LIT') { - $url = self::PAY_URL; - if ($language != 'LIT') { - $url = str_replace('mokejimai.lt', 'webtopay.com', $url); - } - return $url; - } - - /** - * Parses response from WebToPay server and validates signs. - * - * This function accepts both micro and macro responses. - * - * First parameter usualy should be $_GET array. - * - * Description about response can be found here: - * makro: https://www.mokejimai.lt/makro_specifikacija.html - * mikro: https://www.mokejimai.lt/mikro_mokejimu_specifikacija_SMS.html - * - * If response is not correct, WebToPayException will be raised. - * - * @param array $query Response array - * @param array $userData - * - * @return array - * - * @throws WebToPayException - * @deprecated use validateAndParseData() and check status code yourself - */ - public static function checkResponse($query, $userData = array()) { - $projectId = isset($userData['projectid']) ? $userData['projectid'] : null; - $password = isset($userData['sign_password']) ? $userData['sign_password'] : null; - $logFile = isset($userData['log']) ? $userData['log'] : null; - - try { - $data = self::validateAndParseData($query, $projectId, $password); - if ($data['type'] == 'macro' && $data['status'] != 1) { - throw new WebToPayException('Expected status code 1', WebToPayException::E_DEPRECATED_USAGE); - } - - if ($logFile) { - self::log('OK', http_build_query($data), $logFile); - } - return $data; - - } catch (WebToPayException $exception) { - if ($logFile && $exception->getCode() != WebToPayException::E_DEPRECATED_USAGE) { - self::log('ERR', $exception . "\nQuery: " . http_build_query($query), $logFile); - } - throw $exception; - } - } - - /** - * Parses request (query) data and validates its signature. - * - * @param array $query usually $_GET - * @param integer $projectId - * @param string $password - * - * @return array - * - * @throws WebToPayException - */ - public static function validateAndParseData(array $query, $projectId, $password) { - $factory = new WebToPay_Factory(array('projectId' => $projectId, 'password' => $password)); - $validator = $factory->getCallbackValidator(); - $data = $validator->validateAndParseData($query); - return $data; - } - - /** - * Sends SMS answer - * - * @param array $userData - * - * @throws WebToPayException - * @throws WebToPay_Exception_Validation - */ - public static function smsAnswer($userData) { - if (!isset($userData['id']) || !isset($userData['msg']) || !isset($userData['sign_password'])) { - throw new WebToPay_Exception_Validation('id, msg and sign_password are required'); - } - - $smsId = $userData['id']; - $text = $userData['msg']; - $password = $userData['sign_password']; - $logFile = isset($userData['log']) ? $userData['log'] : null; - - try { - - $factory = new WebToPay_Factory(array('password' => $password)); - $factory->getSmsAnswerSender()->sendAnswer($smsId, $text); - - if ($logFile) { - self::log('OK', 'SMS ANSWER ' . $smsId . ' ' . $text, $logFile); - } - - } catch (WebToPayException $e) { - if ($logFile) { - self::log('ERR', 'SMS ANSWER ' . $e, $logFile); - } - throw $e; - } - - } - - - /** - * Gets available payment methods for project. Gets methods min and max amounts in specified currency. - * - * @param integer $projectId - * @param string $currency - * - * @return WebToPay_PaymentMethodList - * - * @throws WebToPayException - */ - public static function getPaymentMethodList($projectId, $currency = 'LTL') { - $factory = new WebToPay_Factory(array('projectId' => $projectId)); - return $factory->getPaymentMethodListProvider()->getPaymentMethodList($currency); - } - - /** - * Logs to file. Just skips logging if file is not writeable - * - * @param string $type - * @param string $msg - * @param string $logfile - */ - protected static function log($type, $msg, $logfile) { - $fp = @fopen($logfile, 'a'); - if (!$fp) { - return; - } - - $logline = array( - $type, - isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '-', - date('[Y-m-d H:i:s O]'), - 'v' . self::VERSION . ':', - $msg - ); - - $logline = implode(' ', $logline)."\n"; - fwrite($fp, $logline); - fclose($fp); - - // clear big log file - if (filesize($logfile) > 1024 * 1024 * pi()) { - copy($logfile, $logfile.'.old'); - unlink($logfile); - } - } -} - - diff --git a/system/library/vendor/webtopay/libwebtopay/src/WebToPay/CallbackValidator.php b/system/library/vendor/webtopay/libwebtopay/src/WebToPay/CallbackValidator.php deleted file mode 100644 index eecb41c..0000000 --- a/system/library/vendor/webtopay/libwebtopay/src/WebToPay/CallbackValidator.php +++ /dev/null @@ -1,104 +0,0 @@ -signer = $signer; - $this->util = $util; - $this->projectId = $projectId; - } - - /** - * Parses callback parameters from query parameters and checks if sign is correct. - * Request has parameter "data", which is signed and holds all callback parameters - * - * @param array $requestData - * - * @return array Parsed callback parameters - * - * @throws WebToPayException - * @throws WebToPay_Exception_Callback - */ - public function validateAndParseData(array $requestData) { - if (!$this->signer->checkSign($requestData)) { - throw new WebToPay_Exception_Callback('Invalid sign parameters, check $_GET length limit'); - } - - if (!isset($requestData['data'])) { - throw new WebToPay_Exception_Callback('"data" parameter not found'); - } - $data = $requestData['data']; - - $queryString = $this->util->decodeSafeUrlBase64($data); - $request = $this->util->parseHttpQuery($queryString); - - if (!isset($request['projectid'])) { - throw new WebToPay_Exception_Callback( - 'Project ID not provided in callback', - WebToPayException::E_INVALID - ); - } - - if ((string) $request['projectid'] !== (string) $this->projectId) { - throw new WebToPay_Exception_Callback( - sprintf('Bad projectid: %s, should be: %s', $request['projectid'], $this->projectId), - WebToPayException::E_INVALID - ); - } - - if (!isset($request['type']) || !in_array($request['type'], array('micro', 'macro'))) { - $micro = ( - isset($request['to']) - && isset($request['from']) - && isset($request['sms']) - ); - $request['type'] = $micro ? 'micro' : 'macro'; - } - - return $request; - } - - /** - * Checks data to have all the same parameters provided in expected array - * - * @param array $data - * @param array $expected - * - * @throws WebToPayException - */ - public function checkExpectedFields(array $data, array $expected) { - foreach ($expected as $key => $value) { - $passedValue = isset($data[$key]) ? $data[$key] : null; - if ($passedValue != $value) { - throw new WebToPayException( - sprintf('Field %s is not as expected (expected %s, got %s)', $key, $value, $passedValue) - ); - } - } - } -} \ No newline at end of file diff --git a/system/library/vendor/webtopay/libwebtopay/src/WebToPay/Exception/Callback.php b/system/library/vendor/webtopay/libwebtopay/src/WebToPay/Exception/Callback.php deleted file mode 100644 index c6315bc..0000000 --- a/system/library/vendor/webtopay/libwebtopay/src/WebToPay/Exception/Callback.php +++ /dev/null @@ -1,8 +0,0 @@ -setField($field); - } - } -} \ No newline at end of file diff --git a/system/library/vendor/webtopay/libwebtopay/src/WebToPay/Factory.php b/system/library/vendor/webtopay/libwebtopay/src/WebToPay/Factory.php deleted file mode 100644 index 242c106..0000000 --- a/system/library/vendor/webtopay/libwebtopay/src/WebToPay/Factory.php +++ /dev/null @@ -1,202 +0,0 @@ -configuration = $configuration; - } - - /** - * Creates or gets callback validator instance - * - * @return WebToPay_CallbackValidator - * - * @throws WebToPay_Exception_Configuration - */ - public function getCallbackValidator() { - if ($this->callbackValidator === null) { - if (!isset($this->configuration['projectId'])) { - throw new WebToPay_Exception_Configuration('You have to provide project ID'); - } - $this->callbackValidator = new WebToPay_CallbackValidator( - $this->configuration['projectId'], - $this->getSigner(), - $this->getUtil() - ); - } - return $this->callbackValidator; - } - - /** - * Creates or gets request builder instance - * - * @throws WebToPay_Exception_Configuration - * - * @return WebToPay_RequestBuilder - */ - public function getRequestBuilder() { - if ($this->requestBuilder === null) { - if (!isset($this->configuration['password'])) { - throw new WebToPay_Exception_Configuration('You have to provide project password to sign request'); - } - if (!isset($this->configuration['projectId'])) { - throw new WebToPay_Exception_Configuration('You have to provide project ID'); - } - $this->requestBuilder = new WebToPay_RequestBuilder( - $this->configuration['projectId'], - $this->configuration['password'], - $this->getUtil() - ); - } - return $this->requestBuilder; - } - - /** - * Creates or gets SMS answer sender instance - * - * @throws WebToPay_Exception_Configuration - * - * @return WebToPay_SmsAnswerSender - */ - public function getSmsAnswerSender() { - if ($this->smsAnswerSender === null) { - if (!isset($this->configuration['password'])) { - throw new WebToPay_Exception_Configuration('You have to provide project password'); - } - $this->smsAnswerSender = new WebToPay_SmsAnswerSender( - $this->configuration['password'], - $this->getWebClient() - ); - } - return $this->smsAnswerSender; - } - - /** - * Creates or gets payment list provider instance - * - * @throws WebToPay_Exception_Configuration - * - * @return WebToPay_PaymentMethodListProvider - */ - public function getPaymentMethodListProvider() { - if ($this->paymentMethodListProvider === null) { - if (!isset($this->configuration['projectId'])) { - throw new WebToPay_Exception_Configuration('You have to provide project ID'); - } - $this->paymentMethodListProvider = new WebToPay_PaymentMethodListProvider( - $this->configuration['projectId'], - $this->getWebClient() - ); - } - return $this->paymentMethodListProvider; - } - - /** - * Creates or gets signer instance. Chooses SS2 signer if openssl functions are available, SS1 in other case - * - * @throws WebToPay_Exception_Configuration - * - * @return WebToPay_Sign_SignCheckerInterface - * - * @throws WebToPayException - */ - protected function getSigner() { - if ($this->signer === null) { - if (function_exists('openssl_pkey_get_public')) { - $webClient = $this->getWebClient(); - $publicKey = $webClient->get('http://downloads.webtopay.com/download/public.key'); - if (!$publicKey) { - throw new WebToPayException('Cannot download public key from WebToPay website'); - } - $this->signer = new WebToPay_Sign_SS2SignChecker($publicKey, $this->getUtil()); - } else { - if (!isset($this->configuration['password'])) { - throw new WebToPay_Exception_Configuration( - 'You have to provide project password if OpenSSL is unavailable' - ); - } - $this->signer = new WebToPay_Sign_SS1SignChecker($this->configuration['password']); - } - } - return $this->signer; - } - - /** - * Creates or gets web client instance - * - * @throws WebToPay_Exception_Configuration - * - * @return WebToPay_WebClient - */ - protected function getWebClient() { - if ($this->webClient === null) { - $this->webClient = new WebToPay_WebClient(); - } - return $this->webClient; - } - - /** - * Creates or gets util instance - * - * @throws WebToPay_Exception_Configuration - * - * @return WebToPay_Util - */ - protected function getUtil() { - if ($this->util === null) { - $this->util = new WebToPay_Util(); - } - return $this->util; - } -} diff --git a/system/library/vendor/webtopay/libwebtopay/src/WebToPay/PaymentMethod.php b/system/library/vendor/webtopay/libwebtopay/src/WebToPay/PaymentMethod.php deleted file mode 100644 index 0354a48..0000000 --- a/system/library/vendor/webtopay/libwebtopay/src/WebToPay/PaymentMethod.php +++ /dev/null @@ -1,218 +0,0 @@ -key = $key; - $this->minAmount = $minAmount; - $this->maxAmount = $maxAmount; - $this->currency = $currency; - $this->logoList = $logoList; - $this->titleTranslations = $titleTranslations; - $this->defaultLanguage = $defaultLanguage; - $this->isIban = $isIban; - $this->baseCurrency = $baseCurrency; - } - - /** - * Sets default language for titles. - * Returns itself for fluent interface - * - * @param string $language - * - * @return WebToPay_PaymentMethod - */ - public function setDefaultLanguage($language) { - $this->defaultLanguage = $language; - return $this; - } - - /** - * Gets default language for titles - * - * @return string - */ - public function getDefaultLanguage() { - return $this->defaultLanguage; - } - - /** - * Get assigned payment method key - * - * @return string - */ - public function getKey() { - return $this->key; - } - - /** - * Gets logo url for this payment method. Uses specified language or default one. - * If logotype is not found for specified language, null is returned. - * - * @param string [Optional] $languageCode - * - * @return string|null - */ - public function getLogoUrl($languageCode = null) { - if ($languageCode !== null && isset($this->logoList[$languageCode])) { - return $this->logoList[$languageCode]; - } elseif (isset($this->logoList[$this->defaultLanguage])) { - return $this->logoList[$this->defaultLanguage]; - } else { - return null; - } - } - - /** - * Gets title for this payment method. Uses specified language or default one. - * - * @param string [Optional] $languageCode - * - * @return string - */ - public function getTitle($languageCode = null) { - if ($languageCode !== null && isset($this->titleTranslations[$languageCode])) { - return $this->titleTranslations[$languageCode]; - } elseif (isset($this->titleTranslations[$this->defaultLanguage])) { - return $this->titleTranslations[$this->defaultLanguage]; - } else { - return $this->key; - } - } - - /** - * Checks if this payment method can be used for specified amount. - * Throws exception if currency checked is not the one, for which payment method list was downloaded. - * - * @param integer $amount - * @param string $currency - * - * @return boolean - * - * @throws WebToPayException - */ - public function isAvailableForAmount($amount, $currency) { - if ($this->currency !== $currency) { - throw new WebToPayException( - 'Currencies does not match. You have to get payment types for the currency you are checking. Given currency: ' - . $currency . ', available currency: ' . $this->currency - ); - } - return ( - ($this->minAmount === null || $amount >= $this->minAmount) - && ($this->maxAmount === null || $amount <= $this->maxAmount) - ); - } - - /** - * Returns min amount for this payment method. If no min amount is specified, returns empty string. - * - * @return string - */ - public function getMinAmountAsString() { - return $this->minAmount === null ? '' : ($this->minAmount . ' ' . $this->currency); - } - - /** - * Returns max amount for this payment method. If no max amount is specified, returns empty string. - * - * @return string - */ - public function getMaxAmountAsString() { - return $this->maxAmount === null ? '' : ($this->maxAmount . ' ' . $this->currency); - } - - /** - * Set if this method returns IBAN number after payment - * - * @param boolean $isIban - */ - public function setIsIban($isIban) { - $this->isIban = $isIban == 1; - } - - /** - * Get if this method returns IBAN number after payment - * - * @return bool - */ - public function isIban() { - return $this->isIban; - } - - /** - * Setter of BaseCurrency - * - * @param string $baseCurrency - */ - public function setBaseCurrency($baseCurrency) - { - $this->baseCurrency = $baseCurrency; - } - - /** - * Getter of BaseCurrency - * - * @return string - */ - public function getBaseCurrency() - { - return $this->baseCurrency; - } -} diff --git a/system/library/vendor/webtopay/libwebtopay/src/WebToPay/PaymentMethodCountry.php b/system/library/vendor/webtopay/libwebtopay/src/WebToPay/PaymentMethodCountry.php deleted file mode 100644 index 6e93dad..0000000 --- a/system/library/vendor/webtopay/libwebtopay/src/WebToPay/PaymentMethodCountry.php +++ /dev/null @@ -1,218 +0,0 @@ -countryCode = $countryCode; - $this->defaultLanguage = $defaultLanguage; - $this->titleTranslations = $titleTranslations; - $this->groups = array(); - } - - /** - * Sets default language for titles. - * Returns itself for fluent interface - * - * @param string $language - * - * @return WebToPay_PaymentMethodCountry - */ - public function setDefaultLanguage($language) { - $this->defaultLanguage = $language; - foreach ($this->groups as $group) { - $group->setDefaultLanguage($language); - } - return $this; - } - - /** - * Gets title of the group. Tries to get title in specified language. If it is not found or if language is not - * specified, uses default language, given to constructor. - * - * @param string [Optional] $languageCode - * - * @return string - */ - public function getTitle($languageCode = null) { - if ($languageCode !== null && isset($this->titleTranslations[$languageCode])) { - return $this->titleTranslations[$languageCode]; - } elseif (isset($this->titleTranslations[$this->defaultLanguage])) { - return $this->titleTranslations[$this->defaultLanguage]; - } else { - return $this->countryCode; - } - } - - /** - * Gets default language for titles - * - * @return string - */ - public function getDefaultLanguage() { - return $this->defaultLanguage; - } - - /** - * Gets country code - * - * @return string - */ - public function getCode() { - return $this->countryCode; - } - - /** - * Adds new group to payment methods for this country. - * If some other group was registered earlier with same key, overwrites it. - * Returns given group - * - * @param WebToPay_PaymentMethodGroup $group - * - * @return WebToPay_PaymentMethodGroup - */ - public function addGroup(WebToPay_PaymentMethodGroup $group) { - return $this->groups[$group->getKey()] = $group; - } - - /** - * Gets group object with specified group key. If no group with such key is found, returns null. - * - * @param string $groupKey - * - * @return null|WebToPay_PaymentMethodGroup - */ - public function getGroup($groupKey) { - return isset($this->groups[$groupKey]) ? $this->groups[$groupKey] : null; - } - - /** - * Returns payment method groups registered for this country. - * - * @return WebToPay_PaymentMethodGroup[] - */ - public function getGroups() { - return $this->groups; - } - - /** - * Gets payment methods in all groups - * - * @return WebToPay_PaymentMethod[] - */ - public function getPaymentMethods() { - $paymentMethods = array(); - foreach ($this->groups as $group) { - $paymentMethods = array_merge($paymentMethods, $group->getPaymentMethods()); - } - return $paymentMethods; - } - - /** - * Returns new country instance with only those payment methods, which are available for provided amount. - * - * @param integer $amount - * @param string $currency - * - * @return WebToPay_PaymentMethodCountry - */ - public function filterForAmount($amount, $currency) { - $country = new WebToPay_PaymentMethodCountry($this->countryCode, $this->titleTranslations, $this->defaultLanguage); - foreach ($this->getGroups() as $group) { - $group = $group->filterForAmount($amount, $currency); - if (!$group->isEmpty()) { - $country->addGroup($group); - } - } - return $country; - } - - /** - * Returns new country instance with only those payment methods, which are returns or not iban number after payment - * - * @param boolean $isIban - * - * @return WebToPay_PaymentMethodCountry - */ - public function filterForIban($isIban = true) { - $country = new WebToPay_PaymentMethodCountry($this->countryCode, $this->titleTranslations, $this->defaultLanguage); - foreach ($this->getGroups() as $group) { - $group = $group->filterForIban($isIban); - if (!$group->isEmpty()) { - $country->addGroup($group); - } - } - return $country; - } - - /** - * Returns whether this country has no groups - * - * @return boolean - */ - public function isEmpty() { - return count($this->groups) === 0; - } - - /** - * Loads groups from given XML node - * - * @param SimpleXMLElement $countryNode - */ - public function fromXmlNode($countryNode) { - foreach ($countryNode->payment_group as $groupNode) { - $key = (string) $groupNode->attributes()->key; - $titleTranslations = array(); - foreach ($groupNode->title as $titleNode) { - $titleTranslations[(string) $titleNode->attributes()->language] = (string) $titleNode; - } - $this->addGroup($this->createGroup($key, $titleTranslations))->fromXmlNode($groupNode); - } - } - - /** - * Method to create new group instances. Overwrite if you have to use some other group subtype. - * - * @param string $groupKey - * @param array $translations - * - * @return WebToPay_PaymentMethodGroup - */ - protected function createGroup($groupKey, array $translations = array()) { - return new WebToPay_PaymentMethodGroup($groupKey, $translations, $this->defaultLanguage); - } -} \ No newline at end of file diff --git a/system/library/vendor/webtopay/libwebtopay/src/WebToPay/PaymentMethodGroup.php b/system/library/vendor/webtopay/libwebtopay/src/WebToPay/PaymentMethodGroup.php deleted file mode 100644 index 4f0330f..0000000 --- a/system/library/vendor/webtopay/libwebtopay/src/WebToPay/PaymentMethodGroup.php +++ /dev/null @@ -1,247 +0,0 @@ -groupKey = $groupKey; - $this->translations = $translations; - $this->defaultLanguage = $defaultLanguage; - $this->paymentMethods = array(); - } - - /** - * Sets default language for titles. - * Returns itself for fluent interface - * - * @param string $language - * - * @return WebToPay_PaymentMethodGroup - */ - public function setDefaultLanguage($language) { - $this->defaultLanguage = $language; - foreach ($this->paymentMethods as $paymentMethod) { - $paymentMethod->setDefaultLanguage($language); - } - return $this; - } - - /** - * Gets default language for titles - * - * @return string - */ - public function getDefaultLanguage() { - return $this->defaultLanguage; - } - - /** - * Gets title of the group. Tries to get title in specified language. If it is not found or if language is not - * specified, uses default language, given to constructor. - * - * @param string [Optional] $languageCode - * - * @return string - */ - public function getTitle($languageCode = null) { - if ($languageCode !== null && isset($this->translations[$languageCode])) { - return $this->translations[$languageCode]; - } elseif (isset($this->translations[$this->defaultLanguage])) { - return $this->translations[$this->defaultLanguage]; - } else { - return $this->groupKey; - } - } - - /** - * Returns group key - * - * @return string - */ - public function getKey() { - return $this->groupKey; - } - - /** - * Returns available payment methods for this group - * - * @return WebToPay_PaymentMethod[] - */ - public function getPaymentMethods() { - return $this->paymentMethods; - } - - - /** - * Adds new payment method for this group. - * If some other payment method with specified key was registered earlier, overwrites it. - * Returns given payment method - * - * @param WebToPay_PaymentMethod $paymentMethod - * - * @return WebToPay_PaymentMethod - */ - public function addPaymentMethod(WebToPay_PaymentMethod $paymentMethod) { - return $this->paymentMethods[$paymentMethod->getKey()] = $paymentMethod; - } - - /** - * Gets payment method object with key. If no payment method with such key is found, returns null. - * - * @param string $key - * - * @return null|WebToPay_PaymentMethod - */ - public function getPaymentMethod($key) { - return isset($this->paymentMethods[$key]) ? $this->paymentMethods[$key] : null; - } - - /** - * Returns new group instance with only those payment methods, which are available for provided amount. - * - * @param integer $amount - * @param string $currency - * - * @return WebToPay_PaymentMethodGroup - */ - public function filterForAmount($amount, $currency) { - $group = new WebToPay_PaymentMethodGroup($this->groupKey, $this->translations, $this->defaultLanguage); - foreach ($this->getPaymentMethods() as $paymentMethod) { - if ($paymentMethod->isAvailableForAmount($amount, $currency)) { - $group->addPaymentMethod($paymentMethod); - } - } - return $group; - } - - /** - * Returns new country instance with only those payment methods, which are returns or not iban number after payment - * - * @param boolean $isIban - * - * @return WebToPay_PaymentMethodGroup - */ - public function filterForIban($isIban = true) { - $group = new WebToPay_PaymentMethodGroup($this->groupKey, $this->translations, $this->defaultLanguage); - foreach ($this->getPaymentMethods() as $paymentMethod) { - if ($paymentMethod->isIban() == $isIban) { - $group->addPaymentMethod($paymentMethod); - } - } - return $group; - } - - /** - * Returns whether this group has no payment methods - * - * @return boolean - */ - public function isEmpty() { - return count($this->paymentMethods) === 0; - } - - /** - * Loads payment methods from given XML node - * - * @param SimpleXMLElement $groupNode - */ - public function fromXmlNode($groupNode) { - foreach ($groupNode->payment_type as $paymentTypeNode) { - $key = (string) $paymentTypeNode->attributes()->key; - $titleTranslations = array(); - foreach ($paymentTypeNode->title as $titleNode) { - $titleTranslations[(string) $titleNode->attributes()->language] = (string) $titleNode; - } - $logoTranslations = array(); - foreach ($paymentTypeNode->logo_url as $logoNode) { - if ((string) $logoNode !== '') { - $logoTranslations[(string) $logoNode->attributes()->language] = (string) $logoNode; - } - } - $minAmount = null; - $maxAmount = null; - $currency = null; - $isIban = false; - $baseCurrency = null; - if (isset($paymentTypeNode->min)) { - $minAmount = (int) $paymentTypeNode->min->attributes()->amount; - $currency = (string) $paymentTypeNode->min->attributes()->currency; - } - if (isset($paymentTypeNode->max)) { - $maxAmount = (int) $paymentTypeNode->max->attributes()->amount; - $currency = (string) $paymentTypeNode->max->attributes()->currency; - } - - if (isset($paymentTypeNode->is_iban)) { - $isIban = (int) $paymentTypeNode->is_iban; - } - if (isset($paymentTypeNode->base_currency)) { - $baseCurrency = (string) $paymentTypeNode->base_currency; - } - $this->addPaymentMethod($this->createPaymentMethod( - $key, $minAmount, $maxAmount, $currency, $logoTranslations, $titleTranslations, $isIban, $baseCurrency - )); - } - } - - /** - * Method to create new payment method instances. Overwrite if you have to use some other subclass. - * - * @param string $key - * @param integer $minAmount - * @param integer $maxAmount - * @param string $currency - * @param array $logoList - * @param array $titleTranslations - * @param bool $isIban - * @param null $baseCurrency - * - * @return WebToPay_PaymentMethod - */ - protected function createPaymentMethod( - $key, $minAmount, $maxAmount, $currency, array $logoList = array(), array $titleTranslations = array(), - $isIban = false, $baseCurrency = null - ) { - return new WebToPay_PaymentMethod( - $key, $minAmount, $maxAmount, $currency, $logoList, $titleTranslations, $this->defaultLanguage, - $isIban, $baseCurrency - ); - } -} \ No newline at end of file diff --git a/system/library/vendor/webtopay/libwebtopay/src/WebToPay/PaymentMethodList.php b/system/library/vendor/webtopay/libwebtopay/src/WebToPay/PaymentMethodList.php deleted file mode 100644 index 4612a1a..0000000 --- a/system/library/vendor/webtopay/libwebtopay/src/WebToPay/PaymentMethodList.php +++ /dev/null @@ -1,205 +0,0 @@ -projectId = $projectId; - $this->countries = array(); - $this->defaultLanguage = $defaultLanguage; - $this->currency = $currency; - $this->amount = $amount; - } - - /** - * Sets default language for titles. - * Returns itself for fluent interface - * - * @param string $language - * - * @return WebToPay_PaymentMethodList - */ - public function setDefaultLanguage($language) { - $this->defaultLanguage = $language; - foreach ($this->countries as $country) { - $country->setDefaultLanguage($language); - } - return $this; - } - - /** - * Gets default language for titles - * - * @return string - */ - public function getDefaultLanguage() { - return $this->defaultLanguage; - } - - /** - * Gets project ID for this payment method list - * - * @return integer - */ - public function getProjectId() { - return $this->projectId; - } - - /** - * Gets currency for min and max amounts in this list - * - * @return string - */ - public function getCurrency() { - return $this->currency; - } - - /** - * Gets whether this list is already filtered for some amount - * - * @return boolean - */ - public function isFiltered() { - return $this->amount !== null; - } - - /** - * Returns available countries - * - * @return WebToPay_PaymentMethodCountry[] - */ - public function getCountries() { - return $this->countries; - } - - /** - * Adds new country to payment methods. If some other country with same code was registered earlier, overwrites it. - * Returns added country instance - * - * @param WebToPay_PaymentMethodCountry $country - * - * @return WebToPay_PaymentMethodCountry - */ - public function addCountry(WebToPay_PaymentMethodCountry $country) { - return $this->countries[$country->getCode()] = $country; - } - - /** - * Gets country object with specified country code. If no country with such country code is found, returns null. - * - * @param string $countryCode - * - * @return null|WebToPay_PaymentMethodCountry - */ - public function getCountry($countryCode) { - return isset($this->countries[$countryCode]) ? $this->countries[$countryCode] : null; - } - - /** - * Returns new payment method list instance with only those payment methods, which are available for provided - * amount. - * Returns itself, if list is already filtered and filter amount matches the given one. - * - * @param integer $amount - * @param string $currency - * - * @return WebToPay_PaymentMethodList - * - * @throws WebToPayException if this list is already filtered and not for provided amount - */ - public function filterForAmount($amount, $currency) { - if ($currency !== $this->currency) { - throw new WebToPayException( - 'Currencies do not match. Given currency: ' . $currency . ', currency in list: ' . $this->currency - ); - } - if ($this->isFiltered()) { - if ($this->amount === $amount) { - return $this; - } else { - throw new WebToPayException('This list is already filtered, use unfiltered list instead'); - } - } else { - $list = new WebToPay_PaymentMethodList($this->projectId, $currency, $this->defaultLanguage, $amount); - foreach ($this->getCountries() as $country) { - $country = $country->filterForAmount($amount, $currency); - if (!$country->isEmpty()) { - $list->addCountry($country); - } - } - return $list; - } - } - - /** - * Loads countries from given XML node - * - * @param SimpleXMLElement $xmlNode - */ - public function fromXmlNode($xmlNode) { - foreach ($xmlNode->country as $countryNode) { - $titleTranslations = array(); - foreach ($countryNode->title as $titleNode) { - $titleTranslations[(string) $titleNode->attributes()->language] = (string) $titleNode; - } - $this->addCountry($this->createCountry((string) $countryNode->attributes()->code, $titleTranslations)) - ->fromXmlNode($countryNode); - } - } - - /** - * Method to create new country instances. Overwrite if you have to use some other country subtype. - * - * @param string $countryCode - * @param array $titleTranslations - * - * @return WebToPay_PaymentMethodCountry - */ - protected function createCountry($countryCode, array $titleTranslations = array()) { - return new WebToPay_PaymentMethodCountry($countryCode, $titleTranslations, $this->defaultLanguage); - } -} \ No newline at end of file diff --git a/system/library/vendor/webtopay/libwebtopay/src/WebToPay/PaymentMethodListProvider.php b/system/library/vendor/webtopay/libwebtopay/src/WebToPay/PaymentMethodListProvider.php deleted file mode 100644 index b53c32a..0000000 --- a/system/library/vendor/webtopay/libwebtopay/src/WebToPay/PaymentMethodListProvider.php +++ /dev/null @@ -1,67 +0,0 @@ -projectId = $projectId; - $this->webClient = $webClient; - if (!function_exists('simplexml_load_string')) { - throw new WebToPayException('You have to install libxml to use payment methods API'); - } - } - - /** - * Gets payment method list for specified currency - * - * @param string $currency - * - * @return WebToPay_PaymentMethodList - * - * @throws WebToPayException - */ - public function getPaymentMethodList($currency) { - if (!isset($this->methodListCache[$currency])) { - $xmlAsString = $this->webClient->get(WebToPay::XML_URL . $this->projectId . '/currency:' . $currency); - $useInternalErrors = libxml_use_internal_errors(false); - $rootNode = simplexml_load_string($xmlAsString); - libxml_clear_errors(); - libxml_use_internal_errors($useInternalErrors); - if (!$rootNode) { - throw new WebToPayException('Unable to load XML from remote server'); - } - $methodList = new WebToPay_PaymentMethodList($this->projectId, $currency); - $methodList->fromXmlNode($rootNode); - $this->methodListCache[$currency] = $methodList; - } - return $this->methodListCache[$currency]; - } -} \ No newline at end of file diff --git a/system/library/vendor/webtopay/libwebtopay/src/WebToPay/RequestBuilder.php b/system/library/vendor/webtopay/libwebtopay/src/WebToPay/RequestBuilder.php deleted file mode 100644 index 1ebd106..0000000 --- a/system/library/vendor/webtopay/libwebtopay/src/WebToPay/RequestBuilder.php +++ /dev/null @@ -1,166 +0,0 @@ -projectId = $projectId; - $this->projectPassword = $projectPassword; - $this->util = $util; - } - - /** - * Builds request data array. - * - * This method checks all given data and generates correct request data - * array or raises WebToPayException on failure. - * - * @param array $data information about current payment request - * - * @return array - * - * @throws WebToPayException - */ - public function buildRequest($data) { - $this->validateRequest($data, self::getRequestSpec()); - $data['version'] = WebToPay::VERSION; - $data['projectid'] = $this->projectId; - unset($data['repeat_request']); - return $this->createRequest($data); - } - - /** - * Builds repeat request data array. - * - * This method checks all given data and generates correct request data - * array or raises WebToPayException on failure. - * - * @param string $orderId order id of repeated request - * - * @return array - * - * @throws WebToPayException - */ - public function buildRepeatRequest($orderId) { - $data['orderid'] = $orderId; - $data['version'] = WebToPay::VERSION; - $data['projectid'] = $this->projectId; - $data['repeat_request'] = '1'; - return $this->createRequest($data); - } - - /** - * Checks data to be valid by passed specification - * - * @param array $data - * @param array $specs - * - * @throws WebToPay_Exception_Validation - */ - protected function validateRequest($data, $specs) { - foreach ($specs as $spec) { - list($name, $maxlen, $required, $regexp) = $spec; - if ($required && !isset($data[$name])) { - throw new WebToPay_Exception_Validation( - sprintf("'%s' is required but missing.", $name), - WebToPayException::E_MISSING, - $name - ); - } - - if (!empty($data[$name])) { - if ($maxlen && strlen($data[$name]) > $maxlen) { - throw new WebToPay_Exception_Validation(sprintf( - "'%s' value is too long (%d), %d characters allowed.", - $name, - strlen($data[$name]), - $maxlen - ), WebToPayException::E_MAXLEN, $name); - } - - if ($regexp !== '' && !preg_match($regexp, $data[$name])) { - throw new WebToPay_Exception_Validation( - sprintf("'%s' value '%s' is invalid.", $name, $data[$name]), - WebToPayException::E_REGEXP, - $name - ); - } - } - } - } - - /** - * Makes request data array from parameters, also generates signature - * - * @param array $request - * - * @return array - */ - protected function createRequest(array $request) { - $data = $this->util->encodeSafeUrlBase64(http_build_query($request)); - return array( - 'data' => $data, - 'sign' => md5($data . $this->projectPassword), - ); - } - - /** - * Returns specification of fields for request. - * - * Array structure: - * name – request item name - * maxlen – max allowed value for item - * required – is this item is required - * regexp – regexp to test item value - * - * @return array - */ - protected static function getRequestSpec() { - return array( - array('orderid', 40, true, ''), - array('accepturl', 255, true, ''), - array('cancelurl', 255, true, ''), - array('callbackurl', 255, true, ''), - array('lang', 3, false, '/^[a-z]{3}$/i'), - array('amount', 11, false, '/^\d+$/'), - array('currency', 3, false, '/^[a-z]{3}$/i'), - array('payment', 20, false, ''), - array('country', 2, false, '/^[a-z_]{2}$/i'), - array('paytext', 255, false, ''), - array('p_firstname', 255, false, ''), - array('p_lastname', 255, false, ''), - array('p_email', 255, false, ''), - array('p_street', 255, false, ''), - array('p_city', 255, false, ''), - array('p_state', 20, false, ''), - array('p_zip', 20, false, ''), - array('p_countrycode', 2, false, '/^[a-z]{2}$/i'), - array('test', 1, false, '/^[01]$/'), - array('time_limit', 19, false, '/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/'), - ); - } -} \ No newline at end of file diff --git a/system/library/vendor/webtopay/libwebtopay/src/WebToPay/Sign/SS1SignChecker.php b/system/library/vendor/webtopay/libwebtopay/src/WebToPay/Sign/SS1SignChecker.php deleted file mode 100644 index 1639483..0000000 --- a/system/library/vendor/webtopay/libwebtopay/src/WebToPay/Sign/SS1SignChecker.php +++ /dev/null @@ -1,38 +0,0 @@ -projectPassword = $projectPassword; - } - - /** - * Check for SS1, which is not depend on openssl functions. - * - * @param array $request - * - * @return boolean - * - * @throws WebToPay_Exception_Callback - */ - public function checkSign(array $request) { - if (!isset($request['data']) || !isset($request['ss1'])) { - throw new WebToPay_Exception_Callback('Not enough parameters in callback. Possible version mismatch'); - } - - return md5($request['data'] . $this->projectPassword) === $request['ss1']; - } -} \ No newline at end of file diff --git a/system/library/vendor/webtopay/libwebtopay/src/WebToPay/Sign/SS2SignChecker.php b/system/library/vendor/webtopay/libwebtopay/src/WebToPay/Sign/SS2SignChecker.php deleted file mode 100644 index ba94567..0000000 --- a/system/library/vendor/webtopay/libwebtopay/src/WebToPay/Sign/SS2SignChecker.php +++ /dev/null @@ -1,47 +0,0 @@ -publicKey = $publicKey; - $this->util = $util; - } - - /** - * Checks signature - * - * @param array $request - * - * @return boolean - * - * @throws WebToPay_Exception_Callback - */ - public function checkSign(array $request) { - if (!isset($request['data']) || !isset($request['ss2'])) { - throw new WebToPay_Exception_Callback('Not enough parameters in callback. Possible version mismatch'); - } - - $ss2 = $this->util->decodeSafeUrlBase64($request['ss2']); - $ok = openssl_verify($request['data'], $ss2, $this->publicKey); - return $ok === 1; - } -} \ No newline at end of file diff --git a/system/library/vendor/webtopay/libwebtopay/src/WebToPay/Sign/SignCheckerInterface.php b/system/library/vendor/webtopay/libwebtopay/src/WebToPay/Sign/SignCheckerInterface.php deleted file mode 100644 index a710e15..0000000 --- a/system/library/vendor/webtopay/libwebtopay/src/WebToPay/Sign/SignCheckerInterface.php +++ /dev/null @@ -1,16 +0,0 @@ -password = $password; - $this->webClient = $webClient; - } - - /** - * Sends answer by sms ID get from callback. Answer can be send only if it was not provided - * when responding to callback - * - * @param integer $smsId - * @param string $text - * - * @throws WebToPayException - */ - public function sendAnswer($smsId, $text) { - $content = $this->webClient->get(WebToPay::SMS_ANSWER_URL, array( - 'id' => $smsId, - 'msg' => $text, - 'transaction' => md5($this->password . '|' . $smsId), - )); - if (strpos($content, 'OK') !== 0) { - throw new WebToPayException( - sprintf('Error: %s', $content), - WebToPayException::E_SMS_ANSWER - ); - } - } -} diff --git a/system/library/vendor/webtopay/libwebtopay/src/WebToPay/Util.php b/system/library/vendor/webtopay/libwebtopay/src/WebToPay/Util.php deleted file mode 100644 index aac1cf0..0000000 --- a/system/library/vendor/webtopay/libwebtopay/src/WebToPay/Util.php +++ /dev/null @@ -1,66 +0,0 @@ - '+', '_' => '/'))); - } - - /** - * Encodes string to url-safe-base64 - * Url-safe-base64 is same as base64, but + is replaced to - and / to _ - * - * @param string $text - * - * @return string - */ - public function encodeSafeUrlBase64($text) { - return strtr(base64_encode($text), array('+' => '-', '/' => '_')); - } - - /** - * Parses HTTP query to array - * - * @param string $query - * - * @return array - */ - public function parseHttpQuery($query) { - $params = array(); - parse_str($query, $params); - if (get_magic_quotes_gpc()) { - $params = $this->stripSlashesRecursively($params); - } - return $params; - } - - /** - * Strips slashes recursively, so this method can be used on arrays with more than one level - * - * @param mixed $data - * - * @return mixed - */ - protected function stripSlashesRecursively($data) { - if (is_array($data)) { - $result = array(); - foreach ($data as $key => $value) { - $result[stripslashes($key)] = $this->stripSlashesRecursively($value); - } - return $result; - } else { - return stripslashes($data); - } - } -} \ No newline at end of file diff --git a/system/library/vendor/webtopay/libwebtopay/src/WebToPay/WebClient.php b/system/library/vendor/webtopay/libwebtopay/src/WebToPay/WebClient.php deleted file mode 100644 index ce4e2de..0000000 --- a/system/library/vendor/webtopay/libwebtopay/src/WebToPay/WebClient.php +++ /dev/null @@ -1,58 +0,0 @@ - 0) { - $uri .= strpos($uri, '?') === false ? '?' : '&'; - $uri .= http_build_query($queryData); - } - $url = parse_url($uri); - if ('https' == $url['scheme']) { - $host = 'ssl://'.$url['host']; - $port = 443; - } else { - $host = $url['host']; - $port = 80; - } - - $fp = fsockopen($host, $port, $errno, $errstr, 30); - if (!$fp) { - throw new WebToPayException(sprintf('Cannot connect to %s', $uri), WebToPayException::E_INVALID); - } - - if(isset($url['query'])) { - $data = $url['path'].'?'.$url['query']; - } else { - $data = $url['path']; - } - - $out = "GET " . $data . " HTTP/1.0\r\n"; - $out .= "Host: ".$url['host']."\r\n"; - $out .= "Connection: Close\r\n\r\n"; - - $content = ''; - - fwrite($fp, $out); - while (!feof($fp)) $content .= fgets($fp, 8192); - fclose($fp); - - list($header, $content) = explode("\r\n\r\n", $content, 2); - - return trim($content); - } -} \ No newline at end of file diff --git a/system/library/vendor/webtopay/libwebtopay/src/WebToPayException.php b/system/library/vendor/webtopay/libwebtopay/src/WebToPayException.php deleted file mode 100644 index c599bf2..0000000 --- a/system/library/vendor/webtopay/libwebtopay/src/WebToPayException.php +++ /dev/null @@ -1,85 +0,0 @@ -fieldName = $fieldName; - } - - /** - * Gets field which failed - * - * @return string|boolean false - */ - public function getField() { - return $this->fieldName; - } -} \ No newline at end of file diff --git a/system/library/vendor/webtopay/libwebtopay/src/includes.php b/system/library/vendor/webtopay/libwebtopay/src/includes.php deleted file mode 100644 index 8fb66f5..0000000 --- a/system/library/vendor/webtopay/libwebtopay/src/includes.php +++ /dev/null @@ -1,23 +0,0 @@ -signer = $this->getMock('WebToPay_Sign_SignCheckerInterface'); - $this->util = $this->getMock('WebToPay_Util', array('decodeSafeUrlBase64', 'parseHttpQuery')); - $this->validator = new WebToPay_CallbackValidator(123, $this->signer, $this->util); - } - - /** - * Exception should be thrown on invalid sign - * - * @expectedException WebToPay_Exception_Callback - */ - public function testValidateAndParseDataWithInvalidSign() { - $request = array('data' => 'abcdef', 'sign' => 'qwerty'); - - $this->signer->expects($this->once())->method('checkSign')->with($request)->will($this->returnValue(false)); - $this->util->expects($this->never())->method($this->anything()); - - $this->validator->validateAndParseData($request); - } - - /** - * Exception should be thrown if project ID does not match expected one - * - * @expectedException WebToPay_Exception_Callback - */ - public function testValidateAndParseDataWithInvalidProject() { - $request = array('data' => 'abcdef', 'sign' => 'qwerty'); - $parsed = array('projectid' => 456); - - $this->signer->expects($this->once())->method('checkSign')->with($request)->will($this->returnValue(true)); - $this->util->expects($this->at(0))->method('decodeSafeUrlBase64')->with('abcdef')->will($this->returnValue('zxc')); - $this->util->expects($this->at(1))->method('parseHttpQuery')->with('zxc')->will($this->returnValue($parsed)); - - $this->validator->validateAndParseData($request); - } - - /** - * Tests validateAndParseData method - */ - public function testValidateAndParseData() { - $request = array('data' => 'abcdef', 'sign' => 'qwerty'); - $parsed = array('projectid' => 123, 'someparam' => 'qwerty123', 'type' => 'micro'); - - $this->signer->expects($this->once())->method('checkSign')->with($request)->will($this->returnValue(true)); - $this->util->expects($this->at(0))->method('decodeSafeUrlBase64')->with('abcdef')->will($this->returnValue('zxc')); - $this->util->expects($this->at(1))->method('parseHttpQuery')->with('zxc')->will($this->returnValue($parsed)); - - $this->assertEquals($parsed, $this->validator->validateAndParseData($request)); - } - - /** - * Tests checkExpectedFields method - it should throw exception (only) when some valus are not as expected or - * unspecified - */ - public function testCheckExpectedFields() { - $exception = null; - try { - $this->validator->checkExpectedFields( - array( - 'abc' => '123', - 'def' => '456', - ), - array( - 'def' => 456, - ) - ); - } catch (WebToPayException $exception) { - // empty block, $exception variable is set to exception object - } - $this->assertNull($exception); - - $exception = null; - try { - $this->validator->checkExpectedFields( - array( - 'abc' => '123', - 'def' => '456', - ), - array( - 'abc' => '123', - 'non-existing' => '789', - ) - ); - } catch (WebToPayException $exception) { - // empty block, $exception variable is set to exception object - } - $this->assertNotNull($exception); - - $exception = null; - try { - $this->validator->checkExpectedFields( - array( - 'abc' => '123', - 'def' => '456', - ), - array( - 'abc' => '1234', - ) - ); - } catch (WebToPayException $exception) { - // empty block, $exception variable is set to exception object - } - $this->assertNotNull($exception); - } -} \ No newline at end of file diff --git a/system/library/vendor/webtopay/libwebtopay/tests/WebToPay/FactoryTest.php b/system/library/vendor/webtopay/libwebtopay/tests/WebToPay/FactoryTest.php deleted file mode 100644 index 1da52de..0000000 --- a/system/library/vendor/webtopay/libwebtopay/tests/WebToPay/FactoryTest.php +++ /dev/null @@ -1,100 +0,0 @@ -factory = new WebToPay_Factory(array( - 'projectId' => '123', - 'password' => 'abc', - )); - $this->factoryWithoutConfiguration = new WebToPay_Factory(); - } - - /** - * Tests getCallbackValidator - */ - public function testGetCallbackValidator() { - $validator = $this->factory->getCallbackValidator(); - $this->assertSame($validator, $this->factory->getCallbackValidator()); - $this->assertInstanceOf('WebToPay_CallbackValidator', $validator); - } - - /** - * Tests getRequestBuilder - */ - public function testGetRequestBuilder() { - $builder = $this->factory->getRequestBuilder(); - $this->assertSame($builder, $this->factory->getRequestBuilder()); - $this->assertInstanceOf('WebToPay_RequestBuilder', $builder); - } - - /** - * Tests getSmsAnswerSender - */ - public function testGetSmsAnswerSender() { - $sender = $this->factory->getSmsAnswerSender(); - $this->assertSame($sender, $this->factory->getSmsAnswerSender()); - $this->assertInstanceOf('WebToPay_SmsAnswerSender', $sender); - } - - /** - * Tests getPaymentMethodListProvider - */ - public function testGetPaymentMethodListProvider() { - $provider = $this->factory->getPaymentMethodListProvider(); - $this->assertSame($provider, $this->factory->getPaymentMethodListProvider()); - $this->assertInstanceOf('WebToPay_PaymentMethodListProvider', $provider); - } - - /** - * Tests exception - * - * @expectedException WebToPay_Exception_Configuration - */ - public function testGetCallbackValidatorWithoutConfiguration() { - $this->factoryWithoutConfiguration->getCallbackValidator(); - } - - /** - * Tests exception - * - * @expectedException WebToPay_Exception_Configuration - */ - public function testGetRequestBuilderWithoutConfiguration() { - $this->factoryWithoutConfiguration->getRequestBuilder(); - } - - /** - * Tests exception - * - * @expectedException WebToPay_Exception_Configuration - */ - public function testGetSmsAnswerSenderWithoutConfiguration() { - $this->factoryWithoutConfiguration->getSmsAnswerSender(); - } - - /** - * Tests exception - * - * @expectedException WebToPay_Exception_Configuration - */ - public function testGetPaymentMethodListProviderWithoutConfiguration() { - $this->factoryWithoutConfiguration->getPaymentMethodListProvider(); - } -} diff --git a/system/library/vendor/webtopay/libwebtopay/tests/WebToPay/RequestBuilderTest.php b/system/library/vendor/webtopay/libwebtopay/tests/WebToPay/RequestBuilderTest.php deleted file mode 100644 index c0344bd..0000000 --- a/system/library/vendor/webtopay/libwebtopay/tests/WebToPay/RequestBuilderTest.php +++ /dev/null @@ -1,94 +0,0 @@ -util = $this->getMock('WebToPay_Util', array('encodeSafeUrlBase64')); - $this->builder = new WebToPay_RequestBuilder(123, 'secret', $this->util); - } - - /** - * Test build request when no orderid is passed - * - * @expectedException WebToPay_Exception_Validation - */ - public function testBuildRequestWithNoOrderId() { - $this->builder->buildRequest(array( - 'accepturl' => 'http://local.test/', - 'cancelurl' => 'http://local.test/', - 'callbackurl' => 'http://local.test/', - )); - } - - /** - * Test build request when invalid currency is passed - * - * @expectedException WebToPay_Exception_Validation - */ - public function testBuildRequestWithInvalidCurrency() { - $this->builder->buildRequest(array( - 'orderid' => 123, - 'accepturl' => 'http://local.test/', - 'cancelurl' => 'http://local.test/', - 'callbackurl' => 'http://local.test/', - 'currency' => 'litai', - )); - } - - /** - * Tests buildRequest method - */ - public function testBuildRequest() { - $this->util - ->expects($this->once()) - ->method('encodeSafeUrlBase64') - ->with( - 'orderid=123&accepturl=http%3A%2F%2Flocal.test%2F&cancelurl=http%3A%2F%2Flocal.test%2F' - . '&callbackurl=http%3A%2F%2Flocal.test%2F&amount=100&some-other-parameter=abc' - . '&version=1.6&projectid=123' - ) - ->will($this->returnValue('encoded')); - $this->assertEquals( - array('data' => 'encoded', 'sign' => md5('encodedsecret')), - $this->builder->buildRequest(array( - 'orderid' => 123, - 'accepturl' => 'http://local.test/', - 'cancelurl' => 'http://local.test/', - 'callbackurl' => 'http://local.test/', - 'amount' => 100, - 'some-other-parameter' => 'abc', - )) - ); - } - - /** - * Tests buildRepeatRequest method - */ - public function testBuildRepeatRequest() { - $this->util - ->expects($this->once()) - ->method('encodeSafeUrlBase64') - ->with('orderid=123&version=1.6&projectid=123&repeat_request=1') - ->will($this->returnValue('encoded')); - $this->assertEquals( - array('data' => 'encoded', 'sign' => md5('encodedsecret')), - $this->builder->buildRepeatRequest(123) - ); - } -} \ No newline at end of file diff --git a/system/library/vendor/webtopay/libwebtopay/tests/WebToPay/Sign/SS1SignCheckerTest.php b/system/library/vendor/webtopay/libwebtopay/tests/WebToPay/Sign/SS1SignCheckerTest.php deleted file mode 100644 index f93351c..0000000 --- a/system/library/vendor/webtopay/libwebtopay/tests/WebToPay/Sign/SS1SignCheckerTest.php +++ /dev/null @@ -1,48 +0,0 @@ -signChecker = new WebToPay_Sign_SS1SignChecker('secret'); - } - - /** - * Should throw exception if not all required parameters are passed - * - * @expectedException WebToPay_Exception_Callback - */ - public function testCheckSignWithoutInformation() { - $this->signChecker->checkSign(array( - 'projectid' => '123', - 'ss1' => 'asd', - 'ss2' => 'zxc', - )); - } - - /** - * Tests checkSign - */ - public function testCheckSign() { - $this->assertTrue($this->signChecker->checkSign(array( - 'data' => 'encodedData', - 'ss1' => md5('encodedDatasecret'), - 'ss2' => 'bad-ss2', - ))); - $this->assertFalse($this->signChecker->checkSign(array( - 'data' => 'encodedData', - 'ss1' => md5('encodedDatasecret1'), - 'ss2' => 'bad-ss2', - ))); - } -} \ No newline at end of file diff --git a/system/library/vendor/webtopay/libwebtopay/tests/WebToPay/Sign/SS2SignCheckerTest.php b/system/library/vendor/webtopay/libwebtopay/tests/WebToPay/Sign/SS2SignCheckerTest.php deleted file mode 100644 index 2a7ee3c..0000000 --- a/system/library/vendor/webtopay/libwebtopay/tests/WebToPay/Sign/SS2SignCheckerTest.php +++ /dev/null @@ -1,122 +0,0 @@ -util = $this->getMock('WebToPay_Util', array('decodeSafeUrlBase64')); - $this->signChecker = new WebToPay_Sign_SS2SignChecker(self::$publicKey, $this->util); - } - - /** - * Should throw exception if not all required parameters are passed - * - * @expectedException WebToPay_Exception_Callback - */ - public function testCheckSignWithoutInformation() { - $this->signChecker->checkSign(array( - 'projectid' => '123', - 'ss1' => 'asd', - 'ss2' => 'zxc', - )); - } - - /** - * Tests checkSign - */ - public function testCheckSign() { - $ss2 = null; - $privateKey = openssl_pkey_get_private(self::$privateKey); - openssl_sign('encodedData', $ss2, $privateKey); - - $this->util - ->expects($this->once()) - ->method('decodeSafeUrlBase64') - ->with('encoded-ss2') - ->will($this->returnValue($ss2)); - - $this->assertTrue($this->signChecker->checkSign(array( - 'data' => 'encodedData', - 'ss1' => 'bad-ss1', - 'ss2' => 'encoded-ss2', - ))); - } - - /** - * Tests checkSign with incorrect ss2 - */ - public function testCheckSignWithBadSignature() { - $this->util - ->expects($this->once()) - ->method('decodeSafeUrlBase64') - ->with('encoded-ss2') - ->will($this->returnValue('bad-ss2')); - - $this->assertFalse($this->signChecker->checkSign(array( - 'data' => 'encodedData', - 'ss1' => 'bad-ss1', - 'ss2' => 'encoded-ss2', - ))); - } -} \ No newline at end of file diff --git a/system/library/vendor/webtopay/libwebtopay/tests/WebToPay/UtilTest.php b/system/library/vendor/webtopay/libwebtopay/tests/WebToPay/UtilTest.php deleted file mode 100644 index 6c45bcf..0000000 --- a/system/library/vendor/webtopay/libwebtopay/tests/WebToPay/UtilTest.php +++ /dev/null @@ -1,76 +0,0 @@ -util = new WebToPay_Util(); - } - - /** - * Tests decodeSafeUrlBase64. Must work on non-url-safe base64 too - */ - public function testDecodeSafeUrlBase64() { - $this->assertEquals( - "\x33\0\1\2\3\4\5\x92\xFF\xAA\0\1\2\3\4\5\x92\xFE\xAA\xEE", - $this->util->decodeSafeUrlBase64('MwABAgMEBZL_qgABAgMEBZL-qu4=') - ); - $this->assertEquals( - "\x33\0\1\2\3\4\5\x92\xFF\xAA\0\1\2\3\4\5\x92\xFE\xAA\xEE", - $this->util->decodeSafeUrlBase64('MwABAgMEBZL/qgABAgMEBZL+qu4=') - ); - } - - /** - * Tests encodeSafeUrlBase64 - */ - public function testEncodeSafeUrlBase64() { - $this->assertEquals( - 'MwABAgMEBZL_qgABAgMEBZL-qu4=', - $this->util->encodeSafeUrlBase64("\x33\0\1\2\3\4\5\x92\xFF\xAA\0\1\2\3\4\5\x92\xFE\xAA\xEE") - ); - } - - /** - * Tests that encode and decode are compatible - */ - public function testEncodeAndDecodeAreCompatible() { - $values = array( - 'Some long string with UTF-8 ąččėę проверка', - "Some binary symbols \0\1\3\xFF\xE0\xD0\xC0\xB0\xA0\x90\x10\x0A ", - 'Some other symbols %=?/-_)22Wq', - ); - foreach ($values as $text) { - $this->assertEquals( - $text, - $this->util->decodeSafeUrlBase64($this->util->encodeSafeUrlBase64($text)) - ); - } - } - - /** - * Tests parseHttpQuery. Must work with and without gpc_magic_quotes - */ - public function testParseHttpQuery() { - $this->assertEquals( - array( - 'param1' => 'some string', - 'param2' => 'special symbols !!%(@_-+/=', - 'param3' => 'slashes \\\'"', - ), - $this->util->parseHttpQuery( - 'param1=some+string¶m2=special+symbols+%21%21%25%28%40_-%2B%2F%3D¶m3=slashes+%5C%27%22' - ) - ); - } -} \ No newline at end of file diff --git a/system/library/vendor/webtopay/libwebtopay/tests/WebToPayTest.php b/system/library/vendor/webtopay/libwebtopay/tests/WebToPayTest.php deleted file mode 100644 index 5f07f44..0000000 --- a/system/library/vendor/webtopay/libwebtopay/tests/WebToPayTest.php +++ /dev/null @@ -1,43 +0,0 @@ -assertEquals($url, WebToPay::PAY_URL); - $url = WebToPay::getPaymentUrl('ENG'); - $this->assertEquals($url, 'https://www.webtopay.com/pay/'); - } - - /** - * Exception should be thrown if project id is not given - * - * @expectedException WebToPayException - */ - public function testBuildRequestWithoutProjectId() { - WebToPay::buildRequest(array( - 'orderid' => '123', - 'accepturl' => 'http://local.test/accept', - 'cancelurl' => 'http://local.test/cancel', - 'callbackurl' => 'http://local.test/callback', - - 'sign_password' => 'asdfghjkl', - )); - } - - /** - * Exception should be thrown if order id is not given - * - * @expectedException WebToPayException - */ - public function testBuildRepeatRequestWithoutProjectId() { - WebToPay::buildRepeatRequest(array( - 'sign_password' => 'asdfghjkl', - 'projectid' => '123', - )); - } -} -