Note: you will have to do part one before part two however, we strongly recommend reading both parts before starting the problem as part two is an extension of part one. All test cases will not pass until both part one and part two are completed.
Part One
Stripe processes charges on behalf of a merchant, takes a fee for processing the charges, and later sends the remaining funds to the merchant. The sending of funds to a merchant is referred to as a
"payout"
. Payouts can only be sent in the
currencies of the merchant's bank accounts.
Therefore, if the merchant processes charges in a currency that they don't have a bank account for, Stripe has to exchange (FX) the funds to the bank account currency first. For example, my online t-shirt business has expanded from the U.S. to parts of Europe so l allow my European customers to pay in Euro (€). However, I still only have a bank account in U.S. Dollars ($) where Stripe sends me the funds from my business sales. Therefore Stripe will exchange any Euro charges to U.S. Dollars before sending a payout to my U.S. Dollar bank account.Complete the function calculate_payouts: when the parameter part is "part_one" it should print out the total amount the merchant will be paid out per bank account currency, given a list of charges this merchant has processed.
Input
calculate_payouts has the following parameters:
part: a string, dictating which part of the question to do, equal to either "part_one" or
"part_two"
. For this part it will equal "part_one".
bank_account_currencies: an array of strings, representing the currencies the merchant has bank accounts in.
charges: an array of strings, representing charges the merchant has processed on Stripe.
Charges will be in chronological order of when they were processed.
Note: depending on the language you choose, the function signature of calculate_payouts may also provide the size of the arrays.
Format of the strings in the array charges
Each value in charges is a comma separated string in the format date, amount, currency where If you need to exchange between two currencies where one isn't USD, you can still use this conversion chart to calculate the exchange rate. For example, I need to exchange 10 EUR to GBP.
10 EUR = 10.5 USD = 8.47 GBP.
Stripe fee
• Stripe takes a fixed fee per charge, 2%. This is taken from the original charge amount.
Output
Print the total amount the merchant will be paid out in each currency, each line in the format currency, amount, e.g. "EUR, 100". Final amounts should be rounded to the nearest whole number in the currency's smallest denomination and should be printed in alphabetical order of currency - do not round any amounts until printing the final output.
• Example Case
Input
part="part_one"
bank_account_currencies=["USD", "CHF"] charges= [
"2022-01-01, 100, USD" ,
"2022-01-01, 200 , USD",
"2022-01-01, 200, CHF"
"2022-01-01, 100, EUR",
]*
Output
CHF, 196
USD, 397
Explanation
The merchant has bank accounts in USD and CHF.
Their default bank account is in USD, so any charges that were not in USD or CHF will be converted to USD.
CHF payout: 200 CHF - 2% Stripe fee = 196 CHF
(1.96 Swiss Francs)
USD payout: (100 USD - 2% Stripe fee) + (200 USD
- 2% Stripe fee) + ((100 EUR - 2% Stripe fee)* 1.05
EUR/USD rate) = 396.9 => 397 USD ($3.97).  Part Two
Charges are paid out to a merchant T days after they occurred, where T depends on the currency of the merchant's bank account. All funds of the same currency that are available to be paid out on the same day should be batched into one single payout.
Update your function calculate_payouts : when the parameter part is "part_two" it should print out the payout date, amount and currency of each payout the merchant receives, given a list of charges this merchant has processed. Make sure not to remove your implementation for Part One, the function should be able to handle both parts.
Input
calculate_payouts has the same parameters, formatting, fees and constraints as in Part One, except the part parameter will equal "part_two"
Payout schedules
The amount of days a payout takes to arrive depends on the currency of the merchant's bank account (not necessarily the currency of the charge) The payout days are as follows: • date is in the format YYYY-MM-DD
• amount is a whole number in the currency's smallest denomination (every currency in this question has 2 decimal places)
• currency is one of ['"CHF", "EUR", "GBP", "USD"] e.g. "2022-02-13,12050,EUR" represents a charge of €120.50 that was processed on 13th of February 2022.
Default bank account
The first element of the
bank_account_currencies array is considered the "default" bank account. Any charges in a currency that a merchant does not have a bank account for, they should be converted to the default currency so we can pay them to their default bank account. E.g. I have two bank accounts, one in EUR and one in USD where my default bank account is EUR. If I process a charge in GBP, it will be converted to EUR and paid out to my EUR bank account.
Exchange rates
For simplicity, the exchange rates between currencies are fixed based on the U.S. Dollar:
• 1 CHF = 0.97 USD
• 1 EUR = 1.05 USD
• 1 GBP = 1.24 USD. Payout schedules
The amount of days a payout takes to arrive depends on the currency of the merchant's bank account (not necessarily the currency of the charge). The payout days are as follows:
• CHF = 3 days
• EUR = 2 days
• GBP = 1 day
• USD = 0 days (instant payout)
You can assume that payouts can be made any day of the year.
Output
Print the payouts the merchant will receive, each line in the format date, currency, amount, e.g.
"2022-02-14,EUR, 100". Final amounts should be rounded to the nearest whole number in the currency's smallest denomination and should be printed in chronological order of payout date, and any payouts on the same date should be in alphabetical order of currency - do not round the amounts until printing the output. • Example Case 1
Input
part="part_two"
bank_account_currencies=["USD", "CHF"]
charges= [
"2022-01-01, 100, USD",
"2022-01-01,200, USD",
"2022-01-01, 200, CHF",
"2022-01-01,100, EUR",
Output
2022-01-01, USD, 397
2022-01-04, CHF, 196
Explanation
The merchant has bank accounts in USD and CHF.
Their default bank account is in USD, so any charges that were not in USD or CAF will be converted to USD.
Let's look at the charges: 2022-01-01,100, USD: 100 USD - 2% Stripe fee = 98 USD. USD has instant payouts, so payout date is the same day 2022-01-01
2022-01-01,200, USD: 200 USD - 2% Stripe fee
= 196 USD. USD has instant payouts, so payout
date is the same day 2022-01-01
2022-01-01,200, CHF: 200 CHF - 2% Stripe fee = 196 CHF. CHF payout schedule is 3 days, so payout date is 2022-01-04
2022-01-01,100, EUR: (100 EUR - 2% Stripe fee)
* 1.05 EUR/USD rate) = 102.9 USD. USD has
instant payouts, so payout date is the same day
2022-01-01
There are 3 USD payouts on 2022-01-01 so let's group them into one payout of (98 + 196 + 102.9)
= 396.9 => 397 USD ($3.97)
There is 1 CHF payout on 2022-01-04: 196 CHF
(1.96 Swiss Francs) • Example Case 2
Input part="part_two"
bank_account_currencies=["USD", "CHF"]
charges= [
"2022-01-01,100,USD",
"2022-01-01, 200, CHF", •
"2022-01-04,100, USD",
Output
2022-01-01, USD,98
2022-01-04, CHF, 196
2022-01-04, USD, 98
Explanation
The merchant has bank accounts in USD and CHF.
Their default bank account is in USD, so any charges that were not in USD or CHF will be converted to USD. Let's look at the charges:
2022-01-01,100, USD: 100 USD - 2% Stripe fee = 98 USD. USD has instant payouts, so payout date is same day 2022-01-01
2022-01-01,200, CHF: 200 CHF - 2% Stripe fee = 196 CHF. CHF payout schedule is 3 days, so payout date 2022-01-04
2022-01-01,100, USD: 100 USD - 2% Stripe fee = 98 USD. USD has instant payouts, so payout date is same day 2022-01-04
There is 1 USD payout on 2022-01-01: 98 USD
($0.98)
There are 2 payouts on 2022-01-04
• There is 1 CHF payout: 196 CHF (1.96 Swiss
Francs)
• There is 1 USD payout: 98 USD ($0.98).      


def calculate_payouts(part, bank_account_currencies, charges) :
# Write your code here