-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Silviana Ghita
committed
Sep 19, 2023
1 parent
740adbf
commit 0c9f63e
Showing
6 changed files
with
241 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |