From 79fbdbd61540bcf17db1e7cab3f09deae968dab0 Mon Sep 17 00:00:00 2001 From: Olivier Bellone Date: Mon, 23 Oct 2017 15:47:06 +0200 Subject: [PATCH] Add support for exchange_rates API requests --- init.php | 1 + lib/ExchangeRate.php | 44 ++++++++++++++++++++++++++++++++ lib/Util/Util.php | 1 + tests/ExchangeRateTest.php | 52 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+) create mode 100644 lib/ExchangeRate.php create mode 100644 tests/ExchangeRateTest.php diff --git a/init.php b/init.php index d919fcd09..8dc6406a2 100644 --- a/init.php +++ b/init.php @@ -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'); diff --git a/lib/ExchangeRate.php b/lib/ExchangeRate.php new file mode 100644 index 000000000..a6a2b7d02 --- /dev/null +++ b/lib/ExchangeRate.php @@ -0,0 +1,44 @@ + 'Stripe\\Customer', 'dispute' => 'Stripe\\Dispute', 'ephemeral_key' => 'Stripe\\EphemeralKey', + 'exchange_rate' => 'Stripe\\ExchangeRate', 'list' => 'Stripe\\Collection', 'login_link' => 'Stripe\\LoginLink', 'invoice' => 'Stripe\\Invoice', diff --git a/tests/ExchangeRateTest.php b/tests/ExchangeRateTest.php new file mode 100644 index 000000000..507a60e24 --- /dev/null +++ b/tests/ExchangeRateTest.php @@ -0,0 +1,52 @@ +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); + } +}