Skip to content

Commit

Permalink
Add support for exchange_rates API requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ob-stripe committed Oct 31, 2017
1 parent a523748 commit 77ffb5b
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
1 change: 1 addition & 0 deletions init.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
require(dirname(__FILE__) . '/lib/Dispute.php');
require(dirname(__FILE__) . '/lib/EphemeralKey.php');
require(dirname(__FILE__) . '/lib/Event.php');
require(dirname(__FILE__) . '/lib/ExchangeRate.php');
require(dirname(__FILE__) . '/lib/FileUpload.php');
require(dirname(__FILE__) . '/lib/Invoice.php');
require(dirname(__FILE__) . '/lib/InvoiceItem.php');
Expand Down
44 changes: 44 additions & 0 deletions lib/ExchangeRate.php
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);
}
}
1 change: 1 addition & 0 deletions lib/Util/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public static function convertToStripeObject($resp, $opts)
'customer' => 'Stripe\\Customer',
'dispute' => 'Stripe\\Dispute',
'ephemeral_key' => 'Stripe\\EphemeralKey',
'exchange_rate' => 'Stripe\\ExchangeRate',
'list' => 'Stripe\\Collection',
'login_link' => 'Stripe\\LoginLink',
'invoice' => 'Stripe\\Invoice',
Expand Down
52 changes: 52 additions & 0 deletions tests/ExchangeRateTest.php
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);
}
}

0 comments on commit 77ffb5b

Please sign in to comment.