40 lines
1.1 KiB
PHP
40 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Integrations\Whmcs\Writers;
|
|
|
|
use App\Integrations\Whmcs\DTOs\OrderItemData;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class OrderItemWriter
|
|
{
|
|
/**
|
|
* Skips items whose order couldn't be resolved — order_items.order_id is NOT NULL.
|
|
* Requires whmcs:sync-orders to have already run.
|
|
*/
|
|
public function write(OrderItemData $data): bool
|
|
{
|
|
if ($data->orderId === null) {
|
|
return false;
|
|
}
|
|
|
|
DB::table('order_items')->updateOrInsert(
|
|
['legacy_id' => $data->legacyId],
|
|
[
|
|
'order_id' => $data->orderId,
|
|
'product_id' => $data->productId,
|
|
'product_pricing_id' => $data->productPricingId,
|
|
'server_name' => $data->serverName,
|
|
'domain_name' => $data->domainName,
|
|
'billing_cycle' => $data->billingCycle,
|
|
'months' => $data->months,
|
|
'quantity' => $data->quantity,
|
|
'price' => $data->price,
|
|
'created_at' => $data->createdAt,
|
|
'updated_at' => $data->updatedAt,
|
|
]
|
|
);
|
|
|
|
return true;
|
|
}
|
|
}
|