Skip to content

Commit

Permalink
checkout api
Browse files Browse the repository at this point in the history
  • Loading branch information
TMuthulakshmi committed Dec 29, 2022
1 parent 68aed4b commit 30be4ee
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 11 deletions.
6 changes: 4 additions & 2 deletions app/Config/Routes.php
Expand Up @@ -90,7 +90,8 @@
//Current Reservation
$routes->post('list', 'Api\Myaccount\Currentreservation\Index::index');
$routes->post('view', 'Api\Myaccount\Currentreservation\Index::view');
$routes->post('paidunpaid', 'Api\Myaccount\Currentreservation\Index::paidunpaid');
$routes->post('paidunpaid', 'Api\Myaccount\Currentreservation\Index::paidunpaid');
$routes->post('striperefunds', 'Api\Myaccount\Currentreservation\Index::striperefunds');
$routes->post('cancelsubscription', 'Api\Myaccount\Currentreservation\Index::cancelsubscription');

//Past Reservation
Expand Down Expand Up @@ -122,7 +123,8 @@
//Checkout
$routes->post('checkout', 'Api\Checkout\Index::index');
$routes->post('checkout/action', 'Api\Checkout\Index::action');
$routes->post('stripepayment', 'Api\Stripe\Index::stripepayment');
$routes->post('stripepayment', 'Api\Stripe\Index::stripepayment');
$routes->post('stripesecretkey', 'Api\Checkout\Index::stripesecretkey');

//Homepage
$routes->get('faq', 'Api\Faq\Index::index');
Expand Down
39 changes: 39 additions & 0 deletions app/Controllers/Api/Checkout/Index.php
Expand Up @@ -7,6 +7,8 @@
use App\Models\Event;
use App\Models\Cart;
use App\Models\Booking;
use App\Models\Users;
use App\Models\Stripe;

class Index extends BaseController
{
Expand All @@ -16,6 +18,8 @@ public function __construct()
$this->event = new Event();
$this->cart = new Cart();
$this->booking = new Booking();
$this->users = new Users();
$this->stripe = new Stripe();
}

public function index()
Expand Down Expand Up @@ -174,6 +178,18 @@ public function index()

$total ='';
$totaldue = (number_format($price,2)+ number_format($transactionfee,2)+ number_format($cleaning_fee,2)+ number_format(($tax*100),2));

//if(isset($post['paymentmethodid'])){
$users = $this->users->getUsers('row', ['users'],['id' => $post['user_id']]);
$userid = $users['id'];
$name = $users['name'];
$email = $users['email'];
$stripecustomerid = $users['stripe_customer_id'];

$customerid = $this->stripe->customer($userid, $name, $email, $stripecustomerid);

$piid = $this->stripe->createPaymentIntents($customerid, $totaldue, $transactionfee=0, $accountid='');
//}
$resultdata = [
'event_id' => $event_id,
'event_name' => $event_name,
Expand All @@ -195,6 +211,7 @@ public function index()
'timer' => $timer,
'count' => $count,
'paymentmethod' => $paymentmethod,
'piid' => $piid['id'],
'stripepublickey' => $setting['stripepublickey'],
];

Expand Down Expand Up @@ -350,4 +367,26 @@ public function action(){

die();
}

public function stripesecretkey()
{
$requestData = $this->request->getPost();
if(isset($requestData['paymentmethodid'])){
$users = $this->users->getUsers('row', ['users'],['id' => $requestData['user_id']]);
$userid = $users['id'];
$name = $users['name'];
$email = $users['email'];
$stripecustomerid = $users['stripe_customer_id'];

$customerid = $this->stripe->customer($userid, $name, $email, $stripecustomerid);

$resturnresult = $this->stripe->createPaymentIntents($customerid, $requestData['price'], $transactionfee=0, $accountid='');


$json = ['1', 'Booking Successfully', $resturnresult['id']];
}else{
$json = ['0', 'Try Later', []];
}

}
}
68 changes: 59 additions & 9 deletions app/Controllers/Api/Myaccount/Currentreservation/Index.php
Expand Up @@ -194,8 +194,56 @@ public function paidunpaid(){
die;
}

public function cancelsubscription(){
$post = $this->request->getPost();
public function striperefunds(){
$post = $this->request->getPost();
$validation = \Config\Services::validation();

$validation->setRules(
[
'paymentintentid' => 'required',
'paymentid' => 'required',
'id' => 'required',
'amount' => 'required',
],

[
'paymentintentid' => [
'required' => 'paymentintentid Id is required.',
],
'paymentid' => [
'required' => 'Payment Id status is required.',
],
'id' => [
'required' => 'Id status is required.',
],
'amount' => [
'required' => 'amount status is required.',
],
]
);

if ($validation->withRequest($this->request)->run()) {
$data = $this->stripe->striperefunds($post);
if($data){
$json = ['1', ' Reservation Cancelled.', $data];
}else{
$json = ['0', ' Try Later.', []];
}
}else{
$json = ['0', $validation->getErrors(), []];
}

echo json_encode([
'status' => $json[0],
'message' => $json[1],
'result' => $json[2],
]);

die;
}

public function cancelsubscription(){
$requestdata = $this->request->getPost();
$validation = \Config\Services::validation();

$validation->setRules(
Expand All @@ -206,7 +254,7 @@ public function cancelsubscription(){

[
'bookingid' => [
'required' => 'Booking Id is required.',
'required' => 'paymentintentid Id is required.',
],
'paymentid' => [
'required' => 'Payment Id status is required.',
Expand All @@ -215,13 +263,15 @@ public function cancelsubscription(){
);

if ($validation->withRequest($this->request)->run()) {

$payment = $this->payments->getPayments('row', ['payment'], ['id' => $post['paymentid']]);
$payment = $this->payments->getPayments('row', ['payment'], ['id' => $requestdata['paymentid']]);
if($payment){
$this->stripe->cancelSchedule($payment['stripe_subscription_id']);
$this->bookingdetails->cancelsubscription(['booking_details_id' => $payment['booking_details_id']]);
echo "fasd";die;
$json = ['1', ' Subscription Cancelled.'];
$data = $this->stripe->cancelSchedule($payment['stripe_scheduled_id']);
$data = $this->bookingdetails->cancelsubscription(['booking_details_id' => $payment['booking_details_id']]);
if($data){
$json = ['1', ' Subscription Cancelled.', $data];
}else{
$json = ['0', ' Try Later.', []];
}
}else{
$json = ['0', ' Try Later.', []];
}
Expand Down

0 comments on commit 30be4ee

Please sign in to comment.