Skip to content

Commit

Permalink
support cursor based pagination
Browse files Browse the repository at this point in the history
Signed-off-by: Bruno Vieira <bruno@chartmogul.com>
  • Loading branch information
kmossco committed Oct 4, 2023
1 parent e6b5880 commit dadc365
Show file tree
Hide file tree
Showing 70 changed files with 1,249 additions and 717 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning].
[Keep a Changelog]: https://keepachangelog.com/en/1.0.0/
[Semantic Versioning]: https://semver.org/spec/v2.0.0.html

## [5.1.3] - 2023-10-03

### Added
- Support for cursor based pagination (#114)
- Linted the project with phpcs and phpcbf (#114)

## [5.1.2] - 2023-09-25

### Added
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ $plan_group_plans = ChartMogul\PlanGroups\Plan::all(
$plan = ChartMogul\Plan::all()->first();
$cus = ChartMogul\Customer::all()->first();

$line_itme_1 = new ChartMogul\LineItems\Subscription([
$line_item_1 = new ChartMogul\LineItems\Subscription([
'subscription_external_id' => "sub_0001",
'subscription_set_external_id' => 'set_0001',
'plan_uuid' => $plan->uuid,
Expand All @@ -534,7 +534,7 @@ $line_itme_1 = new ChartMogul\LineItems\Subscription([
'discount_description' => "5 EUR"
]);

$line_itme_2 = new ChartMogul\LineItems\OneTime([
$line_item_2 = new ChartMogul\LineItems\OneTime([
"description" => "Setup Fees",
"amount_in_cents" => 2500,
"quantity" => 1,
Expand All @@ -555,7 +555,7 @@ $invoice = new ChartMogul\Invoice([
'date' => "2015-11-01 00:00:00",
'currency' => 'USD',
'due_date' => "2015-11-15 00:00:00",
'line_items' => [$line_itme_1, $line_itme_2],
'line_items' => [$line_item_1, $line_item_2],
'transactions' => [$transaction]
]);

Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
"guzzlehttp/psr7": "^1.0",
"http-interop/http-factory-guzzle": "^1.0",
"php-vcr/php-vcr": "^1.5",
"php-http/curl-client": "^2.2"
"php-http/curl-client": "^2.2",
"squizlabs/php_codesniffer": "*",
"friendsofphp/php-cs-fixer": "^3.34"
},
"config": {
"allow-plugins": {
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ parameters:
- src
ignoreErrors:
- '#Unsafe usage of new static\(\).#'
treatPhpDocTypesAsCertain: false
12 changes: 6 additions & 6 deletions src/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
use ChartMogul\Service\ShowTrait;

/**
* @codeCoverageIgnore
* @property-read string $name
* @property-read string $currency
* @property-read string $time_zone
* @property-read string $week_start_on
*/
* @codeCoverageIgnore
* @property-read string $name
* @property-read string $currency
* @property-read string $time_zone
* @property-read string $week_start_on
*/
class Account extends AbstractResource
{
use ShowTrait;
Expand Down
19 changes: 13 additions & 6 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
class Configuration
{
const DEFAULT_MAX_RETRIES = 20;
public const DEFAULT_MAX_RETRIES = 20;

/**
* @var null|Configuration
Expand All @@ -27,6 +27,7 @@ class Configuration

/**
* Creates new config object from apiKey
*
* @param string $apiKey
*/
public function __construct($apiKey = '', $retries = self::DEFAULT_MAX_RETRIES)
Expand All @@ -37,6 +38,7 @@ public function __construct($apiKey = '', $retries = self::DEFAULT_MAX_RETRIES)

/**
* Get Api Key
*
* @return string
*/
public function getApiKey()
Expand All @@ -46,7 +48,8 @@ public function getApiKey()

/**
* Set Api Key
* @param string $apiKey
*
* @param string $apiKey
* @return self
*/
public function setApiKey($apiKey)
Expand All @@ -57,6 +60,7 @@ public function setApiKey($apiKey)

/**
* Get retries
*
* @return int
*/
public function getRetries()
Expand All @@ -66,7 +70,8 @@ public function getRetries()

/**
* Set max retries
* @param int $retries
*
* @param int $retries
* @return self
*/
public function setRetries($retries)
Expand All @@ -77,7 +82,8 @@ public function setRetries($retries)

/**
* Set Default Config object. Default config object is used when no config object is passed during resource call
* @return Configuration
*
* @return Configuration
*/
public static function getDefaultConfiguration()
{
Expand All @@ -89,8 +95,9 @@ public static function getDefaultConfiguration()

/**
* Get the default config object.
* @param Configuration $config
* @return Configuration
*
* @param Configuration $config
* @return Configuration
*/
public static function setDefaultConfiguration(Configuration $config)
{
Expand Down
17 changes: 11 additions & 6 deletions src/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
* @property-read string $linked_in
* @property-read string $twitter
* @property-read string $custom
*/
class Contact extends AbstractResource
{
Expand Down Expand Up @@ -64,6 +63,7 @@ class Contact extends AbstractResource

/**
* Merge Contacts
*
* @param string $into
* @param string $from
* @param ClientInterface|null $client
Expand All @@ -81,16 +81,21 @@ public static function merge($into, $from, ClientInterface $client = null)
/**
* Overrides fromArray so that it will return a collection with cursor instead.
*
* @param array $data
* @param ClientInterface|null $client
* @param array $data
* @param ClientInterface|null $client
* @return CollectionWithCursor|static
*/
public static function fromArray(array $data, ClientInterface $client = null)
{
if (isset($data[static::ROOT_KEY])) {
$array = new CollectionWithCursor(array_map(function ($data) use ($client) {
return static::fromArray($data, $client);
}, $data[static::ROOT_KEY]));
$array = new CollectionWithCursor(
array_map(
function ($data) use ($client) {
return static::fromArray($data, $client);
},
$data[static::ROOT_KEY]
)
);

if (isset($data["cursor"])) {
$array->cursor = $data["cursor"];
Expand Down
Loading

0 comments on commit dadc365

Please sign in to comment.