Skip to content

Commit

Permalink
Merge branch 'main' into feature/proactive-connect
Browse files Browse the repository at this point in the history
  • Loading branch information
SecondeJK committed Jun 28, 2023
2 parents 7c664d8 + 8e9f239 commit ea2ddc1
Show file tree
Hide file tree
Showing 43 changed files with 2,363 additions and 134 deletions.
223 changes: 192 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,21 @@ foreach($response as $index => $data){

The [send example][send_example] also has full working examples.

### Detecting Encoding Type

You can use a static `isGsm7()` method within the SMS Client code to determine whether to send the message using
GSM-7 encoding or Unicode. Here is an example:

```php
$sms = new \Vonage\SMS\Message\SMS('123', '456', 'is this gsm7?');

if (Vonage\SMS\Message\SMS::isGsm7($text)) {
$sms->setType('text');
} else {
$sms->setType('unicode');
}
```

### Receiving a Message

Inbound messages are [sent to your application as a webhook][doc_inbound]. The Client library provides a way to
Expand Down Expand Up @@ -228,9 +243,9 @@ $viberImage = new Vonage\Messages\Channel\Viber\ViberImage(
$client->messages()->send($viberImage);
```

## Verify Examples (v1)
### Verify Examples (v1)

### Starting a Verification
#### Starting a Verification

Vonage's [Verify API][doc_verify] makes it easy to prove that a user has provided their own phone number during signup,
or implement second factor authentication during sign in.
Expand All @@ -245,7 +260,7 @@ echo "Started verification with an id of: " . $response->getRequestId();

Once the user inputs the pin code they received, call the `check()` method (see below) with the request ID and the PIN to confirm the PIN is correct.

### Controlling a Verification
#### Controlling a Verification

To cancel an in-progress verification, or to trigger the next attempt to send the confirmation code, you can pass
either an existing verification object to the client library, or simply use a request ID:
Expand All @@ -255,7 +270,7 @@ $client->verify()->trigger('00e6c3377e5348cdaf567e1417c707a5');
$client->verify()->cancel('00e6c3377e5348cdaf567e1417c707a5');
```

### Checking a Verification
#### Checking a Verification

In the same way, checking a verification requires the PIN the user provided, and the request ID:

Expand All @@ -269,7 +284,7 @@ try {
}
```

### Searching For a Verification
#### Searching For a Verification

You can check the status of a verification, or access the results of past verifications using a request ID.
The verification object will then provide a rich interface:
Expand All @@ -283,7 +298,7 @@ foreach($verification->getChecks() as $check){
}
```

### Payment Verification
#### Payment Verification

Vonage's [Verify API][doc_verify] has SCA (Secure Customer Authentication) support, required by the PSD2 (Payment Services Directive) and used by applications that need to get confirmation from customers for payments. It includes the payee and the amount in the message.

Expand All @@ -297,9 +312,9 @@ echo "Started verification with an id of: " . $response['request_id'];

Once the user inputs the pin code they received, call the `/check` endpoint with the request ID and the pin to confirm the pin is correct.

## Verify Examples (v2)
### Verify Examples (v2)

### Starting a Verification
#### Starting a Verification

Vonage's Verify v2 relies more on asynchronous workflows via. webhooks, and more customisable Verification
workflows to the developer. To start a verification, you'll need the API client, which is under the namespace
Expand Down Expand Up @@ -348,7 +363,7 @@ The base request types are as follows:
For adding workflows, you can see the available valid workflows as constants within the `VerificationWorkflow` object.
For a better developer experience, you can't create an invalid workflow due to the validation that happens on the object.

### Check a submitted code
#### Check a submitted code

To submit a code, you'll need to surround the method in a try/catch due to the nature of the API. If the code is correct,
the method will return a `true` boolean. If it fails, it will throw the relevant Exception from the API that will need to
Expand All @@ -363,7 +378,7 @@ try {
}
```

### Webhooks
#### Webhooks

As events happen during a verification workflow, events and updates will fired as webhooks. Incoming server requests that conform to
PSR-7 standards can be hydrated into a webhook value object for nicer interactions. You can also hydrate
Expand All @@ -383,8 +398,16 @@ $verificationEvent = \Vonage\Verify2\Webhook\Factory::createFromArray($payload);
var_dump($verificationEvent->getStatus());
```

#### Cancelling a request in-flight

You can cancel a request should you need to, before the end user has taken any action.

```php
$requestId = 'c11236f4-00bf-4b89-84ba-88b25df97315';
$client->verify2()->cancel($requestId);
```

### Making a Call
#### Making a Call

All `$client->voice()` methods require the client to be constructed with a `Vonage\Client\Credentials\Keypair`, or a
`Vonage\Client\Credentials\Container` that includes the `Keypair` credentials:
Expand Down Expand Up @@ -884,28 +907,166 @@ try {

Check out the [documentation](https://developer.nexmo.com/number-insight/code-snippets/number-insight-advanced-async-callback) for what to expect in the incoming webhook containing the data you requested.

### Subaccount Examples

This API is used to create and configure subaccounts related to your primary account and transfer credit, balances and bought numbers between accounts.
The subaccounts API is disabled by default. If you want to use subaccounts, [contact support](https://api.support.vonage.com) to have the API enabled on your account.

#### Get a list of Subaccounts

```php
$client = new \Vonage\Client(new \Vonage\Client\Credentials\Basic(API_KEY, API_SECRET));
$apiKey = '34kokdf';
$subaccounts = $client->subaccount()->getSubaccounts($apiKey);
var_dump($subaccounts);
```

#### Create a Subaccount

```php
$client = new \Vonage\Client(new \Vonage\Client\Credentials\Basic(API_KEY, API_SECRET));

$apiKey = 'acc6111f';

$payload = [
'name' => 'sub name',
'secret' => 's5r3fds',
'use_primary_account_balance' => false
];

$account = new Account();
$account->fromArray($payload);

$response = $client->subaccount()->createSubaccount($apiKey, $account);
var_dump($response);
```

#### Get a Subaccount

```php
$client = new \Vonage\Client(new \Vonage\Client\Credentials\Basic(API_KEY, API_SECRET));

$apiKey = 'acc6111f';
$subaccountKey = 'bbe6222f';

$response = $client->subaccount()->getSubaccount($apiKey, $subaccountKey);
var_dump($response);
```

#### Update a Subaccount

```php
$client = new \Vonage\Client(new \Vonage\Client\Credentials\Basic(API_KEY, API_SECRET));

$apiKey = 'acc6111f';
$subaccountKey = 'bbe6222f';

$payload = [
'suspended' => true,
'use_primary_account_balance' => false,
'name' => 'Subaccount department B'
];

$account = new Account();
$account->fromArray($payload);

$response = $client->subaccount()->updateSubaccount($apiKey, $subaccountKey, $account)
var_dump($response);
```

#### Get a list of Credit Transfers

```php
$client = new \Vonage\Client(new \Vonage\Client\Credentials\Basic(API_KEY, API_SECRET));

$apiKey = 'acc6111f';
$filter = new Vonage\Subaccount\Filter\Subaccount(['subaccount' => '35wsf5'])
$transfers = $client->subaccount()->getCreditTransfers($apiKey);
var_dump($transfers);
```

#### Transfer Credit between accounts

```php
$client = new \Vonage\Client(new \Vonage\Client\Credentials\Basic(API_KEY, API_SECRET));

$apiKey = 'acc6111f';

$transferRequest = (new TransferCreditRequest($apiKey))
->setFrom('acc6111f')
->setTo('s5r3fds')
->setAmount('123.45')
->setReference('this is a credit transfer');

$response = $this->subaccountClient->makeCreditTransfer($transferRequest);
```

#### Get a list of Balance Transfers

```php
$client = new \Vonage\Client(new \Vonage\Client\Credentials\Basic(API_KEY, API_SECRET));
$apiKey = 'acc6111f';

$filter = new \Vonage\Subaccount\Filter\Subaccount(['end_date' => '2022-10-02']);
$transfers = $client->subaccount()->getBalanceTransfers($apiKey, $filter);
```

#### Transfer Balance between accounts

```php
$client = new \Vonage\Client(new \Vonage\Client\Credentials\Basic(API_KEY, API_SECRET));

$apiKey = 'acc6111f';

$transferRequest = (new TransferBalanceRequest($apiKey))
->setFrom('acc6111f')
->setTo('s5r3fds')
->setAmount('123.45')
->setReference('this is a credit transfer');

$response = $client->subaccount()->makeBalanceTransfer($transferRequest);
var_dump($response);
```

#### Transfer a Phone Number between accounts

```php
$client = new \Vonage\Client(new \Vonage\Client\Credentials\Basic(API_KEY, API_SECRET));
$apiKey = 'acc6111f';

$numberTransferRequest = (new NumberTransferRequest($apiKey))
->setFrom('acc6111f')
->setTo('s5r3fds')
->setNumber('4477705478484')
->setCountry('GB');

$response = $client->subaccount()->makeNumberTransfer($numberTransferRequest);
var_dump($response);
```

## Supported APIs

| API | API Release Status | Supported?
|------------------------|:--------------------:|:-------------:|
| Account API | General Availability ||
| Alerts API | General Availability ||
| Application API | General Availability ||
| Audit API | Beta ||
| Conversation API | Beta ||
| Dispatch API | Beta ||
| External Accounts API | Beta ||
| Media API | Beta ||
| Messages API | General Availability ||
| Number Insight API | General Availability ||
| Number Management API | General Availability ||
| Pricing API | General Availability ||
| Redact API | General Availability ||
| Reports API | Beta ||
| SMS API | General Availability ||
| Verify API | General Availability ||
| Verify API (Version 2) | Beta ||
| Voice API | General Availability ||
| API | API Release Status | Supported?
|------------------------|:--------------------:|:----------:|
| Account API | General Availability ||
| Alerts API | General Availability ||
| Application API | General Availability ||
| Audit API | Beta ||
| Conversation API | Beta ||
| Dispatch API | Beta ||
| External Accounts API | Beta ||
| Media API | Beta ||
| Messages API | General Availability ||
| Number Insight API | General Availability ||
| Number Management API | General Availability ||
| Pricing API | General Availability ||
| Redact API | General Availability ||
| Reports API | Beta ||
| SMS API | General Availability ||
| Subaccounts API | General Availability ||
| Verify API | General Availability ||
| Verify API (Version 2) | Beta ||
| Voice API | General Availability ||

## Troubleshooting

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"require": {
"php": "~8.0 || ~8.1 || ~8.2",
"ext-mbstring": "*",
"laminas/laminas-diactoros": "^2.21",
"laminas/laminas-diactoros": "^3.0",
"lcobucci/jwt": "^3.4|^4.0",
"psr/container": "^1.0 | ^2.0",
"psr/http-client-implementation": "^1.0",
Expand Down
11 changes: 11 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@
</testsuite>
<testsuite name="proactive_connect">
<directory>test/ProactiveConnect</directory>
<testsuite name="voice">
<directory>test/Voice</directory>
</testsuite>
<testsuite name="messages">
<directory>test/Messages</directory>
</testsuite>
<testsuite name="sms">
<directory>test/SMS</directory>
</testsuite>
<testsuite name="subaccount">
<directory>test/Subaccount</directory>
</testsuite>
</testsuites>
<php>
Expand Down
5 changes: 4 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
use Vonage\Redact\ClientFactory as RedactClientFactory;
use Vonage\Secrets\ClientFactory as SecretsClientFactory;
use Vonage\SMS\ClientFactory as SMSClientFactory;
use Vonage\Subaccount\ClientFactory as SubaccountClientFactory;
use Vonage\Messages\ClientFactory as MessagesClientFactory;
use Vonage\Verify\ClientFactory as VerifyClientFactory;
use Vonage\Verify2\ClientFactory as Verify2ClientFactory;
Expand Down Expand Up @@ -81,6 +82,7 @@
* @method Redact\Client redact()
* @method Secrets\Client secrets()
* @method SMS\Client sms()
* @method Subaccount\Client subaccount()
* @method Verify\Client verify()
* @method Verify2\Client verify2()
* @method Voice\Client voice()
Expand Down Expand Up @@ -218,6 +220,7 @@ public function __construct(
'redact' => RedactClientFactory::class,
'secrets' => SecretsClientFactory::class,
'sms' => SMSClientFactory::class,
'subaccount' => SubaccountClientFactory::class,
'verify' => VerifyClientFactory::class,
'verify2' => Verify2ClientFactory::class,
'voice' => VoiceClientFactory::class,
Expand Down Expand Up @@ -475,7 +478,7 @@ public function send(RequestInterface $request): ResponseInterface
$response = $this->client->sendRequest($request);

if ($this->debug) {
$id = uniqid();
$id = uniqid('', true);
$request->getBody()->rewind();
$response->getBody()->rewind();
$this->log(
Expand Down
7 changes: 6 additions & 1 deletion src/Client/APIResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,15 @@ public function delete(string $id, array $headers = []): ?array
* @throws ClientExceptionInterface
* @throws Exception\Exception
*/
public function get($id, array $query = [], array $headers = [], bool $jsonResponse = true)
public function get($id, array $query = [], array $headers = [], bool $jsonResponse = true, bool $uriOverride = false)
{
$uri = $this->getBaseUrl() . $this->baseUri . '/' . $id;

// This is a necessary hack if you want to fetch a totally different URL but use Vonage Auth
if ($uriOverride) {
$uri = $id;
}

if (!empty($query)) {
$uri .= '?' . http_build_query($query);
}
Expand Down
Loading

0 comments on commit ea2ddc1

Please sign in to comment.