Reputation:
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
Upvotes: 2
Views: 10379
Reputation: 3164
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.
Upvotes: 1