uawdijnntqw1x1x1
IP : 216.73.216.231
Hostname : 213-108-241-110.cprapid.com
Kernel : Linux 213-108-241-110.cprapid.com 5.14.0-570.25.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jul 9 04:57:09 EDT 2025 x86_64
Disable Function : None :)
OS : Linux
PATH:
/
home
/
digilove
/
public_html
/
wp-includes
/
..
/
41423
/
sofort.tar
/
/
fields/getsofort.php000064400000005504152326032300010537 0ustar00<?php /** * @version $Id: getsofort.php 8500 2014-10-21 16:03:28Z alatak $ * * @author Valérie Isaksen * @package VirtueMart * @copyright Copyright (c) 2004 - 2012 VirtueMart Team. All rights reserved. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php * VirtueMart is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. */ defined('JPATH_BASE') or die(); jimport('joomla.form.formfield'); class JFormFieldGetSofort extends JFormField { /** * Element name * * @access protected * @var string */ var $type = 'getSofort'; function getInput() { $jlang = JFactory::getLanguage(); $lang = $jlang->getTag(); $langArray = explode("-", $lang); $lang = strtolower($langArray[1]); $getSofortLang = 'eng-DE'; if ($lang == 'de') { $getSofortLang = "ger-DE"; } // MOre information $getSofortLInk = "https://www.sofort.com/" . $getSofortLang . "/merchant/products/"; //$getSofortLInk="https://www.sofort.com/payment/users/register/688"; $html = '<a href="#" id="sofortmoreinfo_link" ">' . vmText::_('VMPAYMENT_SOFORT_READMORE') . '</a>'; $html .= '<div id="sofortmoreinfo_show_hide" >'; $js = ' jQuery(document).ready(function( $ ) { $("#sofortmoreinfo_show_hide").hide(); jQuery("#sofortmoreinfo_link").click( function() { if ( $("#sofortmoreinfo_show_hide").is(":visible") ) { $("#sofortmoreinfo_show_hide").hide("slow"); $("#sofortmoreinfo_link").html("' . addslashes(vmText::_('VMPAYMENT_SOFORT_READMORE')) . '"); } else { $("#sofortmoreinfo_show_hide").show("slow"); $("#sofortmoreinfo_link").html("' . addslashes(vmText::_('VMPAYMENT_SOFORT_HIDE')) . '"); } }); }); '; $doc = JFactory::getDocument(); $doc->addScriptDeclaration($js); $html .= '<iframe src="' . $getSofortLInk . '" scrolling="yes" style="x-overflow: none;" frameborder="0" height="500px" width="850px"></iframe>'; $html .= '</div>'; // Get Sofort // MOre information $getSofortLInk = "https://www.sofort.com/payment/users/register/688"; $html .= '<p style="margin-top: 20px;"><a target="_blank" href="' . $getSofortLInk . '" id="getsogort_link" class="signin-button-link">' . vmText::_('VMPAYMENT_SOFORT_REGISTERNOW') . '</a>'; if ($lang == 'de') { $manualLink = "https://www.sofort.com/integrationCenter-ger-DE/content/view/full/4947"; } else { $manualLink = "https://www.sofort.com/integrationCenter-eng-DE/content/view/full/4947"; } $html .= '<a target="_blank" href="' . $manualLink . '" id="getsogort_link" class="signin-button-link">' . vmText::_('VMPAYMENT_SOFORT_DOCUMENTATION') . '</a>'; $html .= '</p>'; return $html; } }library/helper/elements/sofort_element.php000064400000000621152326032300015034 0ustar00<?php /** * @author SOFORT AG (integration@sofort.com) * @link http://www.sofort.com/ * * Copyright (c) 2012 SOFORT AG * * Released under the GNU General Public License (Version 2) * [http://www.gnu.org/licenses/gpl-2.0.html] */ /** * * Implementation of a simple element * */ abstract class SofortElement { /** * * Render the element */ public abstract function render(); } ?>library/helper/elements/sofort_html_tag.php000064400000002273152326032300015207 0ustar00<?php /** * @author SOFORT AG (integration@sofort.com) * @link http://www.sofort.com/ * * Copyright (c) 2012 SOFORT AG * * Released under the GNU General Public License (Version 2) * [http://www.gnu.org/licenses/gpl-2.0.html] */ /** * * Implementation of an HTML Tag * */ class SofortHtmlTag extends SofortTag { private static $selfClosingTags = array('base', 'meta', 'link', 'hr', 'br', 'param', 'img', 'area', 'input', 'col'); /** * * Constructor for SofortHtmlTag * @param string $tagname * @param array $attributes * @param array $children */ public function __construct($tagname, array $attributes = array(), $children = array()) { $tagname = strtolower($tagname); $loweredAttributes = array(); foreach ($attributes as $key => $value) { $loweredAttributes[strtolower($key)] = $value; } parent::__construct($tagname, $loweredAttributes, $children); } /** * Renders the element (override) * @see SofortTag::_render() */ protected function _render($output, $attributes) { return in_array($this->tagname, self::$selfClosingTags) ? "<{$this->tagname}{$attributes} />" : "<{$this->tagname}{$attributes}>{$output}</{$this->tagname}>"; } } ?>library/helper/elements/sofort_tag.php000064400000002711152326032300014160 0ustar00<?php /** * @author SOFORT AG (integration@sofort.com) * @link http://www.sofort.com/ * * Copyright (c) 2012 SOFORT AG * * Released under the GNU General Public License (Version 2) * [http://www.gnu.org/licenses/gpl-2.0.html] */ /** * * Implementation of a simple tag * */ class SofortTag extends SofortElement { public $tagname = ''; public $attributes = array(); public $children = array(); /** * * Constructor for SofortTag * @param string $tagname * @param array $attributes * @param array $children */ public function __construct($tagname, array $attributes = array(), $children = array()) { $this->tagname = $tagname; $this->attributes = $attributes; $this->children = is_array($children) ? $children : array($children); } /** * Renders the element (override) * (non-PHPdoc) * @see SofortElement::render() */ public function render() { $output = ''; $attributes = ''; foreach ($this->children as $child) { $output .= is_object($child) ? $child->render() : $child; } foreach ($this->attributes as $key => $value) { $attributes .= " $key=\"$value\""; } return $this->_render($output, $attributes); } /** * * Render the output * @param string $output * @param string $attributes */ protected function _render($output, $attributes) { return $output !== '' ? "<{$this->tagname}{$attributes}>{$output}</{$this->tagname}>" : "<{$this->tagname}{$attributes} />"; } } ?>library/helper/elements/sofort_text.php000064400000001525152326032300014373 0ustar00<?php /** * @author SOFORT AG (integration@sofort.com) * @link http://www.sofort.com/ * * Copyright (c) 2012 SOFORT AG * * Released under the GNU General Public License (Version 2) * [http://www.gnu.org/licenses/gpl-2.0.html] */ /** * * Implementation of simple text * */ class SofortText extends SofortElement { public $text; public $escape = false; /** * * Constructor for SofortText * @param strng $text * @param boolean $escape * @param boolean $trim */ public function __construct($text, $escape = false, $trim = true) { $this->text = $trim ? trim($text) : $text; $this->escape = $escape; } /** * Renders the element (override) * (non-PHPdoc) * @see SofortElement::render() */ public function render() { return $this->escape ? vRequest::vmSpecialChars($this->text) : $this->text; } } ?>library/helper/array_to_xml.php000064400000013542152326032300012701 0ustar00<?php defined('_JEXEC') or die('Restricted access'); require_once('array_to_xml_exception.php'); /** * @author SOFORT AG (integration@sofort.com) * @link http://www.sofort.com/ * * Copyright (c) 2012 SOFORT AG * * Released under the GNU General Public License (Version 2) * [http://www.gnu.org/licenses/gpl-2.0.html] */ /** * * Array To XML conversion * */ class ArrayToXml { /** * Maximum allowed depth * @var int */ private $_maxDepth = 4; /** * Represents the parsed array structure * @var string */ private $_parsedData = null; /** * Loads array into XML representation. * @param array $input * @param int $maxDepth * @throws ArrayToXmlException */ public function __construct(array $input, $maxDepth = 10, $trim = true) { if ($maxDepth > 50) { throw new ArrayToXmlException('Max depth too high.'); } $this->_maxDepth = $maxDepth; if (count($input) == 1) { $tagName = key($input); $SofortTag = new SofortTag($tagName, $this->_extractAttributesSection($input[$tagName]), $this->_extractDataSection($input[$tagName], $trim)); $this->_render($input[$tagName], $SofortTag, 1, $trim); $this->_parsedData = $SofortTag->render(); } elseif(!$input) { $this->_parsedData = ''; } else { throw new ArrayToXmlException('No valid input.'); } } /** * Returns parsed array as XML structure * Pass both params as null to exclude prolog <?xml version="version" encoding="encoding" ?> * @param string $version * @param string $encoding */ public function toXml($version = '1.0', $encoding = 'UTF-8') { return !$version && !$encoding ? $this->_parsedData : "<?xml version=\"{$version}\" encoding=\"{$encoding}\" ?>\n{$this->_parsedData}"; } /** * static entry point. Options are: * - version: (default 1.0) version string to put in xml prolog * - encoding: (default UTF-8) use the specified encoding * - trim: (default true) Trim values * - depth: (default 10) Maximum depth to parse the given array, throws exception when exceeded * * @param array $input the input array * @param array $options set additional options to pass to XmlToArray * @throws ArrayToXmlException */ public static function render(array $input, array $options = array()) { $options = array_merge(array( 'version' => '1.0', 'encoding' => 'UTF-8', 'trim' => true, 'depth' => 10, ), $options ); $Instance = new ArrayToXml($input, $options['depth'], $options['trim']); return $Instance->toXml($options['version'], $options['encoding']); } /** * Checks if current depth is exceeded * @param int $currentDepth * @throws ArrayToXmlException if depth is exceeded */ private function _checkDepth($currentDepth) { if ($this->_maxDepth && $currentDepth > $this->_maxDepth) { throw new ArrayToXmlException("Max depth ({$this->_maxDepth}) exceeded"); } } /** * Creates a new XML node * @param string $name * @param array $attributes * @param array $children * @return Tag */ private function _createNode($name, array $attributes, array $children) { return new SofortTag($name, $attributes, $children); } /** * Creates a new text node * @param string $text * @param bool $trim * @return Text */ private function _createTextNode($text, $trim) { return new SofortText($text, true, $trim); } /** * Extracts the attributes section from a XmlToArray'd structure * @param mixed $node * @return array */ private function _extractAttributesSection(&$node) { $attributes = array(); if (is_array($node) && isset($node['@attributes']) && $node['@attributes']) { $attributes = is_array($node['@attributes']) ? $node['@attributes'] : array($node['@attributes']); unset($node['@attributes']); } elseif (is_array($node) && isset($node['@attributes'])) { unset($node['@attributes']); } return $attributes; } /** * Extracts the data section from a XmlToArray'd structure * @param mixed $node * @return array */ private function _extractDataSection(&$node, $trim) { $children = array(); if (is_array($node) && isset($node['@data']) && $node['@data']) { $children = array($this->_createTextNode($node['@data'], $trim)); unset($node['@data']); } elseif (is_array($node) && isset($node['@data'])) { unset($node['@data']); } return $children; } /** * Recursivly renders a XmlToArray'd structure into an object notation * @param mixed $input * @param Tag $ParentTag * @param int $currentDepth * @param bool $trim * @throws ArrayToXmlException if depth is exceeded */ private function _render($input, SofortTag $ParentTag, $currentDepth, $trim) { $this->_checkDepth($currentDepth); if (is_array($input)) { foreach ($input as $tagName => $data) { $attributes = $this->_extractAttributesSection($data); if (is_array($data) && is_int(key($data))) { $this->_checkDepth($currentDepth+1); foreach ($data as $line) { if (is_array($line)) { $Tag = $this->_createNode($tagName, $this->_extractAttributesSection($line), $this->_extractDataSection($line, $trim)); $ParentTag->children[] = $Tag; $this->_render($line, $Tag, $currentDepth+1, $trim); } else { $ParentTag->children[] = $this->_createNode($tagName, $attributes, array($this->_createTextNode($line, $trim))); } } } elseif (is_array($data)) { $Tag = $this->_createNode($tagName, $attributes, $this->_extractDataSection($data, $trim)); $ParentTag->children[] = $Tag; $this->_render($data, $Tag, $currentDepth+1, $trim); } elseif (is_numeric($tagName)) { $ParentTag->children[] = $this->_createTextNode($data, $trim); } else { $ParentTag->children[] = $this->_createNode($tagName, $attributes, array($this->_createTextNode($data, $trim))); } } return; } $ParentTag->children[] = $this->_createTextNode($input, $trim); } } ?>library/helper/array_to_xml_exception.php000064400000000571152326032300014755 0ustar00<?php defined('_JEXEC') or die('Restricted access'); /** * @author SOFORT AG (integration@sofort.com) * @link http://www.sofort.com/ * * Copyright (c) 2012 SOFORT AG * * Released under the GNU General Public License (Version 2) * [http://www.gnu.org/licenses/gpl-2.0.html] */ /** * * Array To XML Exception * */ class ArrayToXmlException extends Exception {} ?>library/helper/class.abstract_document.inc.php000064400000007421152326032300015555 0ustar00<?php defined('_JEXEC') or die('Restricted access'); /// \cond require_once('pnag_article.php'); require_once('pnag_customer.php'); require_once('pnag_article.php'); require_once('pnag_article.php'); /** * 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 11:34:40 +0100 (Fri, 23 Nov 2012) $ * @version SofortLib 1.5.4 $Id: class.abstract_document.inc.php 5748 2012-11-23 10:34:40Z Niehoff $ * @author SOFORT AG http://www.sofort.com (integration@sofort.com) * @internal * */ class PnagAbstractDocument { /** * Holds all items associated with this kind of document (instance might be invoice, bank transfer, ...) * @var array */ protected $_items = array(); /** * * Holds the instance of PnagCustomer associated with this kind of document * @var object */ protected $_customer = null; /** * * Holds the currency associated with this kind of document * @var String */ protected $_currency = 'EUR'; /** * Holds the amount/total of this kind of document * @var float */ protected $_amount = 0.00; /** * * Holds the refunded amount/total * @var float */ protected $_amountRefunded = 0.00; /** * puts the given article into $this->_items * should only be used for the articles from the shopsystem * @todo change VAT according to legislation */ public function setItem($itemId, $productNumber = 0, $productType = 0, $title = '', $description = '', $quantity = 0, $unitPrice = '', $tax = '19') { array_push($this->_items, new PnagArticle($itemId, $productNumber, $productType, $title, $description, $quantity, $unitPrice, $tax)); return $this; } /** * Getter for items * @return array $this->_items */ public function getItems() { return $this->_items; } /** * searches in the before given shoparticles for the highest tax and returns it * @return int/float - highest found taxvalue e.g. 0 or 7 or 19... */ public function getHighestShoparticleTax() { $highestTax = 0; foreach ($this->_items as $item) { if ($item->getTax() > $highestTax) { $highestTax = $item->getTax(); } } return $highestTax; } /** * Set the customer's credentials * @param $name string * @param $lastname string * @param $firstname string * @param $company string * @param $csID string customer id in shop * @param $vatId string - customer's VAT ID * @param $shopId - shop's ID * @param $Id * @param $cIP * @param $streetAddress string * @param $suburb string * @param $city string * @param $postcode string * @param $state string * @param $country string * @param $formatId string * @param $telephone string * @param $emailAddress string */ public function setCustomer($name = '', $lastname = '', $firstname = '', $company = '', $csID = '', $vatId = '', $shopId = '', $Id = '', $cIP = '', $streetAddress = '', $suburb = '', $city = '', $postcode = '', $state = '', $country = '', $formatId = '', $telephone = '', $emailAddress = '') { $this->_customer = new PnagCustomer($name, $lastname, $firstname, $company, $csID, $vatId, $shopId, $Id, $cIP, $streetAddress, $suburb, $city, $postcode, $state, $country, $formatId, $telephone, $emailAddress); return $this; } /** * * Setter for currency * @param $currency string */ public function setCurrency($currency) { $this->_currency = $currency; return $this; } /** * Calculate the total amount * @private * @return $object */ private function _calcAmount() { $this->_amount = 0.0; foreach($this->_items as $item) { $this->_amount += $item->unitPrice * $item->quantity; } return $this; } /** * get the total amount */ public function getAmount() { return $this->_amount; } } /// \endcond ?>library/helper/class.invoice.inc.php000064400000122045152326032300013510 0ustar00<?php defined('_JEXEC') or die('Restricted access'); /** * 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 $Id: class.invoice.inc.php 5773 2012-11-23 16:15:47Z dehn $ * @package sofortLib * @author SOFORT AG http://www.sofort.com (integration@sofort.com) * */ /** * Abstraction of an invoice * Helper class to ease usage of "Rechnung by sofort" * Encapsulates Multipay, TransactionData and ConfirmSr to handle everything there is about "Rechnung by sofort" * @see SofortLib_Multipay * @see SofortLib_TransactionData * @see SofortLib_ConfirmSr */ class PnagInvoice extends PnagAbstractDocument { const PENDING_CONFIRM_INVOICE = 4195329; const LOSS_CANCELED = 4194824; const LOSS_CONFIRMATION_PERIOD_EXPIRED = 4196360; const PENDING_NOT_CREDITED_YET_PENDING = 32785; const PENDING_NOT_CREDITED_YET_REMINDER_1 = 65553; const PENDING_NOT_CREDITED_YET_REMINDER_2 = 131089; const PENDING_NOT_CREDITED_YET_REMINDER_3 = 262161; const PENDING_NOT_CREDITED_YET_DELCREDERE = 524305; const RECEIVED_CREDITED_PENDING = 33026; const RECEIVED_CREDITED_REMINDER_1 = 65794; const RECEIVED_CREDITED_REMINDER_2 = 131330; const RECEIVED_CREDITED_REMINDER_3 = 262402; const RECEIVED_CREDITED_DELCREDERE = 524546; /* im normalfall nicht möglich */ const REFUNDED_REFUNDED_PENDING = 32836; const REFUNDED_REFUNDED_RECEIVED = 2097220; const REFUNDED_REFUNDED_REMINDER_1 = 65604; const REFUNDED_REFUNDED_REMINDER_2 = 131140; const REFUNDED_REFUNDED_REMINDER_3 = 262212; const REFUNDED_REFUNDED_DELCREDERE = 524356; /* im normalfall nicht möglich */ const REFUNDED_REFUNDED_REFUNDED = 1048644; const PENDING_NOT_CREDITED_YET_RECEIVED = 2097169; const RECEIVED_CREDITED_RECEIVED = 2097410; /** * * Multipay-Object to handle API calls * @var object * @private */ public $SofortLib_Multipay = null; /** * Object TransactionData to handle information about transactions * @var object * @private */ public $SofortLib_TransactionData = null; /** * Object Confirm_SR to handle sofortrechnung/rechnung by sofort items * Handling of Sofortrechung * @var object * @private */ public $ConfirmSr = null; public $EditSr = null; public $CancelSr = null; protected $_items = array(); /** * * Some kind of a bitmask to represent every possible state of Rechnung by sofort * Every combination must be unique to represent a unique state * @var array * @private */ private $_statusMask = array( 'status'=> array( 'pending' => 1, 'received' => 2, 'refunded' => 4, 'loss' => 8, ), 'status_reason' => array( 'not_credited_yet' => 16, 'not_credited' => 32, 'refunded' => 64, 'compensation' => 128, 'credited' => 256, 'canceled' => 512, 'confirm_invoice' => 1024, 'confirmation_period_expired' => 2048, 'wait_for_money' => 4096, 'reversed' => 8192, 'rejected' => 16384, ), 'invoice_status' => array( 'pending' => 32768, 'reminder_1' => 65536, 'reminder_2' => 131072, 'reminder_3' => 262144, 'delcredere' => 524288, 'refunded' => 1048576, 'received' => 2097152, 'empty' => 4194304, ) ); /** * * @see $statusMask * @var string * @private */ private $_status = ''; /** * * @see $statusMask * @var string * @private */ private $_status_reason = ''; /** * * @see $statusMask * @var string */ private $_invoice_status = ''; /** * * Invoice's objection (Einrede) * @var string */ private $_invoice_objection = ''; /** * * language code * @var string */ private $_language_code = ''; /** * * transaction id * @var string * @private */ private $_transactionId = ''; /** * api key given in project setup in payment network backend * @var string * @private */ private $_configKey = ''; /** * * api url * @var string * @private */ private $_apiUrl = ''; /** * time * @var string * @private */ private $_time = ''; /** * payment method * @var string * @private */ private $_payment_method = ''; /** * The resulting url to the invoice (PDF) * @var string * @private */ private $_invoiceUrl = ''; /** * Constructor for PnagInvoice * @param string $apiKey * @param string $transactionId * @param string $apiUrl */ public function __construct($configKey, $transactionId = '') { $this->_transactionId = $transactionId; $this->_configKey = $configKey; $this->_apiUrl = (getenv('sofortApiUrl') != '') ? getenv('sofortApiUrl') : 'https://api.sofort.com/api/xml'; $this->SofortLib_Multipay = new SofortLib_Multipay($this->_configKey, $this->_apiUrl); if ($transactionId != '') { $this->SofortLib_TransactionData = $this->_setupTransactionData(); $this->ConfirmSr = $this->_setupConfirmSr(); } return $this; } /** * Getter for a class constant * @param int $id * @return string */ public function getConstantById($id) { $Object = new ReflectionClass(__CLASS__); $constants = array_flip($Object->getConstants()); return (array_key_exists($id, $constants)) ? $constants[$id] : 0; } /** * * Getter for a class constant * @param string $name * @return int */ public function getConstantByName($name) { $Object = new ReflectionClass(__CLASS__); $constants = $Object->getConstants(); return (array_key_exists($name, $constants)) ? $constants[$name] : 0; } /** * * Set the bitmask to a specific state * @param string $status * @param string $status_reason * @param string $invoice_status * @return string pending - confirm_invoice - empty -> 4195329 */ public function setBitmask($status, $statusReason, $invoiceStatus) { $this->_status = $status; $this->_status_reason = $statusReason; $this->_invoice_status = $invoiceStatus; $string = $this->_status.' - '.$this->_status_reason.' - '.$this->_invoice_status; return $string.' -> '.$this->_calcInvoiceStatusCode()."\n"; } /** * * Set the state * An optional callback can be registered * @param int $state * @param function $callback */ public function setState($state, $callback = '') { $this->_state = $state; if ($callback != '') { call_user_func($callback); } return $this; } /** * Getter for the current state * @return int $this->state */ public function getState() { return $this->_state; } /** * Setter for transactionId * @param $transactionId * @public */ public function setTransactionId($transactionId) { $this->_transactionId = $transactionId; $this->SofortLib_TransactionData = $this->_setupTransactionData(); $this->ConfirmSr = $this->_setupConfirmSr(); return $this; } /** * Construct the SofortLib_TransactionData object * Collect every order's item and set it accordingly * TransactionData is used encapsulated in this class to retrieve information about the order's details * @return object SofortLib_TransactionData * @private */ private function _setupTransactionData() { $SofortLib_TransactionData = new SofortLib_TransactionData($this->_configKey, $this->_apiUrl); $SofortLib_TransactionData->setTransaction($this->_transactionId); $SofortLib_TransactionData->sendRequest(); if (!$SofortLib_TransactionData->getCount()) { return false; } $this->setStatus($SofortLib_TransactionData->getStatus()); $this->setStatusReason($SofortLib_TransactionData->getStatusReason()); $this->setStatusOfInvoice($SofortLib_TransactionData->getInvoiceStatus()); $this->setInvoiceObjection($SofortLib_TransactionData->getInvoiceObjection()); $this->setLanguageCode($SofortLib_TransactionData->getLanguageCode()); $this->setTransaction($this->getTransactionId()); $this->setTime($SofortLib_TransactionData->getTime()); $this->setPaymentMethod($SofortLib_TransactionData->getPaymentMethod()); $this->setInvoiceUrl($SofortLib_TransactionData->getInvoiceUrl()); $this->setAmount($SofortLib_TransactionData->getAmount()); $this->setAmountRefunded($SofortLib_TransactionData->getAmountRefunded()); $itemArray = $SofortLib_TransactionData->getItems(); // should there be any items, fetch them accordingly $this->_items = array(); if (is_array($itemArray) && !empty($itemArray)) { foreach ($itemArray as $item) { $this->setItem($item['item_id'], $item['product_number'], $item['product_type'], $item['title'], $item['description'], $item['quantity'], $item['unit_price'], $item['tax']); $this->_amount += ($item['unit_price'] * $item['quantity']); } } /* * set the state according to the state given by transaction information (status, status_reason, invoice_status) * @see $statusMask */ $this->setState($this->_calcInvoiceStatusCode()); return $SofortLib_TransactionData; } /** * * Setter for SofortLib_Multipay * @param object $SofortLib_Multipay */ public function setSofortLibMultipay($SofortLib_Multipay) { $this->SofortLib_Multipay = $SofortLib_Multipay; } /** * * Setter for SofortLib_TransactionData * @param object $SofortLib_TransactionData */ public function setSofortLibTransactionData($SofortLib_TransactionData) { $this->SofortLib_TransactionData = $SofortLib_TransactionData; } /** * * Setter for SofortLib_EditSr * @param object $SofortLib_EditSr */ public function setSofortLibEditSr($SofortLib_EditSr) { $this->EditSr = $SofortLib_EditSr; } /** * * Setter for SofortLib_CancelSr * @param object $SofortLib_CancelSr */ public function setSofortLibCancelSr($SofortLib_CancelSr) { $this->CancelSr = $SofortLib_CancelSr; } /** * Initialize SofortLib_ConfirmSR * @private * @return Object SofortLib_ConfirmSr */ private function _setupConfirmSr() { $SofortLib_ConfirmSr = new SofortLib_ConfirmSr($this->_configKey); $SofortLib_ConfirmSr->setTransaction($this->_transactionId); return $SofortLib_ConfirmSr; } /** * * Setup EditSr object */ private function _setupEditSr() { $SofortLib_EditSr = new SofortLib_EditSr($this->_configKey); $SofortLib_EditSr->setTransaction($this->_transactionId); return $SofortLib_EditSr; } /** * * Setup CancelSr object */ private function _setupCancelSr() { $SofortLib_CancelSr = new SofortLib_CancelSr($this->_configKey); $SofortLib_CancelSr->setTransaction($this->_transactionId); return $SofortLib_CancelSr; } /** * Refreshes the TransactionData with the data directly from the pnag-server * @return boolean */ public function refreshTransactionData() { $this->SofortLib_TransactionData = $this->_setupTransactionData(); return true; } /** * Wrapper function for cancelling this invoice via SofortLib_Multipay (SofortLib) * @return Ambigious boolean/Array * @todo fix returned value array, empty array * @public */ public function cancelInvoice($transactionId = '', $creditNoteNumber = '') { if ($transactionId != '' || $transactionId = $this->getTransactionId()) { $this->_transactionId = $transactionId; $this->CancelSr = $this->_setupCancelSr(); } if ($this->CancelSr != null) { unset($this->_items); $this->CancelSr->cancelInvoice(); $this->CancelSr->setComment('Vollstorno'); $creditNoteNumber && $this->CancelSr->setCreditNoteNumber($creditNoteNumber); $this->CancelSr->sendRequest(); $this->SofortLib_TransactionData = $this->_setupTransactionData(); return $this->getErrors(); } return false; } /** * Wrapper function for confirming this invoice via SofortLib_Multipay (SofortLib) * @param $transactionId - optional parameter for confirming a transaction on the fly * @param $invoiceNumer - optional parameter for own invoice number * @param $customerNumber - optional parameter for own customer number * @param $orderNumber - optional parameter for own order number * @return Ambigious boolean/Array * @todo fix returned value array, empty array * @public */ public function confirmInvoice($transactionId = '', $invoiceNumber = '', $customerNumber = '', $orderNumber = '') { if ($transactionId != '' || $transactionId = $this->getTransactionId()) { $this->_transactionId = $transactionId; $this->ConfirmSr = $this->_setupConfirmSr(); } if ($this->ConfirmSr != null) { $this->ConfirmSr->confirmInvoice(); $invoiceNumber && $this->ConfirmSr->setInvoiceNumber($invoiceNumber); $customerNumber && $this->ConfirmSr->setCustomerNumber($customerNumber); $orderNumber && $this->ConfirmSr->setOrderNumber($orderNumber); $this->ConfirmSr->setApiVersion('2.0'); $this->ConfirmSr->sendRequest(); $this->SofortLib_TransactionData = $this->_setupTransactionData(); return $this->getErrors(); } return false; } /** * Wrapper function for removing an article via SofortLib_Multipay (SofortLib) * @param $transactionId string * @param $PnagArticels array * @param $comment int * @public * return array */ public function updateInvoice($transactionId, $items, $comment, $invoiceNumber = '', $customerNumber = '', $orderNumber = '') { if ($transactionId != '' || $transactionId = $this->getTransactionId()) { $this->_transactionId = $transactionId; $this->EditSr = $this->_setupEditSr(); } if ($this->EditSr != null) { $this->EditSr->setComment($comment); $invoiceNumber && $this->EditSr->setInvoiceNumber($invoiceNumber); $customerNumber && $this->EditSr->setCustomerNumber($customerNumber); $orderNumber && $this->EditSr->setOrderNumber($orderNumber); $this->EditSr->updateCart($items); $this->EditSr->sendRequest(); $this->SofortLib_TransactionData = $this->_setupTransactionData(); return $this->getErrors(); } return false; } /** * Wrapper function for updating order number after order hast been placed * @param string $transactionId * @param string $orderNumber */ public function updateOrderNumber($transactionId, $orderNumber) { if ($transactionId != '' || $transactionId = $this->getTransactionId()) { $this->_transactionId = $transactionId; $this->EditSr = $this->_setupEditSr(); } if ($this->EditSr != null) { $orderNumber && $this->EditSr->setOrderNumber($orderNumber); $this->EditSr->sendRequest(); } } /* ########################## WRAPPER FUNCTIONS MULTIPAY ########################## */ /** * Wrapper for SofortLib_Multipay::addSofortrechnungItem * @see SofortLib_Multipay * @public * @param $itemId * @param $productNumber * @param $title * @param $unit_price - float precision 2 @see SofortLib_Multipay api * @param $productType * @param $description * @param $quantity - int * @param $tax */ public function addItemToInvoice($itemId, $productNumber, $title, $unitPrice, $productType = 0, $description = '', $quantity = 1, $tax = 19) { $unitPrice = round($unitPrice, 2); // round all prices to two decimals $this->SofortLib_Multipay->addSofortrechnungItem($itemId, $productNumber, $title, $unitPrice, $productType, $description, $quantity, $tax); $this->setItem($itemId, $productNumber, $productType, $title, $description, $quantity, $unitPrice, $tax); $this->_amount += ($quantity * $unitPrice); $this->setAmount($this->_amount, $this->_currency); } /** * Remove an item from the invoice * @public * @param $itemId * @return boolean */ public function removeItemfromInvoice($itemId) { $return = false; $i = 0; foreach ($this->_items as $item) { if ($item->itemId == $itemId) { // TODO: remove item //unset($this->_items[$i]); $this->setAmount($this->getAmount() - $this->getItemAmount($itemId)); $return = $this->SofortLib_Multipay->removeSofortrechnungItem($itemId); } $i++; } return $return; } /** * * Update an invoice's item * @param string $itemId * @param int $quantity * @param float $unitPrice */ public function updateInvoiceItem($itemId, $quantity, $unitPrice) { $return = false; foreach ($this->_items as $item) { if ($item->itemId == $itemId) { $oldPrice = $item->unitPrice * $item->quantity; $item->uniPrice = $unitPrice; $item->quantity = $quantity; $newPrice = $unitPrice * $quantity; $this->setAmount($this->getAmount() - $oldPrice + $newPrice); $return = $this->SofortLib_Multipay->updateSofortrechnungItem($itemId, $quantity, $unitPrice); } } return $return; } /** * * Getter for an invoice's amount * @param string $itemId */ public function getItemAmount($itemId) { return $this->SofortLib_Multipay->getSofortrechnungItemAmount($itemId); } /** * Wrapper for SofortLib_Multipay::setSofortrechnungShippingAddress * @see SofortLib_Multipay * @public * @param $firstname * @param $lastname * @param $street * @param $streetNumber * @param $zipcode * @param $city * @param $salutation * @param $country (optional, default: DE) * @param $nameAdditive (optional) * @param $streetAdditive (optional) * @param $companyName (optional) */ public function addShippingAddress($firstname, $lastname, $street, $streetNumber, $zipcode, $city, $salutation, $country = 'DE', $nameAdditive = '', $streetAdditive = '', $companyName = '') { $this->SofortLib_Multipay->setSofortrechnungShippingAddress($firstname, $lastname, $street, $streetNumber, $zipcode, $city, $salutation, $country, $nameAdditive, $streetAdditive, $companyName); } /** * Wrapper for SofortLib_Multipay::setSofortrechnungShippingAddress * @see SofortLib_Multipay * @public * @param $firstname * @param $lastname * @param $street * @param $streetNumber * @param $zipcode * @param $city * @param $salutation * @param $country (optional, default: DE) * @param $nameAdditive (optional) * @param $streetAdditive (optional) * @deprecated */ public function addShippingAddresss($firstname, $lastname, $street, $streetNumber, $zipcode, $city, $salutation, $country = 'DE', $nameAdditive = '', $streetAdditive = '') { $this->SofortLib_Multipay->setSofortrechnungShippingAddress($firstname, $lastname, $street, $streetNumber, $zipcode, $city, $salutation, $country, $nameAdditive, $streetAdditive); } /** * Wrapper for SofortLib_Multipay::setSofortrechnungInvoiceAddress * @see SofortLib_Multipay * @public * @param $firstname * @param $lastname * @param $street * @param $streetNumber * @param $zipcode * @param $city * @param $salutation * @param $country (optional, default: DE) * @param $nameAdditive (optional) * @param $streetAdditive (optional) * @param $companyName (optional) */ public function addInvoiceAddress($firstname, $lastname, $street, $streetNumber, $zipcode, $city, $salutation, $country = 'DE', $nameAdditive = '', $streetAdditive = '', $companyName = '') { $this->SofortLib_Multipay->setSofortrechnungInvoiceAddress($firstname, $lastname, $street, $streetNumber, $zipcode, $city, $salutation, $country, $nameAdditive, $streetAdditive, $companyName); } /** * Wrapper function for SofortLib_Multipay::setSofortrechnungOrderId * @see SofortLib_Multipay * @public * @param $arg */ public function setOrderId($arg) { $this->SofortLib_Multipay->setSofortrechnungOrderId($arg); } /** * Wrapper function for SofortLib_Multipay::setSofortrechnungCustomerId * @public * @param $arg */ public function setCustomerId($arg) { $this->SofortLib_Multipay->setSofortrechnungCustomerId($arg); } /** * Wrapper function for SofortLib_Multipay::setPhoneNumberCustomer * @public * @param $arg */ public function setPhoneNumberCustomer($arg) { $this->SofortLib_Multipay->setPhoneNumberCustomer($arg); } /** * Wrapper function for SofortLib_Multipay::setEmailCustomer * @public * @param $arg */ public function setEmailCustomer($arg) { $this->SofortLib_Multipay->setEmailCustomer($arg); } /** * Wrapper function for SofortLib_Multipay::addUserVariable * @public * @param $arg */ public function addUserVariable($arg) { $this->SofortLib_Multipay->addUserVariable($arg); } /** * Wrapper function for SofortLib_Multipay::setNotificationUrl * @public * @param $arg */ public function setNotificationUrl($arg) { $this->SofortLib_Multipay->setNotificationUrl($arg); } /** * Wrapper function for SofortLib_Multipay::setAbortUrl * @public * @param $arg */ public function setAbortUrl($arg) { $this->SofortLib_Multipay->setAbortUrl($arg); } /** * Wrapper function for SofortLib_Multipay::setSuccessUrl * @public * @param $arg */ public function setSuccessUrl($arg) { $this->SofortLib_Multipay->setSuccessUrl($arg); } /** * Wrapper function for SofortLib_Multipay::setTimeoutUrl * @public * @param $arg */ public function setTimeoutUrl($arg) { $this->SofortLib_Multipay->setTimeoutUrl($arg); } /** * Wrapper function for SofortLib_Multipay::setTimeout * @public * @param $arg */ public function setTimeout($arg) { $this->SofortLib_Multipay->setTimeout($arg); } /** * Wrapper function for SofortLib_Multipay::setReason * @public * @param $reason1 string * @param $reason2 string */ public function setReason($reason1, $reason2 = '') { $this->SofortLib_Multipay->setReason($reason1, $reason2); } /** * Wrapper function for SofortLib_Multipay::setAmount * @public * @param $arg float * @param $currency string */ public function setAmount($arg, $currency = 'EUR') { $this->SofortLib_Multipay->setAmount($arg, $currency); } /** * current total amount of the given order-articles * @return float - sum (price, total) of all articles */ public function getAmount() { if (isset($this->SofortLib_TransactionData) && $this->SofortLib_TransactionData instanceof SofortLib_TransactionData) { $amount = $this->SofortLib_TransactionData->getAmount(); } else { $amount = $this->_amount; } if ($amount != 0.00) { return $amount; } elseif (isset($this->_amount) && $this->_amount != 0.00) { return $this->_amount; // TODO: check } return 0.0; } /** * * Setter for amount refunded * @param amount $arg */ public function setAmountRefunded($arg) { $this->_amountRefunded = $arg; } /** * * Getter for amount refunded */ public function getAmountRefunded() { return $this->_amountRefunded; } /** * Wrapper function for SofortLib_Multipay::setSofortrechnung * @public */ public function setSofortrechnung() { $this->SofortLib_Multipay->setSofortrechnung(); } /** * Wrapper function for SofortLib_Multipay::setDebitorVatNumber * @public */ public function setDebitorVatNumber($vatNumber) { $this->SofortLib_Multipay->setDebitorVatNumber($vatNumber); } /** * Wrapper function for SofortLib_Multipay::getPaymentUrl * @public * @return url string */ public function getPaymentUrl() { return $this->SofortLib_Multipay->getPaymentUrl(); } /** * * Getter for invoice's number */ public function getInvoiceNumber() { return $this->SofortLib_TransactionData->getInvoiceNumber(); } /** * * Getter for customer's number */ public function getCustomerNumber() { return $this->SofortLib_TransactionData->getCustomerNumber(); } /** * * Getter for order's number */ public function getOrderNumber() { if ($this->SofortLib_TransactionData instanceof SofortLib_TransactionData) { return $this->SofortLib_TransactionData->getOrderNumber(); } return false; } /** * Wrapper function for SofortLib_Multipay::geInvoiceType * @public * @return (OR or LS) */ public function getInvoiceTye() { return $this->SofortLib_TransactionData->getInvoiceType(); } /** * Wrapper function for SofortLib_Multipay::getPaymentUrl * @public * @return url string */ public function getTransactionId() { if ($this->SofortLib_Multipay instanceof SofortLib_Multipay && $transactionId = $this->SofortLib_Multipay->getTransactionId()) { return $transactionId; } elseif ($this->SofortLib_TransactionData instanceof SofortLib_TransactionData && $transactionId = $this->SofortLib_TransactionData->getTransaction()) { return $transactionId; } else { return $this->_transactionId; } } /** * Validate your parameters against API * @return array - any validationerrors and -warnings * @public */ /* public function validateRequest() { $errorsAndWarnings = $this->SofortLib_Multipay->validateRequest('sr'); return $errorsAndWarnings; } */ /** * send the order to pnag (-> buy your products) * @return empty array if ok ELSE array with errors and/or warnings * @public */ public function checkout() { $this->SofortLib_Multipay->sendRequest(); $this->_transactionId = $this->SofortLib_Multipay->getTransactionId(); // set the resulting transaction id $this->SofortLib_TransactionData = $this->_setupTransactionData(); $errors = array(); if ($this->isError()) { $errors = $this->getErrors(); } $warnings = array(); if ($this->isWarning()) { $warnings = $this->getWarnings(); } if (!empty($errors) && !empty($warnings)) { return array(); //no errors or warnings found } else { $returnArray = array(); $returnArray['errors'] = $errors; $returnArray['warnings'] = $warnings; return $returnArray; } } /** * * Getter for information about transaction */ public function getTransactionInfo() { if (is_a($this->SofortLib_TransactionData, 'SofortLib')) { $this->SofortLib_TransactionData->setTransaction($this->transactionId); $this->sendRequest(); return $this->SofortLib_TransactionData; } else { $this->SofortLib_TransactionData = $this->_setupTransactionData(); } return array(); } /* ########################## WRAPPER FUNCTIONS MULTIPAY ########################## */ /** * Output the resulting invoice as pdf, if possible * Function uses file_get_contents, if allow_url_fopen is allowed in php.ini (might be disabled on shared hosting) * As a fallback, downloading via cURL, when module cURL is available * If neither file_get_contents nor cURL is available for downloading, a connection via socket is used to download. * @public * @return boolean */ public function getInvoice() { $errorCode = $this->getHttpResponseCode($this->_invoiceUrl); if (!in_array($errorCode, array('200', '301', '302'))) { return false; } header('Content-type: application/pdf'); header('Content-Disposition: attachment; filename="invoice.pdf"'); echo $this->handleDownload($this->getInvoiceDownloadMethod()); } /** * * Handle download of invoice * @param string $method */ public function handleDownload($method = 'socket') { switch ($method) { case 'file_get_contents': return file_get_contents($this->_invoiceUrl); break; case 'curl': return $this->handleCurlDownload(); break; default: return $this->handleSocketDownload(); break; } } /** * * Getter for invoice's download method */ public function getInvoiceDownloadMethod() { if (ini_get('allow_url_fopen')) { $method = 'file_get_contents'; } elseif (function_exists('curl_init')) { $method = 'curl'; } else { $method = 'socket'; } return $method; } /** * * Handle download via cURL */ private function handleCurlDownload() { $curl_handle=curl_init(); curl_setopt($curl_handle, CURLOPT_URL, $this->_invoiceUrl); curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, false); $buffer = curl_exec($curl_handle); curl_close($curl_handle); return $buffer; } /** * * Handle download via Socket */ private function handleSocketDownload() { $uri = parse_url($this->_invoiceUrl); $host = $uri['host']; $path = $uri['path']; $handle = $this->openSocket($host); $header = $this->makeHeader('GET', $path, $host); fwrite($handle, $header); $buffer = null; while (!feof($handle)) { $buffer .= fgets($handle, 8192); } fclose($handle); return $buffer; } /** * * Getter for HTTP Response code */ public function getHttpResponseCode() { $uri = parse_url($this->_invoiceUrl); $host = $uri['host']; $path = $uri['path']; $handle = $this->openSocket($host); $header = $this->makeHeader('HEAD', $path, $host); fwrite($handle, $header); $buffer = null; while(!feof($handle)) { $buffer .= fgets($handle, 16); } fclose($handle); $httpCode = substr($buffer, 9, 3); return (int)$httpCode; } /** * * Open up a socket * @param string $host */ private function openSocket($host) { if (!$fp = fsockopen('ssl://'.$host, 443, $errno, $errstr, 15)) { return false; } return $fp; } /** * * Make HTTP header for communication * @param string $action * @param string $path * @param string $host */ private function makeHeader($action, $path, $host) { $header = $action." ".$path." HTTP/1.1\r\n"; $header .= 'Host: '.$host."\r\n"; $header .= "User-Agent: SOFORTLib \r\n"; return $header .= "Connection: Close\r\n\r\n"; } /** * Setter for invoiceUrl * @public * @param $invoiceUrl * @return object */ public function setInvoiceUrl($invoiceUrl) { $this->_invoiceUrl = $invoiceUrl; return $this; } /** * Getter for retrieving the invoice's url * @public * @return url string */ public function getInvoiceUrl() { return $this->_invoiceUrl; } /** * Setter for status * @public * @param $status * @return object */ public function setStatus($status) { $this->_status = $status; return $this; } /** * Setter for status_reason * @param $status_reason * @return object */ public function setStatusReason($statusReason) { $this->_status_reason = $statusReason; return $this; } /** * * Setter for invoice_status * @param string $invoice_status | may be emtpy * @return object */ public function setStatusOfInvoice($invoiceStatus = '') { $this->_invoice_status = !empty($invoiceStatus) ? $invoiceStatus : 'empty'; return $this; } /** * * Setter for language_code * @param string $language_code | fallback en * @return object */ public function setLanguageCode($languageCode = '') { $this->_language_code = !empty($languageCode) ? $languageCode : 'en'; return $this; } /** * Setter for transaction * @param $transaction * @return object */ public function setTransaction($transaction) { $this->_transaction = $transaction; return $this; } /** * Setter for variable time * @param $time * @public * return object */ public function setTime($time) { $this->_time = $time; return $this; } /** * Setter for interface version * Wrapper for class Multipay to set version according to shop module and it's interface version * e.g. 'pn_xtc_5.0.0' * @param $arg string */ public function setVersion($arg) { $this->SofortLib_Multipay->setVersion($arg); } /** * Setter for payment_method * @param $paymentMethod * @return object */ public function setPaymentMethod($paymentMethod) { $this->_payment_method = $paymentMethod; return $this; } /** * Sets the reason for objecting this invoice * @param string $invoiceObjection (40-50 chars max.) * @return object */ public function setInvoiceObjection($invoiceObjection) { $this->_invoice_objection = $invoiceObjection; return $this; } /** * Sets the invoice status * @public * @param string $invoiceStatus * @return object */ public function setInvoiceStatus($invoiceStatus) { $this->_invoice_status = $invoiceStatus; return $this; } /** * Returns the reason for objecting this invoice * @public * @return string */ public function getInvoiceObjection() { return $this->_invoice_objection; } /** * Instead of calculated status, this method returns the invoice's staus (string) * @public * @return string */ public function getStatusOfInvoice() { return $this->_invoice_status; } /** * Uses the statusMask to "calculate" the current invoice's payment status * @public * @see Invoice::_calcInvoiceStatusCode * @return int */ public function getInvoiceStatus() { return $this->_calcInvoiceStatusCode(); } /** * * Calculate the current invoice's payment status using bitwise OR * @return int * @private */ private function _calcInvoiceStatusCode() { return $this->_statusMask['status'][$this->_status] | $this->_statusMask['status_reason'][$this->_status_reason] | $this->_statusMask['invoice_status'][$this->_invoice_status]; } /** * Getter for payment_method * @public * @return string */ public function getPaymentMethod() { return $this->_payment_method; } /** * Getter for status_reason * @public * @return string */ public function getStatusReason() { return $this->_status_reason; } /** * Getter for status * @public * @return string */ public function getStatus() { return $this->_status; } /** * Getter for language code * @public * @return string */ public function getLanguageCode() { return $this->_language_code; } /** * Getter for items * @public * @return array */ public function getItems() { return $this->_items; } /** * Setter for invoice items, takes an array of PnagArticle objects * @param array $items */ public function setItems($items) { $this->_items = $items; } /** * return TransactionData, the invoice is working with * NOTICE: if status changed (removeArticle, InvoiceConfirmed etc.) it returns always the FRESH TransactionData from pnag-server * @return object * @see $this->refreshTransactionData(); */ public function getTransactionData() { if ($this->SofortLib_TransactionData) { return $this->SofortLib_TransactionData; } else { return false; } } /** * Check, if errors occured * @public * @return boolean */ public function isError() { if ($this->SofortLib_Multipay) { if ($this->SofortLib_Multipay->isError('sr')) { return true; } } if ($this->ConfirmSr) { if ($this->ConfirmSr->isError('sr')) { return true; } } if ($this->EditSr) { if ($this->EditSr->isError('sr')) { return true; } } if ($this->CancelSr) { if ($this->CancelSr->isError('sr')) { return true; } } if ($this->SofortLib_TransactionData) { if ($this->SofortLib_TransactionData->isError('sr')) { return true; } } return false; } /** * Check, if warnings occured * @public * @return boolean */ public function isWarning() { if ($this->SofortLib_Multipay) { if ($this->SofortLib_Multipay->isWarning('sr')) { return true; } } if ($this->ConfirmSr) { if ($this->ConfirmSr->isWarning('sr')) { return true; } } if ($this->EditSr) { if ($this->EditSr->isWarning('sr')) { return true; } } if ($this->CancelSr) { if ($this->CancelSr->isWarning('sr')) { return true; } } if ($this->SofortLib_TransactionData) { if ($this->SofortLib_TransactionData->isWarning('sr')) { return true; } } return false; } /** * returns one error (as String!) */ public function getError() { if ($this->SofortLib_Multipay) { if ($this->SofortLib_Multipay->isError('sr')) { return $this->SofortLib_Multipay->getError('sr'); } } if ($this->ConfirmSr) { if ($this->ConfirmSr->isError('sr')) { return $this->ConfirmSr->getError('sr'); } } if ($this->EditSr) { if ($this->EditSr->isError('sr')) { return $this->EditSr->getError('sr'); } } if ($this->CancelSr) { if ($this->CancelSr->isError('sr')) { return $this->CancelSr->getError('sr'); } } if ($this->SofortLib_TransactionData) { if ($this->SofortLib_TransactionData->isError('sr')) { return $this->SofortLib_TransactionData->getError('sr'); } } return ''; } /** * collect all errors and returns them * @return array - all errors * @public */ public function getErrors() { $allErrors = array(); if ($this->SofortLib_Multipay) { if ($this->SofortLib_Multipay->isError('sr')) { $allErrors = array_merge($this->SofortLib_Multipay->getErrors('sr'), $allErrors); } } if ($this->ConfirmSr) { if ($this->ConfirmSr->isError('sr')) { $allErrors = array_merge($this->ConfirmSr->getErrors('sr'), $allErrors); } } if ($this->EditSr) { if ($this->EditSr->isError('sr')) { $allErrors = array_merge($this->EditSr->getErrors('sr'), $allErrors); } } if ($this->CancelSr) { if ($this->CancelSr->isError('sr')) { $allErrors = array_merge($this->CancelSr->getErrors('sr'), $allErrors); } } if ($this->SofortLib_TransactionData) { if ($this->SofortLib_TransactionData->isError('sr')) { $allErrors = array_merge($this->SofortLib_TransactionData->getErrors('sr'), $allErrors); } } return $allErrors; } /** * * Ouputs errors in a more convenient array to let users easily iterate * @param int $detailLevel * @public */ public function getErrorCodes($detailLevel = 0) { $errors = $this->getErrors(); if (empty($errors)) return array(); $errorCodes = array(); foreach($errors as $error) { if ($detailLevel === 0) { array_push($errorCodes, $error['code']); } elseif ($detailLevel === 1) { array_push($errorCodes, array( 'code' => $error['code'], 'message' => $error['message'], 'field' => $error['field'], )); } } return $errorCodes; } /** * * collects all warnings and returns them * @return array * @public */ public function getWarnings() { $allWarnings = array(); if ($this->SofortLib_Multipay) { if ($this->SofortLib_Multipay->isWarning('sr')) { $allWarnings = array_merge($this->SofortLib_Multipay->getWarnings('sr'), $allWarnings); } } if ($this->ConfirmSr) { if ($this->ConfirmSr->isWarning('sr')) { $allWarnings = array_merge($this->ConfirmSr->getWarnings('sr'), $allWarnings); } } if ($this->EditSr) { if ($this->EditSr->isWarning('sr')) { $allErrors = array_merge($this->EditSr->getWarnings('sr'), $allErrors); } } if ($this->CancelSr) { if ($this->CancelSr->isWarning('sr')) { $allErrors = array_merge($this->CancelSr->getWarnings('sr'), $allErrors); } } if ($this->SofortLib_TransactionData) { if ($this->SofortLib_TransactionData->isWarning('sr')) { $allWarnings = array_merge($this->SofortLib_TransactionData->getWarnings('sr'), $allWarnings); } } return $allWarnings; } /** * Enabling logging for all encapsed SofortLib components * @public * @return boolean */ public function enableLog() { (is_a($this->SofortLib_Multipay, 'SofortLib')) ? $this->SofortLib_Multipay->setLogEnabled() : ''; (is_a($this->SofortLib_TransactionData, 'SofortLib')) ? $this->SofortLib_TransactionData->setLogEnabled() : ''; (is_a($this->ConfirmSr, 'SofortLib')) ? $this->ConfirmSr->setLogEnabled() : ''; return true; } /** * Disable logging for all encapsed SofortLib components * @public * @return boolean */ public function disableLog() { (is_a($this->SofortLib_Multipay, 'SofortLib')) ? $this->SofortLib_Multipay->setLogDisabled() : ''; (is_a($this->SofortLib_TransactionData, 'SofortLib')) ? $this->SofortLib_TransactionData->setLogDisabled() : ''; (is_a($this->ConfirmSr, 'SofortLib')) ? $this->ConfirmSr->setLogDisabled() : ''; return true; } /** * Log the given String into log.txt * Notice: logging must be enabled -> use enableLog(); * @param string $msg - Message to log * @return bool - true=logged ELSE false=logging failed * @public */ public function log($message){ if (is_a($this->SofortLib_Multipay, 'SofortLib')) { $this->SofortLib_Multipay->log($message); return true; } elseif (is_a($this->SofortLib_TransactionData, 'SofortLib')) { $this->SofortLib_TransactionData->log($message); return true; } elseif (is_a($this->ConfirmSr, 'SofortLib')) { $this->ConfirmSr->log($message); return true; } return false; } /** * Log the given String into error_log.txt * Notice: logging must be enabled -> use enableLog(); * @param string $msg - Message to log * @return bool - true=logged ELSE false=logging failed * @public */ public function logError($message){ if (is_a($this->SofortLib_Multipay, 'SofortLib')) { $this->SofortLib_Multipay->logError($message); return true; } elseif (is_a($this->SofortLib_TransactionData, 'SofortLib')) { $this->SofortLib_TransactionData->logError($message); return true; } elseif (is_a($this->ConfirmSr, 'SofortLib')) { $this->ConfirmSr->logError($message); return true; } return false; } /** * Log the given String into warning_log.txt * @param string $msg - Message to log * @return bool - true=logged ELSE false=logging failed * @public */ public function logWarning($message){ if (is_a($this->SofortLib_Multipay, 'SofortLib')) { $this->SofortLib_Multipay->logWarning($message); return true; } elseif (is_a($this->SofortLib_TransactionData, 'SofortLib')) { $this->SofortLib_TransactionData->logWarning($message); return true; } elseif (is_a($this->ConfirmSr, 'SofortLib')) { $this->ConfirmSr->logWarning($message); return true; } return false; } /** * * Override toString */ public function __toString() { $string = '<pre>'; $string .= print_r($this, 1); $string .= '</pre>'; return $string; } } ?>library/helper/pnag_article.php000064400000005004152326032300012623 0ustar00<?php defined('_JEXEC') or die('Restricted access'); /** * * Data object that encapsulates article's data * $Date: 2012-09-05 14:27:56 +0200 (Mi, 05 Sep 2012) $ * $ID$ * */ class PnagArticle { public $itemId = ''; public $productNumber = ''; public $productType = ''; public $title = ''; public $description = ''; public $quantity = ''; public $unitPrice = ''; public $tax = ''; /** * Constructor for PnagArticle * @param $itemId int * @param $productNumber string * @param $productType string * @param $title string * @param $description string * @param $quantity int * @param $unitPrice float * @param $tax float */ public function __construct($itemId, $productNumber, $productType, $title, $description, $quantity, $unitPrice, $tax) { $this->itemId = $itemId; $this->productNumber = $productNumber; $this->productType = $productType; $this->title = $title; $this->description = $description; $this->quantity = $quantity; $this->unitPrice = $unitPrice; $this->tax = $tax; } /** * * Getter for item id */ public function getItemId () { return $this->itemId; } /** * * Getter for quantity */ public function getQuantity() { return $this->quantity; } /** * * Setter for quantity * @param int $quantity */ public function setQuantity($quantity) { $this->quantity = $quantity; } /** * * Getter for unit price */ public function getUnitPrice() { return $this->unitPrice; } /** * * Setter for unit price * @param float $unitPrice */ public function setUnitPrice($unitPrice) { $this->unitPrice = $unitPrice; } /** * * Getter for title */ public function getTitle() { return $this->title; } /** * * Getter for tax value */ public function getTax() { return $this->tax; } /** * * Setter for tax value * @param float $value */ public function setTax($value) { $this->tax = $value; } /** * * Setter for product number * @param string $productNumber */ public function setProductNumber($productNumber) { $this->productNumber = $productNumber; } /** * * Getter for product number */ public function getProductNumber() { return $this->productNumber; } /** * * Setter for description * @param string $description */ public function setDescription($description) { $this->description = $description; } /** * * Getter for description */ public function getDescription() { return $this->description; } } ?>library/helper/pnag_customer.php000064400000003737152326032300013054 0ustar00<?php defined('_JEXEC') or die('Restricted access'); /** * * Data object that encapsulates user's data * $Date: 2012-09-05 14:27:56 +0200 (Mi, 05 Sep 2012) $ * $ID$ * */ class PnagCustomer { public $name = ''; public $lastname = ''; public $firstname = ''; public $company = ''; public $csID = ''; public $vatId = ''; public $shopId = ''; public $Id = ''; public $cIP = ''; public $streetAddress = ''; public $suburb = ''; public $city = ''; public $postcode = ''; public $state = ''; public $country = ''; public $formatId = ''; public $telephone = ''; public $emailAddress = ''; /** * Set the customer's credentials * @param $name string * @param $lastname string * @param $firstname string * @param $company string * @param $csID string customer id in shop * @param $vatId string - customer's VAT ID * @param $shopId - shop's ID * @param $Id * @param $cIP * @param $streetAddress string * @param $suburb string * @param $city string * @param $postcode string * @param $state string * @param $country string * @param $formatId string * @param $telephone string * @param $emailAddress string */ public function __construct($name = '', $lastname = '', $firstname = '', $company = '', $csID = '', $vatId = '', $shopId = '', $Id = '', $cIP = '', $streetAddress = '', $suburb = '', $city = '', $postcode = '', $state = '', $country = '', $formatId = '', $telephone = '', $emailAddress = '') { $this->name = $name; $this->lastname = $lastname; $this->firstname = $firstname; $this->company = $company; $this->csID = $csID; $this->vatId = $vatId; $this->shopId = $shopId; $this->Id = $Id; $this->cIP = $cIP; $this->street_address = $streetAddress; $this->suburb = $suburb; $this->city = $city; $this->postcode = $postcode; $this->state = $state; $this->country = $country; $this->formatId = $formatId; $this->telephone = $telephone; $this->emailAddress = $emailAddress; } } ?>library/helper/xml_to_array.php000064400000017440152326032300012702 0ustar00<?php defined('_JEXEC') or die('Restricted access'); /** * @author SOFORT AG (integration@sofort.com) * @link http://www.sofort.com/ * * Copyright (c) 2012 SOFORT AG * * Released under the GNU General Public License (Version 2) * [http://www.gnu.org/licenses/gpl-2.0.html] */ require_once('xml_to_array_exception.php'); require_once('xml_to_array_node.php'); /** * * XML To Array conversion */ class XmlToArray { /** * Holds start tags in a row. * Used for error reporting and counting the current depth * @var array */ private $_tagStack = array(); /** * Reference to the current node the parser is at * @var XmlToArrayNode */ private $_CurrentXmlToArrayNode = null; /** * Object reference for logging purposes * @var Object */ private $_Object = null; /** * stop parsing when maxDepth is exceeded, defaults to no maximum (=0). * * @var $_maxDepth int */ private $_maxDepth = 0; private static $_htmlEntityExceptions = array( '€' => '€', ); /** * 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, '<!--') === false && strpos($data, '<?xml') === false) { if (getenv('sofortDebug') == 'true') { trigger_error('Default data handler used. The data passed was: '.$data, E_USER_WARNING); throw new XmlToArrayException('Unknown error occurred'); } } } /** * Handler for end tags * @param resource $parser a resource handle of the XML parser * @param string $name */ private function _end($parser, $name) { array_pop($this->_tagStack); if ($this->_CurrentXmlToArrayNode instanceof XmlToArrayNode) { $this->_CurrentXmlToArrayNode->setClosed(); $breaker = 0; // step up the stack and close all tags as long as current tag is reached in stack if ($this->_CurrentXmlToArrayNode->getName() != $name) { do { $this->_CurrentXmlToArrayNode = $this->_CurrentXmlToArrayNode->getParentXmlToArrayNode(); $this->_CurrentXmlToArrayNode->setClosed(); if ($breaker > 100) { trigger_error('Had to break out from endless loop.', E_USER_WARNING); break; } ++$breaker; } while($this->_CurrentXmlToArrayNode->getName() != $name); } elseif ($this->_CurrentXmlToArrayNode->hasParentXmlToArrayNode()) { $this->_CurrentXmlToArrayNode = $this->_CurrentXmlToArrayNode->getParentXmlToArrayNode(); } } } /** * * External Entity, no operation * @param unknown_type $parser * @param unknown_type $openEntityNames * @param unknown_type $base * @param unknown_type $systemId * @param unknown_type $publicId */ private function _externalEntity($parser , $openEntityNames , $base , $systemId , $publicId) { // noop } /** * * Notation Decl, no operation * @param unknown_type $parser * @param unknown_type $notationName * @param unknown_type $base * @param unknown_type $systemId * @param unknown_type $publicId */ private function _notationDecl($parser , $notationName , $base , $systemId , $publicId) { // noop } /** * * Processing Instruction, no operation * @param unknown_type $parser * @param unknown_type $target * @param unknown_type $data */ private function _processingInstruction($parser, $target, $data) { // noop } /** * * Unparsed Entity Decl, no operation * @param unknown_type $parser * @param unknown_type $entityName * @param unknown_type $base * @param unknown_type $systemId * @param unknown_type $publicd * @param unknown_type $notationName */ private function _unparsedEntityDecl($parser , $entityName , $base , $systemId , $publicd , $notationName) { // noop } /** * Handler for start tags * @param resource $parser a resource handle of the XML parser * @param string $name * @param array $attributes * @todo add check on max depth */ private function _start($parser, $name, $attributes) { $this->_tagStack[] = $name; if ($this->_maxDepth && count($this->_tagStack) > $this->_maxDepth) { throw new XmlToArrayException('Parse Error: max depth exceeded.', '7005'); } $XmlToArrayNode = new XmlToArrayNode($name, $attributes); if ($this->_CurrentXmlToArrayNode instanceof XmlToArrayNode && $this->_CurrentXmlToArrayNode->isOpen()) { $this->_CurrentXmlToArrayNode->addChild($XmlToArrayNode); $XmlToArrayNode->setParentXmlToArrayNode($this->_CurrentXmlToArrayNode); } $this->_CurrentXmlToArrayNode = $XmlToArrayNode; } } ?>library/helper/xml_to_array_exception.php000064400000000220152326032300014744 0ustar00<?php defined('_JEXEC') or die('Restricted access'); /** * * XML to Array Exception * */ class XmlToArrayException extends Exception {} ?>library/helper/xml_to_array_node.php000064400000006011152326032300013677 0ustar00<?php defined('_JEXEC') or die('Restricted access'); /** * * XML To Array Node * */ class XmlToArrayNode { private $_attributes = array(); private $_children = array(); private $_data = ''; private $_name = ''; private $_open = true; private $_ParentXmlToArrayNode = null; /** * * Constructor for XmlToArrayNode * @param string $name * @param array $attributes */ public function __construct($name, $attributes) { $this->_name = $name; $this->_attributes = $attributes; } /** * * Add a child to collection * @param XmlToArrayNode $XmlToArrayNode */ public function addChild(XmlToArrayNode $XmlToArrayNode) { $this->_children[] = $XmlToArrayNode; } /** * * Getter for data, returns an array */ public function getData() { return $this->_data; } /** * * Getter for name, returns the name */ public function getName() { return $this->_name; } /** * * Getter for parent node */ public function getParentXmlToArrayNode() { return $this->_ParentXmlToArrayNode; } /** * * Does it have any children */ public function hasChildren() { return count($this->_children); } /** * * Does it have a node */ public function hasParentXmlToArrayNode() { return $this->_ParentXmlToArrayNode instanceof XmlToArrayNode; } /** * * Is it open, returns _open */ public function isOpen() { return $this->_open; } /** * Renders nodes as array * @param bool $simpleStructure pass true to get an array without @data and @attributes fields * @throws XmlToArrayException */ public function render($simpleStructure) { $array = array(); $multiples = array(); foreach ($this->_children as $Child) { $multiples[$Child->getName()] = isset($multiples[$Child->getName()]) ? $multiples[$Child->getName()] + 1 : 0; } foreach ($this->_children as $Child) { if ($multiples[$Child->getName()]) { if ($simpleStructure && !$Child->hasChildren()) { $array[$Child->getName()][] = $Child->getData(); } else { $array[$Child->getName()][] = $Child->render($simpleStructure); } } elseif ($simpleStructure && !$Child->hasChildren()) { $array[$Child->getName()] = $Child->getData(); } else { $array[$Child->getName()] = $Child->render($simpleStructure); } } if (!$simpleStructure) { $array['@data'] = $this->_data; $array['@attributes'] = $this->_attributes; } return $this->_ParentXmlToArrayNode instanceof XmlToArrayNode ? $array : array($this->_name => $simpleStructure && !$this->hasChildren() ? $this->getData() : $array); } /** * * Set it to closed */ public function setClosed() { $this->_open = false; } /** * * Setter for variable data * @param string $data */ public function setData($data) { $this->_data .= $data; } /** * * Setter for parent node * @param XmlToArrayNode $XmlToArrayNode */ public function setParentXmlToArrayNode(XmlToArrayNode $XmlToArrayNode) { $this->_ParentXmlToArrayNode = $XmlToArrayNode; } } ?>library/logs/log.txt000064400000000000152326032300010460 0ustar00library/logs/log.xml000064400000004100152326032300010446 0ustar00<?xml version="1.0" encoding="UTF-8" ?> <transactions> <transaction_details> <project_id>156252</project_id> <transaction>71365-156252-51CCAA6F-F942</transaction> <test>1</test> <time>2013-06-27T23:11:34+02:00</time> <status>pending</status> <status_reason>not_credited_yet</status_reason> <status_modified>2013-06-27T23:11:34+02:00</status_modified> <payment_method>su</payment_method> <language_code>fr</language_code> <amount>1.00</amount> <amount_refunded>0.00</amount_refunded> <currency_code>EUR</currency_code> <reasons> <reason>83650107</reason> </reasons> <user_variables/> <sender> <holder>Musterman, Petra</holder> <account_number>2345678902</account_number> <bank_code>88888888</bank_code> <bank_name>Demo Bank</bank_name> <bic>PNAGDE00000</bic> <iban>DE96888888882345678902</iban> <country_code>DE</country_code> </sender> <recipient> <holder>Testaccount SOFORT</holder> <account_number>9999999999</account_number> <bank_code>70011110</bank_code> <bank_name>SOFORT Bank</bank_name> <bic>DEKTDE71002</bic> <iban>DE71700111109999999999</iban> <country_code>DE</country_code> </recipient> <email_customer/> <phone_customer/> <exchange_rate>1.0000</exchange_rate> <costs> <fees>0.00</fees> <currency_code>EUR</currency_code> <exchange_rate>1.0000</exchange_rate> </costs> <su> <consumer_protection>0</consumer_protection> </su> <status_history_items> <status_history_item> <status>pending</status> <status_reason>not_credited_yet</status_reason> <time>2013-06-27T23:11:34+02:00</time> </status_history_item> </status_history_items> </transaction_details> </transactions> library/sofortLib.php000064400000043005152326032300010662 0ustar00<?php defined('_JEXEC') or die('Restricted access'); /** * @mainpage * Base class for SOFORT XML-Api * This class implements basic http authentication and a xml-parser * for parsing response messages * * Requires libcurl and openssl * * 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.php 5773 2012-11-23 16:15:47Z dehn $ * @author SOFORT AG http://www.sofort.com (integration@sofort.com) * */ if(!defined('SOFORTLIB_VERSION')) { define('SOFORTLIB_VERSION','1.5.4'); } require_once dirname(__FILE__).'/sofortLib_abstract.inc.php'; require_once dirname(__FILE__).'/sofortLib_confirm_sr.inc.php'; require_once dirname(__FILE__).'/sofortLib_edit_sr.inc.php'; require_once dirname(__FILE__).'/sofortLib_cancel_sr.inc.php'; require_once dirname(__FILE__).'/sofortLib_ideal_banks.inc.php'; require_once dirname(__FILE__).'/sofortLib_debit.inc.php'; require_once dirname(__FILE__).'/sofortLib_http.inc.php'; require_once dirname(__FILE__).'/sofortLib_multipay.inc.php'; require_once dirname(__FILE__).'/sofortLib_notification.inc.php'; require_once dirname(__FILE__).'/sofortLib_refund.inc.php'; require_once dirname(__FILE__).'/sofortLib_transaction_data.inc.php'; require_once dirname(__FILE__).'/sofortLib_Logger.inc.php'; /** Include any available helper here **/ require_once dirname(__FILE__).'/helper/class.abstract_document.inc.php'; require_once dirname(__FILE__).'/helper/class.invoice.inc.php'; require_once dirname(__FILE__).'/helper/elements/sofort_element.php'; require_once dirname(__FILE__).'/helper/elements/sofort_tag.php'; require_once dirname(__FILE__).'/helper/elements/sofort_html_tag.php'; require_once dirname(__FILE__).'/helper/elements/sofort_text.php'; require_once dirname(__FILE__).'/helper/array_to_xml.php'; require_once dirname(__FILE__).'/helper/xml_to_array.php'; /** * * Basic PHP Library for communication with multipay API and related products of sofort.com * @author payment-network.com * */ class SofortLib { public $errorPos = 'global'; //or su, sr, sv... public $errors = array(); public $warnings = array(); public $enableLogging = false; public $errorCountTemp = 0; public $SofortLibHttp = null; public $SofortLibLogger = null; protected $_apiKey; protected $_userId; protected $_response; protected $_products = array('global', 'sr', 'su', 'sv', 'ls', 'sl', 'sf'); private $_logfilePath = false; /** * Constructor for SofortLib * @param string $apiKey */ public function __construct($userId = '', $apiKey = '', $apiUrl = '') { $this->_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)){ $code = isset($error[0]['code'])? $error[0]['code']:''; $message = isset($error[0]['message'])? $error[0]['message']:''; return 'Error: '.$code.': '.$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<br>\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 .= ")<br>\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<pre class=\"sofort-debug\">\n"; $var = print_r($var, true); if ($showHtml) { $var = str_replace('<', '<', str_replace('>', '>', $var)); } echo $var . "\n</pre>\n"; } } /// @endcond ?>library/sofortLib_Logger.inc.php000064400000003224152326032300012730 0ustar00<?php defined('_JEXEC') or die('Restricted access'); /// \cond /** * A basic implementation of logging mechanism intended for debugging * * 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 11:34:40 +0100 (Fri, 23 Nov 2012) $ * @version SofortLib 1.5.4 $Id: sofortLib_Logger.inc.php 5748 2012-11-23 10:34:40Z Niehoff $ * @author SOFORT AG http://www.sofort.com (integration@sofort.com) * */ class SofortLibLogger { public $fp = null; public $maxFilesize = 1048576; /** * Logs $msg to a file which path is being set by it's unified ressource locator * @param String $message * @param URI $uri */ public function log($message, $uri) { if ($this->logRotate($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 ?>library/sofortLib_abstract.inc.php000064400000004522152326032300013316 0ustar00<?php defined('_JEXEC') or die('Restricted access'); /// \cond /** * interface for SOFORT XML-API * * this class implements basic http authentication and a xml-parser * for parsing response messages * * requires libcurl and openssl * * 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 11:34:40 +0100 (Fri, 23 Nov 2012) $ * @version SofortLib 1.5.4 $Id: sofortLib_abstract.inc.php 5748 2012-11-23 10:34:40Z Niehoff $ * @author SOFORT AG http://www.sofort.com (integration@sofort.com) * @internal * */ class SofortLib_Abstract extends SofortLib { protected $_validateOnly = false; protected $_apiVersion = '1.0'; /** * Override this callback to set the response in the right context * * @protected */ protected function _parseXml() { trigger_error('Missing implementation of parseXml()', E_USER_NOTICE); } /** * send this message and get response * save all warnings - errors are only saved if no payment-url is send from pnag * * @return SofortLib_TransactionData $this */ public function sendRequest() { $requestData[$this->_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 ?>library/sofortLib_cancel_sr.inc.php000064400000010304152326032300013437 0ustar00<?php defined('_JEXEC') or die('Restricted access'); /** * This class is for confirming and changing statuses of invoices * * eg: $confirmObj = new SofortLib_CancelSr('yourapikey'); * * $confirmObj->confirmInvoice('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); } } } } } ?>library/sofortLib_classic_notification.inc.php000064400000011672152326032300015706 0ustar00<?php defined('_JEXEC') or die('Restricted access'); /** * Instance of this class handles the callback of SOFORT to notify about a status change, the classic way to do so * * 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-30 12:10:48 +0100 (Fri, 30 Nov 2012) $ * @version SofortLib 1.5.4 $Id: sofortLib_classic_notification.inc.php 5809 2012-11-30 11:10:48Z rotsch $ * @author SOFORT AG http://www.sofort.com (integration@sofort.com) * */ class SofortLib_ClassicNotification { public $params = array(); private $_password; private $_userId; private $_projectId; private $_hashFunction; private $_hashCheck = false; private $_statusReason; /** * * Constructor for SofortLib_ClassicNotification * @param int $userId * @param int $projectId * @param string $password * @param string $hashFunction */ public function __construct($userId, $projectId, $password, $hashFunction = 'sha1') { $this->_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; } } ?>library/sofortLib_confirm_sr.inc.php000064400000020351152326032300013652 0ustar00<?php defined('_JEXEC') or die('Restricted access'); /** * This class is for confirming and changing statuses of invoices * * eg: $confirmObj = new SofortLib_ConfirmSr('yourapikey'); * * $confirmObj->confirmInvoice('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); } } } } } ?>library/sofortLib_debit.inc.php000064400000013134152326032300012601 0ustar00<?php defined('_JEXEC') or die('Restricted access'); /** * class for handling debit/lastschrift * * 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-02-20 18:28:51 +0100 (Wed, 20 Feb 2013) $ * @version SofortLib 1.5.4 $Id: sofortLib_debit.inc.php 5989 2013-02-20 17:28:51Z niehoff $ * @author SOFORT AG http://www.sofort.com (integration@sofort.com) * */ class SofortLib_Debit extends SofortLib_Abstract { protected $_response = array(); protected $_parameters = array(); protected $_xmlRootTag = 'debitpay'; /** * * Constructor for SofortLib_Debit * @param string $configKey */ public function __construct($configKey = '') { list($userId, $projectId, $apiKey) = explode(':', $configKey); $apiUrl = (getenv('debitApiUrl') != '') ? getenv('debitApiUrl') : 'https://www.sofort.com/payment/debitpay/xml'; parent::__construct($userId, $apiKey, $apiUrl); $this->setProjectId($projectId); $this->setDate(); //set date to today } /** * send this debitpay and get response * @return boolean true if transaction was accepted, false otherwise */ public function sendRequest() { parent::sendRequest(); return $this->isError() === false; } /** * Project id * Id of your Sofortlastschrift project * * @param int $id project id * @return SofortLib_Debit $this */ public function setProjectId($id) { $this->_parameters['project_id'] = $id; return $this; } /** * sets date of this debitpay * automatically called in constructor and set to today * * @param String $date date in Format Y-m-d (eg: 2011-01-20), default: today * @return SofortLib_Debit $this */ public function setDate($date = '') { if (empty($date)) { $date = date('Y-m-d'); } $this->_parameters['date'] = $date; return $this; } /** * set data of account * * @param String $bankCode bank code of bank * @param String $accountNumber account number * @param String $holder Name/Holder of this account * @return SofortLib_Debit $this */ public function setSenderAccount($bankCode, $accountNumber, $holder) { $this->_parameters['sl']['sender'] = array( 'holder' => $holder, 'account_number' => $accountNumber, 'bank_code' => $bankCode, ); return $this; } /** * set data of account * * @param String $accountNumber account number * @return SofortLib_Debit $this */ public function setSenderAccountNumber($accountNumber) { $this->_parameters['sl']['sender']['account_number'] = $accountNumber; return $this; } /** * set data of account * * @param String $bankCode bank code of bank * @return SofortLib_Debit $this */ public function setSenderBankCode($bankCode) { $this->_parameters['sl']['sender']['bank_code'] = $bankCode; return $this; } /** * set data of account * * @param String $name Name/Holder of this account * @return SofortLib_Debit $this */ public function setSenderHolder($name) { $this->_parameters['sl']['sender']['holder'] = $name; return $this; } /** * set amount of this transfer * needs to be a decimal e.g. 2.24 * * @param float $amount amount of this transfer */ public function setAmount($amount) { $this->_parameters['sl']['amount'] = $amount; return $this; } /** * add another user-variable to this transfer * this variable could be a customer-number or similar and will * help you identify this transfer later * * @param String $userVariable max 255 characters * @return SofortLib_Debit $this */ public function addUserVariable($userVariable) { $this->_parameters['sl']['user_variables']['user_variable'][] = $userVariable; return $this; } /** * adds another reason (verwendungszweck) * only first two can be used, 27 characters each * * @param $reason string * @return SofortLib_Debit $this */ public function addReason($reason) { $this->_parameters['sl']['reasons']['reason'][] = $reason; return $this; } /** * set reason (verwendugszweck) of this transfer * two lines possible, 27 characters each * * @param $reason1 * @param $reason2 * @return SofortLib_Debit $this */ public function setReason($reason1, $reason2 = '') { $this->_parameters['sl']['reasons']['reason'][0] = $reason1; $this->_parameters['sl']['reasons']['reason'][1] = $reason2; return $this; } /** * get Transaction-Id of this Transfer * @return String transaction-id */ public function getTransactionId() { return $this->_response['transaction']; } /** * * Getter for payment reason * @param int $i */ public function getReason($i = 0) { return $this->_response['reasons'][$i]; } /** * * Getter for amount */ public function getAmount() { return $this->_response['amount']; } /** * * Getter for user variables * @param int $i */ public function getUserVariable($i = 0) { return $this->_response['user_variables'][$i]; } /** * * Getter for response's date */ public function getDate() { return $this->_response['date']; } /** * Has an error occurred * (non-PHPdoc) * @see SofortLib::isError() */ public function isError($paymentMethod = 'all', $message = ''){ return parent::isError($paymentMethod, $message); } /** * Get the error occurred * (non-PHPdoc) * @see SofortLib::getError() */ public function getError($paymentMethod = 'all', $message = '') { return parent::getError($paymentMethod, $message); } /** * * Getter for response */ public function getResponse() { return $this->_response; } protected function _parseXml() {} } ?>library/sofortLib_edit_sr.inc.php000064400000013471152326032300013147 0ustar00<?php defined('_JEXEC') or die('Restricted access'); /** * This class is for confirming and changing statuses of invoices * * eg: $confirmObj = new SofortLib_EditSr('yourapikey'); * * $confirmObj->confirmInvoice('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); } } } } } ?>library/sofortLib_http.inc.php000064400000015320152326032300012470 0ustar00<?php defined('_JEXEC') or die('Restricted access'); /// \cond /** * Encapsulates communication via HTTP * * requires libcurl and openssl * * 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_http.inc.php 5773 2012-11-23 16:15:47Z dehn $ * @author SOFORT AG http://www.sofort.com (integration@sofort.com) * @internal * */ class SofortLib_Http { public $headers; public $connectionMethod; public $compression; public $proxy; public $url; public $info; public $error; public $httpStatus = 200; protected $_response = ''; /** * * Constructor for SofortLib_Http * @param string $url * @param array $headers * @param boolean $compression * @param string $proxy */ public function __construct($url, $headers, $compression = false, $proxy = '') { $this->url = $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 '<center><div style="width:500px;border: 3px solid #FFEEFF; padding: 3px; background-color: #FFDDFF;font-family: verdana; font-size: 10px"><b>cURL Error</b><br>'.$error.'</div></center>'; die; } /** * * Output an xml error * @param string $code * @param string $message */ private function _xmlError($code, $message) { return '<errors><error><code>0'.$code.'</code><message>'.$message.'</message></error></errors>'; } } /// \endcond ?>library/sofortLib_ideal_banks.inc.php000064400000003066152326032300013751 0ustar00<?php defined('_JEXEC') or die('Restricted access'); require_once dirname(__FILE__).'/sofortLib_abstract.inc.php'; /** * This class encapsulates retrieval of listed banks of the Netherlands * * 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-02-27 11:37:15 +0100 (Wed, 27 Feb 2013) $ * @version SofortLib 1.5.4 $Id: sofortLib_ideal_banks.inc.php 6029 2013-02-27 10:37:15Z rotsch $ * @author SOFORT AG http://www.sofort.com (integration@sofort.com) * */ class SofortLib_iDeal_Banks extends SofortLib_Abstract { protected $_xmlRootTag = 'ideal'; protected $_parameters = array(); protected $_response = array(); private $_banks = array(); /** * * Constructor for SofortLib_iDeal_Banks * @param string $configKey * @param strign $apiUrl */ public function __construct($configKey, $apiUrl = '') { list ($userId, $projectId, $apiKey) = explode(':', $configKey); parent::__construct($userId, $apiKey, $apiUrl.'/banks'); } /** * * Getter for bank list */ public function getBanks() { return $this->_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']; } } } } ?>library/sofortLib_ideal_classic.php000064400000007027152326032300013525 0ustar00<?php defined('_JEXEC') or die('Restricted access'); define('VERSION_CLASSIC','1.2.0'); require_once 'sofortLib_http.inc.php'; require_once 'sofortLib_sofortueberweisung_classic.php'; require_once 'sofortLib_Logger.inc.php'; require_once 'sofortLib_ideal_banks.inc.php'; /** * iDeal_Classic extends Sofortueberweisung_Classic, implementing payment via iDeal * Setup a session within iDeal using the classic api * You get the so called payment-url after successful configuration * Payment is enabled with this url being sent to iDeal * * eg: * $sofort = $sofortLib_iDealClassic = new SofortLib_iDealClassic ($configurationKey, $password, $hashfunction = 'sha1'); * $sofort->getRelatedBanks(); //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; } } ?>library/sofortLib_multipay.inc.php000064400000060413152326032300013360 0ustar00<?php defined('_JEXEC') or die('Restricted access'); /** * Setup a multipay payment session * after the configuration of multiple payment methods you will receive * an url and a transaction id, your customer should be redirected to this * url you can use the transaction id for future reference of this payment * * example by usage: * $objMultipay = new SofortLib_Multipays('my-API-KEY'); * $objMultipay->setSofortueberweisung(); //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; } } ?>library/sofortLib_notification.inc.php000064400000005334152326032300014203 0ustar00<?php defined('_JEXEC') or die('Restricted access'); /** * Instance of this class handles the callback of Payment Network to notify about a status change * * In rare cases notifications might be doubled or even wrong alltogether (if * send by a malicious user). So don't use this to change your status but instead * use the transaction id to query the webservice for detailed data (SofortLib_TransactionData) * * eg: $notificationObj = new SofortLib_Notification(); * * $transactionId = $notificationObj->getNotification(); * * 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); $this->log(__CLASS__.' DATA FROM <- file_get_contents'.var_export($data,true)); $this->log(__CLASS__.' <- FROM _POST '.var_export($_POST,true)); if (empty($data)) { $error = error_get_last(); $this->log(__CLASS__.' <- '.var_export($error,true)); $this->errors['error']['message'] = 'file_get_contents in getNotification returned NULL'; return false; } //we don't really need a huge parser, simply extract the transaction-id if (!preg_match('#<transaction>([0-9a-z-]+)</transaction>#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('#<time>(.+)</time>#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; } } ?>library/sofortLib_refund.inc.php000064400000012474152326032300013003 0ustar00<?php defined('_JEXEC') or die('Restricted access'); /** * class for refund/rueckbuchung * * 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:26:25 +0100 (Fri, 23 Nov 2012) $ * @version SofortLib 1.5.4 $Id: sofortLib_refund.inc.php 5776 2012-11-23 16:26:25Z dehn $ * @author SOFORT AG http://www.sofort.com (integration@sofort.com) * */ class SofortLib_Refund extends SofortLib_Abstract { protected $_parameters = array(); protected $_response = array(); protected $_xmlRootTag = 'refunds'; /** * * Constructor for SofortLib_Refund * @param string $configKey */ public function __construct($configKey = '') { list($userId, $projectId, $apiKey) = explode(':', $configKey); $apiUrl = (getenv('refundApiUrl') != '') ? getenv('refundApiUrl') : 'https://www.sofort.com/payment/refunds'; parent::__construct($userId, $apiKey, $apiUrl); } /** * send this message and get response * @return array transactionid=>status */ 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); } } } } } ?>library/sofortLib_sofortueberweisung_classic.php000064400000020370152326032300016404 0ustar00<?php defined('_JEXEC') or die('Restricted access'); require_once 'sofortLib_classic_notification.inc.php'; /** * Setup a sofortueberweisung.de session using the classic api * after the configuration of the configuration you will receive * an url and a transaction id, your customer should be redirected to this url * * * Called by the sofortLib.php/sofortLib_ideal_classic.php etc. * $sofort->new 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; } } ?>library/sofortLib_transaction_data.inc.php000064400000066021152326032300015033 0ustar00<?php defined('_JEXEC') or die('Restricted access'); /** * This class is for retrieving information about transactions, * you can search by transaction-id or by date * * eg: $transactionDataObj = new SofortLib_TransactionData('yourapikey'); * * $transactionDataObj->setTransaction('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; } } } ?>tmpl/display_payment.php000064400000003422152326032300011430 0ustar00<?php defined ('_JEXEC') or die(); /** * @author Valérie Isaksen * @version $Id: display_payment.php 10153 2019-09-19 15:51:37Z Milbo $ * @package VirtueMart * @subpackage payment * @copyright Copyright (C) 2004 - 2015 Virtuemart Team. All rights reserved. - All rights reserved. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php * VirtueMart is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details. * * http://virtuemart.net */ ?> <input type="radio" name="virtuemart_paymentmethod_id" id="payment_id_<?php echo $viewData['plugin']->virtuemart_paymentmethod_id; ?>" value="<?php echo $viewData['plugin']->virtuemart_paymentmethod_id; ?>" <?php echo $viewData ['checked']; ?>> <label for="payment_id_<?php echo $viewData['plugin']->virtuemart_paymentmethod_id; ?>"> <span class="vmpayment"> <?php if (!empty($viewData['payment_logo'] )) { ?> <span class="vmCartPaymentLogo"><?php echo $viewData ['payment_logo']; ?> </span> <?php } ?> <span class="vmpayment_name"><?php echo $viewData['plugin']->payment_name; ?></span> <?php if (!empty($viewData['plugin']->payment_desc )) { ?> <span class="vmpayment_description"><?php echo $viewData['plugin']->payment_desc; ?></span> <?php } ?> <?php if (!empty($viewData['payment_cost'] )) { ?> <span class="vmpayment_cost"><?php echo vmText::_ ('COM_VIRTUEMART_PLUGIN_COST_DISPLAY') . $viewData['payment_cost'] ?></span> <?php } ?> </span> </label>tmpl/order_fe.php000064400000002150152326032300010010 0ustar00<?php defined ('_JEXEC') or die(); /** * @author Valérie Isaksen * @version $Id: order_fe.php 10153 2019-09-19 15:51:37Z Milbo $ * @package VirtueMart * @subpackage payment * @copyright Copyright (C) 2004 - 2014 Virtuemart Team. All rights reserved. - All rights reserved. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php * VirtueMart is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details. * * http://virtuemart.net */ ?> <div class="payment_name" style="width: 100%"> <?php echo $viewData['paymentName'] ; ?> </div> <div class="response_transaction" style="width: 100%"> <span class="response_transaction_title"><?php echo vmText::_ ('VMPAYMENT_SOFORT_RESPONSE_TRANSACTION'); ?> </span> <?php echo $viewData['paymentInfos']->sofort_response_transaction; ?> </div> tmpl/post_payment.php000064400000003602152326032300010750 0ustar00<?php defined ('_JEXEC') or die(); /** * @author Valérie Isaksen * @version $Id: post_payment.php 10153 2019-09-19 15:51:37Z Milbo $ * @package VirtueMart * @subpackage payment * @copyright Copyright (C) 2004 - 2014 Virtuemart Team. All rights reserved. - All rights reserved. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php * VirtueMart is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details. * * http://virtuemart.net */ ?> <div class="post_payment_order_number" style="width: 100%"> <span class="post_payment_order_number_title"><?php echo vmText::_ ('COM_VIRTUEMART_ORDER_NUMBER'); ?> </span> <?php echo $viewData['order']['details']['BT']->order_number; ?> </div> <?php if ($viewData['paymentInfos']->sofort_response_transaction) { ?> <div class="post_payment_transaction" style="width: 100%"> <span class="post_payment_transaction_title"><?php echo vmText::_ ('VMPAYMENT_SOFORT_RESPONSE_TRANSACTION'); ?> </span> <?php echo $viewData['paymentInfos']->sofort_response_transaction; ?> </div> <?php } ?> <div class="post_payment_order_total" style="width: 100%"> <span class="post_payment_order_total_title"><?php echo vmText::_ ('COM_VIRTUEMART_ORDER_PRINT_TOTAL'); ?> </span> <?php echo $viewData['displayTotalInPaymentCurrency']; ?> </div> <a class="vm-button-correct" href="<?php echo JRoute::_('index.php?option=com_virtuemart&view=orders&layout=details&order_number='.$viewData["order"]['details']['BT']->order_number.'&order_pass='.$viewData["order"]['details']['BT']->order_pass, false)?>"><?php echo vmText::_('COM_VIRTUEMART_ORDER_VIEW_ORDER'); ?></a> tmpl/render_pluginname.php000064400000002271152326032300011725 0ustar00<?php defined ('_JEXEC') or die(); /** * @author Valérie Isaksen * @version $Id: render_pluginname.php 10153 2019-09-19 15:51:37Z Milbo $ * @package VirtueMart * @subpackage payment * @copyright Copyright (C) 2004 - 2014 Virtuemart Team. All rights reserved. - All rights reserved. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php * VirtueMart is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details. * * http://virtuemart.net */ ?> <span class="vmpayment"> <?php if (!empty($viewData['logo'])) { ?> <span class="vmCartPaymentLogo" > <?php echo $viewData['logo'] ?> </span> <?php } ?> <span class="vmpayment_name"><?php echo $viewData['payment_name'] ?> </span> <?php if (!empty($viewData['payment_description'])) { ?> <span class="vmpayment_description"><?php echo $viewData['payment_description'] ?> </span> <?php } ?> </span> tmpl/show_order.php000064400000001625152326032300010404 0ustar00<?php defined ('_JEXEC') or die(); /** * @author Valérie Isaksen * @version $Id: show_order.php 10153 2019-09-19 15:51:37Z Milbo $ * @package VirtueMart * @subpackage payment * @copyright Copyright (C) 2004 - 2014 Virtuemart Team. All rights reserved. - All rights reserved. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php * VirtueMart is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details. * * http://virtuemart.net */ ?> <div id="sofort_show_order"> <div class="sofort_payment_name" style="width: 100%"> <?php echo $viewData['payment_name']; ?> </div> </div>
/home/digilove/public_html/wp-includes/../41423/sofort.tar