Skip to content

Commit 4397b4b

Browse files
committed
magento/graphql-ce#716: [Checkout] Set Payment Method and Place Order Mutation
1 parent a8c60a5 commit 4397b4b

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

app/code/Magento/QuoteGraphQl/Model/Cart/SetPaymentMethodOnCart.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
use Magento\Quote\Model\Quote;
1818
use Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderPool;
1919

20+
/**
21+
* Set payment method on cart
22+
*/
2023
class SetPaymentMethodOnCart
2124
{
2225
/**
@@ -69,13 +72,16 @@ public function execute(Quote $cart, array $paymentData): void
6972
? $this->additionalDataProviderPool->getData($paymentMethodCode, $paymentData['additional_data'])
7073
: [];
7174

72-
$payment = $this->paymentFactory->create([
73-
'data' => [
74-
PaymentInterface::KEY_METHOD => $paymentMethodCode,
75-
PaymentInterface::KEY_PO_NUMBER => $poNumber,
76-
PaymentInterface::KEY_ADDITIONAL_DATA => $additionalData,
75+
$payment = $this->paymentFactory->create(
76+
[
77+
'data' =>
78+
[
79+
PaymentInterface::KEY_METHOD => $paymentMethodCode,
80+
PaymentInterface::KEY_PO_NUMBER => $poNumber,
81+
PaymentInterface::KEY_ADDITIONAL_DATA => $additionalData,
82+
],
7783
]
78-
]);
84+
);
7985

8086
try {
8187
$this->paymentMethodManagement->set($cart->getId(), $payment);

app/code/Magento/QuoteGraphQl/Model/Resolver/SetPaymentAndPlaceOrder.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
7878
$paymentData = $args['input']['payment_method'];
7979

8080
$cart = $this->getCartForUser->execute($maskedCartId, $context->getUserId());
81-
$this->setPaymentMethodOnCart->execute($cart, $paymentData);
8281

8382
if ((int)$context->getUserId() === 0) {
8483
if (!$cart->getCustomerEmail()) {
@@ -87,6 +86,8 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
8786
$cart->setCheckoutMethod(CartManagementInterface::METHOD_GUEST);
8887
}
8988

89+
$this->setPaymentMethodOnCart->execute($cart, $paymentData);
90+
9091
try {
9192
$orderId = $this->cartManagement->placeOrder($cart->getId());
9293
$order = $this->orderRepository->get($orderId);

0 commit comments

Comments
 (0)