FIX LOGICAL ISSUES IN PAYMENT CALLBACK PAGE

This commit is contained in:
Srinivas-Saravanan 2024-11-13 14:15:06 +05:30
parent cdba8b8c82
commit bea5fee7ff
4 changed files with 51 additions and 33 deletions

View File

@ -507,6 +507,20 @@ public function create_or_update_invoice_items($invoice_id)
{
$this->save_invoice_item($invoice_id, $this->request->getPost(), (int)$this->request->getVar('product'));
}
public function generate_membership_id($length = 6) {
$characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomIndex = random_int(0, $charactersLength - 1);
$randomString .= $characters[$randomIndex];
}
return $randomString;
}
public function create_or_update_subscription($invoice_id, $msg_flag_name = null)
{
$model = new InvoiceModel();
@ -519,10 +533,10 @@ public function create_or_update_subscription($invoice_id, $msg_flag_name = null
$product_id = $item['product'];
$from_sub_date = $item['from_subscription'];
$to_sub_date = $item['to_subscription'];
$membership_id =random_int(100000, 999999);
$membership_id = $this->generate_membership_id(6);
$result = $subModel->where('membership_id',$membership_id)->findAll();
if (count($result)>0){
$membership_id = random_int(100000,999999);
$membership_id = $this->generate_membership_id(6);
}
// Prepare subscription data
$subscription_data = [
@ -541,6 +555,7 @@ public function create_or_update_subscription($invoice_id, $msg_flag_name = null
$model->insertSubscriptionData($subscription_data);
}
}
## For Updating Events Details ..
public function update_number_formatting($update_events)

View File

@ -2,6 +2,7 @@
namespace App\Controllers;
use App\Models\BooksModel;
use App\Models\CustomerModel;
use App\Models\InvoiceModel;
use App\Models\TransactionModel;
@ -22,17 +23,23 @@ class Payment extends BaseController
{
$model = new CustomerModel();
$model2 = new SubscriptionModel();
$bookModel = new BooksModel();
if ($membership_id != null){
$customer_id = $model2->select('customer_id')->where('membership_id',$membership_id)->first();
$customer_details = $model->get_customer_details_by_customer_id($customer_id);
$scheme = $model2->get_subscription_details_by_membership_id($membership_id);
//var_dump($customer_details);die();
$price = $bookModel->select('price')->where('book_id', 3)->first();
$amount = $price['price'];
log_message('debug','amount is '.$amount);
$response = [
'customer_details' => $customer_details,
'scheme' => $scheme,
'membership_id' =>$membership_id,
'CustomerID' =>$customer_id
'CustomerID' =>$customer_id,
'amount' =>$amount
];
//var_dump($response);die();
return view('subscription_renewal',$response);
@ -49,10 +56,13 @@ class Payment extends BaseController
$customer_id = $model2->select('customer_id')->where('membership_id',$membership_id)->first();
$customer_details = $model->get_customer_details_by_customer_id($customer_id);
log_message('info','inside the method post');
$price = $bookModel->select('price')->where('book_id', 3)->first();
$amount = $price['price'];
$response = [
'customer_details' => $customer_details,
'scheme' => $scheme,
'CustomerID' =>$customer_id
'CustomerID' =>$customer_id,
'amount' =>$amount
];
return $this->response->setJSON($response);
}
@ -142,7 +152,7 @@ public function payment_failure(){
];
$model4 = new TransactionModel();
$model4->save($paramList);
$model4->insert($paramList);
return view('/payment_failure');
}
@ -216,31 +226,18 @@ public function payment_success() {
$db->table('invoiceitems')->insert($requestData);
$model3 = new SubscriptionModel();
$id_exist = $model3->where('customer_id',$customer_id)->first();
if (count($id_exist)>0){
$subscriptionData = [
'scheme_id' =>3,
'customer_id' => $customer_id,
'invoice_id' => $invoice_id,
'from_subscription'=>$fsubscription,
'to_subscription'=>$tsubscription,
'is_renew' => 1,
'business_id'=>2
];
$db->table('subscription')->where('customer_id', $customer_id)->update($subscriptionData);
}else{
$subscriptionData = [
'scheme_id' =>3,
'customer_id' => $customer_id,
'invoice_id' => $invoice_id,
'from_subscription'=>$fsubscription,
'to_subscription'=>$tsubscription,
'is_renew' =>0,
'business_id'=>2
];
$subscriptionData = [
'scheme_id' =>3,
'customer_id' => $customer_id,
'invoice_id' => $invoice_id,
'from_subscription'=>$fsubscription,
'to_subscription'=>$tsubscription,
'is_renew' => 1,
'business_id'=>2,
'status' =>1
];
$db->table('subscription')->insert($subscriptionData);
}
$paramList = [
'BANKTXNID' => $this->request->getVar('BANKTXNID'),

View File

@ -344,14 +344,13 @@ public function getQueryforSubscriptionDetailsBySchemeName($flag,$condition, $va
$builder->select('subscription.from_subscription, subscription.to_subscription, subscription.scheme_id,books.price ,books.short_code');
$builder->join('books', 'subscription.scheme_id = books.book_id');
$builder->where('subscription.membership_id', $membership_id);
$builder->where('subscription.status',1);
$result = $builder->get()->getRowArray();
return $result;
}
}

View File

@ -60,7 +60,7 @@
<label for="membership_id">Membership ID</label>
<input type="text" value="<?= isset($membership_id) && ($membership_id != null) ? $membership_id : '' ?>" class="form-control" id="membership_id" name="membership_id" placeholder="Enter your Membership ID" required>
</div>
<input type="hidden" name = 'amount' value = 1>
<input type="hidden" id="amount" name = 'amount' value = "<?=isset($amount)?$amount: ''?>">
<input type="hidden" id="CustomerID" name = 'CustomerID' value = <?=isset($CustomerID)? $CustomerID['customer_id']: '' ?>>
<!-- Customer Information Section (Hidden Initially) -->
<div id="customerInfo" class="hidden-details d-none">
@ -78,7 +78,7 @@
<div class="form-group">
<select required class="form-control" id="subscriptionPlans">
<option value="" disabled selected>Select a plan</option>
<option value="1500">PUSTHAKAM Membership - 1 Year (RENEWAL) - 1500</option>
<option value="<?= isset($amount)?$amount: '' ?>">PUSTHAKAM Membership - 1 Year (RENEWAL) - <?= isset($amount)?$amount: '' ?> </option>
</select>
</div>
</div>
@ -171,6 +171,13 @@
// Display customer information
$('#customerInfo').removeClass('d-none');
$('#CustomerID').val(response.CustomerID.customer_id);
$('#amount').val(response.amount);
$('#subscriptionPlans').val(response.amount);
$('#subscriptionPlans').html(`
<option value="${response.amount}">
PUSTHAKAM Membership - 1 Year (RENEWAL) - ${response.amount}
</option>
`);
if (response.scheme) {
// Calculate expiration
var date = new Date();