diff --git a/MangoPay/ApiInstantConversion.php b/MangoPay/ApiInstantConversion.php new file mode 100644 index 00000000..4bef5b6b --- /dev/null +++ b/MangoPay/ApiInstantConversion.php @@ -0,0 +1,40 @@ +GetObject('get_conversion_rate', '\MangoPay\ConversionRate', $debitedCurrency, $creditedCurrency); + } + + /** + * This endpoint allows the platform to move funds between two + * wallets of different currencies instantaneously. + * @return \MangoPay\InstantConversion object returned from API + */ + public function CreateInstantConversion($instantConversion){ + return $this->CreateObject('create_instant_conversion', $instantConversion, '\MangoPay\InstantConversion'); + } + + /** + * This endpoint allows the platform to get + * the details of a conversion which has been carried out. + * @param string $id The unique identifier of the conversion. + * @return \MangoPay\InstantConversion object returned from API + */ + public function GetInstantConversion($id){ + return $this->GetObject('get_instant_conversion', '\MangoPay\InstantConversion', $id); + } +} \ No newline at end of file diff --git a/MangoPay/ConversionRate.php b/MangoPay/ConversionRate.php new file mode 100644 index 00000000..f667d1db --- /dev/null +++ b/MangoPay/ConversionRate.php @@ -0,0 +1,34 @@ + ['/deposit-preauthorizations/card/direct', RequestType::POST], 'deposits_get' => ['/deposit-preauthorizations/%s', RequestType::GET], - 'deposits_cancel' => ['/deposit-preauthorizations/%s', RequestType::PUT] + 'deposits_cancel' => ['/deposit-preauthorizations/%s', RequestType::PUT], + + 'get_conversion_rate' => ['/conversion/rate/%s/%s', RequestType::GET], + 'create_instant_conversion' => ['/instant-conversion', RequestType::POST], + 'get_instant_conversion' => ['/instant-conversion/%s', RequestType::GET] ]; /** diff --git a/MangoPay/MangoPayApi.php b/MangoPay/MangoPayApi.php index 844c4b17..eae8122a 100644 --- a/MangoPay/MangoPayApi.php +++ b/MangoPay/MangoPayApi.php @@ -197,6 +197,12 @@ class MangoPayApi */ public $Deposits; + /** + * Provides Instant conversion API methods + * @var ApiInstantConversion + */ + public $InstantConversion; + /** * Constructor */ @@ -233,6 +239,7 @@ public function __construct() $this->Repudiations = new ApiRepudiations($this); $this->Regulatory = new ApiRegulatory($this); $this->Deposits = new ApiDeposits($this); + $this->InstantConversion = new ApiInstantConversion($this); // Setting default NullLogger $this->logger = new NullLogger(); diff --git a/MangoPay/TransactionType.php b/MangoPay/TransactionType.php index 5e90c162..ef6a714d 100644 --- a/MangoPay/TransactionType.php +++ b/MangoPay/TransactionType.php @@ -8,6 +8,7 @@ final class TransactionType const Transfer = 'TRANSFER'; const PayOut = 'PAYOUT'; const CardValidation = 'CARD_VALIDATION'; + const Conversion = 'CONVERSION'; private function __construct() { diff --git a/tests/Cases/InstantConversionTest.php b/tests/Cases/InstantConversionTest.php new file mode 100644 index 00000000..8bfdfbdb --- /dev/null +++ b/tests/Cases/InstantConversionTest.php @@ -0,0 +1,72 @@ +_api->InstantConversion->GetConversionRate('EUR', 'GBP'); + + $this->assertNotNull($response); + $this->assertNotNull($response->ClientRate); + $this->assertNotNull($response->MarketRate); + } + + public function test_createInstantConversion() + { + $response = $this->createInstantConversion(); + + $this->assertNotNull($response); + $this->assertNotNull($response->DebitedFunds->Amount); + $this->assertNotNull($response->CreditedFunds->Amount); + $this->assertSame('SUCCEEDED', $response->Status); + $this->assertSame(TransactionType::Conversion, $response->Type); + } + + public function test_getInstantConversion() + { + $instantConversion = $this->createInstantConversion(); + $returnedInstantConversion = $this->_api->InstantConversion->GetInstantConversion($instantConversion->Id); + + $this->assertNotNull($returnedInstantConversion); + $this->assertNotNull($returnedInstantConversion->DebitedFunds->Amount); + $this->assertNotNull($returnedInstantConversion->CreditedFunds->Amount); + $this->assertSame('SUCCEEDED', $returnedInstantConversion->Status); + $this->assertSame(TransactionType::Conversion, $returnedInstantConversion->Type); + } + + private function createInstantConversion() { + $john = $this->getJohn(); + $creditedWallet = new \MangoPay\Wallet(); + $creditedWallet->Owners = [$john->Id]; + $creditedWallet->Currency = 'GBP'; + $creditedWallet->Description = 'WALLET IN EUR WITH MONEY'; + + $creditedWallet = $this->_api->Wallets->Create($creditedWallet); + + $debitedWallet = $this->getJohnsWalletWithMoney(); + + $instantConversion = new InstantConversion(); + $instantConversion->AuthorId = $debitedWallet->Owners[0]; + $instantConversion->CreditedWalletId = $creditedWallet->Id; + $instantConversion->DebitedWalletId = $debitedWallet->Id; + + $creditedFunds = new Money(); + $creditedFunds->Currency = 'GBP'; + $instantConversion->CreditedFunds = $creditedFunds; + + $debitedFunds = new Money(); + $debitedFunds->Currency = 'EUR'; + $debitedFunds->Amount = 79; + $instantConversion->DebitedFunds = $debitedFunds; + + $instantConversion->Tag = "create instant conversion"; + + return $this->_api->InstantConversion->CreateInstantConversion($instantConversion); + } +} \ No newline at end of file