Skip to content

Commit

Permalink
added quote conversion endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaimoiseanu committed Feb 21, 2024
1 parent d848c30 commit 54a0656
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 7 deletions.
11 changes: 11 additions & 0 deletions MangoPay/ApiConversions.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,15 @@ public function GetQuote($quoteId)
return $this->GetObject('get_conversion_quote', '\MangoPay\Quote', $quoteId);
}

/**
* This call triggers a conversion, at the rate guaranteed by its quote, of the debited funds to the credited wallet.
*
* @param QuotedConversion $quotedConversion
* @return QuotedConversion
*/
public function CreateQuotedConversion($quotedConversion)
{
return $this->CreateObject('create_quoted_conversion', $quotedConversion, '\MangoPay\QuotedConversion');
}

}
3 changes: 2 additions & 1 deletion MangoPay/Libraries/ApiBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ protected function getLogger()
'create_instant_conversion' => ['/instant-conversion', RequestType::POST],
'get_instant_conversion' => ['/instant-conversion/%s', RequestType::GET],
'create_conversion_quote' => ['/conversions/quote', RequestType::POST],
'get_conversion_quote' => ['/conversions/quote/%s', RequestType::GET]
'get_conversion_quote' => ['/conversions/quote/%s', RequestType::GET],
'create_quoted_conversion' => ['/conversions/quoted-conversion', RequestType::POST],
];

/**
Expand Down
21 changes: 21 additions & 0 deletions MangoPay/QuotedConversion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace MangoPay;

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

/**
* @var string
*/
var $QuoteId;

/**
* @var ConversionRate
*/
var $ConversionRateResponse;

}
40 changes: 34 additions & 6 deletions tests/Cases/ConversionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
use MangoPay\InstantConversion;
use MangoPay\Money;
use MangoPay\Quote;
use MangoPay\QuotedConversion;
use MangoPay\TransactionType;
use function PHPUnit\Framework\assertNotNull;

class ConversionsTest extends Base
{
Expand Down Expand Up @@ -41,7 +43,8 @@ public function test_getInstantConversion()
$this->assertSame(TransactionType::Conversion, $returnedInstantConversion->Type);
}

public function test_createQuote(){
public function test_createQuote()
{
$response = $this->createQuote();

$this->assertNotNull($response);
Expand All @@ -51,7 +54,8 @@ public function test_createQuote(){
$this->assertSame('ACTIVE', $response->Status);
}

public function test_getQuote(){
public function test_getQuote()
{
$quote = $this->createQuote();
$response = $this->_api->Conversions->GetQuote($quote->Id);

Expand All @@ -62,6 +66,31 @@ public function test_getQuote(){
$this->assertSame('ACTIVE', $response->Status);
}

public function test_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->createQuote();

$quotedConversion = new QuotedConversion();
$quotedConversion->QuoteId = $quote->Id;
$quotedConversion->AuthorId = $debitedWallet->Owners[0];
$quotedConversion->CreditedWalletId = $creditedWallet->Id;
$quotedConversion->DebitedWalletId = $debitedWallet->Id;

$response = $this->_api->Conversions->CreateQuotedConversion($quotedConversion);

assertNotNull($response);
}

private function createInstantConversion()
{
$john = $this->getJohn();
Expand Down Expand Up @@ -98,18 +127,17 @@ private function createQuote()

$quote = new Quote();
$creditedFunds = new Money();
$creditedFunds->Currency = 'USD';
$creditedFunds->Currency = 'GBP';
$quote->CreditedFunds = $creditedFunds;

$debitedFunds = new Money();
$debitedFunds->Currency = 'GBP';
$debitedFunds->Amount = 1000;
$debitedFunds->Currency = 'EUR';
$debitedFunds->Amount = 50;
$quote->DebitedFunds = $debitedFunds;

$quote->Duration = 90;
$quote->Tag = "Created using the Mangopay PHP SDK";

return $this->_api->Conversions->CreateQuote($quote);

}
}

0 comments on commit 54a0656

Please sign in to comment.