Skip to content

Commit

Permalink
Integrate saferpay plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
LOUARDI Abdeltif committed Dec 14, 2011
1 parent dcf022d commit 4c21958
Show file tree
Hide file tree
Showing 4 changed files with 210 additions and 5 deletions.
51 changes: 50 additions & 1 deletion PaymentFactory.php
Expand Up @@ -2,7 +2,56 @@

namespace OS\PaymentBundle;

use Exception;

/**
* @author ouardisoft
*/
class PaymentFactory
{


private $plugin;

public function __call($name, $arguments)
{
return $this->getPlugin()->$name($arguments);
}

public function getPlugin()
{
return $this->plugin;
}

public function setPlugin($plugin)
{
$exists = true;
if (!class_exists($plugin))
$exists = false;

if (!class_exists(sprintf('OS\\PaymentBundle\\Plugins\\%s', $plugin)) && !$exists) {
$exists = false;
} else {
$plugin = sprintf('OS\\PaymentBundle\\Plugins\\%s', $plugin);
$exists = true;
}

if ($exists == false)
throw new Exception(sprintf('Plugin %s not found.', $plugin));

$this->plugin = new $plugin;

return $this;
}

public function execute($args = array())
{
$this->setPlugin($args['plugin']);

$this
->getPlugin()
->execute($args['options']);

return $this;
}

}
159 changes: 159 additions & 0 deletions Plugins/Saferpay.php
@@ -0,0 +1,159 @@
<?php

namespace OS\PaymentBundle\Plugins;

/**
* @author ouardisoft
*/
class Saferpay
{

private $uri = 'https://www.saferpay.com/hosting/execute.asp';
private $url;
private $options;
private $results;

/**
*
* @return type
*/
public function getUri()
{
return $this->uri;
}

/**
*
* @param type $uri
*/
public function setUri($uri)
{
$this->uri = $uri;
}

/**
*
* @return type
*/
public function getUrl()
{
return $this->url;
}

/**
*
* @param type $url
*/
public function setUrl($url)
{
$this->url = $url;
}

/**
*
* @return type
*/
public function getOptions()
{
return $this->options;
}

/**
*
* @param type $options
*/
public function setOptions($options)
{
$this->options = $options;
}

/**
*
* @return type
*/
public function getResults()
{
return $this->results;
}

/**
*
* @param type $results
*/
public function setResults($results)
{
$this->results = $results;
}

/**
*
*/
public function getQueryStringFromOptions()
{
return http_build_query($this->getOptions());
}

/**
*
*/
public function execute($options)
{
$this->setOptions($options);

$this->dispatch()->call();

return $this;
}

/**
*
*/
public function dispatch()
{
// Generate url
$this->setUrl(sprintf('%s%s%s', $this->getUri(), '?', $this->getQueryStringFromOptions()));

return $this;
}

/**
*
*/
public function call()
{
$content = file_get_contents($this->getUrl());

preg_match('/([^:]+):(.+)/i', $content, $matches);
$status = $matches[1];

if ($status == 'OK') {
$sx = (array) simplexml_load_string($matches[2]);
list($key, $attributes) = each($sx);

$this->setResults($attributes);
} else {
$err['RESULT'] = $matches[1];
$err['AUTHMESSAGE'] = $matches[2];

$this->setResults($err);
}
}

/**
*
*/
public function getTestOptions()
{
return array(
'spPassword' => 'XAjc3Kna',
'ACCOUNTID' => '99867-94913159',
'ORDERID' => '123456789-001',
'AMOUNT' => '4000',
'CURRENCY' => 'EUR',
'PAN' => '9451123100000004',
'EXP' => '1214',
'CVC' => '123'
);
}

}
3 changes: 0 additions & 3 deletions Resources/config/routing.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Resources/config/services.yml
Expand Up @@ -2,6 +2,6 @@ parameters:
payment.factory.class: OS\PaymentBundle\PaymentFactory

services:
payment.facotry:
payment.factory:
class: %payment.factory.class%
arguments: []

0 comments on commit 4c21958

Please sign in to comment.