18
18
use Magento \QuoteGraphQl \Model \Cart \GetCartForUser ;
19
19
use Magento \Quote \Api \Data \PaymentInterfaceFactory ;
20
20
use Magento \Quote \Api \PaymentMethodManagementInterface ;
21
+ use Magento \QuoteGraphQl \Model \Cart \Payment \AdditionalDataProviderPool ;
22
+ use Magento \Framework \App \ObjectManager ;
21
23
22
24
/**
23
25
* Mutation resolver for setting payment method for shopping cart
@@ -39,19 +41,28 @@ class SetPaymentMethodOnCart implements ResolverInterface
39
41
*/
40
42
private $ paymentFactory ;
41
43
44
+ /**
45
+ * @var AdditionalDataProviderPool
46
+ */
47
+ private $ additionalDataProviderPool ;
48
+
42
49
/**
43
50
* @param GetCartForUser $getCartForUser
44
51
* @param PaymentMethodManagementInterface $paymentMethodManagement
45
52
* @param PaymentInterfaceFactory $paymentFactory
53
+ * @param AdditionalDataProviderPool $additionalDataProviderPool
46
54
*/
47
55
public function __construct (
48
56
GetCartForUser $ getCartForUser ,
49
57
PaymentMethodManagementInterface $ paymentMethodManagement ,
50
- PaymentInterfaceFactory $ paymentFactory
58
+ PaymentInterfaceFactory $ paymentFactory ,
59
+ AdditionalDataProviderPool $ additionalDataProviderPool = null
51
60
) {
52
61
$ this ->getCartForUser = $ getCartForUser ;
53
62
$ this ->paymentMethodManagement = $ paymentMethodManagement ;
54
63
$ this ->paymentFactory = $ paymentFactory ;
64
+ $ this ->additionalDataProviderPool = $ additionalDataProviderPool
65
+ ?: ObjectManager::getInstance ()->get (AdditionalDataProviderPool::class);
55
66
}
56
67
57
68
/**
@@ -70,16 +81,17 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
70
81
$ paymentMethodCode = $ args ['input ' ]['payment_method ' ]['code ' ];
71
82
72
83
$ poNumber = $ args ['input ' ]['payment_method ' ]['purchase_order_number ' ] ?? null ;
73
- $ additionalData = $ args[ ' input ' ][ ' payment_method ' ][ ' additional_data ' ] ?? [];
84
+ $ additionalData = $ this -> additionalDataProviderPool -> getData ( $ paymentMethodCode , $ args) ?? [];
74
85
75
86
$ cart = $ this ->getCartForUser ->execute ($ maskedCartId , $ context ->getUserId ());
76
- $ payment = $ this ->paymentFactory ->create ([
87
+ $ payment = $ this ->paymentFactory ->create (
88
+ [
77
89
'data ' => [
78
90
PaymentInterface::KEY_METHOD => $ paymentMethodCode ,
79
91
PaymentInterface::KEY_PO_NUMBER => $ poNumber ,
80
92
PaymentInterface::KEY_ADDITIONAL_DATA => $ additionalData ,
81
- ]
82
- ] );
93
+ ]]
94
+ );
83
95
84
96
try {
85
97
$ this ->paymentMethodManagement ->set ($ cart ->getId (), $ payment );
0 commit comments