Skip to content

Commit

Permalink
Merge pull request #123 from gocardless/template-changes
Browse files Browse the repository at this point in the history
v4.13.0
  • Loading branch information
vdandugc authored Sep 29, 2021
2 parents e63b97b + 614b9aa commit e159de1
Show file tree
Hide file tree
Showing 29 changed files with 92 additions and 59 deletions.
11 changes: 8 additions & 3 deletions lib/Core/ListResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ class ListResponse
public function __construct($unenveloped_body, $model_class, $api_response)
{
$this->api_response = $api_response;
$this->before = $this->api_response->body->meta->cursors->before;
$this->after = $this->api_response->body->meta->cursors->after;

if(!is_null($this->api_response->body->meta)) {
if(property_exists($this->api_response->body->meta->cursors, 'before')) {
$this->before = $this->api_response->body->meta->cursors->before;
}
if(property_exists($this->api_response->body->meta->cursors, 'after')) {
$this->after = $this->api_response->body->meta->cursors->after;
}
}
foreach ($unenveloped_body as $item) {
$this->records[] = new $model_class($item);
}
Expand Down
1 change: 1 addition & 0 deletions lib/Resources/CustomerNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class CustomerNotification extends BaseResource
* <li>`payment_created`</li>
* <li>`payment_cancelled`</li>
* <li>`mandate_created`</li>
* <li>`mandate_blocked`</li>
* <li>`subscription_created`</li>
* <li>`subscription_cancelled`</li>
* <li>`instalment_schedule_created`</li>
Expand Down
6 changes: 6 additions & 0 deletions lib/Resources/RedirectFlow.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* @property-read $description
* @property-read $id
* @property-read $links
* @property-read $mandate_reference
* @property-read $metadata
* @property-read $redirect_url
* @property-read $scheme
Expand Down Expand Up @@ -61,6 +62,11 @@ class RedirectFlow extends BaseResource
*/
protected $links;

/**
* Mandate reference generated by GoCardless or submitted by an integrator.
*/
protected $mandate_reference;

/**
* Key-value store of custom data. Up to 3 keys are permitted, with key
* names up to 50 characters and values up to 500 characters.
Expand Down
16 changes: 16 additions & 0 deletions tests/Core/ListResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,20 @@ public function testForeachCount()
$this->assertEquals('test', $items[1]->foo);
$this->assertEquals(2, count($items));
}

public function testForResponseWithNoCursors()
{
$body = '{"data": [{"id":"1", "foo":"hi"}, {"id": "2", "foo": "test"}]}';
$raw_response = new \GuzzleHttp\Psr7\Response(200, [], $body);

$decoded_body = json_decode($body, true);
$api_response = new ApiResponse($raw_response);
$model_class = 'GoCardlessPro\Core\FakeResource';

$this->list_response = new ListResponse($decoded_body['data'], $model_class, $api_response);
$records = $this->list_response->records;

$this->assertEquals(count($records), 2);
$this->assertEquals('test', $records[1]->foo);
}
}
5 changes: 5 additions & 0 deletions tests/Integration/RedirectFlowsIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function testRedirectFlowsCreate()
$this->assertEquals($body->description, $response->description);
$this->assertEquals($body->id, $response->id);
$this->assertEquals($body->links, $response->links);
$this->assertEquals($body->mandate_reference, $response->mandate_reference);
$this->assertEquals($body->metadata, $response->metadata);
$this->assertEquals($body->redirect_url, $response->redirect_url);
$this->assertEquals($body->scheme, $response->scheme);
Expand Down Expand Up @@ -68,6 +69,7 @@ public function testRedirectFlowsCreateWithIdempotencyConflict()
$this->assertEquals($body->description, $response->description);
$this->assertEquals($body->id, $response->id);
$this->assertEquals($body->links, $response->links);
$this->assertEquals($body->mandate_reference, $response->mandate_reference);
$this->assertEquals($body->metadata, $response->metadata);
$this->assertEquals($body->redirect_url, $response->redirect_url);
$this->assertEquals($body->scheme, $response->scheme);
Expand Down Expand Up @@ -99,6 +101,7 @@ public function testRedirectFlowsGet()
$this->assertEquals($body->description, $response->description);
$this->assertEquals($body->id, $response->id);
$this->assertEquals($body->links, $response->links);
$this->assertEquals($body->mandate_reference, $response->mandate_reference);
$this->assertEquals($body->metadata, $response->metadata);
$this->assertEquals($body->redirect_url, $response->redirect_url);
$this->assertEquals($body->scheme, $response->scheme);
Expand Down Expand Up @@ -129,6 +132,7 @@ public function testRedirectFlowsComplete()
$this->assertEquals($body->description, $response->description);
$this->assertEquals($body->id, $response->id);
$this->assertEquals($body->links, $response->links);
$this->assertEquals($body->mandate_reference, $response->mandate_reference);
$this->assertEquals($body->metadata, $response->metadata);
$this->assertEquals($body->redirect_url, $response->redirect_url);
$this->assertEquals($body->scheme, $response->scheme);
Expand Down Expand Up @@ -166,6 +170,7 @@ public function testRedirectFlowsCompleteWithIdempotencyConflict()
$this->assertEquals($body->description, $response->description);
$this->assertEquals($body->id, $response->id);
$this->assertEquals($body->links, $response->links);
$this->assertEquals($body->mandate_reference, $response->mandate_reference);
$this->assertEquals($body->metadata, $response->metadata);
$this->assertEquals($body->redirect_url, $response->redirect_url);
$this->assertEquals($body->scheme, $response->scheme);
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/bank_authorisations.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"method": "GET",
"path_template": "/bank_authorisations/:identity",
"url_params": {"identity": "BAU123"},
"body": {"bank_authorisations":{"authorisation_type":"example authorisation_type 8081","authorised_at":"2020-01-01T12:00:00.000Z","created_at":"2021-08-12T15:31:47.124Z","expires_at":"2021-08-12T15:31:47.124Z","id":"BAU123","last_visited_at":"2020-01-01T12:00:00.000Z","links":{"billing_request":"BRQ123","institution":"monzo","payment_request":"PRQ123"},"redirect_uri":"https://my-website.com/abc/callback","url":"https://pay.gocardless.com/obauth/BAU123"}}
"body": {"bank_authorisations":{"authorisation_type":"example authorisation_type 8081","authorised_at":"2020-01-01T12:00:00.000Z","created_at":"2021-09-23T16:39:44.437Z","expires_at":"2021-09-23T16:39:44.437Z","id":"BAU123","last_visited_at":"2020-01-01T12:00:00.000Z","links":{"billing_request":"BRQ123","institution":"monzo"},"redirect_uri":"https://my-website.com/abc/callback","url":"https://pay.gocardless.com/obauth/BAU123"}}
},
"create": {
"method": "POST",
"path_template": "/bank_authorisations",
"url_params": {},
"body": {"bank_authorisations":{"authorisation_type":"example authorisation_type 7887","authorised_at":"2020-01-01T12:00:00.000Z","created_at":"2021-08-12T15:31:47.124Z","expires_at":"2021-08-12T15:31:47.124Z","id":"BAU123","last_visited_at":"2020-01-01T12:00:00.000Z","links":{"billing_request":"BRQ123","institution":"monzo","payment_request":"PRQ123"},"redirect_uri":"https://my-website.com/abc/callback","url":"https://pay.gocardless.com/obauth/BAU123"}}
"body": {"bank_authorisations":{"authorisation_type":"example authorisation_type 7887","authorised_at":"2020-01-01T12:00:00.000Z","created_at":"2021-09-23T16:39:44.437Z","expires_at":"2021-09-23T16:39:44.437Z","id":"BAU123","last_visited_at":"2020-01-01T12:00:00.000Z","links":{"billing_request":"BRQ123","institution":"monzo"},"redirect_uri":"https://my-website.com/abc/callback","url":"https://pay.gocardless.com/obauth/BAU123"}}
}
}

4 changes: 2 additions & 2 deletions tests/fixtures/billing_request_flows.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"method": "POST",
"path_template": "/billing_request_flows",
"url_params": {},
"body": {"billing_request_flows":{"authorisation_url":"https://monzo.com/abc-123-things","auto_fulfil":true,"created_at":"2021-08-12T15:31:47.127Z","expires_at":"2021-08-12T15:31:47.127Z","id":"BRF123","links":{"billing_request":"BRQ123"},"lock_bank_account":true,"lock_customer_details":true,"redirect_uri":"https://my-website.com/abc/callback","session_token":"sesh_123"}}
"body": {"billing_request_flows":{"authorisation_url":"https://monzo.com/abc-123-things","auto_fulfil":true,"created_at":"2021-09-23T16:39:44.439Z","expires_at":"2021-09-23T16:39:44.439Z","id":"BRF123","links":{"billing_request":"BRQ123"},"lock_bank_account":true,"lock_customer_details":true,"redirect_uri":"https://my-website.com/abc/callback","session_token":"sesh_123"}}
},
"initialise": {
"method": "POST",
"path_template": "/billing_request_flows/:identity/actions/initialise",
"url_params": {"identity": "BRQ123"},
"body": {"billing_request_flows":{"authorisation_url":"https://monzo.com/abc-123-things","auto_fulfil":false,"created_at":"2021-08-12T15:31:47.127Z","expires_at":"2021-08-12T15:31:47.127Z","id":"BRF123","links":{"billing_request":"BRQ123"},"lock_bank_account":true,"lock_customer_details":true,"redirect_uri":"https://my-website.com/abc/callback","session_token":"sesh_123"}}
"body": {"billing_request_flows":{"authorisation_url":"https://monzo.com/abc-123-things","auto_fulfil":false,"created_at":"2021-09-23T16:39:44.439Z","expires_at":"2021-09-23T16:39:44.439Z","id":"BRF123","links":{"billing_request":"BRQ123"},"lock_bank_account":true,"lock_customer_details":true,"redirect_uri":"https://my-website.com/abc/callback","session_token":"sesh_123"}}
}
}

2 changes: 1 addition & 1 deletion tests/fixtures/billing_request_templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"method": "GET",
"path_template": "/billing_request_templates",
"url_params": {},
"body": {"billing_request_templates":[{"authorisation_url":"https://pay.gocardless.com/BRT123","created_at":"2021-01-01T12:00:00.000Z","id":"BRT123","mandate_request_currency":"GBP","mandate_request_metadata":{},"mandate_request_scheme":"bacs","mandate_request_verify":null,"metadata":{},"name":"12 Month Gold Plan","payment_request_amount":"1000","payment_request_currency":"GBP","payment_request_description":"Top-up Payment","payment_request_metadata":{},"payment_request_scheme":"bacs","redirect_uri":"https://my-website.com/abc/callback","updated_at":"2021-01-01T12:00:00.000Z"},{"authorisation_url":"https://pay.gocardless.com/BRT123","created_at":"2021-01-01T12:00:00.000Z","id":"BRT123","mandate_request_currency":"GBP","mandate_request_metadata":{},"mandate_request_scheme":"bacs","mandate_request_verify":null,"metadata":{},"name":"12 Month Gold Plan","payment_request_amount":"1000","payment_request_currency":"GBP","payment_request_description":"Top-up Payment","payment_request_metadata":{},"payment_request_scheme":"bacs","redirect_uri":"https://my-website.com/abc/callback","updated_at":"2021-01-01T12:00:00.000Z"}]}
"body": {"billing_request_templates":[{"authorisation_url":"https://pay.gocardless.com/BRT123","created_at":"2021-01-01T12:00:00.000Z","id":"BRT123","mandate_request_currency":"GBP","mandate_request_metadata":{},"mandate_request_scheme":"bacs","mandate_request_verify":null,"metadata":{},"name":"12 Month Gold Plan","payment_request_amount":"1000","payment_request_currency":"GBP","payment_request_description":"Top-up Payment","payment_request_metadata":{},"payment_request_scheme":"bacs","redirect_uri":"https://my-website.com/abc/callback","updated_at":"2021-01-01T12:00:00.000Z"},{"authorisation_url":"https://pay.gocardless.com/BRT123","created_at":"2021-01-01T12:00:00.000Z","id":"BRT123","mandate_request_currency":"GBP","mandate_request_metadata":{},"mandate_request_scheme":"bacs","mandate_request_verify":null,"metadata":{},"name":"12 Month Gold Plan","payment_request_amount":"1000","payment_request_currency":"GBP","payment_request_description":"Top-up Payment","payment_request_metadata":{},"payment_request_scheme":"bacs","redirect_uri":"https://my-website.com/abc/callback","updated_at":"2021-01-01T12:00:00.000Z"}],"meta":{"cursors":{"after":"example after 3632","before":"example before 8590"},"limit":50}}
},
"get": {
"method": "GET",
Expand Down
Loading

0 comments on commit e159de1

Please sign in to comment.