Skip to content

Commit

Permalink
added quoted conversions between client wallets
Browse files Browse the repository at this point in the history
  • Loading branch information
Iulian Masar committed Feb 11, 2025
1 parent 914939b commit 8d25db8
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 2 deletions.
21 changes: 19 additions & 2 deletions MangoPay/ApiConversions.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ public function CreateInstantConversion($instantConversion)
}

/**
* This call triggers an immediate conversion at the market rate, of the debited funds to the credited wallet at
* the market rate. A quote is not required for an instant conversion.
* This call triggers an immediate conversion at the market rate,
* of the debited funds to the credited wallet at the market rate.
* A quote is not required for an instant conversion.
*
* @param CreateClientWalletsInstantConversion $instantConversion
* @return \MangoPay\Conversion object returned from API
*/
Expand All @@ -53,6 +55,21 @@ public function CreateQuotedConversion($quotedConversion)
return $this->CreateObject('create_quoted_conversion', $quotedConversion, '\MangoPay\Conversion');
}

/**
* This call triggers a conversion at the rate defined in its quote.
* The debited funds (buy currency), credited funds (sell currency) and currencies are defined in the quote.
* The Client Wallets to debit and credit are defined in the conversion.
*
* Each quoted conversion requires a dedicated Quote object, linked in the QuoteId.*
*
* @param CreateClientWalletsQuotedConversion $quotedConversion
* @return Conversion
*/
public function CreateClientWalletsQuotedConversion($quotedConversion)
{
return $this->CreateObject('create_client_wallets_quoted_conversion', $quotedConversion, '\MangoPay\Conversion');
}

/**
* This endpoint allows the platform to get
* the details of a conversion which has been carried out.
Expand Down
45 changes: 45 additions & 0 deletions MangoPay/CreateClientWalletsQuotedConversion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?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 CreateClientWalletsQuotedConversion extends Dto
{
/**
* The unique identifier of the active quote which guaranteed the rate for the conversion.
* @var string
*/
public $QuoteId;

/**
* Allowed values: FEES, CREDIT
*
* <p>The type of the client wallet to be debited:</p>
* <p>FEES – Fees Wallet, for fees collected by the platform.</p>
* <p>CREDIT – Repudiation Wallet, for funds related to dispute management.</p>
* <p>The amount and currency of the debited funds are defined by the quote.</p>
* @var string
*/
public $DebitedWalletType;

/**
* Allowed values: FEES, CREDIT
*
* <p>The type of the client wallet to be credited:</p>
* <p>FEES – Fees Wallet, for fees collected by the platform.</p>
* <p>CREDIT – Repudiation Wallet, for funds related to dispute management.</p>
* <p>The amount and currency of the credited funds are defined by the quote.</p>
* @var string
*/
public $CreditedWalletType;

/**
* Custom data.
* @var string
*/
public $Tag;
}
1 change: 1 addition & 0 deletions MangoPay/Libraries/ApiBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ protected function getLogger()
'create_client_wallets_instant_conversion' => ['/clients/conversions/instant-conversion', RequestType::POST],
'create_instant_conversion' => ['/conversions/instant-conversion', RequestType::POST],
'create_quoted_conversion' => ['/conversions/quoted-conversion', RequestType::POST],
'create_client_wallets_quoted_conversion' => ['/clients/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
21 changes: 21 additions & 0 deletions tests/Cases/ConversionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use MangoPay\ConversionQuote;
use MangoPay\CreateClientWalletsInstantConversion;
use MangoPay\CreateClientWalletsQuotedConversion;
use MangoPay\CreateInstantConversion;
use MangoPay\CreateQuotedConversion;
use MangoPay\Money;
Expand Down Expand Up @@ -76,6 +77,13 @@ public function test_createQuotedConversion()
assertNotNull($response->QuoteId);
}

public function test_createClientWalletsQuotedConversion()
{
$response = $this->createClientWalletsQuotedConversion();
assertNotNull($response);
assertNotNull($response->QuoteId);
}

public function test_getQuotedConversion()
{
$createdQuotedConversion = $this->createQuotedConversion();
Expand Down Expand Up @@ -118,6 +126,19 @@ private function createQuotedConversion()
return $this->_api->Conversions->CreateQuotedConversion($quotedConversion);
}

private function createClientWalletsQuotedConversion()
{
$quote = $this->createConversionQuote();

$quotedConversion = new CreateClientWalletsQuotedConversion();
$quotedConversion->QuoteId = $quote->Id;
$quotedConversion->DebitedWalletType = 'FEES';
$quotedConversion->CreditedWalletType = 'CREDIT';
$quotedConversion->Tag = 'Created via the PHP SDK';

return $this->_api->Conversions->CreateClientWalletsQuotedConversion($quotedConversion);
}

private function createInstantConversion()
{
$john = $this->getJohn();
Expand Down

0 comments on commit 8d25db8

Please sign in to comment.