lmsqueezy / laravel

A package to easily integrate your Laravel application with Lemon Squeezy.
https://lemonsqueezy.com
MIT License
503 stars 50 forks source link

Fixes for orders #62

Closed calebporzio closed 10 months ago

calebporzio commented 10 months ago

This PR contains the following fixes:

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 commented 10 months ago

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 commented 10 months ago

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

Thanks for the PR!