PageRenderTime 27ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/work/plugins/vmpayment/sofort/sofort/library/sofortLib_confirm_sr.inc.php

https://bitbucket.org/programmerlab/ourteam.co.in
PHP | 312 lines | 153 code | 49 blank | 110 comment | 23 complexity | 16391f10cc3f4b9083228e79298cf7ad MD5 | raw file
Possible License(s): GPL-2.0, GPL-3.0, 0BSD, MIT, LGPL-2.1
  1. <?php
  2. defined('_JEXEC') or die('Restricted access');
  3. /**
  4. * This class is for confirming and changing statuses of invoices
  5. *
  6. * eg: $confirmObj = new SofortLib_ConfirmSr('yourapikey');
  7. *
  8. * $confirmObj->confirmInvoice('1234-456-789654-31321')->sendRequest();
  9. *
  10. * Copyright (c) 2012 SOFORT AG
  11. *
  12. * Released under the GNU General Public License (Version 2)
  13. * [http://www.gnu.org/licenses/gpl-2.0.html]
  14. *
  15. * $Date: 2012-11-23 17:15:47 +0100 (Fri, 23 Nov 2012) $
  16. * @version SofortLib 1.5.4 $Id: sofortLib_confirm_sr.inc.php 5773 2012-11-23 16:15:47Z dehn $
  17. * @author SOFORT AG http://www.sofort.com (integration@sofort.com)
  18. *
  19. */
  20. class SofortLib_ConfirmSr extends SofortLib_Abstract {
  21. protected $_parameters = array();
  22. protected $_invoices = array();
  23. protected $_response = array();
  24. protected $_xmlRootTag = 'confirm_sr';
  25. protected $_apiVersion = '2.0';
  26. private $_file;
  27. /**
  28. * create new confirm object
  29. *
  30. * @param String $apikey your API-key
  31. */
  32. public function __construct($configKey = '') {
  33. list($userId, $projectId, $apiKey) = explode(':', $configKey);
  34. $apiUrl = (getenv('sofortApiUrl') != '') ? getenv('sofortApiUrl') : 'https://api.sofort.com/api/xml';
  35. parent::__construct($userId, $apiKey, $apiUrl);
  36. }
  37. /**
  38. * Set the transaction you want to confirm
  39. * @param String $transaction Transaction Id
  40. * @return SofortLib_ConfirmSr
  41. */
  42. public function setTransaction($transaction, $invoice = 0) {
  43. if ($this->_apiVersion == 1) {
  44. $this->_parameters['transaction'] = $transaction;
  45. } else {
  46. $this->_parameters['invoice'][$invoice]['transaction'] = $transaction;
  47. }
  48. return $this;
  49. }
  50. /**
  51. *
  52. * Setter for invoice number
  53. * @param String $invoiceNumber
  54. * @param object $invoice
  55. */
  56. public function setInvoiceNumber($invoiceNumber, $invoice = 0) {
  57. $this->setApiVersion('2.0');
  58. $this->_parameters['invoice'][$invoice]['invoice_number'] = $invoiceNumber;
  59. return $this;
  60. }
  61. /**
  62. *
  63. * Setter for costumer numer
  64. * @param string $customerNumber
  65. * @param int $invoice
  66. */
  67. public function setCustomerNumber($customerNumber, $invoice = 0) {
  68. $this->setApiVersion('2.0');
  69. $this->_parameters['invoice'][$invoice]['customer_id'] = $customerNumber;
  70. return $this;
  71. }
  72. /**
  73. *
  74. * Setter for order number
  75. * @param string $orderNumber
  76. * @param unknown_type $invoice
  77. */
  78. public function setOrderNumber($orderNumber, $invoice = 0) {
  79. $this->setApiVersion('2.0');
  80. $this->_parameters['invoice'][$invoice]['order_id'] = $orderNumber;
  81. return $this;
  82. }
  83. /**
  84. * set a comment for refunds
  85. * just useable with api version 1.0
  86. * @see SofortLib_EditSr
  87. * @deprecated
  88. * @param string $arg
  89. */
  90. public function setComment($comment) {
  91. $this->setApiVersion('1.0');
  92. $this->_parameters['comment'] = $comment;
  93. return $this;
  94. }
  95. /**
  96. * add one item to the cart if you want to change the invoice
  97. * just useable with api version 1.0
  98. * @see SofortLib_EditSr
  99. * @deprecated
  100. * @param string $productNumber product number, EAN code, ISBN number or similar
  101. * @param string $title description of this title
  102. * @param double $unit_price gross price of one item
  103. * @param int $productType product type number see manual
  104. * @param string $description additional description of this item
  105. * @param int $quantity default 1
  106. * @param int $tax tax in percent, default 19
  107. */
  108. public function addItem($itemId, $productNumber, $productType, $title, $description, $quantity, $unitPrice, $tax) {
  109. $this->setApiVersion('1.0');
  110. $unitPrice = number_format($unitPrice, 2, '.', '');
  111. $tax = number_format($tax, 2, '.', '');
  112. $quantity = intval($quantity);
  113. $this->_parameters['items']['item'][] = array(
  114. 'item_id' => $itemId,
  115. 'product_number' => $productNumber,
  116. 'product_type' => $productType,
  117. 'title' => $title,
  118. 'description' => $description,
  119. 'quantity' => $quantity,
  120. 'unit_price' => $unitPrice,
  121. 'tax' => $tax,
  122. );
  123. }
  124. /**
  125. * TODO: implement removal of items
  126. * @see SofortLib_EditSr
  127. * @deprecated
  128. * @param $productId
  129. * @param $quantity
  130. */
  131. public function removeItem($productId, $quantity = 0) {
  132. $this->setApiVersion('1.0');
  133. if (!isset($this->_parameters['items']['item'][$productId])) {
  134. return false;
  135. } elseif ($quantity = -1) {
  136. unset($this->_parameters['items']['item'][$productId]);
  137. return true;
  138. }
  139. //$this->_parameters['items']['item'][$productId]['quantity'] = $quantity;
  140. return true;
  141. }
  142. /**
  143. *
  144. * just useable with api version 1.0
  145. * @see SofortLib_EditSr
  146. * @deprecated
  147. * @param array $cartItems
  148. */
  149. function updateCart($cartItems = array()) {
  150. $this->setApiVersion('1.0');
  151. if (empty($cartItems)) {
  152. $this->_parameters['items'] = array();
  153. return $this;
  154. }
  155. $i = 0;
  156. foreach ($cartItems as $cartItem) {
  157. $this->_parameters['items']['item'][$i]['item_id'] = $cartItem['itemId'];
  158. $this->_parameters['items']['item'][$i]['product_number'] = $cartItem['productNumber'];
  159. $this->_parameters['items']['item'][$i]['title'] = $cartItem['title'];
  160. $this->_parameters['items']['item'][$i]['description'] = $cartItem['description'];
  161. $this->_parameters['items']['item'][$i]['quantity'] = $cartItem['quantity'];
  162. $this->_parameters['items']['item'][$i]['unit_price'] = number_format($cartItem['unitPrice'], 2, '.', '') ;
  163. $this->_parameters['items']['item'][$i]['tax'] = $cartItem['tax'];
  164. $i++;
  165. }
  166. return $this;
  167. }
  168. /**
  169. * cancel the invoice
  170. * just useable with api version 1.0
  171. * @see SofortLib_EditSr
  172. * @deprecated
  173. * @param string $transaction the transaction id
  174. * @return SofortLib_ConfirmSr
  175. */
  176. public function cancelInvoice($transaction = '') {
  177. $this->setApiVersion('1.0');
  178. if (empty($transaction) && array_key_exists('transaction', $this->_parameters)) {
  179. $transaction = $this->_parameters['transaction'];
  180. }
  181. if (!empty($transaction)) {
  182. $this->_parameters = NULL;
  183. $this->_parameters['transaction'] = $transaction;
  184. $this->_parameters['items'] = array();
  185. }
  186. return $this;
  187. }
  188. /**
  189. * confirm the invoice
  190. * @param string $transaction the transaction id
  191. * @return SofortLib_ConfirmSr
  192. */
  193. public function confirmInvoice($transaction = '') {
  194. if ($this->_apiVersion == 1) {
  195. if (empty($transaction) && array_key_exists('transaction', $this->_parameters)) {
  196. $transaction = $this->_parameters['transaction'];
  197. }
  198. if (!empty($transaction)) {
  199. $this->_parameters = NULL;
  200. $this->_parameters['transaction'] = $transaction;
  201. }
  202. } else {
  203. if (!empty($transaction)) {
  204. $this->_parameters['invoice'][0]['transaction'] = $transaction;
  205. }
  206. }
  207. return $this;
  208. }
  209. /**
  210. * after you you changed/confirmed an invoice you
  211. * can download the new invoice-pdf with this function
  212. * @return string url
  213. */
  214. public function getInvoiceUrl($i = 0) {
  215. return isset($this->_response['invoice'][$i]['download_url']['@data']) ? $this->_response['invoice'][$i]['download_url']['@data'] : '';
  216. }
  217. /**
  218. * Parse the XML (override)
  219. * (non-PHPdoc)
  220. * @see SofortLib_Abstract::_parseXml()
  221. */
  222. protected function _parseXml() {}
  223. /**
  224. * Handle errors if occurred
  225. * (non-PHPdoc)
  226. * @see SofortLib::_handleErrors()
  227. */
  228. protected function _handleErrors() {
  229. if ($this->_apiVersion == 1) {
  230. return parent::_handleErrors();
  231. }
  232. if (!isset($this->_response['invoices']['invoice'][0])) {
  233. $tmp = $this->_response['invoices']['invoice'];
  234. unset($this->_response['invoices']['invoice']);
  235. $this->_response['invoices']['invoice'][0] = $tmp;
  236. }
  237. foreach ($this->_response['invoices']['invoice'] as $response) {
  238. //handle errors
  239. if (isset($response['errors']['error'])) {
  240. if (!isset($response['errors']['error'][0])) {
  241. $tmp = $response['errors']['error'];
  242. unset($response['errors']['error']);
  243. $response['errors']['error'][0] = $tmp;
  244. }
  245. foreach ($response['errors']['error'] as $error) {
  246. $this->errors['sr'][] = $this->_getErrorBlock($error);
  247. }
  248. }
  249. //handle warnings
  250. if (isset($response['warnings']['warning'])) {
  251. if (!isset($response['warnings']['warning'][0])) {
  252. $tmp = $response['warnings']['warning'];
  253. unset($response['warnings']['warning']);
  254. $response['warnings']['warning'][0] = $tmp;
  255. }
  256. foreach ($response['warnings']['warning'] as $error) {
  257. $this->warnings['sr'][] = $this->_getErrorBlock($error);
  258. }
  259. }
  260. }
  261. }
  262. }
  263. ?>