switched to paddle inline checkout, removed paypal and most of stripe. added product sync between app and paddle.
This commit is contained in:
41
app/Services/Paddle/PaddleCustomerService.php
Normal file
41
app/Services/Paddle/PaddleCustomerService.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Paddle;
|
||||
|
||||
use App\Models\Tenant;
|
||||
use App\Services\Paddle\Exceptions\PaddleException;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class PaddleCustomerService
|
||||
{
|
||||
public function __construct(private readonly PaddleClient $client) {}
|
||||
|
||||
public function ensureCustomerId(Tenant $tenant): string
|
||||
{
|
||||
if ($tenant->paddle_customer_id) {
|
||||
return $tenant->paddle_customer_id;
|
||||
}
|
||||
|
||||
$payload = [
|
||||
'email' => $tenant->contact_email ?: ($tenant->user?->email ?? null),
|
||||
'name' => $tenant->name,
|
||||
];
|
||||
|
||||
if (! $payload['email']) {
|
||||
throw new PaddleException('Tenant email address required to create Paddle customer.');
|
||||
}
|
||||
|
||||
$response = $this->client->post('/customers', $payload);
|
||||
$customerId = Arr::get($response, 'data.id') ?? Arr::get($response, 'id');
|
||||
|
||||
if (! $customerId) {
|
||||
Log::error('Paddle customer creation returned no id', ['tenant' => $tenant->id, 'response' => $response]);
|
||||
throw new PaddleException('Failed to create Paddle customer.');
|
||||
}
|
||||
|
||||
$tenant->forceFill(['paddle_customer_id' => $customerId])->save();
|
||||
|
||||
return $customerId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user