...

/

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...

Solution explanation

  • Lines 1–26: We define three processor classes: StripeProcessorPayPalProcessor, and SquareProcessor.

    • Each accepts a different credential parameter in its constructor (apiKeymerchantId, or accessToken).

    • All expose a .charge(amount) method, keeping the interface consistent for consumers.

  • Lines 28–32: We create a processorFactoryMap that maps vendor names ('stripe''paypal''square') to factory ...