Skip to content

Commit

Permalink
Merge pull request #101 from gocardless/template-changes
Browse files Browse the repository at this point in the history
v4.4.0 - Added support for tax
  • Loading branch information
jasonlafferty authored Jul 14, 2020
2 parents bb76cb2 + c725144 commit 2537dcb
Show file tree
Hide file tree
Showing 21 changed files with 321 additions and 32 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ GoCardless supports webhooks, allowing you to receive real-time notifications wh

The client allows you to validate that a webhook you receive is genuinely from GoCardless, and to parse it into `GoCardlessPro\Resources\Event` objects which are easy to work with:

```ruby
```php
<?php
// When you create a webhook endpoint, you can specify a secret. When GoCardless sends
// you a webhook, it'll sign the body using that secret. Since only you and GoCardless
// you a webhook, it will sign the body using that secret. Since only you and GoCardless
// know the secret, you can check the signature and ensure that the webhook is truly
// from GoCardless.
//
Expand All @@ -247,8 +247,8 @@ try {
header("HTTP/1.1 200 OK");
} catch (GoCardlessPro\Core\Exception\InvalidSignatureException) {
// The webhook doesn't appear to be genuinely from GoCardless, as the signature
// included in the `Webhook-Signature` header doesn't match one computed with your
// webhook endpoint secret and the body
// included in the `Webhook-Signature` header doesn't match the one computed with
// your webhook endpoint secret and the body
header("HTTP/1.1 498 Invalid Token");
}
```
Expand Down
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": "4.3.0",
"version": "4.4.0",
"keywords": [
"gocardless",
"direct debit",
Expand Down
18 changes: 16 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' => '4.3.0',
'GoCardless-Client-Version' => '4.4.0',
'User-Agent' => $this->getUserAgent()
),
'http_errors' => false,
Expand Down Expand Up @@ -339,6 +339,20 @@ public function subscriptions()
return $this->subscriptions;
}

/**
* Service for interacting with tax rates
*
* @return Services\TaxRatesService
*/
public function taxRates()
{
if (!isset($this->tax_rates)) {
$this->tax_rates = new Services\TaxRatesService($this->api_client);
}

return $this->tax_rates;
}

private function getUrlForEnvironment($environment)
{
$environment_urls = array(
Expand Down Expand Up @@ -388,7 +402,7 @@ private function getUserAgent()
{
$curlinfo = curl_version();
$uagent = array();
$uagent[] = 'gocardless-pro-php/4.3.0';
$uagent[] = 'gocardless-pro-php/4.4.0';
$uagent[] = 'schema-version/2015-07-06';
$uagent[] = 'GuzzleHttp/' . \GuzzleHttp\Client::VERSION;
$uagent[] = 'php/' . phpversion();
Expand Down
8 changes: 5 additions & 3 deletions lib/Resources/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ class Payment extends BaseResource
* <strong>BECS</strong> - 30 characters<br /> <strong>BECS NZ</strong> - 12
* characters<br /> <strong>Betalingsservice</strong> - 30 characters<br />
* <strong>PAD</strong> - 12 characters<br /> <strong>SEPA</strong> - 140
* characters <p class='restricted-notice'><strong>Restricted</strong>: You
* can only specify a payment reference for Bacs payments (that is, when
* collecting from the UK) if you're on the <a
* characters<br /> Note that this reference must be unique (for each
* merchant) for the BECS scheme as it is a scheme requirement. <p
* class='restricted-notice'><strong>Restricted</strong>: You can only
* specify a payment reference for Bacs payments (that is, when collecting
* from the UK) if you're on the <a
* href='https://gocardless.com/pricing'>GoCardless Plus, Pro or Enterprise
* packages</a>.</p>
*/
Expand Down
11 changes: 10 additions & 1 deletion lib/Resources/Payout.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* @property-read $payout_type
* @property-read $reference
* @property-read $status
* @property-read $tax_currency
*/
class Payout extends BaseResource
{
Expand Down Expand Up @@ -60,7 +61,7 @@ class Payout extends BaseResource

/**
* Fees that have already been deducted from the payout amount in minor unit
* (e.g. pence in GBP, cents in EUR).
* (e.g. pence in GBP, cents in EUR), inclusive of tax if applicable.
*
* For each `late_failure_settled` or `chargeback_settled` action, we refund
* the transaction fees in a payout. This means that a payout can have a
Expand Down Expand Up @@ -117,4 +118,12 @@ class Payout extends BaseResource
*/
protected $status;

/**
* [ISO 4217](http://en.wikipedia.org/wiki/ISO_4217#Active_codes) code for
* the currency in which tax is paid out to the tax authorities of your tax
* jurisdiction. Currently “EUR”, “GBP”, for French or British merchants,
* this will be `null` if tax is not applicable <em>beta</em>
*/
protected $tax_currency;

}
19 changes: 15 additions & 4 deletions lib/Resources/PayoutItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*
* @property-read $amount
* @property-read $links
* @property-read $taxes
* @property-read $type
*/
class PayoutItem extends BaseResource
Expand All @@ -39,8 +40,17 @@ class PayoutItem extends BaseResource
protected $links;

/**
* The type of the credit (positive) or debit (negative) item in the payout.
* One of:
* An array of tax items <em>beta</em>
*
* Note: VAT applies to transaction and surcharge fees for merchants
* operating in the <a href="https://gocardless.com/legal/vat-faqs">UK</a>
* and <a href="https://gocardless.com/fr-fr/legal/faq-tva">France</a>.
*/
protected $taxes;

/**
* The type of the credit (positive) or debit (negative) item in the payout
* (inclusive of VAT if applicable). One of:
* <ul>
* <li>`payment_paid_out` (credit)</li>
* <li>`payment_failed` (debit): The payment failed to be processed.</li>
Expand All @@ -54,7 +64,7 @@ class PayoutItem extends BaseResource
* customer, and the funds have been returned to you.</li>
* <li>`gocardless_fee` (credit/debit): The fees that GoCardless charged for
* a payment. In the case of a payment failure or chargeback, these will
* appear as credits.</li>
* appear as credits. Will include taxes if applicable for merchants.</li>
* <li>`app_fee` (credit/debit): The optional fees that a partner may have
* taken for a payment. In the case of a payment failure or chargeback,
* these will appear as credits.</li>
Expand All @@ -64,7 +74,8 @@ class PayoutItem extends BaseResource
* or chargeback, these will appear as credits.</li>
* <li>`surcharge_fee` (credit/debit): GoCardless deducted a surcharge fee
* as the payment failed or was charged back, or refunded a surcharge fee as
* the bank or customer cancelled the chargeback.</li>
* the bank or customer cancelled the chargeback. Will include taxes if
* applicable for merchants.</li>
* </ul>
*/
protected $type;
Expand Down
8 changes: 5 additions & 3 deletions lib/Resources/Refund.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ class Refund extends BaseResource
* <strong>BECS</strong> - 30 characters<br /> <strong>BECS NZ</strong> - 12
* characters<br /> <strong>Betalingsservice</strong> - 30 characters<br />
* <strong>PAD</strong> - 12 characters<br /> <strong>SEPA</strong> - 140
* characters <p class='restricted-notice'><strong>Restricted</strong>: You
* can only specify a payment reference for Bacs payments (that is, when
* collecting from the UK) if you're on the <a
* characters<br /> Note that this reference must be unique (for each
* merchant) for the BECS scheme as it is a scheme requirement. <p
* class='restricted-notice'><strong>Restricted</strong>: You can only
* specify a payment reference for Bacs payments (that is, when collecting
* from the UK) if you're on the <a
* href='https://gocardless.com/pricing'>GoCardless Plus, Pro or Enterprise
* packages</a>.</p>
*/
Expand Down
57 changes: 57 additions & 0 deletions lib/Resources/TaxRate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?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 tax_rate, providing access to its
* attributes
*
* @property-read $end_date
* @property-read $id
* @property-read $jurisdiction
* @property-read $percentage
* @property-read $start_date
* @property-read $type
*/
class TaxRate extends BaseResource
{
protected $model_name = "TaxRate";

/**
* Date at which GoCardless stopped applying the tax rate for the
* jurisdiction.
*/
protected $end_date;

/**
* The unique identifier created by the jurisdiction, tax type and version
*/
protected $id;

/**
* The jurisdiction this tax rate applies to
*/
protected $jurisdiction;

/**
* The percentage of tax that is applied onto of GoCardless fees
*/
protected $percentage;

/**
* Date at which GoCardless started applying the tax rate in the
* jurisdiction.
*/
protected $start_date;

/**
* The type of tax applied by this rate
*/
protected $type;

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


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

protected $envelope_key = 'tax_rates';
protected $resource_class = '\GoCardlessPro\Resources\TaxRate';


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


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


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

/**
* Get a single tax rate
*
* Example URL: /tax_rates/:identity
*
* @param string $identity The unique identifier created by the jurisdiction, tax type
and version
* @param string[mixed] $params An associative array for any params
* @return TaxRate
**/
public function get($identity, $params = array())
{
$path = Util::subUrl(
'/tax_rates/: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 tax rates
*
* Example URL: /tax_rates
*
* @param string[mixed] $params
* @return Paginator
**/
public function all($params = array())
{
return new Paginator($this, $params);
}

}
1 change: 1 addition & 0 deletions tests/Integration/PayoutItemsIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function testPayoutItemsList()
$record = $records[$num];
$this->assertEquals($body[$num]->amount, $record->amount);
$this->assertEquals($body[$num]->links, $record->links);
$this->assertEquals($body[$num]->taxes, $record->taxes);
$this->assertEquals($body[$num]->type, $record->type);

}
Expand Down
3 changes: 3 additions & 0 deletions tests/Integration/PayoutsIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function testPayoutsList()
$this->assertEquals($body[$num]->payout_type, $record->payout_type);
$this->assertEquals($body[$num]->reference, $record->reference);
$this->assertEquals($body[$num]->status, $record->status);
$this->assertEquals($body[$num]->tax_currency, $record->tax_currency);

}

Expand Down Expand Up @@ -80,6 +81,7 @@ public function testPayoutsGet()
$this->assertEquals($body->payout_type, $response->payout_type);
$this->assertEquals($body->reference, $response->reference);
$this->assertEquals($body->status, $response->status);
$this->assertEquals($body->tax_currency, $response->tax_currency);


$expectedPathRegex = $this->extract_resource_fixture_path_regex($fixture);
Expand Down Expand Up @@ -112,6 +114,7 @@ public function testPayoutsUpdate()
$this->assertEquals($body->payout_type, $response->payout_type);
$this->assertEquals($body->reference, $response->reference);
$this->assertEquals($body->status, $response->status);
$this->assertEquals($body->tax_currency, $response->tax_currency);


$expectedPathRegex = $this->extract_resource_fixture_path_regex($fixture);
Expand Down
Loading

0 comments on commit 2537dcb

Please sign in to comment.