PageRenderTime 22ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Quản lý website bán mỹ phẩm PHP/administrator/components/com_virtuemart_allinone/plugins/vmpayment/klarna/klarna/api/klarnapclass.php

https://gitlab.com/phamngsinh/baitaplon_sinhvien
PHP | 546 lines | 167 code | 50 blank | 329 comment | 9 complexity | 042f12098c5a4c781f2c5eb51a1370a8 MD5 | raw file
  1. <?php
  2. defined('_JEXEC') or die('Restricted access');
  3. /**
  4. * Copyright 2010 KLARNA AB. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification, are
  7. * permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this list of
  10. * conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form must reproduce the above copyright notice, this list
  13. * of conditions and the following disclaimer in the documentation and/or other materials
  14. * provided with the distribution.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY KLARNA AB "AS IS" AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  18. * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KLARNA AB OR
  19. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  22. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  24. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. *
  26. * The views and conclusions contained in the software and documentation are those of the
  27. * authors and should not be interpreted as representing official policies, either expressed
  28. * or implied, of KLARNA AB.
  29. *
  30. * @package KlarnaAPI
  31. */
  32. /**
  33. * PClass object used for part payment.
  34. *
  35. * PClasses are used in conjunction with KlarnaCalc to determine part payment costs.
  36. *
  37. * @package KlarnaAPI
  38. * @version 2.1.3
  39. * @since 2011-10-10
  40. * @link http://integration.klarna.com/
  41. * @copyright Copyright (c) 2010 Klarna AB (http://klarna.com)
  42. */
  43. class KlarnaPClass {
  44. /**
  45. * Invoice type/identifier, used for invoice purchases.
  46. *
  47. * @var int
  48. */
  49. const INVOICE = -1;
  50. /**
  51. * Campaign type pclass.
  52. *
  53. * @var int
  54. */
  55. const CAMPAIGN = 0;
  56. /**
  57. * Account type pclass.
  58. *
  59. * @var int
  60. */
  61. const ACCOUNT = 1;
  62. /**
  63. * Special campaign type pclass.<br>
  64. * "Buy now, pay in x month"<br>
  65. *
  66. * @var int
  67. */
  68. const SPECIAL = 2;
  69. /**
  70. * Fixed campaign type pclass
  71. *
  72. * @var int
  73. */
  74. const FIXED = 3;
  75. /**
  76. * Delayed campaign type pclass.<br>
  77. * "Pay in X months"<br>
  78. *
  79. * @var int
  80. */
  81. const DELAY = 4;
  82. /**
  83. * Klarna Mobile type pclass
  84. *
  85. * @var int
  86. */
  87. const MOBILE = 5;
  88. /**
  89. * The description for this PClass.
  90. * HTML entities for special characters.
  91. *
  92. * @ignore Do not show in PHPDoc.
  93. * @var string
  94. */
  95. protected $description;
  96. /**
  97. * Number of months for this PClass.
  98. *
  99. * @ignore Do not show in PHPDoc.
  100. * @var int
  101. */
  102. protected $months;
  103. /**
  104. * PClass starting fee.
  105. *
  106. * @ignore Do not show in PHPDoc.
  107. * @var float
  108. */
  109. protected $startFee;
  110. /**
  111. * PClass invoice/handling fee.
  112. *
  113. * @ignore Do not show in PHPDoc.
  114. * @var float
  115. */
  116. protected $invoiceFee;
  117. /**
  118. * PClass interest rate.
  119. *
  120. * @ignore Do not show in PHPDoc.
  121. * @var float
  122. */
  123. protected $interestRate;
  124. /**
  125. * PClass minimum amount for purchase/product.
  126. *
  127. * @ignore Do not show in PHPDoc.
  128. * @var float
  129. */
  130. protected $minAmount;
  131. /**
  132. * PClass country.
  133. *
  134. * @ignore Do not show in PHPDoc.
  135. * @see KlarnaCountry
  136. * @var int
  137. */
  138. protected $country;
  139. /**
  140. * PClass ID.
  141. *
  142. * @ignore Do not show in PHPDoc.
  143. * @var int
  144. */
  145. protected $id;
  146. /**
  147. * PClass type.
  148. *
  149. * @see self::CAMPAIGN
  150. * @see self::ACCOUNT
  151. * @see self::SPECIAL
  152. * @see self::FIXED
  153. * @see self::DELAY
  154. * @see self::MOBILE
  155. *
  156. * @ignore Do not show in PHPDoc.
  157. * @var int
  158. */
  159. protected $type;
  160. /**
  161. * Expire date / valid until date as unix timestamp.<br>
  162. * Compare it with e.g. $_SERVER['REQUEST_TIME'].<br>
  163. *
  164. * @ignore Do not show in PHPDoc.
  165. * @var int
  166. */
  167. protected $expire;
  168. /**
  169. * Merchant ID / Estore ID.
  170. *
  171. * @ignore Do not show in PHPDoc.
  172. * @var int
  173. */
  174. protected $eid;
  175. /**
  176. * Class constructor
  177. *
  178. * @param null|array $node Associative or numeric array of PClass data.
  179. * @return void
  180. */
  181. public function __construct($arr = null) {
  182. if(is_array($arr) && count($arr) >= 11) {
  183. /**
  184. * Pclass array
  185. * 0 = eid (this is created in the API)
  186. * 1 = id number
  187. * 2 = description
  188. * 3 = amount of months for part payment
  189. * 4 = start fee
  190. * 5 = invoice fee
  191. * 6 = interest rate
  192. * 7 = minimum purchase amount for pclass
  193. * 8 = country
  194. * 9 = type (This is used to determine which pclass-id is an account and a campaign,
  195. * 0 = campaign, 1 = account, 2 = special campaign i.e. x-mas campaign)
  196. * 10 = expire date
  197. */
  198. foreach($arr as $key => $val) {
  199. switch($key) {
  200. case "0":
  201. case "eid":
  202. $this->setEid($val);
  203. break;
  204. case "1":
  205. case "id":
  206. $this->setId($val);
  207. break;
  208. case "2":
  209. case "desc":
  210. case "description":
  211. $this->setDescription($val);
  212. break;
  213. case "3":
  214. case "months":
  215. $this->setMonths($val);
  216. break;
  217. case "4":
  218. case "startfee":
  219. $this->setStartFee($val);
  220. break;
  221. case "5":
  222. case "invoicefee":
  223. $this->setInvoiceFee($val);
  224. break;
  225. case "6":
  226. case "interestrate":
  227. $this->setInterestRate($val);
  228. break;
  229. case "7":
  230. case "minamount":
  231. $this->setMinAmount($val);
  232. break;
  233. case "8":
  234. case "country":
  235. $this->setCountry($val);
  236. break;
  237. case "9":
  238. case "type":
  239. $this->setType($val);
  240. break;
  241. case "10":
  242. case "expire":
  243. $this->setExpire($val);
  244. break;
  245. default:
  246. //Array index not supported.
  247. break;
  248. }
  249. }
  250. }
  251. }
  252. /**
  253. * Returns an associative array mirroring this PClass.
  254. *
  255. * @return array
  256. */
  257. public function toArray() {
  258. return array(
  259. 'eid' => $this->eid,
  260. 'id' => $this->id,
  261. 'description' => $this->description,
  262. 'months' => $this->months,
  263. 'startfee' => $this->startFee,
  264. 'invoicefee' => $this->invoiceFee,
  265. 'interestrate' => $this->interestRate,
  266. 'minamount' => $this->minAmount,
  267. 'country' => $this->country,
  268. 'type' => $this->type,
  269. 'expire' => $this->expire
  270. );
  271. }
  272. /**
  273. * Sets the descriptiton, converts to HTML entities.
  274. *
  275. * @param string $description PClass description.
  276. * @return void
  277. */
  278. public function setDescription($description) {
  279. $this->description = $description;
  280. }
  281. /**
  282. * Sets the number of months.
  283. *
  284. * @param int $months Number of months.
  285. * @return void
  286. */
  287. public function setMonths($months) {
  288. $this->months = intval($months);
  289. }
  290. /**
  291. * Sets the starting fee.
  292. *
  293. * @param float $startFee Starting fee.
  294. * @return void
  295. */
  296. public function setStartFee($startFee) {
  297. $this->startFee = floatval($startFee);
  298. }
  299. /**
  300. * Sets the invoicing/handling fee.
  301. *
  302. * @param float $invoiceFee Invoicing fee.
  303. * @return void
  304. */
  305. public function setInvoiceFee($invoiceFee) {
  306. $this->invoiceFee = floatval($invoiceFee);
  307. }
  308. /**
  309. * Sets the interest rate.
  310. *
  311. * @param float $interestRate Interest rate.
  312. * @return void
  313. */
  314. public function setInterestRate($interestRate) {
  315. $this->interestRate = floatval($interestRate);
  316. }
  317. /**
  318. * Sets the Minimum amount to use this PClass.
  319. *
  320. * @param float $minAmount Minimum amount.
  321. * @return void
  322. */
  323. public function setMinAmount($minAmount) {
  324. $this->minAmount = floatval($minAmount);
  325. }
  326. /**
  327. * Sets the country for this PClass.
  328. *
  329. * @see KlarnaCountry
  330. *
  331. * @param int $country {@link KlarnaCountry} constant.
  332. * @return void
  333. */
  334. public function setCountry($country) {
  335. $this->country = intval($country);
  336. }
  337. /**
  338. * Sets the ID for this pclass.
  339. *
  340. * @param int $id PClass identifier.
  341. * @return void
  342. */
  343. public function setId($id) {
  344. $this->id = intval($id);
  345. }
  346. /**
  347. * Sets the type for this pclass.
  348. *
  349. * @see self::CAMPAIGN
  350. * @see self::ACCOUNT
  351. * @see self::SPECIAL
  352. * @see self::FIXED
  353. * @see self::DELAY
  354. * @see self::MOBILE
  355. *
  356. * @param int $type PClass type identifier.
  357. * @return void
  358. */
  359. public function setType($type) {
  360. $this->type = intval($type);
  361. }
  362. /**
  363. * Returns the ID for this PClass.
  364. *
  365. * @return int PClass identifier.
  366. */
  367. public function getId() {
  368. return $this->id;
  369. }
  370. /**
  371. * Returns this PClass's type.
  372. *
  373. * @see self::CAMPAIGN
  374. * @see self::ACCOUNT
  375. * @see self::SPECIAL
  376. * @see self::FIXED
  377. * @see self::DELAY
  378. * @see self::MOBILE
  379. *
  380. * @return int PClass type identifier.
  381. */
  382. public function getType() {
  383. return $this->type;
  384. }
  385. /**
  386. * Returns the Merchant ID or Estore ID connected to this PClass.
  387. *
  388. * @return int
  389. */
  390. public function getEid() {
  391. return $this->eid;
  392. }
  393. /**
  394. * Merchant ID or Estore ID connected to this PClass.
  395. *
  396. * @param int $eid Merchant ID.
  397. * @return void
  398. */
  399. public function setEid($eid) {
  400. $this->eid = intval($eid);
  401. }
  402. /**
  403. * Checks whether this PClass is valid.
  404. *
  405. * @param int $now Unix timestamp
  406. * @return bool
  407. */
  408. public function isValid($now = null) {
  409. if($this->expire == null || $this->expire == '-' || $this->expire <= 0) {
  410. //No expire, or unset? assume valid.
  411. return true;
  412. }
  413. if($now === null || !is_numeric($now)) {
  414. $now = time();
  415. }
  416. //If now is before expire, it is still valid.
  417. return ($now > $this->expire) ? false : true;
  418. }
  419. /**
  420. * Returns the valid until/expire date unix timestamp.
  421. *
  422. * @return int
  423. */
  424. public function getExpire() {
  425. return $this->expire;
  426. }
  427. /**
  428. * Sets the valid until/expire date unix timestamp.
  429. *
  430. * @param int $expire
  431. * @return void
  432. */
  433. public function setExpire($expire) {
  434. $this->expire = $expire;
  435. }
  436. /**
  437. * Returns the description for this PClass.
  438. *
  439. * <b>Note</b>:<br>
  440. * Encoded with HTML entities.
  441. *
  442. * @return string PClass description.
  443. */
  444. public function getDescription() {
  445. return $this->description;
  446. }
  447. /**
  448. * Returns the number of months for this PClass.
  449. *
  450. * @return int Number of months.
  451. */
  452. public function getMonths() {
  453. return $this->months;
  454. }
  455. /**
  456. * Returns the starting fee for this PClass.
  457. *
  458. * @return float Starting fee.
  459. */
  460. public function getStartFee() {
  461. return $this->startFee;
  462. }
  463. /**
  464. * Returns the invoicing/handling fee for this PClass.
  465. *
  466. * @return float Invoicing fee.
  467. */
  468. public function getInvoiceFee() {
  469. return $this->invoiceFee;
  470. }
  471. /**
  472. * Returns the interest rate for this PClass.
  473. *
  474. * @return float Interest rate.
  475. */
  476. public function getInterestRate() {
  477. return $this->interestRate;
  478. }
  479. /**
  480. * Returns the minimum order/product amount for which this PClass is allowed.
  481. *
  482. * @return float Minimum amount to use this PClass.
  483. */
  484. public function getMinAmount() {
  485. return $this->minAmount;
  486. }
  487. /**
  488. * Returns the country related to this PClass.
  489. *
  490. * @see KlarnaCountry
  491. * @return int {@link KlarnaCountry} constant.
  492. */
  493. public function getCountry() {
  494. return $this->country;
  495. }
  496. } //end KlarnaPClass