{"id":49263,"date":"2016-05-20T15:17:24","date_gmt":"2016-05-20T15:17:24","guid":{"rendered":"http:\/\/webkul.com\/blog\/?p=49263"},"modified":"2024-03-05T09:58:05","modified_gmt":"2024-03-05T09:58:05","slug":"add-external-php-library-in-magento-2","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/","title":{"rendered":"Adding External Php Library In Magento 2"},"content":{"rendered":"\n<p>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, &nbsp;social networking etc, &nbsp;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 &nbsp;does.<\/p>\n\n\n\n<p>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 &nbsp;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 .<\/p>\n\n\n\n<p>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 :<\/p>\n\n\n\n<div class=\"wk-index-wrap\"><div class=\"block-wrap\">\n<h3 class=\"wp-block-heading index-title\">\nFor 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\n<\/h3>\n<\/div><\/div>\n\n\n\n<p>after installing the composer, go to your Magento 2 root folder and \u00a0run the below command from the terminal :<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">composer require stripe\/stripe-php<\/pre>\n\n\n\n<p>In the above command &#8220;stripe\/stripe-php&#8221; is the package name you can found this on<a href=\"https:\/\/packagist.org\/\"> packagist<\/a> .<\/p>\n\n\n\n<p>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:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"alignleft\"><img decoding=\"async\" width=\"783\" height=\"667\" src=\"http:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/05\/Selection_009.png\" alt=\"Composer.json\" class=\"wp-image-49958\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/05\/Selection_009.png 783w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/05\/Selection_009-250x213.png 250w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/05\/Selection_009-300x256.png 300w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/05\/Selection_009-768x654.png 768w\" sizes=\"(max-width: 783px) 100vw, 783px\" loading=\"lazy\" \/><\/figure>\n<\/div>\n\n\n<p>and the second you will find its folder in Magento 2 vendor folder in the root:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"alignleft\"><img decoding=\"async\" width=\"387\" height=\"530\" src=\"http:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/05\/Selection_010.png\" alt=\"Vendor Folder\" class=\"wp-image-49959\" srcset=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/05\/Selection_010.png 387w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/05\/Selection_010-182x249.png 182w, https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2016\/05\/Selection_010-219x300.png 219w\" sizes=\"(max-width: 387px) 100vw, 387px\" loading=\"lazy\" \/><\/figure>\n<\/div>\n\n\n<p>That&#8217;s all, you will find it very easy to do, but in case you have any doubts please comment below.<\/p>\n\n\n\n<p>Thanks \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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, &nbsp;social networking etc, &nbsp;they all provide their language specific library, that we need <a href=\"https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":33,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-49263","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Adding External Php Library In Magento 2 - Webkul Blog<\/title>\n<meta name=\"description\" content=\"easiest way to add external php library in magento 2\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Adding External Php Library In Magento 2 - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"easiest way to add external php library in magento 2\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2016-05-20T15:17:24+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-05T09:58:05+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/webkul.com\/blog\/wp-content\/uploads\/2016\/05\/Selection_009.png\" \/>\n<meta name=\"author\" content=\"Ashutosh Srivastava\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ashutosh Srivastava\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/\"},\"author\":{\"name\":\"Ashutosh Srivastava\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/5555025750ec4e4df34fadc78b083970\"},\"headline\":\"Adding External Php Library In Magento 2\",\"datePublished\":\"2016-05-20T15:17:24+00:00\",\"dateModified\":\"2024-03-05T09:58:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/\"},\"wordCount\":369,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/webkul.com\/blog\/wp-content\/uploads\/2016\/05\/Selection_009.png\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/\",\"url\":\"https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/\",\"name\":\"Adding External Php Library In Magento 2 - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/webkul.com\/blog\/wp-content\/uploads\/2016\/05\/Selection_009.png\",\"datePublished\":\"2016-05-20T15:17:24+00:00\",\"dateModified\":\"2024-03-05T09:58:05+00:00\",\"description\":\"easiest way to add external php library in magento 2\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/#primaryimage\",\"url\":\"http:\/\/webkul.com\/blog\/wp-content\/uploads\/2016\/05\/Selection_009.png\",\"contentUrl\":\"http:\/\/webkul.com\/blog\/wp-content\/uploads\/2016\/05\/Selection_009.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Adding External Php Library In Magento 2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/5555025750ec4e4df34fadc78b083970\",\"name\":\"Ashutosh Srivastava\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2f5312e6903909ffeb33aa5eb38e1c0bed8f498f92144f5f84065adf7e8708a6?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2f5312e6903909ffeb33aa5eb38e1c0bed8f498f92144f5f84065adf7e8708a6?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g\",\"caption\":\"Ashutosh Srivastava\"},\"sameAs\":[\"http:\/\/webkul.com\"],\"url\":\"https:\/\/webkul.com\/blog\/author\/ashutosh\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Adding External Php Library In Magento 2 - Webkul Blog","description":"easiest way to add external php library in magento 2","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/","og_locale":"en_US","og_type":"article","og_title":"Adding External Php Library In Magento 2 - Webkul Blog","og_description":"easiest way to add external php library in magento 2","og_url":"https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2016-05-20T15:17:24+00:00","article_modified_time":"2024-03-05T09:58:05+00:00","og_image":[{"url":"http:\/\/webkul.com\/blog\/wp-content\/uploads\/2016\/05\/Selection_009.png","type":"","width":"","height":""}],"author":"Ashutosh Srivastava","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Ashutosh Srivastava","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/"},"author":{"name":"Ashutosh Srivastava","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/5555025750ec4e4df34fadc78b083970"},"headline":"Adding External Php Library In Magento 2","datePublished":"2016-05-20T15:17:24+00:00","dateModified":"2024-03-05T09:58:05+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/"},"wordCount":369,"commentCount":2,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"image":{"@id":"https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/#primaryimage"},"thumbnailUrl":"http:\/\/webkul.com\/blog\/wp-content\/uploads\/2016\/05\/Selection_009.png","inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/","url":"https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/","name":"Adding External Php Library In Magento 2 - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/#primaryimage"},"image":{"@id":"https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/#primaryimage"},"thumbnailUrl":"http:\/\/webkul.com\/blog\/wp-content\/uploads\/2016\/05\/Selection_009.png","datePublished":"2016-05-20T15:17:24+00:00","dateModified":"2024-03-05T09:58:05+00:00","description":"easiest way to add external php library in magento 2","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/#primaryimage","url":"http:\/\/webkul.com\/blog\/wp-content\/uploads\/2016\/05\/Selection_009.png","contentUrl":"http:\/\/webkul.com\/blog\/wp-content\/uploads\/2016\/05\/Selection_009.png"},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/add-external-php-library-in-magento-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Adding External Php Library In Magento 2"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/5555025750ec4e4df34fadc78b083970","name":"Ashutosh Srivastava","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/2f5312e6903909ffeb33aa5eb38e1c0bed8f498f92144f5f84065adf7e8708a6?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2f5312e6903909ffeb33aa5eb38e1c0bed8f498f92144f5f84065adf7e8708a6?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Fmike.png&r=g","caption":"Ashutosh Srivastava"},"sameAs":["http:\/\/webkul.com"],"url":"https:\/\/webkul.com\/blog\/author\/ashutosh\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/49263","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/33"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=49263"}],"version-history":[{"count":10,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/49263\/revisions"}],"predecessor-version":[{"id":426071,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/49263\/revisions\/426071"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=49263"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=49263"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=49263"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}