Skip to content

Commit

Permalink
Automated commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
andreals committed Feb 23, 2024
1 parent b31a0a3 commit 1b7b3b0
Show file tree
Hide file tree
Showing 22 changed files with 481 additions and 29 deletions.
57 changes: 35 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ To run your project, right click on your PHP file inside your Test project and c

## Initialize the API Client

**_Note:_** Documentation for the client can be found [here.](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.5/doc/client.md)
**_Note:_** Documentation for the client can be found [here.](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.6/doc/client.md)

The following parameters are configurable for the API Client:

Expand All @@ -115,46 +115,59 @@ The following parameters are configurable for the API Client:
| `retryOnTimeout` | `bool` | Whether to retry on request timeout.<br>*Default*: `true` |
| `httpStatusCodesToRetry` | `array` | Http status codes to retry against.<br>*Default*: `408, 413, 429, 500, 502, 503, 504, 521, 522, 524` |
| `httpMethodsToRetry` | `array` | Http methods to retry against.<br>*Default*: `'GET', 'PUT'` |
| `basicAuthCredentials` | [`BasicAuthCredentials`](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.6/doc/$a/https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.6/basic-authentication.md) | The Credentials Setter for Basic Authentication |

The API client can be initialized as follows:

```php
$client = PagarmeApiSDKClientBuilder::init()
->basicAuthCredentials(
BasicAuthCredentialsBuilder::init(
'BasicAuthUserName',
'BasicAuthPassword'
)
)
->serviceRefererName('ServiceRefererName')
->build();
```

## Authorization

This API uses the following authentication schemes.

* [`httpBasic (Basic Authentication)`](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.6/doc/$a/https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.6/basic-authentication.md)

## API Errors

Here is the list of errors that the API might throw.

| HTTP Status Code | Error Description | Exception Class |
| --- | --- | --- |
| 400 | Invalid request | [`ErrorException`](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.5/doc/models/error-exception.md) |
| 401 | Invalid API key | [`ErrorException`](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.5/doc/models/error-exception.md) |
| 404 | An informed resource was not found | [`ErrorException`](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.5/doc/models/error-exception.md) |
| 412 | Business validation error | [`ErrorException`](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.5/doc/models/error-exception.md) |
| 422 | Contract validation error | [`ErrorException`](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.5/doc/models/error-exception.md) |
| 500 | Internal server error | [`ErrorException`](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.5/doc/models/error-exception.md) |
| 400 | Invalid request | [`ErrorException`](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.6/doc/models/error-exception.md) |
| 401 | Invalid API key | [`ErrorException`](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.6/doc/models/error-exception.md) |
| 404 | An informed resource was not found | [`ErrorException`](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.6/doc/models/error-exception.md) |
| 412 | Business validation error | [`ErrorException`](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.6/doc/models/error-exception.md) |
| 422 | Contract validation error | [`ErrorException`](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.6/doc/models/error-exception.md) |
| 500 | Internal server error | [`ErrorException`](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.6/doc/models/error-exception.md) |

## List of APIs

* [Subscriptions](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.5/doc/controllers/subscriptions.md)
* [Orders](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.5/doc/controllers/orders.md)
* [Plans](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.5/doc/controllers/plans.md)
* [Invoices](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.5/doc/controllers/invoices.md)
* [Customers](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.5/doc/controllers/customers.md)
* [Charges](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.5/doc/controllers/charges.md)
* [Recipients](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.5/doc/controllers/recipients.md)
* [Tokens](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.5/doc/controllers/tokens.md)
* [Transactions](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.5/doc/controllers/transactions.md)
* [Transfers](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.5/doc/controllers/transfers.md)
* [Payables](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.5/doc/controllers/payables.md)
* [Balance Operations](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.5/doc/controllers/balance-operations.md)
* [Subscriptions](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.6/doc/controllers/subscriptions.md)
* [Orders](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.6/doc/controllers/orders.md)
* [Plans](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.6/doc/controllers/plans.md)
* [Invoices](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.6/doc/controllers/invoices.md)
* [Customers](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.6/doc/controllers/customers.md)
* [Charges](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.6/doc/controllers/charges.md)
* [Recipients](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.6/doc/controllers/recipients.md)
* [Tokens](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.6/doc/controllers/tokens.md)
* [Transactions](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.6/doc/controllers/transactions.md)
* [Transfers](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.6/doc/controllers/transfers.md)
* [Payables](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.6/doc/controllers/payables.md)
* [Balance Operations](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.6/doc/controllers/balance-operations.md)

## Classes Documentation

* [ApiException](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.5/doc/api-exception.md)
* [HttpRequest](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.5/doc/http-request.md)
* [HttpResponse](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.5/doc/http-response.md)
* [ApiException](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.6/doc/api-exception.md)
* [HttpRequest](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.6/doc/http-request.md)
* [HttpResponse](https://www.github.com/pagarme/pagarme-php-sdk/tree/6.8.6/doc/http-response.md)

36 changes: 36 additions & 0 deletions doc/auth/basic-authentication.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

# Basic Authentication



Documentation for accessing and setting credentials for httpBasic.

## Auth Credentials

| Name | Type | Description | Setter | Getter |
| --- | --- | --- | --- | --- |
| BasicAuthUserName | `string` | The username to use with basic authentication | `username` | `getBasicAuthUserName()` |
| BasicAuthPassword | `string` | The password to use with basic authentication | `password` | `getBasicAuthPassword()` |



**Note:** Auth credentials can be set using `BasicAuthCredentialsBuilder::init()` in `basicAuthCredentials` method in the client builder and accessed through `getBasicAuthCredentials` method in the client instance.

## Usage Example

### Client Initialization

You must provide credentials in the client as shown in the following code snippet.

```php
$client = PagarmeApiSDKClientBuilder::init()
->basicAuthCredentials(
BasicAuthCredentialsBuilder::init(
'BasicAuthUserName',
'BasicAuthPassword'
)
)
->build();
```


7 changes: 7 additions & 0 deletions doc/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,18 @@ The following parameters are configurable for the API Client:
| `retryOnTimeout` | `bool` | Whether to retry on request timeout.<br>*Default*: `true` |
| `httpStatusCodesToRetry` | `array` | Http status codes to retry against.<br>*Default*: `408, 413, 429, 500, 502, 503, 504, 521, 522, 524` |
| `httpMethodsToRetry` | `array` | Http methods to retry against.<br>*Default*: `'GET', 'PUT'` |
| `basicAuthCredentials` | [`BasicAuthCredentials`]($a/basic-authentication.md) | The Credentials Setter for Basic Authentication |

The API client can be initialized as follows:

```php
$client = PagarmeApiSDKClientBuilder::init()
->basicAuthCredentials(
BasicAuthCredentialsBuilder::init(
'BasicAuthUserName',
'BasicAuthPassword'
)
)
->serviceRefererName('ServiceRefererName')
->build();
```
Expand Down
4 changes: 4 additions & 0 deletions doc/controllers/tokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ $tokensController = $client->getTokensController();

# Create Token

:information_source: **Note** This endpoint does not require authentication.

```php
function createToken(
string $publicKey,
Expand Down Expand Up @@ -65,6 +67,8 @@ $result = $tokensController->createToken(

Gets a token from its id

:information_source: **Note** This endpoint does not require authentication.

```php
function getToken(string $id, string $publicKey): GetTokenResponse
```
Expand Down
71 changes: 71 additions & 0 deletions src/Authentication/BasicAuthCredentialsBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

declare(strict_types=1);

/*
* PagarmeApiSDKLib
*
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
*/

namespace PagarmeApiSDKLib\Authentication;

use Core\Utils\CoreHelper;

/**
* Utility class for initializing BasicAuth security credentials.
*/
class BasicAuthCredentialsBuilder
{
/**
* @var array
*/
private $config;

private function __construct(array $config)
{
$this->config = $config;
}

/**
* Initializer for BasicAuthCredentialsBuilder
*
* @param string $username
* @param string $password
*/
public static function init(string $username, string $password): self
{
return new self(['basicAuthUserName' => $username, 'basicAuthPassword' => $password]);
}

/**
* Setter for BasicAuthUserName.
*
* @param string $username
*
* @return $this
*/
public function username(string $username): self
{
$this->config['basicAuthUserName'] = $username;
return $this;
}

/**
* Setter for BasicAuthPassword.
*
* @param string $password
*
* @return $this
*/
public function password(string $password): self
{
$this->config['basicAuthPassword'] = $password;
return $this;
}

public function getConfiguration(): array
{
return CoreHelper::clone($this->config);
}
}
69 changes: 69 additions & 0 deletions src/Authentication/BasicAuthManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

declare(strict_types=1);

/*
* PagarmeApiSDKLib
*
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
*/

namespace PagarmeApiSDKLib\Authentication;

use Core\Authentication\CoreAuth;
use Core\Request\Parameters\HeaderParam;
use PagarmeApiSDKLib\BasicAuthCredentials;

/**
* Utility class for authorization and token management.
*/
class BasicAuthManager extends CoreAuth implements BasicAuthCredentials
{
private $basicAuthUserName;

private $basicAuthPassword;

/**
* Returns an instance of this class.
*
* @param string $basicAuthUserName The username to use with basic authentication
* @param string $basicAuthPassword The password to use with basic authentication
*/
public function __construct(string $basicAuthUserName, string $basicAuthPassword)
{
parent::__construct(
HeaderParam::init('Authorization', 'Basic ' . base64_encode("$basicAuthUserName:$basicAuthPassword"))
->required()
);
$this->basicAuthUserName = $basicAuthUserName;
$this->basicAuthPassword = $basicAuthPassword;
}

/**
* String value for basicAuthUserName.
*/
public function getBasicAuthUserName(): string
{
return $this->basicAuthUserName;
}

/**
* String value for basicAuthPassword.
*/
public function getBasicAuthPassword(): string
{
return $this->basicAuthPassword;
}

/**
* Checks if provided credentials match with existing ones.
*
* @param string $basicAuthUserName The username to use with basic authentication
* @param string $basicAuthPassword The password to use with basic authentication
*/
public function equals(string $basicAuthUserName, string $basicAuthPassword): bool
{
return $basicAuthUserName == $this->basicAuthUserName &&
$basicAuthPassword == $this->basicAuthPassword;
}
}
35 changes: 35 additions & 0 deletions src/BasicAuthCredentials.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

/*
* PagarmeApiSDKLib
*
* This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
*/

namespace PagarmeApiSDKLib;

/**
* Interface for defining the behavior of Authentication.
*/
interface BasicAuthCredentials
{
/**
* String value for basicAuthUserName.
*/
public function getBasicAuthUserName(): string;

/**
* String value for basicAuthPassword.
*/
public function getBasicAuthPassword(): string;

/**
* Checks if provided credentials match with existing ones.
*
* @param string $basicAuthUserName The username to use with basic authentication
* @param string $basicAuthPassword The password to use with basic authentication
*/
public function equals(string $basicAuthUserName, string $basicAuthPassword): bool;
}
8 changes: 7 additions & 1 deletion src/ConfigurationDefaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class ConfigurationDefaults

public const ENVIRONMENT = Environment::PRODUCTION;

public const BASIC_AUTH_USER_NAME = '';

public const BASIC_AUTH_PASSWORD = '';

/**
* @var array Associative list of all default configurations
*/
Expand All @@ -51,6 +55,8 @@ class ConfigurationDefaults
'httpStatusCodesToRetry' => self::HTTP_STATUS_CODES_TO_RETRY,
'httpMethodsToRetry' => self::HTTP_METHODS_TO_RETRY,
'serviceRefererName' => self::SERVICE_REFERER_NAME,
'environment' => self::ENVIRONMENT
'environment' => self::ENVIRONMENT,
'basicAuthUserName' => self::BASIC_AUTH_USER_NAME,
'basicAuthPassword' => self::BASIC_AUTH_PASSWORD
];
}
11 changes: 11 additions & 0 deletions src/ConfigurationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace PagarmeApiSDKLib;

use CoreInterfaces\Http\HttpConfigurations;
use PagarmeApiSDKLib\Authentication\BasicAuthCredentialsBuilder;

/**
* An interface for all configuration parameters required by the SDK.
Expand All @@ -27,6 +28,16 @@ public function getServiceRefererName(): string;
*/
public function getEnvironment(): string;

/**
* Get the credentials to use with BasicAuth
*/
public function getBasicAuthCredentials(): BasicAuthCredentials;

/**
* Get the credentials builder instance to update credentials for BasicAuth
*/
public function getBasicAuthCredentialsBuilder(): ?BasicAuthCredentialsBuilder;

/**
* Get the base uri for a given server in the current environment.
*
Expand Down
Loading

0 comments on commit 1b7b3b0

Please sign in to comment.