PHPackages                             opaweb/juno-laravel - 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. opaweb/juno-laravel

ActiveLibrary[API Development](/categories/api)

opaweb/juno-laravel
===================

Integração Juno para Laravel

018PHP

Since Mar 23Pushed 5y ago1 watchersCompare

[ Source](https://github.com/opaweb/juno-laravel)[ Packagist](https://packagist.org/packages/opaweb/juno-laravel)[ RSS](/packages/opaweb-juno-laravel/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

juno-laravel
============

[](#juno-laravel)

Forked from jetimob/juno-sdk-php-laravel.

> **DONE:**

- Credit card tokenization (must use JS tokenization from Juno).

> **TODO:**

- UI for credit card;
- Local JS interface for Juno JS tokenization.

Make sure to add **`JUNO_PRIVATE_TOKEN`**, **`JUNO_CLIENT_ID`** and **`JUNO_CLIENT_SECRET`** to your `.env` file to identify your account in every request.

> **`JUNO_PRIVATE_TOKEN`** is also referred as `X-Resource-Token` in the docs.

Installing
----------

[](#installing)

Using Composer:

```
$ composer require opaweb/juno-laravel
```

### Publishing configurations

[](#publishing-configurations)

The command below will publish the configuration file to Laravel's config folder.

```
$ php artisan juno:install
```

Config file
-----------

[](#config-file)

- `private_token`: sets the X-Resource-Token of the authorization endpoint
- `clientId`: in conjunction of `secret` they make the authorization header - base64(`clientId`:`secret`)
- `secret`: in conjunction of `clientId` they make the authorization header - base64(`clientId`:`secret`)
- `guzzle`: sets the configurations of Guzzle
    - `base_uri`: base uri to make the requests to the resource server ([info](https://dev.juno.com.br/api/v2#section/Servidor-de-Recursos))
        - `sandbox`
        - `production`
    - `authorization_base_uri`: base uri to make the requests to the authorization server ([info](https://dev.juno.com.br/api/v2#section/Servidor-de-Autorizacao))
        - `sandbox`
        - `production`
    - `connect_timeout`: number of seconds to wait while trying to connect to a server. 0 waits indefinitely
    - `timeout`: time needed to throw a timeout exception after a request is made. 0 waits indefinitely
    - `debug`: outputs Guzzle's debug messages to stdout
- `version`: Juno's API version
- `environment`: sets the current environment to build the request's URL. ***production*** | ***sandbox***
- `logging`: enables the logging to Laravel's Log facade
- `request_max_attempts`: Juno's API is currently unstable and being so, is common that we need to perform a request more than one time until the request succeeds. Choose a value that you think that is acceptable. If the request fails even after the N times set, an exception will be thrown
- `request_attempt_delay`: Time in *ms* to wait before trying to execute a new request attempt
- `recoverable_status_codes`: Array of status codes that are considered recoverable. Only the ones specified in this array will trigger a reattempt in case of a failed request.

Usage
-----

[](#usage)

Import the API namespace and use it with:

```
use Juno;

$response = Juno::request($requestObject, $resourceToken);
```

Where `$requestObject` MUST be an instance of the Request class.

> Every class inside the `Jetimob\Juno\Lib\Http` namespace implements Request.
> $response will **always** return an instance of `Response`.

> `$resourceToken` is required to make sure that the request is being made to the right endpoint with the right credentials.

Simple requests as `DocumentListRequest` can be made passing the class the `request` function:

```
Juno::request(DocumentListRequest::class, $resourceToken);
```

Complex objects MUST be manually configured, as:

```
$billing = new Billing();
$billing->name = 'NAME';
$billing->document = 'document';
$billing->phone = 'phone';
$billing->email = 'email@xxxxxxx.com';
$billing->notify = true;

$charge = new Charge();
$charge->description    = 'description';
$charge->amount         = 99999.99;
$charge->dueDate        = Juno::formatDate(2020, 2, 25);

$charge->maxOverdueDays = 99;
$charge->fine           = 9.9;
$charge->interest       = 9.9;

/** @var ChargeCreationResponse $response */
$response = Juno::request(new ChargeCreationRequest($charge, $billing), $resourceToken);
```

### Response

[](#response)

Every request made with the API will return an instance of the `Response` object.
All objects that implement `Request` have they own `Response` object. i.e.: `ChargeConsultRequest` has its `ChargeConsultResponse`.
If an error occurs during the request (a non 200 code), the returned object will be an instance of `ErrorResponse`.

### Errors

[](#errors)

When a request is made, several problems can arise, so to prevent this from happening, wrap the `request` call with a `try`/`catch` block.
Every Juno exception is a child of `JunoException` so all exceptions that can arise during a request can be handled within a single `try` block.

```
try {
    Juno::request(DocumentListRequest::class, $resourceToken);
} catch (JunoAccessTokenRejection $e) {
    [...]
} catch (JunoException $e) {
    [...]
} catch (Exception $e) {
    [...]
}
```

Access Token caching
--------------------

[](#access-token-caching)

**The authorization token (access token) is cached to Laravel's default `Cache` facade, make sure to have it correctly configured.**

> If you change the environment from `production` to `sandbox` or vice-versa, you ***MUST*** clear the cache with: **`php artisan juno:clear-cache`**. Otherwise, the cached access token will be used and you'll receive a 401 error.

Creating a custom request
-------------------------

[](#creating-a-custom-request)

If you need to make a custom request to Juno's API, you'll need to create two classes, the `Request` and the `Response`.
Let's imagine that we need to make a request to `docs` endpoint.
We'll need to create `DocsCustomRequest` and `DocsCustomResponse` as exemplified:

***DocsCustomRequest.php***

```
use Jetimob\Juno\Lib\Http\Method;
use Jetimob\Juno\Lib\Http\Request;
use Jetimob\Juno\Lib\Http\BodyType;

class DocsCustomRequest extends Request
{
    /** @var string $id pathParam */
    public string $id;

    public string $param1;
    public string $param2;

    /**
     * @var string $responseClass overrides the response serialization class.
     *
     * Every successful request will have its response cast to an instance of the class defined by
     * this property.
     *
     * If the response class has the same name with 'Request' exchanged with 'Response', you can leave
     * don't need to set this property.
     */
    protected string $responseClass = DocsCustomResponse::class;

    /**
     * @var string $bodyType overrides the request body type
     * @see http://docs.guzzlephp.org/en/stable/request-options.html
     */
    protected string $bodyType = BodyType::JSON;

    /** @var string[] $bodySchema specifies which properties of the current instance should be sent with the body */
    protected array $bodySchema = [
        'param1',
        'param2',
    ]

    /**
     * Specifies the request method
    */
    protected function method(): string
    {
        return Method::GET;
    }

    /**
     * Specifies the endpoint to be merged with base_uri defined in the configuration file.
     * Anything inside brackets {} will trigger the request to update the matched identifier with this
     * instance's property with the same name. e.g.: the {id} below will be exchanged to the value of
     * $this->id;
    */
    protected function urn(): string
    {
        return 'docs/{id}';
    }
}
```

***OddResponseObject.php***

```
use Jetimob\Juno\Lib\Traits\Serializable;

class OddResponseObject
{
    use Serializable;

    public string $property1;
    public int $property2;
}
```

***DocsCustomResponse.php***

```
use Jetimob\Juno\Lib\Http\Response;

/**
 * All properties defined in this class MUST match the object keys defined in Juno's API response.
 *
 * Complex objects can be typed so that the SDK can cast an instance and define this instance property
 * ($param in the class example below)
 *
 * If there is data inside an '_embedded' key, you MUST override the initComplexObjects function and
 * use the helper functions of Response class.
 *
 * @see https://dev.juno.com.br/api/v2
*/
class DocsCustomResponse extends Response
{
    protected string $id;

    protected int $value;

    protected OddResponseObject $param;

    /** @var OddResponseObject $embeddedData */
    protected array $embeddedData;

    /**
     * This function is mainly used to deserialize embedded data.
     *
     * The first parameter given to deserializeEmbeddedArray specifies in which key, inside the
     * _embedded object, is the data that we are trying to deserialize.
    */
    public function initComplexObjects(): void
    {
        $this->embeddedData = $this->deserializeEmbeddedArray(
            'propertyInsideEmbedded', // key name inside _embedded
            OddResponseObject::class, // deserialize each element to the given class
            [],                       // default value if the key is non existent
        );
    }

    [... getters]
}
```

##### usage:

[](#usage-1)

```
$requestData = new DocsCustomRequest();
$requestData->id     = 'XXXXXXXXXXXXXXXXXXXXXXXXX';
$requestData->param1 = 'XXXXXXXXXXXXXXXXXXXXXXXXX';
$requestData->param2 = 'XXXXXXXXXXXXXXXXXXXXXXXXX';

// error handling ignored for example readability
/** @var DocsCustomResponse $response */
$response = Juno::request($requestData, $resourceToken);

// all properties are initialized and can be easily accessed:
$response->getParam()->property1;
```

---

For more information about Juno's API, see the docs [here](https://dev.juno.com.br/api/v2) and [here (detailed PDF)](https://dev.juno.com.br/junoAPI20Integration.pdf).

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity32

Early-stage or recently created project

 Bus Factor1

Top contributor holds 85.5% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/07ab33e5a9f57a4295fbe225fd4427276b2dd16c7d3ab108cca91d48643738ec?d=identicon)[opaweb](/maintainers/opaweb)

---

Top Contributors

[![alanwgt](https://avatars.githubusercontent.com/u/15879871?v=4)](https://github.com/alanwgt "alanwgt (53 commits)")[![opaweb](https://avatars.githubusercontent.com/u/43017037?v=4)](https://github.com/opaweb "opaweb (4 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")[![elton-fonseca](https://avatars.githubusercontent.com/u/3722700?v=4)](https://github.com/elton-fonseca "elton-fonseca (1 commits)")[![hnvas](https://avatars.githubusercontent.com/u/21023685?v=4)](https://github.com/hnvas "hnvas (1 commits)")

### Embed Badge

![Health badge](/badges/opaweb-juno-laravel/health.svg)

```
[![Health](https://phpackages.com/badges/opaweb-juno-laravel/health.svg)](https://phpackages.com/packages/opaweb-juno-laravel)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M271](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[microsoft/microsoft-graph

The Microsoft Graph SDK for PHP

65723.5M96](/packages/microsoft-microsoft-graph)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)

PHPackages © 2026

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