Skip to content

Commit

Permalink
Merge pull request #83 from gocardless/template-changes
Browse files Browse the repository at this point in the history
Release 3.6.0
  • Loading branch information
paprikati authored Mar 4, 2020
2 parents c810d63 + 6d89fa2 commit 4420abb
Show file tree
Hide file tree
Showing 24 changed files with 187 additions and 65 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": "3.5.2",
"version": "3.6.0",
"keywords": [
"gocardless",
"direct debit",
Expand Down
4 changes: 2 additions & 2 deletions lib/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function __construct($config)
'Content-Type' => 'application/json',
'Authorization' => "Bearer " . $access_token,
'GoCardless-Client-Library' => 'gocardless-pro-php',
'GoCardless-Client-Version' => '3.5.2',
'GoCardless-Client-Version' => '3.6.0',
'User-Agent' => $this->getUserAgent()
),
'http_errors' => false,
Expand Down Expand Up @@ -369,7 +369,7 @@ private function getUserAgent()
{
$curlinfo = curl_version();
$uagent = array();
$uagent[] = 'gocardless-pro-php/3.5.2';
$uagent[] = 'gocardless-pro-php/3.6.0';
$uagent[] = 'schema-version/2015-07-06';
$uagent[] = 'GuzzleHttp/' . \GuzzleHttp\Client::VERSION;
$uagent[] = 'php/' . phpversion();
Expand Down
4 changes: 2 additions & 2 deletions lib/Resources/Creditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ class Creditor extends BaseResource
* Boolean value indicating whether the organisation is responsible for
* sending all customer notifications (note this is separate from the
* functionality described
* [here](https://developer.gocardless.com/getting-started/api/handling-customer-notifications/).
* If you are a partner app, and this value is true, you should not send
* [here](/getting-started/api/handling-customer-notifications/)). If you
* are a partner app, and this value is true, you should not send
* notifications on behalf of this organisation.
*/
protected $merchant_responsible_for_notifications;
Expand Down
8 changes: 5 additions & 3 deletions lib/Resources/InstalmentSchedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ class InstalmentSchedule extends BaseResource
/**
* The total amount of the instalment schedule, defined as the sum of all
* individual
* payments. If the requested payment amounts do not sum up correctly, a
* validation
* error will be returned.
* payments, in the lowest denomination for the currency (e.g. pence in GBP,
* cents in
* EUR). If the requested payment amounts do not sum up correctly, a
* validation error
* will be returned.
*/
protected $total_amount;

Expand Down
6 changes: 6 additions & 0 deletions lib/Resources/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*
* @property-read $amount
* @property-read $app_fee
* @property-read $count
* @property-read $created_at
* @property-read $currency
* @property-read $day_of_month
Expand Down Expand Up @@ -47,6 +48,11 @@ class Subscription extends BaseResource
*/
protected $app_fee;

/**
* The total number of payments that should be taken by this subscription.
*/
protected $count;

/**
* Fixed [timestamp](#api-usage-time-zones--dates), recording when this
* resource was created.
Expand Down
39 changes: 37 additions & 2 deletions lib/Services/InstalmentSchedulesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,49 @@ class InstalmentSchedulesService extends BaseService


/**
* Create an instalment schedule
* Create (with dates)
*
* Example URL: /instalment_schedules
*
* @param string[mixed] $params An associative array for any params
* @return InstalmentSchedule
**/
public function create($params = array())
public function createWithDates($params = array())
{
$path = "/instalment_schedules";
if(isset($params['params'])) {
$params['body'] = json_encode(array($this->envelope_key => (object)$params['params']));

unset($params['params']);
}


try {
$response = $this->api_client->post($path, $params);
} catch(InvalidStateException $e) {
if ($e->isIdempotentCreationConflict()) {
if ($this->api_client->error_on_idempotency_conflict) {
throw $e;
}
return $this->get($e->getConflictingResourceId());
}

throw $e;
}


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

/**
* Create (with schedule)
*
* Example URL: /instalment_schedules
*
* @param string[mixed] $params An associative array for any params
* @return InstalmentSchedule
**/
public function createWithSchedule($params = array())
{
$path = "/instalment_schedules";
if(isset($params['params'])) {
Expand Down
78 changes: 72 additions & 6 deletions tests/Integration/InstalmentSchedulesIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ public function testResourceModelExists()
$this->assertNotNull($obj);
}

public function testInstalmentSchedulesCreate()
public function testInstalmentSchedulesCreateWithDates()
{
$fixture = $this->loadJsonFixture('instalment_schedules')->create;
$fixture = $this->loadJsonFixture('instalment_schedules')->create_with_dates;
$this->stub_request($fixture);

$service = $this->client->instalmentSchedules();
$response = call_user_func_array(array($service, 'create'), (array)$fixture->url_params);
$response = call_user_func_array(array($service, 'createWithDates'), (array)$fixture->url_params);

$body = $fixture->body->instalment_schedules;

Expand All @@ -42,9 +42,9 @@ public function testInstalmentSchedulesCreate()
$this->assertRegExp($expectedPathRegex, $dispatchedRequest->getUri()->getPath());
}

public function testInstalmentSchedulesCreateWithIdempotencyConflict()
public function testInstalmentSchedulesCreateWithDatesWithIdempotencyConflict()
{
$fixture = $this->loadJsonFixture('instalment_schedules')->create;
$fixture = $this->loadJsonFixture('instalment_schedules')->create_with_dates;

$idempotencyConflictResponseFixture = $this->loadFixture('idempotent_creation_conflict_invalid_state_error');

Expand All @@ -57,7 +57,73 @@ public function testInstalmentSchedulesCreateWithIdempotencyConflict()
$this->mock->append(new \GuzzleHttp\Psr7\Response(200, [], json_encode($fixture->body)));

$service = $this->client->instalmentSchedules();
$response = call_user_func_array(array($service, 'create'), (array)$fixture->url_params);
$response = call_user_func_array(array($service, 'createWithDates'), (array)$fixture->url_params);
$body = $fixture->body->instalment_schedules;

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

$this->assertEquals($body->created_at, $response->created_at);
$this->assertEquals($body->currency, $response->currency);
$this->assertEquals($body->id, $response->id);
$this->assertEquals($body->links, $response->links);
$this->assertEquals($body->metadata, $response->metadata);
$this->assertEquals($body->name, $response->name);
$this->assertEquals($body->payment_errors, $response->payment_errors);
$this->assertEquals($body->status, $response->status);
$this->assertEquals($body->total_amount, $response->total_amount);


$expectedPathRegex = $this->extract_resource_fixture_path_regex($fixture);
$conflictRequest = $this->history[0]['request'];
$this->assertRegExp($expectedPathRegex, $conflictRequest->getUri()->getPath());
$getRequest = $this->history[1]['request'];
$this->assertEquals($getRequest->getUri()->getPath(), '/instalment_schedules/ID123');
}

public function testInstalmentSchedulesCreateWithSchedule()
{
$fixture = $this->loadJsonFixture('instalment_schedules')->create_with_schedule;
$this->stub_request($fixture);

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

$body = $fixture->body->instalment_schedules;

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

$this->assertEquals($body->created_at, $response->created_at);
$this->assertEquals($body->currency, $response->currency);
$this->assertEquals($body->id, $response->id);
$this->assertEquals($body->links, $response->links);
$this->assertEquals($body->metadata, $response->metadata);
$this->assertEquals($body->name, $response->name);
$this->assertEquals($body->payment_errors, $response->payment_errors);
$this->assertEquals($body->status, $response->status);
$this->assertEquals($body->total_amount, $response->total_amount);


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

public function testInstalmentSchedulesCreateWithScheduleWithIdempotencyConflict()
{
$fixture = $this->loadJsonFixture('instalment_schedules')->create_with_schedule;

$idempotencyConflictResponseFixture = $this->loadFixture('idempotent_creation_conflict_invalid_state_error');

// The POST request responds with a 409 to our original POST, due to an idempotency conflict
$this->mock->append(new \GuzzleHttp\Psr7\Response(409, [], $idempotencyConflictResponseFixture));

// The client makes a second request to fetch the resource that was already
// created using our idempotency key. It responds with the created resource,
// which looks just like the response for a successful POST request.
$this->mock->append(new \GuzzleHttp\Psr7\Response(200, [], json_encode($fixture->body)));

$service = $this->client->instalmentSchedules();
$response = call_user_func_array(array($service, 'createWithSchedule'), (array)$fixture->url_params);
$body = $fixture->body->instalment_schedules;

$this->assertInstanceOf('\GoCardlessPro\Resources\InstalmentSchedule', $response);
Expand Down
7 changes: 7 additions & 0 deletions tests/Integration/SubscriptionsIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function testSubscriptionsCreate()

$this->assertEquals($body->amount, $response->amount);
$this->assertEquals($body->app_fee, $response->app_fee);
$this->assertEquals($body->count, $response->count);
$this->assertEquals($body->created_at, $response->created_at);
$this->assertEquals($body->currency, $response->currency);
$this->assertEquals($body->day_of_month, $response->day_of_month);
Expand Down Expand Up @@ -73,6 +74,7 @@ public function testSubscriptionsCreateWithIdempotencyConflict()

$this->assertEquals($body->amount, $response->amount);
$this->assertEquals($body->app_fee, $response->app_fee);
$this->assertEquals($body->count, $response->count);
$this->assertEquals($body->created_at, $response->created_at);
$this->assertEquals($body->currency, $response->currency);
$this->assertEquals($body->day_of_month, $response->day_of_month);
Expand Down Expand Up @@ -121,6 +123,7 @@ public function testSubscriptionsList()
$record = $records[$num];
$this->assertEquals($body[$num]->amount, $record->amount);
$this->assertEquals($body[$num]->app_fee, $record->app_fee);
$this->assertEquals($body[$num]->count, $record->count);
$this->assertEquals($body[$num]->created_at, $record->created_at);
$this->assertEquals($body[$num]->currency, $record->currency);
$this->assertEquals($body[$num]->day_of_month, $record->day_of_month);
Expand Down Expand Up @@ -160,6 +163,7 @@ public function testSubscriptionsGet()

$this->assertEquals($body->amount, $response->amount);
$this->assertEquals($body->app_fee, $response->app_fee);
$this->assertEquals($body->count, $response->count);
$this->assertEquals($body->created_at, $response->created_at);
$this->assertEquals($body->currency, $response->currency);
$this->assertEquals($body->day_of_month, $response->day_of_month);
Expand Down Expand Up @@ -198,6 +202,7 @@ public function testSubscriptionsUpdate()

$this->assertEquals($body->amount, $response->amount);
$this->assertEquals($body->app_fee, $response->app_fee);
$this->assertEquals($body->count, $response->count);
$this->assertEquals($body->created_at, $response->created_at);
$this->assertEquals($body->currency, $response->currency);
$this->assertEquals($body->day_of_month, $response->day_of_month);
Expand Down Expand Up @@ -236,6 +241,7 @@ public function testSubscriptionsCancel()

$this->assertEquals($body->amount, $response->amount);
$this->assertEquals($body->app_fee, $response->app_fee);
$this->assertEquals($body->count, $response->count);
$this->assertEquals($body->created_at, $response->created_at);
$this->assertEquals($body->currency, $response->currency);
$this->assertEquals($body->day_of_month, $response->day_of_month);
Expand Down Expand Up @@ -281,6 +287,7 @@ public function testSubscriptionsCancelWithIdempotencyConflict()

$this->assertEquals($body->amount, $response->amount);
$this->assertEquals($body->app_fee, $response->app_fee);
$this->assertEquals($body->count, $response->count);
$this->assertEquals($body->created_at, $response->created_at);
$this->assertEquals($body->currency, $response->currency);
$this->assertEquals($body->day_of_month, $response->day_of_month);
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/bank_details_lookups.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"method": "POST",
"path_template": "/bank_details_lookups",
"url_params": {},
"body": {"bank_details_lookups":{"available_debit_schemes":["bacs"],"bank_name":null,"bic":null}}
"body": {"bank_details_lookups":{"available_debit_schemes":["bacs"],"bank_name":"NATWEST BANK PLC","bic":"BARCGB22XXX"}}
}
}

6 changes: 3 additions & 3 deletions tests/fixtures/creditor_bank_accounts.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
"method": "GET",
"path_template": "/creditor_bank_accounts",
"url_params": {},
"body": {"creditor_bank_accounts":[{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":null,"bank_name":"BARCLAYS BANK PLC","country_code":null,"created_at":"2014-01-01T12:00:00.000Z","currency":null,"enabled":true,"id":"BA123","links":{"creditor":"CR123"},"metadata":{}},{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":null,"bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"creditor":"CR123"},"metadata":{}}],"meta":{"cursors":{"after":"example after 9267","before":"example before 1297"},"limit":50}}
"body": {"creditor_bank_accounts":[{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"creditor":"CR123"},"metadata":{}},{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"creditor":"CR123"},"metadata":{}}],"meta":{"cursors":{"after":"example after 6258","before":"example before 1528"},"limit":50}}
},
"get": {
"method": "GET",
"path_template": "/creditor_bank_accounts/:identity",
"url_params": {"identity": "BA123"},
"body": {"creditor_bank_accounts":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":null,"bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":null,"enabled":true,"id":"BA123","links":{"creditor":"CR123"},"metadata":{}}}
"body": {"creditor_bank_accounts":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"creditor":"CR123"},"metadata":{}}}
},
"disable": {
"method": "POST",
"path_template": "/creditor_bank_accounts/:identity/actions/disable",
"url_params": {"identity": "BA123"},
"body": {"creditor_bank_accounts":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":null,"enabled":true,"id":"BA123","links":{"creditor":"CR123"},"metadata":{}}}
"body": {"creditor_bank_accounts":{"account_holder_name":"Billie Jean","account_number_ending":"1234","account_type":"savings","bank_name":"BARCLAYS BANK PLC","country_code":"GB","created_at":"2014-01-01T12:00:00.000Z","currency":"EUR","enabled":true,"id":"BA123","links":{"creditor":"CR123"},"metadata":{}}}
}
}

Loading

0 comments on commit 4420abb

Please sign in to comment.