CardStore Class
The CardStore class is part of the myPOS IPC SDK and is used to store card details securely. It extends the core Base class and supports optional card verification, currency configuration, and validation logic.
This class helps you tokenize and securely save card data for future payments. You can also choose to verify the card (e.g., using a small authorization amount) before storing.
Class Information
- Namespace:
Mypos\IPC - Located at:
CardStore.php - Extends:
Mypos\IPC\Base - Known Subclasses:
Mypos\IPC\IAStoreCardMypos\IPC\IAStoredCardUpdate
Method Summary
| Method | Return Type | Description |
|---|---|---|
getAmount() | float | Gets the amount used for card verification, if enabled. |
setAmount(float $amount) | void | Sets the amount for verification during card storage. |
setCardVerification(int $cardVerification) | void | Enables or disables card verification (1 = No, 2 = Yes). |
getCardVerification() | int | Returns whether card verification is enabled. |
getCurrency() | string | Gets the currency code (ISO 4217) used for verification. |
setCurrency(string $currency) | CardStore | Sets the transaction currency for card verification. |
validate() | bool | Validates all required fields before the card is stored. |
Throws Mypos\IPC\IPC_Exception on failure.
Inherited Methods from Base
The CardStore class inherits all basic API interaction methods from Base, such as:
_addPostParam()getOutputFormat()setOutputFormat()processPost()processHtmlPost()getCnf()setCnf()isValidSignature()
Card Verification Constants
| Constant | Value | Description |
|---|---|---|
CARD_VERIFICATION_NO | 1 | Do not verify the card before storing. |
CARD_VERIFICATION_YES | 2 | Perform verification before storing the card. |
Example Usage
<?php
namespace Mypos\IPC;
abstract class CardStore extends Base
{
const CARD_VERIFICATION_NO = 1;
const CARD_VERIFICATION_YES = 2;
private $currency = 'EUR', $amount, $cardVerification;
/**
* Amount of the transaction
* Used in the request if CardVerification = CARD_VERIFICATION_YES.
*
* @return float
*/
public function getAmount()
{
return $this->amount;
}
/**
* Amount of the transaction.
* Used in the request if CardVerification = CARD_VERIFICATION_YES.
*
* @param float $amount
*/
public function setAmount($amount)
{
$this->amount = $amount;
}
/**
* Specify whether the inputted card data to be verified or not before storing
*
* @param int $cardVerification
*/
public function setCardVerification($cardVerification)
{
$this->cardVerification = $cardVerification;
}
/**
* Validate all set purchase details
*
* @return boolean
* @throws IPC_Exception
*/
public function validate()
{
if ($this->getCardVerification() == null || !in_array($this->getCardVerification(), [
self::CARD_VERIFICATION_NO,
self::CARD_VERIFICATION_YES,
])) {
throw new IPC_Exception('Invalid card verification');
}
if ($this->getCardVerification() == self::CARD_VERIFICATION_YES) {
if ($this->getCurrency() === null || strpos(Defines::AVL_CURRENCIES, $this->getCurrency()) === false) {
throw new IPC_Exception('Invalid currency');
}
}
return true;
}
/**
* Specify whether the inputted card data to be verified or not before storing
*
* @return int
*/
public function getCardVerification()
{
return $this->cardVerification;
}
/**
* ISO-4217 Three letter currency code
* Used in the request if CardVerification = CARD_VERIFICATION_YES.
*
* @return string
*/
public function getCurrency()
{
return $this->currency;
}
/**
* ISO-4217 Three letter currency code
* Used in the request if CardVerification = CARD_VERIFICATION_YES.
*
* @param string $currency
*
* @return CardStore
*/
public function setCurrency($currency)
{
$this->currency = $currency;
return $this;
}
}
Use Case
Use the CardStore class when:
- You want to save a customer's card for future use.
- You want to verify the card by charging and possibly refunding a small amount (optional).
- You need to tokenize cards securely within PCI-compliant infrastructure.