-
Notifications
You must be signed in to change notification settings - Fork 863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for exchange_rates API requests #386
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace Stripe; | ||
|
||
/** | ||
* Class ExchangeRate | ||
* | ||
* @package Stripe | ||
*/ | ||
class ExchangeRate extends ApiResource | ||
{ | ||
/** | ||
* This is a special case because the exchange rates endpoint has an | ||
* underscore in it. The parent `className` function strips underscores. | ||
* | ||
* @return string The name of the class. | ||
*/ | ||
public static function className() | ||
{ | ||
return 'exchange_rate'; | ||
} | ||
|
||
/** | ||
* @param array|string $currency | ||
* @param array|string|null $opts | ||
* | ||
* @return ExchangeRate | ||
*/ | ||
public static function retrieve($currency, $opts = null) | ||
{ | ||
return self::_retrieve($currency, $opts); | ||
} | ||
|
||
/** | ||
* @param array|null $params | ||
* @param array|string|null $opts | ||
* | ||
* @return ExchangeRate | ||
*/ | ||
public static function all($params = null, $opts = null) | ||
{ | ||
return self::_all($params, $opts); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace Stripe; | ||
|
||
class ExchangeRateTest extends TestCase | ||
{ | ||
public function testRetrieve() | ||
{ | ||
$this->mockRequest( | ||
'GET', | ||
'/v1/exchange_rates/usd', | ||
array(), | ||
array( | ||
'id' => 'usd', | ||
'object' => 'exchange_rate', | ||
'rates' => array('eur' => 0.845876), | ||
) | ||
); | ||
|
||
$currency = "usd"; | ||
$rates = ExchangeRate::retrieve($currency); | ||
$this->assertEquals('exchange_rate', $rates->object); | ||
} | ||
|
||
public function testList() | ||
{ | ||
$this->mockRequest( | ||
'GET', | ||
'/v1/exchange_rates', | ||
array(), | ||
array( | ||
'object' => 'list', | ||
'data' => array( | ||
array( | ||
'id' => 'eur', | ||
'object' => 'exchange_rate', | ||
'rates' => array('usd' => 1.18221), | ||
), | ||
array( | ||
'id' => 'usd', | ||
'object' => 'exchange_rate', | ||
'rates' => array('eur' => 0.845876), | ||
), | ||
), | ||
) | ||
); | ||
|
||
$listRates = ExchangeRate::all(); | ||
$this->assertTrue(is_array($listRates->data)); | ||
$this->assertEquals('exchange_rate', $listRates->data[0]->object); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really wish we could do
$this->assertInstanceOf(ExchangeRate::class, $rates);
here instead, but unfortunately that doesn't fly with PHP <= 5.4 😢There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh ...
Well, it's worth noting that 5.4 has been EOLed for more than two years (since mid-2015) and hasn't even been receiving security fixes for more than a year, which means that it's not safe to use. This approach works fine for now, but it's totally plausible to drop support for it at this point. (If you're not updating off of PHP 5.4, you're also probably not bothering to update your version of stripe-php.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I misread that. It's 5.5 has been EOLed for two years and hasn't been receiving updates for a year.
5.4 has been EOLed for three years (mid-2014) and hasn't been receiving updates for two years!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
http://php.net/supported-versions.php