A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
I use the shopify-api-node library for creating orders.
This is how I create the order:
const orderData = {
// test: true,
transactions: [
{
kind: 'sale',
status: 'pending',
amount: sumValue,
},
],
financial_status: 'pending',
line_items: lineItems,
currency: 'CZK',
customer: {
email: customerData.email,
// accepts_marketing: true,
first_name: customerData.firstName,
last_name: customerData.lastName,
state: customerData.country,
note: null,
verified_email: true,
multipass_identifier: null,
phone: customerData.phone,
currency: 'CZK',
addresses: [
{
address1: `${customerData.street} ${customerData.streetNumber}`,
first_name: customerData.firstName,
last_name: customerData.lastName,
city: customerData.city,
zip: customerData.zip,
},
],
},
};
const order = await shopify.order.create(orderData);
It all works fine, order is created, waiting for the payment. The problem is, when the customer pay for the order and I want to add a transaction. The example below.
await shopify.transaction.create(5004209225923, {
amount: 690,
currency: 'CZK',
kind: 'capture',
});
This works for the orders created with shopify checkout but it doesnt work for orders which I created with api.
Then I get this error:
"message": "Response code 422 (Unprocessable Entity)"
So I assume there must be something I have to change when creating an order.
So I would like to ask where could be the problem? Or is there any other way how to set order as "PAID" ?
Below I send an order created with API:
{ "order": { "id": 5004209225923, "admin_graphql_api_id": "gid://shopify/Order/5004209225923", "app_id": 6321473, "browser_ip": null, "buyer_accepts_marketing": true, "cancel_reason": null, "cancelled_at": null, "cart_token": null, "checkout_id": null, "checkout_token": null, "closed_at": null, "confirmed": true, "contact_email": "roman.jelinek91@gmail.com", "created_at": "2023-01-08T08:16:54+01:00", "currency": "CZK", "current_subtotal_price": "690.00", "current_subtotal_price_set": { "shop_money": { "amount": "690.00", "currency_code": "CZK" }, "presentment_money": { "amount": "690.00", "currency_code": "CZK" } }, "current_total_discounts": "0.00", "current_total_discounts_set": { "shop_money": { "amount": "0.00", "currency_code": "CZK" }, "presentment_money": { "amount": "0.00", "currency_code": "CZK" } }, "current_total_duties_set": null, "current_total_price": "690.00", "current_total_price_set": { "shop_money": { "amount": "690.00", "currency_code": "CZK" }, "presentment_money": { "amount": "690.00", "currency_code": "CZK" } }, "current_total_tax": "0.00", "current_total_tax_set": { "shop_money": { "amount": "0.00", "currency_code": "CZK" }, "presentment_money": { "amount": "0.00", "currency_code": "CZK" } }, "customer_locale": null, "device_id": null, "discount_codes": [], "email": "roman.jelinek91@gmail.com", "estimated_taxes": false, "financial_status": "pending", "fulfillment_status": null, "gateway": "", "landing_site": null, "landing_site_ref": null, "location_id": null, "name": "3331294", "note": null, "note_attributes": [], "number": 294, "order_number": 1294, "order_status_url": "https://checkout.starly.cz/60881535171/orders/dc43a3803b2c6911441dde0122b1bc4a/authenticate?key=054d9eed2ff8806849a19ab62bab4756", "original_total_duties_set": null, "payment_gateway_names": [ "" ], "phone": null, "presentment_currency": "CZK", "processed_at": "2023-01-08T08:16:54+01:00", "processing_method": "", "reference": null, "referring_site": null, "source_identifier": null, "source_name": "6321473", "source_url": null, "subtotal_price": "690.00", "subtotal_price_set": { "shop_money": { "amount": "690.00", "currency_code": "CZK" }, "presentment_money": { "amount": "690.00", "currency_code": "CZK" } }, "tags": "", "tax_lines": [], "taxes_included": false, "test": false, "token": "dc43a3803b2c6911441dde0122b1bc4a", "total_discounts": "0.00", "total_discounts_set": { "shop_money": { "amount": "0.00", "currency_code": "CZK" }, "presentment_money": { "amount": "0.00", "currency_code": "CZK" } }, "total_line_items_price": "690.00", "total_line_items_price_set": { "shop_money": { "amount": "690.00", "currency_code": "CZK" }, "presentment_money": { "amount": "690.00", "currency_code": "CZK" } }, "total_outstanding": "690.00", "total_price": "690.00", "total_price_set": { "shop_money": { "amount": "690.00", "currency_code": "CZK" }, "presentment_money": { "amount": "690.00", "currency_code": "CZK" } }, "total_price_usd": "30.59", "total_shipping_price_set": { "shop_money": { "amount": "0.00", "currency_code": "CZK" }, "presentment_money": { "amount": "0.00", "currency_code": "CZK" } }, "total_tax": "0.00", "total_tax_set": { "shop_money": { "amount": "0.00", "currency_code": "CZK" }, "presentment_money": { "amount": "0.00", "currency_code": "CZK" } }, "total_tip_received": "0.00", "total_weight": 0, "updated_at": "2023-01-08T08:53:20+01:00", "user_id": null, "customer": { "id": 5887522799811, "email": "roman.jelinek91@gmail.com", "accepts_marketing": true, "created_at": "2022-01-09T09:52:54+01:00", "updated_at": "2023-01-08T08:16:55+01:00", "first_name": "Roman", "last_name": "Jelínek", "orders_count": 42, "state": "disabled", "total_spent": "41570.00", "last_order_id": 5004209225923, "note": null, "verified_email": true, "multipass_identifier": null, "tax_exempt": false, "tags": "", "last_order_name": "3331294", "currency": "CZK", "phone": "+420731799162", "accepts_marketing_updated_at": "2022-11-12T07:26:59+01:00", "marketing_opt_in_level": "single_opt_in", "tax_exemptions": [], "sms_marketing_consent": { "state": "not_subscribed", "opt_in_level": "single_opt_in", "consent_updated_at": null, "consent_collected_from": "SHOPIFY" }, "admin_graphql_api_id": "gid://shopify/Customer/5887522799811", "default_address": { "id": 7657749381315, "customer_id": 5887522799811, "first_name": "Roman", "last_name": "Jelínek", "company": null, "address1": "Na Peniku 429", "address2": null, "city": "Písek", "province": null, "country": "Czech Republic", "zip": "397 01", "phone": "+420 731 799 162", "name": "Roman Jelínek", "province_code": null, "country_code": "CZ", "country_name": "Czech Republic", "default": true } }, "discount_applications": [], "fulfillments": [], "line_items": [ { "id": 12459086184643, "admin_graphql_api_id": "gid://shopify/LineItem/12459086184643", "fulfillable_quantity": 1, "fulfillment_service": "manual", "fulfillment_status": null, "gift_card": false, "grams": 0, "name": "paper", "price": "690.00", "price_set": { "shop_money": { "amount": "690.00", "currency_code": "CZK" }, "presentment_money": { "amount": "690.00", "currency_code": "CZK" } }, "product_exists": false, "product_id": null, "properties": [ { "name": "Varianta", "value": "mapa v tubě bez rámu" }, { "name": "Barva rámu", "value": "Bez rámu" }, { "name": "Množství", "value": "1" }, { "name": "Nadpis", "value": "Zadejte váš nadpis" }, { "name": "Místo", "value": "Praha" }, { "name": "_exportUrl", "value": "https://starmap.vercel.app//export/f8580dbd-2bc2-4241-ba21-7f865778ef3b" } ], "quantity": 1, "requires_shipping": true, "sku": null, "taxable": true, "title": "paper", "total_discount": "0.00", "total_discount_set": { "shop_money": { "amount": "0.00", "currency_code": "CZK" }, "presentment_money": { "amount": "0.00", "currency_code": "CZK" } }, "variant_id": null, "variant_inventory_management": null, "variant_title": null, "vendor": null, "tax_lines": [], "duties": [], "discount_allocations": [] } ], "payment_terms": null, "refunds": [], "shipping_lines": [] } }
Thank you
Hi @RomanJelinek91 - thanks for getting in touch, this is a great question. I had to do a little bit of investigation on our end and from what I could see in the snippet you provided, my thinking is that there may be missing or incorrect data present in the order data you're sending when your await function is triggered.
I'm not a JS expert, but generally you would need to provide the parent_id of the transaction when you are using the Transaction API to create a new transaction for an order. This could be why the call doesn't work why you try to process the transaction for orders created through the API. I'd check this part of our documentation out to make sure you're including all of the required fields.
This document here also goes over how you can capture that parent_id value if you wanted to check it out. We do also have a way to just mark orders as paid pretty easily in GraphQL, which is covered here, but this would only switch the order's status to "paid" without actually taking payment.
Hope this helps - let us know if we can clarify anything further on our end.
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Hi! Transactions with kind "capture" must be children of transactions with kind "authorization", because you capture a payment that has been authorized.
I think you should create a first transaction with kind "authorization" instead of "sale" and then create a "capture" transaction with the id of the "authorization" transaction as parent.
const orderData = {
...
transactions: [
{
kind: 'authorization',
status: 'success',
amount: sumValue,
},
],
...
}
Then :
await shopify.transaction.create(5004209225923, {
parent_id: <previous transaction id>
amount: 690,
currency: 'CZK',
kind: 'capture',
});