Back to Top

Adding External Php Library In Magento 2

Updated 5 March 2024

In this post we will learn how to add external library in magento 2. As a magento 2 extension developer, it is very important to know how to add external library in magento 2 the right way . Payment gateways ,shipping api,  social networking etc,  they all provide their language specific library, that we need to include in our magento extension to connect with them and obviously we need to add them in the right way as magento  does.

When you will see the magento 2 folder structure, you will notice vendor folder in the root, when you will open this folder you will notice many libraries such as braintree, symphony, doctrine etc, they all are provided when you will download  magento 2 but what if the extension you are creating require another library for example if you want to create stripe payment method in magento 2 you will need to add stripe library for the api calls .

Magento 2 uses various technologies and composer is one of them ,composer is used to manage dependency in the project the best way to add any external library without going into the code is composer, magento have a composer.json file in its root. For adding stripe library in the vendor folder, you just need to run this command from the command line :

after installing the composer, go to your Magento 2 root folder and  run the below command from the terminal :

composer require stripe/stripe-php

In the above command “stripe/stripe-php” is the package name you can found this on packagist .

Start your headless eCommerce
now.
Find out More

after executing the above command the latest version of the stripe library will be installed on your Magento 2 extension and it will be autoloaded in your project. You can find the changes in two places in the Magento first in the composer.json file in the Magento 2 root:

Composer.json

and the second you will find its folder in Magento 2 vendor folder in the root:

Vendor Folder

That’s all, you will find it very easy to do, but in case you have any doubts please comment below.

Thanks 🙂

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


2 comments

  • Sandhya
    • Ayaz Mittaqi (Moderator)
  • Back to Top

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home

    Table of Content