Download the PHP package hugomarques62/juno-sdk-php-laravel without Composer
On this page you can find all versions of the php package hugomarques62/juno-sdk-php-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hugomarques62/juno-sdk-php-laravel
More information about hugomarques62/juno-sdk-php-laravel
Files in hugomarques62/juno-sdk-php-laravel
Package juno-sdk-php-laravel
Short Description Juno integration developed to Jetimob's internal use.
License MIT
Homepage https://github.com/jetimob/juno-sdk-php-laravel
Informations about the package juno-sdk-php-laravel
juno-sdk-php-laravel
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 asX-Resource-Token
in the docs.
Installing
Using Composer:
Publishing configurations
The command below will publish the configuration file to Laravel's config folder.
Config file
private_token
: sets the X-Resource-Token of the authorization endpointclientId
: in conjunction ofsecret
they make the authorization header - base64(clientId
:secret
)secret
: in conjunction ofclientId
they make the authorization header - base64(clientId
:secret
)guzzle
: sets the configurations of Guzzlebase_uri
: base uri to make the requests to the resource server (info)sandbox
production
authorization_base_uri
: base uri to make the requests to the authorization server (info)sandbox
production
connect_timeout
: number of seconds to wait while trying to connect to a server. 0 waits indefinitelytimeout
: time needed to throw a timeout exception after a request is made. 0 waits indefinitelydebug
: outputs Guzzle's debug messages to stdout
version
: Juno's API versionenvironment
: sets the current environment to build the request's URL. production | sandboxlogging
: enables the logging to Laravel's Log facaderequest_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 thrownrequest_attempt_delay
: Time in ms to wait before trying to execute a new request attemptrecoverable_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
Import the API namespace and use it with:
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 ofResponse
.
$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:
Complex objects MUST be manually configured, as:
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
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.
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
tosandbox
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
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
OddResponseObject.php
DocsCustomResponse.php
usage:
For more information about Juno's API, see the docs here and here (detailed PDF).