package Ġio . ple o . ant ae us . core . external Ċ Ċ import Ġio . ple o . ant ae us . core . exceptions . Currency Mismatch Exception Ċ import Ġio . ple o . ant ae us . core . exceptions . Customer NotFoundException Ċ import Ġio . ple o . ant ae us . core . exceptions . Network Exception Ċ import Ġio . ple o . ant ae us . models . Customer Ċ import Ġio . ple o . ant ae us . models . Invoice Ċ import Ġkotlin . random . Random Ċ Ċ // ĠBased Ġon Ġthe Ġpossible ĠExceptions Ġthat Ġwe Ġhave Ġto Ġhandle , Ġthis Ġclass Ġsim ulates Ġa ĠPayment Provider Ġthat Ġmay Ġreturn Ġany Ġof Ġthose Ġexceptions Ċ class ĠSome Bank Ġ: ĠPayment Provider Ġ{ ĊĊĠĠĠ Ġoverride Ġfun Ġcharge ( invoice : ĠInvoice , Ġcustomer : Customer ): ĠBoolean Ġ{ ĊĊĠĠĠĠĠĠĠ Ġ// Random ly Ġwith Ġa Ġchance Ġof Ġ 5 % Ġthrow Ġa ĠCustomer NotFoundException Ġto Ġsimulate Ġthat Ġthe Ġpayment Ġprovider Ġdoes Ġnot Ġhave Ġthis Ġcustomer Ġanymore ĊĠĠĠĠĠĠĠ Ġif ( Random . nextInt ( from = 0 , until = 1 0 0 ) Ġ<= Ġ 5 ){ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġthrow ĠCustomer NotFoundException ( customer . id ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġ// Random ly Ġwith Ġa Ġchance Ġof Ġ 5 % Ġthrow Ġa ĠCurrency Mismatch Exception Ġto Ġsimulate Ġthat Ġthe Ġcustomer Ġchanged Ġhis Ġcurrency Ġon Ġhis Ġpayment Ġprovider Ġaccount ĊĠĠĠĠĠĠĠ Ġif ( customer . currency Ġ!= Ġinvoice . amount . currency ){ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġthrow ĠCurrency Mismatch Exception ( invoice . id , customer . id ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġ// Random ly Ġwith Ġa Ġchance Ġof Ġ 5 % Ġthrow Ġa ĠNetwork Exception Ġto Ġsimulate Ġa Ġnetwork Ġerror ĊĠĠĠĠĠĠĠ Ġif ( Random . nextInt ( from = 0 , until = 1 0 0 ) Ġ<= Ġ 5 ){ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġthrow ĠNetwork Exception () ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġ// Random ly Ġwith Ġa Ġchance Ġof Ġ 5 % Ġreturn Ġfalse Ġto Ġsimulate Ġcustomer Ġins ufficient Ġfunds ĊĠĠĠĠĠĠĠ Ġreturn Ġ( Random . nextInt ( from = 0 , until = 1 0 0 ) Ġ<= Ġ 9 5 ) ĊĠĠĠ Ġ} Ċ }