Skip to content

Commit

Permalink
Merge pull request #182 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
jessezach authored May 23, 2024
2 parents 882efd6 + 7244584 commit a342e18
Show file tree
Hide file tree
Showing 39 changed files with 375 additions and 79 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.7.0",
"version": "5.8.0",
"keywords": [
"gocardless",
"direct debit",
Expand Down
34 changes: 32 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.7.0',
'GoCardless-Client-Version' => '5.8.0',
'User-Agent' => $this->getUserAgent()
),
'http_errors' => false,
Expand Down Expand Up @@ -102,6 +102,8 @@ public function __construct($config)

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

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

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

$this->services['mandate_imports'] = new Services\MandateImportsService($this->api_client);
Expand All @@ -114,6 +116,8 @@ public function __construct($config)

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

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

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

$this->services['payouts'] = new Services\PayoutsService($this->api_client);
Expand Down Expand Up @@ -336,6 +340,19 @@ public function institutions()
return $this->services['institutions'];
}

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

/**
* Service for interacting with mandates
*
Expand Down Expand Up @@ -414,6 +431,19 @@ public function payerAuthorisations()
return $this->services['payer_authorisations'];
}

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

/**
* Service for interacting with payments
*
Expand Down Expand Up @@ -619,7 +649,7 @@ private function getUserAgent()
{
$curlinfo = curl_version();
$uagent = array();
$uagent[] = 'gocardless-pro-php/5.7.0';
$uagent[] = 'gocardless-pro-php/5.8.0';
$uagent[] = 'schema-version/2015-07-06';
if (defined('\GuzzleHttp\Client::MAJOR_VERSION')) {
$uagent[] = 'GuzzleHttp/' . \GuzzleHttp\Client::MAJOR_VERSION;
Expand Down
25 changes: 25 additions & 0 deletions lib/Resources/Logo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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 logo, providing access to its
* attributes
*
* @property-read $id
*/
class Logo extends BaseResource
{
protected $model_name = "Logo";

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

}
25 changes: 25 additions & 0 deletions lib/Resources/PayerTheme.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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 payer_theme, providing access to its
* attributes
*
* @property-read $id
*/
class PayerTheme extends BaseResource
{
protected $model_name = "PayerTheme";

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

}
61 changes: 61 additions & 0 deletions lib/Services/LogosService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?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\Logo;
use \GoCardlessPro\Core\Exception\InvalidStateException;


/**
* Service that provides access to the Logo
* endpoints of the API
*
* @method createForCreditor()
*/
class LogosService extends BaseService
{

protected $envelope_key = 'logos';
protected $resource_class = '\GoCardlessPro\Resources\Logo';


/**
* Create a logo associated with a creditor
*
* Example URL: /creditors/:identity/branding/logos
*
* @param string $identity Unique identifier, beginning with "CR".
* @param string[mixed] $params An associative array for any params
* @return Logo
**/
public function createForCreditor($identity, $params = array())
{
$path = Util::subUrl(
'/creditors/:identity/branding/logos',
array(

'identity' => $identity
)
);
if(isset($params['params'])) {
$params['body'] = json_encode(array($this->envelope_key => (object)$params['params']));

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


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


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

}
61 changes: 61 additions & 0 deletions lib/Services/PayerThemesService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?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\PayerTheme;
use \GoCardlessPro\Core\Exception\InvalidStateException;


/**
* Service that provides access to the PayerTheme
* endpoints of the API
*
* @method createForCreditor()
*/
class PayerThemesService extends BaseService
{

protected $envelope_key = 'payer_themes';
protected $resource_class = '\GoCardlessPro\Resources\PayerTheme';


/**
* Create a payer theme associated with a creditor
*
* Example URL: /creditors/:identity/branding/payer_themes
*
* @param string $identity Unique identifier, beginning with "CR".
* @param string[mixed] $params An associative array for any params
* @return PayerTheme
**/
public function createForCreditor($identity, $params = array())
{
$path = Util::subUrl(
'/creditors/:identity/branding/payer_themes',
array(

'identity' => $identity
)
);
if(isset($params['params'])) {
$params['body'] = json_encode(array($this->envelope_key => (object)$params['params']));

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


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


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

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

namespace GoCardlessPro\Integration;

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

public function testLogosCreateForCreditor()
{
$fixture = $this->loadJsonFixture('logos')->create_for_creditor;
$this->stub_request($fixture);

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

$body = $fixture->body->logos;

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

$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());
}


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

namespace GoCardlessPro\Integration;

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

public function testPayerThemesCreateForCreditor()
{
$fixture = $this->loadJsonFixture('payer_themes')->create_for_creditor;
$this->stub_request($fixture);

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

$body = $fixture->body->payer_themes;

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

$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());
}


}
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": "POST",
"path_template": "/bank_authorisations",
"url_params": {},
"body": {"bank_authorisations":{"authorisation_type":"example authorisation_type 8081","authorised_at":"2020-01-01T12:00:00.000Z","created_at":"2024-01-18T10:46:40.090Z","expires_at":"2024-01-18T10:46:40.090Z","id":"BAU123","last_visited_at":"2020-01-01T12:00:00.000Z","links":{"billing_request":"BRQ123","institution":"monzo"},"qr_code_url":"https://pay.gocardless.com/obauth/BAU123/qr_code","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":"2024-05-23T09:00:16.718Z","expires_at":"2024-05-23T09:00:16.718Z","id":"BAU123","last_visited_at":"2020-01-01T12:00:00.000Z","links":{"billing_request":"BRQ123","institution":"monzo"},"qr_code_url":"https://pay.gocardless.com/obauth/BAU123/qr_code","redirect_uri":"https://my-website.com/abc/callback","url":"https://pay.gocardless.com/obauth/BAU123"}}
},
"get": {
"method": "GET",
"path_template": "/bank_authorisations/:identity",
"url_params": {"identity": "BAU123"},
"body": {"bank_authorisations":{"authorisation_type":"example authorisation_type 7887","authorised_at":"2020-01-01T12:00:00.000Z","created_at":"2024-01-18T10:46:40.090Z","expires_at":"2024-01-18T10:46:40.090Z","id":"BAU123","last_visited_at":"2020-01-01T12:00:00.000Z","links":{"billing_request":"BRQ123","institution":"monzo"},"qr_code_url":"https://pay.gocardless.com/obauth/BAU123/qr_code","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":"2024-05-23T09:00:16.718Z","expires_at":"2024-05-23T09:00:16.718Z","id":"BAU123","last_visited_at":"2020-01-01T12:00:00.000Z","links":{"billing_request":"BRQ123","institution":"monzo"},"qr_code_url":"https://pay.gocardless.com/obauth/BAU123/qr_code","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":false,"created_at":"2024-01-18T10:46:40.094Z","customer_details_captured":true,"exit_uri":"https://my-website.com/abc/callback","expires_at":"2024-01-18T10:46:40.094Z","id":"BRF123","language":"en","links":{"billing_request":"BRQ123"},"lock_bank_account":true,"lock_currency":true,"lock_customer_details":false,"prefilled_bank_account":{"account_type":"savings"},"prefilled_customer":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","danish_identity_number":"220550-6218","email":"[email protected]","family_name":"Osborne","given_name":"Frank","postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},"redirect_uri":"https://my-website.com/abc/callback","session_token":"sesh_123","show_redirect_buttons":false,"show_success_redirect_button":true}}
"body": {"billing_request_flows":{"authorisation_url":"https://monzo.com/abc-123-things","auto_fulfil":true,"created_at":"2024-05-23T09:00:16.721Z","customer_details_captured":true,"exit_uri":"https://my-website.com/abc/callback","expires_at":"2024-05-23T09:00:16.721Z","id":"BRF123","language":"en","links":{"billing_request":"BRQ123"},"lock_bank_account":false,"lock_currency":true,"lock_customer_details":true,"prefilled_bank_account":{"account_type":"savings"},"prefilled_customer":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","danish_identity_number":"220550-6218","email":"[email protected]","family_name":"Osborne","given_name":"Frank","postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},"redirect_uri":"https://my-website.com/abc/callback","session_token":"sesh_123","show_redirect_buttons":false,"show_success_redirect_button":false}}
},
"initialise": {
"method": "POST",
"path_template": "/billing_request_flows/:identity/actions/initialise",
"url_params": {"identity": "BRF123"},
"body": {"billing_request_flows":{"authorisation_url":"https://monzo.com/abc-123-things","auto_fulfil":false,"created_at":"2024-01-18T10:46:40.094Z","customer_details_captured":false,"exit_uri":"https://my-website.com/abc/callback","expires_at":"2024-01-18T10:46:40.094Z","id":"BRF123","language":"en","links":{"billing_request":"BRQ123"},"lock_bank_account":false,"lock_currency":true,"lock_customer_details":false,"prefilled_bank_account":{"account_type":"savings"},"prefilled_customer":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","danish_identity_number":"220550-6218","email":"[email protected]","family_name":"Osborne","given_name":"Frank","postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},"redirect_uri":"https://my-website.com/abc/callback","session_token":"sesh_123","show_redirect_buttons":false,"show_success_redirect_button":false}}
"body": {"billing_request_flows":{"authorisation_url":"https://monzo.com/abc-123-things","auto_fulfil":true,"created_at":"2024-05-23T09:00:16.721Z","customer_details_captured":true,"exit_uri":"https://my-website.com/abc/callback","expires_at":"2024-05-23T09:00:16.721Z","id":"BRF123","language":"en","links":{"billing_request":"BRQ123"},"lock_bank_account":false,"lock_currency":true,"lock_customer_details":true,"prefilled_bank_account":{"account_type":"savings"},"prefilled_customer":{"address_line1":"221B Baker Street","address_line2":"Marylebone","address_line3":"City of Westminster","city":"London","company_name":"Hamilton Trading Ltd.","country_code":"GB","danish_identity_number":"220550-6218","email":"[email protected]","family_name":"Osborne","given_name":"Frank","postal_code":"NW1 6XE","region":"Greater London","swedish_identity_number":"556564-5404"},"redirect_uri":"https://my-website.com/abc/callback","session_token":"sesh_123","show_redirect_buttons":true,"show_success_redirect_button":true}}
}
}

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_description":"Top-up Payment","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":"faster_payments","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_description":"Top-up Payment","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":"faster_payments","redirect_uri":"https://my-website.com/abc/callback","updated_at":"2021-01-01T12:00:00.000Z"}],"meta":{"cursors":{"after":"example after 4467","before":"example before 2286"},"limit":50}}
"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_description":"Top-up Payment","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":"faster_payments","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_description":"Top-up Payment","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":"faster_payments","redirect_uri":"https://my-website.com/abc/callback","updated_at":"2021-01-01T12:00:00.000Z"}],"meta":{"cursors":{"after":"example after 4983","before":"example before 8146"},"limit":50}}
},
"get": {
"method": "GET",
Expand Down
Loading

0 comments on commit a342e18

Please sign in to comment.