Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Enver Cigal committed Apr 20, 2022
0 parents commit 5ed0f04
Show file tree
Hide file tree
Showing 23 changed files with 1,396 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/vendor/
/.idea/
.phpunit.result.cache
composer.lock
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Macellan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
159 changes: 159 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
## Contents

- [Installation](#installation)
- [Setting up the Iys service](#setting-up-the-IYS-service)
- [Enums](#enums)
- [Usage](#usage)
- [Testing](#testing)
- [License](#license)

## Installation

You can install this package via composer:

``` bash
composer require macellan/iys
```

### Setting up the IYS service

Add your IYS login to your config/services.php:

```php
// config/services.php
...
'iys' => [
'username' => env('IYS_USERNAME', ''),
'password' => env('IYS_PASSWORD', ''),
'iys_code' => env('IYS_CODE', ''),
'brand_code' => env('IYS_BRAND_CODE', ''),
'url' => env('IYS_URL', ''),
],
...
```

## Enums

IYS consent source types:

```php
enum ConsentSourceTypes: string
{
case PHYSICAL = 'HS_FIZIKSEL_ORTAM';
case WET_SIGNATURE = 'HS_ISLAK_IMZA';
case WEB = 'HS_WEB';
case CALL_CENTER = 'HS_CAGRI_MERKEZI';
case SOCIAL_MEDIA = 'HS_SOSYAL_MEDYA';
case EMAIL = 'HS_EPOSTA';
case MESSAGE = 'HS_MESAJ';
case MOBILE = 'HS_MOBIL';
case HS_EORTAM = 'HS_EORTAM';
case ACTIVITY = 'HS_ETKINLIK';
case HS_2015 = 'HS_2015';
case HS_ATM = 'HS_ATM';
case HS_DECISION = 'HS_KARAR';
}
```

IYS permission types:

```php
enum PermissionTypes: string
{
case CALL = 'ARAMA';
case MESSAGE = 'MESAJ';
case EMAIL = 'EPOSTA';
}
```

IYS recipient types:

```php
enum RecipientTypes: string
{
case INDIVIDUAL = 'BIREYSEL';
case TRADER = 'TACIR';
}
```

IYS source types:

```php
enum SourceTypes: string
{
case HS = 'HS';
case IYS = 'IYS';
}
```

IYS status types:

```php
enum StatusTypes: string
{
case APPROVE = 'ONAY';
case REJECT = 'RET';
}
```

## Usage

**NOTE:**
Authentication token is generated per UserManager instance. Expire time is two hour.

With the usage in this example, you can submit a single release. This method works with the "Permission" model

```php
IysManager::make()->createPermissionDriver()->sendSinglePermission(
Permission::make()
->setConsentDate('2022-02-10 09:50:02')
->setSource(ConsentSourceTypes::MOBILE)
->setRecipient('[email protected]')
->setRecipientType(RecipientTypes::INDIVIDUAL)
->setStatus(StatusTypes::APPROVE)
->setType(PermissionTypes::EMAIL)
);
```

You can send permissions by filling out the permission list model. The permission list model is the permission model array.

```php
$permissionList = PermissionList::make()
->addPermission($permission
->setConsentDate('2022-02-10 09:50:02')
->setRecipient('[email protected]')
->setStatus(StatusTypes::APPROVE)
->setType(PermissionTypes::EMAIL))
->setSource(ConsentSourceTypes::MOBILE)
->setRecipientType(RecipientTypes::INDIVIDUAL);
->addPermission($permission
->setConsentDate('2022-02-10 09:50:03')
->setRecipient('[email protected]')
->setStatus(StatusTypes::REJECT)
->setType(PermissionTypes::MESSAGE));
->setSource(ConsentSourceTypes::MOBILE)
->setRecipientType(RecipientTypes::INDIVIDUAL);

IysManager::make()->createPermissionDriver()->sendPermissions($permissionList);
```

You can get send permission information with request id

```php
IysManager::make()->createPermissionDriver()->getPermissionsStatus('request_id');
```
You can get changed permission by IYS

```php
IysManager::make()->createPermissionDriver()->getChangedPermissions();
```

## Testing

``` bash
composer test
```

## License

The MIT License (MIT). Please see [License File](LICENSE) for more information.
48 changes: 48 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "macellan/iys",
"description": "Iys library for Laravel",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Enver Cigal",
"email": "[email protected]"
}
],
"require": {
"php": ">=8.1",
"ext-json": "*",
"guzzlehttp/guzzle": "^7.2|^7.0.1",
"illuminate/http": "^8.0 || ^9.0",
"illuminate/support": "^8.0 || ^9.0"
},
"require-dev": {
"mockery/mockery": "^1.4.4",
"orchestra/testbench": "^7.1",
"phpunit/phpunit": "^9.5.10",
"squizlabs/php_codesniffer": "^3.6"
},
"autoload": {
"psr-4": {
"Macellan\\Iys\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Macellan\\Iys\\Tests\\": "tests"
}
},
"scripts": {
"test": "vendor/bin/phpunit",
"check-style": "phpcs -p --standard=PSR12 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests",
"fix-style": "phpcbf -p --standard=PSR12 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 src tests"
},
"config": {
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": false
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
22 changes: 22 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
>
<testsuites>
<testsuite name="Laravel Iys Library Test Suite">
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
<php>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
</php>
</phpunit>
42 changes: 42 additions & 0 deletions src/Auth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Macellan\Iys;

use Illuminate\Http\Client\RequestException;
use Illuminate\Support\Facades\Http;
use Macellan\Iys\Enums\Config;

class Auth
{
private int $timeout = 10;

private string $username;

private string $password;

private string $endPoint;

public function __construct(array $config)
{
$this->username = $config[Config::USERNAME->value];

$this->password = $config[Config::PASSWORD->value];

$this->endPoint = $config[Config::URL->value] . '/oauth2/token';
}

/**
* @throws RequestException
*/
public function login()
{
return Http::timeout($this->timeout)
->asJson()->acceptJson()
->post($this->endPoint, [
'username' => $this->username,
'password' => $this->password,
'grant_type' => 'password',
])
->throw();
}
}
27 changes: 27 additions & 0 deletions src/Drivers/AbstractDriver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Macellan\Iys\Drivers;

use Macellan\Iys\Enums\Config;

abstract class AbstractDriver
{
protected string $branchCode;

protected string $iysCode;

protected string $bearer;

protected string $baseUrl;

public function __construct(array $config, string $bearer)
{
$this->branchCode = $config[Config::BRAND_CODE->value];

$this->iysCode = $config[Config::IYS_CODE->value];

$this->baseUrl = $config[Config::URL->value];

$this->bearer = $bearer;
}
}
20 changes: 20 additions & 0 deletions src/Drivers/Permission/Enums/ConsentSourceTypes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Macellan\Iys\Drivers\Permission\Enums;

enum ConsentSourceTypes: string
{
case PHYSICAL = 'HS_FIZIKSEL_ORTAM';
case WET_SIGNATURE = 'HS_ISLAK_IMZA';
case WEB = 'HS_WEB';
case CALL_CENTER = 'HS_CAGRI_MERKEZI';
case SOCIAL_MEDIA = 'HS_SOSYAL_MEDYA';
case EMAIL = 'HS_EPOSTA';
case MESSAGE = 'HS_MESAJ';
case MOBILE = 'HS_MOBIL';
case HS_EORTAM = 'HS_EORTAM';
case ACTIVITY = 'HS_ETKINLIK';
case HS_2015 = 'HS_2015';
case HS_ATM = 'HS_ATM';
case HS_DECISION = 'HS_KARAR';
}
10 changes: 10 additions & 0 deletions src/Drivers/Permission/Enums/PermissionTypes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Macellan\Iys\Drivers\Permission\Enums;

enum PermissionTypes: string
{
case CALL = 'ARAMA';
case MESSAGE = 'MESAJ';
case EMAIL = 'EPOSTA';
}
9 changes: 9 additions & 0 deletions src/Drivers/Permission/Enums/RecipientTypes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Macellan\Iys\Drivers\Permission\Enums;

enum RecipientTypes: string
{
case INDIVIDUAL = 'BIREYSEL';
case TRADER = 'TACIR';
}
9 changes: 9 additions & 0 deletions src/Drivers/Permission/Enums/SourceTypes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Macellan\Iys\Drivers\Permission\Enums;

enum SourceTypes: string
{
case HS = 'HS';
case IYS = 'IYS';
}
9 changes: 9 additions & 0 deletions src/Drivers/Permission/Enums/StatusTypes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Macellan\Iys\Drivers\Permission\Enums;

enum StatusTypes: string
{
case APPROVE = 'ONAY';
case REJECT = 'RET';
}
Loading

0 comments on commit 5ed0f04

Please sign in to comment.