Skip to content

Commit c583448

Browse files
Adds conversion date preference parameter (#92)
* Updates detailed rates endpoint with conversion date preference parameter * Updates conversions create endpoint with conversion date preference parameter
1 parent f514961 commit c583448

File tree

7 files changed

+154
-3
lines changed

7 files changed

+154
-3
lines changed

src/EntryPoint/ConversionsEntryPoint.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ public function create(
5656
'client_buy_amount' => $conversion->getClientBuyAmount(),
5757
'client_sell_amount' => $conversion->getClientSellAmount(),
5858
'unique_request_id' => $conversion->getUniqueRequestId(),
59-
'on_behalf_of' => $onBehalfOf
59+
'on_behalf_of' => $onBehalfOf,
60+
'conversion_date_preference' => $conversion->getConversionDatePreference()
6061
]
6162
);
6263

src/EntryPoint/RatesEntryPoint.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function multiple($currencyPairs, $ignoreInvalidPairs = null, $onBehalfOf
4646
* @param string $amount
4747
* @param DateTime|null $conversionDate
4848
* @param null|string $onBehalfOf
49+
* @param null|string $conversionDatePreference
4950
*
5051
* @return DetailedRate
5152
*/
@@ -55,7 +56,8 @@ public function detailed(
5556
$fixedSide,
5657
$amount,
5758
DateTime $conversionDate = null,
58-
$onBehalfOf = null
59+
$onBehalfOf = null,
60+
$conversionDatePreference = null
5961
) {
6062
$response = $this->request(
6163
'GET',
@@ -66,7 +68,8 @@ public function detailed(
6668
'fixed_side' => $fixedSide,
6769
'amount' => $amount,
6870
'conversion_date' => (null === $conversionDate) ? null : $conversionDate->format('Y-m-d'),
69-
'on_behalf_of' => $onBehalfOf
71+
'on_behalf_of' => $onBehalfOf,
72+
'conversion_date_preference' => $conversionDatePreference
7073
]
7174
);
7275
return $this->createDetailedRateFromResponse($response);

src/Model/Conversion.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ class Conversion
125125
* @var String
126126
*/
127127
private $uniqueRequestId;
128+
/**
129+
* @var String
130+
*/
131+
private $conversionDatePreference;
128132

129133
/**
130134
* @param string $buyCurrency
@@ -688,4 +692,23 @@ public function setUniqueRequestId($uniqueRequestId)
688692
$this->uniqueRequestId = $uniqueRequestId;
689693
return $this;
690694
}
695+
696+
/**
697+
* @return string
698+
*/
699+
public function getConversionDatePreference()
700+
{
701+
return $this->conversionDatePreference;
702+
}
703+
704+
/**
705+
* @param string $conversionDatePreference
706+
*
707+
* @return $this
708+
*/
709+
public function setConversionDatePreference($conversionDatePreference)
710+
{
711+
$this->conversionDatePreference = $conversionDatePreference;
712+
return $this;
713+
}
691714
}

tests/EntryPoint/ConversionsEntryPointTest.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,4 +539,75 @@ public function canRetrieveConversionCancellationQuote(){
539539
$this->assertSame($dummy['amount'], $conversionConversionCancellationQuote->getAmount());
540540
$this->assertSame($dummy['currency'], $conversionConversionCancellationQuote->getCurrency());
541541
}
542+
543+
544+
/**
545+
* @test
546+
*/
547+
public function canCreateConversionWithConversionDatePreference()
548+
{
549+
550+
$data = '{
551+
"id": "d56d7553-19ab-4cde-b44b-79cac86989cb",
552+
"settlement_date": "2020-05-19T13:30:00+00:00",
553+
"conversion_date": "2020-05-19T00:00:00+00:00",
554+
"short_reference": "20200519-XYLXJL",
555+
"creator_contact_id": "42a6af4a-65b8-4721-43d9-7f395da2551e",
556+
"account_id": "3f22044f-ae21-42a1-bc4f-cd0370b008a5",
557+
"currency_pair": "EURGBP",
558+
"status": "awaiting_funds",
559+
"buy_currency": "EUR",
560+
"sell_currency": "GBP",
561+
"client_buy_amount": "1000.00",
562+
"client_sell_amount": "805.90",
563+
"fixed_side": "buy",
564+
"core_rate": "0.8059",
565+
"partner_rate": "",
566+
"partner_status": "funds_arrived",
567+
"partner_buy_amount": "0.00",
568+
"partner_sell_amount": "0.00",
569+
"client_rate": "0.8059",
570+
"deposit_required": false,
571+
"deposit_amount": "0.00",
572+
"deposit_currency": "",
573+
"deposit_status": "not_required",
574+
"deposit_required_at": "",
575+
"payment_ids": [],
576+
"unallocated_funds": "1000.00",
577+
"unique_request_id": null,
578+
"created_at": "2020-05-19T12:31:43+00:00",
579+
"updated_at": "2020-05-19T12:31:43+00:00",
580+
"mid_market_rate": "0.8058"
581+
}';
582+
583+
$entryPoint = new ConversionsEntryPoint($this->getMockedClient(
584+
json_decode($data),
585+
'POST',
586+
'conversions/create',
587+
[],
588+
[
589+
'buy_currency' => 'EUR',
590+
'sell_currency' => 'GBP',
591+
'fixed_side' => 'buy',
592+
'amount' => '1000',
593+
'term_agreement' => 'true',
594+
'conversion_date_preference' => 'earliest',
595+
'reason' => null,
596+
'conversion_date' => null,
597+
'client_buy_amount' => null,
598+
'client_sell_amount' => null,
599+
'unique_request_id' => null,
600+
'on_behalf_of' => null
601+
602+
]
603+
));
604+
605+
$conversion = Conversion::create('EUR', 'GBP', 'buy')->setConversionDatePreference('earliest');
606+
$createdConversion = $entryPoint->create($conversion, 1000, null, true);
607+
608+
$this->assertTrue($createdConversion instanceof Conversion);
609+
$this->assertSame('805.90', $createdConversion->getClientSellAmount());
610+
$this->assertSame('2020-05-19T13:30:00+00:00', $createdConversion->getSettlementDate()->format(DateTime::RFC3339));
611+
612+
}
542613
}

tests/VCR/Conversions/Test.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace CurrencyCloud\tests\VCR\Conversions;
33

44
use CurrencyCloud\Criteria\ConversionProfitLossCriteria;
5+
use CurrencyCloud\Model\Conversion;
56
use CurrencyCloud\Model\Pagination;
67
use CurrencyCloud\Tests\BaseCurrencyCloudVCRTestCase;
78
use DateTime;
@@ -145,4 +146,5 @@ public function canRetrieveConversionCancellationQuote(){
145146
$this->assertSame($dummy['amount'], $conversionCancellationQuote->getAmount());
146147
$this->assertSame($dummy['currency'], $conversionCancellationQuote->getCurrency());
147148
}
149+
148150
}

tests/VCR/Rates/Test.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,24 @@ public function canProvidedDetailedRate()
4949
);
5050
$this->validateObjectStrictName($detailedRate, $dummy);
5151
}
52+
53+
/**
54+
* @vcr Rates/can_provided_detailed_rate_with_conversion_date_preference.yaml
55+
* @test
56+
*/
57+
public function canProvidedDetailedRateWithConversionDatePreference()
58+
{
59+
60+
$detailedRate = $this->getAuthenticatedClient()->rates()->detailed('GBP', 'USD',
61+
'buy', 10000, null, null, "conversion_date_preference");
62+
63+
$this->assertTrue($detailedRate instanceof DetailedRate);
64+
65+
$dummy = json_decode(
66+
'{"settlement_cut_off_time": "2020-05-21T14:00:00Z","currency_pair": "GBPUSD","client_buy_currency": "GBP","client_sell_currency": "USD","client_buy_amount": "10000.00","client_sell_amount": "14081.00","fixed_side": "buy","client_rate": "1.4081","partner_rate": null,"core_rate": "1.4081","deposit_required": false,"deposit_amount": "0.0","deposit_currency": "USD","mid_market_rate": "1.4080"}',
67+
true
68+
);
69+
$this->validateObjectStrictName($detailedRate, $dummy);
70+
}
71+
5272
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
-
2+
request:
3+
method: GET
4+
url: https://devapi.currencycloud.com/v2/rates/detailed?buy_currency=GBP&sell_currency=USD&fixed_side=buy&amount=10000&conversion_date_preference=optimize_liquidity
5+
body: ''
6+
headers:
7+
X-Auth-Token: 038022bcd2f372cac7bab448db7b5c3b
8+
response:
9+
status: 200
10+
headers:
11+
Date: Tue, 19 May 2020 11:32:53 GMT
12+
Content-Type: application/json
13+
Content-Length: '377'
14+
X-Request-Id: '2773737871964103057'
15+
X-Content-Type-Options:
16+
body: '{
17+
"settlement_cut_off_time": "2020-05-21T14:00:00Z",
18+
"currency_pair": "GBPUSD",
19+
"client_buy_currency": "GBP",
20+
"client_sell_currency": "USD",
21+
"client_buy_amount": "10000.00",
22+
"client_sell_amount": "14081.00",
23+
"fixed_side": "buy",
24+
"client_rate": "1.4081",
25+
"partner_rate": null,
26+
"core_rate": "1.4081",
27+
"deposit_required": false,
28+
"deposit_amount": "0.0",
29+
"deposit_currency": "USD",
30+
"mid_market_rate": "1.4080"
31+
}'

0 commit comments

Comments
 (0)