initial project
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers\Frontend;
|
||||
|
||||
use App\Controllers\BaseController;
|
||||
use CodeIgniter\HTTP\ResponseInterface;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use App\Models\Orders;
|
||||
|
||||
class PaymentController extends BaseController
|
||||
{
|
||||
use ResponseTrait;
|
||||
|
||||
private $fiuu;
|
||||
private $order;
|
||||
public function __construct()
|
||||
{
|
||||
$this->fiuu = new \App\Libraries\Fiuu();
|
||||
$this->order = new Orders();
|
||||
}
|
||||
|
||||
// public function createPayment()
|
||||
// {
|
||||
// $data = $this->request->getJSON(true); // true = associative array
|
||||
|
||||
// $amount = $data['amount'] ?? '0.00';
|
||||
// $orderId = $data['order_id'] ?? 'UNKNOWN';
|
||||
|
||||
// // log_message('debug', " order_id: $orderId, amount: $amount");
|
||||
|
||||
// $result = $this->fiuu->createPayment($orderId, $amount);
|
||||
// return $this->response->setJSON($result);
|
||||
// }
|
||||
public function createPayment()
|
||||
{
|
||||
$data = $this->request->getJSON(true);
|
||||
$orderId = $data['order_id'] ?? 'UNKNOWN';
|
||||
$amount = $data['amount'] ?? '0.00';
|
||||
|
||||
$customer = [
|
||||
'name' => $data['bill_name'] ?? 'John Doe',
|
||||
'email' => $data['bill_email'] ?? 'johndoe@example.com',
|
||||
'mobile' => $data['bill_mobile'] ?? '601133094116',
|
||||
'desc' => $data['bill_desc'] ?? 'Test payment',
|
||||
'address' => $data['bill_address'] ?? '123 Jalan Teknologi',
|
||||
'postcode' => $data['bill_postcode'] ?? '47000',
|
||||
'city' => $data['bill_city'] ?? 'Petaling Jaya',
|
||||
'state' => $data['bill_state'] ?? 'Selangor',
|
||||
'country' => $data['bill_country'] ?? 'MY'
|
||||
];
|
||||
|
||||
// Call the updated Fiuu library method
|
||||
$result = $this->fiuu->createPayment($orderId, $amount, $customer);
|
||||
|
||||
return $this->response->setJSON($result);
|
||||
}
|
||||
|
||||
public function fiuuPaymentReturn()
|
||||
{
|
||||
$data = $this->request->getPost();
|
||||
|
||||
$this->fiuu->paymentNotification($data);
|
||||
}
|
||||
|
||||
public function fiuuPaymentNotification()
|
||||
{
|
||||
$data = $this->request->getPost();
|
||||
|
||||
$this->fiuu->paymentNotification($data);
|
||||
}
|
||||
|
||||
public function payAgain($order_id){
|
||||
$order = $this->order->select('orders.*, customers.name, customers.email, customers.phone')
|
||||
->join('customers', 'customers.id = orders.customer_id')
|
||||
->where('orders.id', $order_id)
|
||||
->where('orders.payment_status', 'unpaid')
|
||||
->first();
|
||||
if(!$order){
|
||||
return $this->fail('Order not found', 400);
|
||||
}
|
||||
|
||||
$payment_details = [
|
||||
'bill_name' => $order['name'],
|
||||
'bill_email' => $order['email'],
|
||||
'bill_mobile' => $order['phone'],
|
||||
'bill_desc' => 'US Pizza - Payment for ' . ucfirst($order['order_type']) . ' - ' . $order['order_so'],
|
||||
];
|
||||
$respond_data = [];
|
||||
$result = $this->fiuu->createPayment($order['order_so'], $order['grand_total'], $payment_details);
|
||||
|
||||
$respond_data['redirect_url'] = $result['redirect_url'];
|
||||
$respond_data['status'] = 200;
|
||||
$respond_data['message'] = 'Payment link generated successfully';
|
||||
|
||||
return $this->respond($respond_data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user