<?php
class CreateInvoice extends CreateRecord
{
protected static string $resource = InvoiceResource::class;
protected function mutateFormDataBeforeCreate(array $data): array
{
\Midtrans\Config::$serverKey = config('midtrans.serverKey');
\Midtrans\Config::$isProduction = false;
\Midtrans\Config::$isSanitized = true;
\Midtrans\Config::$is3ds = true;
$repeater = $data['item_variations'];
$totalPrice = 0;
for ($i=0; $i < count($repeater); $i++) {
$totalPrice += $repeater[$i]['price'];
}
$partner = Partner::find($data['partner_id']);
$params = array(
'transaction_details' => array(
'order_id' => rand(),
'gross_amount' => $totalPrice,
),
'customer_details' => array(
'first_name' => $partner->name,
'phone' => $partner->phone_number,
),
);
$snapToken = \Midtrans\Snap::getSnapToken($params);
$data['midtrans_order_id'] = $snapToken;
return $data;
}
}