-
Notifications
You must be signed in to change notification settings - Fork 850
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for exchange_rates API requests
- Loading branch information
Showing
4 changed files
with
98 additions
and
0 deletions.
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_rates', | ||
'rates' => array('eur' => 0.845876), | ||
) | ||
); | ||
|
||
$currency = "usd"; | ||
$rates = ExchangeRate::retrieve($currency); | ||
$this->assertEquals('exchange_rates', $rates->object); | ||
} | ||
|
||
public function testList() | ||
{ | ||
$this->mockRequest( | ||
'GET', | ||
'/v1/exchange_rates', | ||
array(), | ||
array( | ||
'object' => 'list', | ||
'data' => array( | ||
array( | ||
'id' => 'eur', | ||
'object' => 'exchange_rates', | ||
'rates' => array('usd' => 1.18221), | ||
), | ||
array( | ||
'id' => 'usd', | ||
'object' => 'exchange_rates', | ||
'rates' => array('eur' => 0.845876), | ||
), | ||
), | ||
) | ||
); | ||
|
||
$listRates = ExchangeRate::all(); | ||
$this->assertTrue(is_array($listRates->data)); | ||
$this->assertEquals('exchange_rates', $listRates->data[0]->object); | ||
} | ||
} |