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());
}
Related
I'm just trying a very simple test
<?php
require 'vendor/autoload.php';
class Blog
{
public function post ()
{
return 'ok';
}
}
$builder = new \Aura\Di\ContainerBuilder();
$blog = $builder->newInstance('Blog');
echo $blog->post();
This results to:
Fatal error: Uncaught Error: Call to undefined method Aura\Di\Container::post()
Am I missing something?
Yes , you are missing to read the docs. You have created builder. Next you need to get the di via new instance. This is what you assigned to blog variable.
Please consider reading getting started http://auraphp.com/packages/3.x/Di/getting-started.html#1-1-1-2
// autoload and rest of code
$builder = new \Aura\Di\ContainerBuilder();
$di = $builder->newInstance();
Now you create instance of object
$blog = $di->newInstance('Blog');
echo $blog->post();
Please read the docs.
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)
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.
I am trying to integrate the WHAnonymous API in my symfony project.
I have included it in my project using composer install and it is now in my vendor folder.
But I am not understanding how to import it into my project!
This is my manager class.
<?php
namespace AppBundle\Managers;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class WhatsAppManager
{
private $test;
/**
* Constructor
*/
public function __construct()
{
$this->test =1;
}
public function sendMessage()
{
$username = ""; // Your number with country code, ie: 34123456789
$nickname = ""; // Your nickname, it will appear in push notifications
$debug = true; // Shows debug log
// Create a instance of WhastPort.
$w = new WhatsProt($username, $nickname, $debug);
var_dump("In send message method");
}
}
?>
I have used
require_once 'whatsprot.class.php';
and
require_once 'Whatsapp\Bundle\Chat-api\src\whatsprot.class.php';
and
use Whatsapp\Bundle\Chat-api\Whatsprot
But it is just not working.
Please tell me the right way to do it!
And is there something i should do when i am using 3rd party vendors in symfony.
I did look into the documentation of the WHanonymous but i found only snippets of code to use it and not the way to import it.
Git repo for WHAnonymous : https://github.com/WHAnonymous
The class doesn't have a namespace, but is correctly loaded by the autoload system created my composer. So you can reference to the class without any include or require directive but simply with a \ as example:
// Create a instance of WhastPort.
$w = new \WhatsProt($username, $nickname, $debug);
Hope this help
In localhost, it works fine. After uploading into my hosting i got this error. I'm using zend framework 1.12.
Fatal error: Class 'Application_Models_DBTable_Kereta' not found in /home/mysite/public_html/application/controllers/CarController.php
others post said the problem is because the case sensitivity of file names. But i tried to change and nothing happens. See my attachment for the structured of my project. The attachment shown application and model names.
edited : This problem occurs to all my models class.. can't find models..
Controller code :
class CarController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
//klu login sbgai admin, papar layout admin, klu login sbgai user, papar layout user laaaa,
Zend_Session::start();//start session
$session = new Zend_Session_Namespace("MyNamespace");
$id_pengguna = $session->id_pengguna;
$kategori = $session->kategori;
if($kategori==3)
{
$this->_helper->layout->setLayout('layoutadmin');
}
else
{
}
}
public function indexAction()
{
// $albums = new Application_Model_DbTable_Albums();
//$this->view->albums = $albums->fetchAll();
}
public function reservationAction()
{
if($this->getRequest()->isPost())
{
$jadual_tarikhmula = $this->getRequest()->getPost("jadual_tarikhmula");
$jadual_tarikhtamat = $this->getRequest()->getPost("jadual_tarikhtamat");
$jadual_masamula1 = $this->getRequest()->getPost("jadual_masamula1");
$jadual_masamula2 = $this->getRequest()->getPost("jadual_masamula2");
$jadual_masatamat1 = $this->getRequest()->getPost("jadual_masatamat1");
$jadual_masatamat2 = $this->getRequest()->getPost("jadual_masatamat2");
$simpan = array($jadual_tarikhmula,$jadual_tarikhmula,$jadual_masamula1,$jadual_masatamat1);
$papar = $this->view->dataReserve= $simpan;
$db = new Application_Model_DbTable_Kereta();
$paparkereta = $this->view->reserve = $db->getReservationCar($jadual_tarikhmula,$jadual_tarikhmula,$jadual_masamula1,$jadual_masatamat1);
$this->view->dataWujud = count($paparkereta);
$gambar = $this->view->gambarKereta = $db->getGambarKereta($paparkereta[0]['id_kereta'],false);
}
}
}
Your folder name is DbTable and your model class name is ..._DBTable_... ?
Note that Linux is case-sensitive directory or filename.
And did you add this line to .ini file?
Appnamespace = "Application"
Are you sure you don't have another class named Kereta in /home/mysite/public_html/application/controllers/CarController.php ?
Also, consider cleaning the symfony cache with symfony cc. It's the cache for autoload that is giving you this error I guess.