Skip to content

Commit 72afaec

Browse files
authored
Merge pull request #50 from unzerdev/develop
Develop
2 parents 169cf8d + a9a0581 commit 72afaec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2487
-97
lines changed

Block/Customer/CardsRenderer.php

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Unzer\PAPI\Block\Customer;
5+
6+
use IntlDateFormatter;
7+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
8+
use Magento\Framework\View\Element\Template;
9+
use Magento\Framework\View\Element\Template\Context;
10+
use Magento\Payment\Model\CcConfigProvider;
11+
use Magento\Vault\Api\Data\PaymentTokenInterface;
12+
use Magento\Vault\Block\AbstractCardRenderer;
13+
use Unzer\PAPI\Model\Config;
14+
use Unzer\PAPI\Model\System\Config\CreditCardBrand;
15+
16+
/**
17+
* Cards Renderer
18+
*
19+
* Copyright (C) 2021 - today Unzer GmbH
20+
*
21+
* Licensed under the Apache License, Version 2.0 (the "License");
22+
* you may not use this file except in compliance with the License.
23+
* You may obtain a copy of the License at
24+
*
25+
* http://www.apache.org/licenses/LICENSE-2.0
26+
*
27+
* Unless required by applicable law or agreed to in writing, software
28+
* distributed under the License is distributed on an "AS IS" BASIS,
29+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30+
* See the License for the specific language governing permissions and
31+
* limitations under the License.
32+
*
33+
* @link https://docs.unzer.com/
34+
*/
35+
class CardsRenderer extends AbstractCardRenderer
36+
{
37+
/**
38+
* @var TimezoneInterface
39+
*/
40+
private TimezoneInterface $timezoneInterface;
41+
42+
/**
43+
* @var CreditCardBrand
44+
*/
45+
private CreditCardBrand $creditCardBrand;
46+
47+
/**
48+
* Constructor
49+
*
50+
* @param Context $context
51+
* @param CcConfigProvider $iconsProvider
52+
* @param TimezoneInterface $timezoneInterface
53+
* @param CreditCardBrand $creditCardBrand
54+
* @param array $data
55+
*/
56+
public function __construct(
57+
Template\Context $context,
58+
CcConfigProvider $iconsProvider,
59+
TimezoneInterface $timezoneInterface,
60+
CreditCardBrand $creditCardBrand,
61+
array $data = []
62+
) {
63+
parent::__construct($context, $iconsProvider, $data);
64+
$this->timezoneInterface = $timezoneInterface;
65+
$this->creditCardBrand = $creditCardBrand;
66+
}
67+
68+
/**
69+
* Can render specified token
70+
*
71+
* @param PaymentTokenInterface $token
72+
* @return boolean
73+
*/
74+
public function canRender(PaymentTokenInterface $token): bool
75+
{
76+
return $token->getPaymentMethodCode() === Config::METHOD_CARDS;
77+
}
78+
79+
/**
80+
* Get Number Last 4 digits
81+
*
82+
* @return string
83+
*/
84+
public function getNumberLast4Digits(): string
85+
{
86+
return $this->getTokenDetails()['maskedCC'];
87+
}
88+
89+
/**
90+
* Get Expiration Date
91+
*
92+
* @return string
93+
*/
94+
public function getExpDate(): string
95+
{
96+
return $this->timezoneInterface->formatDate(
97+
$this->getTokenDetails()['expirationDate'],
98+
IntlDateFormatter::LONG
99+
);
100+
}
101+
102+
/**
103+
* Get Brand
104+
*
105+
* @return string
106+
*/
107+
public function getBrand(): string
108+
{
109+
return $this->creditCardBrand->getBrandByType($this->getTokenDetails()['type']);
110+
}
111+
112+
/**
113+
* Get Icon Url
114+
*
115+
* @return string
116+
*/
117+
public function getIconUrl(): string
118+
{
119+
return $this->getIconForType($this->getTokenDetails()['type'])['url'];
120+
}
121+
122+
/**
123+
* Get Icon Height
124+
*
125+
* @return int
126+
*/
127+
public function getIconHeight(): int
128+
{
129+
return $this->getIconForType($this->getTokenDetails()['type'])['height'];
130+
}
131+
132+
/**
133+
* Get Icon Width
134+
*
135+
* @return int
136+
*/
137+
public function getIconWidth(): int
138+
{
139+
return $this->getIconForType($this->getTokenDetails()['type'])['width'];
140+
}
141+
}

Block/Customer/PaypalRenderer.php

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Unzer\PAPI\Block\Customer;
5+
6+
use Unzer\PAPI\Model\Config;
7+
use Magento\Framework\View\Element\Template;
8+
use Magento\Vault\Api\Data\PaymentTokenInterface;
9+
use Magento\Vault\Block\AbstractTokenRenderer;
10+
11+
/**
12+
* PayPal Renderer
13+
*
14+
* Copyright (C) 2021 - today Unzer GmbH
15+
*
16+
* Licensed under the Apache License, Version 2.0 (the "License");
17+
* you may not use this file except in compliance with the License.
18+
* You may obtain a copy of the License at
19+
*
20+
* http://www.apache.org/licenses/LICENSE-2.0
21+
*
22+
* Unless required by applicable law or agreed to in writing, software
23+
* distributed under the License is distributed on an "AS IS" BASIS,
24+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25+
* See the License for the specific language governing permissions and
26+
* limitations under the License.
27+
*
28+
* @link https://docs.unzer.com/
29+
*/
30+
class PaypalRenderer extends AbstractTokenRenderer
31+
{
32+
/**
33+
* @var Config
34+
*/
35+
private Config $config;
36+
37+
/**
38+
* Initialize dependencies.
39+
*
40+
* @param Template\Context $context
41+
* @param Config $config
42+
* @param array $data
43+
*/
44+
public function __construct(
45+
Template\Context $context,
46+
Config $config,
47+
array $data = []
48+
) {
49+
parent::__construct($context, $data);
50+
$this->config = $config;
51+
}
52+
53+
/**
54+
* @inheritdoc
55+
*/
56+
public function getIconUrl()
57+
{
58+
return ''; //$this->config->getPayPalIcon()['url'];
59+
}
60+
61+
/**
62+
* @inheritdoc
63+
*/
64+
public function getIconHeight()
65+
{
66+
return ''; //$this->config->getPayPalIcon()['height'];
67+
}
68+
69+
/**
70+
* @inheritdoc
71+
*/
72+
public function getIconWidth()
73+
{
74+
return ''; //$this->config->getPayPalIcon()['width'];
75+
}
76+
77+
/**
78+
* Can render specified token
79+
*
80+
* @param PaymentTokenInterface $token
81+
* @return boolean
82+
*/
83+
public function canRender(PaymentTokenInterface $token): bool
84+
{
85+
return $token->getPaymentMethodCode() === Config::METHOD_PAYPAL;
86+
}
87+
88+
/**
89+
* Get email of PayPal payer
90+
*
91+
* @return string
92+
*/
93+
public function getPayerEmail(): string
94+
{
95+
return $this->getTokenDetails()['payerEmail'] ?? (string)__('Unknown Email Address');
96+
}
97+
}

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,18 @@ All notable changes to this project will be documented in this file.
33

44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
55

6+
## [2.2.0](https://github.com/unzerdev/magento2/compare/2.1.1..2.2.0)
7+
8+
### Added
9+
* Magento Vault support to credit card and PayPal payment methods
10+
### Changed
11+
* requirement of Unzer PHP SDK to use their new 3-digit versioning
12+
### Removed
13+
* support for end-of-life PHP Versions 7.1, 7.2, 7.3
14+
615
## [2.1.1](https://github.com/unzerdev/magento2/compare/2.1.0..2.1.1)
716

817
### Fixed
9-
1018
* Checkout Problems with Bundle Products and Discounts
1119

1220
## [2.1.0](https://github.com/unzerdev/magento2/compare/2.0.0..2.1.0)

0 commit comments

Comments
 (0)