/** * Build a new PaymentMethod object from an name pair * * @param GatewayType $gateway * @param string $method_name * @param string $submethod_name * @param bool $is_recurring * * @return PaymentMethod */ public static function newFromCompoundName(GatewayType $gateway, $method_name, $submethod_name, $is_recurring) { $method = new PaymentMethod(); $method->gateway = $gateway; $method->name = PaymentMethod::parseCompoundMethod($method_name, $submethod_name); $method->is_recurring = $is_recurring; try { // FIXME: I don't like that we're couple to the gateway already. $spec = array(); if ($method_name) { $spec = $gateway->getPaymentMethodMeta($method_name); } // When we have a more specific method, child metadata supercedes // parent metadata if ($submethod_name) { $spec = array_replace_recursive($spec, $gateway->getPaymentSubmethodMeta($submethod_name)); } $method->spec = $spec; } catch (Exception $ex) { // Return empty method. $method->name = "none"; $method->spec = array(); } return $method; }