PHP Composer Guide

Welcome! This article will assist you to understand better about getting to know Composer!

In this article, we’ll cover what Composer is, what Composer does, how to use a composer, when to use Composer and how Composer is used in Xendit PHP SDK, and how you can easily integrate Xendit with your PHP application via composer.

What is a composer? What does a composer do?

If you’ve been coding in PHP for some time, you'll be aware of how PHP libraries can help save work and make code reusable. In the past, it was harder to add libraries to PHP, which led to a lot of reinventing the wheel for common features. For example, when you want to integrate with a new library, you have to download the library and call include native PHP function and you’re able to execute your desired function in that library.

In a nutshell, we need a tool which can be used to install libraries and manage application dependencies. Composer does a great job of this. It is an application-level package manager for PHP that has gained immense popularity and become the standard for managing dependencies in PHP applications.


"Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you" — Composer Introduction

It’s important to note that Composer allows you to install the necessary libraries on a per-project basis. It allows you to use different versions of the same library across different PHP projects. Of course, there’s an option to install a library globally, but it’s not recommended. If you’ve heard of npm for Node.js, or Bundler for Ruby, that's what Composer is for PHP.

To install and use libraries that are managed by Composer, you just need to declare them in your project in a standard format, and Composer will manage the rest. For example, if you want to install the phpmailer library by using Composer, you just need to run the following command in the root of your project.

$composer require phpmailer/phpmailer 

When to use Composer

Now you should have understood the composer from the previous section. And you might be wondering when is the right time to use a composer. If your PHP project uses multiple external libraries and various packages as helpers within your project, composer is the right tool for you to consider and use.

Composer allows you to very easily install a multitude of libraries for your project without dealing with the details. It allows the authors to use another library themselves without you having to deal with all the details.

For example, if you would want to manually install a library that requires to install two additional libraries in the correct version, with these libraries requiring one additional library each, and additionally you'd have to initialize the autoloading of all five libraries, this might be some task to tackle.

With Composer, you only require one library, and after that everything is done for you.

Additionally, it makes updating way easier for you. If your library has a bug that got fixed in a newer version, you simply update and see if your application still runs. You would spend most of the time checking everything still runs - and barely any time updating.

How to use Composer

There are two ways when it comes to installing libraries with Composer. Let’s quickly go through it to understand how it works.

The install Command

To use install, you need to create a composer.json file in your project first. In the composer.json file, you just need to declare your project dependencies, as shown in the following snippet.

    "require": {
        "phpmailer/phpmailer": "~6.1"

Next, when you run the composer install command from that folder,

$composer install 

Composer installs the phpmailer package and its dependencies in the vendor directory. More importantly, it also creates the composer.lock file, which maintains a list of all of the packages and the exact versions of them that are installed.

How composer is used in Xendit PHP SDK


Install the Xendit PHP library by adding the following to your composer.json file

  "repositories": [
      "type": "vcs",
      "url": ""
  "require": {
    "xendit/xendit-php": "4.0.0" // Refer to GitHub for our latest version

Then install the library by running

composer install

You've successfully installed Xendit's PHP library with Composer.

SDK Usage for Xendit APIs

Next, you can use the Xendit PHP SDK to accept payments or complete a payout. All code snippets and examples for this are visible on our GitHub repository.

Last Updated on 2023-12-05