Magento 2 How to set Payment Method on the cart using GraphQL

We are all know that without payment not possible buy to any item in this world :laughing:, So the following article teach you how to set Paymnt Method on the cart.

Magento supports the following offline Payment Method:

  • Bank Transfer Payment
  • Cash on Delivery
  • Check / Money order
  • No Payment Information Required
  • Purchase Order

Magento also supports the following online Payment Method:

  • Braintree
  • Braintree Vault
  • PayPal Express Checkout
  • PayPal Payflow Link
  • PayPal Payflow Pro
  • PayPal Payments Advanced
  • PayPal Website Payments Pro Hosted Solution
  • Express Checkout for other PayPal solutions

Syntax

saveCopyzoom_out_map
mutation {
  setPaymentMethodOnCart(
    input: SetPaymentMethodOnCartInput
  )
    SetPaymentMethodOnCartOutput
  }
}

Offline Payment Method

Request

saveCopyzoom_out_map
mutation {
  setPaymentMethodOnCart(
    input: {
      cart_id: "2U1u9wHHOFNR3UAnBWMTznJfyKA74ZIc"
      payment_method: { code: "checkmo" }
    }
  ) {
    cart {
      selected_payment_method {
        code
        title
      }
    }
  }
}

Response

saveCopyzoom_out_map
{
  "data": {
    "setPaymentMethodOnCart": {
      "cart": {
        "selected_payment_method": {
          "code": "checkmo",
          "title": "Check / Money order"
        }
      }
    }
  }
}

That's it!!

If you are looking for more GraphQL solutions then check out our another article which is List of GraphQL Queries and Mutations for Magento 2.

I hope this article helps you to find what you were looking for.

Bookmark it for your future reference. Do comment below if you have any other questions on that.

P.S. Do share this article with your team.




Search
Recent Articles
Tags
Newsletter
Copyright © 2022 devhooks.in All rights reserved.
Ads OFF toggle_off
wifi_off