AAAAindex.html000066600000000000151373413000006530 0ustar00.htaccess000066600000000177151373413000006350 0ustar00 Order allow,deny Deny from all sofort/index.html000066600000000040151373413000010050 0ustar00 sofort/.htaccess000066600000000177151373413000007664 0ustar00 Order allow,deny Deny from all sofort/library/sofortLib_refund.inc.php000066600000012474151373413000014324 0ustar00status */ public function sendRequest() { parent::sendRequest(); return $this->getStatusArray(); } /** * add a new refund to this message * * @param string $transaction transaction id of transfer you want to refund * @param float $amount amount of money to refund, less or equal to amount of original transfer * @param string $comment comment that will be displayed in admin-menu later * @return SofortLib_Refund $this */ public function addRefund($transaction, $amount, $comment = '') { $this->_parameters['refund'][] = array( 'transaction' => $transaction, 'amount' => $amount, 'comment' => $comment, ); return $this; } /** * set data of account * * @param string $bank_code bank code of bank * @param string $account_number account number * @param string $holder Name/Holder of this account * @return SofortLib_Multipay $this */ public function setSenderAccount($bankCode, $accountNumber, $holder = '') { $this->_parameters['sender'] = array( 'holder' => $holder, 'account_number' => $accountNumber, 'bank_code' => $bankCode, ); return $this; } /** * * Setter for title * @param string $arg */ public function setTitle($arg) { $this->_parameters['title'] = $arg; return $this; } /** * * Getter for transactions * @param int $i */ public function getTransactionId($i = 0) { return $this->_response['refunds']['refund'][$i]['transaction']['@data']; } /** * * Getter for amounts * @param int $i */ public function getAmount($i = 0) { return $this->_response['refunds']['refund'][$i]['amount']['@data']; } /** * * Getter for statuses * @param int $i */ public function getStatus($i = 0) { return $this->_response['refunds']['refund'][$i]['status']['@data']; } /** * * Getter for comments * @param int $i */ public function getComment($i = 0) { return $this->_response['refunds']['refund'][$i]['comment']['@data']; } /** * * Getter for refund's title */ public function getTitle() { return $this->_response['refunds']['title']['@data']; } /** * * Getter for refund's errors * @param int $i */ public function getRefundError($i = 0) { return parent::getError('all', $this->_response[$i]); } /** * * Has an error occurred for refund * @param int $i */ public function isRefundError($i = 0) { return $this->_response['refunds']['refund'][$i]['status']['@data'] == 'error'; } /** * * Getter for DTA (MT940) */ public function getDta() { return $this->_response['refunds']['dta']['@data']; } /** * * Getter for response, as an array */ public function getAsArray() { return $this->_response; } /** * * Getter for status array * @deprecated */ public function getStatusArray() { $ret = array(); foreach ($this->_response['refunds']['refund'] as $transaction) { $ret[$transaction['transaction']['@data']] = $transaction['status']['@data']; } return $ret; } /** * Parse the XML (override) * @see SofortLib_Abstract::_parseXml() */ protected function _parseXml() {} /** * Handle errors occurred * @see SofortLib::_handleErrors() */ protected function _handleErrors() { if (!isset($this->_response['refunds']['refund'][0])) { $tmp = $this->_response['refunds']['refund']; unset($this->_response['refunds']['refund']); $this->_response['refunds']['refund'][] = $tmp; } foreach ($this->_response['refunds']['refund'] as $response) { //handle errors if (isset($response['errors']['error'])) { if (!isset($response['errors']['error'][0])) { $tmp = $response['errors']['error']; unset($response['errors']['error']); $response['errors']['error'][0] = $tmp; } foreach ($response['errors']['error'] as $error) { $this->errors['global'][] = $this->_getErrorBlock($error); } } //handle warnings if (isset($response['warnings']['warning'])) { if (!isset($response['warnings']['warning'][0])) { $tmp = $response['warnings']['warning']; unset($response['warnings']['warning']); $response['warnings']['warning'][0] = $tmp; } foreach ($response['warnings']['warning'] as $error) { $this->warnings['global'][] = $this->_getErrorBlock($error); } } } } } ?>sofort/library/sofortLib_ideal_classic.php000066600000007027151373413000015046 0ustar00getRelatedBanks(); //get all iDEAL-Banks * $sofort->getPaymentUrl(); //returns paymentUrl including (including ...&hash=1234567890&...) * * Copyright (c) 2012 SOFORT AG * * Released under the GNU General Public License (Version 2) * [http://www.gnu.org/licenses/gpl-2.0.html] * * $Date: 2012-11-23 17:15:47 +0100 (Fri, 23 Nov 2012) $ * @version SofortLib 1.5.4 $Id: sofortLib_ideal_classic.php 5773 2012-11-23 16:15:47Z dehn $ * @author SOFORT AG http://www.sofort.com (integration@sofort.com) * */ class SofortLib_iDealClassic extends SofortLib_SofortueberweisungClassic { private $_apiUrl = ''; private $_apiKey = ''; private $_relatedBanks = array(); private $_SofortLib_iDeal_Banks = null; protected $_password; protected $_userId; protected $_projectId; protected $_paymentUrl = 'https://www.sofort.com/payment/ideal'; protected $_hashFields = array( 'user_id', 'project_id', 'sender_holder', 'sender_account_number', 'sender_bank_code', 'sender_country_id', 'amount', 'reason_1', 'reason_2', 'user_variable_0', 'user_variable_1', 'user_variable_2', 'user_variable_3', 'user_variable_4', 'user_variable_5', ); /** * * Contructor for SofortLib_iDealClassic * @param string $configKey * @param string $password * @param string $hashFunction */ public function __construct($configKey, $password, $hashFunction = 'sha1') { list($userId, $projectId, $apiKey) = explode(':', $configKey); $this->_password = $password; $this->_userId = $this->params['user_id'] = $userId; $this->_projectId = $this->params['project_id'] = $projectId; $this->_hashFunction = strtolower($hashFunction); $this->_paymentUrl = $this->_getPaymentDomain(); $this->_SofortLib_iDeal_Banks = new SofortLib_iDeal_Banks($configKey, $this->_paymentUrl); } /** * * Set sender's country id * @param string $senderCountryId * @return instance */ public function setSenderCountryId($senderCountryId = 'NL') { $this->params['sender_country_id'] = $senderCountryId; } /** * * Set sender's bank code * @param string $senderBankCode * @return instance */ public function setSenderBankCode($senderBankCode) { $this->params['sender_bank_code'] = $senderBankCode; return $this; } /** * Getter for occurred errors * (non-PHPdoc) * @see SofortLib_SofortueberweisungClassic::getError() */ public function getError(){ return $this->error; } /** * Get related banks of iDeal * @return array */ public function getRelatedBanks() { $this->_SofortLib_iDeal_Banks->sendRequest(); return $this->_SofortLib_iDeal_Banks->getBanks(); } /** * Getter for the payment domain * (non-PHPdoc) * @see SofortLib_SofortueberweisungClassic::_getPaymentDomain() */ protected function _getPaymentDomain() { return (getenv('idealApiUrl') != '') ? getenv('idealApiUrl') : $this->_paymentUrl; } } ?>sofort/library/sofortLib_http.inc.php000066600000015320151373413000014011 0ustar00url = $url; $this->headers = $headers; $this->compression = $compression; $this->proxy = $proxy; } /** * * Getter for information * @param string $opt */ public function getinfo($opt = '') { if (!empty($opt)) { return $this->info[$opt]; } else { return $this->info; } } /** * send data to server with POST request * @param string $data * @param string $url * @param string $headers */ public function post($data, $url = false, $headers = false) { if (function_exists('curl_init')) { return $this->postCurl($data, $url, $headers); } else { return $this->postSocket($data, $url, $headers); } } /** * post data using curl * @param string $data * @param string $url * @param string $headers */ public function postCurl($data, $url = false, $headers = false) { $this->connectionMethod = 'cURL'; if ($url === false) { $url = $this->url; } if ($headers === false) { $headers = $this->headers; } $headers[] = 'User-Agent: SofortLib-php/'.SOFORTLIB_VERSION.'-'.$this->connectionMethod; $process = curl_init($url); // curl_setopt($process, CURLOPT_HTTPHEADER, $headers); curl_setopt($process, CURLOPT_HTTPHEADER, array_merge($headers, array('Expect:'))); curl_setopt($process, CURLOPT_POST, 1); curl_setopt($process, CURLOPT_HEADER, false); if ($this->compression !== false) { curl_setopt($process, CURLOPT_ENCODING, $this->compression); } curl_setopt($process, CURLOPT_TIMEOUT, 15); if ($this->proxy) { curl_setopt($process, CURLOPT_PROXY, $this->proxy); } curl_setopt($process, CURLOPT_POSTFIELDS, $data); curl_setopt($process, CURLOPT_RETURNTRANSFER, 1); curl_setopt($process, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($process, CURLOPT_SSL_VERIFYPEER, false); $return = curl_exec($process); $this->info = curl_getinfo($process); $this->error = curl_error($process); $this->httpStatus = $this->info['http_code']; $this->_response = $return; curl_close($process); if ($this->error) { return $this->_xmlError('00'.$this->error, $this->_response); } return $return; } /** * * HTTP error handling * @return array(code, message, response[if available]) */ public function getHttpCode() { switch ($this->httpStatus) { case(200): return array('code' => 200, 'message' => $this->_xmlError($this->httpStatus, 'OK'), 'response' => $this->_response); break; case(301): case(302): return array('code' => $this->httpStatus, 'message' => $this->_xmlError($this->httpStatus, 'Redirected Request'), 'response' => $this->_response); break; case(401): $this->error = 'Unauthorized'; return array('code' => 401, 'message' => $this->_xmlError($this->httpStatus, 'Unauthorized'), 'response' => $this->_response); break; case(0): case(404): $this->httpStatus = 404; $this->error = 'URL not found '.$this->url; return array('code' => 404, 'message' => $this->_xmlError($this->httpStatus, 'URL not found '.$this->url), 'response' => ''); break; case(500): $this->error = 'An error occurred'; return array('code' => 500, 'message' => $this->_xmlError($this->httpStatus, 'An error occurred'), 'response' => $this->_response); break; default: return array('code' => $this->httpStatus, 'message' => $this->_xmlError($this->httpStatus, 'Something went wrong, not handled httpStatus'), 'response' => $this->_response); break; } } /** * * Getter for HTTP status code */ public function getHttpStatusCode() { $status = $this->getHttpCode(); return $status['code']; } /** * * Getter for HTTP status message */ public function getHttpStatusMessage() { $status = $this->getHttpCode(); return $status['message']; } /** * this is a fallback with fsockopen if curl is not activated * we still need openssl and ssl wrapper support (PHP >= 4.3.0) * @param string $data * @param string $url * @param array $headers * @return string body */ public function postSocket($data, $url = false, $headers = false) { $this->connectionMethod = 'Socket'; if ($url === false) { $url = $this->url; } if ($headers === false) { $headers = $this->headers; } $headers[] = 'User-Agent: SofortLib-php/'.SOFORTLIB_VERSION.'-'.$this->connectionMethod; $uri = parse_url($url); $out = 'POST '.$uri['path'].' HTTP/1.1'."\r\n"; $out .= 'HOST: '.$uri['host']."\r\n"; $out .= 'Connection: close'."\r\n"; $out .= 'Content-Length: '.strlen($data)."\r\n"; foreach ($headers as $header) { $out .= $header."\r\n"; } $out .= "\r\n".$data; //connect to webservice if (!$fp = fsockopen('ssl://'.$uri['host'], 443, $errno, $errstr, 15)) { $this->error = 'fsockopen() failed, enable ssl and curl: '.$errno.' '.$errstr; return false; } //send data stream_set_timeout($fp, 15); fwrite($fp, $out); //read response $return = ''; while (!feof($fp)) { $return .= fgets($fp, 512); } fclose($fp); //split header/body preg_match('#^(.+?)\r\n\r\n(.*)#ms', $return, $body); //get statuscode preg_match('#HTTP/1.*([0-9]{3}).*#i', $body[1], $status); $this->info['http_code'] = $status[1]; $this->httpStatus = $status[1]; return $body[2]; } /** * * Error method - format an error * @param string $error */ public function error($error) { echo '
cURL Error
'.$error.'
'; die; } /** * * Output an xml error * @param string $code * @param string $message */ private function _xmlError($code, $message) { return '0'.$code.''.$message.''; } } /// \endcond ?>sofort/library/sofortLib_notification.inc.php000066600000004553151373413000015526 0ustar00getNotification(); * * Copyright (c) 2012 SOFORT AG * * Released under the GNU General Public License (Version 2) * [http://www.gnu.org/licenses/gpl-2.0.html] * * $Date: 2012-11-23 17:15:47 +0100 (Fri, 23 Nov 2012) $ * @version SofortLib 1.5.4 $Id: sofortLib_notification.inc.php 5773 2012-11-23 16:15:47Z dehn $ * @author SOFORT AG http://www.sofort.com (integration@sofort.com) * */ class SofortLib_Notification extends SofortLib_Abstract { protected $_parameters = array(); protected $_response = array(); private $_transactionId = ''; private $_time; /** * Constructor for SofortLib_Notification */ public function __construct() { parent::__construct('', '', ''); } /** * reads the input and tries to read the transaction id * * @return array transactionid=>status */ public function getNotification($source = 'php://input') { $data = file_get_contents($source); //we don't really need a huge parser, simply extract the transaction-id if (!preg_match('#([0-9a-z-]+)#i', $data, $matches)) { $this->log(__CLASS__.' <- '.$data); $this->errors['error']['message'] = 'could not parse message'; return false; } $this->_transactionId = $matches[1]; $this->log(__CLASS__.' <- '.$data); preg_match('##i', $data, $matches); if (isset($matches[1])) { $this->_time = $matches[1]; } return $this->_transactionId; } /** * Sending a request is not possible * (non-PHPdoc) * @see SofortLib_Abstract::sendRequest() */ public function sendRequest() { trigger_error('sendRequest() not possible in this case', E_USER_NOTICE); } /** * * Getter for variable time */ public function getTime() { return $this->_time; } /** * * Getter for transaction */ public function getTransactionId() { return $this->_transactionId; } } ?>sofort/library/sofortLib_multipay.inc.php000066600000060413151373413000014701 0ustar00setSofortueberweisung(); //OR setSofortrechnung(), setSofortvorkasse() etc. * $objMultipay->set...($param); //set params for PNAG-API (watch API-documentation for needed params) * $objMultipay->add...($param); //add params for PNAG-API (watch API-documentation for needed params) * $errorsAndWarnings = $objMultipay->validateRequest(); //send param against the PNAG-API without setting an order * ... make own validation of $errorsAndWarnings and if ok ... * $objMultipay->sendRequest(); //set the order at PNAG * $errorsAndWarnings = $objMultipay->getErrors(); //should not occur, if validation was ok * ... make own validation of $errorsAndWarnings and if ok ... * ... finish order in the shopsystem * * Copyright (c) 2012 SOFORT AG * * Released under the GNU General Public License (Version 2) * [http://www.gnu.org/licenses/gpl-2.0.html] * * $Date: 2012-11-23 17:15:47 +0100 (Fri, 23 Nov 2012) $ * @version SofortLib 1.5.4 $Id: sofortLib_multipay.inc.php 5773 2012-11-23 16:15:47Z dehn $ * @author SOFORT AG http://www.sofort.com (integration@sofort.com) * */ class SofortLib_Multipay extends SofortLib_Abstract { protected $_parameters = array(); protected $_response = array(); protected $_xmlRootTag = 'multipay'; private $_paymentMethods = array(); private $_transactionId = ''; private $_paymentUrl = ''; /** * create a new payment object * @param string $apikey your API key * @param int $projectId your project id */ public function __construct($configKey = '') { list($userId, $projectId, $apiKey) = explode(':', $configKey); $apiUrl = (getenv('sofortApiUrl') != '') ? getenv('sofortApiUrl') : 'https://api.sofort.com/api/xml'; parent::__construct($userId, $apiKey, $apiUrl); $this->_parameters['project_id'] = $projectId; } /** * the language code will help in determing what language to * use when displaying the payment form, other data like * browser settings and ip will be used as well * * @param string $arg de|en|nl|fr ... * @return SofortLib_Multipay */ public function setLanguageCode($arg) { $this->_parameters['language_code'] = $arg; return $this; } /** * timeout how long this transaction configuration will be valid for * this is the time between the generation of the payment url and * the user completing the form, should be at least two to three minutes * defaults to unlimited if not set * * @param int $arg timeout in seconds * @return SofortLib_Multipay */ public function setTimeout($arg) { $this->_parameters['timeout'] = $arg; return $this; } /** * set the email address of the customer * this will be used for sofortvorkasse and sofortrechnung * * @param string $arg email address * @return SofortLib_Multipay */ public function setEmailCustomer($arg) { $this->_parameters['email_customer'] = $arg; return $this; } /** * set the phone number of the customer * * @param string $arg phone number * @return SofortLib_Multipay */ public function setPhoneNumberCustomer($arg) { $this->_parameters['phone_customer'] = $arg; return $this; } /** * add another variable this can be your internal order id or similar * * @param string $arg the contents of the variable * @return SofortLib_Multipay */ public function addUserVariable($arg) { $this->_parameters['user_variables']['user_variable'][] = $arg; return $this; } /** * set data of account * * @param string $bank_code bank code of bank * @param string $account_number account number * @param string $holder Name/Holder of this account * @return SofortLib_Multipay $this */ public function setSenderAccount($bankCode, $accountNumber, $holder) { $this->_parameters['sender'] = array( 'bank_code' => $bankCode, 'account_number' => $accountNumber, 'holder' => $holder, ); return $this; } /** * amount of this payment * * @param double $arg * @param string $currency currency of this transaction, default EUR * @return SofortLib_Multipay $this */ public function setAmount($arg, $currency = 'EUR') { $this->_parameters['amount'] = $arg; $this->_parameters['currency_code'] = $currency; return $this; } /** * set the reason values of this transfer * * @param string $arg max 27 characters * @param string $arg2 max 27 characters * @return SofortLib_Multipay $this */ public function setReason($arg, $arg2 = '') { $arg = preg_replace('#[^a-zA-Z0-9+-\.,]#', ' ', $arg); $arg = substr($arg, 0, 27); $arg2 = preg_replace('#[^a-zA-Z0-9+-\.,]#', ' ', $arg2); $arg2 = substr($arg2, 0, 27); $this->_parameters['reasons']['reason'][0] = $arg; $this->_parameters['reasons']['reason'][1] = $arg2; return $this; } /** * * Setter for redirecting the success link automatically * @param boolean $arg */ public function setSuccessLinkRedirect($arg) { $this->_parameters['success_link_redirect'] = $arg; } /** * the customer will be redirected to this url after a successful * transaction, this should be a page where a short confirmation is * displayed * * @param string $arg the url after a successful transaction * @return SofortLib_Multipay */ public function setSuccessUrl($successUrl, $redirect = true) { $this->_parameters['success_url'] = $successUrl; $this->setSuccessLinkRedirect($redirect); return $this; } /** * the customer will be redirected to this url if he uses the * abort link on the payment form, should redirect him back to * his cart or to the payment selection page * * @param string $arg url for aborting the transaction * @return SofortLib_Multipay */ public function setAbortUrl($arg) { $this->_parameters['abort_url'] = $arg; return $this; } /** * if the customer takes too much time or if your timeout is set too short * he will be redirected to this page * * @param string $arg url * @return SofortLib_Multipay */ public function setTimeoutUrl($arg) { $this->_parameters['timeout_url'] = $arg; return $this; } /** * set the url where you want notification about status changes * being sent to. Use SofortLib_Notification and SofortLib_TransactionData * to further process that notification * * @param string $arg url * @return SofortLib_Multipay */ public function setNotificationUrl($arg) { $this->_parameters['notification_urls']['notification_url'] = array($arg); return $this; } /** * you can set set multiple urls for receiving notifications * this might be helpfull if you have several systems for processing * an order (e.g. an ERP system) * * @param string $arg url * @return SofortLib_Multipay */ public function addNotificationUrl($arg) { $this->_parameters['notification_urls']['notification_url'][] = $arg; return $this; } /** * set the email address where you want notification about status changes * being sent to. * * @param string $arg email address * @return SofortLib_Multipay */ public function setNotificationEmail($arg) { $this->_parameters['notification_emails']['notification_email'] = array($arg); return $this; } /** * you can set set multiple emails for receiving notifications * * @param string $arg email * @return SofortLib_Multipay */ public function addNotificationEmail($arg) { $this->_parameters['notification_emails']['notification_email'][] = $arg; return $this; } /** * set the version of this payment module * this is helpfull so the support staff can easily * find out if someone uses an outdated module * * @param string $arg version string of your module * @return SofortLib_Multipay */ public function setVersion($arg) { $this->_parameters['interface_version'] = $arg; return $this; } /** * add sofortueberweisung as payment method * @param double $amount this amount only applies to this payment method * @return SofortLib_Multipay $this */ public function setSofortueberweisung($amount = '') { $this->_paymentMethods[] = 'su'; if (!array_key_exists('su', $this->_parameters) || !is_array($this->_parameters['su'])) { $this->_parameters['su'] = array(); } if (!empty($amount)) { $this->_parameters['su']['amount'] = $amount; } return $this; } /** * add sofortueberweisung as payment method * adds customer protection * @param double $amount this amount only applies to this payment method * @return SofortLib_Multipay $this */ public function setSofortueberweisungCustomerprotection($customerProtection = true) { $this->_paymentMethods[] = 'su'; if (!array_key_exists('su', $this->_parameters) || !is_array($this->_parameters['su'])) { $this->_parameters['su'] = array(); } $this->_parameters['su']['customer_protection'] = $customerProtection ? 1 : 0; return $this; } /** * add sofortlastschrift as payment method * @param double $amount this amount only applies to this payment method * @return SofortLib_Multipay $this */ public function setSofortlastschrift($amount = '') { $this->_paymentMethods[] = 'sl'; if (!array_key_exists('sl', $this->_parameters) || !is_array($this->_parameters['sl'])) { $this->_parameters['sl'] = array(); } if (!empty($amount)) { $this->_parameters['sl']['amount'] = $amount; } return $this; } /** * set the address of the customer for address validation, * this should be the invoice address of the customer * * @param string $firstname * @param string $lastname * @param string $street * @param string $streetNumber * @param string $zipcode * @param string $city * @param int $salutation [2|3] 2=Mr. 3=Mrs. * @param string $country country code, only DE allowed at the moment * @return SofortLib_Multipay $this */ public function setSofortlastschriftAddress($firstname, $lastname, $street, $streetNumber, $zipcode, $city, $salutation, $country = 'DE') { $this->_parameters['sl']['invoice_address']['salutation'] = $salutation; $this->_parameters['sl']['invoice_address']['firstname'] = $firstname; $this->_parameters['sl']['invoice_address']['lastname'] = $lastname; $this->_parameters['sl']['invoice_address']['street'] = $street; $this->_parameters['sl']['invoice_address']['street_number'] = $streetNumber; $this->_parameters['sl']['invoice_address']['zipcode'] = $zipcode; $this->_parameters['sl']['invoice_address']['city'] = $city; $this->_parameters['sl']['invoice_address']['country_code'] = $country; return $this; } /** * add lastschrift as payment method * @param double $amount this amount only applies to this payment method * @return SofortLib_Multipay $this */ public function setLastschrift($amount = '') { $this->_paymentMethods[] = 'ls'; if (!array_key_exists('ls', $this->_parameters) || !is_array($this->_parameters['ls'])) { $this->_parameters['ls'] = array(); } if (!empty($amount)) { $this->_parameters['ls']['amount'] = $amount; } return $this; } /** * * Setter for base checks disabled of Lastschrift */ public function setLastschriftBaseCheckDisabled() { $this->_parameters['ls']['base_check_disabled'] = 1; return $this; } /** * * Setter for extende checks disabled of Lastschrift */ public function setLastschriftExtendedCheckDisabled() { $this->_parameters['ls']['extended_check_disabled'] = 1; return $this; } /** * * Setter for mobile checks disabled of Lastschrift */ public function setLastschriftMobileCheckDisabled() { $this->_parameters['ls']['mobile_check_disabled'] = 1; return $this; } /** * set the address of the customer for address validation, * this should be the invoice address of the customer * * @param string $firstname * @param string $lastname * @param string $street * @param string $streetNumber * @param string $zipcode * @param string $city * @param int $salutation [2|3] 2=Mr. 3=Mrs. * @param string $country country code, only DE allowed at the moment * * @return SofortLib_Multipay object */ public function setLastschriftAddress($firstname, $lastname, $street, $streetNumber, $zipcode, $city, $salutation, $country = 'DE') { $this->_parameters['ls']['invoice_address']['salutation'] = $salutation; $this->_parameters['ls']['invoice_address']['firstname'] = $firstname; $this->_parameters['ls']['invoice_address']['lastname'] = $lastname; $this->_parameters['ls']['invoice_address']['street'] = $street; $this->_parameters['ls']['invoice_address']['street_number'] = $streetNumber; $this->_parameters['ls']['invoice_address']['zipcode'] = $zipcode; $this->_parameters['ls']['invoice_address']['city'] = $city; $this->_parameters['ls']['invoice_address']['country_code'] = $country; return $this; } /** * add sofortrechnung as payment method * if you use this payment method you have to provide * the customer address and cart as well * the total amount of this payment method will * be determined by the total of the cart * * @return SofortLib_Multipay object */ public function setSofortrechnung() { $this->_paymentMethods[] = 'sr'; if (!array_key_exists('sr', $this->_parameters) || !is_array($this->_parameters['sr'])) { $this->_parameters['sr'] = array(); } return $this; } /** * add sofortvorkasse as payment method * @param double $amount this amount only applies to this payment method * * @return SofortLib_Multipay objet */ public function setSofortvorkasse($amount = '') { $this->_paymentMethods[] = 'sv'; if (!array_key_exists('sv', $this->_parameters) || !is_array($this->_parameters['sv'])) { $this->_parameters['sv'] = array(); } if (!empty($amount)) { $this->_parameters['sv']['amount'] = $amount; } return $this; } /** * add sofortvorkasse as payment method * adds customer protection * @param double $amount this amount only applies to this payment method * @return SofortLib_Multipay $this */ public function setSofortvorkasseCustomerprotection($customerProtection = true) { $this->_paymentMethods[] = 'sv'; if (!array_key_exists('sv', $this->_parameters) || !is_array($this->_parameters['sv'])) { $this->_parameters['sv'] = array(); } $this->_parameters['sv']['customer_protection'] = $customerProtection ? 1 : 0; return $this; } /** * set the customer id which will appear on top of the invoice * @param int $arg * @return SofortLib_Multipay $this */ public function setSofortrechnungCustomerId($arg) { $this->_parameters['sr']['customer_id'] = $arg; return $this; } /** * set the order id which will appear on top of the invoice * @param int $arg * @return SofortLib_Multipay $this */ public function setSofortrechnungOrderId($arg) { $this->_parameters['sr']['order_id'] = $arg; return $this; } /** * set debitor vat number for invoice * @param string $vatNumber * @return SofortLib_Multipay $this */ public function setDebitorVatNumber($vatNumber) { $this->_parameters['sr']['debitor_vat_number'] = $vatNumber; return $this; } /** * set the invoice address of the customer * * @param string $firstname * @param string $lastname * @param string $street * @param string $streetNumber * @param string $zipcode * @param string $city * @param int $salutation [2|3] 2 = Mr. 3 = Mrs. * @param string $country country code, only DE allowed at the moment * @return SofortLib_Multipay $this */ public function setSofortrechnungInvoiceAddress($firstname, $lastname, $street, $streetNumber, $zipcode, $city, $salutation, $country = 'DE', $nameAdditive = '', $streetAdditive = '', $companyName = '') { $this->_parameters['sr']['invoice_address']['salutation'] = $salutation; $this->_parameters['sr']['invoice_address']['firstname'] = $firstname; $this->_parameters['sr']['invoice_address']['lastname'] = $lastname; $this->_parameters['sr']['invoice_address']['street'] = $street; $this->_parameters['sr']['invoice_address']['street_number'] = $streetNumber; $this->_parameters['sr']['invoice_address']['zipcode'] = $zipcode; $this->_parameters['sr']['invoice_address']['city'] = $city; $this->_parameters['sr']['invoice_address']['country_code'] = $country; $this->_parameters['sr']['invoice_address']['name_additive'] = $nameAdditive; $this->_parameters['sr']['invoice_address']['street_additive'] = $streetAdditive; $this->_parameters['sr']['invoice_address']['company'] = $companyName; return $this; } /** * set the shipping address of the customer * * @param string $firstname * @param string $lastname * @param string $street * @param string $streetNumber * @param string $zipcode * @param string $city * @param int $salutation [2|3] 1 = Mr. 2 = Mrs. * @param string $country country code, only DE allowed at the moment * @return SofortLib_Multipay $this */ public function setSofortrechnungShippingAddress($firstname, $lastname, $street, $streetNumber, $zipcode, $city, $salutation, $country = 'DE', $nameAdditive = '', $streetAdditive = '', $companyName = '') { $this->_parameters['sr']['shipping_address']['salutation'] = $salutation; $this->_parameters['sr']['shipping_address']['firstname'] = $firstname; $this->_parameters['sr']['shipping_address']['lastname'] = $lastname; $this->_parameters['sr']['shipping_address']['street'] = $street; $this->_parameters['sr']['shipping_address']['street_number'] = $streetNumber; $this->_parameters['sr']['shipping_address']['zipcode'] = $zipcode; $this->_parameters['sr']['shipping_address']['city'] = $city; $this->_parameters['sr']['shipping_address']['country_code'] = $country; $this->_parameters['sr']['shipping_address']['name_additive'] = $nameAdditive; $this->_parameters['sr']['shipping_address']['street_additive'] = $streetAdditive; $this->_parameters['sr']['shipping_address']['company'] = $companyName; return $this; } /** * add one item to the cart * * @param int $itemId unique item id * @param string $productNumber product number, EAN code, ISBN number or similar * @param string $title description of this title * @param double $unit_price gross price of one item * @param int $productType product type number see manual (0=other, 1=shipping, ...) * @param string $description additional description of this item * @param int $quantity default 1 * @param int $tax tax in percent, default 19 */ public function addSofortrechnungItem($itemId, $productNumber, $title, $unitPrice, $productType = 0, $description = '', $quantity = 1, $tax = 19) { $unitPrice = number_format($unitPrice, 2, '.', ''); $tax = number_format($tax, 2, '.', ''); $quantity = intval($quantity); if (empty($title)) { $this->setError('Title must not be empty. Title: '.$title.', Productnumber: '.$productNumber.', Unitprice: '.$unitPrice.', Quantity: '.$quantity.', Description: '.$description); } $this->_parameters['sr']['items']['item'][] = array( 'item_id' => $itemId, 'product_number' => $productNumber, 'product_type' => $productType, 'title' => $title, 'description' => $description, 'quantity' => $quantity, 'unit_price' => $unitPrice, 'tax' => $tax, ); } /** * * Setter for commenting Rechnung by sofort * @param string $comment */ public function setSofortrechungComment($comment) { $this->_parameters['sr']['items']['comment'] = $comment; } /** * Remove one item from cart * @param $itemId * @return boolean */ public function removeSofortrechnungItem($itemId) { $i = 0; foreach ($this->_parameters['sr']['items'] as $item) { if (isset($item['item_id']) && $item['item_id'] == $itemId) { unset($this->_parameters['sr']['items']['item'][$i]); return true; } $i++; } return false; } /** * Update one item in cart * @param $itemId * @param $quantity * @param $unit_price * @return boolean */ public function updateSofortrechnungItem($itemId, $quantity, $unitPrice) { $i = 0; foreach ($this->_parameters['sr']['items'] as $item) { if (isset($item[$i]['item_id']) && $item[$i]['item_id'] == $itemId) { $this->_parameters['sr']['items']['item'][$i]['quantity'] = $quantity; $this->_parameters['sr']['items']['item'][$i]['unit_price'] = $unitPrice; return true; } $i++; } return false; } /** * * Getter for invoice's item * @param int $itemId */ public function getSofortrechnungItemAmount($itemId) { $i = 0; foreach ($this->_parameters['sr']['items'] as $item) { if (isset($item['item_id']) && $item['item_id'] == $itemId) { return $this->_parameters['sr']['items']['item'][$i]['quantity'] * $this->_parameters['sr']['items']['item'][$i]['unit_price']; } $i++; } } /** * * Setter for invoice's time for payment * @param string $arg */ public function setSofortrechnungTimeForPayment($arg) { $this->_parameters['sr']['time_for_payment'] = $arg; return $this; } /** * makes a request against the pnag-API and returns all API-Fault/Warnings * it doesnt result in an order at pnag! * @return bool */ public function sendValidationRequest() { $this->_validateOnly = true; $this->sendRequest(); return isset($this->_response['validation']['status']['@data']) ? true : false; } /** * * Getter for invoice's item * @param int $itemId */ public function getSofortrechnungItem($itemId) { return $this->_parameters['sr']['items'][$itemId]; } /** * * Getter for all invoice's items */ public function getSofortrechnungItems() { return $this->_parameters['sr']['items']; } /** * after configuration and sending this request * you can use this function to redirect the customer * to the payment form * * @return string url of payment form */ public function getPaymentUrl() { $this->_paymentUrl = isset($this->_response['new_transaction']['payment_url']['@data']) ? $this->_response['new_transaction']['payment_url']['@data'] : false; return $this->_paymentUrl; } /** * * Getter for payment method * @param int $i */ public function getPaymentMethod($i = 0) { if ($i < 0 || $i >= count($this->_paymentMethods)) { return false; } return $this->_paymentMethods[$i]; } /** * * Is sofortüberweisung */ public function isSofortueberweisung() { return array_key_exists('su', $this->_parameters); } /** * * Is vorkasse by sofort */ public function isSofortvorkasse() { return array_key_exists('sv', $this->_parameters); } /** * * Check if it is a sofortlastschrift */ public function isSofortlastschrift() { return array_key_exists('sl', $this->_parameters); } /** * * Is lastschrift by sofort */ public function isLastschrift() { return array_key_exists('ls', $this->_parameters); } /** * * Is rechnung by sofort */ public function isSofortrechnung() { return array_key_exists('sr', $this->_parameters); } /** * * Check if consumer protection / customer protection enabled * @param string $product */ public function isConsumerProtection($product) { if (in_array($product, array('su', 'sv'))) { if(isset($this->_parameters[$product]['customer_protection'])) { return $this->_parameters[$product]['customer_protection']; } else { return false; } } else { return false; } } /** * * Check if debit pay check disabled * @param string $product * @param boolean $check */ public function isDebitpayCheckDisabled($product, $check) { if (in_array($product, array('ls', 'sl')) && in_array($check, array('base_check_disabled', 'extended_check_disabled', 'mobile_check_disabled'))) { return $this->_parameters[$product][$check]; } else { return false; } } /** * use this id to track the transaction * * @return string transaction id */ public function getTransactionId() { return $this->_transactionId; } /** * Parse the XML (override) * (non-PHPdoc) * @see SofortLib_Abstract::_parseXml() */ protected function _parseXml() { $this->_transactionId = isset($this->_response['new_transaction']['transaction']['@data']) ? $this->_response['new_transaction']['transaction']['@data'] : false; } } ?>sofort/library/sofortLib.php000066600000042627151373413000012214 0ustar00_userId = $userId; $this->_apiKey = $apiKey; $this->SofortLibHttp = new SofortLib_Http($apiUrl, $this->_getHeaders()); $this->SofortLibLogger = new SofortLibLogger(); $this->enableLogging = (getenv('sofortDebug') == 'true') ? true : false; } /** * Getter for warnings * * @return empty array if no warnings exists ELSE array with warning-codes and warning-messages * @public */ public function getWarnings($paymentMethod = 'all', $message = '') { if ($message == '') { $message = $this->warnings; } else { $message = $this->_parseErrorresponse($message); } $supportedPaymentMethods = $this->_products; if (!in_array($paymentMethod, $supportedPaymentMethods)) { $paymentMethod = 'all'; } $returnArray = array(); //return global + selected payment method foreach ($supportedPaymentMethods as $pm) { if (($paymentMethod == 'all' || $pm == 'global' || $paymentMethod == $pm) && array_key_exists($pm, $message)) { $returnArray = array_merge($returnArray, $message[$pm]); } } return $returnArray; } /** * Getter for errors * * @param (optional) array $message response array * @return emtpy array if no error exist ELSE array with error-codes and error-messages * @public */ public function getErrors($paymentMethod = 'all', $message = '') { if ($message == '') { $message = $this->handleErrors($this->errors); } else { $message = $this->_parseErrorresponse($message); } if (!$this->isError($paymentMethod, $message)) { return array(); } $supportedPaymentMethods = $this->_products; if (!in_array($paymentMethod, $supportedPaymentMethods)) { $paymentMethod = 'all'; } $returnArray = array(); //return global + selected payment method foreach ($supportedPaymentMethods as $pm) { if (($paymentMethod == 'all' || $pm == 'global' || $paymentMethod == $pm) && array_key_exists($pm, $message)) { $returnArray = array_merge($returnArray, $message[$pm]); } } return $returnArray; } /** * * Alter error array and set error message and error code together as one * @param array $errors */ function handleErrors($errors) { $errorKeys = array_keys($errors); foreach($errorKeys as $errorKey) { $i = 0; foreach ($errors[$errorKey] as $partialError) { if (!empty($errors[$errorKey][$i]['field']) && $errors[$errorKey][$i]['field'] !== '') { $errors[$errorKey][$i]['code'] .= '.'.$errors[$errorKey][$i]['field']; } $i++; }; } return $errors; } /** * returns one error message * @see getErrors() for more detailed errors * @param array $message response array * @return string errormessage ELSE false * @public */ public function getError($paymentMethod = 'all', $message = '') { if ($message == '') { $message = $this->errors; } else{ $message = $this->_parseErrorresponse($message); } $supportedPaymentMethods = $this->_products; if (!in_array($paymentMethod, $supportedPaymentMethods)) { $paymentMethod = 'all'; } if (is_array($message)) { if ($paymentMethod == 'all') { foreach ($message as $key => $error) { if (is_array($error) && !empty($error)){ return 'Error: '.$error[0]['code'].':'.$error[0]['message']; } } } else { foreach ($message as $key => $error) { if ($key != 'global' && $key != $paymentMethod) { continue; } if (is_array($error) && !empty($error)){ return 'Error: '.$error[0]['code'].':'.$error[0]['message']; } } } } return false; } /** * * checks (response)-array for warnings * @param array $message response array * @param string $paymentMethod - 'all', 'sr', 'su', 'sv', 'sa', 'ls', 'sl', 'sf' (if unknown then it uses "all") * @return boolean true if warnings found ELSE false * @public */ public function isWarning($paymentMethod = 'all', $message = '') { if ($message == '') { $message = $this->warnings; } if (empty($message)) { return false; } if (!in_array($paymentMethod, $this->_products)) { $paymentMethod = 'all'; } if ($paymentMethod == 'all') { if (is_array($message)) { foreach ($message as $error) { if (!empty($error)) { return true; } } } } else { //paymentMethod-specific search if (is_array($message)) { if ((isset($message[$paymentMethod]) && !empty($message[$paymentMethod])) || (isset($message['global']) && !empty($message['global']))) { return true; } } } return false; } /** * checks (response)-array for error * @param array $message response array * @param string $paymentMethod - 'all', 'sr', 'su', 'sv', 'sa', 'ls', 'sl', 'sf' (if unknown then it uses "all") * @return boolean true if errors found (in given payment-method or in 'global') ELSE false * @public */ public function isError($paymentMethod = 'all', $message = '') { if ($message == '') { $message = $this->errors; } if (empty($message)) { return false; } if (!in_array($paymentMethod, $this->_products)) { $paymentMethod = 'all'; } if ($paymentMethod == 'all') { if (is_array($message)) { foreach ($message as $error) { if (!empty($error)) { return true; } } } } else { //paymentMethod-specific search if (is_array($message)) { if ((isset($message[$paymentMethod]) && !empty($message[$paymentMethod])) || (isset($message['global']) && !empty($message['global']))) { return true; } } } return false; } /** * set Errors * later use getError(), getErrors() or isError() to retrieve them * @param string $message - Detailinformationen about the error * @param string $pos - Position in the errors-array, must be one of: 'global', 'sr', 'su', 'sv', 'sa', 'ls', 'sl', 'sf' * @param string $errorCode - a number or string to specify the errors in the module * @param string $field - if $errorCode deals with a field */ public function setError($message, $pos = 'global', $errorCode = '-1', $field = '') { $supportedErrorsPos = array('global', 'sr', 'su', 'sv', 'sa', 'ls', 'sl', 'sf'); if (!in_array($pos, $supportedErrorsPos)) { $paymentMethod = 'global'; } if (!isset($this->errors[$pos])) { $this->errors[$pos] = array(); } $error = array ('code' => $errorCode, 'message' => $message, 'field' => $field); $this->errors[$pos][] = $error; } /** * delete all warnings * @public */ public function deleteAllWarnings() { $this->errorPos = 'global'; $this->errorCountTemp = 0; $this->warnings = array(); } /** * delete all errors * @public */ public function deleteAllErrors() { $this->errorPos = 'global'; $this->errorCountTemp = 0; $this->errors = array(); } /** * internal send-method, will check http-errorcode and return body * @param String $message message to post * @return string error or body * @protected */ protected function _sendMessage($message) { $response = $this->SofortLibHttp->post($message); if ($response === false) { return $this->SofortLibHttp->error; } $http = $this->SofortLibHttp->getHttpCode(); if (!in_array($http['code'], array('200', '301', '302'))) { return $http['message']; } return $response; } /** * * define all headers here * @private */ private function _getHeaders() { $header = array(); $header[] = 'Authorization: Basic '.base64_encode($this->_userId.':'.$this->_apiKey); $header[] = 'Content-Type: application/xml; charset=UTF-8'; $header[] = 'Accept: application/xml; charset=UTF-8'; $header[] = 'X-Powered-By: PHP/'.phpversion(); return $header; } /** * * prepare $this->errors for insertion of errors * @private */ private function _createErrorArrayStructure() { if (!isset($this->errors[$this->errorPos])) { $this->errors[$this->errorPos] = array(); } if (!isset($this->errors[$this->errorPos][$this->errorCountTemp])) { $this->errors[$this->errorPos][$this->errorCountTemp] = array(); } } /** * * prepare $this->warnings for insertion of errors * @see _createErrorsarrayStructure(); * @private */ private function _createWarningArrayStructure() { if (!isset($this->warnings[$this->errorPos])) { $this->warnings[$this->errorPos] = array(); } if (!isset($this->warnings[$this->errorPos][$this->errorCountTemp])) { $this->warnings[$this->errorPos][$this->errorCountTemp] = array(); } } /** * display stacktrace * @private * @param $provideObject */ private function _backtrace($provideObject = false) { $last = ''; $file = __FILE__; $args = ''; $message = ''; foreach (debug_backtrace($provideObject) as $row) { if ($last != $row['file']) { $message .= "File: $file
\n"; } $last=$row['file']; $message .= ' Line: $row[line]: '; if ($row['class']!='') { $message .= '$row[class]$row[type]$row[function]'; } else { $message .= '$row[function]'; } $message .= '('; $message .= join('', '',$args); $message .= ")
\n"; } return $message; } /** * *Setter for an error * @public * @param string $message * @param boolean $fatal */ public function error($message, $fatal = false){ $errorArray = array('message' => 'Error: '.$message, 'code' => '10'); $this->errors['global'][] = $errorArray; } /** * * error while parsing xml * @public * @param unknown_type $message */ public function fatalError($message){ return $this->error($message, true); } /** * * Enable logging in object * @see SofortLib setLogEnabled * @deprecated * @public */ public function enableLog() { $this->enableLogging = true; return $this; } /** * * Disable logging in object * @see SofortLib setLogDisabled * @deprecated * @public */ public function disableLog() { $this->enableLogging = false; return $this; } /** * * Set logging enable * @uses enableLog(); * @public */ public function setLogEnabled() { $this->enableLogging = true; return $this; } /** * * Set logging disabled * @uses disableLog(); * @public */ public function setLogDisabled() { $this->enableLogging = false; return $this; } /** * * Set the SofortLibLogger object * @param object $SofortLibLogger * @public */ public function setLogger($SofortLibLogger) { $this->SofortLibLogger = $SofortLibLogger; } /** * * log the given string into warning_log.txt * use $this->enableLog(); to enable logging before! * @param string $message */ public function logWarning($message) { if ($this->enableLogging) { $uri = dirname(__FILE__).'/logs/warning_log.txt'; $this->SofortLibLogger->log($message, $uri); } } /** * * log the given string into error_log.txt * use $this->enableLog(); to enable logging before! * @param string $message */ public function logError($message) { if ($this->enableLogging) { $uri = dirname(__FILE__).'/logs/error_log.txt'; $this->SofortLibLogger->log($message, $uri); } } /** * * log the given string into log.txt * use $this->enableLog(); to enable logging before! * @param string $message */ public function log($message) { if ($this->enableLogging) { $uri = $this->_logfilePath ? $this->_logfilePath : dirname(__FILE__).'/logs/log.xml'; $this->SofortLibLogger->log($message, $uri); } } /** * * Set the path of the logfile * @param string $path */ public function setLogfilePath($path) { $this->_logfilePath = $path; } /** * sets the api version which should be used * @param float $version */ public function setApiVersion($version) { $this->_apiVersion = $version; } /** * * Handle Errors occurred */ protected function _handleErrors() { //handle errors if (isset($this->_response['errors']['error'])) { if (!isset($this->_response['errors']['error'][0])) { $tmp = $this->_response['errors']['error']; unset($this->_response['errors']['error']); $this->_response['errors']['error'][0] = $tmp; } foreach ($this->_response['errors']['error'] as $error) { $this->errors['global'][] = $this->_getErrorBlock($error); } } foreach ($this->_products as $product) { if (isset($this->_response['errors'][$product])) { if (!isset($this->_response['errors'][$product]['errors']['error'][0])) { $tmp = $this->_response['errors'][$product]['errors']['error']; unset($this->_response['errors'][$product]['errors']['error']); $this->_response['errors'][$product]['errors']['error'][0] = $tmp; } foreach ($this->_response['errors'][$product]['errors']['error'] as $error) { $this->errors[$product][] = $this->_getErrorBlock($error); } } } //handle warnings if (isset($this->_response['new_transaction']['warnings']['warning'])) { if (!isset($this->_response['new_transaction']['warnings']['warning'][0])) { $tmp = $this->_response['new_transaction']['warnings']['warning']; unset($this->_response['new_transaction']['warnings']['warning']); $this->_response['new_transaction']['warnings']['warning'][0] = $tmp; } foreach ($this->_response['new_transaction']['warnings']['warning'] as $warning) { $this->warnings['global'][] = $this->_getErrorBlock($warning); } } foreach ($this->_products as $product) { if (isset($this->_response['new_transaction']['warnings'][$product])) { if (!isset($this->_response['new_transaction']['warnings'][$product]['warnings']['warning'][0])) { $tmp = $this->_response['new_transaction']['warnings'][$product]['warnings']['warning']; unset($this->_response['new_transaction']['warnings'][$product]['warnings']['warning']); $this->_response['new_transaction']['warnings'][$product]['warnings']['warning'][0] = $tmp; } foreach ($this->_response['new_transaction']['warnings'][$product]['warnings']['warning'] as $warning) { $this->warnings[$product][] = $this->_getErrorBlock($warning); } } } } /** * * parse the XML received or being sent */ protected function _parseXml() {} /** * * Getter for error block * @param unknown_type $error */ protected function _getErrorBlock($error) { $newError['code'] = isset($error['code']['@data']) ? $error['code']['@data'] : ''; $newError['message'] = isset($error['message']['@data']) ? $error['message']['@data'] : ''; $newError['field'] = isset($error['field']['@data']) ? $error['field']['@data'] : ''; return $newError; } /** * * Static debug method * @param mixed $var * @param boolean $showHtml */ public static function debug($var = false, $showHtml = false) { echo "\n
\n";
		$var = print_r($var, true);
		
		if ($showHtml) {
			$var = str_replace('<', '<', str_replace('>', '>', $var));
		}
		
		echo $var . "\n
\n"; } } /// @endcond ?>sofort/library/sofortLib_Logger.inc.php000066600000003411151373413000014247 0ustar00logRotate($uri)) { $this->fp = fopen($uri, 'w'); fclose($this->fp); } $this->fp = fopen($uri, 'a'); fwrite($this->fp, '['.date('Y-m-d H:i:s').'] '.$message."\n"); fclose($this->fp); } /** * Copy the content of the logfile to a backup file if file size got too large * Put the old log file into a tarball for later reference * @param URI $uri */ public function logRotate($uri) { $date = date('Y-m-d_h-i-s', time()); if (file_exists($uri)) { if ($this->fp != null && filesize($uri) != false && filesize($uri) >= $this->maxFilesize) { $oldUri = $uri; // file ending $ending = $ext = pathinfo($oldUri, PATHINFO_EXTENSION); $newUri = dirname($oldUri).'/log_'.$date.'.'.$ending; rename($oldUri, $newUri); if (file_exists($oldUri)) { unlink($oldUri); } return true; } } return false; } } /// \endcond ?>sofort/library/sofortLib_edit_sr.inc.php000066600000013471151373413000014470 0ustar00confirmInvoice('1234-456-789654-31321')->sendRequest(); * * Copyright (c) 2012 SOFORT AG * * Released under the GNU General Public License (Version 2) * [http://www.gnu.org/licenses/gpl-2.0.html] * * $Date: 2012-05-21 16:53:26 +0200 (Mo, 21 Mai 2012) $ * @version SofortLib 1.5.4 $Id: sofortLib_edit_sr.inc.php 4191 2012-05-21 14:53:26Z niehoff $ * @author SOFORT AG http://www.sofort.com (integration@sofort.com) * */ class SofortLib_EditSr extends SofortLib_Abstract { protected $_apiVersion = '1.0'; protected $_parameters = array(); protected $_response = array(); protected $_xmlRootTag = 'edit_sr'; private $_file; /** * * Constructor for SofortLib_EditSr * @param String $apikey your API-key */ public function __construct($configKey = '') { list($userId, $projectId, $apiKey) = explode(':', $configKey); $apiUrl = (getenv('sofortApiUrl') != '') ? getenv('sofortApiUrl') : 'https://api.sofort.com/api/xml'; parent::__construct($userId, $apiKey, $apiUrl); } /** * * Setter for transaction * @param string $transaction * @param int $invoice */ public function setTransaction($transaction, $invoice = 0) { $this->_parameters['invoice'][$invoice]['transaction'] = $transaction; return $this; } /** * * Setter for invoice's number * @param string $invoiceNumber * @param int $invoice */ public function setInvoiceNumber($invoiceNumber, $invoice = 0) { $this->_parameters['invoice'][$invoice]['invoice_number'] = $invoiceNumber; return $this; } /** * * Setter for customer's number * @param string $customerNumber * @param int $invoice */ public function setCustomerNumber($customerNumber, $invoice = 0) { $this->_parameters['invoice'][$invoice]['customer_id'] = $customerNumber; return $this; } /** * * Setter for order's number * @param string $orderNumber * @param int $invoice */ public function setOrderNumber($orderNumber, $invoice = 0) { $this->_parameters['invoice'][$invoice]['order_id'] = $orderNumber; return $this; } /** * set a comment for refunds * just useable with api version 1.0 * @param string $arg */ public function setComment($comment, $invoice = 0) { $this->_parameters['invoice'][$invoice]['comment'] = $comment; return $this; } /** * add one item to the cart if you want to change the invoice * * @param string $itemId itemId * @param double $unit_price gross price of one item * @param int $quantity default 1 */ public function addItem($itemId, $productNumber, $productType, $title, $description, $quantity, $unitPrice, $tax, $invoice = 0) { $unitPrice = number_format($unitPrice, 2, '.', ''); $tax = number_format($tax, 2, '.', ''); $quantity = intval($quantity); $this->_parameters['invoice'][$invoice]['items']['item'][] = array( 'item_id' => $itemId, 'product_number' => $productNumber, 'product_type' => $productType, 'title' => $title, 'description' => $description, 'quantity' => $quantity, 'unit_price' => $unitPrice, 'tax' => $tax, ); } /** * * Update the invoice's cart via passing an array * @param array $cartItems * @param int $invoice */ function updateCart($cartItems = array(), $invoice = 0) { $i = 0; foreach ($cartItems as $cartItem) { $this->_parameters['invoice'][$invoice]['items']['item'][$i]['item_id'] = $cartItem['itemId']; $this->_parameters['invoice'][$invoice]['items']['item'][$i]['product_number'] = $cartItem['productNumber']; $this->_parameters['invoice'][$invoice]['items']['item'][$i]['title'] = $cartItem['title']; $this->_parameters['invoice'][$invoice]['items']['item'][$i]['description'] = $cartItem['description']; $this->_parameters['invoice'][$invoice]['items']['item'][$i]['quantity'] = $cartItem['quantity']; $this->_parameters['invoice'][$invoice]['items']['item'][$i]['unit_price'] = number_format($cartItem['unitPrice'], 2, '.', '') ; $this->_parameters['invoice'][$invoice]['items']['item'][$i]['tax'] = $cartItem['tax']; $i++; } } /** * after you you changed/confirmed an invoice you * can download the new invoice-pdf with this function * @return string url */ public function getInvoiceUrl() { return $this->_file; } /** * Parse the XML (override) * @see SofortLib_Abstract::_parseXml() */ protected function _parseXml() { $this->_file = isset($this->_response['invoice']['download_url']['@data']) ? $this->_response['invoice']['download_url']['@data'] : ''; } /** * Error handling (override) * @see SofortLib::_handleErrors() */ protected function _handleErrors() { if (!isset($this->_response['invoices']['invoice'][0])) { $tmp = $this->_response['invoices']['invoice']; unset($this->_response['invoices']['invoice']); $this->_response['invoices']['invoice'][0] = $tmp; } foreach ($this->_response['invoices']['invoice'] as $response) { //handle errors if (isset($response['errors']['error'])) { if (!isset($response['errors']['error'][0])) { $tmp = $response['errors']['error']; unset($response['errors']['error']); $response['errors']['error'][0] = $tmp; } foreach ($response['errors']['error'] as $error) { $this->errors['sr'][] = $this->_getErrorBlock($error); } } //handle warnings if (isset($response['warnings']['warning'])) { if (!isset($response['warnings']['warning'][0])) { $tmp = $response['warnings']['warning']; unset($response['warnings']['warning']); $response['warnings']['warning'][0] = $tmp; } foreach ($response['warnings']['warning'] as $error) { $this->warnings['sr'][] = $this->_getErrorBlock($error); } } } } } ?>sofort/library/index.html000066600000000057151373413000011524 0ustar00 sofort/library/sofortLib_classic_notification.inc.php000066600000011672151373413000017227 0ustar00_password = $password; $this->_userId = $userId; $this->_projectId = $projectId; $this->_hashFunction = strtolower($hashFunction); $this->_statusReason = false; } /** * * Get the Notification details * @param string $request (POST-Data) */ public function getNotification($request) { if (array_key_exists('status_reason', $request) && !empty($request['status_reason'])) { $this->_statusReason = $request['status_reason']; } if (array_key_exists('international_transaction', $request)) { //standard notification $fields = array( 'transaction', 'user_id', 'project_id', 'sender_holder', 'sender_account_number', 'sender_bank_code', 'sender_bank_name', 'sender_bank_bic', 'sender_iban', 'sender_country_id', 'recipient_holder', 'recipient_account_number', 'recipient_bank_code', 'recipient_bank_name', 'recipient_bank_bic', 'recipient_iban', 'recipient_country_id', 'international_transaction', 'amount', 'currency_id', 'reason_1', 'reason_2', 'security_criteria', 'user_variable_0', 'user_variable_1', 'user_variable_2', 'user_variable_3', 'user_variable_4', 'user_variable_5', 'created', ); } else { //ideal $fields = array( 'transaction', 'user_id', 'project_id', 'sender_holder', 'sender_account_number', 'sender_bank_name', 'sender_bank_bic', 'sender_iban', 'sender_country_id', 'recipient_holder', 'recipient_account_number', 'recipient_bank_code', 'recipient_bank_name', 'recipient_bank_bic', 'recipient_iban', 'recipient_country_id', 'amount', 'currency_id', 'reason_1', 'reason_2', 'user_variable_0', 'user_variable_1', 'user_variable_2', 'user_variable_3', 'user_variable_4', 'user_variable_5', 'created', ); } // http-notification with status if (array_key_exists('status', $request) && !empty($request['status'])) { array_push($fields, 'status', 'status_modified'); } $this->params = array(); foreach ($fields as $key) { $this->params[$key] = $request[$key]; } $this->params['project_password'] = $this->_password; $validationHash = $this->_getHashHexValue(implode('|', $this->params), $this->_hashFunction); $messageHash = $request['hash']; $this->_hashCheck = ($validationHash === $messageHash); return $this; } /** * * Check if error occurred * @return boolean */ public function isError() { if (!$this->_hashCheck) { return true; } return false; } /** * * Get error if occurred */ public function getError() { if (!$this->_hashCheck) { return 'hash-check failed'; } return false; } /** * * Getter for transactionId */ public function getTransaction() { return $this->params['transaction']; } /** * * Getter for amount * @return float */ public function getAmount() { return $this->params['amount']; } /** * Getter for user variables * @param int $i */ public function getUserVariable($i = 0) { return $this->params['user_variable_'.$i]; } /** * * Getter for currency * @return string */ public function getCurrency() { return $this->params['currency_id']; } /** * * Getter for time * return timestamp */ public function getTime() { return $this->params['created']; } /** * * Getter for status * @return string */ public function getStatus() { return $this->params['status']; } /** * * Getter for status reason * @return string */ public function getStatusReason() { return $this->_statusReason; } /** * Getter for Hash Hex Value * @param string $data string to be hashed * @return string the hash */ protected function _getHashHexValue($data, $hashFunction = 'sha1') { if ($hashFunction == 'sha1') { return sha1($data); } if ($hashFunction == 'md5') { return md5($data); } //mcrypt installed? if (function_exists('hash') && in_array($hashFunction, hash_algos())) { return hash($hashFunction, $data); } return false; } } ?>sofort/library/.htaccess000066600000000177151373413000011330 0ustar00 Order allow,deny Deny from all sofort/library/sofortLib_transaction_data.inc.php000066600000066021151373413000016354 0ustar00setTransaction('1234-456-789654-31321')->sendRequest(); * * echo $transactionDataObj->getStatus(); * * Copyright (c) 2012 SOFORT AG * * Released under the GNU General Public License (Version 2) * [http://www.gnu.org/licenses/gpl-2.0.html] * * $Date: 2013-04-29 13:22:26 +0200 (Mon, 29 Apr 2013) $ * @version SofortLib 1.5.4 $Id: sofortLib_transaction_data.inc.php 6103 2013-04-29 11:22:26Z dehn $ * @author SOFORT AG http://www.sofort.com (integration@sofort.com) * */ class SofortLib_TransactionData extends SofortLib_Abstract { protected $_parameters = array(); protected $_response = array(); protected $_xmlRootTag = 'transaction_request'; private $_count = 0; /** * * Constructor for SofortLib_TransactionData * @param string $configKey */ public function __construct($configKey = '') { list($userId, $projectId, $apiKey) = explode(':', $configKey); $apiUrl = (getenv('sofortApiUrl') != '') ? getenv('sofortApiUrl') : 'https://api.sofort.com/api/xml'; parent::__construct($userId, $apiKey, $apiUrl); return $this; } /** * use this function if you want to request * detailed information about a single transaction * * @param String $arg * @return SofortLib_TransactionData $this */ public function setTransaction($arg) { $this->_parameters['transaction'] = $arg; return $this; } /** * use this function if you want to request * detailed information about several transactions * at once * * @param String $arg * @return SofortLib_TransactionData $this */ public function addTransaction($arg) { if (is_array($arg)) { foreach($arg as $element) { $this->_parameters['transaction'][] = $element; } } else { $this->_parameters['transaction'][] = $arg; } return $this; } /** * you can request all transactions of a certain time * period * * use setNumber() to limit the results * * @param string $from date possible formats: 2011-01-25 or 2011-01-25T19:01:02+02:00 * @param string $to date possible formats: 2011-01-25 or 2011-01-25T19:01:02+02:00 * @return SofortLib_TransactionData $this * @see setNumber() */ public function setTime($from, $to) { $this->_parameters['from_time'] = $from; $this->_parameters['to_time'] = $to; return $this; } /** * you can limit the number of results * * @param int $number number of results [0-100] * @param int $page result page * @return SofortLib_TransactionData $this * @see setTime() */ public function setNumber($number, $page = '1') { $this->_parameters['number'] = $number; $this->_parameters['page'] = $page; return $this; } /** * returns the state of consumer_protection if set * @param int $i if you request multiple transactions at once you can set the number here * @return boolean */ public function getConsumerProtection($i = 0) { $paymentMethod = $this->getPaymentMethod($i); if (in_array($paymentMethod, array('su', 'sv'))) { if(isset($this->_response[$i][$paymentMethod]['consumer_protection']['@data'])) { return $this->_response[$i][$paymentMethod]['consumer_protection']['@data']; } else { return false; } } else { return false; } } /** * returns the InvoiceAddress * @param int $i if you request multiple transactions at once you can set the number here * @return array */ public function getInvoiceAddress($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } $invoiceAddress = array( 'firstname' => $this->_response[$i]['sr']['invoice_address']['firstname']['@data'], 'lastname' => $this->_response[$i]['sr']['invoice_address']['lastname']['@data'], 'name_additive' => $this->_response[$i]['sr']['invoice_address']['name_additive']['@data'], 'street' => $this->_response[$i]['sr']['invoice_address']['street']['@data'], 'street_number' => $this->_response[$i]['sr']['invoice_address']['street_number']['@data'], 'street_additive' => $this->_response[$i]['sr']['invoice_address']['street_additive']['@data'], 'zipcode' => $this->_response[$i]['sr']['invoice_address']['zipcode']['@data'], 'city' => $this->_response[$i]['sr']['invoice_address']['city']['@data'], 'country_code' => $this->_response[$i]['sr']['invoice_address']['country_code']['@data'], 'salutation' => !empty($this->_response[$i]['sr']['invoice_address']['salutation']['@data']) ? $this->_response[$i]['sr']['invoice_address']['salutation']['@data'] : '', 'company' => $this->_response[$i]['sr']['invoice_address']['company']['@data'], ); return $invoiceAddress; } /** * returns the ShippingAddress * @param int $i if you request multiple transactions at once you can set the number here * @return array */ public function getShippingAddress($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } $shippingAddress = array( 'firstname' => $this->_response[$i]['sr']['shipping_address']['firstname']['@data'], 'lastname' => $this->_response[$i]['sr']['shipping_address']['lastname']['@data'], 'name_additive' => $this->_response[$i]['sr']['shipping_address']['name_additive']['@data'], 'street' => $this->_response[$i]['sr']['shipping_address']['street']['@data'], 'street_number' => $this->_response[$i]['sr']['shipping_address']['street_number']['@data'], 'street_additive' => $this->_response[$i]['sr']['shipping_address']['street_additive']['@data'], 'zipcode' => $this->_response[$i]['sr']['shipping_address']['zipcode']['@data'], 'city' => $this->_response[$i]['sr']['shipping_address']['city']['@data'], 'country_code' => $this->_response[$i]['sr']['shipping_address']['country_code']['@data'], 'salutation' => !empty($this->_response[$i]['sr']['shipping_address']['salutation']['@data']) ? $this->_response[$i]['sr']['shipping_address']['salutation']['@data'] : '', 'company' => $this->_response[$i]['sr']['shipping_address']['company']['@data'], ); return $shippingAddress; } /** * returns the status of a transaction * @param int $i if you request multiple transactions at once you can set the number here * @return string pending|received|loss|refunded */ public function getStatus($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['status']['@data']; } /** * returns the detailed status description of a transaction * @param int $i if you request multiple transactions at once you can set the number here * @return string message */ public function getStatusReason($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['status_reason']['@data']; } /** * returns the time of the last status-change so you can check if sth. changed * @param int $i if you request multiple transactions at once you can set the number here * @return string time e.g. 2011-01-01T12:35:09+01:00 use strtotime() to convert it to unixtime */ public function getStatusModifiedTime($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['status_modified']['@data']; } /** * returns the language code of a transaction * @param int $i if you request multiple transactions at once you can set the number here * @return string language_code */ public function getLanguageCode($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['language_code']['@data']; } /** * returns the total amount of a transaction * @param int $i if you request multiple transactions at once you can set the number here * @return double amount */ public function getAmount($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['amount']['@data']; } /** * * Getter for order number * @param int $i */ public function getOrderNumber($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['sr']['shop_order_number']['@data']; } /** * refund, if a transaction was refundend. amount = amountRefunded if everything was refunded * @param int $i if you request multiple transactions at once you can set the number here * @return double amount */ public function getAmountRefunded($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['amount_refunded']['@data']; } /** * * Getter for the amounts received * @param int $i */ public function getAmountReceived($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['sv']['received_amount']['@data']; } /** * returns the currency of a transaction * @param int $i if you request multiple transactions at once you can set the number here * @return string EUR|USD|GBP.... */ public function getCurrency($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['currency_code']['@data']; } /** * returns the payment method of a transaction * @param int $i if you request multiple transactions at once you can set the number here * @return string su|sr|sl|sv|ls */ public function getPaymentMethod($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['payment_method']['@data']; } /** * returns the transaction id of a transaction * @param int $i if you request multiple transactions at once you can set the number here * @return string transaction id */ public function getTransaction($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['transaction']['@data']; } /** * * Returns an array containing all items of a transaction * @param int $i if you request multiple transactions at once you can set the number here * @ return array transactions items */ public function getItems($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } $items = array(); if (isset($this->_response[$i]['sr']['items']['item'][0])) { foreach ($this->_response[$i]['sr']['items']['item'] as $key => $item) { $items[$key]['item_id'] = $item['item_id']['@data']; $items[$key]['product_number'] = $item['product_number']['@data']; $items[$key]['product_type'] = $item['product_type']['@data']; $items[$key]['number_type'] = $item['number_type']['@data']; $items[$key]['title'] = $item['title']['@data']; $items[$key]['description'] = $item['description']['@data']; $items[$key]['quantity'] = $item['quantity']['@data']; $items[$key]['unit_price'] = $item['unit_price']['@data']; $items[$key]['tax'] = $item['tax']['@data']; } } return $items; } /** * * Returns an array containing reason of a transaction * @param int $i if you request multiple transactions at once you can set the number here * @ return array transaction reason */ public function getReason($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } $reasons[] = $this->_response[$i]['reasons']['reason'][0]['@data']; $reasons[] = $this->_response[$i]['reasons']['reason'][1]['@data']; return $reasons; } /** * returns the user variable of a transaction * @param int $n number of the variable * @param int $i if you request multiple transactions at once you can set the number here * @return string the content of this variable */ public function getUserVariable($n, $i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } if($n == 0 && !array_key_exists($n, $this->_response[$i]['user_variables']['user_variable'])) { return $this->_response[$i]['user_variables']['user_variable']['@data']; } return $this->_response[$i]['user_variables']['user_variable'][$n]['@data']; } /** * returns the time of a transaction * @param int $i if you request multiple transactions at once you can set the number here * @return string time e.g. 2011-01-01T12:35:09+01:00 use strtotime() to convert it to unixtime */ public function getTime($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['time']['@data']; } /** * returns the project id of a transaction * @param int $i if you request multiple transactions at once you can set the number here * @return int project id */ public function getProjectId($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['project_id']['@data']; } /** * you can request the url to the pdf of a sr-invoice with this function * @param int $i if you request multiple transactions at once you can set the number here * @return string url to the pdf */ public function getInvoiceUrl($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['sr']['invoice_url']['@data']; } /** * returns the status of an invoice * @param int $i if you request multiple transactions at once you can set the number here * @return string the status can be pending|received|reminder_1|reminder_2|reminder_3|encashment */ public function getInvoiceStatus($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['sr']['invoice_status']['@data']; } /** * returns the status of an invoice * @param int $i if you request multiple transactions at once you can set the number here * @return string the status can be pending|received|reminder_1|reminder_2|reminder_3|encashment */ public function getInvoiceObjection($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['sr']['invoice_objection']['@data']; } /** * checks if the transaction was a test * @param int $i if you request multiple transactions at once you can set the number here * @return bool true|false */ public function isTest($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['test']['@data']; } /** * * check if the transaction was a sofortueberweisung * @param int $i if you request multiple transactions at once you can set the number here * @return boolean true|false */ public function isSofortueberweisung($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['payment_method']['@data'] == 'su'; } /** * * check if the transaction was a sofortvorkasse * @param int $i if you request multiple transactions at once you can set the number here * @return boolean true|false */ public function isSofortvorkasse($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['payment_method']['@data'] == 'sv'; } /** * * check if the transaction was a sofortlastschrift * @param int $i if you request multiple transactions at once you can set the number here * @return boolean true|false */ public function isSofortlastschrift($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['payment_method']['@data'] == 'sl'; } /** * * check if the transaction was a lastschrift by sofort * @param int $i if you request multiple transactions at once you can set the number here * @return boolean true|false */ public function isLastschrift($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['payment_method']['@data'] == 'ls'; } /** * * check if the transaction was a sofortrechnung * @param int $i if you request multiple transactions at once you can set the number here * @return boolean true|false */ public function isSofortrechnung($i = 0) { if($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['payment_method']['@data'] == 'sr'; } /** * * check if status of transaction is received * @param int $i if you request multiple transactions at once you can set the number here * @return boolean true|false */ public function isReceived($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['status']['@data'] == 'received'; } /** * * check if status of transaction is loss * @param int $i if you request multiple transactions at once you can set the number here * @return boolean true|false */ public function isLoss($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['status']['@data'] == 'loss'; } /** * * check if status of transaction is pending * @param int $i if you request multiple transactions at once you can set the number here * @return boolean true|false */ public function isPending($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['status']['@data'] == 'pending'; } /** * * check if status of transaction is refunded * @param int $i if you request multiple transactions at once you can set the number here * @return boolean true|false */ public function isRefunded($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['status']['@data'] == 'refunded'; } /** * returns the holder of the receiving account * @param int $i if you request multiple transactions at once you can set the number here * @return string value */ public function getRecipientHolder($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['recipient']['holder']['@data']; } /** * * returns the account number of the receiving account * @param int $i if you request multiple transactions at once you can set the number here * @return string value */ public function getRecipientAccountNumber($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['recipient']['account_number']['@data']; } /** * * returns the bank code of the receiving account * @param int $i if you request multiple transactions at once you can set the number here * @return string value */ public function getRecipientBankCode($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['recipient']['bank_code']['@data']; } /** * * returns the country code of the receiving account * @param int $i if you request multiple transactions at once you can set the number here * @return string value */ public function getRecipientCountryCode($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['recipient']['country_code']['@data']; } /** * * returns the bank name of the receiving account * @param int $i if you request multiple transactions at once you can set the number here * @return string value */ public function getRecipientBankName($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['recipient']['bank_name']['@data']; } /** * * returns the BIC of the receiving account * @param int $i if you request multiple transactions at once you can set the number here * @return string value */ public function getRecipientBic($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['recipient']['bic']['@data']; } /** * * returns the IBAN of the receiving account * @param int $i if you request multiple transactions at once you can set the number here * @return string value */ public function getRecipientIban($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['recipient']['iban']['@data']; } /** * returns the holder of the sending account * @param int $i if you request multiple transactions at once you can set the number here * @return string value */ public function getSenderHolder($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['sender']['holder']['@data']; } /** * * returns the account number of the sending account * @param int $i if you request multiple transactions at once you can set the number here * @return string value */ public function getSenderAccountNumber($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['sender']['account_number']['@data']; } /** * * returns the bank code of the sending account * @param int $i if you request multiple transactions at once you can set the number here * @return string value */ public function getSenderBankCode($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['sender']['bank_code']['@data']; } /** * * returns the country code of the sending account * @param int $i if you request multiple transactions at once you can set the number here * @return string value */ public function getSenderCountryCode($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['sender']['country_code']['@data']; } /** * * returns the bank name of the sending account * @param int $i if you request multiple transactions at once you can set the number here * @return string value */ public function getSenderBankName($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['sender']['bank_name']['@data']; } /** * * returns the BIC of the sending account * @param int $i if you request multiple transactions at once you can set the number here * @return string value */ public function getSenderBic($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['sender']['bic']['@data']; } /** * * returns the IBAN of the sending account * @param int $i if you request multiple transactions at once you can set the number here * @return string value */ public function getSenderIban($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['sender']['iban']['@data']; } /** * returns the reason the customer needs to use when paying for "Rechnung by sofort" * @param int $n specify reason linenumber, can be 1 or 2; us 0 for an array with all reasons * @param int $i if you request multiple transactions at once you can set the number here * @return string|array reason */ public function getInvoiceReason($n = 0, $i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } if ($n == 1) { return $this->_response[$i]['sr']['reason_1']['@data']; } if ($n == 2) { return $this->_response[$i]['sr']['reason_2']['@data']; } return array($this->_response[$i]['sr']['reason_1']['@data'], $this->_response[$i]['sr']['reason_2']['@data']); } /** * get debitor text (Forderungsabtretung) * @param int $i if you request multiple transactions at once you can set the number here * @return string */ public function getInvoiceDebitorText($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['sr']['debitor_text']['@data']; } /** * * date of the invoice * @param int $i if you request multiple transactions at once you can set the number here * @return string */ public function getInvoiceDate($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['sr']['invoice_date']['@data']; } /** * * due date of the invoice, only available for confirmed invoices * @param int $i if you request multiple transactions at once you can set the number here * @return string */ public function getInvoiceDueDate($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['sr']['due_date']['@data']; } /** * * Getter for invoice number * @param int $i if you request multiple transactions at once you can set the number here * @return string */ public function getInvoiceNumber($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['sr']['invoice_number']['@data']; } /** * * invoice receiving bank account * @param int $i if you request multiple transactions at once you can set the number here * @return string */ public function getInvoiceBankHolder($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['sr']['recipient_bank_account']['holder']['@data']; } /** * * invoice receiving bank account * @param int $i if you request multiple transactions at once you can set the number here * @return string */ public function getInvoiceBankAccountNumber($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['sr']['recipient_bank_account']['account_number']['@data']; } /** * * invoice receiving bank account * @param int $i if you request multiple transactions at once you can set the number here * @return string */ public function getInvoiceBankCode($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['sr']['recipient_bank_account']['bank_code']['@data']; } /** * * invoice receiving bank account * @param int $i if you request multiple transactions at once you can set the number here * @return string */ public function getInvoiceBankName($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['sr']['recipient_bank_account']['bank_name']['@data']; } /** * get the invoice type * @param int $i if you request multiple transactions at once you can set the number here * @return string (OR or LS) */ public function getInvoiceType($i = 0) { if ($i < 0 || $i >= $this->_count) { return false; } return $this->_response[$i]['sr']['invoice_type']['@data']; } /** * * Getter for count */ public function getCount() { return $this->_count; } /** * Parse the XML (override) * (non-PHPdoc) * @see SofortLib_Abstract::_parseXml() */ protected function _parseXml() { if (isset($this->_response['transactions']['transaction_details'])) { $transactionFromXml = (isset($this->_response['transactions']['transaction_details'][0])) ? $this->_response['transactions']['transaction_details'] : $this->_response['transactions']; $this->_count = count($transactionFromXml); $transactions = array(); foreach ($transactionFromXml as $transaction) { if (!empty($transaction)) { if (isset($transaction['sr']['items']['item']) && !isset($transaction['sr']['items']['item'][0])) { $tmp = $transaction['sr']['items']['item']; unset($transaction['sr']['items']['item']); $transaction['sr']['items']['item'][] = $tmp; unset($tmp); } $transactions[] = $transaction; } } $this->_response = $transactions; $this->_count = count($transactions); } else { $this->_count = 0; } } } ?>sofort/library/sofortLib_sofortueberweisung_classic.php000066600000020370151373413000017725 0ustar00new SofortLib_SofortueberweisungClassic( $userid, $projectid, $password [, $hashfunction='sha1'] ); * $sofort->set...(); //set params for Hashcalculation * $sofort->set...(); //set more params for Hashcalculation * $sofort->getPaymentUrl(); * Notice: sometimes getPaymentUrl() must be overwritten by calling class because of changed hash-params * * * Copyright (c) 2012 SOFORT AG * * Released under the GNU General Public License (Version 2) * [http://www.gnu.org/licenses/gpl-2.0.html] * * $Date: 2012-11-23 17:15:47 +0100 (Fri, 23 Nov 2012) $ * @version SofortLib 1.5.4 $Id: sofortLib_sofortueberweisung_classic.php 5773 2012-11-23 16:15:47Z dehn $ * @author SOFORT AG http://www.sofort.com (integration@sofort.com) * */ class SofortLib_SofortueberweisungClassic { public $params = array(); protected $_password; protected $_userId; protected $_projectId; protected $_hashFunction; protected $_paymentUrl = 'https://www.sofort.com/payment/start'; protected $_hashFields = array( 'user_id', 'project_id', 'sender_holder', 'sender_account_number', 'sender_bank_code', 'sender_country_id', 'amount','currency_id', 'reason_1','reason_2', 'user_variable_0', 'user_variable_1', 'user_variable_2', 'user_variable_3', 'user_variable_4', 'user_variable_5', ); /** * * Constructor for SofortLib_SofortueberweisungClassic * @param int $userId * @param int $projectId * @param string $password * @param string $hashFunction * @param string $paymentUrl */ public function __construct($userId, $projectId, $password, $hashFunction = 'sha1', $paymentUrl = null) { $this->_password = $password; $this->_userId = $this->params['user_id'] = $userId; $this->_projectId = $this->params['project_id'] = $projectId; $this->_hashFunction = strtolower($hashFunction); $this->params['encoding'] = 'UTF-8'; if ($paymentUrl) $this->_paymentUrl = $paymentUrl; $this->_paymentUrl = $this->_getPaymentDomain(); } /** * * Setter for amount * @param float $arg * @param string $currency */ public function setAmount($arg, $currency = 'EUR') { $this->params['amount'] = $arg; $this->params['currency_id'] = $currency; } /** * * Setter for sender and holder * @param unknown_type $senderHolder */ public function setSenderHolder($senderHolder) { $this->params['sender_holder'] = $senderHolder; } /** * * Setter for sender's account number * @param string $senderAccountNumber */ public function setSenderAccountNumber($senderAccountNumber) { $this->params['sender_account_number'] = $senderAccountNumber; } /** * * Set the reason (Verwendungszweck) for sending money * @param string $arg * @param string $arg2 */ public function setReason($arg, $arg2 = '') { $this->params['reason_1'] = preg_replace('#[^a-zA-Z0-9+-\.,]#', ' ', $arg); $this->params['reason_2'] = preg_replace('#[^a-zA-Z0-9+-\.,]#', ' ', $arg2); return $this; } /** * * User variables can be added here * @param string $arg */ public function addUserVariable($arg) { $i = 0; while ($i < 6) { if (array_key_exists('user_variable_'.$i, $this->params)) { $i++; } else { break; } } $this->params['user_variable_'.$i] = $arg; return $this; } /** * the customer will be redirected to this url after a successful * transaction, this should be a page where a short confirmation is * displayed * * @param string $arg the url after a successful transaction * @return SofortLib_Multipay */ public function setSuccessUrl($arg) { $this->params['user_variable_3'] = $arg; return $this; } /** * the customer will be redirected to this url if he uses the * abort link on the payment form, should redirect him back to * his cart or to the payment selection page * * @param string $arg url for aborting the transaction * @return SofortLib_Multipay */ public function setAbortUrl($arg) { $this->params['user_variable_4'] = $arg; return $this; } /** * set the url where you want notification about status changes * being sent to. Use SofortLib_Notification and SofortLib_TransactionData * to further process that notification * * @param string $arg url * @return SofortLib_Multipay */ public function setNotificationUrl($arg) { $this->params['user_variable_5'] = $arg; return $this; } /** * * Setter for interface version * @param string $arg */ public function setVersion($arg) { $this->params['interface_version'] = $arg; return $this; } /** * * Getter for payment URL */ public function getPaymentUrl() { //fields required for hash $hashFields = $this->_hashFields; //build parameter-string for hashing $hashString = ''; foreach ($hashFields as $value) { if (array_key_exists($value, $this->params)) { $hashString .= $this->params[$value]; } $hashString .= '|'; } $hashString .= $this->_password; //calculate hash $hash = $this->getHashHexValue($hashString, $this->_hashFunction); $this->params['hash'] = $hash; //create parameter string $paramString = ''; foreach ($this->params as $key => $value) { $paramString .= $key.'='.urlencode($value).'&'; } $paramString = substr($paramString, 0, -1); //remove last & return $this->_paymentUrl.'?'.$paramString; } /** * * Has an error occurred */ public function isError() { return false; } /** * * Getter for error occurred */ public function getError() { return false; } /** * Get the hash value * @param string $data string to be hashed * @return string the hash */ public function getHashHexValue($data, $hashFunction = 'sha1') { if($hashFunction == 'sha1') { return sha1($data); } if($hashFunction == 'md5') { return md5($data); } //mcrypt installed? if (function_exists('hash') && in_array($hashFunction, hash_algos())) { return hash($hashFunction, $data); } return false; } /** * * Generate a password * @param int [optional] $length length of return value, default 24 * @return string */ public static function generatePassword($length = 24) { $password = ''; //we generate about 5-34 random characters [A-Za-z0-9] in every loop do { $randomBytes = ''; $strong = false; if (function_exists('openssl_random_pseudo_bytes')) { //php >= 5.3 $randomBytes = openssl_random_pseudo_bytes(32, $strong);//get 256bit } if (!$strong) { //fallback $randomBytes = pack('I*', mt_rand()); //get 32bit (pseudo-random) } //convert bytes to base64 and remove special chars $password .= preg_replace('#[^A-Za-z0-9]#', '', base64_encode($randomBytes)); } while (strlen($password) < $length); return substr($password, 0, $length); } /** * checks wich hash algorithms are supported by the server * and returns the best one * * @return sha512|sha256|sha1|md5|empty string */ public function getSupportedHashAlgorithm() { $algorithms = $this->getSupportedHashAlgorithms(); if(is_array($algorithms)) { return $algorithms[0]; } else { return ''; //no hash function found } } /** * checks wich hash algorithms are supported by the server * * @return array with all supported algorithms, preferred as first one (index 0) */ public function getSupportedHashAlgorithms() { $algorithms = array(); if (function_exists('hash') && in_array('sha512', hash_algos())) { $algorithms[] = 'sha512'; } if(function_exists('hash') && in_array('sha256', hash_algos())) { $algorithms[] = 'sha256'; } if(function_exists('sha1')) { //deprecated $algorithms[] = 'sha1'; } if(function_exists('md5')) { //deprecated $algorithms[] = 'md5'; } return $algorithms; } /** * * Getter for payment domain */ protected function _getPaymentDomain() { return (getenv('sofortPaymentUrl') != '') ? getenv('sofortPaymentUrl') : $this->_paymentUrl; } } ?>sofort/library/logs/.htaccess000066600000000177151373413000012274 0ustar00 Order allow,deny Deny from all sofort/library/logs/index.html000066600000000037151373413000012466 0ustar00 sofort/library/logs/log.txt000066600000000000151373413000012001 0ustar00sofort/library/logs/log.xml000066600000004100151373413000011767 0ustar00 156252 71365-156252-51CCAA6F-F942 1 pending not_credited_yet 2013-06-27T23:11:34+02:00 su fr 1.00 0.00 EUR 83650107 Musterman, Petra 2345678902 88888888 Demo Bank PNAGDE00000 DE96888888882345678902 DE Testaccount SOFORT 9999999999 70011110 SOFORT Bank DEKTDE71002 DE71700111109999999999 DE 1.0000 0.00 EUR 1.0000 0 pending not_credited_yet sofort/library/sofortLib_abstract.inc.php000066600000004522151373413000014637 0ustar00_xmlRootTag] = $this->_parameters; $requestData = $this->_prepareRootTag($requestData); $xmlRequest = ArrayToXml::render($requestData); $this->_log($xmlRequest, ' XmlRequest -> '); $xmlResponse = $this->_sendMessage($xmlRequest); try { $this->_response = XmlToArray::render($xmlResponse); } catch (Exception $e) { $this->_response = array('errors' => array('error' => array('code' => array('@data' => '0999'), 'message' => array('@data' => $e->getMessage())))); } $this->_log($xmlResponse, ' XmlResponse <- '); $this->_handleErrors(); $this->_parseXml(); return $this; } /** * * Log XML with message * @param string $xml * @param string $message */ protected function _log($xml, $message) { $this->log(get_class($this).$message.$xml); } /** * * prepare the root tag * @param array $requestData */ private function _prepareRootTag($requestData) { if ($this->_apiVersion) { $requestData[$this->_xmlRootTag]['@attributes']['version'] = $this->_apiVersion; } if ($this->_validateOnly) { $requestData[$this->_xmlRootTag]['@attributes']['validate_only'] = 'yes'; } return $requestData; } } /// \endcond ?>sofort/library/sofortLib_cancel_sr.inc.php000066600000010304151373413000014760 0ustar00confirmInvoice('1234-456-789654-31321')->sendRequest(); * * Copyright (c) 2012 SOFORT AG * * Released under the GNU General Public License (Version 2) * [http://www.gnu.org/licenses/gpl-2.0.html] * * $Date: 2012-05-21 16:53:26 +0200 (Mo, 21 Mai 2012) $ * @version SofortLib 1.5.4 $Id: sofortLib_cancel_sr.inc.php 4191 2012-05-21 14:53:26Z niehoff $ * @author SOFORT AG http://www.sofort.com (integration@sofort.com) * */ class SofortLib_CancelSr extends SofortLib_Abstract { protected $_apiVersion = '1.0'; protected $_parameters = array(); protected $_response = array(); protected $_xmlRootTag = 'cancel_sr'; private $_file; /** * create new confirm object * * @param String $apikey your API-key */ public function __construct($configKey = '') { list($userId, $projectId, $apiKey) = explode(':', $configKey); $apiUrl = (getenv('sofortApiUrl') != '') ? getenv('sofortApiUrl') : 'https://api.sofort.com/api/xml'; parent::__construct($userId, $apiKey, $apiUrl); } /** * Set the transaction you want to confirm/change * @param String $transaction Transaction Id * @return SofortLib_ConfirmSr */ public function setTransaction($transaction, $invoice = 0) { $this->_parameters['invoice'][$invoice]['transaction'] = $transaction; return $this; } /** * set a comment for refunds * @param string $arg */ public function setComment($comment, $invoice = 0) { $this->_parameters['invoice'][$invoice]['comment'] = $comment; return $this; } /** * * Setter for credit note number * @param string $creditNoteNumber * @param int $invoice */ public function setCreditNoteNumber($creditNoteNumber, $invoice = 0) { $this->_parameters['invoice'][$invoice]['credit_note_number'] = $creditNoteNumber; return $this; } /** * cancel the invoice * @param string $transaction the transaction id * @return SofortLib_ConfirmSr */ public function cancelInvoice($transaction = '', $invoice = 0) { if (empty($transaction) && array_key_exists('transaction', $this->_parameters)) { $transaction = $this->_parameters['invoice'][$invoice]['transaction']; } if (!empty($transaction)) { $this->_parameters = NULL; $this->_parameters['invoice'][$invoice]['transaction'] = $transaction; $this->_parameters['invoice'][$invoice]['items'] = array(); } return $this; } /** * after you you changed/confirmed an invoice you * can download the new invoice-pdf with this function * @return string url */ public function getInvoiceUrl() { return $this->_file; } /** * Parse the XML (override) * (non-PHPdoc) * @see SofortLib_Abstract::_parseXml() */ protected function _parseXml() { $this->_file = isset($this->_response['invoice']['download_url']['@data']) ? $this->_response['invoice']['download_url']['@data'] : ''; } /** * Error handling (override) * (non-PHPdoc) * @see SofortLib::_handleErrors() */ protected function _handleErrors() { if (!isset($this->_response['invoices']['invoice'][0])) { $tmp = $this->_response['invoices']['invoice']; unset($this->_response['invoices']['invoice']); $this->_response['invoices']['invoice'][0] = $tmp; } foreach ($this->_response['invoices']['invoice'] as $response) { //handle errors if (isset($response['errors']['error'])) { if (!isset($response['errors']['error'][0])) { $tmp = $response['errors']['error']; unset($response['errors']['error']); $response['errors']['error'][0] = $tmp; } foreach ($response['errors']['error'] as $error) { $this->errors['sr'][] = $this->_getErrorBlock($error); } } //handle warnings if (isset($response['warnings']['warning'])) { if (!isset($response['warnings']['warning'][0])) { $tmp = $response['warnings']['warning']; unset($response['warnings']['warning']); $response['warnings']['warning'][0] = $tmp; } foreach ($response['warnings']['warning'] as $error) { $this->warnings['sr'][] = $this->_getErrorBlock($error); } } } } } ?>sofort/library/sofortLib_confirm_sr.inc.php000066600000020351151373413000015173 0ustar00confirmInvoice('1234-456-789654-31321')->sendRequest(); * * Copyright (c) 2012 SOFORT AG * * Released under the GNU General Public License (Version 2) * [http://www.gnu.org/licenses/gpl-2.0.html] * * $Date: 2012-11-23 17:15:47 +0100 (Fri, 23 Nov 2012) $ * @version SofortLib 1.5.4 $Id: sofortLib_confirm_sr.inc.php 5773 2012-11-23 16:15:47Z dehn $ * @author SOFORT AG http://www.sofort.com (integration@sofort.com) * */ class SofortLib_ConfirmSr extends SofortLib_Abstract { protected $_parameters = array(); protected $_invoices = array(); protected $_response = array(); protected $_xmlRootTag = 'confirm_sr'; protected $_apiVersion = '2.0'; private $_file; /** * create new confirm object * * @param String $apikey your API-key */ public function __construct($configKey = '') { list($userId, $projectId, $apiKey) = explode(':', $configKey); $apiUrl = (getenv('sofortApiUrl') != '') ? getenv('sofortApiUrl') : 'https://api.sofort.com/api/xml'; parent::__construct($userId, $apiKey, $apiUrl); } /** * Set the transaction you want to confirm * @param String $transaction Transaction Id * @return SofortLib_ConfirmSr */ public function setTransaction($transaction, $invoice = 0) { if ($this->_apiVersion == 1) { $this->_parameters['transaction'] = $transaction; } else { $this->_parameters['invoice'][$invoice]['transaction'] = $transaction; } return $this; } /** * * Setter for invoice number * @param String $invoiceNumber * @param object $invoice */ public function setInvoiceNumber($invoiceNumber, $invoice = 0) { $this->setApiVersion('2.0'); $this->_parameters['invoice'][$invoice]['invoice_number'] = $invoiceNumber; return $this; } /** * * Setter for costumer numer * @param string $customerNumber * @param int $invoice */ public function setCustomerNumber($customerNumber, $invoice = 0) { $this->setApiVersion('2.0'); $this->_parameters['invoice'][$invoice]['customer_id'] = $customerNumber; return $this; } /** * * Setter for order number * @param string $orderNumber * @param unknown_type $invoice */ public function setOrderNumber($orderNumber, $invoice = 0) { $this->setApiVersion('2.0'); $this->_parameters['invoice'][$invoice]['order_id'] = $orderNumber; return $this; } /** * set a comment for refunds * just useable with api version 1.0 * @see SofortLib_EditSr * @deprecated * @param string $arg */ public function setComment($comment) { $this->setApiVersion('1.0'); $this->_parameters['comment'] = $comment; return $this; } /** * add one item to the cart if you want to change the invoice * just useable with api version 1.0 * @see SofortLib_EditSr * @deprecated * @param string $productNumber product number, EAN code, ISBN number or similar * @param string $title description of this title * @param double $unit_price gross price of one item * @param int $productType product type number see manual * @param string $description additional description of this item * @param int $quantity default 1 * @param int $tax tax in percent, default 19 */ public function addItem($itemId, $productNumber, $productType, $title, $description, $quantity, $unitPrice, $tax) { $this->setApiVersion('1.0'); $unitPrice = number_format($unitPrice, 2, '.', ''); $tax = number_format($tax, 2, '.', ''); $quantity = intval($quantity); $this->_parameters['items']['item'][] = array( 'item_id' => $itemId, 'product_number' => $productNumber, 'product_type' => $productType, 'title' => $title, 'description' => $description, 'quantity' => $quantity, 'unit_price' => $unitPrice, 'tax' => $tax, ); } /** * TODO: implement removal of items * @see SofortLib_EditSr * @deprecated * @param $productId * @param $quantity */ public function removeItem($productId, $quantity = 0) { $this->setApiVersion('1.0'); if (!isset($this->_parameters['items']['item'][$productId])) { return false; } elseif ($quantity = -1) { unset($this->_parameters['items']['item'][$productId]); return true; } //$this->_parameters['items']['item'][$productId]['quantity'] = $quantity; return true; } /** * * just useable with api version 1.0 * @see SofortLib_EditSr * @deprecated * @param array $cartItems */ function updateCart($cartItems = array()) { $this->setApiVersion('1.0'); if (empty($cartItems)) { $this->_parameters['items'] = array(); return $this; } $i = 0; foreach ($cartItems as $cartItem) { $this->_parameters['items']['item'][$i]['item_id'] = $cartItem['itemId']; $this->_parameters['items']['item'][$i]['product_number'] = $cartItem['productNumber']; $this->_parameters['items']['item'][$i]['title'] = $cartItem['title']; $this->_parameters['items']['item'][$i]['description'] = $cartItem['description']; $this->_parameters['items']['item'][$i]['quantity'] = $cartItem['quantity']; $this->_parameters['items']['item'][$i]['unit_price'] = number_format($cartItem['unitPrice'], 2, '.', '') ; $this->_parameters['items']['item'][$i]['tax'] = $cartItem['tax']; $i++; } return $this; } /** * cancel the invoice * just useable with api version 1.0 * @see SofortLib_EditSr * @deprecated * @param string $transaction the transaction id * @return SofortLib_ConfirmSr */ public function cancelInvoice($transaction = '') { $this->setApiVersion('1.0'); if (empty($transaction) && array_key_exists('transaction', $this->_parameters)) { $transaction = $this->_parameters['transaction']; } if (!empty($transaction)) { $this->_parameters = NULL; $this->_parameters['transaction'] = $transaction; $this->_parameters['items'] = array(); } return $this; } /** * confirm the invoice * @param string $transaction the transaction id * @return SofortLib_ConfirmSr */ public function confirmInvoice($transaction = '') { if ($this->_apiVersion == 1) { if (empty($transaction) && array_key_exists('transaction', $this->_parameters)) { $transaction = $this->_parameters['transaction']; } if (!empty($transaction)) { $this->_parameters = NULL; $this->_parameters['transaction'] = $transaction; } } else { if (!empty($transaction)) { $this->_parameters['invoice'][0]['transaction'] = $transaction; } } return $this; } /** * after you you changed/confirmed an invoice you * can download the new invoice-pdf with this function * @return string url */ public function getInvoiceUrl($i = 0) { return isset($this->_response['invoice'][$i]['download_url']['@data']) ? $this->_response['invoice'][$i]['download_url']['@data'] : ''; } /** * Parse the XML (override) * (non-PHPdoc) * @see SofortLib_Abstract::_parseXml() */ protected function _parseXml() {} /** * Handle errors if occurred * (non-PHPdoc) * @see SofortLib::_handleErrors() */ protected function _handleErrors() { if ($this->_apiVersion == 1) { return parent::_handleErrors(); } if (!isset($this->_response['invoices']['invoice'][0])) { $tmp = $this->_response['invoices']['invoice']; unset($this->_response['invoices']['invoice']); $this->_response['invoices']['invoice'][0] = $tmp; } foreach ($this->_response['invoices']['invoice'] as $response) { //handle errors if (isset($response['errors']['error'])) { if (!isset($response['errors']['error'][0])) { $tmp = $response['errors']['error']; unset($response['errors']['error']); $response['errors']['error'][0] = $tmp; } foreach ($response['errors']['error'] as $error) { $this->errors['sr'][] = $this->_getErrorBlock($error); } } //handle warnings if (isset($response['warnings']['warning'])) { if (!isset($response['warnings']['warning'][0])) { $tmp = $response['warnings']['warning']; unset($response['warnings']['warning']); $response['warnings']['warning'][0] = $tmp; } foreach ($response['warnings']['warning'] as $error) { $this->warnings['sr'][] = $this->_getErrorBlock($error); } } } } } ?>sofort/library/sofortLib_ideal_banks.inc.php000066600000003066151373413000015272 0ustar00_banks; } /** * Parse the xml (override) * (non-PHPdoc) * @see SofortLib_Abstract::_parseXml() */ protected function _parseXml() { if (isset($this->_response['ideal']['banks']['bank'][0]['code']['@data'])) { foreach($this->_response['ideal']['banks']['bank'] as $key => $bank) { $this->_banks[$key]['code'] = $bank['code']['@data']; $this->_banks[$key]['name'] = $bank['name']['@data']; } } } } ?>sofort/library/helper/xml_to_array.php000066600000017440151373413000014223 0ustar00 '€', ); /** * Loads XML into array representation. * @param string $input * @param int $maxDepth * @throws XmlToArrayException */ public function __construct($input, $maxDepth = 20) { if (!is_string($input)) throw new XmlToArrayException('No valid input.'); $this->_maxDepth = $maxDepth; $XMLParser = xml_parser_create(); xml_parser_set_option($XMLParser, XML_OPTION_SKIP_WHITE, false); xml_parser_set_option($XMLParser, XML_OPTION_CASE_FOLDING, false); xml_parser_set_option($XMLParser, XML_OPTION_TARGET_ENCODING, 'UTF-8'); xml_set_character_data_handler($XMLParser, array($this, '_contents')); xml_set_default_handler($XMLParser, array($this, '_default')); xml_set_element_handler($XMLParser, array($this, '_start'), array($this, '_end')); xml_set_external_entity_ref_handler($XMLParser, array($this, '_externalEntity')); xml_set_notation_decl_handler($XMLParser, array($this, '_notationDecl')); xml_set_processing_instruction_handler($XMLParser, array($this, '_processingInstruction')); xml_set_unparsed_entity_decl_handler($XMLParser, array($this, '_unparsedEntityDecl')); if (!xml_parse($XMLParser, $input, true)) { $errorCode = xml_get_error_code($XMLParser); $message = sprintf('%s. line: %d, char: %d'.($this->_tagStack ? ', tag: %s' : ''), xml_error_string($errorCode), xml_get_current_line_number($XMLParser), xml_get_current_column_number($XMLParser)+1, implode('->', $this->_tagStack)); xml_parser_free($XMLParser); throw new XmlToArrayException($message, $errorCode); } xml_parser_free($XMLParser); } /** * * Log messages (debugging purpose) * @param string $msg * @param int $type */ public function log($msg, $type = 2) { if (class_exists('Object')) { !($this->_Object instanceof Object) && $this->_Object = new Object(); return $this->_Object->log($msg, $type); } return false; } /** * Returns parsed XML as array structure * @return array */ public function toArray($simpleStructure = false) { return $this->_CurrentXmlToArrayNode->render($simpleStructure); } /** * Static entry point * @param string $input * @param bool $simpleStructure * @param int $maxDepth only parse XML to the provided depth * @return array * @throws XmlToArrayException */ public static function render($input, $simpleStructure = false, $maxDepth = 20) { $Instance = new XmlToArray($input, $maxDepth); return $Instance->toArray($simpleStructure); } /** * Handles cdata of the XML (user data between the tags) * @param resource $parser a resource handle of the XML parser * @param string $data */ private function _contents($parser, $data) { if (trim($data) !== '' && $this->_CurrentXmlToArrayNode instanceof XmlToArrayNode) $this->_CurrentXmlToArrayNode->setData($data); } /** * Default handler for all other XML sections not implemented as callback * @param resource $parser a resource handle of the XML parser * @param mixed $data * @throws XmlToArrayException */ private function _default($parser, $data) { $data = trim($data); if (in_array($data, get_html_translation_table(HTML_ENTITIES))) { $this->_CurrentXmlToArrayNode instanceof XmlToArrayNode && $this->_CurrentXmlToArrayNode->setData(html_entity_decode($data)); } elseif ($data && isset(self::$_htmlEntityExceptions[$data])) { $this->_CurrentXmlToArrayNode instanceof XmlToArrayNode && $this->_CurrentXmlToArrayNode->setData(self::$_htmlEntityExceptions[$data]); } elseif ($data && is_string($data) && strpos($data, ' sofort.php000066600000104730151373413000006577 0ustar00_loggable = TRUE; $this->tableFields = array_keys($this->getTableSQLFields()); $this->_tablepkey = 'id'; //virtuemart_sofort_id'; $this->_tableId = 'id'; //'virtuemart_sofort_id'; $varsToPush = array('payment_logos' => array('', 'char'), 'configuration_key' => array('', 'char'), 'buyer_protection' => array('', 'int'), 'payment_currency' => array('', 'int'), 'email_currency' => array('', 'int'), 'countries' => array('', 'char'), 'min_amount' => array('', 'float'), 'max_amount' => array('', 'float'), 'cost_per_transaction' => array('', 'char'), 'cost_percent_total' => array('', 'char'), 'tax_id' => array('', 'int'), 'status_pending' => array('', 'char'), 'status_received' => array('', 'char'), 'status_loss' => array('', 'char'), 'status_refunded' => array('', 'char'), 'debug' => array('', 'int'), ); $this->setConfigParameterable($this->_configTableFieldName, $varsToPush); } /** * @return string */ public function getVmPluginCreateTableSQL () { return $this->createTableSQL('Payment Sofort Table'); } /** * @return array */ function getTableSQLFields () { $SQLfields = array( 'id' => 'int(11) UNSIGNED NOT NULL AUTO_INCREMENT', 'virtuemart_order_id' => 'int(1) UNSIGNED', 'order_number' => 'char(64)', 'virtuemart_paymentmethod_id' => 'mediumint(1) UNSIGNED', 'payment_name' => 'varchar(1000)', 'payment_order_total' => 'decimal(15,5) NOT NULL', 'payment_currency' => 'smallint(1)', 'email_currency' => 'smallint(1)', 'cost_per_transaction' => 'decimal(10,2)', 'cost_percent_total' => 'decimal(10,2)', 'tax_id' => 'smallint(1)', 'sofort_custom' => 'varchar(255)', 'security' => 'varchar(50)', 'sofort_response_amount' => 'decimal(15,5) NOT NULL', 'sofort_response_currency' => 'varchar(50)', 'sofort_response_status' => 'varchar(50)', 'sofort_response_status_reason' => 'varchar(50)', 'sofort_response_transaction' => 'varchar(100)', 'sofort_response_invoice' => 'varchar(1000)' ); return $SQLfields; } /** * @param $cart * @param $order * @return bool|null */ function plgVmConfirmedOrder ($cart, $order) { if (!($method = $this->getVmPluginMethod($order['details']['BT']->virtuemart_paymentmethod_id))) { return NULL; // Another method was selected, do nothing } if (!$this->selectedThisElement($method->payment_element)) { return FALSE; } $this->sendTransactionRequest($method,$cart, $order); } function displayErrors ($errors) { foreach ($errors as $error) { vmError(JText::sprintf('VMPAYMENT_SOFORT_ERROR_FROM', $error ['message'], $error ['field'], $error ['code'])); vmInfo(JText::sprintf('VMPAYMENT_SOFORT_ERROR_FROM', $error ['message'], $error ['field'], $error ['code'])); if ($error ['message'] == 401) { vmdebug('check you payment parameters: custom_id, project_id, api key'); } } } function sendTransactionRequest ($method, $cart, $order, $doRedirect = true) { $session = JFactory::getSession(); $return_context = $session->getId(); //$this->_debug = $method->debug; //$this->logInfo('plgVmConfirmedOrder order number: ' . $order['details']['BT']->order_number, 'message'); vmdebug('SOFORT sendTransactionRequest'); if (!class_exists('VirtueMartModelOrders')) { require(JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php'); } if (!class_exists('VirtueMartModelCurrency')) { require(JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'currency.php'); } if (!class_exists ('CurrencyDisplay')) { require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php'); } if (!class_exists('TableVendors')) { require(JPATH_VM_ADMINISTRATOR . DS . 'tables' . DS . 'vendors.php'); } $this->getPaymentCurrency($method); $email_currency = $this->getEmailCurrency($method); $currency_code_3 = shopFunctions::getCurrencyByID($method->payment_currency, 'currency_code_3'); $totalInPaymentCurrency = vmPSPlugin::getAmountInCurrency($order['details']['BT']->order_total,$method->payment_currency); $cd = CurrencyDisplay::getInstance($cart->pricesCurrency); // Prepare data that should be stored in the database $dbValues['order_number'] = $order['details']['BT']->order_number; $dbValues['payment_name'] = $this->renderPluginName($method, 'create_order'); $dbValues['virtuemart_paymentmethod_id'] = $cart->virtuemart_paymentmethod_id; $dbValues['cost_per_transaction'] = $method->cost_per_transaction; $dbValues['cost_percent_total'] = $method->cost_percent_total; $dbValues['payment_currency'] = $method->payment_currency; $dbValues['email_currency'] = $email_currency; $dbValues['payment_order_total'] = $totalInPaymentCurrency['value']; $dbValues['tax_id'] = $method->tax_id; $dbValues['sofort_custom'] = $return_context; $security = self::getSecurityKey(); $dbValues['security'] = $security; vmdebug('SOFORT sendTransactionRequest ... after storePSPluginInternalData', $security); if (!class_exists('SofortLib')) { require(JPATH_ROOT . DS . 'plugins' . DS . 'vmpayment' . DS . 'sofort' . DS . 'sofort' . DS . 'library' . DS . 'sofortLib.php'); } $sofort = new SofortLib_Multipay($method->configuration_key); $sofort->setVersion(self::RELEASE); $sofort->setAmount($totalInPaymentCurrency['value'], $currency_code_3); $sofort->setReason($order['details']['BT']->order_number); $sofort->setSuccessUrl(self::getSuccessUrl($order)); $sofort->setAbortUrl(self::getCancelUrl($order)); $sofort->setNotificationUrl(self::getNotificationUrl($security, $order['details']['BT']->order_number)); $sofort->setSofortueberweisung(); $sofort->setSofortueberweisungCustomerprotection($method->buyer_protection); $jlang = JFactory::getLanguage (); $lang = $jlang->getTag (); $langArray = explode ("-", $lang); $lang = strtolower ($langArray[1]); $sofort->setLanguageCode($lang); $sofort->sendRequest(); vmdebug('SOFORT sendTransactionRequest ... SofortLib_Multipay ... sendRequest()'); if ($sofort->isError()) { $errors = $sofort->getErrors(); vmdebug('SOFORT sendTransactionRequest ... SofortLib_Multipay ... getErrors()', $errors); $this->displayErrors($errors); // TODO redirect to cancel URL //return $cancel_url; return; } $url = $sofort->getPaymentUrl(); $dbValues['sofort_response_transaction'] = $sofort->getTransactionId(); vmdebug('storePSPluginInternalData', $dbValues); $this->storePSPluginInternalData($dbValues); if ($doRedirect) { $mainframe = JFactory::getApplication(); $mainframe->redirect($url); } } /** * @param $virtuemart_paymentmethod_id * @param $paymentCurrencyId * @return bool|null */ function plgVmgetPaymentCurrency ($virtuemart_paymentmethod_id, &$paymentCurrencyId) { if (!($method = $this->getVmPluginMethod($virtuemart_paymentmethod_id))) { return NULL; // Another method was selected, do nothing } if (!$this->selectedThisElement($method->payment_element)) { return FALSE; } $this->getPaymentCurrency($method); $paymentCurrencyId = $method->payment_currency; } /** * @param $virtuemart_paymentmethod_id * @param $paymentCurrencyId * @return bool|null */ function plgVmgetEmailCurrency ($virtuemart_paymentmethod_id, $virtuemart_order_id, &$emailCurrencyId) { if (!($method = $this->getVmPluginMethod($virtuemart_paymentmethod_id))) { return NULL; // Another method was selected, do nothing } if (!$this->selectedThisElement($method->payment_element)) { return FALSE; } if (!($payments = $this->getDatasByOrderId($virtuemart_order_id))) { // JError::raiseWarning(500, $db->getErrorMsg()); return ''; } //vmdebug('plgVmgetEmailCurrency', $payments); if (empty($payments[0]->email_currency)) { $vendorId = 1; //VirtueMartModelVendor::getLoggedVendor(); $db = JFactory::getDBO(); $q = 'SELECT `vendor_currency` FROM `#__virtuemart_vendors` WHERE `virtuemart_vendor_id`=' . $vendorId; $db->setQuery($q); $emailCurrencyId = $db->loadResult(); } else { $emailCurrencyId = $payments[0]->email_currency; } } /** * @param $html * @return bool|null|string */ function plgVmOnPaymentResponseReceived (&$html) { if (!class_exists('VirtueMartCart')) { require(JPATH_VM_SITE . DS . 'helpers' . DS . 'cart.php'); } if (!class_exists('shopFunctionsF')) { require(JPATH_VM_SITE . DS . 'helpers' . DS . 'shopfunctionsf.php'); } if (!class_exists('VirtueMartModelOrders')) { require(JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php'); } // the payment itself should send the parameter needed. $virtuemart_paymentmethod_id = JRequest::getInt('pm', 0); $order_number = JRequest::getString('on', 0); if (!($method = $this->getVmPluginMethod($virtuemart_paymentmethod_id))) { //vmdebug('plgVmOnPaymentResponseReceived NOT getVmPluginMethod'); return NULL; // Another method was selected, do nothing } if (!$this->selectedThisElement($method->payment_element)) { //vmdebug('SOFORT plgVmOnPaymentResponseReceived NOT selectedThisElement'); return NULL; } if (!($virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber($order_number))) { //vmdebug('SOFORT plgVmOnPaymentResponseReceived NOT getOrderIdByOrderNumber'); return NULL; } if (!($paymentTables = $this->getDatasByOrderId($virtuemart_order_id))) { // JError::raiseWarning(500, $db->getErrorMsg()); return ''; } $orderModel = VmModel::getModel('orders'); $order = $orderModel->getOrder($virtuemart_order_id); // may be we did not receive the notification // Thus the call of the success-URL should check, if the notification has already been arrived at the shop . //If this is not true, a transaction detail request (step 4) should be triggered with the call of the success-URL, if (count($paymentTables) == 1) { $cart = VirtueMartCart::getCart(); $this->sendTransactionRequest($method,$cart, $order, false); } $html = $this->_getPaymentResponseHtml($method, $order, $paymentTables); //We delete the old stuff // get the correct cart / session $cart = VirtueMartCart::getCart(); $cart->emptyCart(); return TRUE; } /** * @return bool|null */ function plgVmOnUserPaymentCancel () { $order_number = JRequest::getString('on', ''); $virtuemart_paymentmethod_id = JRequest::getInt('pm', ''); if (empty($order_number) or empty($virtuemart_paymentmethod_id) or !$this->selectedThisByMethodId($virtuemart_paymentmethod_id)) { vmdebug('plgVmOnUserPaymentCancel', $order_number, $virtuemart_paymentmethod_id); return NULL; } if (!class_exists('VirtueMartModelOrders')) { require(JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php'); } if (!($virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber($order_number))) { return NULL; } if (!($paymentTable = $this->getDataByOrderId($virtuemart_order_id))) { return NULL; } vmdebug('plgVmOnUserPaymentCancel', 'VMPAYMENT_SOFORT_PAYMENT_CANCELLED'); VmInfo(Jtext::_('VMPAYMENT_SOFORT_PAYMENT_CANCELLED')); $session = JFactory::getSession(); $return_context = $session->getId(); if (strcmp($paymentTable->sofort_custom, $return_context) === 0) { vmDebug('handlePaymentUserCancel'); $this->handlePaymentUserCancel($virtuemart_order_id); } else { vmDebug('Return context', $paymentTable->sofort_custom, $return_context); } return TRUE; } /* * plgVmOnPaymentNotification() - This event is fired by Offline Payment. It can be used to validate the payment data as entered by the user. * Return: * Parameters: * None * @author Valerie Isaksen */ /** * @return bool|null */ function plgVmOnPaymentNotification () { //$this->_debug = true; if (!class_exists('VirtueMartModelOrders')) { require(JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php'); } $order_number = JRequest::getString('on', ''); if (empty($order_number)) { return FALSE; } if (!($virtuemart_order_id = VirtueMartModelOrders::getOrderIdByOrderNumber($order_number))) { return FALSE; } if (!($payments = $this->getDatasByOrderId($virtuemart_order_id))) { return FALSE; } $this->logInfo('plgVmOnPaymentNotification OK ', 'message'); $method = $this->getVmPluginMethod($payments[0]->virtuemart_paymentmethod_id); if (!$this->selectedThisElement($method->payment_element)) { return FALSE; } if (!class_exists('SofortLib')) { require(JPATH_ROOT . DS . 'plugins' . DS . 'vmpayment' . DS . 'sofort' . DS . 'sofort' . DS . 'library' . DS . 'sofortLib.php'); } $sofortLib_Notification = new SofortLib_Notification(); $transactionId = $sofortLib_Notification->getNotification(); //no valid parameters/xml if (empty($transactionId) || $sofortLib_Notification->isError()) { $this->logInfo('plgVmOnPaymentNotification NO transaaction or $sofortLib_Notification is error \n', 'message'); return FALSE; } $this->logInfo('plgVmOnPaymentNotification transaction ' . $transactionId, 'message'); $sofortLib_TransactionData = new SofortLib_TransactionData($method->configuration_key); $sofortLib_TransactionData->setTransaction($transactionId)->sendRequest(); $this->logInfo('plgVmOnPaymentNotification setTransaction OK', 'message'); // check that secret , and order are identical $security = JRequest::getString('security', ''); if ($security != $payments[0]->security) { $this->logInfo('plgVmOnPaymentNotification SECURITY not the one expected GOT: ' . $security . ' stored: ' . $payments[0]->security, 'message'); $emailBody = "Hello,\n\nerror while receiving a SOFORT NOTIFICATION" . "\n"; $emailBody .= "for order number: " . $order_number . "\n"; $emailBody .= "security token received: " . $security . "\n"; $emailBody .= "security token expected: " . $payments[0]->security . "\n"; $this->sendEmailToVendorAndAdmins(JText::_('VMPAYMENT_SOFORT_ERROR_NOTIFICATION'), $emailBody); return false; } $paymentMethod = $sofortLib_TransactionData->getPaymentMethod(); if ($paymentMethod != self::SU_SOFORTBANKING) { // answer not expected $this->logInfo('plgVmOnPaymentNotification not the one one expected?' . $paymentMethod . ' ' . self::SU_SOFORTBANKING, 'message'); $emailBody = "Hello,\n\nerror while receiving a SOFORT NOTIFICATION" . "\n"; $emailBody .= "Payment method is " . $paymentMethod . " Should be SU \n"; $this->sendEmailToVendorAndAdmins(JText::_('VMPAYMENT_SOFORT_ERROR_NOTIFICATION'), $emailBody); return false; } $this->logInfo('plgVmOnPaymentNotification so', 'message'); $sofort_data['sofort_response_amount'] = $sofortLib_TransactionData->getAmount(); $sofort_data['sofort_response_currency'] = $sofortLib_TransactionData->getCurrency(); // check that the amount is the same if (!$this->_checkAmountAndCurrency($sofort_data, $payments)) { return false; } $modelOrder = VmModel::getModel('orders'); $order = array(); $status = 'status_' . $sofortLib_TransactionData->getStatus(); //$this->logInfo('plgVmOnPaymentNotification getStatus:' .$status. ' '.var_export($method, true) , 'message'); $order['customer_notified'] = true; $order['order_status'] = $method->$status; $order['comments'] = JText::_('VMPAYMENT_SOFORT_RESPONSE_STATUS_REASON_' . $sofortLib_TransactionData->getStatusReason()); $sofort_data['sofort_response_status_reason'] = $sofortLib_TransactionData->getStatusReason(); $sofort_data['sofort_response_transaction'] = $sofortLib_TransactionData->getTransaction(); $sofort_data['payment_name'] = str_replace(array('\t', '\n'), '', $this->renderPluginName($method)); $sofort_data['virtuemart_order_id'] = $payments[0]->virtuemart_order_id; $sofort_data['order_number'] = $payments[0]->order_number; $sofort_data['virtuemart_paymentmethod_id'] = $payments[0]->virtuemart_paymentmethod_id; $sofort_data['sofort_response_status'] = $sofortLib_TransactionData->getStatus();; $sofort_data['sofort_response_status_reason'] = $sofortLib_TransactionData->getStatusReason(); $this->logInfo('storePSPluginInternalData before storePSPluginInternalData ' . var_export($sofort_data, true), 'message'); $this->storePSPluginInternalData($sofort_data); $modelOrder->updateStatusForOneOrder($payments[0]->virtuemart_order_id, $order, TRUE); } function _checkAmountAndCurrency ($sofort_data, $payments) { $payment_currency_code_3 = shopFunctions::getCurrencyByID($payments[0]->payment_currency, 'currency_code_3'); if (($sofort_data['sofort_response_amount'] != $payments[0]->payment_order_total) or ($sofort_data['sofort_response_currency'] != $payment_currency_code_3)) { $this->logInfo('plgVmOnPaymentNotification _checkAmountAndCurrency' . $sofort_data['sofort_response_amount'] . ' ' . $payments[0]->payment_order_total, 'message'); $this->logInfo('plgVmOnPaymentNotification _checkAmountAndCurrency' . $sofort_data['sofort_response_currency'] . ' ' . $payment_currency_code_3, 'message'); $emailBody = "Hello,\n\nerror while receiving a SOFORT NOTIFICATION" . "\n"; $emailBody .= "for order number: " . $payments[0]->order_number . "\n"; $emailBody .= "Amount received: " . $sofort_data['sofort_response_amount'] . "\n"; $emailBody .= "Amount expected: " . $payments[0]->payment_order_total . "\n"; $emailBody .= "Currency received: " . $sofort_data['sofort_response_currency'] . "\n"; $emailBody .= "Currency expected: " . $payment_currency_code_3 . "\n"; $this->sendEmailToVendorAndAdmins(JText::_('VMPAYMENT_SOFORT_ERROR_NOTIFICATION'), $emailBody); return false; } return true; } /** * Display stored payment data for an order * @param int $virtuemart_order_id * @param int $payment_method_id * @see components/com_virtuemart/helpers/vmPSPlugin::plgVmOnShowOrderBEPayment() */ function plgVmOnShowOrderBEPayment ($virtuemart_order_id, $payment_method_id) { if (!$this->selectedThisByMethodId($payment_method_id)) { return NULL; // Another method was selected, do nothing } if (!($payments = $this->getDatasByOrderId($virtuemart_order_id))) { // JError::raiseWarning(500, $db->getErrorMsg()); return ''; } $html = '' . "\n"; $html .= $this->getHtmlHeaderBE(); $code = "sofort_response_"; $first = TRUE; foreach ($payments as $payment) { $html .= ''; // Now only the first entry has this data when creating the order if ($first) { $html .= $this->getHtmlRowBE('SOFORT_PAYMENT_NAME', $payment->payment_name); // keep that test to have it backwards compatible. Old version was deleting that column when receiving an IPN notification if ($payment->payment_order_total and $payment->payment_order_total != 0.00) { $html .= $this->getHtmlRowBE('SOFORT_PAYMENT_ORDER_TOTAL', $payment->payment_order_total . " " . shopFunctions::getCurrencyByID($payment->payment_currency, 'currency_code_3')); } if ($payment->email_currency and $payment->email_currency != 0) { $html .= $this->getHtmlRowBE('SOFORT_PAYMENT_EMAIL_CURRENCY', shopFunctions::getCurrencyByID($payment->email_currency, 'currency_code_3')); } if ($payment->email_currency and $payment->email_currency != 0) { $html .= $this->getHtmlRowBE('SOFORT_RESPONSE_TRANSACTION', $payment->sofort_response_transaction); } $first = FALSE; } else { foreach ($payment as $key => $value) { // only displays if there is a value or the value is different from 0.00 and the value if ($value) { if (substr($key, 0, strlen($code)) == $code) { $html .= $this->getHtmlRowBE($key, $value); } } } } } $html .= '
' . JText::_('COM_VIRTUEMART_DATE') . '' . $payment->created_on . '
' . "\n"; return $html; } /** * @param $method * @param $order * @return string */ function _getPaymentResponseHtml ($method, $order, $payments) { VmConfig::loadJLang('com_virtuemart_orders', TRUE); if (!class_exists('CurrencyDisplay') ) { require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php'); } if (!class_exists('VirtueMartCart')) { require(JPATH_VM_SITE . DS . 'helpers' . DS . 'cart.php'); } VmConfig::loadJLang('com_virtuemart_orders',TRUE); $totalInPaymentCurrency = vmPSPlugin::getAmountInCurrency($order['details']['BT']->order_total,$order['details']['BT']->order_currency); $cart = VirtueMartCart::getCart(); $currencyDisplay = CurrencyDisplay::getInstance($cart->pricesCurrency); $payment = end($payments); $pluginName = $this->renderPluginName($method, $where = 'post_payment'); $html = $this->renderByLayout('post_payment', array( 'order' => $order, 'paymentInfos' => $payment, 'pluginName' => $pluginName, 'displayTotalInPaymentCurrency' => $totalInPaymentCurrency['display'] )); //vmdebug('_getPaymentResponseHtml', $html,$pluginName,$paypalTable ); return $html; } /* * @param $method plugin * @param $where from where tis function is called */ protected function renderPluginName ($method, $where = 'checkout') { $display_logos = ""; $logos = $method->payment_logos; if (!empty($logos)) { $display_logos = $this->displayLogos($logos) . ' '; } $payment_name = $method->payment_name; $html = $this->renderByLayout('render_pluginname', array( 'where' => $where, 'logo' => $display_logos, 'payment_name' => $payment_name, 'payment_description' => $method->payment_desc, )); return $html; } /** * @param VirtueMartCart $cart * @param $method * @param $cart_prices * @return int */ /* function getCosts (VirtueMartCart $cart, $method, $cart_prices) { if (preg_match('/%$/', $method->cost_percent_total)) { $cost_percent_total = substr($method->cost_percent_total, 0, -1); } else { $cost_percent_total = $method->cost_percent_total; } return ($method->cost_per_transaction + ($cart_prices['salesPrice'] * $cost_percent_total * 0.01)); }*/ /** * Check if the payment conditions are fulfilled for this payment method * * @author: Valerie Isaksen * * @param $cart_prices: cart prices * @param $payment * @return true: if the conditions are fulfilled, false otherwise * */ protected function checkConditions ($cart, $method, $cart_prices) { $this->convert_condition_amount($method); $amount = $this->getCartAmount($cart_prices); $address = (($cart->ST == 0) ? $cart->BT : $cart->ST); $amount_cond = ($amount >= $method->min_amount AND $amount <= $method->max_amount OR ($method->min_amount <= $amount AND ($method->max_amount == 0))); $countries = array(); if (!empty($method->countries)) { if (!is_array($method->countries)) { $countries[0] = $method->countries; } else { $countries = $method->countries; } } // probably did not gave his BT:ST address if (!is_array($address)) { $address = array(); $address['virtuemart_country_id'] = 0; } if (!isset($address['virtuemart_country_id'])) { $address['virtuemart_country_id'] = 0; } if (in_array($address['virtuemart_country_id'], $countries) || count($countries) == 0) { if ($amount_cond) { return TRUE; } } return FALSE; } /** * We must reimplement this triggers for joomla 1.7 */ /** * Create the table for this plugin if it does not yet exist. * This functions checks if the called plugin is active one. * When yes it is calling the standard method to create the tables * * @author Valérie Isaksen * */ function plgVmOnStoreInstallPaymentPluginTable ($jplugin_id) { return $this->onStoreInstallPluginTable($jplugin_id); } /** * This event is fired after the payment method has been selected. It can be used to store * additional payment info in the cart. * * @author Valérie isaksen * * @param VirtueMartCart $cart: the actual cart * @return null if the payment was not selected, true if the data is valid, error message if the data is not vlaid * */ public function plgVmOnSelectCheckPayment (VirtueMartCart $cart, &$msg) { return $this->OnSelectCheck($cart); } /** * plgVmDisplayListFEPayment * This event is fired to display the pluginmethods in the cart (edit shipment/payment) for exampel * * @param object $cart Cart object * @param integer $selected ID of the method selected * @return boolean True on success, false on failures, null when this plugin was not selected. * On errors, JError::raiseWarning (or JError::raiseError) must be used to set a message. * * @author Valerie Isaksen */ public function plgVmDisplayListFEPayment (VirtueMartCart $cart, $selected = 0, &$htmlIn) { if ($this->getPluginMethods($cart->vendorId) === 0) { if (empty($this->_name)) { $app = JFactory::getApplication(); $app->enqueueMessage(JText::_('COM_VIRTUEMART_CART_NO_' . strtoupper($this->_psType))); return false; } else { return false; } } $htmla = array(); $html = ''; VmConfig::loadJLang('com_virtuemart'); $currency = CurrencyDisplay::getInstance(); foreach ($this->methods as $method) { if ($this->checkConditions($cart, $method, $cart->pricesUnformatted)) { $pricesUnformatted = $cart->pricesUnformatted; $methodSalesPrice = $this->calculateSalesPrice($cart, $method, $pricesUnformatted); $logo = $this->displayLogos($method->payment_logos); $logo_link = $this->getLogoLink(); $payment_cost = ''; if ($methodSalesPrice) { $payment_cost = $currency->priceDisplay($methodSalesPrice); } if ($selected == $method->virtuemart_paymentmethod_id) { $checked = 'checked="checked"'; } else { $checked = ''; } $html .= $this->renderByLayout('display_payment', array( 'plugin' => $method, 'checked' => $checked, 'payment_logo' => $logo, 'payment_logo_link' => $logo_link, 'payment_cost' => $payment_cost, )); $htmla[] = $html; } } if (!empty($htmla)) { $htmlIn[] = $htmla; } return true; } /** * displays the logos of a VirtueMart plugin * * @author Valerie Isaksen * @param array $logo_list * @return html with logos */ protected function getLogoLink () { $jlang = JFactory::getLanguage (); $lang = $jlang->getTag (); $langArray = explode ("-", $lang); $lang = strtolower ($langArray[1]); $listOfLangs=array('de','en','nl', 'pl', 'fr', 'it','es'); $linkLang='en'; if (in_array($lang,$listOfLangs)) { $linkLang=$lang; } $logoLink="https://images.sofort.com/".$linkLang."/su/landing.php"; return $logoLink; } /* * plgVmonSelectedCalculatePricePayment * Calculate the price (value, tax_id) of the selected method * It is called by the calculator * This function does NOT to be reimplemented. If not reimplemented, then the default values from this function are taken. * @author Valerie Isaksen * @cart: VirtueMartCart the current cart * @cart_prices: array the new cart prices * @return null if the method was not selected, false if the payment is not valid any more, true otherwise * * */ /** * @param VirtueMartCart $cart * @param array $cart_prices * @param $cart_prices_name * @return bool|null */ public function plgVmOnSelectedCalculatePricePayment (VirtueMartCart $cart, array &$cart_prices, &$cart_prices_name) { return $this->onSelectedCalculatePrice($cart, $cart_prices, $cart_prices_name); } /** * plgVmOnCheckAutomaticSelectedPayment * Checks how many plugins are available. If only one, the user will not have the choice. Enter edit_xxx page * The plugin must check first if it is the correct type * * @author Valerie Isaksen * @param VirtueMartCart cart: the cart object * @return null if no plugin was found, 0 if more then one plugin was found, virtuemart_xxx_id if only one plugin is found * */ function plgVmOnCheckAutomaticSelectedPayment (VirtueMartCart $cart, array $cart_prices = array(), &$paymentCounter) { return $this->onCheckAutomaticSelected($cart, $cart_prices, $paymentCounter); } /** * This method is fired when showing the order details in the frontend. * It displays the method-specific data. * * @param integer $order_id The order ID * @return mixed Null for methods that aren't active, text (HTML) otherwise * @author Valerie Isaksen */ public function plgVmOnShowOrderFEPayment ($virtuemart_order_id, $virtuemart_paymentmethod_id, &$payment_name) { if (!($this->selectedThisByMethodId($virtuemart_paymentmethod_id))) { return NULL; } $payments = $this->getDatasByOrderId($virtuemart_order_id); $nb = count($payments); $payment_name = $this->renderByLayout('order_fe', array( 'paymentInfos' => $payments[$nb - 1], 'paymentName' => $payments[0]->payment_name, )); } /** * This event is fired during the checkout process. It can be used to validate the * method data as entered by the user. * * @return boolean True when the data was valid, false otherwise. If the plugin is not activated, it should return null. public function plgVmOnCheckoutCheckDataPayment($psType, VirtueMartCart $cart) { return null; } */ /** * This method is fired when showing when printing an Order * It displays the the payment method-specific data. * * @param integer $order_number The order number * @param integer $method_id method used for this order * @return mixed Null when for payment methods that were not selected, text (HTML) otherwise * @author Valerie Isaksen */ function plgVmonShowOrderPrintPayment ($order_number, $method_id) { return $this->onShowOrderPrint($order_number, $method_id); } /** * Save updated order data to the method specific table * * @param array $_formData Form data * @return mixed, True on success, false on failures (the rest of the save-process will be * skipped!), or null when this method is not actived. public function plgVmOnUpdateOrderPayment( $_formData) { return null; } */ /** * Save updated orderline data to the method specific table * * @param array $_formData Form data * @return mixed, True on success, false on failures (the rest of the save-process will be * skipped!), or null when this method is not actived. public function plgVmOnUpdateOrderLine( $_formData) { return null; } */ /** * plgVmOnEditOrderLineBE * This method is fired when editing the order line details in the backend. * It can be used to add line specific package codes * * @param integer $_orderId The order ID * @param integer $_lineId * @return mixed Null for method that aren't active, text (HTML) otherwise public function plgVmOnEditOrderLineBE( $_orderId, $_lineId) { return null; } */ /** * This method is fired when showing the order details in the frontend, for every orderline. * It can be used to display line specific package codes, e.g. with a link to external tracking and * tracing systems * * @param integer $_orderId The order ID * @param integer $_lineId * @return mixed Null for method that aren't active, text (HTML) otherwise public function plgVmOnShowOrderLineFE( $_orderId, $_lineId) { return null; } */ function plgVmDeclarePluginParamsPayment ($name, $id, &$data) { return $this->declarePluginParams('payment', $name, $id, $data); } /** * @param $name * @param $id * @param $table * @return bool */ function plgVmSetOnTablePluginParamsPayment ($name, $id, &$table) { return $this->setOnTablePluginParams($name, $id, $table); } static function getSuccessUrl ($order) { return JURI::root()."index.php?option=com_virtuemart&view=pluginresponse&task=pluginresponsereceived&pm=" . $order['details']['BT']->virtuemart_paymentmethod_id . '&on=' . $order['details']['BT']->order_number . "&Itemid=" . JRequest::getInt('Itemid'). '&lang='.JRequest::getCmd('lang',''); ; } static function getCancelUrl ($order) { return JURI::root()."index.php?option=com_virtuemart&view=pluginresponse&task=pluginUserPaymentCancel&pm=" . $order['details']['BT']->virtuemart_paymentmethod_id . '&on=' . $order['details']['BT']->order_number . '&Itemid=' . JRequest::getInt('Itemid').'&lang='.JRequest::getCmd('lang',''); } static function getNotificationUrl ($security, $order_number) { return JURI::root() . "index.php?option=com_virtuemart&view=pluginresponse&task=pluginnotification&tmpl=component&&security=" . $security . "&on=" . $order_number .'&lang='.JRequest::getCmd('lang',''); } static function getSecurityKey () { if (!class_exists('SofortLib_SofortueberweisungClassic')) { require(JPATH_ROOT . DS . 'plugins' . DS . 'vmpayment' . DS . 'sofort' . DS . 'sofort' . DS . 'library' . DS . 'sofortLib_sofortueberweisung_classic.php'); } return SofortLib_SofortueberweisungClassic::generatePassword(); } } // No closing tag