payment:GWM
This commit is contained in:
parent
a098635f9b
commit
2a30fb895c
@ -63,6 +63,7 @@ $routes->get('/payment_failed/(:any)', 'PaymentController::payment_failed/$1');
|
||||
$routes->post('/payment/(:any)', 'PaymentController::index/$1');
|
||||
$routes->get('payment_form', 'PaymentController::payment_form');
|
||||
$routes->post('processPayment', 'PaymentController::processPayment');
|
||||
$routes->get('createCreditPackCatalogObject', 'PaymentController::createCreditPackCatalogObject');
|
||||
|
||||
|
||||
$routes->match(['get','post'],'/test','Test_controller::sendEmail');
|
||||
|
||||
@ -7,43 +7,33 @@ namespace App\Controllers;
|
||||
|
||||
|
||||
use Square\SquareClient;
|
||||
|
||||
use Square\Models\Money;
|
||||
|
||||
use Square\Models\CreatePaymentRequest;
|
||||
|
||||
use Square\Api\CatalogApi;
|
||||
use Square\Model\CreateCatalogObjectRequest;
|
||||
use Square\Model\CatalogObject;
|
||||
use Square\Model\CatalogTax;
|
||||
use Square\Model\Money;
|
||||
use Square\Model\OrderLineItem;
|
||||
use Square\Model\CreatePaymentRequest;
|
||||
use Square\Exceptions\ApiException;
|
||||
|
||||
use Square\Api\Orders\CreateOrderRequest;
|
||||
use Square\Api\OrdersApi;
|
||||
use Square\Api\PaymentsApi;
|
||||
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;
|
||||
|
||||
use App\Models\Rule_model;
|
||||
|
||||
use App\Models\Cart_token_model;
|
||||
|
||||
use App\Models\Member_address_model;
|
||||
|
||||
use App\Models\Zipcode_model;
|
||||
|
||||
use App\Models\Country_model;
|
||||
|
||||
class PaymentController extends BaseController
|
||||
|
||||
{
|
||||
|
||||
|
||||
@ -51,35 +41,20 @@ 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();
|
||||
|
||||
$this->RuleModel = new Rule_model();
|
||||
|
||||
$this->Cart_token_model = new Cart_token_model();
|
||||
|
||||
$this->MemberAddressModel = new Member_address_model();
|
||||
|
||||
$this->ZipcodeModel = new Zipcode_model();
|
||||
|
||||
$this->CountryModel = new Country_model();
|
||||
|
||||
}
|
||||
@ -89,12 +64,9 @@ class PaymentController extends BaseController
|
||||
|
||||
|
||||
public function index($token = null)
|
||||
|
||||
{
|
||||
if($this->request->getmethod() == 'post')
|
||||
|
||||
{
|
||||
|
||||
// echo $token;die();
|
||||
if(!session()->has('logged_user'))
|
||||
{
|
||||
@ -106,22 +78,14 @@ class PaymentController extends BaseController
|
||||
|
||||
$this->session->set('token',$token);
|
||||
return redirect()->to(base_url());
|
||||
|
||||
}
|
||||
|
||||
else{
|
||||
|
||||
|
||||
|
||||
$this->payment_form();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
// echo $this->session->get('logged_user');die();
|
||||
$this->payment_form();
|
||||
|
||||
@ -140,9 +104,7 @@ class PaymentController extends BaseController
|
||||
|
||||
|
||||
public function payment_form()
|
||||
|
||||
{
|
||||
|
||||
// if(!session()->has('logged_user'))
|
||||
// {
|
||||
// return redirect()->to(base_url());
|
||||
@ -172,7 +134,6 @@ class PaymentController extends BaseController
|
||||
for($i=0;$i<$count;$i++)
|
||||
{
|
||||
$packageData = $this->PackagesModel->where('id',$CartData[$i]['pack_id'])->find();
|
||||
|
||||
$packageData[0]['count'] = $CartData[$i]['count'];
|
||||
|
||||
array_push($packageArray , $packageData[0]);
|
||||
@ -225,6 +186,7 @@ class PaymentController extends BaseController
|
||||
$data['gst'] = $gst;
|
||||
$data['pst'] = $pst;
|
||||
$data['packageArray'] = $packageArray;
|
||||
$data['EncodedArray'] = json_encode($packageArray);
|
||||
$data['country'] = $this->CountryModel->findAll();
|
||||
$data['userdata'] = $this->MemberModel->where('id', session()->get('logged_user'))->find();
|
||||
|
||||
@ -247,150 +209,123 @@ class PaymentController extends BaseController
|
||||
$output .= '<option value="'.$row['id'].'">'.$row['code'].'</option>';
|
||||
}
|
||||
$data['zipcode'] = $output;
|
||||
|
||||
|
||||
// echo '<pre>';
|
||||
// print_r($data);
|
||||
// echo '</pre>';
|
||||
// die();
|
||||
echo view('checkout',$data);
|
||||
} else { return redirect()->to(base_url()."view/".md5(session()->get('logged_user'))); }
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function processPayment()
|
||||
|
||||
{
|
||||
public function processPayment()
|
||||
{
|
||||
|
||||
try {
|
||||
|
||||
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
|
||||
|
||||
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);
|
||||
|
||||
$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;
|
||||
|
||||
$idempotencyKey = $data->idempotencyKey;
|
||||
|
||||
$amount = $data->amount;
|
||||
|
||||
$order_id = $data->order_id;
|
||||
|
||||
$order_id = $data->order_id;
|
||||
$add = $data->address;
|
||||
|
||||
$EncodedArray = json_decode($data->EncodedArray,true);
|
||||
parse_str( $add, $address);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//print_r($add);die();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$Final_amount = round( ( $amount + (($amount * ($gst + $pst) ) / 100) ) , 2 );
|
||||
$Final_amount = $Final_amount * 100;
|
||||
|
||||
$locationId = getenv('SQUARE_LOCATION_ID');
|
||||
|
||||
|
||||
$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($Final_amount);
|
||||
|
||||
|
||||
|
||||
// Set currency to the currency for the location
|
||||
|
||||
$money->setCurrency($location_info->getCurrency());
|
||||
|
||||
|
||||
|
||||
//print_r($money); die();
|
||||
|
||||
|
||||
|
||||
try {
|
||||
//create order for the payment
|
||||
// $order_line_item = new \Square\Models\OrderLineItem('1');
|
||||
// $order_line_item->setCatalogObjectId('EVYRQAQXPNUJWLLMAAHDXUHI');
|
||||
// $order_line_item1 = new \Square\Models\OrderLineItem('2');
|
||||
// $order_line_item1->setCatalogObjectId('CMU64OVJDUL7YJAFGQI33IZM');
|
||||
|
||||
// Every payment you process with the SDK must have a unique idempotency key.
|
||||
// $line_items = [$order_line_item,$order_line_item1];
|
||||
$line_items = [];
|
||||
foreach ($EncodedArray as $key => $row)
|
||||
{
|
||||
$order_line_item = '';
|
||||
$order = $order_line_item.$key;
|
||||
|
||||
$order = new \Square\Models\OrderLineItem($row['count']);
|
||||
$order->setCatalogObjectId($row['variation_id']);
|
||||
array_push($line_items , $order);
|
||||
}
|
||||
|
||||
// If you're unsure whether a particular payment succeeded, you can reattempt
|
||||
$pricing_options = new \Square\Models\OrderPricingOptions();
|
||||
$pricing_options->setAutoApplyTaxes(true);
|
||||
|
||||
$order = new \Square\Models\Order($locationId);
|
||||
$order->setLineItems($line_items);
|
||||
$order->setPricingOptions($pricing_options);
|
||||
|
||||
$body = new \Square\Models\CreateOrderRequest();
|
||||
$body->setOrder($order);
|
||||
$body->setIdempotencyKey($idempotencyKey);
|
||||
|
||||
$order_api_response = $square_client->getOrdersApi()->createOrder($body);
|
||||
|
||||
// it with the same idempotency key without worrying about double charging
|
||||
if ($order_api_response->isSuccess()) {
|
||||
|
||||
// the buyer.
|
||||
|
||||
$create_payment_request = new CreatePaymentRequest($token, $idempotencyKey, $money);
|
||||
$Data['order'] = json_encode($order_api_response->getResult());
|
||||
$this->TransactionModel->where('member_id', session()->get('logged_user'))
|
||||
->where('order_id', $order_id )
|
||||
->set($Data)->update();
|
||||
|
||||
$create_payment_request->setLocationId($location_info->getId());
|
||||
$order_api_response_result = json_encode($order_api_response->getResult());
|
||||
$order_api_response_result = json_decode( $order_api_response_result ,true);
|
||||
$orderIdFromSquare = $order_api_response_result['order']['id'];
|
||||
|
||||
|
||||
|
||||
$response = $payments_api->createPayment($create_payment_request);
|
||||
|
||||
|
||||
// Create a payment for the order
|
||||
$amount_money = new \Square\Models\Money();
|
||||
$amount_money->setAmount($Final_amount);
|
||||
$amount_money->setCurrency($location_info->getCurrency());
|
||||
|
||||
$body = new \Square\Models\CreatePaymentRequest($token, $idempotencyKey,$amount_money);
|
||||
$body->setOrderId($orderIdFromSquare);
|
||||
$body->setReferenceId($order_id);
|
||||
$body->setLocationId($locationId);
|
||||
|
||||
$response = $square_client->getPaymentsApi()->createPayment($body);
|
||||
|
||||
|
||||
if ($response->isSuccess()) {
|
||||
|
||||
|
||||
|
||||
$data = json_encode($response->getResult());
|
||||
|
||||
$result = json_decode( $data ,true);
|
||||
|
||||
//Trancaction Table Data
|
||||
@ -403,86 +338,62 @@ class PaymentController extends BaseController
|
||||
$TrancactionData['city'] = $address['city'];
|
||||
$TrancactionData['zip_code'] = $address['pincode'];
|
||||
if($address['country']=='Canada'){ $TrancactionData['state'] = $address['canada_state']; }else{ $TrancactionData['state'] = $address['state'];}
|
||||
|
||||
$TrancactionData['transaction_id'] = $result['payment']['id'];
|
||||
|
||||
$TrancactionData['payment_order_id'] = $result['payment']['order_id'];
|
||||
|
||||
$TrancactionData['transaction'] = json_encode($response->getResult());
|
||||
|
||||
$update = $this->TransactionModel->where('member_id', session()->get('logged_user'))
|
||||
|
||||
->where('order_id', $order_id )
|
||||
|
||||
->set($TrancactionData)->update();
|
||||
|
||||
if( $update)
|
||||
|
||||
{
|
||||
|
||||
$this->creditsModel->where('order_id', $order_id )->where('member_id', session()->get('logged_user'))
|
||||
|
||||
->set(array( 'is_active' => 1 , 'transaction_id' => $result['payment']['id'] ))->update();
|
||||
|
||||
$this->creditsModel->where('order_id', $order_id )->where('member_id', session()->get('logged_user'))->set(array( 'is_active' => 1 , 'transaction_id' => $result['payment']['id'] ))->update();
|
||||
$this->cartModel->where('order_id', $order_id )->delete();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
echo json_encode($response->getResult());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
$data = json_encode($response->getErrors());
|
||||
|
||||
$result = json_decode( $data ,true);
|
||||
|
||||
//Trancaction Table Data
|
||||
|
||||
$TrancactionData['status'] = 'Failed';
|
||||
|
||||
// $TrancactionData['member_id'] = session()->get('logged_user');
|
||||
$TrancactionData['first_name'] = $address['name'];
|
||||
$TrancactionData['last_name'] = $address['last_name'];
|
||||
$TrancactionData['address'] = $address['address'];
|
||||
$TrancactionData['country'] = $address['country'];
|
||||
$TrancactionData['city'] = $address['city'];
|
||||
$TrancactionData['zip_code'] = $address['pincode'];
|
||||
if($address['country']=='Canada'){ $TrancactionData['state'] = $address['canada_state']; }else{ $TrancactionData['state'] = $address['state'];}
|
||||
|
||||
// $TrancactionData['member_id'] = session()->get('logged_user');
|
||||
$TrancactionData['first_name'] = $address['name'];
|
||||
$TrancactionData['last_name'] = $address['last_name'];
|
||||
$TrancactionData['address'] = $address['address'];
|
||||
$TrancactionData['country'] = $address['country'];
|
||||
$TrancactionData['city'] = $address['city'];
|
||||
$TrancactionData['zip_code'] = $address['pincode'];
|
||||
if($address['country']=='Canada'){ $TrancactionData['state'] = $address['canada_state']; }else{ $TrancactionData['state'] = $address['state'];}
|
||||
//$TrancactionData['order_id'] = $order_id;
|
||||
|
||||
$TrancactionData['transaction'] = json_encode($response->getErrors());
|
||||
|
||||
$update = $this->TransactionModel->where('member_id', session()->get('logged_user'))
|
||||
|
||||
->where('order_id', $order_id )
|
||||
|
||||
->set($TrancactionData)->update();
|
||||
|
||||
if( $update)
|
||||
|
||||
{
|
||||
|
||||
|
||||
|
||||
$this->creditsModel->where('order_id', $order_id )->delete();
|
||||
|
||||
$this->cartModel->where('order_id', $order_id )->set(array('order_id'=>null))->update();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
echo json_encode(array('errors' => $response->getErrors()));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
$errors = $order_api_response->getErrors();
|
||||
|
||||
}
|
||||
|
||||
|
||||
} catch (ApiException $e) {
|
||||
|
||||
echo json_encode(array('errors' => $e));
|
||||
@ -491,154 +402,73 @@ class PaymentController extends BaseController
|
||||
|
||||
} 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();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function payment_success( $local_order_id = null)
|
||||
|
||||
{
|
||||
// $data['TransactionData'] = $this->TransactionModel->where('order_id', $local_order_id )->where('member_id', session()->get('logged_user'))->find();
|
||||
// $memberCredits = $this->creditsModel->where('order_id', $local_order_id )
|
||||
// ->where('member_id', session()->get('logged_user'))
|
||||
// ->select('package_name')
|
||||
// ->select('cost')
|
||||
// ->selectSum('credit_points', 'credit_points')
|
||||
// ->selectSum('cost', 'costSum')
|
||||
// ->selectCount('package_name', 'pack_count')
|
||||
// ->groupBy('package_name')->findAll();
|
||||
// $Subtotal = 0;
|
||||
// foreach ($memberCredits as $key => $ele) {
|
||||
// $Subtotal = $Subtotal + $ele['costSum'];
|
||||
// }
|
||||
// $data['memberCredits'] =$memberCredits;
|
||||
// $data['order_id'] = $local_order_id;
|
||||
// $timestamp = strtotime($data['TransactionData'][0]['created_at']);
|
||||
// $data['formattedDate'] = date('l, F j, Y', $timestamp);
|
||||
// $data['Subtotal'] = $Subtotal;
|
||||
// $data['gst'] = $this->RuleModel->select('value')->where('rule_key', 3 )->get()->getRow()->value;
|
||||
// $data['pst'] = $this->RuleModel->select('value')->where('rule_key', 4 )->get()->getRow()->value;
|
||||
// $data['card_brand'] = json_decode($data['TransactionData'][0]['transaction'] , true)['payment']['card_details']['card']['card_brand'];
|
||||
// $data['last_4'] = json_decode($data['TransactionData'][0]['transaction'] , true)['payment']['card_details']['card']['last_4'];
|
||||
// echo view('success_mail',$data);
|
||||
// die();
|
||||
|
||||
if( $local_order_id != null)
|
||||
|
||||
{
|
||||
|
||||
$data['TransactionData'] = $this->TransactionModel->where('order_id', $local_order_id )->where('member_id', session()->get('logged_user'))->find();
|
||||
|
||||
if($data['TransactionData']){
|
||||
|
||||
$memberCredits = $this->creditsModel->where('order_id', $local_order_id )
|
||||
|
||||
->where('member_id', session()->get('logged_user'))
|
||||
|
||||
->select('package_name')
|
||||
|
||||
->select('cost')
|
||||
|
||||
->selectSum('credit_points', 'credit_points')
|
||||
|
||||
->selectSum('cost', 'costSum')
|
||||
|
||||
->selectCount('package_name', 'pack_count')
|
||||
|
||||
->groupBy('package_name')->findAll();
|
||||
|
||||
|
||||
|
||||
if($data['TransactionData'][0]['is_mail_triggered'] == 0){
|
||||
|
||||
$sendmail_controller = new Sendmail_controller();
|
||||
|
||||
$mail = $sendmail_controller->index(session()->get('logged_user_email') , $local_order_id , 5);
|
||||
|
||||
if($mail == true){
|
||||
|
||||
$this->TransactionModel->where('order_id', $local_order_id )->set(array('is_mail_triggered'=>1))->update();
|
||||
|
||||
}
|
||||
|
||||
$admin_email = $this->RuleModel->select('value')->where('rule_key', 10 )->get()->getRow()->value;
|
||||
$sendmail_controller->index($admin_email , $local_order_id , 5);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$Subtotal = 0;
|
||||
|
||||
$Subtotal = 0;
|
||||
foreach ($memberCredits as $key => $ele) {
|
||||
|
||||
$Subtotal = $Subtotal + $ele['costSum'];
|
||||
|
||||
}
|
||||
|
||||
$data['memberCredits'] =$memberCredits;
|
||||
|
||||
|
||||
|
||||
$data['order_id'] = $local_order_id;
|
||||
|
||||
$timestamp = strtotime($data['TransactionData'][0]['created_at']);
|
||||
|
||||
$data['formattedDate'] = date('l, F j, Y', $timestamp);
|
||||
|
||||
$data['Subtotal'] = $Subtotal;
|
||||
|
||||
$data['gst'] = $this->RuleModel->select('value')->where('rule_key', 3 )->get()->getRow()->value;
|
||||
|
||||
$data['pst'] = $this->RuleModel->select('value')->where('rule_key', 4 )->get()->getRow()->value;
|
||||
|
||||
$data['card_brand'] = json_decode($data['TransactionData'][0]['transaction'] , true)['payment']['card_details']['card']['card_brand'];
|
||||
|
||||
$data['last_4'] = json_decode($data['TransactionData'][0]['transaction'] , true)['payment']['card_details']['card']['last_4'];
|
||||
|
||||
|
||||
echo view('payment',$data);
|
||||
|
||||
}else{
|
||||
|
||||
// echo 'invalid order_id';
|
||||
return redirect()->to(base_url());
|
||||
|
||||
@ -653,90 +483,148 @@ class PaymentController extends BaseController
|
||||
|
||||
|
||||
public function payment_failed( $local_order_id = null)
|
||||
|
||||
{
|
||||
|
||||
if( $local_order_id != null)
|
||||
|
||||
{
|
||||
|
||||
$data['TransactionData'] = $this->TransactionModel->where('order_id', $local_order_id )->where('member_id', session()->get('logged_user'))->find();
|
||||
|
||||
if($data['TransactionData']){
|
||||
|
||||
$sendmail_controller = new Sendmail_controller();
|
||||
|
||||
$mail = $sendmail_controller->index(session()->get('logged_user_email') , $local_order_id , 7);
|
||||
|
||||
$admin_email = $this->RuleModel->select('value')->where('rule_key', 10 )->get()->getRow()->value;
|
||||
$sendmail_controller->index($admin_email , $local_order_id , 7 ,'admin');
|
||||
|
||||
$data['category'] = json_decode($data['TransactionData'][0]['transaction'] , true)[0]['category'];
|
||||
|
||||
$data['code'] = json_decode($data['TransactionData'][0]['transaction'] , true)[0]['code'];
|
||||
|
||||
$data['detail'] = json_decode($data['TransactionData'][0]['transaction'] , true)[0]['detail'];
|
||||
|
||||
$data['order_id'] = $data['TransactionData'][0]['order_id'];
|
||||
|
||||
$timestamp = strtotime($data['TransactionData'][0]['created_at']);
|
||||
|
||||
$data['formattedDate'] = date('l, F j, Y', $timestamp);
|
||||
|
||||
|
||||
|
||||
echo view('payment_failed',$data);
|
||||
|
||||
}else{
|
||||
|
||||
// echo 'invalid order_id';
|
||||
return redirect()->to(base_url());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function createCreditPackCatalogObject()
|
||||
{
|
||||
|
||||
include 'app/Libraries/LocationInfo.php';
|
||||
|
||||
|
||||
$gst = $this->RuleModel->select('value')->where('rule_key', 3 )->get()->getRow()->value;
|
||||
$pst = $this->RuleModel->select('value')->where('rule_key', 4 )->get()->getRow()->value;
|
||||
$idempotencyKey = $this->generateIdempotencyKey();
|
||||
$locationId = getenv('SQUARE_LOCATION_ID');
|
||||
|
||||
|
||||
// Initialize the Square Client
|
||||
$square_client = new SquareClient([
|
||||
'accessToken' => getenv('SQUARE_ACCESS_TOKEN'),
|
||||
'environment' => getenv('ENVIRONMENT'),
|
||||
'userAgentDetail' => 'golf_evo', // Replace with your app's user agent detail
|
||||
]);
|
||||
|
||||
|
||||
|
||||
$money1 = new \Square\Models\Money();
|
||||
$money1->setAmount(550*100);
|
||||
$money1->setCurrency($location_info->getCurrency());
|
||||
|
||||
$money2 = new \Square\Models\Money();
|
||||
$money2->setAmount(1000*100);
|
||||
$money2->setCurrency($location_info->getCurrency());
|
||||
|
||||
|
||||
$item_variation_data = new \Square\Models\CatalogItemVariation();
|
||||
$item_variation_data->setItemId('#PaymentItems');
|
||||
$item_variation_data->setName('Evo Pack 1');
|
||||
$item_variation_data->setPricingType('FIXED_PRICING');
|
||||
$item_variation_data->setPriceMoney($money1);
|
||||
|
||||
$catalog_object1 = new \Square\Models\CatalogObject('ITEM_VARIATION', '#creditPack1');
|
||||
$catalog_object1->setItemVariationData($item_variation_data);
|
||||
|
||||
$item_variation_data2 = new \Square\Models\CatalogItemVariation();
|
||||
$item_variation_data2->setItemId('#PaymentItems');
|
||||
$item_variation_data2->setName('Evo Pack 2');
|
||||
$item_variation_data2->setPricingType('FIXED_PRICING');
|
||||
$item_variation_data2->setPriceMoney($money2);
|
||||
|
||||
$catalog_object2 = new \Square\Models\CatalogObject('ITEM_VARIATION', '#creditPack2');
|
||||
$catalog_object2->setItemVariationData($item_variation_data2);
|
||||
|
||||
|
||||
$variations = [$catalog_object1 , $catalog_object2];
|
||||
|
||||
$tax_data = new \Square\Models\CatalogTax();
|
||||
$tax_data->setName('GST/PST');
|
||||
$tax_data->setCalculationPhase('TAX_SUBTOTAL_PHASE');
|
||||
$tax_data->setInclusionType('ADDITIVE');
|
||||
$tax_data->setPercentage($gst + $pst);
|
||||
|
||||
$catalog_object3 = new \Square\Models\CatalogObject('TAX', '#sales_tax');
|
||||
$catalog_object3->setTaxData($tax_data);
|
||||
//echo json_encode($catalog_object3);
|
||||
|
||||
$tax_ids = ['#sales_tax'];
|
||||
$item_data = new \Square\Models\CatalogItem();
|
||||
$item_data->setName('Evo pack Items');
|
||||
$item_data->setTaxIds($tax_ids);
|
||||
$item_data->setVariations($variations);
|
||||
$item_data->setProductType('REGULAR');
|
||||
|
||||
$catalog_object = new \Square\Models\CatalogObject('ITEM', '#PaymentItems');
|
||||
$catalog_object->setItemData($item_data);
|
||||
|
||||
|
||||
|
||||
$objects = [$catalog_object, $catalog_object3];
|
||||
$catalog_object_batch = new \Square\Models\CatalogObjectBatch($objects);
|
||||
|
||||
$batches = [$catalog_object_batch];
|
||||
$body = new \Square\Models\BatchUpsertCatalogObjectsRequest($idempotencyKey, $batches);
|
||||
|
||||
$api_response = $square_client->getCatalogApi()->batchUpsertCatalogObjects($body);
|
||||
|
||||
if ($api_response->isSuccess()) {
|
||||
$result = $api_response->getResult();
|
||||
echo json_encode($result);
|
||||
} else {
|
||||
$errors = $api_response->getErrors();
|
||||
echo json_encode($errors);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function generateIdempotencyKey($length = 32) {
|
||||
// Define characters that can be used in the key
|
||||
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
// Get the total number of characters
|
||||
$characterCount = strlen($characters);
|
||||
// Initialize the idempotency key
|
||||
$idempotencyKey = '';
|
||||
// Generate a random key of the specified length
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$idempotencyKey .= $characters[random_int(0, $characterCount - 1)];
|
||||
}
|
||||
return $idempotencyKey;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// $data['TransactionData'] = $this->TransactionModel->where('order_id', $code )->where('member_id', session()->get('logged_user'))->find();
|
||||
// $memberCredits = $this->creditsModel->where('order_id', $code )
|
||||
// ->where('member_id', session()->get('logged_user'))
|
||||
// ->select('package_name')
|
||||
// ->select('cost')
|
||||
// ->selectSum('credit_points', 'credit_points')
|
||||
// ->selectSum('cost', 'costSum')
|
||||
// ->selectCount('package_name', 'pack_count')
|
||||
// ->groupBy('package_name')->findAll();
|
||||
// $Subtotal = 0;
|
||||
// foreach ($memberCredits as $key => $ele) {
|
||||
// $Subtotal = $Subtotal + $ele['costSum'];
|
||||
// }
|
||||
// $data['memberCredits'] =$memberCredits;
|
||||
// $data['order_id'] = $code;
|
||||
// $timestamp = strtotime($data['TransactionData'][0]['created_at']);
|
||||
// $data['formattedDate'] = date('l, F j, Y', $timestamp);
|
||||
// $data['Subtotal'] = $Subtotal;
|
||||
// $data['gst'] = $this->RuleModel->select('value')->where('rule_key', 3 )->get()->getRow()->value;
|
||||
// $data['pst'] = $this->RuleModel->select('value')->where('rule_key', 4 )->get()->getRow()->value;
|
||||
// $data['card_brand'] = json_decode($data['TransactionData'][0]['transaction'] , true)['payment']['card_details']['card']['card_brand'];
|
||||
// $data['last_4'] = json_decode($data['TransactionData'][0]['transaction'] , true)['payment']['card_details']['card']['last_4'];
|
||||
// echo view('success_mail',$data);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ class Packages_and_pricing_model extends Model
|
||||
protected $table = 'packages_and_pricing';
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $allowedFields = ['package_name','package_type', 'credit','cost','discription','offer_label', 'is_active'];
|
||||
protected $allowedFields = ['package_name','package_type', 'credit','cost','discription','offer_label', 'is_active', 'catalog_object' , 'variation_id'];
|
||||
|
||||
|
||||
}
|
||||
@ -16,7 +16,7 @@ class Transaction_model extends Model
|
||||
|
||||
|
||||
|
||||
protected $allowedFields = ['status','member_id','transaction_id','payment_order_id','order_id','transaction','is_mail_triggered', 'first_name','last_name','address', 'city' , 'state' , 'zip_code' , 'country'];
|
||||
protected $allowedFields = ['status','member_id','transaction_id','payment_order_id','order_id','transaction','is_mail_triggered', 'first_name','last_name','address', 'city' , 'state' , 'zip_code' , 'country', 'order'];
|
||||
|
||||
|
||||
|
||||
|
||||
@ -55,7 +55,7 @@
|
||||
|
||||
<div class="qty-no">
|
||||
<button type="button" class="minus"><i class="fa fa-minus"></i></button>
|
||||
<input type="number" onKeyDown="return false" id="0" class="input-text qty text" name="count[]" value="5" title="Qty" size="4" min="1" max="" step="1" placeholder="" inputmode="numeric" autocomplete="off" disabled/>
|
||||
<input type="number" onKeyDown="return false" id="0" class="input-text qty text" name="count[]" value="1" title="Qty" size="4" min="1" max="" step="1" placeholder="" inputmode="numeric" autocomplete="off" disabled/>
|
||||
<button type="button" class="plus"><i class="fa fa-plus"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -480,6 +480,8 @@ $web_payment_sdk_url = $_ENV["ENVIRONMENT"] === Environment::PRODUCTION ? "https
|
||||
|
||||
<input type="hidden" value="<?= $order_id; ?>" name="order_id" id="order_id">
|
||||
|
||||
<input type="hidden" value="<?= htmlspecialchars($EncodedArray); ?>" name="EncodedArray" id="EncodedArray">
|
||||
|
||||
<input type="hidden" value="" name="address_id" id="address_id">
|
||||
|
||||
<div id="card-container"></div>
|
||||
|
||||
@ -6,12 +6,11 @@
|
||||
"license": "MIT",
|
||||
"require": {
|
||||
"php": "^7.4 || ^8.0",
|
||||
"codeigniter4/framework": "^4.0",
|
||||
"codeigniter4/framework": "4.3.7",
|
||||
"daycry/cronjob": "^2.2",
|
||||
"google/apiclient": "^2.15",
|
||||
"guzzlehttp/guzzle": "^7.7",
|
||||
"ramsey/uuid": "^4.2",
|
||||
"square/square": "18.0.0.20220420"
|
||||
"square/square": "20.1.0.20220720"
|
||||
},
|
||||
"require-dev": {
|
||||
"fakerphp/faker": "^1.9",
|
||||
|
||||
1030
composer.lock
generated
1030
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -76,6 +76,8 @@ window.createPayment = async function(token) {
|
||||
|
||||
order_id : document.getElementById('order_id').value,
|
||||
|
||||
EncodedArray : document.getElementById('EncodedArray').value,
|
||||
|
||||
address : address
|
||||
|
||||
});
|
||||
@ -111,8 +113,6 @@ window.createPayment = async function(token) {
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (data.errors && data.errors.length > 0) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user