Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
nanthakumar5 committed Dec 24, 2022
2 parents f39b429 + de96f6e commit 2cecdc2
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/Config/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@
//Transaction
$routes->post('transaction', 'Api\Myaccount\TransactionInfo\Index::index');

//Subscription
$routes->post('subscription', 'Api\Myaccount\Subscription\Index::index');
$routes->post('subscription/list', 'Api\Myaccount\Subscription\Index::subscription');

//Stallmanager
$routes->post('stallmanager', 'Api\Myaccount\Stallmanager\Index::index');
$routes->post('addstallmanager', 'Api\Myaccount\Stallmanager\Index::add');
Expand Down
95 changes: 95 additions & 0 deletions app/Controllers/Api/Myaccount/Subscription/Index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

namespace App\Controllers\Api\Myaccount\Subscription;

use App\Controllers\BaseController;
use App\Models\Users;
use App\Models\Plan;
use App\Models\Payments;

class Index extends BaseController
{
public function __construct()
{
$this->users = new Users();
$this->plan = new Plan();
$this->payments = new Payments();
}

public function index()
{
$post = $this->request->getPost();
$validation = \Config\Services::validation();
$validation->setRules(
[
'user_id' => 'required',
],

[
'user_id' => [
'required' => 'user_id is required.',
],
]
);

if ($validation->withRequest($this->request)->run()) {
$users = getUserDetails($post['user_id']);
$data['plans'] = $this->plan->getPlan('all', ['plan'], ['type' => [$users['type']]]);
$data['subscriptions'] = $this->payments->getPayments('row', ['payment', 'plan'], ['ninstatus' => ['0'], 'id' => $users['subscription_id']]);
$data['userdetail'] = $users;
if($data){
$json = ['0', count($data), $data];
}else{
$json = ['0', 'No Record Fount', $data];
}
} else {
$json = ['0', $validation->getErrors(), []];
}

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

die;
}

public function subscription(){
$requestData = $this->request->getPost();
$validation = \Config\Services::validation();
$validation->setRules(
[
'stripepay' => 'required',
'type' => 'required',
],

[
'stripepay' => [
'required' => 'stripepay is required.',
],
'type' => [
'required' => 'type is required.',
],
]
);

if ($validation->withRequest($this->request)->run()) {
if(isset($requestData['stripepay'])){
$json = ['1', 'Your payment is processed successfully',[]];
}else{
$json = ['0', 'Your payment is not processed successfully.',[]];
}
} else {
$json = ['0', $validation->getErrors(), []];
}

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

die;
}
}

0 comments on commit 2cecdc2

Please sign in to comment.