Skip to content

Commit

Permalink
Integrated Spot FX endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Silviana Ghita committed Sep 19, 2023
1 parent 740adbf commit 0c9f63e
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 1 deletion.
40 changes: 40 additions & 0 deletions MangoPay/ApiInstantConversion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace MangoPay;

/**
* Class to management MangoPay API for instant conversions
*/
class ApiInstantConversion extends Libraries\ApiBase
{
/**
* This endpoint allows the platform to get a real
* time indicative market rate of a specific currency pair.
* The rate returned is given in real time.
* @param string $debitedCurrency The sell currency – the currency of the wallet to be debited
* @param string $creditedCurrency The buy currency – the currency of the wallet to be credited.
* @return \MangoPay\ConversionRate object returned from API
*/
public function GetConversionRate($debitedCurrency, $creditedCurrency){
return $this->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);
}
}
34 changes: 34 additions & 0 deletions MangoPay/ConversionRate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace MangoPay;

/**
* Real time indicative market rate of a specific currency pair
*/
class ConversionRate extends Libraries\EntityBase
{
/**
* The sell currency – the currency of the wallet to be debited.
* @var string
*/
public $DebitedCurrency;

/**
* The buy currency – the currency of the wallet to be credited.
* @var string
*/
public $CreditedCurrency;

/**
* The market rate plus Mangopay's commission,
* charged during the platform's billing cycle. This is an indicative rate.
* @var string
*/
public $ClientRate;

/**
* The rate used for the conversion, excluding Mangopay's commission.
* @var string
*/
public $MarketRate;
}
86 changes: 86 additions & 0 deletions MangoPay/InstantConversion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace MangoPay;

class InstantConversion extends Libraries\EntityBase
{
/**
* The unique identifier of the user at the source of the transaction.
* @var string
*/
public $AuthorId;

/**
* The unique identifier of the debited wallet.
* @var string
*/
public $DebitedWalletId;

/**
* The unique identifier of the credited wallet
* @var string
*/
public $CreditedWalletId;

/**
* The sell funds
* @var Money
*/
public $DebitedFunds;


/**
* The buy funds
* @var Money
*/
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
*/
public $Nature;

/**
* The code indicates the result of the operation.
* This information is mostly used to handle errors or for filtering purposes.
* @var string
*/
public $ResultCode;

/**
* The explanation of the result code.
* @var string
*/
public $ResultMessage;

/**
* The date and time at which the status changed to SUCCEEDED,
* indicating that the transaction occurred.
* The statuses CREATED and FAILED return an ExecutionDate of null
* @var int
*/
public $ExecutionDate;
}
6 changes: 5 additions & 1 deletion MangoPay/Libraries/ApiBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,11 @@ protected function getLogger()

'deposits_create' => ['/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]
];

/**
Expand Down
7 changes: 7 additions & 0 deletions MangoPay/MangoPayApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ class MangoPayApi
*/
public $Deposits;

/**
* Provides Instant conversion API methods
* @var ApiInstantConversion
*/
public $InstantConversion;

/**
* Constructor
*/
Expand Down Expand Up @@ -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();
Expand Down
69 changes: 69 additions & 0 deletions tests/Cases/InstantConversionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace MangoPay\Tests\Cases;

use MangoPay\InstantConversion;
use MangoPay\Money;

class InstantConversionTest extends Base
{
public function test_getConversionRate()
{
$response = $this->_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);
}

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);
}

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);
}
}

0 comments on commit 0c9f63e

Please sign in to comment.