From 4c219583e2cedd0179a4bfbac675f86f60969086 Mon Sep 17 00:00:00 2001 From: LOUARDI Abdeltif Date: Wed, 14 Dec 2011 16:47:28 +0000 Subject: [PATCH] Integrate saferpay plugin --- PaymentFactory.php | 51 ++++++++++- Plugins/Saferpay.php | 159 ++++++++++++++++++++++++++++++++++ Resources/config/routing.yml | 3 - Resources/config/services.yml | 2 +- 4 files changed, 210 insertions(+), 5 deletions(-) create mode 100644 Plugins/Saferpay.php delete mode 100644 Resources/config/routing.yml diff --git a/PaymentFactory.php b/PaymentFactory.php index 72bf407..6c13765 100644 --- a/PaymentFactory.php +++ b/PaymentFactory.php @@ -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; + } + } \ No newline at end of file diff --git a/Plugins/Saferpay.php b/Plugins/Saferpay.php new file mode 100644 index 0000000..ac86405 --- /dev/null +++ b/Plugins/Saferpay.php @@ -0,0 +1,159 @@ +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' + ); + } + +} \ No newline at end of file diff --git a/Resources/config/routing.yml b/Resources/config/routing.yml deleted file mode 100644 index 215fd6c..0000000 --- a/Resources/config/routing.yml +++ /dev/null @@ -1,3 +0,0 @@ -OSPaymentBundle_homepage: - pattern: /hello/{name} - defaults: { _controller: OSPaymentBundle:Default:index } diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 94bb826..e89b24f 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -2,6 +2,6 @@ parameters: payment.factory.class: OS\PaymentBundle\PaymentFactory services: - payment.facotry: + payment.factory: class: %payment.factory.class% arguments: []