Skip to content

Commit

Permalink
rename InstantConversion to Conversions
Browse files Browse the repository at this point in the history
added quote endpoints
  • Loading branch information
mihaimoiseanu committed Feb 21, 2024
1 parent c2500b8 commit d848c30
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 9 deletions.
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 Quote $quote
* @return Quote
*/
public function CreateQuote($quote)
{
return $this->CreateObject('create_conversion_quote', $quote, '\MangoPay\Quote');
}

/**
* This endpoint allows the platform to get the details of a quote
* @param string $quoteId
* @return Quote
*/
public function GetQuote($quoteId)
{
return $this->GetObject('get_conversion_quote', '\MangoPay\Quote', $quoteId);
}

}
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' => ['/conversion/rate/%s/%s', RequestType::GET],
'create_instant_conversion' => ['/instant-conversion', RequestType::POST],
'get_instant_conversion' => ['/instant-conversion/%s', RequestType::GET]
'get_instant_conversion' => ['/instant-conversion/%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
43 changes: 43 additions & 0 deletions MangoPay/Quote.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace MangoPay;

use MangoPay\Libraries\EntityBase;

class Quote 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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

use MangoPay\InstantConversion;
use MangoPay\Money;
use MangoPay\Quote;
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_createQuote(){
$response = $this->createQuote();

$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_getQuote(){
$quote = $this->createQuote();
$response = $this->_api->Conversions->GetQuote($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 @@ -68,6 +90,26 @@ private function createInstantConversion()

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

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

private function createQuote()
{

$quote = new Quote();
$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->CreateQuote($quote);

}
}

0 comments on commit d848c30

Please sign in to comment.