diff --git a/MangoPay/ApiConversions.php b/MangoPay/ApiConversions.php new file mode 100644 index 00000000..874299ff --- /dev/null +++ b/MangoPay/ApiConversions.php @@ -0,0 +1,75 @@ +GetObject('get_conversion_rate', '\MangoPay\ConversionRate', $debitedCurrency, $creditedCurrency); + } + + /** + * This endpoint allows the platform to move funds between two + * wallets of different currencies instantaneously. + * @param CreateInstantConversion $instantConversion + * @return \MangoPay\Conversion object returned from API + */ + public function CreateInstantConversion($instantConversion) + { + return $this->CreateObject('create_instant_conversion', $instantConversion, '\MangoPay\Conversion'); + } + + /** + * This call triggers a conversion, at the rate guaranteed by its quote, of the debited funds to the credited wallet. + * + * @param CreateQuotedConversion $quotedConversion + * @return Conversion + */ + public function CreateQuotedConversion($quotedConversion) + { + return $this->CreateObject('create_quoted_conversion', $quotedConversion, '\MangoPay\Conversion'); + } + + /** + * 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\Conversion object returned from API + */ + public function GetConversion($id) + { + return $this->GetObject('get_conversion', '\MangoPay\Conversion', $id); + } + + /** + * This call guarantees a conversion rate to let you Create a Quoted Conversion. + * @param ConversionQuote $quote + * @return ConversionQuote + */ + public function CreateConversionQuote($quote) + { + return $this->CreateObject('create_conversion_quote', $quote, '\MangoPay\ConversionQuote'); + } + + /** + * This endpoint allows the platform to get the details of a quote + * @param string $quoteId + * @return ConversionQuote + */ + public function GetConversionQuote($quoteId) + { + return $this->GetObject('get_conversion_quote', '\MangoPay\ConversionQuote', $quoteId); + } +} diff --git a/MangoPay/ApiInstantConversion.php b/MangoPay/ApiInstantConversion.php deleted file mode 100644 index b0263635..00000000 --- a/MangoPay/ApiInstantConversion.php +++ /dev/null @@ -1,43 +0,0 @@ -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); - } -} diff --git a/MangoPay/InstantConversion.php b/MangoPay/Conversion.php similarity index 80% rename from MangoPay/InstantConversion.php rename to MangoPay/Conversion.php index 781b78c2..cd8a6c11 100644 --- a/MangoPay/InstantConversion.php +++ b/MangoPay/Conversion.php @@ -2,8 +2,36 @@ namespace MangoPay; -class InstantConversion extends Libraries\EntityBase +class Conversion extends Libraries\EntityBase { + /** + * The unique identifier of the active quote which guaranteed the rate for the conversion. + * @var string + */ + public $QuoteId; + + /** + * The type of transaction + * @var string + * @see \MangoPay\TransactionType + */ + public $Type; + + /** + * The nature of the transaction, providing more + * information about the context in which the transaction occurred: + * @var string + * @see \MangoPay\TransactionNature + */ + public $Nature; + + /** + * The status of the transaction. + * @var string + * @see \MangoPay\TransactionStatus + */ + public $Status; + /** * The unique identifier of the user at the source of the transaction. * @var string @@ -36,32 +64,11 @@ class InstantConversion extends Libraries\EntityBase public $CreditedFunds; /** - * Real time indicative market rate of a specific currency pair - * @var ConversionRate - */ - public $ConversionRate; - - /** - * The status of the transaction. - * @var string - * @see \MangoPay\TransactionStatus - */ - public $Status; - - /** - * The type of transaction - * @var string - * @see \MangoPay\TransactionType - */ - public $Type; - - /** - * The nature of the transaction, providing more - * information about the context in which the transaction occurred: - * @var string - * @see \MangoPay\TransactionNature + * Information about the fees taken by the platform for + * this transaction (and hence transferred to the Fees Wallet). + * @var Money */ - public $Nature; + public $Fees; /** * The code indicates the result of the operation. @@ -83,4 +90,11 @@ class InstantConversion extends Libraries\EntityBase * @var int */ public $ExecutionDate; + + /** + * Real time indicative market rate of a specific currency pair + * @var ConversionRate + */ + public $ConversionRateResponse; + } diff --git a/MangoPay/ConversionQuote.php b/MangoPay/ConversionQuote.php new file mode 100644 index 00000000..54e0ddcf --- /dev/null +++ b/MangoPay/ConversionQuote.php @@ -0,0 +1,43 @@ + ['/deposit-preauthorizations/%s', RequestType::GET], '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] + 'get_conversion_rate' => ['/conversions/rate/%s/%s', RequestType::GET], + 'create_instant_conversion' => ['/conversions/instant-conversion', RequestType::POST], + 'create_quoted_conversion' => ['/conversions/quoted-conversion', RequestType::POST], + 'get_conversion' => ['/conversions/%s', RequestType::GET], + 'create_conversion_quote' => ['/conversions/quote', RequestType::POST], + 'get_conversion_quote' => ['/conversions/quote/%s', RequestType::GET], ]; /** diff --git a/MangoPay/Libraries/Configuration.php b/MangoPay/Libraries/Configuration.php index c262f7df..f1a4d949 100644 --- a/MangoPay/Libraries/Configuration.php +++ b/MangoPay/Libraries/Configuration.php @@ -42,7 +42,7 @@ class Configuration * [INTERNAL USAGE ONLY] * Switch debug mode: log all request and response data */ - public $DebugMode = false; + public $DebugMode = true; /** * Set the logging class if DebugMode is enabled diff --git a/MangoPay/MangoPayApi.php b/MangoPay/MangoPayApi.php index eae8122a..d2f588ec 100644 --- a/MangoPay/MangoPayApi.php +++ b/MangoPay/MangoPayApi.php @@ -199,9 +199,9 @@ class MangoPayApi /** * Provides Instant conversion API methods - * @var ApiInstantConversion + * @var ApiConversions */ - public $InstantConversion; + public $Conversions; /** * Constructor @@ -239,7 +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); + $this->Conversions = new ApiConversions($this); // Setting default NullLogger $this->logger = new NullLogger(); diff --git a/tests/Cases/ConversionsTest.php b/tests/Cases/ConversionsTest.php new file mode 100644 index 00000000..3bbbd4f2 --- /dev/null +++ b/tests/Cases/ConversionsTest.php @@ -0,0 +1,162 @@ +_api->Conversions->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->assertNotNull($response->Fees); + $this->assertSame('SUCCEEDED', $response->Status); + $this->assertSame(TransactionType::Conversion, $response->Type); + } + + public function test_getInstantConversion() + { + $instantConversion = $this->createInstantConversion(); + $returnedInstantConversion = $this->_api->Conversions->GetConversion($instantConversion->Id); + + $this->assertNotNull($returnedInstantConversion); + $this->assertNotNull($returnedInstantConversion->DebitedFunds->Amount); + $this->assertNotNull($returnedInstantConversion->CreditedFunds->Amount); + $this->assertNotNull($returnedInstantConversion->Fees); + $this->assertSame('SUCCEEDED', $returnedInstantConversion->Status); + $this->assertSame(TransactionType::Conversion, $returnedInstantConversion->Type); + } + + public function test_createConversionQuote() + { + $response = $this->createConversionQuote(); + + $this->assertNotNull($response); + $this->assertNotNull($response->DebitedFunds->Amount); + $this->assertNotNull($response->CreditedFunds->Amount); + $this->assertNotNull($response->ConversionRateResponse->ClientRate); + $this->assertSame('ACTIVE', $response->Status); + } + + public function test_getConversionQuote() + { + $quote = $this->createConversionQuote(); + $response = $this->_api->Conversions->GetConversionQuote($quote->Id); + + $this->assertNotNull($response); + $this->assertNotNull($response->DebitedFunds->Amount); + $this->assertNotNull($response->CreditedFunds->Amount); + $this->assertNotNull($response->ConversionRateResponse->ClientRate); + $this->assertSame('ACTIVE', $response->Status); + } + + public function test_createQuotedConversion() + { + $response = $this->createQuotedConversion(); + assertNotNull($response); + assertNotNull($response->QuoteId); + } + + public function test_getQuotedConversion(){ + $createdQuotedConversion = $this->createQuotedConversion(); + $response = $this->_api->Conversions->GetConversion($createdQuotedConversion->Id); + assertNotNull($response); + assertNotNull($response->QuoteId); + } + + private function createQuotedConversion() + { + $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(); + + $quote = $this->createConversionQuote(); + + $quotedConversion = new CreateQuotedConversion(); + $quotedConversion->QuoteId = $quote->Id; + $quotedConversion->AuthorId = $debitedWallet->Owners[0]; + $quotedConversion->CreditedWalletId = $creditedWallet->Id; + $quotedConversion->DebitedWalletId = $debitedWallet->Id; + + return $this->_api->Conversions->CreateQuotedConversion($quotedConversion); + } + + 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 CreateInstantConversion(); + $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; + + $fees = new Money(); + $fees->Currency = 'EUR'; + $fees->Amount = 9; + $instantConversion->Fees = $fees; + + $instantConversion->Tag = "create instant conversion"; + + return $this->_api->Conversions->CreateInstantConversion($instantConversion); + } + + private function createConversionQuote() + { + + $quote = new ConversionQuote(); + $creditedFunds = new Money(); + $creditedFunds->Currency = 'GBP'; + $quote->CreditedFunds = $creditedFunds; + + $debitedFunds = new Money(); + $debitedFunds->Currency = 'EUR'; + $debitedFunds->Amount = 50; + $quote->DebitedFunds = $debitedFunds; + + $quote->Duration = 90; + $quote->Tag = "Created using the Mangopay PHP SDK"; + + return $this->_api->Conversions->CreateConversionQuote($quote); + } +} diff --git a/tests/Cases/InstantConversionTest.php b/tests/Cases/InstantConversionTest.php deleted file mode 100644 index 78638a95..00000000 --- a/tests/Cases/InstantConversionTest.php +++ /dev/null @@ -1,73 +0,0 @@ -_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); - } -}