Skip to content

Commit

Permalink
Deprecate setPaymentMethodAndPlaceOrderMutation
Browse files Browse the repository at this point in the history
  • Loading branch information
pmclain committed Sep 8, 2019
1 parent d93d288 commit 28596de
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
use Magento\Sales\Api\OrderRepositoryInterface;

/**
* @inheritdoc
* Resolver for setting payment method and placing order
*
* @deprecated Should use setPaymentMethodOnCart and placeOrder mutations in single request.
* @see \Magento\QuoteGraphQl\Model\Resolver\SetPaymentMethodOnCart
* @see \Magento\QuoteGraphQl\Model\Resolver\PlaceOrder
*/
class SetPaymentAndPlaceOrder implements ResolverInterface
{
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/QuoteGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Mutation {
setShippingMethodsOnCart(input: SetShippingMethodsOnCartInput): SetShippingMethodsOnCartOutput @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\SetShippingMethodsOnCart")
setPaymentMethodOnCart(input: SetPaymentMethodOnCartInput): SetPaymentMethodOnCartOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\SetPaymentMethodOnCart")
setGuestEmailOnCart(input: SetGuestEmailOnCartInput): SetGuestEmailOnCartOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\SetGuestEmailOnCart")
setPaymentMethodAndPlaceOrder(input: SetPaymentMethodAndPlaceOrderInput): PlaceOrderOutput @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\SetPaymentAndPlaceOrder")
setPaymentMethodAndPlaceOrder(input: SetPaymentMethodAndPlaceOrderInput): PlaceOrderOutput @deprecated(reason: "Should use setPaymentMethodOnCart and placeOrder mutations in single request.") @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\SetPaymentAndPlaceOrder")
placeOrder(input: PlaceOrderInput): PlaceOrderOutput @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\PlaceOrder")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,14 @@ public function testSetPaymentOnCartWithSimpleProduct()
$query = $this->getQuery($maskedQuoteId, $methodCode);
$response = $this->graphQlMutation($query, [], '', $this->getHeaderMap());

self::assertArrayHasKey('setPaymentMethodAndPlaceOrder', $response);
self::assertArrayHasKey('order', $response['setPaymentMethodAndPlaceOrder']);
self::assertArrayHasKey('order_id', $response['setPaymentMethodAndPlaceOrder']['order']);
self::assertArrayHasKey('setPaymentMethodOnCart', $response);
self::assertArrayHasKey('cart', $response['setPaymentMethodOnCart']);
self::assertArrayHasKey('selected_payment_method', $response['setPaymentMethodOnCart']['cart']);
self::assertArrayHasKey('code', $response['setPaymentMethodOnCart']['cart']['selected_payment_method']);
self::assertEquals($methodCode, $response['setPaymentMethodOnCart']['cart']['selected_payment_method']['code']);

self::assertArrayHasKey('order', $response['placeOrder']);
self::assertArrayHasKey('order_id', $response['placeOrder']['order']);
}

/**
Expand Down Expand Up @@ -116,9 +121,14 @@ public function testSetPaymentOnCartWithVirtualProduct()
$query = $this->getQuery($maskedQuoteId, $methodCode);
$response = $this->graphQlMutation($query, [], '', $this->getHeaderMap());

self::assertArrayHasKey('setPaymentMethodAndPlaceOrder', $response);
self::assertArrayHasKey('order', $response['setPaymentMethodAndPlaceOrder']);
self::assertArrayHasKey('order_id', $response['setPaymentMethodAndPlaceOrder']['order']);
self::assertArrayHasKey('setPaymentMethodOnCart', $response);
self::assertArrayHasKey('cart', $response['setPaymentMethodOnCart']);
self::assertArrayHasKey('selected_payment_method', $response['setPaymentMethodOnCart']['cart']);
self::assertArrayHasKey('code', $response['setPaymentMethodOnCart']['cart']['selected_payment_method']);
self::assertEquals($methodCode, $response['setPaymentMethodOnCart']['cart']['selected_payment_method']['code']);

self::assertArrayHasKey('order', $response['placeOrder']);
self::assertArrayHasKey('order_id', $response['placeOrder']['order']);
}

/**
Expand Down Expand Up @@ -224,12 +234,25 @@ private function getQuery(
) : string {
return <<<QUERY
mutation {
setPaymentMethodAndPlaceOrder(input: {
cart_id: "$maskedQuoteId"
setPaymentMethodOnCart(
input: {
cart_id: "{$maskedQuoteId}"
payment_method: {
code: "$methodCode"
code: "{$methodCode}"
}
}
) {
cart {
selected_payment_method {
code
}
}) {
}
}
placeOrder(
input: {
cart_id: "{$maskedQuoteId}"
}
) {
order {
order_id
}
Expand Down

0 comments on commit 28596de

Please sign in to comment.