/**
  * @param \Enlight_Controller_ActionEventArgs $args
  */
 public function onPreDispatchPaymentPaypal($args)
 {
     $request = $args->getRequest();
     /** @var \Shopware_Controllers_Frontend_PaymentPaypal $action */
     $action = $args->getSubject();
     if ($request->getActionName() != 'return') {
         return;
     }
     $paymentId = $this->session->PaypalPlusPayment;
     if (empty($paymentId)) {
         return;
     }
     $payerId = $request->getParam('PayerID');
     $this->restClient->setAuthToken();
     $uri = 'payments/payment/' . $paymentId;
     $payment = $this->restClient->get($uri, array('payer_id' => $payerId));
     $statusId = $this->paypalBootstrap->Config()->get('paypalStatusId', 12);
     if (!empty($payment['transactions'][0]['amount']['total'])) {
         $ppAmount = floatval($payment['transactions'][0]['amount']['total']);
         $ppCurrency = floatval($payment['transactions'][0]['amount']['currency']);
     } else {
         $ppAmount = 0;
         $ppCurrency = '';
     }
     $swAmount = $action->getAmount();
     $swCurrency = $action->getCurrencyShortName();
     if (abs($swAmount - $ppAmount) >= 0.01 || $ppCurrency != $swCurrency) {
         $action->redirect(array('controller' => 'checkout', 'action' => 'confirm'));
         return;
     }
     if ($payment['state'] == 'created') {
         $uri = "payments/payment/{$paymentId}/execute";
         $payment = $this->restClient->create($uri, array('payer_id' => $payerId));
     }
     if ($payment['state'] == 'approved') {
         if (!empty($payment['transactions'][0]['related_resources'][0]['sale']['id'])) {
             $transactionId = $payment['transactions'][0]['related_resources'][0]['sale']['id'];
         } else {
             $transactionId = $payment['id'];
         }
         $orderNumber = $action->saveOrder($transactionId, sha1($payment['id']), $statusId);
         if ($payment['payment_instruction']) {
             $this->saveInvoiceInstructions($orderNumber, $payment);
         }
         try {
             $sql = '
                 INSERT INTO s_order_attributes (orderID, swag_payal_express)
                 SELECT id, 2 FROM s_order WHERE ordernumber = ?
                 ON DUPLICATE KEY UPDATE swag_payal_express = 2
             ';
             $action->get('db')->query($sql, array($orderNumber));
         } catch (\Exception $e) {
         }
         $action->redirect(array('controller' => 'checkout', 'action' => 'finish', 'sUniqueID' => sha1($payment['id'])));
     }
 }
Пример #2
0
 /**
  * @param ControllerAction $action
  */
 public function onPaypalPlus(ControllerAction $action)
 {
     $config = $this->config;
     $router = $action->Front()->Router();
     $view = $action->View();
     $user = $view->getAssign('sUserData');
     $basket = $view->getAssign('sBasket');
     $cancelUrl = $router->assemble(array('controller' => 'payment_paypal', 'action' => 'cancel', 'forceSecure' => true));
     $returnUrl = $router->assemble(array('controller' => 'payment_paypal', 'action' => 'return', 'forceSecure' => true));
     $profile = $this->getProfile();
     $this->restClient->setAuthToken();
     $uri = 'payments/payment';
     $params = array('intent' => 'sale', 'experience_profile_id' => $profile['id'], 'payer' => array('payment_method' => 'paypal'), 'transactions' => $this->getTransactionData($basket, $user), 'redirect_urls' => array('return_url' => $returnUrl, 'cancel_url' => $cancelUrl));
     $payment = $this->restClient->create($uri, $params);
     if (!empty($payment['links'][1]['href'])) {
         $view->assign('PaypalPlusApprovalUrl', $payment['links'][1]['href']);
         $view->assign('PaypalPlusModeSandbox', $config->get('paypalSandbox'));
         $view->assign('PaypalLocale', $this->paypalBootstrap->getLocaleCode());
         $db = $this->bootstrap->get('db');
         $sql = 'SELECT paymentmeanID AS id, paypal_plus_media AS media
                 FROM s_core_paymentmeans_attributes WHERE paypal_plus_active = 1';
         $paymentMethods = $db->fetchAssoc($sql);
         $view->assign('PaypalPlusThirdPartyPaymentMethods', $paymentMethods);
         $this->session->PaypalPlusPayment = $payment['id'];
     }
 }
 public function testClientAction()
 {
     $this->get('paypalClient');
     $config = $this->Request()->getParams();
     $config = new \Enlight_Config($config, true);
     // Test timeout
     $timeout = ($config->get('paypalTimeout') ?: 20) * 0.25;
     $config->set('paypalTimeout', $timeout);
     /** @var Zend_Http_Client|Client|RestClient $client */
     $client = null;
     try {
         $client = new Client($config, true);
         $data = $client->getBalance();
         for ($i = 0; isset($data['L_AMT' . $i]); $i++) {
             unset($data['L_AMT' . $i], $data['L_CURRENCYCODE' . $i]);
         }
         unset($data['VERSION']);
         if (isset($data['L_ERRORCODE0'])) {
             $data['code'] = $data['L_ERRORCODE0'];
             $data['message'] = $this->formatErrorMessage($data);
             unset($data['L_ERRORCODE0'], $data['L_SHORTMESSAGE0'], $data['L_LONGMESSAGE0'], $data['L_SEVERITYCODE0']);
         }
         if ($config->get('paypalClientId', false) && $data['ACK'] == 'Success') {
             $client = new RestClient($config);
             $data = $client->setAuthToken();
             $data = array('ACK' => 'Success') + $data;
             if (isset($data['access_token'])) {
                 $data['access_token'] = preg_replace('/[A-Z]/', '#', $data['access_token']);
             }
             unset($data['expires_in']);
         }
     } catch (Exception $e) {
         $data = array('code' => $e->getCode(), 'message' => $e->getMessage());
     }
     $data['shopware_version'] = Shopware::VERSION;
     $data['php_version'] = phpversion();
     if ($config->get('paypalCurl', true) && function_exists('curl_version')) {
         $curlVersion = curl_version();
         $data['curl_version'] = $curlVersion['version'];
         $data['system_host'] = $curlVersion['host'];
         $data['ssl_version'] = $curlVersion['ssl_version'];
         $data['libz_version'] = $curlVersion['libz_version'];
     }
     $this->View()->assign($data);
 }