diff --git a/app/Config/CronJob.php b/app/Config/CronJob.php index d821a95..3ab6a3c 100644 --- a/app/Config/CronJob.php +++ b/app/Config/CronJob.php @@ -4,7 +4,6 @@ namespace Config; use CodeIgniter\Config\BaseConfig; use Daycry\CronJob\Scheduler; -use App\Controllers\Member_controller; class CronJob extends \Daycry\CronJob\Config\CronJob { @@ -119,12 +118,6 @@ class CronJob extends \Daycry\CronJob\Config\CronJob */ public function init(Scheduler $schedule) { - - $Member_controller = new Member_controller(); - - //$schedule->call( function() { $Member_controller->shedule(); } )->everyMinute(); - $schedule->url('http://localhost/golf_backend/scheduler')->everyFiveMinutes(); - // $schedule->command('foo:bar')->everyMinute(); // $schedule->shell('cp foo bar')->daily( '11:00 pm' ); diff --git a/app/Config/Database.php b/app/Config/Database.php index 0bad5b4..b87f88e 100644 --- a/app/Config/Database.php +++ b/app/Config/Database.php @@ -26,11 +26,15 @@ class Database extends Config */ public array $default = [ 'DSN' => '', + // 'hostname' => 'giowm1257.siteground.biz', + // 'username' => 'uzc4szyzilgtb', + // 'password' => '%oG5)&$2q1@c', + // 'database' => 'dbphhez2g1zmyf', 'hostname' => 'localhost', 'username' => 'root', 'password' => '', 'database' => 'golf', - 'DBDriver' => 'MySQLi', + 'DBDriver' => 'mysqli', 'DBPrefix' => '', 'pConnect' => false, 'DBDebug' => true, diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 9556364..8b6c00c 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -49,7 +49,10 @@ $routes->match(['get','post'],'/change_password_form','Member_controller::change $routes->match(['get','post'],'/member_deactivate/(:any)','Member_controller::member_deactivate/$1'); $routes->match(['get','post'],'/member_activate/(:any)','Member_controller::member_activate/$1'); $routes->match(['get'],'/scheduler','Member_controller::scheduler'); -$routes->match(['get'],'/processPayment','Member_controller::processPayment'); + +$routes->get('payment', 'PaymentController::index'); +$routes->post('processPayment', 'PaymentController::processPayment'); + diff --git a/app/Controllers/Admin_controller.php b/app/Controllers/Admin_controller.php index 145cdcb..25a3158 100644 --- a/app/Controllers/Admin_controller.php +++ b/app/Controllers/Admin_controller.php @@ -30,6 +30,8 @@ class Admin_controller extends BaseController $data=[]; + //$database = \Config\Database::connect(); + if($this->request->getmethod() == 'post') { @@ -37,7 +39,7 @@ class Admin_controller extends BaseController //echo $email; die(); $password = $this->request->getVar('password'); $userdata = $this->UserModel->verifyEmail($email); - + //print_r($userdata); die(); if($userdata) { @@ -49,12 +51,12 @@ class Admin_controller extends BaseController } else{ $this->session->setTempdata('error','sorry wrong password entered for the Email',3); - return redirect()->to(base_url()."/admin"); + return redirect()->to(base_url()."admin"); } }else { $this->session->setTempdata('error','sorry Email does not exist',3); - return redirect()->to(base_url()."/admin"); + return redirect()->to(base_url()."admin"); } } return view('admin_login'); diff --git a/app/Controllers/Dashboard.php b/app/Controllers/Dashboard.php index 27e6b84..bd9737c 100644 --- a/app/Controllers/Dashboard.php +++ b/app/Controllers/Dashboard.php @@ -4,17 +4,25 @@ use App\Models\Dashboard_model; use App\Models\Packages_and_pricing_model; use App\Models\Member_credits_model; use App\Models\Cart_model; - +use App\Models\Member_model; +use App\Models\Common_model; +use App\Models\Credits_usage_tracking_model; +use App\Models\User_model; class Dashboard extends BaseController { public function __construct() { + $this->session = session(); $this->dModel = new Dashboard_model(); + $this->UserModel = new User_model(); $this->PackagesModel = new Packages_and_pricing_model(); $this->creditsModel = new Member_credits_model(); $this->cartModel = new Cart_model(); + $this->MemberModel = new Member_model(); + $this->cModel = new Common_model(); + $this->CreditsUsageTrackingModel = new Credits_usage_tracking_model(); } public function index() { @@ -32,6 +40,10 @@ class Dashboard extends BaseController $id = session()->get('logged_user'); $data['userdata']=$this->dModel->getLoggedInUserData($id); + $data['MembersCount'] = $this->MemberModel->selectCount('id')->get()->getRow()->id; + $data['AdminCount'] = $this->UserModel->selectCount('id')->where('role','Admin')->get()->getRow()->id; + $data['CoachCount'] = $this->UserModel->selectCount('id')->where('role','Coach')->get()->getRow()->id; + $data['FrontdeskCount'] = $this->UserModel->selectCount('id')->where('role','Frontdesk')->get()->getRow()->id; echo view('layout/header',$data); echo view('dashboard',$data); echo view('layout/footer'); diff --git a/app/Controllers/Member_controller.php b/app/Controllers/Member_controller.php index 80b8393..8a4a788 100644 --- a/app/Controllers/Member_controller.php +++ b/app/Controllers/Member_controller.php @@ -325,8 +325,8 @@ class Member_controller extends BaseController //print_r($FormData);die(); $needed_points = $FormData['points']; - $columnName = 'running_balance'; - $count = $this->creditsModel->selectSum($columnName)->where('member_id',$FormData['member_id'])->get()->getRow()->$columnName; + + $count = $this->creditsModel->selectSum('running_balance')->where('member_id',$FormData['member_id'])->get()->getRow()->running_balance; if($count > $needed_points) { $creditsData = $this->creditsModel->where('member_id',$FormData['member_id'])->findAll(); @@ -447,22 +447,63 @@ class Member_controller extends BaseController - public function processPayment() { - $square = new SquareService(); - $result = $square->processPayment(100); // Process payment of $100 - return $result; - // Handle the payment result - // ... - } - // public function processPayment() - // { - // $square = new SquareService(); - // $paymentForm = $square->getSquarePaymentForm(); + try { + $amount = 100; // Amount in cents - // // Load the Square payment form view - // return view('payment_form', ['paymentForm' => $paymentForm]); - // } + $square = new SquareService(); + $response = $square->processPayment($amount); + + // Handle the payment response + if ($response->isSuccess()) { + // Payment succeeded + } else { + // Payment failed + } + } catch (\Exception $e) { + // Handle exceptions + echo $e->getMessage(); + log_message('error', 'Exception: ' . $e->getMessage()); + // ... + } catch (\Error $e) { + // Handle errors + echo $e->getMessage(); + log_message('error', 'Error: ' . $e->getMessage()); + // ... + } + } + + + public function processCardPayment() + { + try { + //echo "hai"; die(); + // Get the payment nonce and amount from the submitted form + $nonce = 'test'; + $amount = 100; +// echo $nonce;die(); + $square = new SquareService(); + $response = $square->processCardPayment($nonce, $amount); + + // Handle the payment response + if ($response && $response->isSuccess()) { + // Payment succeeded + } else { + // Payment failed + } + } catch (\Exception $e) { + // Handle exceptions + echo $e->getMessage(); + log_message('error', 'Exception: ' . $e->getMessage()); + // ... + } catch (\Error $e) { + // Handle errors + echo $e->getMessage(); + log_message('error', 'Error: ' . $e->getMessage()); + // ... + } + } + // ----------------------------------------------- } diff --git a/app/Controllers/PaymentController.php b/app/Controllers/PaymentController.php new file mode 100644 index 0000000..4ff7b4f --- /dev/null +++ b/app/Controllers/PaymentController.php @@ -0,0 +1,134 @@ +TransactionModel = new transaction_model(); + + } + + + public function index() + { + + + // Load the payment form view + return view('payment_form'); + + } + + public function processPayment() + { + try { + + if ($_SERVER['REQUEST_METHOD'] != 'POST') { + error_log('Received a non-POST request'); + echo 'Request not allowed'; + http_response_code(405); + return; + } + + include 'App\Libraries\LocationInfo.php'; + + $json = file_get_contents('php://input'); + $data = json_decode($json); + + $token = $data->token; + $idempotencyKey = $data->idempotencyKey; + $amount = $data->amount; + + + $square_client = new SquareClient([ + 'accessToken' => getenv('SQUARE_ACCESS_TOKEN'), + 'environment' => getenv('ENVIRONMENT'), + 'userAgentDetail' => 'golf_evo', // Remove or replace this detail when building your own app + ]); + + $payments_api = $square_client->getPaymentsApi(); + + // To learn more about splitting payments with additional recipients, + // see the Payments API documentation on our [developer site] + // (https://developer.squareup.com/docs/payments-api/overview). + + $money = new Money(); + // Monetary amounts are specified in the smallest unit of the applicable currency. + // This amount is in cents. It's also hard-coded for $1.00, which isn't very useful. + $money->setAmount($amount); + + // Set currency to the currency for the location + $money->setCurrency($location_info->getCurrency()); + + //print_r($money); die(); + + try { + // Every payment you process with the SDK must have a unique idempotency key. + // If you're unsure whether a particular payment succeeded, you can reattempt + // it with the same idempotency key without worrying about double charging + // the buyer. + $create_payment_request = new CreatePaymentRequest($token, $idempotencyKey, $money); + $create_payment_request->setLocationId($location_info->getId()); + + $response = $payments_api->createPayment($create_payment_request); + + if ($response->isSuccess()) { + echo json_encode($response->getResult()); + + + $TrancactionData['member_id'] = 0; + $TrancactionData['transaction'] = json_encode($response->getResult()); + $this->TransactionModel->save($TrancactionData); + + + } else { + echo json_encode(array('errors' => $response->getErrors())); + } + } catch (ApiException $e) { + echo json_encode(array('errors' => $e)); + } + } catch (\Exception $e) { + // Handle exceptions + + // Example: Logging the exception + log_message('error', 'Exception: ' . $e->getMessage()); + + // Example: Displaying a custom error message + echo 'An exception occurred: ' . $e->getMessage(); + } catch (\Error $e) { + // Handle errors + + // Example: Logging the error + log_message('error', 'Error: ' . $e->getMessage()); + + // Example: Displaying a custom error message + echo 'An error occurred: ' . $e->getMessage(); + } + } + + + + + + + + + + +} + + + + + diff --git a/app/Libraries/LocationInfo.php b/app/Libraries/LocationInfo.php new file mode 100644 index 0000000..03bf725 --- /dev/null +++ b/app/Libraries/LocationInfo.php @@ -0,0 +1,49 @@ +square_client = new SquareClient([ + 'accessToken' => $access_token, + 'environment' => getenv('ENVIRONMENT') + ]); + $location = $this->square_client->getLocationsApi()->retrieveLocation(getenv('SQUARE_LOCATION_ID'))->getResult()->getLocation(); + $this->location_id = $location->getId(); + $this->currency = $location->getCurrency(); + $this->country = $location->getCountry(); + } + + public function getCurrency() { + return $this->currency; + } + + public function getCountry() { + return $this->country; + } + + public function getId() { + return $this->location_id; + } +} + +$location_info = new LocationInfo(); + +?> \ No newline at end of file diff --git a/app/Libraries/SquareService.php b/app/Libraries/SquareService.php deleted file mode 100644 index c505980..0000000 --- a/app/Libraries/SquareService.php +++ /dev/null @@ -1,61 +0,0 @@ -client = new SquareClient([ - 'accessToken' => getenv('SQUARE_ACCESS_TOKEN'), - 'environment' => getenv('SQUARE_ENVIRONMENT') // Use 'sandbox' for testing - ]); - } - - public function processPayment($amount) - { - try { - // Create a charge request - $request = new ChargeRequest([ - 'amount_money' => [ - 'amount' => $amount, - 'currency' => 'USD' - ], - 'source_id' => 'your-test-card-nonce' // Use a test card nonce for sandbox testing - ]); - - // Make the API call to charge the payment - $response = $this->client->getTransactionsApi()->charge(getenv('SQUARE_LOCATION_ID'), $request); - - // Handle the payment response - // ... - - return $response->getResult(); - } catch (ApiException $e) { - // Handle API errors - return $e->getMessage(); - // ... - } - } - - public function getSquarePaymentForm() - { - // Create a payment form using the Square Payment Form library - $paymentForm = $this->client->getPaymentFormApi()->createPaymentForm([ - 'location_id' => getenv('SQUARE_LOCATION_ID'), - 'amount_money' => [ - 'amount' => 100, - 'currency' => 'USD' - ], - 'form_id' => 'your-form-id' // Unique ID for your payment form - ]); - - return $paymentForm->getResult(); - } -} -?> \ No newline at end of file diff --git a/app/Models/transaction_model.php b/app/Models/transaction_model.php new file mode 100644 index 0000000..0bfb9b8 --- /dev/null +++ b/app/Models/transaction_model.php @@ -0,0 +1,13 @@ + + +
- - +