Skip to content

Commit

Permalink
Merge pull request #632 from Mangopay/feature/quoted_conversion
Browse files Browse the repository at this point in the history
Quoted conversion
  • Loading branch information
mihaimoiseanu authored Mar 7, 2024
2 parents eb8ff0d + f795725 commit 0af54bd
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 6 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 GetConversionQuote($quoteId)
return $this->GetObject('get_conversion_quote', '\MangoPay\ConversionQuote', $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');
}

}
1 change: 1 addition & 0 deletions MangoPay/Libraries/ApiBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ protected function getLogger()
'get_instant_conversion' => ['/conversions/%s', RequestType::GET],
'create_conversion_quote' => ['/conversions/quote', RequestType::POST],
'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;

}
41 changes: 35 additions & 6 deletions tests/Cases/ConversionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
use MangoPay\ConversionQuote;
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 +44,8 @@ public function test_getInstantConversion()
$this->assertSame(TransactionType::Conversion, $returnedInstantConversion->Type);
}

public function test_createConversionQuote(){
public function test_createConversionQuote()
{
$response = $this->createConversionQuote();

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

public function test_getConversionQuote(){
public function test_getConversionQuote()
{
$quote = $this->createConversionQuote();
$response = $this->_api->Conversions->GetConversionQuote($quote->Id);

Expand All @@ -62,6 +67,31 @@ public function test_getConversionQuote(){
$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 @@ -103,18 +133,17 @@ private function createConversionQuote()

$quote = new ConversionQuote();
$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->CreateConversionQuote($quote);

}
}

0 comments on commit 0af54bd

Please sign in to comment.