Hi i am trying to integrate razorpay payment gateway in codeigniter. The code that I'm using is
View Code
<?php echo form_open_multipart('user/addcredit/'); ?>
<div class="form-group">
<script
src="https://checkout.razorpay.com/v1/checkout.js"
data-key="razorpay_key">
</script>
</div>
<?php echo form_close(); ?>
Controller code
class User extends CI_Controller
{
public function addcredit()
{
require_once (APPPATH . 'base_url()/litehires/assets/razorpay-php/Razorpay.php');
use Razorpay\Api\Api;
$api = new Api('rzp_test_KEY_ID', ''rzp_test_KEY_ID');
if (isset($_POST['razorpay_payment_id']) === false) {
die("Payment id not provided");
}
$id = $_POST['razorpay_payment_id'];
echo json_encode($payment->toArray());
}
}
What I got to know is that I cannot use 'use' keyword inside the function. But I'm not able to find alternative way to do the integration. I haven't use composer, so would appreciate if anyone could please tell me how to integrate this payment without composer
You can easily put the use keyword at the top of that file. If there is already an Api class clashing with this, you can do the following:
<?php
require_once (APPPATH . 'base_url()/litehires/assets/razorpay-php/Razorpay.php');
use Razorpay\Api as RazorpayApi;
class User extends CI_Controller
{
public function addcredit()
{
$api = new RazorpayApi('rzp_test_KEY_ID', 'rzp_test_KEY_ID');
This will include the file, then use the class, so it is available below in the controller.
Disclaimer: I work for Razorpay.
Related
I am using a Laravel app, and on one of my custom pages I have the following:
index1.php:
require_once __DIR__ . '/../../../vanguard/extra/auth.php';
$request->session()->forget('token1');
$request->session()->put('token1', $generate_token1);
$request->session()->keep(['token1']);
redirectTo('index2.php');
index2.php:
require_once __DIR__ . '/../../../vanguard/extra/auth.php';
$token1 = $request->session()->get('token1');
echo $token1;
It seem's the session isn't being saved across the pages. If I use all the code on one file it works. Any ideas?
I am using this because I can't seem to use session_start(); with Laravel.
Rather making a custom page make a class
define a class with a namespace
and use it in any of your pages inside any page like below.
Here are my steps :
The content for app/library/myFunctions.php is below :
<?php namespace App\library {
class myFunctions {
public function is_ok() {
return 'myFunction is OK';
}
}
}
?>
At resources/views/test.blade.php , I added :
<?php
$FmyFunctions1 = new myFunctions;
$is_ok = ($FmyFunctions1->is_ok());
?>
Then at composer.json within "autoload": I added :
"files": [
"app/library/myFunctions.php"
],
And within app\Http\Controllers\HomeController.php at public index() I add :
return view('test');
To create simple Rest API I have followed below steps
downloaded CodeIgniter-restserver
and copy pasted REST_Controller from downloaded file into libraries under my project(src is the project name).
And then created Api.php inside controller of my project
<?php
require(APPPATH'.libraries/REST_Controller.php');
class API extends REST_Controller {
function test()
{
echo "RESTfull API";
}
}
?>
And I run the URLhttp://localhost/src/index.php/Api/test in postman but it is not showing results.
You need to follow the below link
https://itsolutionstuff.com/post/codeigniter-3-restful-api-tutorialexample.html
and then after you run the code you will get a small error
Unable to load the requested language file: language/english/rest_controller_lang.php
The problem is that codeigniter can't find the rest_controller translations. You just need to create this file /application/languages/english/rest_controller_lang.php
Then copy & paste this code inside:
<?php
/*
* English language
*/
$lang['text_rest_invalid_api_key'] = 'Invalid API key %s'; // %s is the REST API key
$lang['text_rest_invalid_credentials'] = 'Invalid credentials';
$lang['text_rest_ip_denied'] = 'IP denied';
$lang['text_rest_ip_unauthorized'] = 'IP unauthorized';
$lang['text_rest_unauthorized'] = 'Unauthorized';
$lang['text_rest_ajax_only'] = 'Only AJAX requests are allowed';
$lang['text_rest_api_key_unauthorized'] = 'This API key does not have access to the requested controller';
$lang['text_rest_api_key_permissions'] = 'This API key does not have enough permissions';
$lang['text_rest_api_key_time_limit'] = 'This API key has reached the time limit for this method';
$lang['text_rest_ip_address_time_limit'] = 'This IP Address has reached the time limit for this method';
$lang['text_rest_unknown_method'] = 'Unknown method';
$lang['text_rest_unsupported'] = 'Unsupported protocol';
Hope this helps
Hope this will help you :
require APPPATH . '/libraries/REST_Controller.php';
class Api extends REST_Controller {
function test_get()
{
$data = array('response' => 'RESTfull API');
if(count($data ) > 0)
{
$this->response($data ,REST_Controller::HTTP_OK);
}
else
{
$error = array('message' => 'No record found');
$this->response($error,REST_Controller::HTTP_OK);
}
}
For more pls read : https://code.tutsplus.com/tutorials/working-with-restful-services-in-codeigniter--net-8814
Please read this article line by line. This is the best solution for beginners to use CodeIgniter Rest API library.
<?php
require(APPPATH.'/libraries/REST_Controller.php');
class API extends REST_Controller {
function test_get()
{
$data = array("message"=>"RESTfull API");
$this->response($data);
}
}
?>
call: http://localhost/src/index.php/Api/test
Note: In rest API you should define the method type as GET, POST, PUT, and DELETE
How to use the Rest API library in CodeIgniter
try
<?php
require(APPPATH'.libraries/REST_Controller.php');
class ApiController extends REST_Controller {
function test()
{
echo "RESTfull API";
die;
}
}
?>
I suggest to use built-in method response from the library
Try lowercase: api/test instead of Api/test
Upd. Add to config/routes.php
$route['api/test'] = 'api/test';
Another one thing, if you have routes try figure out, does they use pluralize, if it foes, so you can try to check /apis/test instead of /api/test
because pluralize transform controller name from one to many form (sorry for primitive English)
I'm using CakePHP 3.2. I have to integrate CCAvenue Payment gateway to my website.
I'm using https://github.com/kishanio/CCAvenue-PHP-Library library to integrate CCAvenue in my website.
But installing it via composer is not working
composer require kishanio/ccavenue
So, I downloaded and extract all files to
/vendor/CCAvenue-PHP-Library-master
path to Payment.php
/vendor/CCAvenue-PHP-Library-master/src/Payment.php
And in controller, I'm doing like
<?php
namespace App\Controller;
use App\Controller\AppController;
use Cake\Event\Event;
require_once(ROOT.'/vendor/CCAvenue-PHP-Library-master/src/Payment.php');
use Kishanio\CCAvenue\Payment as CCAvenueClient;
class OrdersController extends AppController
{
public function paymentViaPaymentGateway($invoice = null)
{
$payble_amount = 500;
$ccavenue = new CCAvenueClient('key', 'id', 'redirect');
// set details
$ccavenue->setAmount($payble_amount);
$ccavenue->setOrderId($invoice);
$ccavenue->setBillingName($getOrder->user_address->name);
$ccavenue->setBillingAddress($getOrder->user_address->line_1);
$ccavenue->setBillingCity($getOrder->user_address->city);
$ccavenue->setBillingZip($getOrder->user_address->postal);
$ccavenue->setBillingState($getOrder->user_address->state);
$ccavenue->setBillingCountry('India');
$ccavenue->setBillingEmail($this->Auth->user('email'));
$ccavenue->setBillingTel($this->Auth->user('mobile'));
$ccavenue->setBillingNotes($invoice);
// copy all the billing details to shipping details
$ccavenue->billingSameAsShipping();
// get encrypted data to be passed
$data = $ccavenue->getEncryptedData();
// merchant id to be passed along the param
$merchant = $ccavenue->getMerchantId();
$this->set('data', $data);
$this->set('merchant', $merchant);
}
}
Utils.php is located in same directory as Payment.php
and Payment.php contains
namespace Kishanio\CCAvenue;
use Kishanio\CCAvenue\Utils;
and Utils.php contains
namespace Kishanio\CCAvenue;
use Kishanio\CCAvenue\Payment;
But, this gives error as
Fatal error: Class 'Kishanio\CCAvenue\Utils' not found in
/path_to/vendor/CCAvenue-PHP-Library-master/src/Payment.php on line
243
content of Payment.php where error is pointing.
public function getEncryptedData() {
$utils = new Utils( $this ); // line 243
$merchant_data = $this->getMerchantData( $utils->getChecksum() );
return $utils->encrypt($merchant_data,$this->getWorkingKey());
}
I'm trying to write an external library which has functions commonly used among various classes.
Currently I'm trying to write a log message function. The problem is I need access to the session library and a model. How do I access them without extending from CI_Controller? Any workaround?
Here's my code:
Common_functions library:
public function _send_message($message, $log_to_db=TRUE)
{
$this->session->set_userdata("message", $message);
if($log_to_db) $this->User_log_model->log_mesage($message);
}
Usage in other classes example:
public function new_user()
{
$this->_set_validation_rules();
if($this->form_validation->run())
{
if($user_id = $this->User_model->insert($this->_prepare_new_user_array()))
{
$this->common_functions->_send_message("New User created successfully. | user_id: " . $user_id);
}
else {
$this->common_functions->_send_message("Unable to create new User record.");
}
}
}
Managed to solve it. Just moved my log message functions to the User_log_model instead.
I've started reading on zend framework and it's use with Doctrine and have implemented a small project to grasp the understanding.I've come to a point where i needed my model generated as in having a generate script like the one suggested in Doctrine 1.2.2 pdf manual.After few unsuccessful attempts like
Class 'sfYaml' not found in
G:\php_document\zendworkspace\BookingManager\library\doctrine\Doctrine\Parser\Yml.php
on line 80
i've googled and found out what people are doing about that.
To me it sounds too much the fact of having a command line script to do that work.So my question is do i really need the command line or i fail to load something is my application.ini file to get the error up there?
my testerController is like this:
class Testing_TesterController extends Zend_Controller_Action {
public function init(){
$optionDoctrine = Zend_Registry::get("config")->toArray();
$this->config = $optionDoctrine["doctrine"];
}
public function generateAction() {
$this->view->drop="dropping database............";
Doctrine_Core::dropDatabases();
$this->view->create = "creating database........";
Doctrine_Core::createDatabases();
$this->view->models = "generating models....";
//things started breadking from this line Doctrine_Core::generateModelsFromYaml("$this->config[yaml_schema_path]","$this->config[models_path]");
// $this->view->tables = "creating tables.......";
// Doctrine_Core::createTablesFromModels($this->config["models_path"]);
// $this->view->success = "tables and model successfully generated";
// $optionobject= Zend_Registry::get("config")->toArray();
// $this->view->generate =$optionobject["doctrine"]["yaml_schema_path"];
}
public function testAction(){
$dbs= Doctrine_Manager::connection()->import->listDatabases();
$this->view->test = $dbs;
//$this->view->test = "test";
}
}
the generate view is like this
<h1>My Manager:: generate page</h1><br>
<div style="text-align: left"><?php echo $this->drop; ?></div>
<div style="text-align: left"><?php echo $this->create; ?></div>
<div style="text-align: left"><?php var_dump($this->models); ?></div>
<div style="text-align: left"><?php echo $this->tables; ?></div>
here is my bootstrap class
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initDoctrine(){
require_once 'doctrine/Doctrine.php';
$this->getApplication()->getAutoloader()->pushAutoloader(array('Doctrine','autoload'),"Doctrine");
//$this->getApplication()->getAutoloader()->pushAutoloader(array('Doctrine','modelsAutoload'),"Doctrine");
$manager = Doctrine_Manager::getInstance();
//$manager->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING,Doctrine_Core::MODEL_LOADING_AGGRESSIVE);
$manager->setAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE,true);
$doctrineConfig = $this->getOption('doctrine');
$conn = Doctrine_Manager::connection($doctrineConfig['dsn'],'doctrine');
return $conn;
}
protected function _initDoctrineConfig(){
$conf = new Zend_Config($this->getOptions(),true);
Zend_Registry::set('config',$conf);
return $conf;
}
}
I've also adopted the use of modules which seems to complicate my situation so what do you think is the best to go with? thanks for reading
You need to grab the sfYaml component and install it. I Thought it was int the Doctrine svn repo as an svn:external but maybe not... you can get it from the Symfony components site.
Im not sure what tutorial youre following but if you drop:
http://svn.symfony-project.com/components/yaml/branches/1.0/
into your library folder as sfYaml and add library/sfYaml to the include path you should be fine assuming youve gotten everything else set up correctly.
Also whay is your command line script using Zend_Controller stuff? Shouldnt you be using the Zend_Tool_Framework infrastructure or writing a completely custom script? Thats how I've done it in the past anyway...