1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 
	<?php
defined( 'ABSPATH' ) || exit();
class WC_Stripe_Payment_Factory {
    private static $classes = array(
        'charge'         => 'WC_Stripe_Payment_Charge',
        'payment_intent' => 'WC_Stripe_Payment_Intent',
        'local_charge'   => 'WC_Stripe_Payment_Charge_Local',
    );
    
    public static function load( $type, $payment_method, $gateway ) {
        $classes = apply_filters( 'wc_stripe_payment_classes', self::$classes );
        if ( ! isset( $classes[ $type ] ) ) {
            throw Exception( 'No class defined for type ' . $type );
        }
        $classname = $classes[ $type ];
        $args = func_get_args();
        if ( count( $args ) > 3 ) {
            $args     = array_slice( $args, 3 );
            $instance = new $classname( $payment_method, $gateway, ...$args );
        } else {
            $instance = new $classname( $payment_method, $gateway );
        }
        return $instance;
    }
}