Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversions Quote #631

Merged
merged 3 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Class to management MangoPay API for instant conversions
*/
class ApiInstantConversion extends Libraries\ApiBase
class ApiConversions extends Libraries\ApiBase
{
/**
* This endpoint allows the platform to get a real
Expand Down Expand Up @@ -40,4 +40,25 @@ public function GetInstantConversion($id)
{
return $this->GetObject('get_instant_conversion', '\MangoPay\InstantConversion', $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: 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;
}
4 changes: 3 additions & 1 deletion MangoPay/Libraries/ApiBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ protected function getLogger()

'get_conversion_rate' => ['/conversions/rate/%s/%s', RequestType::GET],
'create_instant_conversion' => ['/conversions/instant-conversion', RequestType::POST],
'get_instant_conversion' => ['/conversions/%s', RequestType::GET]
'get_instant_conversion' => ['/conversions/%s', RequestType::GET],
'create_conversion_quote' => ['/conversions/quote', RequestType::POST],
'get_conversion_quote' => ['/conversions/quote/%s', RequestType::GET],
];

/**
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

namespace MangoPay\Tests\Cases;

use MangoPay\ConversionQuote;
use MangoPay\InstantConversion;
use MangoPay\Money;
use MangoPay\TransactionType;

class InstantConversionTest extends Base
class ConversionsTest extends Base
{
public function test_getConversionRate()
{
$response = $this->_api->InstantConversion->GetConversionRate('EUR', 'GBP');
$response = $this->_api->Conversions->GetConversionRate('EUR', 'GBP');

$this->assertNotNull($response);
$this->assertNotNull($response->ClientRate);
Expand All @@ -31,7 +32,7 @@ public function test_createInstantConversion()
public function test_getInstantConversion()
{
$instantConversion = $this->createInstantConversion();
$returnedInstantConversion = $this->_api->InstantConversion->GetInstantConversion($instantConversion->Id);
$returnedInstantConversion = $this->_api->Conversions->GetInstantConversion($instantConversion->Id);

$this->assertNotNull($returnedInstantConversion);
$this->assertNotNull($returnedInstantConversion->DebitedFunds->Amount);
Expand All @@ -40,6 +41,27 @@ public function test_getInstantConversion()
$this->assertSame(TransactionType::Conversion, $returnedInstantConversion->Type);
}

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

$this->assertNotNull($response);
$this->assertNotNull($response->DebitedFunds->Amount);
$this->assertNotNull($response->CreditedFunds->Amount);
$this->assertNotNull($response->ConversionRateResponse->ClientRate);
$this->assertSame('ACTIVE', $response->Status);
}

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

$this->assertNotNull($response);
$this->assertNotNull($response->DebitedFunds->Amount);
$this->assertNotNull($response->CreditedFunds->Amount);
$this->assertNotNull($response->ConversionRateResponse->ClientRate);
$this->assertSame('ACTIVE', $response->Status);
}

private function createInstantConversion()
{
$john = $this->getJohn();
Expand Down Expand Up @@ -73,6 +95,26 @@ private function createInstantConversion()

$instantConversion->Tag = "create instant conversion";

return $this->_api->InstantConversion->CreateInstantConversion($instantConversion);
return $this->_api->Conversions->CreateInstantConversion($instantConversion);
}

private function createConversionQuote()
{

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

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

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

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

}
}
Loading