Skip to content

Commit

Permalink
magento#716: [Checkout] Set Payment Method and Place Order Mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
naydav committed Jun 20, 2019
1 parent a8c60a5 commit 4397b4b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
use Magento\Quote\Model\Quote;
use Magento\QuoteGraphQl\Model\Cart\Payment\AdditionalDataProviderPool;

/**
* Set payment method on cart
*/
class SetPaymentMethodOnCart
{
/**
Expand Down Expand Up @@ -69,13 +72,16 @@ public function execute(Quote $cart, array $paymentData): void
? $this->additionalDataProviderPool->getData($paymentMethodCode, $paymentData['additional_data'])
: [];

$payment = $this->paymentFactory->create([
'data' => [
PaymentInterface::KEY_METHOD => $paymentMethodCode,
PaymentInterface::KEY_PO_NUMBER => $poNumber,
PaymentInterface::KEY_ADDITIONAL_DATA => $additionalData,
$payment = $this->paymentFactory->create(
[
'data' =>
[
PaymentInterface::KEY_METHOD => $paymentMethodCode,
PaymentInterface::KEY_PO_NUMBER => $poNumber,
PaymentInterface::KEY_ADDITIONAL_DATA => $additionalData,
],
]
]);
);

try {
$this->paymentMethodManagement->set($cart->getId(), $payment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
$paymentData = $args['input']['payment_method'];

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

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

$this->setPaymentMethodOnCart->execute($cart, $paymentData);

try {
$orderId = $this->cartManagement->placeOrder($cart->getId());
$order = $this->orderRepository->get($orderId);
Expand Down

0 comments on commit 4397b4b

Please sign in to comment.