1818use Magento \QuoteGraphQl \Model \Cart \GetCartForUser ;
1919use Magento \Quote \Api \Data \PaymentInterfaceFactory ;
2020use Magento \Quote \Api \PaymentMethodManagementInterface ;
21+ use Magento \QuoteGraphQl \Model \Cart \Payment \AdditionalDataProviderPool ;
22+ use Magento \Framework \App \ObjectManager ;
2123
2224/**
2325 * Mutation resolver for setting payment method for shopping cart
@@ -39,19 +41,28 @@ class SetPaymentMethodOnCart implements ResolverInterface
3941 */
4042 private $ paymentFactory ;
4143
44+ /**
45+ * @var AdditionalDataProviderPool
46+ */
47+ private $ additionalDataProviderPool ;
48+
4249 /**
4350 * @param GetCartForUser $getCartForUser
4451 * @param PaymentMethodManagementInterface $paymentMethodManagement
4552 * @param PaymentInterfaceFactory $paymentFactory
53+ * @param AdditionalDataProviderPool $additionalDataProviderPool
4654 */
4755 public function __construct (
4856 GetCartForUser $ getCartForUser ,
4957 PaymentMethodManagementInterface $ paymentMethodManagement ,
50- PaymentInterfaceFactory $ paymentFactory
58+ PaymentInterfaceFactory $ paymentFactory ,
59+ AdditionalDataProviderPool $ additionalDataProviderPool = null
5160 ) {
5261 $ this ->getCartForUser = $ getCartForUser ;
5362 $ this ->paymentMethodManagement = $ paymentMethodManagement ;
5463 $ this ->paymentFactory = $ paymentFactory ;
64+ $ this ->additionalDataProviderPool = $ additionalDataProviderPool
65+ ?: ObjectManager::getInstance ()->get (AdditionalDataProviderPool::class);
5566 }
5667
5768 /**
@@ -70,16 +81,17 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
7081 $ paymentMethodCode = $ args ['input ' ]['payment_method ' ]['code ' ];
7182
7283 $ poNumber = $ args ['input ' ]['payment_method ' ]['purchase_order_number ' ] ?? null ;
73- $ additionalData = $ args[ ' input ' ][ ' payment_method ' ][ ' additional_data ' ] ?? [];
84+ $ additionalData = $ this -> additionalDataProviderPool -> getData ( $ paymentMethodCode , $ args) ?? [];
7485
7586 $ cart = $ this ->getCartForUser ->execute ($ maskedCartId , $ context ->getUserId ());
76- $ payment = $ this ->paymentFactory ->create ([
87+ $ payment = $ this ->paymentFactory ->create (
88+ [
7789 'data ' => [
7890 PaymentInterface::KEY_METHOD => $ paymentMethodCode ,
7991 PaymentInterface::KEY_PO_NUMBER => $ poNumber ,
8092 PaymentInterface::KEY_ADDITIONAL_DATA => $ additionalData ,
81- ]
82- ] );
93+ ]]
94+ );
8395
8496 try {
8597 $ this ->paymentMethodManagement ->set ($ cart ->getId (), $ payment );
0 commit comments