Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Changelog
## 4.1.0
* added `Castle\PaymentRequiredError` (`Castle_PaymentRequiredError`) for HTTP 402 responses

## 4.0.0
**BREAKING CHANGES:**

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ Whenever something unexpected happens, an [exception](lib/Castle/Errors.php) is
| `Castle_InternalServerError` | The Castle API returned a `5xx` response (triggers failover) |
| `Castle_ConfigurationError` | The Castle secret API key has not been set |
| `Castle_UnauthorizedError` | Wrong Castle API secret key |
| `Castle_PaymentRequiredError` | HTTP 402 response |
| `Castle_BadRequest` | The request was invalid. For example if a challenge is created without the user having MFA enabled. |
| `Castle_ForbiddenError` | The user has entered the wrong code too many times and a new challenge has to be requested. |
| `Castle_NotFoundError` | The resource requestd was not found. For example if a session has been revoked. |
Expand Down
2 changes: 1 addition & 1 deletion lib/Castle/Castle.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

abstract class Castle
{
const VERSION = '4.0.0';
const VERSION = '4.1.0';

const HEADER_COOKIE = 'Cookie';
const HEADER_USER_AGENT = 'User-Agent';
Expand Down
5 changes: 5 additions & 0 deletions lib/Castle/Errors.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ class InvalidRequestTokenError extends InvalidParametersError

}

class PaymentRequiredError extends ApiError
{

}

class WebhookVerificationError extends Error
{

Expand Down
2 changes: 2 additions & 0 deletions lib/Castle/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public function handleApiError($response, $status)
throw new BadRequest($msg, $type, $status);
case 401:
throw new UnauthorizedError($msg, $type, $status);
case 402:
throw new PaymentRequiredError($msg, $type, $status);
case 403:
throw new ForbiddenError($msg, $type, $status);
case 404:
Expand Down
2 changes: 2 additions & 0 deletions lib/aliases.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function castle_legacy_alias_map()
'Castle_NotFoundError' => 'Castle\\NotFoundError',
'Castle_InvalidParametersError' => 'Castle\\InvalidParametersError',
'Castle_InvalidRequestTokenError' => 'Castle\\InvalidRequestTokenError',
'Castle_PaymentRequiredError' => 'Castle\\PaymentRequiredError',
'Castle_WebhookVerificationError' => 'Castle\\WebhookVerificationError',
);
}
Expand Down Expand Up @@ -82,6 +83,7 @@ class_alias($target, $class);
'Castle\\NotFoundError',
'Castle\\InvalidParametersError',
'Castle\\InvalidRequestTokenError',
'Castle\\PaymentRequiredError',
'Castle\\WebhookVerificationError',
);

Expand Down
8 changes: 8 additions & 0 deletions test/ErrorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ public function testUnauthorized()
$this->request->send('GET', '/test');
}

public function testPaymentRequired()
{
Castle_RequestTransport::setResponse(402);

$this->expectException(Castle_PaymentRequiredError::class);
$this->request->send('GET', '/test');
}

public function testForbidden()
{
Castle_RequestTransport::setResponse(403);
Expand Down
2 changes: 1 addition & 1 deletion test/RequestContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function contextProvider() {
}

public function contextJsonProvider() {
return array(array('{"ip":"8.8.8.8","headers":{"User-Agent":"TestAgent","X-Castle-Client-Id":"1ccf8dee-904b-4d20-8a88-55ded468bcc5"},"library":{"name":"castle-php","version":"4.0.0"}}'));
return array(array('{"ip":"8.8.8.8","headers":{"User-Agent":"TestAgent","X-Castle-Client-Id":"1ccf8dee-904b-4d20-8a88-55ded468bcc5"},"library":{"name":"castle-php","version":"4.1.0"}}'));
}

/**
Expand Down
Loading