Order does not appear in orders page but payment is success using node js api

I am trying to make an order and with the payment. Also, I am using a production not a sandbox to test this. So this is how I implement my code.

Create Order Service :-

 async createOrder(req: Request, res: Response) {
    try {
      appLogger.info("Create order start");
      const ordersApi = this.client.ordersApi;
      const createOrderRequest: OrderDto = req.body;
      const order = squareOrderCreateRequestBody(createOrderRequest);
      const response = await ordersApi.createOrder(order);
      if (response.result) {
        appLogger.info("Order create success");
        const createPaymentRequest: PaymentDto = req.body;
        return await this.makePayment(createPaymentRequest, res);
      }
    } catch (error) {
      console.log(error);
      appLogger.error(`Error make order:", ${error}`);
      return handleError({ error }, res);
    }
  }

Make Payment Service:-

  // Make a payment
  async makePayment(dto: PaymentDto, res: Response) {
    try {
      console.log({ dto });
      appLogger.info("Make payment start");
      const paymentsApi = this.client.paymentsApi;
      const payment = createPaymentObject(dto);
      const response = await paymentsApi.createPayment(payment);
      appLogger.info("Payment success");
      return res.status(200).json(serializeBigInts(response.result.payment));
    } catch (error) {
      console.log(error);
      appLogger.error(`Error make payment:", ${error}`);
      return handleError({ error }, res);
    }
  }

squareOrderCreateRequestBody :-

export function squareOrderCreateRequestBody(
  dto: OrderDto
): CreateOrderRequest {
  const order: CreateOrderRequest = {
    order: {
      locationId: dto.locationId,
      referenceId: `ref-${uuidv4()}`,
      customerId: dto.customerId,
      lineItems: dto.lineItems.map((product: OrderLineItem): OrderLineItem => {
        return {
          quantity: product.quantity,
          catalogObjectId: product.catalogObjectId,
          basePriceMoney: {
            amount: BigInt(product.basePriceMoney.amount),
            currency: "AUD",
          },
        };
      }),
    },
    idempotencyKey: uuidv4(),
  };
  return order;
}

createPaymentObject :-

export function createPaymentObject(
  dto: PaymentDto
): CreatePaymentRequest {
  const payment: CreatePaymentRequest = {
    sourceId: dto.sourceId,
    idempotencyKey: uuidv4(),
    buyerEmailAddress: dto.buyerEmailAddress,
    note: dto.note || "",
    // billingAddress: dto.billingAddress,
    amountMoney: {
      amount: BigInt(dto.amountMoney.amount),
      currency: dto.amountMoney.currency,
    },
    orderId:'****',
    locationId:'****',
    autocomplete:true
  };
  return payment;
}

So these are my order and payment implimation.
I use React JS and web SDK to make CARD payments and send tokens to my API service.
This is my POSTMAN example of creating an order and related payment.

create/order 
{
    "locationId": "***",
    "customerId": "stefany-test",
    "lineItems": [
        {
            "quantity": "1",
            "catalogObjectId": "***",
            "basePriceMoney": {
                "amount": 2,
                "currency": "AUD"
            }
        }
    ],
    "sourceId": "cnon:***",
    "amountMoney": {
        "amount": 2,
        "currency": "AUD"
    },
    "buyerEmailAddress": "***@***.com.au",
    "note": "***"
}

Now my problem is when I hit this endpoint and check the response it returns the order-creates a success response and payment success response too. Also when I check the transaction table on my seller dashboard it appears the payment detail. So that means the transaction was a success too.

But when I checked the shop unit (iPad POS Stand | Square Stand) this order did not appear in the order list. So that means my Node Js application order and payment creation succeeded yet when I checked my iPad on my shop order did not appear in the order list.

What went wrong? Can u guys help me with this question, please?

Thank you very much for your time

This is because there isn’t a fulfillment in the order. With Square only orders with fulfillments that have been fully paid for will show in the orders section of the Dashboard. :slightly_smiling_face:

@Bryan-Square Thanks for the reply. Is this correct?

export function squareOrderCreateRequestBody(
  dto: OrderDto
): CreateOrderRequest {
  const order: CreateOrderRequest = {
    order: {
      locationId: dto.locationId,
      referenceId: `ref-${uuidv4()}`,
      customerId: dto.customerId,
      lineItems: dto.lineItems.map((product: OrderLineItem): OrderLineItem => {
        return {
          quantity: product.quantity,
          catalogObjectId: product.catalogObjectId,
          basePriceMoney: {
            amount: BigInt(product.basePriceMoney.amount),
            currency: "AUD",
          },
        };
      }),
      fulfillments: dto.lineItems.map((item: OrderLineItem): Fulfillment => {
        return {
          type: "PICKUP",
          state: "PROPOSED",
          pickupDetails: {
            recipient: {
              displayName: dto.customerId,
            },
            //expiresAt: "2019-02-14T20:21:54.859Z",
            //autoCompleteDuration: "P0DT1H0S",
            scheduleType: "SCHEDULED",
            pickupAt: new Date().toISOString(),
            //note: "Pour over coffee",
          },
        };
      }),
    },
    idempotencyKey: uuidv4(),
  };
  return order;
}
1 Like

That looks correct. Also you can use our API Explorer to easily build requests in different languages. :slightly_smiling_face:

@Bryan-Square Thank you very much :heart: