src/Models/Payment.php
public static function build(array $array) {
        if (array_key_exists("type", $array) && in_array($array["type"], self::$availableTypes)) {
            switch ($array["type"]) {
                case Payment::TYPE_CREDIT:
                    return new CreditCard($array);
                    break;

                case Payment::TYPE_BOLETO:
                    return new Boleto($array);
                    break;

                case Payment::TYPE_DEBIT:
                case Payment::TYPE_TRANSFER:
                case Payment::TYPE_VOUCHER:
                    return new Payment($array);
                    break;

                default:  // Exception
            }
        }
        throw new \InvalidArgumentException("Array must contain a valid 'type' field");
    }
public static function build(array $array) {
        if (array_key_exists("type", $array) && in_array($array["type"], self::$availableTypes)) {
            switch ($array["type"]) {
                case Payment::TYPE_CREDIT:
                    return new CreditCard($array);
                    break;

                case Payment::TYPE_BOLETO:
                    return new Boleto($array);
                    break;

                case Payment::TYPE_DEBIT:
                case Payment::TYPE_TRANSFER:
                case Payment::TYPE_VOUCHER:
                    return new Payment($array);
                    break;

                default:  // Exception
            }
        }
        throw new \InvalidArgumentException("Array must contain a valid 'type' field");
    }
public static function build ( array $ array ) { if ( array_key_exists ( "type" , $ array ) && in_array ( $ array [ "type" ] , self :: $ availableTypes ) ) { switch ( $ array [ "type" ] ) { case Payment :: TYPE_CREDIT : return new CreditCard ( $ array ) ; break ; case Payment :: TYPE_BOLETO : return new Boleto ( $ array ) ; break ; case Payment :: TYPE_DEBIT : case Payment :: TYPE_TRANSFER : case Payment :: TYPE_VOUCHER : return new Payment ( $ array ) ; break ; default : // Exception } } throw new \ InvalidArgumentException ( "Array must contain a valid 'type' field" ) ; }
Given an array, instantiates a payment among the possible
types of payments. The decision of what Model to use is made
by field 'type'
@param $array: array containing fields of the Payment
@return Payment CreditCard or Boleto object
Given an array instantiates a payment among the possible types of payments . The decision of what Model to use is made by field type