payment:GWM

This commit is contained in:
sriramv 2023-06-02 17:28:51 +05:30
parent 1fcf0d4889
commit 6a82176d96
4 changed files with 52 additions and 29 deletions

View File

@ -15,6 +15,7 @@ use App\Models\Member_credits_model;
use App\Models\Packages_and_pricing_model; use App\Models\Packages_and_pricing_model;
use App\Models\Cart_model; use App\Models\Cart_model;
use App\Models\Credits_usage_tracking_model; use App\Models\Credits_usage_tracking_model;
use App\Models\Rule_model;
class PaymentController extends BaseController class PaymentController extends BaseController
{ {
@ -31,40 +32,45 @@ class PaymentController extends BaseController
$this->cartModel = new Cart_model(); $this->cartModel = new Cart_model();
$this->CreditsUsageTrackingModel = new Credits_usage_tracking_model(); $this->CreditsUsageTrackingModel = new Credits_usage_tracking_model();
$this->TransactionModel = new transaction_model(); $this->TransactionModel = new transaction_model();
$this->RuleModel = new Rule_model();
} }
public function index() public function index()
{ {
if($this->request->getmethod() == 'get') $CartData = $this->cartModel->where('member_id',session()->get('logged_user'))->findAll();
{ $count = count($CartData);
echo 'EGF'.rand(10,100).rand(10,100).rand(10,100); if($count)
} else if($this->request->getmethod() == 'post') { {
$credit_pack_expiry_duration = $this->RuleModel->select('value')->where('rule_key', 1 )->get()->getRow()->value;
$count = count($this->request->getVar('pack_id')); $gst = $this->RuleModel->select('value')->where('rule_key', 3 )->get()->getRow()->value;
$pst = $this->RuleModel->select('value')->where('rule_key', 4 )->get()->getRow()->value;
$today = date("Y-m-d");
$days = "+".$credit_pack_expiry_duration." days";
$amount = 0; $amount = 0;
$orderId = 'EGF'.rand(10,100).rand(10,100).rand(10,100);
$packageArray = [];
for($i=0;$i<$count;$i++) for($i=0;$i<$count;$i++)
{ {
$packageData = $this->PackagesModel->where('id',$CartData[$i]['pack_id'])->find();
$packageData = $this->PackagesModel->where('id',$this->request->getVar('pack_id')[$i])->find(); $packageData[0]['count'] = $CartData[$i]['count'];
array_push($packageArray , $packageData[0]);
$today = date("Y-m-d"); $cost = $packageData[0]['cost'] * $CartData[$i]['count'];
$cost = $packageData[0]['cost'] * $this->request->getVar('count')[$i]; // $this->RuleModel->where('rule_key', 1 )->find()->value;
$credits_data['member_id'] = session()->get('logged_user'); $credits_data['member_id'] = session()->get('logged_user');
$credits_data['package_name'] = $packageData[0]['package_name']; $credits_data['package_name'] = $packageData[0]['package_name'];
$credits_data['package_type'] = $packageData[0]['package_type']; $credits_data['package_type'] = $packageData[0]['package_type'];
$credits_data['credit_points'] = $packageData[0]['credit']; $credits_data['credit_points'] = $packageData[0]['credit'];
$credits_data['running_balance'] = $packageData[0]['credit']; $credits_data['running_balance'] = $packageData[0]['credit'];
$credits_data['expired_points'] = 0; $credits_data['expired_points'] = 0;
$credits_data['expiring_date'] = date('Y-m-d', strtotime('+1 month', strtotime($today))); $credits_data['expiring_date'] = date('Y-m-d', strtotime($days, strtotime($today)));
$credits_data['cost'] = $packageData[0]['cost']; $credits_data['cost'] = $packageData[0]['cost'];
$credits_data['is_active'] = 0; $credits_data['is_active'] = 0;
$credits_data['order_id'] = $orderId;
$credits_data['cost_with_tax'] = round( ( $packageData[0]['cost'] + (($packageData[0]['cost'] * ($gst + $pst) ) / 100) ) , 2 );
$single_pack_no_of_count = $this->request->getVar('count')[$i]; $single_pack_no_of_count = $CartData[$i]['count'];
for($j=0;$j<$single_pack_no_of_count;$j++) for($j=0;$j<$single_pack_no_of_count;$j++)
{ {
$insert_data = $this->creditsModel->save($credits_data); $insert_data = $this->creditsModel->save($credits_data);
@ -72,13 +78,25 @@ class PaymentController extends BaseController
$amount = $amount + $cost; $amount = $amount + $cost;
} }
$data['amount'] = $amount; $data['amount'] = $amount;
$data['order_id'] = $orderId;
echo view('payment_form',$data); $data['gst'] = $gst;
} $data['pst'] = $pst;
$data['packageArray'] = $packageArray;
$data['userdata']=$this->dModel->getLoggedInUserData(session()->get('logged_user'));
// echo '<pre>';
// print_r($data);
// echo '</pre>';
// die();
echo view('payment_form',$data);
} else { echo 'cart empty .. !'; }
} }
public function payment_form() public function payment_form()
{ {
return view('payment_form'); return view('payment_form');
@ -99,11 +117,13 @@ class PaymentController extends BaseController
$json = file_get_contents('php://input'); $json = file_get_contents('php://input');
$data = json_decode($json); $data = json_decode($json);
$gst = $this->RuleModel->select('value')->where('rule_key', 3 )->get()->getRow()->value;
$pst = $this->RuleModel->select('value')->where('rule_key', 4 )->get()->getRow()->value;
$token = $data->token; $token = $data->token;
$idempotencyKey = $data->idempotencyKey; $idempotencyKey = $data->idempotencyKey;
$amount = $data->amount; $amount = $data->amount;
$order_id = $data->order_id;
$Final_amount = round( ( $amount + (($amount * ($gst + $pst) ) / 100) ) , 2 );
$square_client = new SquareClient([ $square_client = new SquareClient([
'accessToken' => getenv('SQUARE_ACCESS_TOKEN'), 'accessToken' => getenv('SQUARE_ACCESS_TOKEN'),
@ -120,7 +140,7 @@ class PaymentController extends BaseController
$money = new Money(); $money = new Money();
// Monetary amounts are specified in the smallest unit of the applicable currency. // 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. // This amount is in cents. It's also hard-coded for $1.00, which isn't very useful.
$money->setAmount($amount); $money->setAmount($Final_amount);
// Set currency to the currency for the location // Set currency to the currency for the location
$money->setCurrency($location_info->getCurrency()); $money->setCurrency($location_info->getCurrency());
@ -140,11 +160,12 @@ class PaymentController extends BaseController
if ($response->isSuccess()) { if ($response->isSuccess()) {
echo json_encode($response->getResult()); echo json_encode($response->getResult());
$TrancactionId = $response->getResult()->payment->id;
$TrancactionData['member_id'] = 0; $TrancactionData['member_id'] = session()->get('logged_user');
$TrancactionData['transaction'] = json_encode($response->getResult()); $TrancactionData['transaction'] = json_encode($response->getResult());
$this->TransactionModel->save($TrancactionData); $this->TransactionModel->save($TrancactionData);
$this->creditsModel->where('order_id', $order_id )->where('member_id', session()->get('logged_user'))
->set(array( 'is_active' => 1 , 'transaction_id' => $TrancactionId ))->update();
} else { } else {
echo json_encode(array('errors' => $response->getErrors())); echo json_encode(array('errors' => $response->getErrors()));

View File

@ -7,7 +7,7 @@ class Member_credits_model extends Model
protected $table = 'member_credits'; protected $table = 'member_credits';
protected $primaryKey = 'id'; protected $primaryKey = 'id';
protected $allowedFields = ['member_id','package_name','package_type','credit_points','running_balance','used_points', 'expired_points','expiring_date', 'cost' ,'is_active']; protected $allowedFields = ['member_id','package_name','package_type','credit_points','running_balance','used_points', 'expired_points','expiring_date', 'cost' ,'is_active', 'order_id','transaction_id' ,'cost_with_tax'];
} }

View File

@ -62,6 +62,7 @@ $web_payment_sdk_url = $_ENV["ENVIRONMENT"] === Environment::PRODUCTION ? "https
</div> </div>
</div> </div>
<input type="hidden" value="<?= $amount; ?>" name="amount" id="amount"> <input type="hidden" value="<?= $amount; ?>" name="amount" id="amount">
<input type="hidden" value="<?= $order_id; ?>" name="order_id" id="order_id">
<div id="card-container"></div><button id="card-button" type="button">Pay with Card <?= $amount; ?></button> <div id="card-container"></div><button id="card-button" type="button">Pay with Card <?= $amount; ?></button>
<span id="payment-flow-message"></span> <span id="payment-flow-message"></span>
</div> </div>

View File

@ -65,3 +65,4 @@ $app->setContext($context);
*/ */
$app->run(); $app->run();