laravel / cashier-paddle

Cashier Paddle provides an expressive, fluent interface to Paddle's subscription billing services.
https://laravel.com/docs/cashier-paddle
MIT License
238 stars 57 forks source link

Customer Id not matches after checkout. #269

Closed bluzeey closed 1 month ago

bluzeey commented 1 month ago

Cashier Paddle Version

2.4

Laravel Version

11.2.0

PHP Version

8.2

Database Driver & Version

My SQL 8.0 for MacOS ( Homebrew)

Description

So this is my checkout function using paddle.

    {
        // If your checkout requires auth user
        // Replace this with Auth::user()->checkout($priceId)->returnTo(route('dashboard'))
        $user= auth()->user();

        if(!$user->customer()){
            $user->createAsCustomer(['name'=>$user->name, "email"=> $user->email]);
            $user->save();
        }

        $checkout = $user->subscribe($priceId)->returnTo(route('dashboard'));

        $checkout = [
            'items' => $checkout->getItems(),
            'custom' => $checkout->getCustomData(),
![Screenshot 2024-07-23 at 6 42 45 PM](https://github.com/user-attachments/assets/9bf48dfb-7d60-4399-bd1e-14e2b55f0b8e)

            'return_url' => $checkout->getReturnUrl(),
        ];

        return \response()->json($checkout);
    }

Once subscription is done. Here are the images for current customers I have and what i get from webhooks. Screenshot 2024-07-23 at 6 43 48 PM Getting customer id "customer_id":"ctm_01j1f4eqj4mv97kgsdpb0w2836".

{"data":{"id":"txn_01j3fq3mtwz0h4d5bt1zcz2x37","items":[{"price":{"id":"pri_01j1yd1qbee4venpj1r0kt8m7m","name":"KanbanCast Pro","type":"standard","status":"active","quantity":{"maximum":999999,"minimum":1},"tax_mode":"account_setting","created_at":"2024-07-04T08:16:21.358404Z","product_id":"pro_01j1yd12mfa18ewr1ny42s8p6t","unit_price":{"amount":"900","currency_code":"USD"},"updated_at":"2024-07-04T08:16:21.358404Z","custom_data":null,"description":"KanbanCast Pro Subscription","trial_period":{"interval":"day","frequency":7},"billing_cycle":{"interval":"month","frequency":1},"unit_price_overrides":[]},"price_id":"pri_01j1yd1qbee4venpj1r0kt8m7m","quantity":1,"proration":null}],"origin":"web","status":"completed","details":{"totals":{"fee":"0","tax":"0","total":"0","credit":"0","balance":"0","discount":"0","earnings":"0","subtotal":"0","grand_total":"0","currency_code":"USD","credit_to_balance":"0"},"line_items":[{"id":"txnitm_01j3fq3tb9808r03v8764wnnb7","totals":{"tax":"0","total":"0","discount":"0","subtotal":"0"},"item_id":null,"product":{"id":"pro_01j1yd12mfa18ewr1ny42s8p6t","name":"KanbanCast","type":"standard","status":"active","image_url":null,"created_at":"2024-07-04T08:16:00.143Z","updated_at":"2024-07-04T08:16:00.143Z","custom_data":null,"description":"Subscription product for Kanbancast.com","tax_category":"standard"},"price_id":"pri_01j1yd1qbee4venpj1r0kt8m7m","quantity":1,"tax_rate":"0.18","unit_totals":{"tax":"0","total":"0","discount":"0","subtotal":"0"}}],"payout_totals":{"fee":"0","tax":"0","total":"0","credit":"0","balance":"0","discount":"0","earnings":"0","fee_rate":"0","subtotal":"0","grand_total":"0","currency_code":"USD","exchange_rate":"1","credit_to_balance":"0"},"tax_rates_used":[{"totals":{"tax":"0","total":"0","discount":"0","subtotal":"0"},"tax_rate":"0.18"}],"adjusted_totals":{"fee":"0","tax":"0","total":"0","earnings":"0","subtotal":"0","grand_total":"0","currency_code":"USD"}},"checkout":{"url":"https://kanbancast.com/?_ptxn=txn_01j3fq3mtwz0h4d5bt1zcz2x37"},"payments":[{"amount":"0","status":"authorized","created_at":"2024-07-23T11:55:16.62649Z","error_code":null,"captured_at":null,"method_details":{"card":{"type":"visa","last4":"4242","expiry_year":2027,"expiry_month":6,"cardholder_name":"Sahil maheshwari"},"type":"card"},"payment_method_id":"paymtd_01j3fq47r186j7weg0wsj3m2j4","payment_attempt_id":"ec42e961-09c0-42e8-8c8b-7bc904bd997f","stored_payment_method_id":"c5d1f8df-06e9-4403-a555-16e1e7ea45f7"}],"billed_at":"2024-07-23T11:55:18.546448Z","address_id":"add_01j3fq3swyq6q1agtjwhd6f5ca","created_at":"2024-07-23T11:54:57.327082Z","invoice_id":null,"updated_at":"2024-07-23T11:56:50.358001719Z","business_id":null,"custom_data":null,"customer_id":"ctm_01j1f4eqj4mv97kgsdpb0w2836","discount_id":null,"receipt_data":null,"currency_code":"USD","billing_period":{"ends_at":"2024-07-30T11:55:18.874Z","starts_at":"2024-07-23T11:55:18.874Z"},"invoice_number":null,"billing_details":null,"collection_mode":"automatic","subscription_id":"sub_01j3fq49z33k0etep4qby7tyxv"},"event_id":"evt_01j3fq73qdds66ytpdasg9cmvv","event_type":"transaction.updated","occurred_at":"2024-07-23T11:56:50.797290Z","notification_id":"ntf_01j3fq73xna1yn70ncb54b3a42"}  

I get back events through webhook, but they have different customer id , then the user model customer.

Steps To Reproduce

To recreate the same, we use the checkout function and link it to a paddle store with webhook.

driesvints commented 1 month ago

This shouldn't be possible. The customer is always created before the subscription is made. Maybe you need to refresh the user model right before the $checkout = $user->subscribe call? In any case this is something for a support channel:

bluzeey commented 1 month ago

Apologies, for dragging conversation @driesvints . I tried the refresh on the user model as well. But second i was thinking if we could pass the user attributes in the custom data with checkout , so i can access them in the webhook , but that didn't work as well