<?php
declare(strict_types=1);
/*
* This file is part of the league/commonmark package.
*
* (c) Colin O'Dell <colinodell@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace League\CommonMark\Util;
/**
* Array collection
*
* Provides a wrapper around a standard PHP array.
*
* @internal
*
* @phpstan-template T
* @phpstan-implements \IteratorAggregate<int, T>
* @phpstan-implements \ArrayAccess<int, T>
*/
final class ArrayCollection implements \IteratorAggregate, \Countable, \ArrayAccess
{
/**
* @var array<int, mixed>
* @phpstan-var array<int, T>
*/
private array $elements;
/**
* Constructor
*
* @param array<int|string, mixed> $elements
*
* @phpstan-param array<int, T> $elements
*/
public function __construct(array $elements = [])
{
$this->elements = $elements;
}
/**
* @return mixed|false
*
* @phpstan-return T|false
*/
public function first()
{
return \reset($this->elements);
}
/**
* @return mixed|false
*
* @phpstan-return T|false
*/
public function last()
{
return \end($this->elements);
}
/**
* Retrieve an external iterator
*
* @return \ArrayIterator<int, mixed>
*
* @phpstan-return \ArrayIterator<int, T>
*/
#[\ReturnTypeWillChange]
public function getIterator(): \ArrayIterator
{
return new \ArrayIterator($this->elements);
}
/**
* Count elements of an object
*
* @return int The count as an integer.
*/
public function count(): int
{
return \count($this->elements);
}
/**
* Whether an offset exists
*
* {@inheritDoc}
*
* @phpstan-param int $offset
*/
public function offsetExists($offset): bool
{
return \array_key_exists($offset, $this->elements);
}
/**
* Offset to retrieve
*
* {@inheritDoc}
*
* @phpstan-param int $offset
*
* @phpstan-return T|null
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return $this->elements[$offset] ?? null;
}
/**
* Offset to set
*
* {@inheritDoc}
*
* @phpstan-param int|null $offset
* @phpstan-param T $value
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value): void
{
if ($offset === null) {
$this->elements[] = $value;
} else {
$this->elements[$offset] = $value;
}
}
/**
* Offset to unset
*
* {@inheritDoc}
*
* @phpstan-param int $offset
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset): void
{
if (! \array_key_exists($offset, $this->elements)) {
return;
}
unset($this->elements[$offset]);
}
/**
* Returns a subset of the array
*
* @return array<int, mixed>
*
* @phpstan-return array<int, T>
*/
public function slice(int $offset, ?int $length = null): array
{
return \array_slice($this->elements, $offset, $length, true);
}
/**
* @return array<int, mixed>
*
* @phpstan-return array<int, T>
*/
public function toArray(): array
{
return $this->elements;
}
}
Get access token to initiates payment transaction.
generate-token
| Parameter | Type | Comments |
|---|---|---|
| client_id | string | Enter merchant API client/primary key |
| secret_id | string | Enter merchant API secret key |
| env | string | Enter merchant API environment |
| merchant_id | string | Enter merchant API merchant id |
Request Example (guzzle)
<?php
require_once('vendor/autoload.php');
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', $base_url. 'v1/generate-token', [
'headers' => [
'accept' => 'application/json',
'content-type' => 'application/json',
],
'form_params' => [
'client_id' => '$client_id',
'secret_id' => 'secret_id',
'env' => 'env',
'merchant_id' => 'merchant_id',
],
]);
echo $response->getBody();
**Response: SUCCESS (200 OK)**
{
"message": {
"success": [
"Successfully token is generated"
]
},
"data": {
"token":"eyJpdiI6InpkczhjTjhQdVhUL2lKQ0pSUUx6aUE9PSIsInZhbHVlIjoiVGVBTVBDTXltbjNZcEIvdEJveGpTSno3TU5NRUtnVkhCZ1pHTFNCUnZGQ2UxMnYxN202cEE1YVRDTEFsc0ZERExoTjdtL0dTL2xoU3QzeUJJOExiMUx5T0w1L0llUXhTUkU1cWVLWEdEbEplb0dKNXcwbTNRM0VxdkUwYzZuNFdtNkhMQ0pRZysyNWkvdzBxSlBoSVBSOGFTekNnR2RXNHVtcG9lMGZOTmNCcm1hR3c5Sk9KTnB4Y3ltZDl6cm90MThrR21Ca3B1azc3bXRiQ0J6SW96UVo1elNkU1ZqeE05bTcwWGp1MEUxWlJFdnNWTmpSbnVpeW92b2U4dXZkUGgyb1VmK0luaGdyaFlsVTZlcVpVRnZlTG1DeFF6Ykk2T2h6Z3JzbnIyNHpNdHowSE5JdDR0Y0pZT20zUm1XYW8iLCJtYWMiOiJlY2M4NGE1OGUzYzkzYzk0YzljNmVmNjE0YWI0ZDIwOGI3NDQ2YWEyY2ZhNzc0NzE4ZmY1ZmYyMz
IyZmQzNDY1IiwidGFnIjoiIn0=",
},
"type": "success"
}
**Response: ERROR (400 FAILED)**
{
"message": {
"error": [
"Invalid credentials."
]
},
"data": null,
"type": "error"
}