Skip to content

Commit de9736c

Browse files
authored
Add files via upload
1 parent b56729d commit de9736c

18 files changed

Lines changed: 1601 additions & 0 deletions

Common.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
/**
4+
* The goal of this file is to allow developers a location
5+
* where they can overwrite core procedural functions and
6+
* replace them with their own. This file is loaded during
7+
* the bootstrap process and is called during the frameworks
8+
* execution.
9+
*
10+
* This can be looked at as a `master helper` file that is
11+
* loaded early on, and may also contain additional functions
12+
* that you'd like to use throughout your entire application
13+
*
14+
* @link: https://codeigniter4.github.io/CodeIgniter4/
15+
*/

Config/Constants.php

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
//--------------------------------------------------------------------
4+
// App Namespace
5+
//--------------------------------------------------------------------
6+
// This defines the default Namespace that is used throughout
7+
// CodeIgniter to refer to the Application directory. Change
8+
// this constant to change the namespace that all application
9+
// classes should use.
10+
//
11+
// NOTE: changing this will require manually modifying the
12+
// existing namespaces of App\* namespaced-classes.
13+
//
14+
defined('APP_NAMESPACE') || define('APP_NAMESPACE', 'App');
15+
16+
/*
17+
|--------------------------------------------------------------------------
18+
| Composer Path
19+
|--------------------------------------------------------------------------
20+
|
21+
| The path that Composer's autoload file is expected to live. By default,
22+
| the vendor folder is in the Root directory, but you can customize that here.
23+
*/
24+
defined('COMPOSER_PATH') || define('COMPOSER_PATH', ROOTPATH . 'vendor/autoload.php');
25+
26+
/*
27+
|--------------------------------------------------------------------------
28+
| Timing Constants
29+
|--------------------------------------------------------------------------
30+
|
31+
| Provide simple ways to work with the myriad of PHP functions that
32+
| require information to be in seconds.
33+
*/
34+
defined('SECOND') || define('SECOND', 1);
35+
defined('MINUTE') || define('MINUTE', 60);
36+
defined('HOUR') || define('HOUR', 3600);
37+
defined('DAY') || define('DAY', 86400);
38+
defined('WEEK') || define('WEEK', 604800);
39+
defined('MONTH') || define('MONTH', 2592000);
40+
defined('YEAR') || define('YEAR', 31536000);
41+
defined('DECADE') || define('DECADE', 315360000);
42+
43+
/*
44+
|--------------------------------------------------------------------------
45+
| Exit Status Codes
46+
|--------------------------------------------------------------------------
47+
|
48+
| Used to indicate the conditions under which the script is exit()ing.
49+
| While there is no universal standard for error codes, there are some
50+
| broad conventions. Three such conventions are mentioned below, for
51+
| those who wish to make use of them. The CodeIgniter defaults were
52+
| chosen for the least overlap with these conventions, while still
53+
| leaving room for others to be defined in future versions and user
54+
| applications.
55+
|
56+
| The three main conventions used for determining exit status codes
57+
| are as follows:
58+
|
59+
| Standard C/C++ Library (stdlibc):
60+
| http://www.gnu.org/software/libc/manual/html_node/Exit-Status.html
61+
| (This link also contains other GNU-specific conventions)
62+
| BSD sysexits.h:
63+
| http://www.gsp.com/cgi-bin/man.cgi?section=3&topic=sysexits
64+
| Bash scripting:
65+
| http://tldp.org/LDP/abs/html/exitcodes.html
66+
|
67+
*/
68+
defined('EXIT_SUCCESS') || define('EXIT_SUCCESS', 0); // no errors
69+
defined('EXIT_ERROR') || define('EXIT_ERROR', 1); // generic error
70+
defined('EXIT_CONFIG') || define('EXIT_CONFIG', 3); // configuration error
71+
defined('EXIT_UNKNOWN_FILE') || define('EXIT_UNKNOWN_FILE', 4); // file not found
72+
defined('EXIT_UNKNOWN_CLASS') || define('EXIT_UNKNOWN_CLASS', 5); // unknown class
73+
defined('EXIT_UNKNOWN_METHOD') || define('EXIT_UNKNOWN_METHOD', 6); // unknown class member
74+
defined('EXIT_USER_INPUT') || define('EXIT_USER_INPUT', 7); // invalid user input
75+
defined('EXIT_DATABASE') || define('EXIT_DATABASE', 8); // database error
76+
defined('EXIT__AUTO_MIN') || define('EXIT__AUTO_MIN', 9); // lowest automatically-assigned error code
77+
defined('EXIT__AUTO_MAX') || define('EXIT__AUTO_MAX', 125); // highest automatically-assigned error code
78+
79+
define('SITE_NAME', 'Sample');
80+
define('RAZOR_KEY', 'xxxxxxxxx');
81+
define('RAZOR_SECRET_KEY', 'xxxxxxxxx');

Controllers/BaseController.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace App\Controllers;
4+
5+
/**
6+
* Class BaseController
7+
*
8+
* BaseController provides a convenient place for loading components
9+
* and performing functions that are needed by all your controllers.
10+
* Extend this class in any new controllers:
11+
* class Home extends BaseController
12+
*
13+
* For security be sure to declare any new methods as protected or private.
14+
*
15+
* @package CodeIgniter
16+
*/
17+
18+
use CodeIgniter\Controller;
19+
20+
class BaseController extends Controller
21+
{
22+
23+
/**
24+
* An array of helpers to be loaded automatically upon
25+
* class instantiation. These helpers will be available
26+
* to all other controllers that extend BaseController.
27+
*
28+
* @var array
29+
*/
30+
protected $helpers = [];
31+
/**
32+
* Constructor.
33+
*/
34+
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger) {
35+
// Do Not Edit This Line
36+
parent::initController($request, $response, $logger);
37+
//--------------------------------------------------------------------
38+
// Preload any models, libraries, etc, here.
39+
//--------------------------------------------------------------------
40+
// E.g.:
41+
helper(['form', 'url', 'html']);
42+
}
43+
44+
protected function load_view($data, $layout_file = 'layout'){
45+
$setData = $data;
46+
return view($layout_file, $setData);
47+
}
48+
}

Controllers/Home.php

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
<?php namespace App\Controllers;
2+
require_once(APPPATH."Libraries/razorpay/razorpay-php/Razorpay.php");
3+
use Razorpay\Api\Api;
4+
use Razorpay\Api\Errors\SignatureVerificationError;
5+
class Home extends BaseController
6+
{
7+
8+
public function index() {
9+
$data['page_desc'] = 'Pricing';
10+
$data['template_file'] = 'pricing/pricing';
11+
return $this->load_view($data);
12+
}
13+
public function buynow($price){
14+
15+
$api = new Api(RAZOR_KEY, RAZOR_SECRET_KEY);
16+
/**
17+
* You can calculate payment amount as per your logic
18+
* Always set the amount from backend for security reasons
19+
*/
20+
$razorpayPricing = $api->order->create(array(
21+
'receipt' => rand(),
22+
'amount' => $price*100, // 2000 rupees in paise
23+
'currency' => 'INR',
24+
'payment_capture' => 1 // auto capture
25+
));
26+
27+
$amount = $razorpayPricing['amount'];
28+
$razorpayOrderId = $razorpayPricing['id'];
29+
30+
$postData=['name'=>'Sample','email'=>'sample@email.com','contact'=>'9876543210'];
31+
$pricingDetails = ['title'=>'Subscription'];
32+
$data = $this->prepareData($amount,$razorpayOrderId,$postData,$pricingDetails);
33+
34+
//save data in database here;
35+
36+
$data['template_file'] = 'inc/rezorpay';
37+
$data['page_title'] = 'Pay Now';
38+
$data['page_desc'] = 'Pay Now';
39+
$data['data'] = $data;
40+
$data['add_custom_js'] = "
41+
options.handler = function (response){
42+
document.getElementById('razorpay_payment_id').value = response.razorpay_payment_id;
43+
document.getElementById('razorpay_signature').value = response.razorpay_signature;
44+
document.getElementById('razorpay_order_id').value = '".$razorpayOrderId."';
45+
document.razorpayform.submit();
46+
};
47+
48+
// Boolean whether to show image inside a white frame. (default: true)
49+
options.theme.image_padding = false;
50+
51+
options.modal = {
52+
ondismiss: function() {
53+
console.log('This code runs when the popup is closed');
54+
},
55+
backdropclose: false
56+
};
57+
58+
var rzp = new Razorpay(options);
59+
$(document).ready(function(e){
60+
console.log('window loaded');
61+
$('#rzp-button1').click();
62+
rzp.open();
63+
event.preventDefault();
64+
});
65+
";
66+
return $this->load_view($data, 'layout');
67+
68+
}
69+
/**
70+
* This function verifies the payment,after successful payment
71+
*/
72+
public function verify()
73+
{
74+
//log_message('error','post==='.json_encode($_POST));
75+
$success = true;
76+
$error = "payment_failed";
77+
if (empty($_POST['razorpay_payment_id']) === false) {
78+
$api = new Api(RAZOR_KEY, RAZOR_SECRET_KEY);
79+
try {
80+
$attributes = array(
81+
'razorpay_order_id' => $_POST['razorpay_order_id'],
82+
'razorpay_payment_id' => $_POST['razorpay_payment_id'],
83+
'razorpay_signature' => $_POST['razorpay_signature']
84+
);
85+
$result = $api->utility->verifyPaymentSignature($attributes);
86+
//log_message('error','result==='.json_encode($result));
87+
} catch(SignatureVerificationError $e) {
88+
$success = false;
89+
$result = $e->getMessage();
90+
log_message('error','error==='.json_encode($result));
91+
}
92+
}
93+
if ($success === true) {
94+
/**
95+
* Call this function from where ever you want
96+
* to save save data before of after the payment
97+
*/
98+
//redirectsuccess
99+
$this->setSession(['razorpay_order_id'=>$_POST['razorpay_order_id']]);
100+
return redirect()->to(base_url('home/success'));
101+
}
102+
else {
103+
//redirect failed
104+
return redirect()->to(base_url('home/failed'));
105+
}
106+
}
107+
108+
/**
109+
* This function preprares payment parameters
110+
* @param $amount
111+
* @param $razorpayOrderId
112+
* @return array
113+
*/
114+
public function prepareData($amount,$razorpayOrderId,$postData,$pricingDetails)
115+
{
116+
117+
$data = array(
118+
"key" => RAZOR_KEY,
119+
"amount" => $amount,
120+
"name" => $pricingDetails['title'],
121+
"description" => "Pay for subscription",
122+
"image" => "",
123+
"prefill" => array(
124+
"name" => $postData['name'],
125+
"email" => $postData['email'],
126+
"contact" => $postData['contact']
127+
),
128+
"notes" => array(
129+
"address" => "Mohali,India",
130+
"merchant_order_id" => rand(),
131+
),
132+
"theme" => array(
133+
"color" => "#F37254"
134+
),
135+
"order_id" => $razorpayOrderId,
136+
);
137+
return $data;
138+
}
139+
/**
140+
* This is a function called when payment successfull,
141+
* and shows the success message
142+
*/
143+
public function success()
144+
{
145+
if(!$this->session->has('razorpay_order_id')){
146+
return redirect()->to(base_url());
147+
}
148+
$data['razorpay_order_id'] = $this->isSession('razorpay_order_id');
149+
$this->session->remove('razorpay_order_id');
150+
$data['template_file'] = 'pricing/success';
151+
$data['page_title'] = 'Success';
152+
$data['page_desc'] = 'Success';
153+
return $this->load_view($data, 'layout');
154+
}
155+
/**
156+
* This is a function called when payment failed,
157+
* and shows the error message
158+
*/
159+
public function paymentFailed()
160+
{
161+
$data['template_file'] = 'pricing/error';
162+
$data['page_title'] = 'Success';
163+
$data['page_desc'] = 'Success';
164+
return $this->load_view($data, 'layout');
165+
}
166+
167+
}

Views/errors/cli/error_404.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
use CodeIgniter\CLI\CLI;
3+
4+
CLI::error('ERROR: ' . $code);
5+
CLI::write($message);
6+
CLI::newLine();
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
An uncaught Exception was encountered
2+
3+
Type: <?= get_class($exception), "\n"; ?>
4+
Message: <?= $message, "\n"; ?>
5+
Filename: <?= $exception->getFile(), "\n"; ?>
6+
Line Number: <?= $exception->getLine(); ?>
7+
8+
<?php if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE === true): ?>
9+
10+
Backtrace:
11+
<?php foreach ($exception->getTrace() as $error): ?>
12+
<?php if (isset($error['file'])): ?>
13+
<?= trim('-' . $error['line'] . ' - ' . $error['file'] . '::' . $error['function']) . "\n" ?>
14+
<?php endif ?>
15+
<?php endforeach ?>
16+
17+
<?php endif ?>

Views/errors/cli/production.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
// On the CLI, we still want errors in productions
4+
// so just use the exception template.
5+
include __DIR__ . '/error_exception.php';

0 commit comments

Comments
 (0)