diff --git a/DIEGIMAS.txt b/DIEGIMAS.txt
index 927eeb2..a64c67c 100644
--- a/DIEGIMAS.txt
+++ b/DIEGIMAS.txt
@@ -1,12 +1,11 @@
Diegimas
1. Ikelkite viska i pagrindine csCart direktorija.
-2. Ivikdykite SQL uzklausa Jusu csCart duomenu bazeje:
-REPLACE INTO cscart_payment_processors (processor_id, processor, processor_script,processor_template, admin_template, callback, type)
- values ('1111', 'Paysera','paysera.php', 'paysera.tpl','paysera.tpl', 'N', 'P');
+2. Ivikdykite SQL uzklausas esancias /var/databse/backup/db_changes_paysera.sql faile Jusu csCart duomenu bazeje.
+
3. Administravime eikite i Administration -> Payment methods -> Add payment. Naudokite siuos nustatymus: General tab -> Name = "Paysera - payment gateway", Processor -> "Paysera".
4. Paspauskite konfiguruoti ir iveskite visus duomenis.
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 76d11d7..f0bebac 100644
--- a/README.md
+++ b/README.md
@@ -1,24 +1,11 @@
-plugin-cscart
-=============
-
-Paysera.com payment gateway plugin for csCart 2.x-3
-
-Requirements
-------------
-
-- csCart 2.x - 3.x
-
Installation
-------------
-1. Download this repository as zip and extract "payments,skins,stores" folders into csCart main directory.
-2. Insert this SQL statement in your cscart database:
-REPLACE INTO cscart_payment_processors (processor_id, processor, processor_script,processor_template, admin_template, callback, type)
- values ('1111', 'Paysera','paysera.php', 'paysera.tpl','paysera.tpl', 'N', 'P');
+1. Download the repository files ant put them in your default cscart directory.
+2. Insert SQL statements from/var/databse/backup/db_changes_paysera.sql into your cscart database:
+
3. In administrator menu go to Administration -> Payment methods -> Add payment. Use these settings General tab -> Name = "Paysera - payment gateway", Processor -> "Paysera".
4. Press configure and fill all the necessary information and save.
Contacts
---------
-If any problems occur please feel free to seek help via support@paysera.com
\ No newline at end of file
+If any problems occur please feel free to seek help via support@paysera.com
diff --git a/README.txt b/README.txt
index 6483035..f0bebac 100644
--- a/README.txt
+++ b/README.txt
@@ -1,12 +1,11 @@
Installation
1. Download the repository files ant put them in your default cscart directory.
-2. Insert this SQL statement in your cscart database:
-REPLACE INTO cscart_payment_processors (processor_id, processor, processor_script,processor_template, admin_template, callback, type)
- values ('1111', 'Paysera','paysera.php', 'paysera.tpl','paysera.tpl', 'N', 'P');
+2. Insert SQL statements from/var/databse/backup/db_changes_paysera.sql into your cscart database:
+
3. In administrator menu go to Administration -> Payment methods -> Add payment. Use these settings General tab -> Name = "Paysera - payment gateway", Processor -> "Paysera".
4. Press configure and fill all the necessary information and save.
Contacts
-If any problems occur please feel free to seek help via support@paysera.com
\ No newline at end of file
+If any problems occur please feel free to seek help via support@paysera.com
diff --git a/payments/paysera.php b/app/payments/paysera.php
old mode 100644
new mode 100755
similarity index 67%
rename from payments/paysera.php
rename to app/payments/paysera.php
index 7d33d6f..ba3781e
--- a/payments/paysera.php
+++ b/app/payments/paysera.php
@@ -1,10 +1,14 @@
$processor_data['params']['project_id'],
- 'sign_password' => $processor_data['params']['sign'],
+ 'projectid' => $processor_data['processor_params']['project_id'],
+ 'sign_password' => $processor_data['processor_params']['sign'],
));
@@ -69,23 +75,28 @@ function fn_payment_end($order_id, $pp_response, $force_notification = array())
} catch (Exception $e) {
exit(sprintf("ERROR: %s", $e->getMessage()));
}
- } elseif ($mode == 'cancel') {
- fn_payment_end($_REQUEST['orderId'], $response);
- fn_order_placement_routines($_REQUEST['orderId']);
+ }
+ elseif ($mode == 'failed') { //echo 'ok'; die;
+ //fn_payment_end($_REQUEST['order_id'], $response);
+ fn_order_placement_routines('route', $_REQUEST['order_id']);
exit;
}
exit;
} else {
-
+//print_r($order_info);
+$pid = $order_info['payment_method']['processor_params']['project_id'];
+$psign = $order_info['payment_method']['processor_params']['sign'];
+$ptest = $order_info['payment_method']['processor_params']['test'];
+$pcurr = $order_info['payment_method']['processor_params']['currency'];
$_order_id = ($order_info['repaid']) ? ($order_id . '_' . $order_info['repaid']) : $order_id;
- $s_id = Session::get_id();
+ //$s_id = Session::get_id();
$order_info['b_country'] = strtolower($order_info['b_country']);
$language = strtoupper($_SESSION['settings']['cart_languageC']['value']);
$currency = strtoupper($_SESSION['settings']['secondary_currencyC']['value']);
-
+//echo $currency;
$currencyCo = db_get_field("SELECT ?:currencies.coefficient FROM ?:currencies WHERE ?:currencies.currency_code = ?s", $currency);
$price = intval(number_format($order_info['total'] / $currencyCo, 2, '', ''));
@@ -93,19 +104,19 @@ function fn_payment_end($order_id, $pp_response, $force_notification = array())
$url = strtr($url, array('index.php' => '/payments/paysera.php'));
$urlIndex = strtr($url, array('/payments/paysera.php' => 'index.php'));
- $psData = fn_get_payment_method_data($_SESSION['cart']['payment_id']);
+ //$psData = fn_get_payment_method_data($_SESSION['cart']['payment_id']);
try {
$payment_info = array(
- 'projectid' => $psData['params']['project_id'],
- 'sign_password' => $psData['params']['sign'],
+ 'projectid' => $pid,
+ 'sign_password' => $psign,
'orderid' => $_order_id,
'lang' => ($language === 'LT') ? 'LIT' : 'ENG',
'amount' => $price,
'currency' => $currency,
- 'accepturl' => "{$urlIndex}?dispatch=payment_notification.return&payment=paysera&orderId={$_order_id}",
- 'cancelurl' => "{$urlIndex}?dispatch=payment_notification.cancel&payment=paysera&orderId={$_order_id}",
- 'callbackurl' => "{$urlIndex}?dispatch=payment_notification.callback&payment=paysera&orderId={$_order_id}",
+ 'accepturl' => fn_url("payment_notification.success?payment=paysera&order_id=$order_id", AREA, 'current'),
+ 'cancelurl' => fn_url("payment_notification.failed?payment=paysera&order_id=$order_id", AREA, 'current'),
+ 'callbackurl' => fn_url("payment_notification.notify?payment=paysera&order_id=$order_id", AREA, 'current'),
'payment' => '',
'country' => $order_info['b_country'],
'logo' => '',
@@ -119,12 +130,12 @@ function fn_payment_end($order_id, $pp_response, $force_notification = array())
'p_zip' => $order_info['b_zipcode'],
'p_countrycode' => $order_info['b_country'],
- 'test' => $psData['params']['test'],
- );
-
- WebToPay::redirectToPayment($payment_info);
+ 'test' => $ptest,
+ ); ///print_r($payment_info); //die;
+ WebToPay::redirectToPayment($payment_info);
+
} catch (WebToPayException $e) {
exit(get_class($e) . ': ' . $e->getMessage());
- }
+ } die;
fn_start_payment($_order_id, false, $payment_info);
}
\ No newline at end of file
diff --git a/payments/vendor/webtopay/libwebtopay/WebToPay.php b/app/payments/vendor/webtopay/libwebtopay/WebToPay.php
old mode 100644
new mode 100755
similarity index 87%
rename from payments/vendor/webtopay/libwebtopay/WebToPay.php
rename to app/payments/vendor/webtopay/libwebtopay/WebToPay.php
index 4c6ae0b..13af3aa
--- a/payments/vendor/webtopay/libwebtopay/WebToPay.php
+++ b/app/payments/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/skins/basic/admin/views/payments/components/cc_processors/paysera.tpl b/design/backend/templates/views/payments/components/cc_processors/paysera.tpl
old mode 100644
new mode 100755
similarity index 87%
rename from skins/basic/admin/views/payments/components/cc_processors/paysera.tpl
rename to design/backend/templates/views/payments/components/cc_processors/paysera.tpl
index 48b9641..26d4d17
--- a/skins/basic/admin/views/payments/components/cc_processors/paysera.tpl
+++ b/design/backend/templates/views/payments/components/cc_processors/paysera.tpl
@@ -23,13 +23,13 @@
-
+
diff --git a/design/themes/basic/templates/views/orders/components/payments/paysera.php b/design/themes/basic/templates/views/orders/components/payments/paysera.php
new file mode 100644
index 0000000..e758a2c
--- /dev/null
+++ b/design/themes/basic/templates/views/orders/components/payments/paysera.php
@@ -0,0 +1,49 @@
+ array("Type" => "System", "Value" => "Paysera"),
+ "adminusername" => array("FriendlyName" => "Admin Username", "Type" => "text", "Size" => "15", "Description" => "Enter admin username"),
+ "projectID" => array("FriendlyName" => "Project ID", "Type" => "text", "Size" => "10", "Description" => "Enter unique Project ID",),
+ "projectPass" => array("FriendlyName" => "Project password", "Type" => "text", "Size" => "32", "Description" => "Enter unique sign password",),
+ "testmode" => array("FriendlyName" => "Test Mode", "Type" => "yesno", "Description" => "Tick this to enable test mode",),
+ );
+ return $configarray;
+}
+
+function paysera_link($params) {
+
+ $URL = array();
+
+ $URL['accept'] = $params['systemurl'] . '/modules/gateways/callback/paysera.php?accepturl=1';
+ $URL['cancel'] = $params['systemurl'] . '/clientarea.php';
+ $URL['callback'] = $params['systemurl'] . '/modules/gateways/callback/paysera.php';
+ try {
+ WebToPay::redirectToPayment(array(
+ 'projectid' => $params['projectID'],
+ 'sign_password' => $params['projectPass'],
+
+ 'orderid' => $params['invoiceid'],
+ 'amount' => intval(number_format($params['amount'], 2, '', '')),
+ 'currency' => $params['currency'],
+
+ 'accepturl' => $URL['accept'],
+ 'cancelurl' => $URL['cancel'],
+ 'callbackurl' => $URL['callback'],
+
+ 'p_firstname' => $params['clientdetails']['firstname'],
+ 'p_lastname' => $params['clientdetails']['lastname'],
+ 'p_email' => $params['clientdetails']['email'],
+ 'p_street' => $params['clientdetails']['address1'] . $params['clientdetails']['address2'],
+ 'p_city' => $params['clientdetails']['city'],
+ 'p_state' => $params['clientdetails']['state'],
+ 'p_zip' => $params['clientdetails']['postcode'],
+ 'p_countrycode' => $params['clientdetails']['country'],
+ 'test' => $params['testmode'] == 'on' ? 1 : 0,
+ ));
+ } catch (WebToPayException $e) {
+ echo get_class($e) . ': ' . $e->getMessage();
+ }
+}
diff --git a/skins/basic/customer/views/orders/components/payments/paysera.tpl b/design/themes/basic/templates/views/orders/components/payments/paysera.tpl
old mode 100644
new mode 100755
similarity index 100%
rename from skins/basic/customer/views/orders/components/payments/paysera.tpl
rename to design/themes/basic/templates/views/orders/components/payments/paysera.tpl
diff --git a/payments/vendor/autoload.php b/payments/vendor/autoload.php
deleted file mode 100644
index 4c1ef81..0000000
--- a/payments/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/payments/vendor/composer/autoload_classmap.php b/payments/vendor/composer/autoload_classmap.php
deleted file mode 100644
index b46a4ea..0000000
--- a/payments/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/payments/vendor/composer/autoload_namespaces.php b/payments/vendor/composer/autoload_namespaces.php
deleted file mode 100644
index 7b9d516..0000000
--- a/payments/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/payments/vendor/composer/installed.json b/payments/vendor/composer/installed.json
deleted file mode 100644
index 5d9a5cc..0000000
--- a/payments/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/payments/vendor/webtopay/libwebtopay/.hgignore b/payments/vendor/webtopay/libwebtopay/.hgignore
deleted file mode 100644
index dfd15be..0000000
--- a/payments/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/payments/vendor/webtopay/libwebtopay/.hgtags b/payments/vendor/webtopay/libwebtopay/.hgtags
deleted file mode 100644
index e705d88..0000000
--- a/payments/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/payments/vendor/webtopay/libwebtopay/COPYING b/payments/vendor/webtopay/libwebtopay/COPYING
deleted file mode 100644
index cca7fc2..0000000
--- a/payments/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/payments/vendor/webtopay/libwebtopay/README b/payments/vendor/webtopay/libwebtopay/README
deleted file mode 100644
index ae1140c..0000000
--- a/payments/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/payments/vendor/webtopay/libwebtopay/build.sh b/payments/vendor/webtopay/libwebtopay/build.sh
deleted file mode 100644
index e9c410a..0000000
--- a/payments/vendor/webtopay/libwebtopay/build.sh
+++ /dev/null
@@ -1,2 +0,0 @@
-cd build
-php phing-2.4.12.phar
diff --git a/payments/vendor/webtopay/libwebtopay/build/build.xml b/payments/vendor/webtopay/libwebtopay/build/build.xml
deleted file mode 100644
index d0e19e9..0000000
--- a/payments/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/payments/vendor/webtopay/libwebtopay/build/phing-2.4.12.phar b/payments/vendor/webtopay/libwebtopay/build/phing-2.4.12.phar
deleted file mode 100644
index c50bfbd..0000000
Binary files a/payments/vendor/webtopay/libwebtopay/build/phing-2.4.12.phar and /dev/null differ
diff --git a/payments/vendor/webtopay/libwebtopay/composer.json b/payments/vendor/webtopay/libwebtopay/composer.json
deleted file mode 100644
index 1399eb4..0000000
--- a/payments/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/payments/vendor/webtopay/libwebtopay/demo_shop/buy.php b/payments/vendor/webtopay/libwebtopay/demo_shop/buy.php
deleted file mode 100644
index 4650376..0000000
--- a/payments/vendor/webtopay/libwebtopay/demo_shop/buy.php
+++ /dev/null
@@ -1,16 +0,0 @@
- $item,
- 'id' => $id,
-));
-
diff --git a/payments/vendor/webtopay/libwebtopay/demo_shop/includes/config.php b/payments/vendor/webtopay/libwebtopay/demo_shop/includes/config.php
deleted file mode 100644
index 410f948..0000000
--- a/payments/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/payments/vendor/webtopay/libwebtopay/demo_shop/includes/helpers.php b/payments/vendor/webtopay/libwebtopay/demo_shop/includes/helpers.php
deleted file mode 100644
index 43d1ebc..0000000
--- a/payments/vendor/webtopay/libwebtopay/demo_shop/includes/helpers.php
+++ /dev/null
@@ -1,65 +0,0 @@
- $shopItems,
-));
-
diff --git a/payments/vendor/webtopay/libwebtopay/demo_shop/orders.php b/payments/vendor/webtopay/libwebtopay/demo_shop/orders.php
deleted file mode 100644
index 799be50..0000000
--- a/payments/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/payments/vendor/webtopay/libwebtopay/demo_shop/paymentMethod.php b/payments/vendor/webtopay/libwebtopay/demo_shop/paymentMethod.php
deleted file mode 100644
index c30ad64..0000000
--- a/payments/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/payments/vendor/webtopay/libwebtopay/demo_shop/request.php b/payments/vendor/webtopay/libwebtopay/demo_shop/request.php
deleted file mode 100644
index 8844352..0000000
--- a/payments/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/payments/vendor/webtopay/libwebtopay/demo_shop/response.php b/payments/vendor/webtopay/libwebtopay/demo_shop/response.php
deleted file mode 100644
index 776b939..0000000
--- a/payments/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('