/**
  * {@inheritDoc}
  */
 protected function populateConfig(ArrayObject $config)
 {
     $config->defaults(['payum.action.capture' => new CaptureAction(), 'payum.action.capture_offsite' => new OffsiteCaptureAction(), 'payum.action.convert_payment' => new ConvertPaymentAction(), 'payum.action.status' => new StatusAction()]);
     if (false == $config['payum.api']) {
         //BC layer
         if ($config['options']) {
             $config->defaults($config['options']);
         }
         $config->defaults(['type' => $this->omnipayGatewayTypeOrClass]);
         // omnipay does not provide required options.
         $config['payum.required_options'] = ['type'];
         $gateway = null;
         if ($config['type']) {
             try {
                 /** @var GatewayInterface $gateway */
                 $gateway = $this->omnipayGatewayFactory->create($config['type']);
             } catch (OmnipayException $e) {
                 throw new LogicException(sprintf('Given omnipay gateway type %s or class is not supported. Supported: %s', $config['type'], implode(', ', $this->omnipayGatewayFactory->getSupportedGateways())), 0, $e);
             }
             $config['payum.default_options'] = array_replace(['testMode' => true], $gateway->getDefaultParameters());
             $config->defaults($config['payum.default_options']);
         }
         $config['payum.api'] = function (ArrayObject $config) use($gateway) {
             $config->validateNotEmpty($config['payum.required_options']);
             $gateway->initialize((array) $config);
             return $gateway;
         };
     }
 }
Esempio n. 2
0
 protected function createGateway($gatewayName)
 {
     $httpClient = new Client();
     if (isset($this->registeredGateways[$gatewayName])) {
         $gateway = $this->registeredGateways[$gatewayName];
     } else {
         /** @var GatewayInterface $gateway */
         $gateway = $this->gatewayFactory->create($gatewayName, $httpClient);
     }
     $config = isset($this->config[$gatewayName]) ? $this->config[$gatewayName] : [];
     $gateway->initialize($config);
     return $gateway;
 }
 public function proccessPayment()
 {
     $gateway = \Omnipay\Common\GatewayFactory::create('SecurePay_DirectPost');
     $gateway->setMerchantId('ABC0030');
     $gateway->setTransactionPassword('abc123');
     $gateway->setTestMode(true);
     $gateway->setSignature('AXuZQmuwvbGStYcypPeU5U8SBEARA5zfmvXmgoF1BAwXTE6RuKyx59gj');
     //var_dump( $gateway->getSolutionType()); exit;
     //var_dump($gateway->getDefaultParameters()); exit;
     $options = array('amount' => '10.00', 'returnUrl' => 'https://www.example.com/return', 'cancelUrl' => 'https://www.example.com/cancel', 'currency' => 'AUD');
     $response = $gateway->authorize($options)->send();
     var_dump($response);
     exit;
     //$response->redirect();
     //$response = $gateway->purchase($options)->send();
     //var_dump($response->isSuccessful(),$response->getMessage(),$response->isRedirect());
     exit;
     $response = $gateway->purchase(array('amount' => '10.00', 'currency' => 'AUD', 'card' => $formData))->send();
     if ($response->isSuccessful()) {
         // payment was successful: update database
         print_r($response);
     } elseif ($response->isRedirect()) {
         // redirect to offsite payment gateway
         $response->redirect();
     } else {
         // payment failed: display message to customer
         echo $response->getMessage();
     }
     var_dump($settings);
     exit;
 }
 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;
 }
 public function testGetShortName()
 {
     // test a couple of known getShortName() examples
     $gateway = GatewayFactory::create('PayPal_Express');
     $this->assertSame('PayPal_Express', $gateway->getShortName());
     $gateway = GatewayFactory::create('Stripe');
     $this->assertSame('Stripe', $gateway->getShortName());
 }
Esempio n. 6
0
 function capturePayment()
 {
     $gateway = GatewayFactory::create('AuthorizeNet_AIM');
     $gateway->setApiLoginId('2Scf4XP24');
     $gateway->setTransactionKey('96eRW9zn78X5s5dN');
     $card = array('number' => '4242424242424242', 'expiryMonth' => '6', 'expiryYear' => '2016', 'cvv' => '123');
     $response = $gateway->purchase(array('developerMode' => true, 'amount' => $this->amount(), 'currency' => 'USD', 'card' => $card))->send();
     return $response;
 }
 /**
  * Create the Form and the relevant gateway.
  * Set properties on gateway from config.
  *
  * @param Controller $controller
  * @param string $name
  */
 public function __construct($controller, $name = 'OmnipayableForm')
 {
     $fields = $this->getPaymentFields();
     $actions = $this->getPaymentActions();
     $validator = $this->getRequiredFields();
     parent::__construct($controller, $name, $fields, $actions, $validator);
     $gateway = Config::inst()->get('Omnipayable', 'Gateway');
     $gateways = Config::inst()->get('Omnipayable', 'Gateways');
     $gatewayConfig = $gateways[$gateway];
     $this->gateway = GatewayFactory::create($gateway);
     foreach ($gatewayConfig as $key => $value) {
         $method = "set{$key}";
         if (method_exists($this->gateway, $method)) {
             $this->gateway->{$method}($value);
         }
     }
 }
Esempio n. 8
0
 /**
  * Returns an Omnipay gateway.
  *
  * @param string $key        Gateway key as defined in the config
  *
  * @throws \RuntimeException If no gateway is configured for the key
  * @return AbstractGateway
  */
 public function get($key = null)
 {
     $config = $this->getConfig();
     if (is_null($key) && isset($config['default'])) {
         // No key was specified, so use the default gateway
         $key = $config['default'];
     }
     if (isset($this->cache[$key])) {
         // We've already instantiated this gateway, so just return the cached copy
         return $this->cache[$key];
     }
     $gatewayName = $this->getGatewayName($key);
     if (!$gatewayName) {
         // Invalid gateway key
         throw new \RuntimeException('Gateway key "' . $key . '" is not configured');
     }
     $adapter = new PsrLogAdapter($this->logger);
     $logPlugin = new LogPlugin($adapter, MessageFormatter::DEBUG_FORMAT);
     $client = new Client();
     $client->addSubscriber($logPlugin);
     $factory = new GatewayFactory();
     /** @var GatewayInterface $gateway */
     $gateway = $factory->create($gatewayName, $client);
     if (isset($config[$key])) {
         // Default parameters have been configured, so use them
         $combinedParameters = array_merge($this->getParametersByGatewayName($gatewayName), $config[$key]);
         $gatewayName = strtolower($combinedParameters['gateway']);
         if (isset($config['defaults'][$gatewayName])) {
             $combinedParameters = array_merge($combinedParameters, $config['defaults'][$gatewayName]);
         }
         $gateway->initialize($combinedParameters);
     }
     // Cache the gateway
     $this->cache[$key] = $gateway;
     return $gateway;
 }
<?php

namespace PHPSTORM_META;

/** @noinspection PhpIllegalArrayKeyTypeInspection */
/** @noinspection PhpUnusedLocalVariableInspection */
$STATIC_METHOD_TYPES = [\Omnipay\Omnipay::create('') => ['Skeleton' instanceof \Omnipay\Skeleton\Gateway], \Omnipay\Common\GatewayFactory::create('') => ['Skeleton' instanceof \Omnipay\Skeleton\Gateway]];
 /**
  * @expectedException \Omnipay\Common\Exception\RuntimeException
  * @expectedExceptionMessage Class '\Omnipay\Invalid\Gateway' not found
  */
 public function testCreateInvalid()
 {
     $gateway = GatewayFactory::create('Invalid');
 }
Esempio n. 11
0
 /**
  * Get the omnipay gateway associated with this payment,
  * with configuration applied.
  *
  * @throws RuntimeException - when gateway doesn't exist.
  * @return AbstractGateway omnipay gateway class
  */
 public function oGateway()
 {
     $factory = new GatewayFactory();
     $gateway = $factory->create($this->payment->Gateway, self::$httpclient, self::$httprequest);
     $parameters = Config::inst()->forClass('Payment')->parameters;
     if (isset($parameters[$this->payment->Gateway])) {
         $gateway->initialize($parameters[$this->payment->Gateway]);
     }
     return $gateway;
 }
Esempio n. 12
0
<?php

namespace PHPSTORM_META;

/** @noinspection PhpIllegalArrayKeyTypeInspection */
/** @noinspection PhpUnusedLocalVariableInspection */
$STATIC_METHOD_TYPES = [\Omnipay\Omnipay::create('') => ['Braintree' instanceof \Omnipay\Braintree\Gateway], \Omnipay\Common\GatewayFactory::create('') => ['Braintree' instanceof \Omnipay\Braintree\Gateway]];
<?php

namespace PHPSTORM_META;

/** @noinspection PhpIllegalArrayKeyTypeInspection */
/** @noinspection PhpUnusedLocalVariableInspection */
$STATIC_METHOD_TYPES = [\Omnipay\Omnipay::create('') => ['SecureTrading' instanceof \Omnipay\SecureTrading\Gateway], \Omnipay\Common\GatewayFactory::create('') => ['SecureTrading' instanceof \Omnipay\SecureTrading\Gateway]];
Esempio n. 14
0
 /**
  * Checks if the given gateway name is an off-site gateway.
  * 
  * @param  string  $gateway gateway name
  * @throws RuntimeException
  * @return boolean the gateway offsite or not
  */
 public static function is_offsite($gateway)
 {
     $factory = new GatewayFactory();
     $gateway = $factory->create($gateway);
     return $gateway->supportsCompletePurchase() || $gateway->supportsCompleteAuthorize() || method_exists($gateway, 'isOffsite') && $gateway->isOffsite();
 }
 /**
  * Checks if the given gateway name is an off-site gateway.
  *
  * @param  string $gateway gateway name
  * @throws \RuntimeException
  * @return boolean the gateway offsite or not
  */
 public static function isOffsite($gateway)
 {
     if (self::getConfigSetting($gateway, 'is_offsite')) {
         return true;
     }
     $factory = new GatewayFactory();
     $gateway = $factory->create($gateway);
     // Some offsite gateways don't separate between authorize and complete requests,
     // so we need a different way to determine they're off site in the first place
     // without kicking off a purchase request within Omnipay.
     if (method_exists($gateway, 'isOffsite')) {
         return !!$gateway->isOffsite();
     }
     if ($gateway instanceof AbstractGateway) {
         return $gateway->supportsCompletePurchase() || $gateway->supportsCompleteAuthorize();
     }
     return false;
 }
Esempio n. 16
0
<?php

namespace PHPSTORM_META;

/** @noinspection PhpIllegalArrayKeyTypeInspection */
/** @noinspection PhpUnusedLocalVariableInspection */
$STATIC_METHOD_TYPES = [\Omnipay\Omnipay::create('') => ['Pesapal' instanceof \Omnipay\Pesapal\Gateway], \Omnipay\Common\GatewayFactory::create('') => ['Pesapal' instanceof \Omnipay\Pesapal\Gateway]];
Esempio n. 17
0
 function init()
 {
     parent::init();
     //Memorize checkout page if not logged in
     $this->api->memorize('next_url', array('page' => $_GET['page'], 'order_id' => $_GET['order_id']));
     //Check for the authtentication
     if (!$this->app->auth->model->id) {
         $this->stepLogin();
         return;
     }
     $customer = $this->add('xepan\\commerce\\Model_Customer');
     if (!$customer->loadLoggedIn()) {
         $this->add('View_Error')->set("customer not found");
         // $this->app->redirect("logout");
         return;
     }
     // Check if order is owned by current member ??????
     if (isset($_GET['order_id'])) {
         $order = $this->order = $this->api->memorize('checkout_order', $this->api->recall('checkout_order', $this->add('xepan/commerce/Model_SalesOrder')->tryLoad($_GET['order_id'] ?: 0)));
         if (!$order->loaded()) {
             $this->api->forget('checkout_order');
             $this->add('View_Error')->set('Order not found');
             return;
         }
         if ($order['contact_id'] != $customer->id) {
             $this->add('View_Error')->set('Order does not belongs to your account. ' . $order->id);
             return;
         }
     }
     if ($_GET['canceled']) {
         $this->stepFailure();
         return;
     }
     //
     $this->api->stickyGET('step');
     $step = isset($_GET['step']) ? $_GET['step'] : "address";
     try {
         $this->{"step{$step}"}();
     } catch (Exception $e) {
         // remove all database tables if exists or connetion available
         // remove config-default.php if exists
         throw $e;
     }
     // ================================= PAYMENT MANAGEMENT =======================
     if ($_GET['pay_now'] == 'true') {
         if (!$this->app->recall('checkout_order') instanceof \xepan\commerce\Model_SalesOrder) {
             throw new \Exception("order not found");
         }
         $order = $this->order = $this->app->recall('checkout_order');
         $this->order->reload();
         // create gateway
         $gateway = $this->gateway;
         $gateway_factory = new GatewayFactory();
         $gateway = $gateway_factory->create($order['paymentgateway']);
         $gateway_parameters = $order->ref('paymentgateway_id')->get('parameters');
         $gateway_parameters = json_decode($gateway_parameters, true);
         // fill default values from database
         foreach ($gateway_parameters as $param => $value) {
             $param = ucfirst($param);
             $fn = "set" . $param;
             $gateway->{$fn}($value);
         }
         $protocol = stripos($_SERVER['SERVER_PROTOCOL'], 'https') === true ? 'https://' : 'http://';
         $params = array('amount' => $order['net_amount'], 'currency' => 'INR', 'description' => 'Invoice Against Order Payment', 'transactionId' => $order->id, 'headerImageUrl' => 'http://xavoc.com/logo.png', 'returnUrl' => $protocol . $_SERVER['HTTP_HOST'] . $this->api->url(null, array('paid' => 'true', 'pay_now' => 'true', 'order_id' => $this->order->id))->getURL(), 'cancelUrl' => $protocol . $_SERVER['HTTP_HOST'] . $this->api->url(null, array('canceled' => 'true', 'order_id' => $this->order->id))->getURL(), 'language' => 'EN', 'billing_name' => $customer['first_name'], 'billing_address' => $order['billing_address'], 'billing_city' => $order['billing_city'], 'billing_state' => $order['billing_state'], 'billing_country' => $order['billing_country'], 'billing_zip' => $order['billing_pincode'], 'billing_tel' => $customer['contacts_str'], 'billing_email' => $this->app->auth->model['username'], 'delivery_address' => $order['shipping_address'], 'delivery_city' => $order['shipping_city'], 'delivery_state' => $order['shipping_state'], 'delivery_country' => $order['shipping_country'], 'delivery_zip' => $order['shipping_pincode'], 'delivery_tel' => $customer['contacts_str'], 'delivery_email' => $this->app->auth->model['username']);
         // Step 2. if got returned from gateway ... manage ..
         if ($_GET['paid']) {
             $response = $gateway->completePurchase($params)->send($params);
             if (!$response->isSuccessful()) {
                 $order_status = $response->getOrderStatus();
                 throw new \Exception("Failed");
                 //   	if(in_array($order_status, ['Failure']))
                 //   		$order_status = "onlineFailure";
                 //   	elseif(in_array($order_status, ['Aborted']))
                 //   		$order_status = "onlineAborted";
                 //   	else
                 //   		$order_status = "onlineFailure";
                 // $order->setStatus($order_status);
                 $this->api->redirect($this->api->url(null, array('step' => "Failure", 'message' => $order_status, 'order_id' => $_GET['order_id'])));
             }
             $invoice = $order->invoice();
             $invoice->PayViaOnline($response->getTransactionReference(), $response->getData());
             //Change Order Status onlineUnPaid to Submitted
             $order->submit();
             //send email after payment id paid successfully
             try {
                 $salesorder_m = $this->add('xepan\\base\\Model_ConfigJsonModel', ['fields' => ['from_email' => 'Dropdown', 'subject' => 'line', 'body' => 'xepan\\base\\RichText', 'master' => 'xepan\\base\\RichText', 'detail' => 'xepan\\base\\RichText'], 'config_key' => 'SALESORDER_LAYOUT', 'application' => 'commerce']);
                 $salesorder_m->add('xepan\\hr\\Controller_ACL');
                 $salesorder_m->tryLoadAny();
                 $config = $this->app->epan->config;
                 $email_setting = $this->add('xepan\\communication\\Model_Communication_EmailSetting');
                 $email_setting->load($salesorder_m['from_email']);
                 $customer = $invoice->customer();
                 $to_email = implode(',', $customer->getEmails());
                 /*To Maintain the complability to send function*/
                 $subject = $salesorder_m['subject'];
                 $body = $salesorder_m['body'];
                 // $merge_model_array=[];
                 $this->merge_model_array = array_merge($this->merge_model_array, $invoice->get());
                 $this->merge_model_array = array_merge($this->merge_model_array, $order->get());
                 $this->merge_model_array = array_merge($this->merge_model_array, $customer->get());
                 $temp_subject = $this->add('GiTemplate');
                 $temp_subject->loadTemplateFromString($subject);
                 $subject_v = $this->add('View', null, null, $temp_subject);
                 $subject_v->template->set($this->merge_model_array);
                 $email_subject = $subject_v->getHtml();
                 $temp_body = $this->add('GiTemplate');
                 $temp_body->loadTemplateFromString($body);
                 $body_v = $this->add('View', null, null, $temp_body);
                 $body_v->template->set($this->merge_model_array);
                 $email_body = $body_v->getHtml();
                 $invoice->acl = false;
                 $invoice->send($email_setting->id, $to_email, null, null, $email_subject, $email_body);
                 // $subject_v->destroy();
                 // $body_v->destroy();
             } catch (Exception $e) {
             }
             $this->api->forget('checkout_order');
             // $this->stepComplete();
             $this->api->redirect($this->api->url(null, array('step' => "Complete", 'pay_now' => true, 'paid' => true, 'order_id' => $_GET['order_id'])));
             exit;
             // return;
         }
         // Step 1. initiate purchase ..
         try {
             //Sending $param with send function for passing value to gateway
             //dont know it's right way or no
             $response = $gateway->purchase($params)->send($params);
             if ($response->isSuccessful()) {
                 // mark order as complete if not COD
                 // Not doing onsite transactions now ...
                 $responsereturn = $response->getData();
             } elseif ($response->isRedirect()) {
                 $response->redirect();
             } else {
                 // display error to customer
                 exit($response->getMessage());
             }
         } catch (\Exception $e) {
             throw $e;
             // internal error, log exception and display a generic message to the customer
             exit('Sorry, there was an error processing your payment. Please try again later.' . $e->getMessage() . " " . get_class($e));
         }
     }
     // ================================= PAYMENT MANAGEMENT END ===================
 }
Esempio n. 18
0
<?php

namespace PHPSTORM_META;

/** @noinspection PhpIllegalArrayKeyTypeInspection */
/** @noinspection PhpUnusedLocalVariableInspection */
$STATIC_METHOD_TYPES = [\Omnipay\Omnipay::create('') => ['Creditcall' instanceof \Omnipay\Creditcall\Gateway], \Omnipay\Common\GatewayFactory::create('') => ['Creditcall' instanceof \Omnipay\Creditcall\Gateway]];
Esempio n. 19
0
 function init()
 {
     parent::init();
     // $crud =$this->app->layout->add('xepan\base\CRUD');
     $crud = $this->add('xepan\\base\\CRUD', ['allow_add' => false], null, ['view/payment/grid']);
     $btn = $crud->grid->addButton('Update')->addClass('btn btn-primary');
     $crud->setModel('xepan\\commerce\\PaymentGateway', array('is_active', 'name', 'processing', 'gateway_image_id'));
     $crud->grid->add('VirtualPage')->addColumn('Update_data')->set(function ($page) {
         $id = $_GET[$page->short_name . '_id'];
         $payment_gateway = $page->add('xepan/commerce/Model_PaymentGateway')->load($id);
         $form = $page->add('Form');
         $fields = json_decode($payment_gateway['default_parameters'], true);
         $values = json_decode($payment_gateway['parameters'], true);
         foreach ($fields as $field => $value) {
             if (is_array($value)) {
                 $form->addField('DropDown', $field)->setValueList($value)->set($values[$field]);
             } else {
                 $form->addField('line', $field)->set($values[$field]);
             }
         }
         $form->addSubmit('Update');
         if ($form->isSubmitted()) {
             $fields = json_decode($payment_gateway['default_parameters'], true);
             foreach ($fields as $field => $value) {
                 if (is_array($value)) {
                     $fields[$field] = $value[$form[$field]];
                 } else {
                     $fields[$field] = $form[$field];
                 }
             }
             $payment_gateway['parameters'] = json_encode($fields);
             $payment_gateway->save();
             $form->js(null, $form->js()->reload())->univ()->successMessage('Update Information')->execute();
         }
     });
     //update all Paymentgateway with there default parameters
     if ($btn->isClicked()) {
         $gateway = new GatewayFactory();
         //Get Omnipay Gateway
         $payment_gateway = $gateway->getSupportedGateways();
         //Save in SQL Model
         foreach ($payment_gateway as $gateway) {
             //tryload  PaymentGateway Model with name
             $pg_model = $this->add('xepan/commerce/Model_PaymentGateway');
             $pg_model->addCondition('name', $gateway);
             $pg_model->tryLoadAny();
             try {
                 //create OmniPay Object
                 $gateway_factory = GatewayFactory::create($gateway);
                 $pg_model['default_parameters'] = $gateway_factory->getDefaultParameters();
                 //getDefault Params
                 $pg_model['processing'] = $pg_model['processing'] ?: "OffSite";
                 $pg_model->saveAndUnload();
             } catch (\Exception $e) {
                 // throw $e;
             }
         }
         //xepan payment gateway
         foreach ($this->xepan_custom_gateway as $gateway_name) {
             $pg_model = $this->add('xepan/commerce/Model_PaymentGateway');
             $pg_model->addCondition('name', $gateway_name);
             $pg_model->tryLoadAny();
             try {
                 //create OmniPay Object
                 $gatewayfactory = new GatewayFactory();
                 $gateway_factory = $gatewayfactory->create($gateway_name);
                 $pg_model['default_parameters'] = $gateway_factory->getDefaultParameters();
                 //getDefault Params
                 $pg_model['processing'] = $pg_model['processing'] ?: "OffSite";
                 $pg_model->saveAndUnload();
             } catch (\Exception $e) {
                 throw $e;
             }
         }
         $crud->grid->js()->reload()->execute();
     }
     $crud->grid->addPaginator(10);
     $crud->grid->addQuickSearch(['name']);
 }
 public function gateway($name = null)
 {
     $gateway = $this->factory->create($this->config['gateways'][$name]['factory']);
     $gateway->initialize($this->config['gateways'][$name]);
     return $gateway;
 }