Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for orders #62

Merged
merged 9 commits into from
Nov 20, 2023
Merged

Fixes for orders #62

merged 9 commits into from
Nov 20, 2023

Conversation

calebporzio
Copy link
Contributor

@calebporzio calebporzio commented Nov 19, 2023

This PR contains the following fixes:

  • The fix from Use Order::STATUS_PAID instead of static::STATUS_PAID #61 (changing static:: to Order::)
  • Populate the the identifier field from the payload
    • I was getting a db error because it was never filled from the webhook handler
  • Making tax_name a nullable field because it was coming back "null" for me
  • Retrieving order details from $payload['data']['attributes']['first_order_item']
    • Not sure if this is the right way, but it's the only thing in my webhook payload that contained "product_id" and "variant_id"
    • Maybe the payloads are different if the product has a variant or not, but in my case, I can't create a "checkout" link without a variant, so I had to create a variant

I didn't add any tests because there's no precedent for webhook tests. Might be something to consider: tests with payload stubs to simulate handling new orders and subscriptions...

I do not intend for this PR to be merged (unless you want). This is more like a log of what got it all working for me locally for your reference.

Thanks for all your hard work on this!

@calebporzio
Copy link
Contributor Author

Here's a dump of my order created payload for reference:

{
    "type": "orders",
    "id": "...",
    "attributes": {
        "store_id": 50882,
        "customer_id": ...,
        "identifier": "3d4fb652-1b16-44b8-9330-01ae5d46d1ee",
        "order_number": 508829,
        "user_name": "Caleb Porzio",
        "user_email": "...",
        "currency": "USD",
        "currency_rate": "1.00000000",
        "tax_name": null,
        "tax_rate": "0.00",
        "status": "paid",
        "status_formatted": "Paid",
        "refunded": false,
        "refunded_at": null,
        "subtotal": 8900,
        "discount_total": 0,
        "tax": 0,
        "total": 8900,
        "subtotal_usd": 8900,
        "discount_total_usd": 0,
        "tax_usd": 0,
        "total_usd": 8900,
        "subtotal_formatted": "$89.00",
        "discount_total_formatted": "$0.00",
        "tax_formatted": "$0.00",
        "total_formatted": "$89.00",
        "first_order_item": {
            "id": 1564670,
            "order_id": 1602320,
            "product_id": 131530,
            "variant_id": 154371,
            "price_id": 152412,
            "product_name": "Basic",
            "variant_name": "Default",
            "price": 8900,
            "created_at": "2023-11-19T19:06:28.000000Z",
            "updated_at": "2023-11-19T19:06:28.000000Z",
            "test_mode": true
        },
        "urls": {
            "receipt": "..."
        },
        "created_at": "2023-11-19T19:06:23.000000Z",
        "updated_at": "2023-11-19T19:06:28.000000Z",
        "test_mode": true
    },
    "relationships": {
        "store": {
            "links": {
                "related": "https://api.lemonsqueezy.com/v1/orders/1602320/store",
                "self": "https://api.lemonsqueezy.com/v1/orders/1602320/relationships/store"
            }
        },
        "customer": {
            "links": {
                "related": "https://api.lemonsqueezy.com/v1/orders/1602320/customer",
                "self": "https://api.lemonsqueezy.com/v1/orders/1602320/relationships/customer"
            }
        },
        "order-items": {
            "links": {
                "related": "https://api.lemonsqueezy.com/v1/orders/1602320/order-items",
                "self": "https://api.lemonsqueezy.com/v1/orders/1602320/relationships/order-items"
            }
        },
        "subscriptions": {
            "links": {
                "related": "https://api.lemonsqueezy.com/v1/orders/1602320/subscriptions",
                "self": "https://api.lemonsqueezy.com/v1/orders/1602320/relationships/subscriptions"
            }
        },
        "license-keys": {
            "links": {
                "related": "https://api.lemonsqueezy.com/v1/orders/1602320/license-keys",
                "self": "https://api.lemonsqueezy.com/v1/orders/1602320/relationships/license-keys"
            }
        },
        "discount-redemptions": {
            "links": {
                "related": "https://api.lemonsqueezy.com/v1/orders/1602320/discount-redemptions",
                "self": "https://api.lemonsqueezy.com/v1/orders/1602320/relationships/discount-redemptions"
            }
        }
    },
    "links": {
        "self": "https://api.lemonsqueezy.com/v1/orders/1602320"
    }
}

@driesvints driesvints merged commit afbd6ec into lmsqueezy:main Nov 20, 2023
3 checks passed
@driesvints
Copy link
Collaborator

Hah, some stupid mistakes on my end 😅 sorry about that.

Thanks for the PR!

@driesvints driesvints changed the title Fix order webhook handler Fixes for orders Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants