PHPackages                             9orky/espago-api-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. 9orky/espago-api-php

ActiveLibrary[API Development](/categories/api)

9orky/espago-api-php
====================

Client for Espago API

v0.8.2(9y ago)2601PHPPHP &gt;=7.0

Since Nov 5Pushed 9y ago3 watchersCompare

[ Source](https://github.com/9orky/espago-api-php)[ Packagist](https://packagist.org/packages/9orky/espago-api-php)[ RSS](/packages/9orky-espago-api-php/feed)WikiDiscussions master Synced today

READMEChangelog (6)Dependencies (6)Versions (7)Used By (0)

Espago API (PHP) [![Build Status](https://camo.githubusercontent.com/240d78d80e468a6ffaed23acd0963890cd70530e277963ea86f681ded92b511e/68747470733a2f2f7472617669732d63692e6f72672f396f726b792f65737061676f2d6170692d7068702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/9orky/espago-api-php)
============================================================================================================================================================================================================================================================================================================

[](#espago-api-php-)

Unofficial client of the Espago API written in PHP7.

Installation
============

[](#installation)

To install via Composer just type in your console:

```
composer require "9orky/espago-api-php"
```

and you're done!

Usage
=====

[](#usage)

To avoid one huge file with all API methods, client was split into smaller functional pieces. The facade APIs are behind is at: **Gorky\\Espago\\Factory\\ApiFactory**

Bootstrap
---------

[](#bootstrap)

All you need to do is to instantiate an API Factory with:

- apiUrl - this is quite obvious, for development purposes your URL is:
- apiCredentials - this is an object which resides at **Gorky\\Espago\\Model\\ApiCredentials** and requires three arguments which should be provided to you by Espago: public key, app ID and password.

How does this look in a code?

```
$apiFactory = new \Gorky\Espago\Factory\ApiFactory(
    'https://sandbox.espago.com',
    new \Gorky\Espago\Model\ApiCredentials('app_id', 'public_key', 'password')
);
```

Conducting a simplest transaction
=================================

[](#conducting-a-simplest-transaction)

Ok, now with our Api Factory handy we can proceed to make our first transaction. What we needed is to ask a Customer for his card details and charge him.

Obtaining a Token
-----------------

[](#obtaining-a-token)

First step to our simple transaction is to generate a special Token which will be a Card's representation in Espago.

```
$tokensApi = $apiFactory->buildTokensApi();

// first we need Customer card's representation
$unauthorizedCard = $tokensApi->createUnauthorizedCard(
    '4111111111111111',
    'John',
    'Doe',
    '04',
    '2020',
    '111'
);

// so now we can transform it to a Token
$token = $tokensApi->createToken($unauthorizedCard);
```

Token's model is a Response object so, together with others, it resides at: **Gorky\\Espago\\Model** directory. Explore the area to be familiar with what system can handle.

Making a Charge
---------------

[](#making-a-charge)

We have a Token so now it's time to charge a Customer. To do this we have to call Charges API and provide some payment details.

```
$chargesApi = $apiFactory->buildChargesApi();

// carefuly study Gorky\Espago\Model\Response\Charge and corresponding API documents!
$charge = $chargesApi->createChargeByToken($token, 12.66, 'PLN', 'doughnuts');
```

Yes, it was actually that easy :-)

Remembering the Card in Espago
------------------------------

[](#remembering-the-card-in-espago)

At this moment payment transaction is executed and Customer is charged. But wait, he just forgot to buy his wife some flowers for their anniversary. Oh no, he must type all these numbers and letters once again! But no worries though, we can actually save Customer's Card in Espago for us to use it when needed.

To match Card with a Customer we need to create a Client. We have do this with a little help of our friend Token.

```
$tokensApi = $apiFactory->buildTokensApi();

$unauthorizedCard = $tokensApi->createUnauthorizedCard(
    '4111111111111111',
    'John',
    'Doe',
    '04',
    '2020',
    '111'
);

$token = $tokensApi->createToken($unauthorizedCard);

$clientsApi = $apiFactory->buildClientsApi();

$client = $clientsApi->createClient($token, 'john@example.com', 'Our precious client John');

$chargesApi = $apiFactory->buildChargesApi();

$charge = $chargesApi->createChargeByClient($client, 12.66, 'PLN', 'doughnuts');
```

All you have to do now is to persist a Client's ID and from now on you can charge Customer on demand. It's very convenient when your Customers are returning ones.

Fancy
=====

[](#fancy)

There is a simple Console Application to play with using your sandbox account! :-) To make it usable we have to make some preparations.

Making credentials file
-----------------------

[](#making-credentials-file)

In a main directory create PHP file called: *credentials.php*:

```
// credentials.php

return [
    'app_id'     => 'your_app_id',
    'public_key' => 'your_public_key',
    'password'   => 'your_password'
];
```

Time to play
------------

[](#time-to-play)

Create new Client:

```
php espago.php customer:create
```

Charge Client:

```
php espago.php customer:charge --interactive
```

or

```
php espago.php customer:charge --clientId="1234" --amount="6.67" --currency="PLN" --description="flowers"
```

Capture Authorization hold:

```
php espago.php customer:charge --capture --chargeId="pay_COy6zH9fLj1d7K" --amount="23.44"
```

Refund Charge:

```
php espago.php customer:charge --refund --chargeId="pay_COy6zH9fLj1d7K" --amount="23.44"
```

Cancel Charge:

```
php espago.php customer:charge --cancel --chargeId="pay_COy6zH9fLj1d7K"
```

Note: Remember that you can always use --interactive switch which is more convenient:

```
php espago.php customer:charge --cancel --interactive
```

API documentation is right here:

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~12 days

Total

6

Last Release

3463d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1598561?v=4)[Tomasz Szpak](/maintainers/9orky)[@9orky](https://github.com/9orky)

---

Top Contributors

[![9orky](https://avatars.githubusercontent.com/u/1598561?v=4)](https://github.com/9orky "9orky (13 commits)")

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/9orky-espago-api-php/health.svg)

```
[![Health](https://phpackages.com/badges/9orky-espago-api-php/health.svg)](https://phpackages.com/packages/9orky-espago-api-php)
```

###  Alternatives

[statamic/cms

The Statamic CMS Core Package

4.8k3.6M982](/packages/statamic-cms)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3741.3M46](/packages/tencentcloud-tencentcloud-sdk-php)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k38](/packages/neuron-core-neuron-ai)[avalara/avataxclient

Client library for Avalara's AvaTax suite of business tax calculation and processing services. Uses the REST v2 API.

528.5M7](/packages/avalara-avataxclient)[files.com/files-php-sdk

Files.com PHP SDK

2481.1k](/packages/filescom-files-php-sdk)[aimeos/prisma

A powerful PHP package for integrating media related Large Language Models (LLMs) into your applications

1943.1k5](/packages/aimeos-prisma)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
