Every time a customer creates an order/payment, I am looking to get the order_id and custoer_id for the associated order/payment. The API documentation says the order.created and payment.created events should carry this data. I only see order_id and not customer_id and I am not sure why. Here is an example for payment.created and order.created events respectively:
==============================
PAYMENT HAS BEEN CREATED
Full payment created body:
{
merchant_id: 'QMQ16MVGWH93N',
type: 'payment.created',
event_id: '09687ac3-dd61-3c4d-943f-81a8c4bb48f7',
created_at: '2023-04-27T17:13:58.1Z',
data: {
type: 'payment',
id: 'BEiQODmyka1vygHYMWJ518PzvaB',
object: { payment: [Object] }
}
}
payment obj body:
{
amount_money: { amount: 0, currency: 'USD' },
application_details: { square_product: 'ECOMMERCE_API' },
cash_details: { buyer_supplied_money: { amount: 0, currency: 'USD' } },
created_at: '2023-04-27T17:13:58.096Z',
id: 'BEiQODmyka1vygHYMWJ518PzvaB',
location_id: '3WRDA0JSAPRV7',
order_id: 'an7ELCle1DxIEdzxPRnOYMhlA9HZY',
receipt_number: 'BEiQ',
source_type: 'CASH',
status: 'APPROVED',
total_money: { amount: 0, currency: 'USD' },
updated_at: '2023-04-27T17:13:58.096Z',
version: 0
}
==============================
GATHERING DATA FROM ORDER ID: gqNnEoSGre5lxk7fQ6LyyYCOCoGZY
the result:
{
order: {
id: 'gqNnEoSGre5lxk7fQ6LyyYCOCoGZY',
locationId: '3WRDA0JSAPRV7',
referenceId: '11ede51c6346e556a0853cecef6ab90e',
source: { name: 'Checkout Link' },
lineItems: [ [Object] ],
fulfillments: [ [Object] ],
netAmounts: {
totalMoney: [Object],
taxMoney: [Object],
discountMoney: [Object],
tipMoney: [Object],
serviceChargeMoney: [Object]
},
createdAt: '2023-04-27T16:56:27.320Z',
updatedAt: '2023-04-27T16:56:28.000Z',
state: 'OPEN',
version: 4,
totalMoney: { amount: 0n, currency: 'USD' },
totalTaxMoney: { amount: 0n, currency: 'USD' },
totalDiscountMoney: { amount: 0n, currency: 'USD' },
totalTipMoney: { amount: 0n, currency: 'USD' },
totalServiceChargeMoney: { amount: 0n, currency: 'USD' },
netAmountDueMoney: { amount: 0n, currency: 'USD' }
}
}
the line items:
[
{
uid: 'pEn5lbhESa7Ei67ij10dgD',
name: 'Test Item',
quantity: '2',
catalogObjectId: 'Y6UFKSMFYWHQKZUGLY62XPO5',
catalogVersion: 1682613226304n,
variationName: 'Regular',
itemType: 'ITEM',
basePriceMoney: { amount: 0n, currency: 'USD' },
variationTotalPriceMoney: { amount: 0n, currency: 'USD' },
grossSalesMoney: { amount: 0n, currency: 'USD' },
totalTaxMoney: { amount: 0n, currency: 'USD' },
totalDiscountMoney: { amount: 0n, currency: 'USD' },
totalMoney: { amount: 0n, currency: 'USD' }
}
]
CUSTOMER ID: undefined
UPDATE: I was reading online and saw that customer ids may not always appear in payment created/order created. This begs the question: how do I find the customer for a specific order. I am trying to send them an email after they made an order.
I am using a square checkout URL for my customers to make orders. So I need a customer_id generated and associated with an order whenever they make a purchase.