<?php
namespace PhpOffice\PhpSpreadsheet\Worksheet;
use Iterator as NativeIterator;
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
/**
* @implements NativeIterator<int, Row>
*/
class RowIterator implements NativeIterator
{
/**
* Worksheet to iterate.
*
* @var Worksheet
*/
private $subject;
/**
* Current iterator position.
*
* @var int
*/
private $position = 1;
/**
* Start position.
*
* @var int
*/
private $startRow = 1;
/**
* End position.
*
* @var int
*/
private $endRow = 1;
/**
* Create a new row iterator.
*
* @param Worksheet $subject The worksheet to iterate over
* @param int $startRow The row number at which to start iterating
* @param int $endRow Optionally, the row number at which to stop iterating
*/
public function __construct(Worksheet $subject, $startRow = 1, $endRow = null)
{
// Set subject
$this->subject = $subject;
$this->resetEnd($endRow);
$this->resetStart($startRow);
}
public function __destruct()
{
$this->subject = null; // @phpstan-ignore-line
}
/**
* (Re)Set the start row and the current row pointer.
*
* @param int $startRow The row number at which to start iterating
*
* @return $this
*/
public function resetStart(int $startRow = 1)
{
if ($startRow > $this->subject->getHighestRow()) {
throw new PhpSpreadsheetException(
"Start row ({$startRow}) is beyond highest row ({$this->subject->getHighestRow()})"
);
}
$this->startRow = $startRow;
if ($this->endRow < $this->startRow) {
$this->endRow = $this->startRow;
}
$this->seek($startRow);
return $this;
}
/**
* (Re)Set the end row.
*
* @param int $endRow The row number at which to stop iterating
*
* @return $this
*/
public function resetEnd($endRow = null)
{
$this->endRow = $endRow ?: $this->subject->getHighestRow();
return $this;
}
/**
* Set the row pointer to the selected row.
*
* @param int $row The row number to set the current pointer at
*
* @return $this
*/
public function seek(int $row = 1)
{
if (($row < $this->startRow) || ($row > $this->endRow)) {
throw new PhpSpreadsheetException("Row $row is out of range ({$this->startRow} - {$this->endRow})");
}
$this->position = $row;
return $this;
}
/**
* Rewind the iterator to the starting row.
*/
public function rewind(): void
{
$this->position = $this->startRow;
}
/**
* Return the current row in this worksheet.
*/
public function current(): Row
{
return new Row($this->subject, $this->position);
}
/**
* Return the current iterator key.
*/
public function key(): int
{
return $this->position;
}
/**
* Set the iterator to its next value.
*/
public function next(): void
{
++$this->position;
}
/**
* Set the iterator to its previous value.
*/
public function prev(): void
{
--$this->position;
}
/**
* Indicate if more rows exist in the worksheet range of rows that we're iterating.
*/
public function valid(): bool
{
return $this->position <= $this->endRow && $this->position >= $this->startRow;
}
}
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"
}