amex.php
5 days ago
diners.php
5 days ago
discover.php
5 days ago
index.html
5 days ago
jcb.php
5 days ago
mastercard.php
5 days ago
visa.php
5 days ago
mastercard.php
99 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package VikAppointments |
| 4 | * @subpackage core |
| 5 | * @author E4J s.r.l. |
| 6 | * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved. |
| 7 | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 | * @link https://vikwp.com |
| 9 | */ |
| 10 | |
| 11 | // No direct access |
| 12 | defined('ABSPATH') or die('No script kiddies please!'); |
| 13 | |
| 14 | /** |
| 15 | * This class is used to handle MasterCard credit cards. |
| 16 | * |
| 17 | * @since 1.6 |
| 18 | */ |
| 19 | class CCMasterCard extends CreditCard |
| 20 | { |
| 21 | /** |
| 22 | * Checks if the credit card number is valid. |
| 23 | * The card number is valid when its length is equals to 16. |
| 24 | * |
| 25 | * @return boolean True if the card number is valid. |
| 26 | * |
| 27 | * @uses getCardNumber() |
| 28 | * @uses getCardNumberDigits() |
| 29 | */ |
| 30 | public function isCardNumberValid() |
| 31 | { |
| 32 | return strlen($this->getCardNumber()) == $this->getCardNumberDigits(); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Gets the credit card number digits count. |
| 37 | * |
| 38 | * @return integer Return the digits count (16). |
| 39 | */ |
| 40 | public function getCardNumberDigits() |
| 41 | { |
| 42 | return 16; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Formats the credit card number to be more human-readable. |
| 47 | * e.g. 5353 0000 0000 0000 |
| 48 | * |
| 49 | * @return string The formatted card number. |
| 50 | * |
| 51 | * @uses getCardNumber() |
| 52 | */ |
| 53 | public function formatCardNumber() |
| 54 | { |
| 55 | $cc = $this->getCardNumber(); |
| 56 | |
| 57 | return substr($cc, 0, 4) . ' ' . substr($cc, 4, 4) . ' ' . substr($cc, 8, 4) . ' ' . substr($cc, 12, 4); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Gets a masked version of the credit card for privacy. |
| 62 | * e.g. **** **** **** 0000 |
| 63 | * e.g. 5353 0000 0000 **** |
| 64 | * |
| 65 | * @return array A list containing 2 different masked versions of card number. |
| 66 | * |
| 67 | * @uses getCardNumber() |
| 68 | */ |
| 69 | public function getMaskedCardNumber() |
| 70 | { |
| 71 | $cc = $this->getCardNumber(); |
| 72 | |
| 73 | return array( |
| 74 | '**** **** **** ' . substr($cc, 12, 4), |
| 75 | substr($cc, 0, 4) . ' ' . substr($cc, 4, 4) . ' ' . substr($cc, 8, 4) . ' ****', |
| 76 | ); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Gets the MasterCard alias. |
| 81 | * |
| 82 | * @return string The alias of the credit card brand (mastercard). |
| 83 | */ |
| 84 | public function getBrandAlias() |
| 85 | { |
| 86 | return CreditCard::MASTER_CARD; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Gets the name of the credit card brand. |
| 91 | * |
| 92 | * @return string The name of the credit card brand (MasterCard). |
| 93 | */ |
| 94 | public function getBrandName() |
| 95 | { |
| 96 | return 'MasterCard'; |
| 97 | } |
| 98 | } |
| 99 |