skip to Main Content

I am following this tutorial to process cart / checkout for placing orders using graphql. Magento GraphQl Tutorial. And we have installed stripe on magento(backend).

So we are facing issue while placing order, we have done few steps upto point 5.

  1. Customer logs in get a authentication token
  2. Create empty cart
  3. Add product to cart
  4. Set billing and shipping address for cart
  5. Set payment method to stripe_payments (without card details)
  6. How to set payment information and where to set ?
  7. Placing order receiving error here

How can I set payment method and debit card details to cart using graphql and place an successful test order?

2

Answers


  1. Make sure all steps ( 1 to 5 ) have been done without any issue. Please check the below steps for the mutation by which you can set the payment method and place the order.

    Example: Use the setPaymentMethodOnCart mutation to set the payment method for your order. The value checkmo (“Check / Money order” payment method code) was returned in the query.

    mutation {
          setPaymentMethodOnCart(input: {
              cart_id: "{ CART_ID }"
              payment_method: {
                  code: "checkmo"
              }
          }) {
            cart {
              selected_payment_method {
                code
              }
            }
          }
        }
    

    Response:

    If the operation is successful, the response contains the code of the selected payment method.

    {
      "data": {
        "setPaymentMethodOnCart": {
          "cart": {
            "selected_payment_method": {
              "code": "checkmo"
            }
          }
        }
      }
    }
    

    Set payment method and place order
    Use the setPaymentMethodAndPlaceOrder mutation to set the payment method and place the order.

    Request:

    mutation {
      setPaymentMethodAndPlaceOrder(input: {
          cart_id: "{ CART_ID }"
          payment_method: {
              code: "checkmo"
          }
      }) {
        order {
          order_id
        }
      }
    }
    

    Response:

    If the operation is successful, the response contains the order ID.

    {
      "data": {
        "setPaymentMethodAndPlaceOrder": {
          "order": {
            "order_id": "000000001"
          }
        }
      }
    }
    

    Note: Make sure “setPaymentMethodAndPlaceOrder mutation” is not deprecated in the current version of Magento 2.

    Login or Signup to reply.
  2. First check the available payment method ( added from magneto dashboard only)
    Then set that payment method and post the query

    https://devdocs.magento.com/guides/v2.4/graphql/tutorials/checkout/checkout-payment-method.html

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search