mirror of
https://github.com/anikeen-com/id.git
synced 2026-03-15 06:36:14 +00:00
refactored code
Signed-off-by: Maurice Preuß (envoyr) <hello@envoyr.com>
This commit is contained in:
230
README.md
230
README.md
@@ -4,16 +4,18 @@
|
||||
[](https://packagist.org/packages/anikeen/id)
|
||||
[](https://packagist.org/packages/anikeen/id)
|
||||
|
||||
PHP Anikeen ID API Client for Laravel 10+
|
||||
PHP Anikeen ID API Client for Laravel 11+
|
||||
|
||||
## Table of contents
|
||||
|
||||
1. [Installation](#installation)
|
||||
2. [Event Listener](#event-listener)
|
||||
3. [Configuration](#configuration)
|
||||
4. [Examples](#examples)
|
||||
5. [Documentation](#documentation)
|
||||
6. [Development](#Development)
|
||||
4. [Implementing Auth](#implementing-auth)
|
||||
5. [General](#general)
|
||||
6. [Examples](#examples)
|
||||
7. [Documentation](#documentation)
|
||||
8. [Development](#Development)
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -23,39 +25,22 @@ composer require anikeen/id
|
||||
|
||||
## Event Listener
|
||||
|
||||
- Add `SocialiteProviders\Manager\SocialiteWasCalled` event to your `listen[]` array in `app/Providers/EventServiceProvider`.
|
||||
- Add your listeners (i.e. the ones from the providers) to the `SocialiteProviders\Manager\SocialiteWasCalled[]` that you just created.
|
||||
- The listener that you add for this provider is `'Anikeen\\Id\\Socialite\\AnikeenIdExtendSocialite@handle',`.
|
||||
- Note: You do not need to add anything for the built-in socialite providers unless you override them with your own providers.
|
||||
In Laravel 11, the default EventServiceProvider provider was removed. Instead, add the listener using the listen method on the Event facade, in your `AppServiceProvider`
|
||||
|
||||
```
|
||||
/**
|
||||
* The event handler mappings for the application.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $listen = [
|
||||
\SocialiteProviders\Manager\SocialiteWasCalled::class => [
|
||||
// add your listeners (aka providers) here
|
||||
'Anikeen\\Id\\Socialite\\AnikeenIdExtendSocialite@handle',
|
||||
],
|
||||
];
|
||||
Event::listen(function (\SocialiteProviders\Manager\SocialiteWasCalled $event) {
|
||||
$event->extendSocialite('anikeen-id', \Anikeen\Id\Socialite\Provider::class);
|
||||
});
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
Copy configuration to config folder:
|
||||
|
||||
```
|
||||
$ php artisan vendor:publish --provider="Anikeen\Id\Providers\AnikeenIdServiceProvider"
|
||||
```
|
||||
|
||||
Add environmental variables to your `.env`
|
||||
|
||||
```
|
||||
ANIKEEN_ID_KEY=
|
||||
ANIKEEN_ID_SECRET=
|
||||
ANIKEEN_ID_REDIRECT_URI=http://localhost
|
||||
ANIKEEN_ID_CALLBACK_URL=http://localhost/auth/callback
|
||||
```
|
||||
|
||||
You will need to add an entry to the services configuration file so that after config files are cached for usage in production environment (Laravel command `artisan config:cache`) all config is still available.
|
||||
@@ -63,13 +48,20 @@ You will need to add an entry to the services configuration file so that after c
|
||||
**Add to `config/services.php`:**
|
||||
|
||||
```php
|
||||
'anikeen-id' => [
|
||||
'anikeen' => [
|
||||
'client_id' => env('ANIKEEN_ID_KEY'),
|
||||
'client_secret' => env('ANIKEEN_ID_SECRET'),
|
||||
'redirect' => env('ANIKEEN_ID_REDIRECT_URI')
|
||||
'redirect' => env('ANIKEEN_ID_CALLBACK_URL'),
|
||||
'base_url' => env('ANIKEEN_ID_BASE_URL'),
|
||||
],
|
||||
```
|
||||
|
||||
```php
|
||||
$middleware->web(append: [
|
||||
\Anikeen\Id\Http\Middleware\CreateFreshApiToken::class,
|
||||
]);
|
||||
```
|
||||
|
||||
## Implementing Auth
|
||||
|
||||
This method should typically be called in the `boot` method of your `AuthServiceProvider` class:
|
||||
@@ -132,30 +124,9 @@ reference the provider in the `providers` configuration of your `auth.php` confi
|
||||
],
|
||||
```
|
||||
|
||||
## Examples
|
||||
## General
|
||||
|
||||
#### Basic
|
||||
|
||||
```php
|
||||
$anikeenId = new Anikeen\IdAnikeenId();
|
||||
|
||||
$anikeenId->setClientId('abc123');
|
||||
|
||||
// Get SSH Key by User ID
|
||||
$result = $anikeenId->getSshKeysByUserId(38);
|
||||
|
||||
// Check, if the query was successfull
|
||||
if ( ! $result->success()) {
|
||||
die('Ooops: ' . $result->error());
|
||||
}
|
||||
|
||||
// Shift result to get single key data
|
||||
$sshKey = $result->shift();
|
||||
|
||||
echo $sshKey->name;
|
||||
```
|
||||
|
||||
#### Setters
|
||||
#### Setters and Getters
|
||||
|
||||
```php
|
||||
$anikeenId = new Anikeen\Id\AnikeenId();
|
||||
@@ -169,6 +140,72 @@ $anikeenId = $anikeenId->withClientSecret('abc123');
|
||||
$anikeenId = $anikeenId->withToken('abcdef123456');
|
||||
```
|
||||
|
||||
#### Error handling for an unsuccessful query:
|
||||
|
||||
```php
|
||||
$result = $anikeenId->sshKeysByUserId('someInvalidId');
|
||||
|
||||
// Check, if the query was successfully
|
||||
if (!$result->success()) {
|
||||
die('Ooops: ' . $result->error());
|
||||
}
|
||||
```
|
||||
|
||||
#### Shift result to get single key data:
|
||||
|
||||
```php
|
||||
$result = $anikeenId->sshKeysByUserId('someValidId');
|
||||
|
||||
$sshKey = $result->shift();
|
||||
|
||||
echo $sshKey->name;
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
#### Get User SSH Key
|
||||
|
||||
```php
|
||||
$anikeenId = new Anikeen\IdAnikeenId();
|
||||
|
||||
$anikeenId->setClientId('abc123');
|
||||
|
||||
// Get SSH Key by User ID
|
||||
$result = $anikeenId->sshKeysByUserId('someValidId');
|
||||
|
||||
// Check, if the query was successfully
|
||||
if (!$result->success()) {
|
||||
die('Ooops: ' . $result->error());
|
||||
}
|
||||
|
||||
// Shift result to get single key data
|
||||
$sshKey = $result->shift();
|
||||
|
||||
echo $sshKey->name;
|
||||
```
|
||||
|
||||
#### Create Order Preview
|
||||
|
||||
```php
|
||||
$anikeenId = new \Anikeen\Id\AnikeenId();
|
||||
|
||||
// Create new Order Preview
|
||||
$result = $anikeenId->createOrderPreview([
|
||||
'country_iso' => 'de',
|
||||
'items' => [
|
||||
[
|
||||
'type' => 'physical',
|
||||
'name' => 'Test',
|
||||
'price' => 2.99,
|
||||
'unit' => 'onetime',
|
||||
'units' => 1,
|
||||
]
|
||||
]
|
||||
])->shift();
|
||||
|
||||
echo $preview->gross_total;
|
||||
```
|
||||
|
||||
#### OAuth Tokens
|
||||
|
||||
```php
|
||||
@@ -202,52 +239,109 @@ AnikeenId::withClientId('abc123')->withToken('abcdef123456')->getAuthedUser();
|
||||
|
||||
## Documentation
|
||||
|
||||
## AnikeenId
|
||||
|
||||
### Oauth
|
||||
|
||||
```php
|
||||
public function retrievingToken(string $grantType, array $attributes)
|
||||
public function retrievingToken(string $grantType, array $attributes): Result
|
||||
```
|
||||
|
||||
### SshKeys
|
||||
### ManagesPricing
|
||||
|
||||
```php
|
||||
public function getSshKeysByUserId(int $id)
|
||||
public function createSshKey(string $publicKey, string $name = NULL)
|
||||
public function deleteSshKey(int $id)
|
||||
public function createOrderPreview(array $attributes = []): Result
|
||||
```
|
||||
|
||||
### Users
|
||||
### ManagesSshKeys
|
||||
|
||||
```php
|
||||
public function getAuthedUser()
|
||||
public function createUser(array $parameters)
|
||||
public function isEmailExisting(string $email)
|
||||
public function sshKeysByUserId(string $sskKeyId): Result
|
||||
public function createSshKey(string $publicKey, ?string $name = null): Result
|
||||
public function deleteSshKey(int $sshKeyId): Result
|
||||
```
|
||||
|
||||
### Delete
|
||||
### ManagesUsers
|
||||
|
||||
```php
|
||||
|
||||
public function getAuthedUser(): Result
|
||||
public function createUser(array $attributes): Result
|
||||
public function isEmailExisting(string $email): Result
|
||||
```
|
||||
|
||||
### Get
|
||||
|
||||
## Billable
|
||||
|
||||
### ManagesBalance
|
||||
|
||||
```php
|
||||
|
||||
public function balance(): float
|
||||
public function charges(): float
|
||||
public function charge(float $amount, string $paymentMethodId, array $options = []): Result
|
||||
```
|
||||
|
||||
### Post
|
||||
### ManagesInvoices
|
||||
|
||||
```php
|
||||
|
||||
public function invoices(): Result
|
||||
public function invoice(string $invoiceId): Result
|
||||
public function getInvoiceDownloadUrl(string $invoiceId): string
|
||||
```
|
||||
|
||||
### Put
|
||||
### ManagesOrders
|
||||
|
||||
```php
|
||||
|
||||
public function orders(): Result
|
||||
public function createOrder(array $attributes = []): Result
|
||||
public function order(string $orderId): Result
|
||||
public function updateOrder(string $orderId, array $attributes = []): Result
|
||||
public function checkoutOrder(string $orderId): Result
|
||||
public function revokeOrder(string $orderId): Result
|
||||
public function deleteOrder(string $orderId): Result
|
||||
public function orderItems(string $orderId): Result
|
||||
public function createOrderItem(string $orderId, array $attributes = []): Result
|
||||
public function orderItem(string $orderId, string $orderItemId): Result
|
||||
public function updateOrderItem(string $orderId, string $orderItemId, array $attributes = []): Result
|
||||
public function deleteOrderItem(string $orderId, string $orderItemId): Result
|
||||
```
|
||||
|
||||
### ManagesPaymentMethods
|
||||
|
||||
```php
|
||||
public function hasPaymentMethod(): bool
|
||||
public function paymentMethods(): Result
|
||||
public function hasDefaultPaymentMethod(): bool
|
||||
public function defaultPaymentMethod(): Result
|
||||
public function billingPortalUrl(string $returnUrl, array $options): string
|
||||
public function createSetupIntent(array $options = []): Result
|
||||
```
|
||||
|
||||
### ManagesSubscriptions
|
||||
|
||||
```php
|
||||
public function subscriptions(): Result
|
||||
public function subscription(string $subscriptionId): Result
|
||||
public function createSubscription(array $attributes): Result
|
||||
public function checkoutSubscription(string $subscriptionId): Result
|
||||
public function revokeSubscription(string $subscriptionId): Result
|
||||
public function resumeSubscription(string $subscriptionId): Result
|
||||
```
|
||||
|
||||
### ManagesTaxation
|
||||
|
||||
```php
|
||||
public function vat(): float
|
||||
```
|
||||
|
||||
### ManagesTransactions
|
||||
|
||||
```php
|
||||
public function transactions(): Result
|
||||
public function createTransaction(array $attributes = []): Result
|
||||
public function transaction(string $transactionId): Result
|
||||
```
|
||||
|
||||
|
||||
[**OAuth Scopes Enums**](https://github.com/anikeen-com/id/blob/main/src/Enums/Scope.php)
|
||||
|
||||
## Development
|
||||
|
||||
Reference in New Issue
Block a user