payment:GWM
This commit is contained in:
parent
05e04fcd12
commit
63846190b1
@ -50,7 +50,8 @@ $routes->match(['get','post'],'/member_deactivate/(:any)','Member_controller::me
|
||||
$routes->match(['get','post'],'/member_activate/(:any)','Member_controller::member_activate/$1');
|
||||
$routes->match(['get'],'/scheduler','Member_controller::scheduler');
|
||||
|
||||
$routes->get('payment', 'PaymentController::index');
|
||||
$routes->match(['get','post'],'/payment', 'PaymentController::index');
|
||||
$routes->get('payment_form', 'PaymentController::payment_form');
|
||||
$routes->post('processPayment', 'PaymentController::processPayment');
|
||||
|
||||
|
||||
|
||||
@ -8,8 +8,8 @@ use App\Models\Member_credits_model;
|
||||
use App\Models\Packages_and_pricing_model;
|
||||
use App\Models\Cart_model;
|
||||
use App\Models\Credits_usage_tracking_model;
|
||||
use Config\Services;
|
||||
use App\Libraries\SquareService;
|
||||
|
||||
|
||||
class Member_controller extends BaseController
|
||||
{
|
||||
public $session;
|
||||
@ -444,63 +444,7 @@ class Member_controller extends BaseController
|
||||
|
||||
|
||||
|
||||
public function processPayment()
|
||||
{
|
||||
try {
|
||||
$amount = 100; // Amount in cents
|
||||
|
||||
$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());
|
||||
// ...
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------------------------
|
||||
}
|
||||
|
||||
@ -8,7 +8,13 @@ use Square\Models\CreatePaymentRequest;
|
||||
use Square\Exceptions\ApiException;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use App\Models\transaction_model;
|
||||
|
||||
use App\Models\Member_model;
|
||||
use App\Models\Dashboard_model;
|
||||
use App\Models\Common_model;
|
||||
use App\Models\Member_credits_model;
|
||||
use App\Models\Packages_and_pricing_model;
|
||||
use App\Models\Cart_model;
|
||||
use App\Models\Credits_usage_tracking_model;
|
||||
|
||||
class PaymentController extends BaseController
|
||||
{
|
||||
@ -16,6 +22,14 @@ class PaymentController extends BaseController
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->session = session();
|
||||
$this->MemberModel = new Member_model();
|
||||
$this->dModel = new Dashboard_model();
|
||||
$this->cModel = new Common_model();
|
||||
$this->creditsModel = new Member_credits_model();
|
||||
$this->PackagesModel = new Packages_and_pricing_model();
|
||||
$this->cartModel = new Cart_model();
|
||||
$this->CreditsUsageTrackingModel = new Credits_usage_tracking_model();
|
||||
$this->TransactionModel = new transaction_model();
|
||||
|
||||
}
|
||||
@ -24,11 +38,51 @@ class PaymentController extends BaseController
|
||||
public function index()
|
||||
{
|
||||
|
||||
|
||||
// Load the payment form view
|
||||
return view('payment_form');
|
||||
if($this->request->getmethod() == 'get')
|
||||
{
|
||||
echo 'EGF'.rand(10,100).rand(10,100).rand(10,100);
|
||||
} else if($this->request->getmethod() == 'post') {
|
||||
|
||||
$count = count($this->request->getVar('pack_id'));
|
||||
|
||||
$amount = 0;
|
||||
for($i=0;$i<$count;$i++)
|
||||
{
|
||||
|
||||
$packageData = $this->PackagesModel->where('id',$this->request->getVar('pack_id')[$i])->find();
|
||||
|
||||
$today = date("Y-m-d");
|
||||
$cost = $packageData[0]['cost'] * $this->request->getVar('count')[$i];
|
||||
|
||||
$credits_data['member_id'] = session()->get('logged_user');
|
||||
$credits_data['package_name'] = $packageData[0]['package_name'];
|
||||
$credits_data['package_type'] = $packageData[0]['package_type'];
|
||||
$credits_data['credit_points'] = $packageData[0]['credit'];
|
||||
$credits_data['running_balance'] = $packageData[0]['credit'];
|
||||
$credits_data['expired_points'] = 0;
|
||||
$credits_data['expiring_date'] = date('Y-m-d', strtotime('+1 month', strtotime($today)));
|
||||
$credits_data['cost'] = $packageData[0]['cost'];
|
||||
$credits_data['is_active'] = 0;
|
||||
|
||||
$single_pack_no_of_count = $this->request->getVar('count')[$i];
|
||||
for($j=0;$j<$single_pack_no_of_count;$j++)
|
||||
{
|
||||
$insert_data = $this->creditsModel->save($credits_data);
|
||||
}
|
||||
|
||||
$amount = $amount + $cost;
|
||||
}
|
||||
$data['amount'] = $amount;
|
||||
|
||||
echo view('payment_form',$data);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public function payment_form()
|
||||
{
|
||||
return view('payment_form');
|
||||
}
|
||||
|
||||
public function processPayment()
|
||||
{
|
||||
@ -90,7 +144,7 @@ class PaymentController extends BaseController
|
||||
$TrancactionData['member_id'] = 0;
|
||||
$TrancactionData['transaction'] = json_encode($response->getResult());
|
||||
$this->TransactionModel->save($TrancactionData);
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
echo json_encode(array('errors' => $response->getErrors()));
|
||||
|
||||
@ -8,10 +8,10 @@
|
||||
$(document).on('click','.submit',function(){
|
||||
var formId = $(this).closest('form').attr('id');
|
||||
var formData = $('#' + formId).serialize(); // Serialize form data
|
||||
|
||||
alert(formData);
|
||||
$.ajax({
|
||||
type: "post",
|
||||
url: "<?php echo base_url(); ?>buy_pack",
|
||||
type: "get",
|
||||
url: "<?php echo base_url(); ?>payment",
|
||||
data: formData,
|
||||
json: true,
|
||||
success: function(response) {
|
||||
@ -176,6 +176,7 @@ $(document).on('click','.checkout',function(){
|
||||
<button type="button" class="btn btn-default btn-sm submit"> BUY</button>
|
||||
<button type="button" class="btn btn-default btn-sm Addtocart"> Add to cart</button>
|
||||
</form>
|
||||
<a href="<?= base_url() ?>payment?pack_id=<?= $row['id']; ?>" > buy pack </a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -183,7 +184,15 @@ $(document).on('click','.checkout',function(){
|
||||
<?php } ?>
|
||||
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<form method="post" action="<?= base_url('/payment'); ?>">
|
||||
<input type ="text" name="pack_id[]" >
|
||||
<input type ="text" name="count[]" >
|
||||
<input type ="text" name="pack_id[]" >
|
||||
<input type ="text" name="count[]" >
|
||||
<button type="submit" >submit</button>
|
||||
</form>
|
||||
</div>
|
||||
</br><h1>My credits table</h1></br>
|
||||
<table id="mytable">
|
||||
<thead>
|
||||
|
||||
@ -61,8 +61,8 @@ $web_payment_sdk_url = $_ENV["ENVIRONMENT"] === Environment::PRODUCTION ? "https
|
||||
<span>OR</span>
|
||||
</div>
|
||||
</div>
|
||||
<input type="hidden" value="500" name="amount" id="amount">
|
||||
<div id="card-container"></div><button id="card-button" type="button">Pay with Card</button>
|
||||
<input type="hidden" value="<?= $amount; ?>" name="amount" id="amount">
|
||||
<div id="card-container"></div><button id="card-button" type="button">Pay with Card <?= $amount; ?></button>
|
||||
<span id="payment-flow-message"></span>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user