/** * This method sets the card handler by the given brand information and by a list of accepted brands. * * @param array $brandInformationMap * @param array|string $acceptedBrands A list of brands or a single brand name. * @param string $parameterKeyForMappedBrand The key name for the parameter to map the brands to. * @return Customweb_Payment_Authorization_Method_CreditCard_ElementBuilder */ public function setCardHandlerByBrandInformationMap($brandInformationMap, $acceptedBrands = null, $parameterKeyForMappedBrand = null) { $informationMap = Customweb_Payment_Authorization_Method_CreditCard_CardInformation::getCardInformationObjects($brandInformationMap, $acceptedBrands, $parameterKeyForMappedBrand); $this->cardHandler = new Customweb_Payment_Authorization_Method_CreditCard_CardHandler($informationMap); return $this; }
/** * This method creates a map of Customweb_Payment_Authorization_Method_CreditCard_CardInformation objects, with the * brand as the key. It can be optionally filtered by a list of brands. Only the brands indicated by $filterByBrands * will be in the returned map. * * @param array $data * @param array|string $filterByBrands Either an array with accepted brands or a single brand name. * @param string $parameterKeyForMappedBrand The key name for the parameter to map the brands to. * @return Customweb_Payment_Authorization_Method_CreditCard_CardInformation[] */ public static function getCardInformationObjects(array $data, $filterByBrands = null, $parameterKeyForMappedBrand = null) { if (is_string($filterByBrands)) { $filterByBrands = array($filterByBrands); } // Ensures lowercase if (is_array($filterByBrands)) { foreach ($filterByBrands as $key => $value) { $filterByBrands[$key] = strtolower($value); } } $objects = array(); foreach ($data as $brand => $information) { $brand = strtolower($brand); // Filter the brand, in case it is not in the given list of accepted brands if ($filterByBrands !== null && !in_array($brand, $filterByBrands)) { continue; } if (!isset($information['credit_card_information'])) { continue; } $ccInformation = $information['credit_card_information']; $object = new Customweb_Payment_Authorization_Method_CreditCard_CardInformation(); $object->setBrandName($information['method_name'])->setBrandKey($brand)->setCardNumberLengths($ccInformation['lengths'])->setIssuerIdentificationNumberPrefixes($ccInformation['issuer_identification_number_prefixes'])->setValidators($ccInformation['validators'])->setGreyImageUrl($information['image_grey'])->setColorImageUrl($information['image_color']); if (isset($ccInformation['cvv_length'])) { $object->setCvvLength($ccInformation['cvv_length']); $object->setCvvPresentOnCard(true); if (isset($ccInformation['cvv_required']) && $ccInformation['cvv_required'] == 'true') { $object->setCvvRequired(true); } } else { $object->setCvvPresentOnCard(false); } if ($parameterKeyForMappedBrand !== null && isset($information['parameters'][$parameterKeyForMappedBrand])) { $object->setMappedBrandKey($information['parameters'][$parameterKeyForMappedBrand]); } $brand = strtolower($brand); $objects[$brand] = $object; } return $objects; }