Skip to content

Commit a5ffeb4

Browse files
MRSH-1024 add custom markup to get exchange rate methods (#6)
## Added - exchange rate custom markup to config `SHIPPER_EXCHANGE_RATE_MARKUP_PERCENT` and `getRate` method [(MRSH-1024)](https://ego-digital.atlassian.net/browse/MRSH-1024);
1 parent 0cbb1b6 commit a5ffeb4

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Optional:
3737

3838
SHIPPER_EXCHANGE_RATE_FROM="EUR,USD"
3939
SHIPPER_EXCHANGE_RATE_TO="EUR,USD"
40+
SHIPPER_EXCHANGE_RATE_MARKUP_PERCENT=5
4041

4142

4243
## Usage

config/shipper-exchange-rate.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@
88
'from' => env('SHIPPER_EXCHANGE_RATE_FROM', ['EUR', 'USD', 'ILS']),
99

1010
'to' => env('SHIPPER_EXCHANGE_RATE_TO', ['EUR', 'USD']),
11+
12+
'markup_percent' => env('SHIPPER_EXCHANGE_RATE_MARKUP_PERCENT', 0),
1113
];

src/ShipperExchangeRate.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,17 @@ public function getRate(string $from, string $to): float
5656
$this->callAutoFetchCallback($from, $to);
5757
}
5858
}
59+
return $this->getRateWithMarkup($rate);
60+
}
5961

60-
return $rate;
62+
/**
63+
* @param float $rate
64+
* @return float
65+
*/
66+
public function getRateWithMarkup(float $rate): float
67+
{
68+
$markup = config('shipper-exchange-rate.markup_percent', 0);
69+
return $rate + ($rate * $markup / 100);
6170
}
6271

6372
/**

tests/SrcTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,21 @@ public function auto_add_currency(): void
6666
$this->assertGreaterThan(0, $rate);
6767
$this->assertEquals(['UAH', 'USD'], $test);
6868
}
69+
70+
/**
71+
* @test
72+
* @return void
73+
* @throws RatePairNotFoundException
74+
*/
75+
public function auto_add_currency_with_markup(): void
76+
{
77+
$exchange_rate_markup = 7.25;
78+
config(['shipper-exchange-rate.markup_percent' => $exchange_rate_markup]);
79+
$service = new ShipperExchangeRate();
80+
$this->assertEquals(0, DB::table('shipper_exchange_rates')->count());
81+
$rate = $service->getRate('UAH', 'USD');
82+
$this->assertGreaterThan(0, $rate);
83+
$origin_rate = $service->retrieveRate('UAH', 'USD');
84+
$this->assertEquals($exchange_rate_markup, $rate / $origin_rate * 100 - 100);
85+
}
6986
}

0 commit comments

Comments
 (0)