Request Builder is a component of the Magento payment gateway responsible for building a request from several parts. It allows implementing complex, yet atomic and testable, building strategies. Each builder can have simple logic or contain builder composites.
The basic interface for a request builder is
\Magento\Payment\Gateway\Request\BuilderComposite is a container for a list of
\Magento\Payment\Gateway\Request\BuilderInterface implementations. It gets a list of classes, or types, or virtual type names, and performs a lazy instantiation on an actual
BuilderComposite::build() call. So that you can have as many objects, as required, but only those, which are needed for a request are instantiated.
BuilderComposite implements the composite design pattern.
The concatenation strategy is defined in the
BuilderComposite::merge() method. So if you need to alter the strategy, you need to add your custom implementation of
Adding a builder composite
Builder composites are added using dependency injection in
di.xml. A builder composite might comprise simple builders as well as other builder composites.
Example of adding composite builders for the Braintree payment provider (
(The code sample is from Magento CE v2.1. Although the payment provider gateway was added in v2.0, the particular default implementation using the gateway were added in v2.1)