Skip to content

takkie-halimi/Updated-Commission-Fee-Calculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Commission Fee Calculator

An experimental Dev-Task that parses operations from a csv file and calculates commission fees.

Installation

Clone repository and install dependencies via composer.

 composer install --no-dev  

Usage

<?php

require_once __DIR__ . '/vendor/autoload.php';

use Payme\CommissionFeeCalculator\OperationCollection;
use Payme\CommissionFeeCalculator\Services\CurrencyService;
use Payme\CommissionFeeCalculator\Services\CommissionService;
use Payme\CommissionFeeCalculator\Exceptions\InvalidCurrencyException;
use Payme\CommissionFeeCalculator\Exceptions\InvalidOperationTypeException;
use Payme\CommissionFeeCalculator\Exceptions\InvalidUserTypeException;

// Initialize CURL:
$API_URL = curl_init('https://developers.paysera.com/tasks/api/currency-exchange-rates');
curl_setopt($API_URL, CURLOPT_RETURNTRANSFER, true);

// Store the data:
$json = curl_exec($API_URL);
curl_close($API_URL);

// Decode JSON response:
$jsonCurrencies = json_decode($json, true);


$currencies  = [];
foreach ($jsonCurrencies['rates'] as $key => $value) {
    $currencies[] = array('symbol' => $key, 'rate' => $value);
}

    $currencyService = new CurrencyService();
    $currencyService->collectCurrenciesFromArray($currencies);

    $collection = new OperationCollection();
try {
    $collection->parseFromCSV($argv[1]);
} catch (Exception $e) {
}

    $commissionService = new CommissionService($currencyService);

try {
    foreach ($commissionService->calculateFeesFromCollection($collection) as $fee) {
        echo $fee . PHP_EOL;
    }
} catch (InvalidCurrencyException|InvalidOperationTypeException|InvalidUserTypeException $e) {
}

Demo

 php main.php input.csv

Tests

Install dev dependencies via composer and run tests.

 composer install --dev
 ./vendor/bin/phpunit tests

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages