PHP Razorpay namespacing conflict with application's autoloader

73 Views Asked by At

I'm trying to integrate Razorpay client into my existing app and having the issue:

Warning: include_once(MY XAMPP PATH/system/classes/Razorpay\Api\Api.class.php): failed to open stream: No such file or directory in MY XAMPP PATH\system\JCApp.php on line 18

Here are the contents,

index.php

<?php
require_once('system/MyApp.php');
$app = new MyApp();
$app->init();
$rzpyObj = $app->loadRazorPay();
?>

MyApp.php

<?php
use Razorpay\Api\Api;
class MyApp {
    
    public function init() {
        $this->maintenanceMode();
        $this->loadConfig();
        $this->loadClasses();
    }
    
    public function loadClasses() {
        spl_autoload_register(function ($className) {
            include_once __DIR__. '/classes/' . $className . '.class.php';
        });
    }
    
    public function loadRazorPay() {
        require(__DIR__. '/third-party-libs/razorpay-config.php');
        require(__DIR__. '/third-party-libs/razorpay/Razorpay.php');
        return new Razorpay\Api\Api($keyId, $keySecret);
    }

My directory structure:

|-- index.php
|-- system
   |-- MyApp.php
   |-- third-party-libs
      |-- razorpay-config.php
      |-- razorpay
         |-- all files of razorpay as in github

Appreciate your help!

0

There are 0 best solutions below