## Composer

The easiest way to install [bulkgate/php-sdk](https://packagist.org/packages/bulkgate/php-sdk) into a project is by using [Composer](https://getcomposer.org/) via the command line.

```
composer require bulkgate/php-sdk
```

## Nette DI Extension

You can also use DI container to install this SDK

```yaml
extensions:
	sdk: BulkGate\Sdk\DI\Extension

sdk:
	application_id: 451
	application_token: NKN02TWE6NfBkfl-your-secret-token-Wf05GaqLIWLW4aBj
	sender:
		tag: 'sdk' # Optional
		default_country: cz # Optional
	configurator:
		sms: # Optional
			sender_id: gText
			sender_id_value: 'Example'
			unicode: true
		viber: # Optional
			sender: Sender
			button:
				caption: 'Button Caption'
				url: 'https://www.bulkgate.com/'
			image: 
				url: 'https://www.example.com/example.png'
				zoom: true
			expiration: 3600 # seconds
```

```php

use BulkGate\Sdk\Sender;
use BulkGate\Sdk\Message\Sms;

class Sdk
{
    private Sender $sender;

    public function __construct(Sender $sender)
    {
        $this->sender = $sender;
    }
    

    public function sendMessage(string $phone_number, string $text): void
    {    
        $this->sender->send(new Sms($phone_number, $text));
    }
}

```

By default `application_id` and `application_token` are enough; the remaining
options have default values. On top of those you can set:

| Option | Default | Meaning |
|:--|:--|:--|
| `application_product` | `nette` | Product identification in the requests |
| `connection.api` | `https://portal.bulkgate.com/api/1.0/integration` | API address |
| `connection.content_type` | `application/json` | Request content type |
| `configurator.sms.country` | — | Per-country routes; with it `SmsCountryConfigurator` is used instead of `SmsConfigurator` |

```yaml
sdk:
	configurator:
		sms:
			country:
				cz:
					gate: gGate2
					sender: 'BulkGate'
```

For Viber the `sender` is required, and so are `button.url` and `image.url` once
you include the matching section.

Besides the sender, the extension also registers the
[`BulkGate\Sdk\NumberChecker` and `BulkGate\Sdk\CreditChecker`](https://www.bulkgate.com/en/docs/php-sdk/php-sdk-number-checker/2.0/)
services, so you can have them injected through a constructor.

### Manual creation

```php
use BulkGate\Sdk\Connection\ConnectionStream;
use BulkGate\Sdk\MessageSender;
use BulkGate\Sdk\Message\Sms;

$connection = new ConnectionStream(
    /*application_id: */ 451, 
    /*application_token:*/ 'NKN02TWE6NfBkfl-your-secret-token-Wf05GaqLIWLW4aBj'
);

$sender = new MessageSender($connection);

$sender->send(new Sms($phone_number, $text));

/* Optional */

$sender->setTag('sdk');

$sender->setDefaultCountry('cz');

$viber_configurator = new ViberConfigurator('Sender');
$viber_configurator->button('Button Caption', 'https://www.bulkgate.com/');
$viber_configurator->image('https://www.example.com/example.png', true);
$viber_configurator->expiration(3_600);

$sender->addSenderConfigurator($viber_configurator);

$sms_configurator = new SmsConfigurator('gText', 'Example', true);

$sender->addSenderConfigurator($sms_configurator);

$sender->send(new Sms($phone_number, $text));
```

