Skip to content

Commit

Permalink
Merge pull request #24 from tarfin-labs/iys-integration
Browse files Browse the repository at this point in the history
Iys integration
  • Loading branch information
tkaratug authored May 6, 2021
2 parents 437efd4 + 58b7a69 commit 3ce5366
Show file tree
Hide file tree
Showing 11 changed files with 610 additions and 7 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,24 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [7.3, 7.4]
php: [7.4]
laravel: [8.*]
dependency-version: [prefer-lowest, prefer-stable]

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}

steps:
- name: Checkout the code
uses: actions/checkout@v1
uses: actions/checkout@v2

- name: Disable Xdebug
run: sudo phpdismod xdebug
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: simplexml

- name: Install dependencies
run: composer install --no-progress --no-ansi --profile --no-interaction --no-scripts --no-suggest --prefer-dist
run: composer install --no-progress --no-ansi --profile --no-interaction --no-scripts --prefer-dist

- name: Execute tests
run: vendor/bin/phpunit --testdox --colors=always --exclude-group skipped
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to `netgsm` will be documented in this file

## Unreleased

## [4.0.0] - 2021-04-26

- IYS integration (add, search) added.

## [3.0.1] - 2020-10-08

- Upgrade packages for Laravel 8.
Expand Down
103 changes: 103 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ This package also provides some simple reporting.
- [Account Balance](#account-balance)
- [Remaining Balance](#remaining-balance)
- [Remaining Package Credits](#remaining-package-credits)
- [IYS Integration](#iys-integration)
- [Add Address](#add-address)
- [Search Address](#search-address)
- [Testing](#testing)
- [Security](#security)
- [Contributing](#contributing)
Expand Down Expand Up @@ -56,6 +59,7 @@ NETGSM_USER_CODE=
NETGSM_SECRET=
NETGSM_LANGUAGE=
NETGSM_HEADER=
NETGSM_BRANDCODE=
],
...
```
Expand Down Expand Up @@ -298,6 +302,105 @@ class Illuminate\Support\Collection#105 (1) {
}
```

### IYS Integration

With these services you can add and search any address to IYS.

#### Add Address

This service is used to add a phone number or email address to IYS using NetGsm IYS service.

##### Object Parameters

| Method | Description | Type | Required |
| --------------------- | ----------- | ---- | -------- |
| setRefId() | Reference id to query your request | String | No
| setType() | Communication type | String | Yes
| setSource() | Source of permission | String | Yes
| setRecipient() | phone number or email address | String | Yes
| setStatus() | Permission status | String | Yes
| setConsentDate() | Permission date | Datetime (YYYY-MM-DD H:i:s) | Yes
| setRecipientType() | Recipient type | String | Yes
| setRetailerCode() | Retailer code | Integer | No
| setRetailerAccess() | Retailer access | Integer | No

##### Usage

```php
$address = new \TarfinLabs\Netgsm\Iys\Requests\Add();
$address->setRefId(999999)
->setType('MESAJ')
->setSource('HS_WEB')
->setRecipient('+905XXXXXXXXX')
->setStatus('ONAY')
->setConsentDate(now()->toDateTimeString())
->setRecipientType('TACIR');

\TarfinLabs\Netgsm\Netgsm::iys()->addAddress($address)->send();
```

##### Response Parameters
```json
{
"code": "0",
"error": "false",
"uid": "73113cb9-dff0-415b-9491-xxxxxxxxxx"
}
```

#### Search Address

This service is used to search a phone number or email address on IYS using NetGsm IYS service.

##### Object Parameters

| Method | Description | Type | Required |
| --------------------- | ----------- | ---- | -------- |
| setType() | Communication type | String | Yes (if refId is set to null)
| setRecipient() | phone number or email address | String | Yes (if refId is set to null)
| setRecipientType() | Recipient type | String | Yes (if refId is set to null)
| setRefId() | Reference id to query your request | String | No

##### Usage

```php
$address = new \TarfinLabs\Netgsm\Iys\Requests\Search();
$address->setType('MESAJ')
->setRecipient('+905XXXXXXXXX')
->setRecipientType('TACIR')
->setRefId(999999);

\TarfinLabs\Netgsm\Netgsm::iys()->searchAddress($address)->send();
```

##### Response Parameters
* Response with a matched address.
```json
{
"code": "0",
"error": "false",
"query": {
"consentDate": "2020-11-06 11:22:34",
"source": "HS_FIZIKSEL_ORTAM",
"recipient": "+905XXXXXXXXX",
"recipientType": "BIREYSEL",
"type": "MESAJ",
"status": "ONAY",
"creationDate": "2020-11-06 11:23:49",
"retailerAccessCount": 0
// "querystatus": null
}
}
```

* Response without any matched address
```json
{
"code": "50",
"error": "Kayıt bulunamadi."
}
```

### Testing

``` bash
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
}
],
"require": {
"php": "^7.3",
"php": "^7.4",
"guzzlehttp/guzzle": "^7.1",
"illuminate/support": "^8.0",
"illuminate/notifications": "^8.0",
Expand All @@ -40,7 +40,7 @@
"ext-simplexml": "*"
},
"require-dev": {
"fzaninotto/faker": "^1.9",
"fakerphp/faker": "^1.14",
"phpunit/phpunit": "^9.4",
"mockery/mockery": "^1.4",
"orchestra/testbench": "^6.0"
Expand Down
1 change: 1 addition & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
'credentials' => [
'user_code' => env('NETGSM_USERCODE'),
'secret' => env('NETGSM_SECRET'),
'brand_code'=> env('NETGSM_BRANDCODE'),
],
'defaults' => [
'language' => env('NETGSM_LANGUAGE', 'tr'),
Expand Down
42 changes: 42 additions & 0 deletions src/Iys/AbstractNetgsmIys.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace TarfinLabs\Netgsm\Iys;

use TarfinLabs\Netgsm\NetgsmApiClient;

abstract class AbstractNetgsmIys extends NetgsmApiClient
{
protected string $url = '';

protected string $method = 'GET';

protected array $body = [];

/**
* Send request.
*
* @return string
*/
public function send(): string
{
$response = $this->client->request($this->method, $this->url, [
'headers' => [
'Content-Type' => 'application/json',
],
'json' => [
'header' => [
'username' => $this->credentials['user_code'],
'password' => $this->credentials['secret'],
'brandCode' => $this->credentials['brand_code'],
],
'body' => [
'data' => [
$this->body,
],
],
],
]);

return $response->getBody()->getContents();
}
}
39 changes: 39 additions & 0 deletions src/Iys/NetgsmIys.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace TarfinLabs\Netgsm\Iys;

use TarfinLabs\Netgsm\Iys\Requests\Add;
use TarfinLabs\Netgsm\Iys\Requests\Search;

class NetgsmIys extends AbstractNetgsmIys
{
/**
* Add address request.
*
* @param Add $request
* @return $this
*/
public function addAddress(Add $request): NetgsmIys
{
$this->url = $request->getUrl();
$this->body = $request->body();
$this->method = 'POST';

return $this;
}

/**
* Search address request.
*
* @param Search $request
* @return $this
*/
public function searchAddress(Search $request): NetgsmIys
{
$this->url = $request->getUrl();
$this->body = $request->body();
$this->method = 'POST';

return $this;
}
}
Loading

0 comments on commit 3ce5366

Please sign in to comment.