Quantcast
Channel: Webkul Blog
Viewing all articles
Browse latest Browse all 5490

Adding External Php Library In Magento 2

$
0
0

Upload files using magento2 mediastorage module

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 :

For this command you must install composer on your server ,if you are not familiar with composer go through this link first : https://getcomposer.org/doc/00-intro.md

after installing the composer, goto your magento 2 root folder and  run 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 .

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

Composer.jsonand 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 🙂

 


Viewing all articles
Browse latest Browse all 5490

Trending Articles