Create an order using the Orders API

Hm,

What about this T7YXs01hu16TIc2NtSmbpTjASrJZY
Can you check please?

That one is paid for however it doesn’t have a fulfillments.

Hi Bryan,

This is my code that is running after an order is being placed through website:

//  get square order ID
        // the $order_id is already known
        $square_OID = get_post_meta($order_id, '_wc_square_credit_card_square_order_id', true);

        $pickup_details = new \SquareConnect\Model\OrderFulfillmentPickupDetails();
        $pickup_details->setExpiresAt('2020-01-25T18:25:34-08:00');
        $pickup_details->setAutoCompleteDuration('P1W3D');
        $pickup_details->setScheduleType('SCHEDULED');
        $pickup_details->setPickupAt('2020-01-25T18:25:34-08:00');
        $pickup_details->setPickupWindowDuration('P2DT12H30M15S');
        $pickup_details->setPrepTimeDuration('P2DT12H30M15S');
        $pickup_details->setNote('notes');

        $order_fulfillment = new SquareConnect\Model\OrderFulfillment();
        $order_fulfillment->setPickupDetails($pickup_details);
        $order_fulfillment->setState('COMPLETED');
        $order_fulfillment->setType('PICKUP');

        $fulfillments = [$order_fulfillment];
        
        $order = new SquareConnect\Model\Order(array($square_OID));
        $order->setCustomerId('35D37A18Z8ZN9AA2PDYQ5Q08M');
        $order->setFulfillments($fulfillments);

        $body = new SquareConnect\Model\CreateOrderRequest();
        $body->setOrder($order);
        $body->setIdempotencyKey(uniqid());

        $access_token = 'my_token';
        $host = 'https://connect.squareupsandbox.com';
        $location_id = 'my_loc_ID';

        $api_config = new SquareConnect\Configuration();
        $api_config->setAccessToken($access_token);
        $api_config->setHost($host);
        $api_client = new SquareConnect\ApiClient($api_config);

        $apiInstance1 = new SquareConnect\Api\OrdersApi($api_client);

        try {
            $result = $apiInstance1->createOrder($location_id, $body);
            print_r($result->getOrder());
        } catch (Exception $e) {
            print_r($e->getMessage());

        }```

Order is completed and paid. Still getting an error that says

{“errors”: [{“code”: “MISSING_REQUIRED_PARAMETER”,“detail”: “Missing required parameter.”,“field”: “order.fulfillments[0].pickup_details.recipient”,“category”: “INVALID_REQUEST_ERROR”}]} ```

What do I miss?
Thanks

:wave: The order is missing the recipient. I should look something like:

"recipient": 
        {
          "display_name": "John Doe",
          "email_address": "recipient email address",
          "phone_number": "1 (234) 567 8900"
        },

:wave: The order is missing the recipient . I should look something like:
VidMate Bluestacks.red

"recipient": 
        {
          "display_name": "John Doe", 
          "email_address": "recipient email address",
          "phone_number": "1 (234) 567 8900"
        },

Worked for us.

Thanks for info, even so there is no more error message, but still order doesn’t show up, just the transaction.

Is the order paid for? Do you have an order_id that isn’t showing up?

Yes, the order is paid, the transaction ID is nX5RNTmEaiSWmvTAwhmgOt4paYWZY and the Payment ID is Fe28YENDTLhG7S46KNJ3kB1CZTaZY. The reference Order ID should be 5570

@cadobe, that order doesn’t have a fulfillment. For orders to show in the Orders section of the Dashboard they have to have a fulfillment and be fully paid for. :smiley:

Can you provide me the link to create fulfillment using the API please?

The fulfillment is either in CreateOrder or UpdateOrder requests. For example:

{
  "idempotency_key": "{{$guid}}",
  "order": {
    "location_id": "{{location_id}}",
  	"reference_id": "my-order-0001",
  	  "line_items": [
    {
      "name": "New York Strip Steak",
      "quantity": "1",
      "variation_name": "Re",
      "base_price_money": {
        "amount": 100,
        "currency": "USD"
      }
    }
  ],
  "fulfillments": [
    {
      "type": "PICKUP",
      "status": "PROPOSED",
      "pickup_details": 
      {
        "is_square_pickup_order": true,
        "recipient": 
        {
          "display_name": "Jack Dorsyss",
          "email_address": "recipient email address",
          "phone_number": "1 (234) 567 8900"
        },
        "schedule_type": "ASAP",
        "pickup_at": "2019-02-23T01:02:05+00:01",
        "pickup_window_duration": "P1W3D",
        "prep_time_duration": "P1W3D",
        "note": "OPTIONAL NOTE ABOUT THE ORDER"
      }
    }
   ]
  }
}

Just asking, I’ve tried the API to create an order and get a 200 Response back. As I see I am using the API on browser being logged into my Square account. But the order that I’ve created still not going/showing on Orders. Is that normal? Here is the code

{
  "order": {
    "id": "5sfLcADTasqzdya4cDdsf2GMdI9YY",
    "location_id": "L1539FJ41VFCK",
    "fulfillments": [
      {
        "uid": "jpnpj7svQ4g20O1WAsI6OD",
        "type": "PICKUP",
        "state": "PROPOSED",
        "pickup_details": {
          "pickup_at": "2021-11-05T02:25:34.000Z",
          "schedule_type": "ASAP",
          "recipient": {
            "display_name": "Jack Dorsyss",
            "email_address": "[email protected]",
            "phone_number": "1234567890"
          },
          "pickup_window_duration": "P1W3D",
          "prep_time_duration": "P1W3D",
          "is_curbside_pickup": true
        }
      }
    ],
    "created_at": "2021-11-04T01:04:27.788Z",
    "updated_at": "2021-11-04T01:04:27.788Z",
    "state": "OPEN",
    "version": 1,
    "total_tax_money": {
      "amount": 0,
      "currency": "USD"
    },
    "total_discount_money": {
      "amount": 0,
      "currency": "USD"
    },
    "total_tip_money": {
      "amount": 0,
      "currency": "USD"
    },
    "total_money": {
      "amount": 0,
      "currency": "USD"
    },
    "total_service_charge_money": {
      "amount": 0,
      "currency": "USD"
    },
    "net_amounts": {
      "total_money": {
        "amount": 0,
        "currency": "USD"
      },
      "tax_money": {
        "amount": 0,
        "currency": "USD"
      },
      "discount_money": {
        "amount": 0,
        "currency": "USD"
      },
      "tip_money": {
        "amount": 0,
        "currency": "USD"
      },
      "service_charge_money": {
        "amount": 0,
        "currency": "USD"
      }
    },
    "source": {
      "name": "Sandbox for sq0idp-0VIllxOE-OrNTjuAj2Wa0A"
    },
    "customer_id": "YQ6ECK2ETMYNSCV895YKF9MH70"
  }
}

Just asking. I used the browser API and place an order. I am using the Square portal/API testing being logged into my Square account. The response is 200 which is OK but the order still not showing in Orders nor transactions. Is that normal?
On the other hand, if the above is normal, using the API on code, can you create an order for a dummy product, but you do not have that product yet into your Square Item library?
Here is the code that I use to create a new order having fulfillment:

{
  "order": {
    "id": "5sfLcADTasqzdya4cDdsf2GMdI9YY",
    "location_id": "L1539FJ41VFCK",
    "fulfillments": [
      {
        "uid": "jpnpj7svQ4g20O1WAsI6OD",
        "type": "PICKUP",
        "state": "PROPOSED",
        "pickup_details": {
          "pickup_at": "2021-11-05T02:25:34.000Z",
          "schedule_type": "ASAP",
          "recipient": {
            "display_name": "Jack Dorsyss",
            "email_address": "[email protected]",
            "phone_number": "1234567890"
          },
          "pickup_window_duration": "P1W3D",
          "prep_time_duration": "P1W3D",
          "is_curbside_pickup": true
        }
      }
    ],
    "created_at": "2021-11-04T01:04:27.788Z",
    "updated_at": "2021-11-04T01:04:27.788Z",
    "state": "OPEN",
    "version": 1,
    "total_tax_money": {
      "amount": 0,
      "currency": "USD"
    },
    "total_discount_money": {
      "amount": 0,
      "currency": "USD"
    },
    "total_tip_money": {
      "amount": 0,
      "currency": "USD"
    },
    "total_money": {
      "amount": 0,
      "currency": "USD"
    },
    "total_service_charge_money": {
      "amount": 0,
      "currency": "USD"
    },
    "net_amounts": {
      "total_money": {
        "amount": 0,
        "currency": "USD"
      },
      "tax_money": {
        "amount": 0,
        "currency": "USD"
      },
      "discount_money": {
        "amount": 0,
        "currency": "USD"
      },
      "tip_money": {
        "amount": 0,
        "currency": "USD"
      },
      "service_charge_money": {
        "amount": 0,
        "currency": "USD"
      }
    },
    "source": {
      "name": "Sandbox for sq0idp-0VIllxOE-OrNTjuAj2Wa0A"
    },
    "customer_id": "YQ6ECK2ETMYNSCV895YKF9MH70"
  }
}

Using the API POST/v2/orders, to create and fulfill an order. Product is already on my Items library. Everything is running The Request is OK and the Response is 200 OK.

Still not going through to see the new order on the Order Tab, Here is the response

{
  "order": {
    "id": "ZyoU5MBLBRBM5RqbJ82irlREqeKZY",
    "location_id": "L1539FJ41VFCK",
    "line_items": [
      {
        "uid": "clKCbRtmtDytLuWx9XS7C",
        "quantity": "1",
        "name": "Product name",
        "base_price_money": {
          "amount": 2499,
          "currency": "USD"
        },
        "gross_sales_money": {
          "amount": 2499,
          "currency": "USD"
        },
        "total_tax_money": {
          "amount": 0,
          "currency": "USD"
        },
        "total_discount_money": {
          "amount": 0,
          "currency": "USD"
        },
        "total_money": {
          "amount": 2499,
          "currency": "USD"
        },
        "variation_total_price_money": {
          "amount": 2499,
          "currency": "USD"
        },
        "item_type": "ITEM"
      }
    ],
    "fulfillments": [
      {
        "uid": "7VQSQmNgq7afpt6gm8XTNB",
        "type": "PICKUP",
        "state": "PROPOSED",
        "pickup_details": {
          "pickup_at": "2021-11-05T06:25:34.000Z",
          "schedule_type": "ASAP",
          "recipient": {
            "display_name": "Person",
            "email_address": "some email",
            "phone_number": "1234567890"
          },
          "pickup_window_duration": "P1W3D",
          "prep_time_duration": "P1W3D",
          "is_curbside_pickup": true
        }
      }
    ],
    "created_at": "2021-11-04T13:15:22.982Z",
    "updated_at": "2021-11-04T13:15:22.982Z",
    "state": "OPEN",
    "version": 1,
    "total_tax_money": {
      "amount": 0,
      "currency": "USD"
    },
    "total_discount_money": {
      "amount": 0,
      "currency": "USD"
    },
    "total_tip_money": {
      "amount": 0,
      "currency": "USD"
    },
    "total_money": {
      "amount": 2499,
      "currency": "USD"
    },
    "total_service_charge_money": {
      "amount": 0,
      "currency": "USD"
    },
    "net_amounts": {
      "total_money": {
        "amount": 2499,
        "currency": "USD"
      },
      "tax_money": {
        "amount": 0,
        "currency": "USD"
      },
      "discount_money": {
        "amount": 0,
        "currency": "USD"
      },
      "tip_money": {
        "amount": 0,
        "currency": "USD"
      },
      "service_charge_money": {
        "amount": 0,
        "currency": "USD"
      }
    },
    "source": {
      "name": "Sandbox token"
    }
  }
}

@cadobe That order isn’t paid for. For orders to show in the Orders section of the Dashboard they have to have a fulfillment and be fully paid for. :slightly_smiling_face:

On the 200 OK Response is the amount 2499, I am confused, how should like that order being paid?

That is the amount for the order total. You’ll now need to call CreatePayment with that order_id in the payment request. For example:

{
    "idempotency_key": "{{$guid}}",
    "autocomplete": true,
    "amount_money": {
        "amount": 2499,
        "currency": "USD"
    },
    "source_id": "cnon:card-nonce-ok",
    "order_id": "ZyoU5MBLBRBM5RqbJ82irlREqeKZY"
}

I feel so frustrated.
So, the workflow is this: create order, pay the order and fulfill the order all in one request.
The order id is VeHsLgVkNsOy07I51kEMS0w553TZY and still not showing, all responses are 200 on API logs, and no errors displayed on my debugging . Not sure what should I do, I feel like giving up on this, was trying to get a demo done but looks like is not worth it. I am sorry saying this, but this is how I feel.

With Square the flow would be the following:

  1. Create the order with a fulfillment using CreateOrder
  2. Take the order_id and pass it into the CreatePayment request when paying for the order.

The order will the show in the Dashboard or push to the POS and allow you to update the progress of the fulfillment. Or if you would like to update the fulfillment you can use UpdateOrder with something like this to progress the fulfillment:

{
  "order": {
    "version": 1,
    "fulfillments": [
      {
        "uid": "my_fulfillments_uid",
        "state": "COMPLETED"
      }
    ]
  }
}

There you go. I feel like spring is comming :slight_smile:

Cool. It showed. I missed the setOrderId on the payment section.
How do I get the order ID if the CreateOrder and CreatePayment are on the same, one single request?