Fatal error: Uncaught Error: Class 'Mollie\Api\MollieApiClient' not found

2020-02-15 php api

So, it's my first time using an API for transactions, but I have a difficult time importing the class.

I use the Mollie API and installed it with the composer.

I use mollie 2.0.

This is how my folder structure looks like and where I store my autoloader:

htdocs->vendor->autoload.php

This is how my main project folder looks like:

htdocs->elf->mollieApi.php //(mollieApi is where I try to call the API and do stuff)

Inside of the elf directory, I have the mollie-api-php folder which gets downloaded when you use the composer.

This is how mollieApi.php looks like:

// autoload
require __DIR__ . "/../vendor/autoload.php";

// API key
require "api_keys/apiKey.php";

//Database connection
require("../database/connection.php");

// Use Mollie
use Mollie\Api\MollieApiClient;

$mollie = new MollieApiClient(); //this line doesn't work and throws the fatal error
$mollie->setApiKey(api_key);

//more stuff regarding mollie, but pretty useless to share

my composer.json looks like this and it is located in my htdocs:

{
    "require": {
        "mollie/mollie-api-php": "^2.0"
    }
}

What I have tried:

  • Move the mollie-api-php map into the vendor map
  • Moved autoload.php into the elf directory
  • Tried taking out the class which was throwing the error etc and place it in my elf directory (which worked, but it then started to complain about having to import other stuff and I could tell the solution would turn into hell, because I also had to import other directories, etc)
  • I looked up a couple of StackOverflow questions regarding this, but unfortunately, they're all too specific and the questions do not seem to apply to my problem.

What I want to achieve:

I want to be able to import (autoload) the Mollie class, get to know what I was doing wrong (use Mollie\Api\MollieApiClient;) and actually be able to use it.

Answers

Related