123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Payment\Block\Info;
- /**
- * Credit card generic payment info
- *
- * @api
- * @since 100.0.2
- */
- class Cc extends \Magento\Payment\Block\Info
- {
- /**
- * Payment config model
- *
- * @var \Magento\Payment\Model\Config
- */
- protected $_paymentConfig;
- /**
- * @param \Magento\Framework\View\Element\Template\Context $context
- * @param \Magento\Payment\Model\Config $paymentConfig
- * @param array $data
- */
- public function __construct(
- \Magento\Framework\View\Element\Template\Context $context,
- \Magento\Payment\Model\Config $paymentConfig,
- array $data = []
- ) {
- parent::__construct($context, $data);
- $this->_paymentConfig = $paymentConfig;
- }
- /**
- * Retrieve credit card type name
- *
- * @return string
- */
- public function getCcTypeName()
- {
- $types = $this->_paymentConfig->getCcTypes();
- $ccType = $this->getInfo()->getCcType();
- if (isset($types[$ccType])) {
- return $types[$ccType];
- }
- return empty($ccType) ? __('N/A') : $ccType;
- }
- /**
- * Whether current payment method has credit card expiration info
- *
- * @return bool
- */
- public function hasCcExpDate()
- {
- return (int)$this->getInfo()->getCcExpMonth() || (int)$this->getInfo()->getCcExpYear();
- }
- /**
- * Retrieve CC expiration month
- *
- * @return string
- */
- public function getCcExpMonth()
- {
- $month = $this->getInfo()->getCcExpMonth();
- if ($month < 10) {
- $month = '0' . $month;
- }
- return $month;
- }
- /**
- * Retrieve CC expiration date
- *
- * @return \DateTime
- */
- public function getCcExpDate()
- {
- $date = new \DateTime('now', new \DateTimeZone($this->_localeDate->getConfigTimezone()));
- $date->setDate($this->getInfo()->getCcExpYear(), $this->getInfo()->getCcExpMonth() + 1, 0);
- return $date;
- }
- /**
- * Prepare credit card related payment info
- *
- * @param \Magento\Framework\DataObject|array $transport
- * @return \Magento\Framework\DataObject
- */
- protected function _prepareSpecificInformation($transport = null)
- {
- if (null !== $this->_paymentSpecificInformation) {
- return $this->_paymentSpecificInformation;
- }
- $transport = parent::_prepareSpecificInformation($transport);
- $data = [];
- if ($ccType = $this->getCcTypeName()) {
- $data[(string)__('Credit Card Type')] = $ccType;
- }
- if ($this->getInfo()->getCcLast4()) {
- $data[(string)__('Credit Card Number')] = sprintf('xxxx-%s', $this->getInfo()->getCcLast4());
- }
- if (!$this->getIsSecureMode()) {
- if ($ccSsIssue = $this->getInfo()->getCcSsIssue()) {
- $data[(string)__('Switch/Solo/Maestro Issue Number')] = $ccSsIssue;
- }
- $year = $this->getInfo()->getCcSsStartYear();
- $month = $this->getInfo()->getCcSsStartMonth();
- if ($year && $month) {
- $data[(string)__('Switch/Solo/Maestro Start Date')] = $this->_formatCardDate($year, $month);
- }
- }
- return $transport->setData(array_merge($data, $transport->getData()));
- }
- /**
- * Format year/month on the credit card
- *
- * @param string $year
- * @param string $month
- * @return string
- */
- protected function _formatCardDate($year, $month)
- {
- return sprintf('%s/%s', sprintf('%02d', $month), $year);
- }
- }
|