payment_method, shipment_method

bashesselsbashessels Member Posts: 2

I'm trying to create a new finished checkout by a customer using the following calls:

  • /checkouts.json POST
  • /checkouts/{id}/products.json POST (looped)
  • /shippingmethods.json GET
  • paymentmethods.json GET
  • /checkouts/{id}.json PUT
  • /checkouts/{id}/validate.json GET
  • /checkouts/{id}/order.json POST

For the first call I have to send a body json to fill out the details. Two of these segments are shipmentmethod and paymentmethod. According to the documentation I have to send something that looks like a magic string (the example is "core|1|1"). I have no idea what that means or where it comes from or what it's related to. So I tried just doing something like:

          payment_method:
          {
            id = 96
          },
          shipment_method:
          {
            id = 575481
          },

and

          payment_method: 96,
          shipment_method: 57548,

Using ID's that I found with the relevant calls. But when I do validate I get the following error:

{"validated":false,"errors":["Please select a payment method","Please select a shipping method"]}

And when I retrieve the new checkout object those fields are empty.

I'm confused about how this should work now. The documentation doesn't seem to be very clear on what those ID values should contain and where it comes from.

I'm sure it's something stupid that I've read over or missed completely.

Another question is .... is this set of calls the only way to retroactively add a checkout (order by a customer) to the system? Or is there an easier way than this?


Thanks in advance,

Bas Hessels

3 comments

  • LeahLeah Moderator, Lightspeed Staff Posts: 113 moderator

    Hi Bas,

    If you take a look here: https://developers.lightspeedhq.com/ecom/endpoints/checkout/ you can see all the relevant endpoints. To get the shipping method ID, you need to do a GET to see a list of all available methods for the checkout. You can then use the information in this response to do a PUT to set the shipment method. The same principle applies to the GET for payment methods with one caveat. In the response for the payment methods, you will see something similar to this:

    {

      "paymentmethods": [

        {

          "id": 128,

          "key": "pickup",

          "title": "Pay at pickup"

        },

        {

          "id": 100,

          "key": "paypal",

          "title": "PayPal"

        }

      ]

    }

    But when you PUT to set the payment method, the payload fields should be in this format:

    {

     "payment_method": {

      "id": "paypal",

      "method": "PayPal"

     }

    }

    With the shipping and payment attached, you should then be able to validate the checkout and convert it to an order.

    This process is really the only way to create an order via the API so you will need to go through the steps each time you want to create a new order.

    API Support
    Lightspeed HQ
  • bashesselsbashessels Member Posts: 2

    Hey Leah,

    Thank you for your help. I've managed to get payment_method working by using the key from the payment method list in the id field with the PUT call.

    But this doesn't seem to be working the same way with shipment_method.

    Shipmentmethods collection doesn't contain any key field.


    	"shippingmethods": [	{
    		"id": 575481,
    		"type": "default",
    		"isBackofficeOnly": false,
    		"sortOrder": 2,
    		"freeAbove": 1000000,
    		"paymentPriceExcl": 0,
    		"paymentPriceIncl": 0,
    		"title": "standaardverzending",
    		"description": "standaardverzending",
    		"tax": {
    			"resource": {
    				"id": 927941,
    				"url": "taxes\/927941",
    				"link": "https:\/\/api.webshopapp.com\/en\/taxes\/927941.json"
    			}
    		},
    		"countries": {
    			"resource": {
    				"id": false,
    				"url": "shippingmethods\/575481\/countries",
    				"link": "https:\/\/api.webshopapp.com\/en\/shippingmethods\/575481\/countries.json"
    			}
    		},
    		"values": {
    			"resource": {
    				"id": false,
    				"url": "shippingmethods\/575481\/values",
    				"link": "https:\/\/api.webshopapp.com\/en\/shippingmethods\/575481\/values.json"
    			}
    		}
    	},
    


    The closest thing is title. I've done

              shipment_method = new
              {
                id = "standaardverzending"
              },
    

    and

              shipment_method = "standaardverzending"
    

    Neither of which seem to be working.

  • LeahLeah Moderator, Lightspeed Staff Posts: 113 moderator

    Hi @bashessels, you need to do a GET for the shipping methods available for the checkout you're working with as outlined here: https://developers.lightspeedhq.com/ecom/endpoints/checkout/#get-shipment-methods

    The ID will be something like: 'core|12345|1234567' or 'postnl|Default'

    API Support
    Lightspeed HQ
Sign In or Register to comment.