11
11
use Magento \Framework \GraphQl \Exception \GraphQlAuthorizationException ;
12
12
use Magento \Framework \GraphQl \Query \ResolverInterface ;
13
13
use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
14
+ use Magento \Framework \Serialize \Serializer \Json as JsonSerializer ;
14
15
use Magento \GraphQl \Model \Query \ContextInterface ;
15
16
use Magento \Vault \Model \PaymentTokenManagement ;
16
17
19
20
*/
20
21
class PaymentTokens implements ResolverInterface
21
22
{
23
+ /**
24
+ * Cart types
25
+ */
26
+ const BASE_CART_TYPES = [
27
+ 'VI ' => 'Visa ' ,
28
+ 'MC ' => 'MasterCard ' ,
29
+ 'AE ' => 'American Express ' ,
30
+ 'DN ' => 'Diners ' ,
31
+ 'DI ' => 'Discover ' ,
32
+ 'JCB ' => 'JCB ' ,
33
+ 'UN ' => 'UnionPay ' ,
34
+ 'MI ' => 'Maestro International ' ,
35
+ 'MD ' => 'Maestro Domestic ' ,
36
+ 'HC ' => 'Hipercard ' ,
37
+ 'ELO ' => 'Elo ' ,
38
+ 'AU ' => 'Aura '
39
+ ];
40
+
22
41
/**
23
42
* @var PaymentTokenManagement
24
43
*/
25
44
private $ paymentTokenManagement ;
26
45
46
+ /**
47
+ * @var JsonSerializer
48
+ */
49
+ private $ serializer ;
50
+
27
51
/**
28
52
* @param PaymentTokenManagement $paymentTokenManagement
53
+ * @param JsonSerializer $serializer
29
54
*/
30
55
public function __construct (
31
- PaymentTokenManagement $ paymentTokenManagement
56
+ PaymentTokenManagement $ paymentTokenManagement ,
57
+ JsonSerializer $ serializer
32
58
) {
33
59
$ this ->paymentTokenManagement = $ paymentTokenManagement ;
60
+ $ this ->serializer = $ serializer ;
34
61
}
35
62
36
63
/**
@@ -56,9 +83,35 @@ public function resolve(
56
83
'public_hash ' => $ token ->getPublicHash (),
57
84
'payment_method_code ' => $ token ->getPaymentMethodCode (),
58
85
'type ' => $ token ->getType (),
59
- 'details ' => $ token ->getTokenDetails (),
86
+ 'details ' => $ this -> getCartDetailsInformation ( $ token ->getTokenDetails () ),
60
87
];
61
88
}
62
89
return ['items ' => $ result ];
63
90
}
91
+
92
+ /**
93
+ * Set full cart type information
94
+ *
95
+ * @param string|null $tokenDetails
96
+ * @return string
97
+ */
98
+ private function getCartDetailsInformation (?string $ tokenDetails ): ?string
99
+ {
100
+ if (is_null ($ tokenDetails )) {
101
+ return $ tokenDetails ;
102
+ }
103
+
104
+ $ cartDetails = $ this ->serializer ->unserialize ($ tokenDetails );
105
+ if (!isset ($ cartDetails ['cc_type ' ])) {
106
+ return $ cartDetails ;
107
+ }
108
+
109
+ $ ccCartType = $ cartDetails ['cc_type ' ];
110
+
111
+ if (array_key_exists ($ ccCartType , self ::BASE_CART_TYPES )) {
112
+ $ cartDetails ['cc_type ' ] = self ::BASE_CART_TYPES [$ ccCartType ];
113
+ }
114
+
115
+ return $ this ->serializer ->serialize ($ cartDetails );
116
+ }
64
117
}
0 commit comments