/** * Get a list of supported gateways, in friendly format (e.g. PayPal_Express) */ public static function find($directory = null) { $result = array(); // find all gateways in the Billing directory $directory = dirname(__DIR__); $it = new RecursiveDirectoryIterator($directory); foreach (new RecursiveIteratorIterator($it) as $file) { $filepath = $file->getPathName(); if ('Gateway.php' === substr($filepath, -11)) { // determine class name $type = substr($filepath, 0, -11); $type = str_replace(array($directory, DIRECTORY_SEPARATOR), array('', '_'), $type); $type = trim($type, '_'); $class = Helper::getGatewayClassName($type); // ensure class exists and is not abstract if (class_exists($class)) { $reflection = new ReflectionClass($class); if (!$reflection->isAbstract() and $reflection->implementsInterface('\\Omnipay\\Common\\GatewayInterface')) { $result[] = $type; } } } } return $result; }
/** * Create a new gateway instance * * @param string $class Gateway name * @param ClientInterface|null $httpClient A Guzzle HTTP Client implementation * @param HttpRequest|null $httpRequest A Symfony HTTP Request implementation */ public function create($class, ClientInterface $httpClient = null, HttpRequest $httpRequest = null) { $class = Helper::getGatewayClassName($class); if (!class_exists($class)) { throw new RuntimeException("Class '{$class}' not found"); } return new $class($httpClient, $httpRequest); }
public function validateData(Order $order, array $data) { $result = ValidationResult::create(); //TODO: validate credit card data if (!Helper::validateLuhn($data['number'])) { $result->error(_t('OnsitePaymentCheckoutComponent.CREDIT_CARD_INVALID', 'Credit card is invalid')); throw new ValidationException($result); } }
/** * Initialize the object with parameters. * * If any unknown parameters passed, they will be ignored. * * @param array An associative array of parameters */ public function initialize(array $parameters = array()) { if (null !== $this->response) { throw new RuntimeException('Request cannot be modified after it has been sent!'); } $this->parameters = new ParameterBag(); Helper::initialize($this, $parameters); return $this; }
public function validateData(Order $order, array $data) { $result = new ValidationResult(); //TODO: validate credit card data if (!Helper::validateLuhn($data['number'])) { $result->error('Credit card is invalid'); throw new ValidationException($result); } }
/** * Initialize this item with the specified parameters * * @param array|null $parameters An array of parameters to set on this object * * @return Customer */ public function initialize($parameters = null) { $this->parameters = new ParameterBag(); $this->setType(self::TYPE_NEW); $this->setGroup(self::GROUP_PRIVATE); if ($parameters !== null) { Helper::initialize($this, $parameters); } return $this; }
/** * @param GatewayInterface $gatewayInstance * @param string|null $alias */ public function registerGateway(GatewayInterface $gatewayInstance, $alias = null) { $name = $alias ?: Helper::getGatewayShortName(get_class($gatewayInstance)); if (in_array($name, $this->disabledGateways)) { return; } $this->registeredGateways[$name] = $gatewayInstance; if ($this->initializeOnRegistration) { $gatewayInstance->initialize($this->getGatewayConfig($name)); $this->cache[$name] = $gatewayInstance; } }
public function initialize(array $parameters = array()) { $this->parameters = new ParameterBag(); // set default parameters foreach ($this->getDefaultParameters() as $key => $value) { if (is_array($value)) { $this->parameters->set($key, reset($value)); } else { $this->parameters->set($key, $value); } } Helper::initialize($this, $parameters); return $this; }
/** * Add the parameters to the bag * @param array $parameters */ private function addParameters(array $parameters) { $this->parameters = new ParameterBag(); $supportedKeys = Settings::getKeys(); if (is_array($parameters)) { foreach ($parameters as $key => $value) { $method = 'set' . ucfirst(Helper::camelCase($key)); if (method_exists($this, $method)) { $this->{$method}($value); } elseif (in_array($key, $supportedKeys)) { $this->parameters->set($key, $value); } } } }
/** * Model validation ensures that any data that is present in the model is * formatted correctly. No business logic validation is performed at this * level. * * @throws InvalidRequestException if validation fails. */ public function validate() { if (strlen($this['CardNumber'])) { if (!preg_match('/^\\d{12,19}$/', $this['CardNumber'])) { throw new InvalidRequestException('CardNumber should have 12 to 19 digits'); } if (!Helper::validateLuhn($this['CardNumber'])) { throw new InvalidRequestException('CardNumber is invalid'); } } if (strlen($this['ExpirationMonth'] && strlen($this['ExpirationYear']))) { $time = gmmktime(0, 0, 0, $this['ExpirationMonth'], 1, $this['ExpirationYear']); if (gmdate('Ym', $time) < gmdate('Ym')) { throw new InvalidRequestException('Card has expired'); } } if (strlen($this['Track1Data']) && !preg_match('/^.{1,76}$/', $this['Track1Data'])) { throw new InvalidRequestException('Track1Data should have 76 or fewer characters'); } if (strlen($this['Track2Data']) && !preg_match('/^.{1,37}$/', $this['Track2Data'])) { throw new InvalidRequestException('Track2Data should have 37 or fewer characters'); } if (strlen($this['MagneprintData']) && !preg_match('/^.{1,700}$/', $this['MagneprintData'])) { throw new InvalidRequestException('MagneprintData should have 700 or fewer characters'); } if (strlen($this['CVV']) && !preg_match('/^\\d{1,4}$/', $this['CVV'])) { throw new InvalidRequestException('CVV should have 4 or fewer digits'); } if (strlen($this['EncryptedTrack1Data']) && !preg_match('/^.{1,300}$/', $this['EncryptedTrack1Data'])) { throw new InvalidRequestException('EncryptedTrack1Data should have 300 or fewer characters'); } if (strlen($this['EncryptedTrack2Data']) && !preg_match('/^.{1,200}$/', $this['EncryptedTrack2Data'])) { throw new InvalidRequestException('EncryptedTrack2Data should have 200 or fewer characters'); } if (strlen($this['EncryptedCardData']) && !preg_match('/^.{1,200}$/', $this['EncryptedCardData'])) { throw new InvalidRequestException('EncryptedCardData should have 200 or fewer characters'); } if (strlen($this['CardDataKeySerialNumber']) && !preg_match('/^.{1,26}$/', $this['CardDataKeySerialNumber'])) { throw new InvalidRequestException('CardDataKeySerialNumber should have 26 or fewer characters'); } if (isset($this['EncryptedFormat'])) { try { EncryptedFormat::memberByValue($this['EncryptedFormat']); } catch (\Exception $e) { throw new InvalidRequestException('Invalid value for EncryptedFormat'); } } }
/** * Create gateway service. * * @param ContainerBuilder $container * @param string $name * @param array $parameters */ public function createGatewayService(ContainerBuilder $container, $name, array $parameters) { $type = $parameters['type']; $class = trim(Helper::getGatewayClassName($type), "\\"); $definition = new Definition($class); $definition->setFactoryService('sylius.omnipay.gateway_factory')->setFactoryMethod('create')->setArguments(array($type)); $reflection = new \ReflectionClass($class); foreach ($parameters['options'] as $optionName => $value) { $method = 'set' . ucfirst($optionName); if ($reflection->hasMethod($method)) { $definition->addMethodCall($method, array($value)); } } $container->setDefinition(sprintf('sylius.omnipay.gateway.%s', $name), $definition); $this->gateways[$name] = isset($parameters['label']) ? $parameters['label'] : $name; }
protected function resolve($name) { $config = $this->getConfig($name); if (is_null($config)) { throw new \UnexpectedValueException("Gateway [{$name}] is not defined."); } $gateway = $this->factory->create($config['driver']); $class = trim(Helper::getGatewayClassName($config['driver']), "\\"); $reflection = new \ReflectionClass($class); foreach ($config['options'] as $optionName => $value) { $method = 'set' . ucfirst($optionName); if ($reflection->hasMethod($method)) { $gateway->{$method}($value); } } return $gateway; }
/** * Initialize the object with parameters. * * If any unknown parameters passed, they will be ignored. * * @param array $parameters An associative array of parameters * * @return $this * @throws RuntimeException */ public function initialize(array $parameters = array()) { $this->parameters = new ParameterBag(); $tempParams = array(); foreach ($parameters as $key => $value) { if (is_array($value) || is_object($value)) { $tempParams[$key] = (array) $value; foreach ((array) $value as $subKey => $subValue) { $tempParams[$subKey] = $subValue; } continue; } $tempParams[$key] = $value; } Helper::initialize($this, $tempParams); return $this; }
public function getProvidersAction() { $gateways = \Omnipay\Tool::getSupportedGateways(); $available = []; $activeProviders = Model\Configuration::get("OMNIPAY.ACTIVEPROVIDERS"); if (!is_array($activeProviders)) { $activeProviders = []; } foreach ($gateways as $gateway) { $class = \Omnipay\Common\Helper::getGatewayClassName($gateway); if (\Pimcore\Tool::classExists($class)) { if (!in_array($gateway, $activeProviders)) { $available[] = ["name" => $gateway]; } } } $this->_helper->json(array("data" => $available)); }
/** * @inheritdoc */ public function initialize(array $parameters = array()) { if (null !== $this->response) { throw new RuntimeException('Request cannot be modified after it has been sent!'); } $this->parameters = new ParameterBag(); $supportedKeys = $this->getSupportedKeys(); if (is_array($parameters)) { foreach ($parameters as $key => $value) { $method = 'set' . ucfirst(Helper::camelCase($key)); if (method_exists($this, $method)) { $this->{$method}($value); } else { if (in_array($key, $supportedKeys)) { $this->parameters->set($key, $value); } } } } return $this; }
/** * Initialize the object with parameters. * * If any unknown parameters passed, they will be ignored. * * @param array $parameters An associative array of parameters * @return CreditCard provides a fluent interface. */ public function initialize($parameters = null) { $this->parameters = new ParameterBag(); Helper::initialize($this, $parameters); return $this; }
/** * Validate this credit card. If the card is invalid, InvalidCreditCardException is thrown. * * This method is called internally by gateways to avoid wasting time with an API call * when the credit card is clearly invalid. * * Generally if you want to validate the credit card yourself with custom error * messages, you should use your framework's validation library, not this method. */ public function validate() { foreach (array('number', 'expiryMonth', 'expiryYear') as $key) { if (!$this->getParameter($key)) { throw new InvalidCreditCardException("The {$key} parameter is required"); } } if ($this->getExpiryDate('Ym') < gmdate('Ym')) { throw new InvalidCreditCardException('Card has expired'); } if (!Helper::validateLuhn($this->getNumber())) { throw new InvalidCreditCardException('Card number is invalid'); } }
/** * Validate this credit card. If the card is invalid, InvalidCreditCardException is thrown. * * This method is called internally by gateways to avoid wasting time with an API call * when the credit card is clearly invalid. * * Generally if you want to validate the credit card yourself with custom error * messages, you should use your framework's validation library, not this method. * * @throws InvalidCreditCardException * @return void */ public function validate() { foreach (array('number', 'expiryMonth', 'expiryYear') as $key) { if (!$this->getParameter($key)) { throw new InvalidCreditCardException("The {$key} parameter is required"); } } if ($this->getExpiryDate('Ym') < gmdate('Ym')) { throw new InvalidCreditCardException('Card has expired'); } if (!Helper::validateLuhn($this->getNumber())) { throw new InvalidCreditCardException('Card number is invalid'); } if (!is_null($this->getNumber()) && !preg_match('/^\\d{12,19}$/i', $this->getNumber())) { throw new InvalidCreditCardException('Card number should have 12 to 19 digits'); } }
public function acceptNotification(array $parameters = array()) { // Rename hmacSignature parameter if (isset($parameters['additionalData_hmacSignature'])) { $parameters['hmacSignature'] = $parameters['additionalData_hmacSignature']; } // Add secret from configuration $parameters['secret'] = $this->getSecret(); $notification = new \Omnipay\Adyen\Message\PostNotification(); Helper::initialize($notification, $parameters); return $notification; }
public function creditCardLuhn($attribute, $params) { if (!OmnipayHelper::validateLuhn($this->{$attribute})) { $this->addError($attribute, Craft::t('Not a valid Credit Card Number')); } }
/** * Create a new gateway instance * * @param string $class Gateway name * @param ClientInterface|null $httpClient A Guzzle HTTP Client implementation * @param HttpRequest|null $httpRequest A Symfony HTTP Request implementation * @param EventDispatcherInterface|null $eventDispatcher A Symfony event dispatcher implementation * @throws RuntimeException If no such gateway is found * @return GatewayInterface An object of class $class is created and returned */ public function create($class, ClientInterface $httpClient = null, HttpRequest $httpRequest = null, EventDispatcherInterface $eventDispatcher = null) { $class = Helper::getGatewayClassName($class); if (!class_exists($class)) { throw new RuntimeException("Class '{$class}' not found"); } if ($eventDispatcher === null) { $eventDispatcher = $this->getDefaultEventDispatcher(); } return new $class($httpClient, $httpRequest, $eventDispatcher); }
/** * Convert an amount into a float. * * @var string|int|float $value The value to convert. * @throws InvalidRequestException on any validation failure. * @return float The amount converted to a float. */ public function toFloat($value) { try { return Helper::toFloat($value); } catch (InvalidArgumentException $e) { // Throw old exception for legacy implementations. throw new InvalidRequestException($e->getMessage(), $e->getCode(), $e); } }
/** * @param array $parameters * @return $this */ public function loadParameters($parameters = []) { Helper::initialize($this, $parameters); return $this; }
/** * Underscored types should be resolved in a PSR-0 fashion. */ public function testGetGatewayClassNameUnderscoreNamespace() { $class = Helper::getGatewayClassName('PayPal_Express'); $this->assertEquals('\\Omnipay\\PayPal\\ExpressGateway', $class); }
/** * @expectedException \InvalidArgumentException * @expectedExceptionMessage Data type is not a valid decimal number */ public function testToFloatFromBoolean() { $shortName = Helper::toFloat(false); }
/** * @param GatewayInterface $gatewayInstance * @param string|null $alias */ public function registerGateway(GatewayInterface $gatewayInstance, $alias = null) { $name = $alias ?: Helper::getGatewayShortName(get_class($gatewayInstance)); $this->registeredGateways[$name] = $gatewayInstance; }
/** * Validate credit card details: * - country * - email * - name * - phone. */ protected function validateCreditCardDetails() { $this->validate('card'); $card = $this->getCard(); foreach (array('country', 'email', 'name', 'phone') as $key) { $method = 'get' . ucfirst(Helper::camelCase($key)); if (null === $card->{$method}()) { throw new InvalidCreditCardDetailsException("The {$key} parameter is required"); } } }
/** * Initialize this gateway with default parameters * * @param array $parameters * @return $this */ public function initialize(array $parameters = array()) { $this->parameters = new ParameterBag(); // set default parameters foreach ($this->getDefaultParameters() as $key => $value) { if (is_array($value)) { $this->parameters->set($key, reset($value)); } else { $this->parameters->set($key, $value); } } $event = new GatewayEvent($this, $this->parameters); $this->dispatch(GatewayEvent::PRE_INITIALIZE, $event); Helper::initialize($this, $parameters); $event = new GatewayEvent($this, $this->parameters); $this->dispatch(GatewayEvent::POST_INITIALIZE, $event); return $this; }