Paddle subscription cancellation and invoice downloading issues.

mohamedfourti

Dec 30th, 2024 07:15 AM

Hello,

I’ve been testing the Paddle sandbox and ran into issues with both subscription cancellation and invoice downloading.

For cancellation, I got this error:

SQLSTATE: Invalid datetime format: 1292 Incorrect datetime value: '2025-01-13T12:29:59.848Z' for column `database`.`subscriptions`.`ends_at` at row 1 (Connection: mysql, SQL: update `subscriptions` set `ends_at` = 2025-01-13T12:29:59.848Z, `subscriptions`.`updated_at` = 2024-12-30 14:20:08 where `id` = 1)  

I’ve set up all the .env variables, so I’m not sure if the issue is on my end or Wave’s side. However, the cancellation worked fine when I tested on a fresh Wave install using Herd and ngrok. It seems like it might be caused by my setup, I’m using Laravel Sail with Cloudflare Tunnel and WSL.

For invoice downloading, I encountered this error:

Undefined property: stdClass::$data  
"userId": 2,  
"exception": "[object] (ErrorException(code: 0): Undefined property: stdClass::$data at /var/www/html/wave/src/Http/Controllers/SubscriptionController.php:201)  

This happens even on a fresh Wave install using Herd and ngrok, so it might not be related to my setup.

Any help to fix these issues would be greatly appreciated. Thanks! 😊

Edit: after further testing it turns out its caused by having a Trial period in paddle not sure how to fix this but I will try to find a workaround

bobbyiliev

Jan 3rd, 2025 12:53 AM

Hey! 👋

Thanks for reporting these issues. I haven’t tested Wave extensively with Paddle trial periods yet, but I’ll try to look into this when I have some time.

If you manage to find a solution, a PR would be greatly appreciated to help the community! 😊

Best of luck, and feel free to share any updates!

- Bobby

mohamedfourti

Jan 3rd, 2025 01:55 PM

Hello! No way a newbie like me could fix this xD, but I did figure out a workaround for anyone else stuck on this. It's just a temporary fix, though. The trial period price is set to 0.00, so I just filtered the invoices before showing them to users in the settings.invoices blade file.

@php
    $invoices = auth()->user()->invoices();
    $filteredInvoices = [];
    if (is_array($invoices)) {
        $filteredInvoices = array_filter($invoices, function($invoice) {
            return $invoice->total > 0.00;
        });
    }
@endphp

And then I just used the $filteredInvoices variable in the Blade file. Also for the cancellation issue, it turned out to be a problem with how the endsAt record was stored in the database. I had to convert it from ISO 8601 datetime format to MySQL DateTime. Not sure how this will affect other databases, but it works for me, I just updated the record in the cancel function of update.php.

    public function cancel()
    {
        $subscription = auth()->user()->latestSubscription();
        $response = Http::withToken(config('wave.paddle.api_key'))->post($this->paddle_url . '/subscriptions/' . $subscription->vendor_subscription_id . '/cancel', [
            'reason' => 'Customer requested cancellation'
        ]);
    
        if ($response->successful()) {
            $this->cancellation_scheduled = true;
    
            $responseObject = json_decode($response->body());
            
            // Convert the ISO 8601 datetime to MySQL datetime format
            $endsAt = new \DateTime($responseObject->data->current_billing_period->ends_at);
            $subscription->ends_at = $endsAt->format('Y-m-d H:i:s');
            
            $subscription->save();
    
            $this->js("window.dispatchEvent(new CustomEvent('close-modal', { detail: { id: 'cancel-modal' }}));");
            Notification::make()
                ->title('Cancellation scheduled.')
                ->success()
                ->send();
        }
    }

Before it worked because i was using sqlite but not with MySQL/MariaDB so you might want to look into that. Hope this helps in any way!