42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\PayRegistrationRequest;
|
|
use App\Models\PaymentIntent;
|
|
use App\Models\Registration;
|
|
use App\Services\XenditService;
|
|
|
|
class PaymentController extends Controller
|
|
{
|
|
public function pay(Registration $registration, PayRegistrationRequest $request, XenditService $xendit)
|
|
{
|
|
$data = $request->validated();
|
|
|
|
// TODO: determine amount from event pricing table
|
|
$amount = 1000000; // placeholder IDR
|
|
|
|
$intent = PaymentIntent::create([
|
|
'registration_id' => $registration->id,
|
|
'provider' => 'XENDIT',
|
|
'channel' => $data['method'], // INVOICE
|
|
'amount' => $amount,
|
|
'currency' => 'IDR',
|
|
'status' => 'PENDING',
|
|
]);
|
|
|
|
$invoice = $xendit->createInvoice($intent, $registration);
|
|
|
|
$intent->provider_ref_id = $invoice['provider_ref_id'];
|
|
$intent->checkout_url = $invoice['checkout_url'];
|
|
$intent->raw_payload = $invoice['raw_payload'] ?? null;
|
|
$intent->save();
|
|
|
|
return response()->json([
|
|
'payment_intent_id' => $intent->id,
|
|
'checkout_url' => $intent->checkout_url,
|
|
]);
|
|
}
|
|
}
|