1 | <?php |
||
2 | /** |
||
3 | * Copyright © Getnet. All rights reserved. |
||
4 | * |
||
5 | * @author Bruno Elisei <[email protected]> |
||
6 | * See LICENSE for license details. |
||
7 | */ |
||
8 | |||
9 | declare(strict_types=1); |
||
10 | |||
11 | namespace Getnet\PaymentMagento\Plugin; |
||
12 | |||
13 | use Magento\Sales\Api\Data\OrderPaymentInterface; |
||
14 | use Magento\Vault\Api\Data\PaymentTokenInterface; |
||
15 | use Magento\Vault\Api\PaymentTokenManagementInterface; |
||
16 | |||
17 | /** |
||
18 | * Class Payment Token Management Interface - Corrected duplicity. |
||
19 | */ |
||
20 | class PaymentToken |
||
21 | { |
||
22 | /** |
||
23 | * Around Save Token With Payment Link. |
||
24 | * |
||
25 | * @param PaymentTokenManagementInterface $paymentTokenManagement |
||
26 | * @param callable $proceed |
||
27 | * @param PaymentTokenInterface $token |
||
28 | * @param OrderPaymentInterface $payment |
||
29 | * |
||
30 | * @return $proceed |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
31 | */ |
||
32 | public function aroundSaveTokenWithPaymentLink( |
||
33 | PaymentTokenManagementInterface $paymentTokenManagement, |
||
34 | callable $proceed, |
||
35 | PaymentTokenInterface $token, |
||
36 | OrderPaymentInterface $payment |
||
37 | ): bool { |
||
38 | $order = $payment->getOrder(); |
||
39 | |||
40 | if ($order->getCustomerIsGuest()) { |
||
41 | return $proceed($token, $payment); |
||
42 | } |
||
43 | |||
44 | $existingToken = $paymentTokenManagement->getByGatewayToken( |
||
45 | $token->getGatewayToken(), |
||
46 | $payment->getMethodInstance()->getCode(), |
||
47 | $order->getCustomerId() |
||
48 | ); |
||
49 | |||
50 | if ($existingToken === null) { |
||
51 | return $proceed($token, $payment); |
||
52 | } |
||
53 | |||
54 | $existingToken->addData($token->getData()); |
||
55 | |||
56 | return $proceed($existingToken, $payment); |
||
57 | } |
||
58 | } |
||
59 |