Order Payment webhook is not triggered although order is paid

Solved

Order Payment webhook is not triggered although order is paid

allium
Shopify Partner
5 0 0

We have a webhook for Order Payment event. I created an order with a transaction kind sale and the order is marked as paid in the admin dashboard but the webhook is not triggered. This is a test environment and allows bogus gateway. Here is the curl 

 

curl --location 'https://domain/orders.json' \
--header 'Content-Type: application/json' \
--header 'X-Shopify-Access-Token: token' \
--data '{
    "order": {
        "line_items": [
            {
                "variant_id": 47197185507622,
                "quantity": 3
            }
        ],
        "transactions": [
            {
                "kind": "sale",
                "status": "success",
                "amount": "117.00",
                "gateway": "bogus",
                "test": true
            }
        ],
        "currency": "USD"
    }
}'

 


I also tried to create an order with a transaction authorized and then tried to capture the transaction but got error saying Reference can't be blank although I passed the correct parent_id

 

 

curl --location 'https://domain/orders.json' \
--header 'Content-Type: application/json' \
--header 'X-Shopify-Access-Token: token' \
--data '{
    "order": {
        "line_items": [
            {
                "variant_id": 47197185507622,
                "quantity": 3
            }
        ],
        "transactions": [
            {
                "kind": "authorization",
                "status": "success",
                "amount": "117.00",
                "gateway": "bogus",
                "test": true
            }
        ],
        "currency": "USD"
    }
}'

 

Capture transaction 

 

 

curl --location 'https://domain/orders/{order_id}/transactions.json' \
--header 'Content-Type: application/json' \
--header 'X-Shopify-Access-Token: token' \
--data '{
    "transaction": {
        "kind": "capture",
        "amount": "117.00",
        "currency": "USD",
        "parent_id": <previous_authorization_txn_id>,
        "test": true
    }
}'

 

But I'm getting this error

 

{
    "errors": {
        "base": [
            "Reference can't be blank"
        ]
    }
}

 

 

Accepted Solution (1)
SBD_
Shopify Staff
1829 271 414

This is an accepted solution.

Hey @allium 

 

Ah I just hit your issue. Previously I was creating a transaction on an existing order what wasn't created via the API.

 

Second attempt, I was able to use the API to create and trigger an orders/paid webhook like this:

 

1. Created an order.

 

 

{
    "order": {
        "line_items": [
            {
                "variant_id": <some-variant-id>,
                "quantity": 1,
                "price": 100
            }
        ],
        "financial_status": "pending",
        "transactions": [
            {
                "kind": "authorization",
                "amount": 100
            }
        ]
    }
}

 

 

2. Marked as paid. POST /admin/api/2023-10/orders/<order-id>/transactions.json

 

 

{
    "transaction": {
        "amount": "100",
        "kind": "capture"
    }
}

 

 

Let me know how you go!

 

Scott | Developer Advocate @ Shopify 

View solution in original post

Replies 7 (7)

SBD_
Shopify Staff
1829 271 414

Hey @allium 

 

Creating a paid Order through the API will not trigger that webhook (more info here).

 

Side note: I also tested using the orderMarkAsPaid mutation and it did trigger the orders/paid webhook.

Scott | Developer Advocate @ Shopify 

allium
Shopify Partner
5 0 0

Thanks @SBD_ for your response. 

1. What is equivalent to orderMarkAsPaid REST API?

2. I tried to create an order with authorization transaction and change it to capture. I think that simulates state changes, but getting error Reference Can't be blank

SBD_
Shopify Staff
1829 271 414

Hey @allium 

 

I was able to do the equivalent in REST with POST /admin/api/2023-10/orders/<order-id>/transactions.json

 

{
    "transaction": {
        "amount": "<full-amount-here>",
        "kind": "capture"
    }
}

 

This triggered an orders/paid notification.

 

The reference error could be a bogus gateway thing - does it work if you just include `amount` and `kind`? How about if you create an order without any transactions and then create the capture transaction?

Scott | Developer Advocate @ Shopify 

allium
Shopify Partner
5 0 0

Now I've tried to create order without transactions but status is showing paid

 

{
    "order": {
        "line_items": [
            {
                "variant_id": 47197185507622,
                "quantity": 3
            }
        ],
        "currency": "USD",
        "billing_address": {
            "first_name": "Jhon",
            "last_name": "Doe",
            "address1": "Broadway",
            "phone": null,
            "city": "New York",
            "zip": "10012",
            "province": "New York",
            "country": "United States",
            "address2": null,
            "company": null,
            "latitude": 40.7256202,
            "longitude": -73.9966338,
            "name": "Jhon Doe",
            "country_code": "US",
            "province_code": "NY"
        },
        "customer": {
            "email": "jhon@gmail.com",
            "first_name": "Jhon",
            "last_name": "Doe",
            "phone": null,
            "currency": "USD"
        },
        "shipping_address": {
            "first_name": "Jhon",
            "last_name": "Doe",
            "address1": "Broadway",
            "phone": null,
            "city": "New York",
            "zip": "10012",
            "province": "New York",
            "country": "United States",
            "address2": null,
            "company": null,
            "latitude": 40.7256202,
            "longitude": -73.9966338,
            "name": "Jhon Doe",
            "country_code": "US",
            "province_code": "NY"
        }
    }
}

 
When tried to capture transaction 

{
    "transaction": {
        "kind": "capture",
        "amount": 117
    }
}

Getting this error

{
    "errors": {
        "base": [
            "Unable to find parent transaction"
        ]
    }
}

 BTW I'm using API version 2023-04, I tried to use 2023-10 but no luck.

allium
Shopify Partner
5 0 0

@SBD_ Could you please provide the sample payload you utilized for creating the order and executing the transaction, along with the API version you're using? I'm wondering what I'm doing wrong

SBD_
Shopify Staff
1829 271 414

This is an accepted solution.

Hey @allium 

 

Ah I just hit your issue. Previously I was creating a transaction on an existing order what wasn't created via the API.

 

Second attempt, I was able to use the API to create and trigger an orders/paid webhook like this:

 

1. Created an order.

 

 

{
    "order": {
        "line_items": [
            {
                "variant_id": <some-variant-id>,
                "quantity": 1,
                "price": 100
            }
        ],
        "financial_status": "pending",
        "transactions": [
            {
                "kind": "authorization",
                "amount": 100
            }
        ]
    }
}

 

 

2. Marked as paid. POST /admin/api/2023-10/orders/<order-id>/transactions.json

 

 

{
    "transaction": {
        "amount": "100",
        "kind": "capture"
    }
}

 

 

Let me know how you go!

 

Scott | Developer Advocate @ Shopify 

allium
Shopify Partner
5 0 0

Thanks @SBD_ . It works now