Skip to content

Commit

Permalink
Merge pull request #190 from gocardless/template-changes
Browse files Browse the repository at this point in the history
Changes from gocardless/gocardless-pro-php-template
  • Loading branch information
KarmanLeung authored Aug 5, 2024
2 parents 5b64d04 + c48d9a9 commit 146bb80
Show file tree
Hide file tree
Showing 37 changed files with 367 additions and 83 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "gocardless/gocardless-pro",
"description": "GoCardless Pro PHP Client Library",
"version": "5.9.0",
"version": "5.10.0",
"keywords": [
"gocardless",
"direct debit",
Expand Down
19 changes: 17 additions & 2 deletions lib/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __construct($config)
'Content-Type' => 'application/json',
'Authorization' => "Bearer " . $access_token,
'GoCardless-Client-Library' => 'gocardless-pro-php',
'GoCardless-Client-Version' => '5.9.0',
'GoCardless-Client-Version' => '5.10.0',
'User-Agent' => $this->getUserAgent()
),
'http_errors' => false,
Expand Down Expand Up @@ -98,6 +98,8 @@ public function __construct($config)

$this->services['events'] = new Services\EventsService($this->api_client);

$this->services['exports'] = new Services\ExportsService($this->api_client);

$this->services['instalment_schedules'] = new Services\InstalmentSchedulesService($this->api_client);

$this->services['institutions'] = new Services\InstitutionsService($this->api_client);
Expand Down Expand Up @@ -314,6 +316,19 @@ public function events()
return $this->services['events'];
}

/**
* Service for interacting with exports
*
* @return Services\ExportsService
*/
public function exports()
{
if (!isset($this->services['exports'])) {
throw new \Exception('Key exports does not exist in services array');
}
return $this->services['exports'];
}

/**
* Service for interacting with instalment schedule
*
Expand Down Expand Up @@ -649,7 +664,7 @@ private function getUserAgent()
{
$curlinfo = curl_version();
$uagent = array();
$uagent[] = 'gocardless-pro-php/5.9.0';
$uagent[] = 'gocardless-pro-php/5.10.0';
$uagent[] = 'schema-version/2015-07-06';
if (defined('\GuzzleHttp\Client::MAJOR_VERSION')) {
$uagent[] = 'GuzzleHttp/' . \GuzzleHttp\Client::MAJOR_VERSION;
Expand Down
10 changes: 5 additions & 5 deletions lib/Resources/BillingRequestTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class BillingRequestTemplate extends BaseResource
/**
* [ISO 4217](http://en.wikipedia.org/wiki/ISO_4217#Active_codes) currency
* code. `GBP` and `EUR` supported; `GBP` with your customers in the UK and
* for `EUR` with your customers in Germany only.
* for `EUR` with your customers in supported Eurozone countries only.
*/
protected $payment_request_currency;

Expand All @@ -147,10 +147,10 @@ class BillingRequestTemplate extends BaseResource
/**
* (Optional) A scheme used for Open Banking payments. Currently
* `faster_payments` is supported in the UK (GBP) and `sepa_credit_transfer`
* and `sepa_instant_credit_transfer` are supported in Germany (EUR). In
* Germany, `sepa_credit_transfer` is used as the default. Please be aware
* that `sepa_instant_credit_transfer` may incur an additional fee for your
* customer.
* and `sepa_instant_credit_transfer` are supported in supported Eurozone
* countries (EUR). For Eurozone countries, `sepa_credit_transfer` is used
* as the default. Please be aware that `sepa_instant_credit_transfer` may
* incur an additional fee for your customer.
*/
protected $payment_request_scheme;

Expand Down
8 changes: 3 additions & 5 deletions lib/Resources/CustomerBankAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ class CustomerBankAccount extends BaseResource
protected $model_name = "CustomerBankAccount";

/**
* Name of the account holder, as known by the bank. Usually this is the
* same as the name stored with the linked
* [creditor](#core-endpoints-creditors). This field will be transliterated,
* upcased and truncated to 18 characters. This field is required unless the
* request includes a [customer bank account
* Name of the account holder, as known by the bank. This field will be
* transliterated, upcased and truncated to 18 characters. This field is
* required unless the request includes a [customer bank account
* token](#javascript-flow-customer-bank-account-tokens).
*/
protected $account_holder_name;
Expand Down
1 change: 1 addition & 0 deletions lib/Resources/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class Event extends BaseResource
* <ul>
* <li>`billing_requests`</li>
* <li>`creditors`</li>
* <li>`exports`</li>
* <li>`instalment_schedules`</li>
* <li>`mandates`</li>
* <li>`payer_authorisations`</li>
Expand Down
50 changes: 50 additions & 0 deletions lib/Resources/Export.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
/**
* WARNING: Do not edit by hand, this file was generated by Crank:
*
* https://github.com/gocardless/crank
*/

namespace GoCardlessPro\Resources;

/**
* A thin wrapper around a export, providing access to its
* attributes
*
* @property-read $created_at
* @property-read $currency
* @property-read $download_url
* @property-read $export_type
* @property-read $id
*/
class Export extends BaseResource
{
protected $model_name = "Export";

/**
* Fixed [timestamp](#api-usage-time-zones--dates), recording when this
* resource was created.
*/
protected $created_at;

/**
* The currency of the export (if applicable)
*/
protected $currency;

/**
* Download url for the export file. Subject to expiry.
*/
protected $download_url;

/**
* The type of the export
*/
protected $export_type;

/**
* Unique identifier, beginning with "EX".
*/
protected $id;

}
6 changes: 6 additions & 0 deletions lib/Resources/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* @property-read $metadata
* @property-read $month
* @property-read $name
* @property-read $parent_plan_paused
* @property-read $payment_reference
* @property-read $retry_if_possible
* @property-read $start_date
Expand Down Expand Up @@ -135,6 +136,11 @@ class Subscription extends BaseResource
*/
protected $name;

/**
* Whether the parent plan of this subscription is paused.
*/
protected $parent_plan_paused;

/**
* An optional payment reference. This will be set as the reference on each
* payment
Expand Down
95 changes: 95 additions & 0 deletions lib/Services/ExportsService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php
/**
* WARNING: Do not edit by hand, this file was generated by Crank:
*
* https://github.com/gocardless/crank
*/

namespace GoCardlessPro\Services;

use \GoCardlessPro\Core\Paginator;
use \GoCardlessPro\Core\Util;
use \GoCardlessPro\Core\ListResponse;
use \GoCardlessPro\Resources\Export;
use \GoCardlessPro\Core\Exception\InvalidStateException;


/**
* Service that provides access to the Export
* endpoints of the API
*
* @method get()
* @method list()
*/
class ExportsService extends BaseService
{

protected $envelope_key = 'exports';
protected $resource_class = '\GoCardlessPro\Resources\Export';


/**
* Get a single export
*
* Example URL: /exports/:identity
*
* @param string $identity Unique identifier, beginning with "EX".
* @param string[mixed] $params An associative array for any params
* @return Export
**/
public function get($identity, $params = array())
{
$path = Util::subUrl(
'/exports/:identity',
array(

'identity' => $identity
)
);
if(isset($params['params'])) { $params['query'] = $params['params'];
unset($params['params']);
}


$response = $this->api_client->get($path, $params);


return $this->getResourceForResponse($response);
}

/**
* List exports
*
* Example URL: /exports
*
* @param string[mixed] $params An associative array for any params
* @return ListResponse
**/
protected function _doList($params = array())
{
$path = "/exports";
if(isset($params['params'])) { $params['query'] = $params['params'];
unset($params['params']);
}


$response = $this->api_client->get($path, $params);


return $this->getResourceForResponse($response);
}

/**
* List exports
*
* Example URL: /exports
*
* @param string[mixed] $params
* @return Paginator
**/
public function all($params = array())
{
return new Paginator($this, $params);
}

}
93 changes: 93 additions & 0 deletions tests/Integration/ExportsIntegrationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php
//
// WARNING: Do not edit by hand, this file was generated by Crank:
// https://github.com/gocardless/crank
//

namespace GoCardlessPro\Integration;

class ExportsIntegrationTest extends IntegrationTestBase
{
public function testResourceModelExists()
{
$obj = new \GoCardlessPro\Resources\Export(array());
$this->assertNotNull($obj);
}

public function testExportsGet()
{
$fixture = $this->loadJsonFixture('exports')->get;
$this->stub_request($fixture);

$service = $this->client->exports();
$response = call_user_func_array(array($service, 'get'), (array)$fixture->url_params);

$body = $fixture->body->exports;

$this->assertInstanceOf('\GoCardlessPro\Resources\Export', $response);

$this->assertEquals($body->created_at, $response->created_at);
$this->assertEquals($body->currency, $response->currency);
$this->assertEquals($body->download_url, $response->download_url);
$this->assertEquals($body->export_type, $response->export_type);
$this->assertEquals($body->id, $response->id);


$expectedPathRegex = $this->extract_resource_fixture_path_regex($fixture);
$dispatchedRequest = $this->history[0]['request'];
$this->assertMatchesRegularExpression($expectedPathRegex, $dispatchedRequest->getUri()->getPath());
}


public function testExportsList()
{
$fixture = $this->loadJsonFixture('exports')->list;
$this->stub_request($fixture);

$service = $this->client->exports();
$response = call_user_func_array(array($service, 'list'), (array)$fixture->url_params);

$body = $fixture->body->exports;

$records = $response->records;
$this->assertInstanceOf('\GoCardlessPro\Core\ListResponse', $response);
$this->assertInstanceOf('\GoCardlessPro\Resources\Export', $records[0]);
if (!is_null($fixture->body) && property_exists($fixture->body, 'meta') && !is_null($fixture->body->meta)) {
$this->assertEquals($fixture->body->meta->cursors->before, $response->before);
$this->assertEquals($fixture->body->meta->cursors->after, $response->after);
}



foreach (range(0, count($body) - 1) as $num) {
$record = $records[$num];

if (isset($body[$num]->created_at)) {
$this->assertEquals($body[$num]->created_at, $record->created_at);
}

if (isset($body[$num]->currency)) {
$this->assertEquals($body[$num]->currency, $record->currency);
}

if (isset($body[$num]->download_url)) {
$this->assertEquals($body[$num]->download_url, $record->download_url);
}

if (isset($body[$num]->export_type)) {
$this->assertEquals($body[$num]->export_type, $record->export_type);
}

if (isset($body[$num]->id)) {
$this->assertEquals($body[$num]->id, $record->id);
}

}

$expectedPathRegex = $this->extract_resource_fixture_path_regex($fixture);
$dispatchedRequest = $this->history[0]['request'];
$this->assertMatchesRegularExpression($expectedPathRegex, $dispatchedRequest->getUri()->getPath());
}


}
Loading

0 comments on commit 146bb80

Please sign in to comment.