Skip to content

Commit

Permalink
Merge pull request #635 from Mangopay/feature/conversions
Browse files Browse the repository at this point in the history
Conversions
  • Loading branch information
iulian03 authored Mar 8, 2024
2 parents c2500b8 + fe49ef5 commit ebbbd28
Show file tree
Hide file tree
Showing 11 changed files with 425 additions and 149 deletions.
75 changes: 75 additions & 0 deletions MangoPay/ApiConversions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace MangoPay;

/**
* Class to management MangoPay API for instant conversions
*/
class ApiConversions 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.
* @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);
}
}
43 changes: 0 additions & 43 deletions MangoPay/ApiInstantConversion.php

This file was deleted.

66 changes: 40 additions & 26 deletions MangoPay/InstantConversion.php → MangoPay/Conversion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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;

}
43 changes: 43 additions & 0 deletions MangoPay/ConversionQuote.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace MangoPay;

use MangoPay\Libraries\EntityBase;

class ConversionQuote extends EntityBase
{
/**
* Expiration date
* @var int
*/
public $ExpirationDate;

/**
* @var string
* @see \MangoPay\TransactionStatus
*/
public $Status;

/**
* The time in seconds during which the quote is active and can be used for conversions.
* @var int
*/
public $Duration;

/**
* Debited funds
* @var \MangoPay\Money
*/
public $DebitedFunds;

/**
* Credited funds
* @var \MangoPay\Money
*/
public $CreditedFunds;

/**
* @var ConversionRate
*/
var $ConversionRateResponse;
}
53 changes: 53 additions & 0 deletions MangoPay/CreateInstantConversion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace MangoPay;

use MangoPay\Libraries\Dto;

class CreateInstantConversion extends Dto
{

/**
* The unique identifier of the user at the source of the transaction.
* @var string
*/
var $AuthorId;

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

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

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

/**
* The buy funds
* @var Money
*/
var $CreditedFunds;

/**
* Information about the fees taken by the platform for this transaction (and hence transferred to the Fees Wallet).
* @var Money
*/
var $Fees;

/**
* Custom data.
* @var string
*/
var $Tag;

}
42 changes: 42 additions & 0 deletions MangoPay/CreateQuotedConversion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace MangoPay;

use MangoPay\Libraries\Dto;

/**
* A conversion, at the rate guaranteed by its quote, of the debited funds to the credited wallet.
*/
class CreateQuotedConversion extends Dto
{

/**
* The unique identifier of the active quote which guaranteed the rate for the conversion.
* @var string
*/
var $QuoteId;

/**
* The unique identifier of the user at the source of the transaction.
* @var string
*/
var $AuthorId;

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

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

/**
* Custom data.
* @var string
*/
var $Tag;
}
9 changes: 6 additions & 3 deletions MangoPay/Libraries/ApiBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,12 @@ protected function getLogger()
'deposits_get' => ['/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],
];

/**
Expand Down
2 changes: 1 addition & 1 deletion MangoPay/Libraries/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions MangoPay/MangoPayApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ class MangoPayApi

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

/**
* Constructor
Expand Down Expand Up @@ -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();
Expand Down
Loading

0 comments on commit ebbbd28

Please sign in to comment.