Migrate billing from Paddle to Lemon Squeezy
This commit is contained in:
@@ -7,7 +7,7 @@ use App\Models\EventPackage;
|
||||
use App\Models\PackagePurchase;
|
||||
use App\Models\Tenant;
|
||||
use App\Notifications\Customer\WithdrawalConfirmed;
|
||||
use App\Services\Paddle\PaddleTransactionService;
|
||||
use App\Services\LemonSqueezy\LemonSqueezyOrderService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@@ -36,7 +36,7 @@ class WithdrawalController extends Controller
|
||||
|
||||
public function confirm(
|
||||
WithdrawalConfirmRequest $request,
|
||||
PaddleTransactionService $transactions,
|
||||
LemonSqueezyOrderService $orders,
|
||||
string $locale
|
||||
): RedirectResponse {
|
||||
$user = $request->user();
|
||||
@@ -60,10 +60,10 @@ class WithdrawalController extends Controller
|
||||
->with('error', __('marketing.withdrawal.errors.not_eligible', [], $locale));
|
||||
}
|
||||
|
||||
$transactionId = $this->resolveTransactionId($purchase);
|
||||
$orderId = $this->resolveOrderId($purchase);
|
||||
|
||||
if (! $transactionId) {
|
||||
Log::warning('Withdrawal missing Paddle transaction reference.', [
|
||||
if (! $orderId) {
|
||||
Log::warning('Withdrawal missing Lemon Squeezy order reference.', [
|
||||
'purchase_id' => $purchase->id,
|
||||
'provider' => $purchase->provider,
|
||||
]);
|
||||
@@ -74,11 +74,11 @@ class WithdrawalController extends Controller
|
||||
}
|
||||
|
||||
try {
|
||||
$transactions->refund($transactionId, ['reason' => 'withdrawal']);
|
||||
$orders->refund($orderId, ['reason' => 'withdrawal']);
|
||||
} catch (\Throwable $exception) {
|
||||
Log::warning('Withdrawal refund failed', [
|
||||
'purchase_id' => $purchase->id,
|
||||
'transaction_id' => $transactionId,
|
||||
'order_id' => $orderId,
|
||||
'error' => $exception->getMessage(),
|
||||
]);
|
||||
|
||||
@@ -94,13 +94,13 @@ class WithdrawalController extends Controller
|
||||
$withdrawalMeta = array_merge($withdrawalMeta, [
|
||||
'confirmed_at' => $confirmedAt->toIso8601String(),
|
||||
'confirmed_by' => $user?->id,
|
||||
'transaction_id' => $transactionId,
|
||||
'order_id' => $orderId,
|
||||
]);
|
||||
|
||||
$metadata['withdrawal'] = $withdrawalMeta;
|
||||
|
||||
$purchase->forceFill([
|
||||
'provider_id' => $transactionId,
|
||||
'provider_id' => $orderId,
|
||||
'refunded' => true,
|
||||
'metadata' => $metadata,
|
||||
])->save();
|
||||
@@ -127,7 +127,7 @@ class WithdrawalController extends Controller
|
||||
->with('package')
|
||||
->where('tenant_id', $tenant->id)
|
||||
->where('type', 'endcustomer_event')
|
||||
->where('provider', 'paddle')
|
||||
->where('provider', 'lemonsqueezy')
|
||||
->where('refunded', false)
|
||||
->orderByDesc('purchased_at')
|
||||
->orderByDesc('id')
|
||||
@@ -151,7 +151,7 @@ class WithdrawalController extends Controller
|
||||
$reasons[] = 'type';
|
||||
}
|
||||
|
||||
if ($purchase->provider !== 'paddle') {
|
||||
if ($purchase->provider !== 'lemonsqueezy') {
|
||||
$reasons[] = 'provider';
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ class WithdrawalController extends Controller
|
||||
$reasons[] = 'refunded';
|
||||
}
|
||||
|
||||
if (! $this->resolveTransactionId($purchase)) {
|
||||
if (! $this->resolveOrderId($purchase)) {
|
||||
$reasons[] = 'missing_reference';
|
||||
}
|
||||
|
||||
@@ -224,13 +224,13 @@ class WithdrawalController extends Controller
|
||||
];
|
||||
}
|
||||
|
||||
private function resolveTransactionId(PackagePurchase $purchase): ?string
|
||||
private function resolveOrderId(PackagePurchase $purchase): ?string
|
||||
{
|
||||
if ($purchase->provider === 'paddle' && $purchase->provider_id) {
|
||||
if ($purchase->provider === 'lemonsqueezy' && $purchase->provider_id) {
|
||||
return (string) $purchase->provider_id;
|
||||
}
|
||||
|
||||
return data_get($purchase->metadata, 'paddle_transaction_id');
|
||||
return data_get($purchase->metadata, 'lemonsqueezy_order_id');
|
||||
}
|
||||
|
||||
private function deactivateTenantPackage(Tenant $tenant, PackagePurchase $purchase): void
|
||||
|
||||
Reference in New Issue
Block a user