...
/Solution: Create a Pluggable Payment Processor Factory
Solution: Create a Pluggable Payment Processor Factory
Use a vendor-to-factory function map to construct the correct payment processor with the proper credentials.
We'll cover the following...
We'll cover the following...
Solution explanation
Lines 1–26: We define three processor classes:
StripeProcessor,PayPalProcessor, andSquareProcessor.Each accepts a different credential parameter in its constructor (
apiKey,merchantId, oraccessToken).All expose a
.charge(amount)method, keeping the interface consistent for consumers.
Lines 28–32: We create a
processorFactoryMapthat maps vendor names ('stripe','paypal','square') to factory ...