Exemplo n.º 1
0
 /**
  * Gateway payment action method.
  *
  * Collects the payment information and transmit it to the payment provider.
  */
 public function gatewayAction()
 {
     $router = $this->Front()->Router();
     $config = $this->plugin->Config();
     $client = $this->get('paypalClient');
     $logoImage = $config->get('paypalLogoImage');
     if ($this->plugin->isShopware51()) {
         /** @var \Shopware\Bundle\MediaBundle\MediaService $mediaService */
         $mediaService = $this->get('shopware_media.media_service');
         $logoImage = $mediaService->getUrl($logoImage);
     }
     if (empty($logoImage) && empty($this->View()->theme)) {
         $logoImage = 'frontend/_resources/images/logo.jpg';
     }
     $logoImage = 'string:{link file=' . var_export($logoImage, true) . ' fullPath}';
     $logoImage = $this->View()->fetch($logoImage);
     $shopName = Shopware()->Config()->get('shopName');
     $shopName = $config->get('paypalBrandName', $shopName);
     $borderColor = ltrim($config->get('paypalCartBorderColor'), '#');
     if ($this->getUser() === null) {
         $paymentAction = 'Authorization';
     } else {
         $paymentAction = $config->get('paypalPaymentAction', 'Sale');
     }
     $params = array('PAYMENTACTION' => $paymentAction, 'RETURNURL' => $router->assemble(array('action' => 'return', 'forceSecure' => true)), 'CANCELURL' => $router->assemble(array('action' => 'cancel', 'forceSecure' => true)), 'NOTIFYURL' => $router->assemble(array('action' => 'notify', 'forceSecure' => true, 'appendSession' => true)), 'GIROPAYSUCCESSURL' => $router->assemble(array('action' => 'return', 'forceSecure' => true)), 'GIROPAYCANCELURL' => $router->assemble(array('action' => 'cancel', 'forceSecure' => true)), 'BANKTXNPENDINGURL' => $router->assemble(array('action' => 'return', 'forceSecure' => true)), 'ALLOWNOTE' => 1, 'ADDROVERRIDE' => $this->getUser() === null ? 0 : 1, 'BRANDNAME' => $shopName, 'LOGOIMG' => $logoImage, 'CARTBORDERCOLOR' => $borderColor, 'CUSTOM' => $this->createPaymentUniqueId(), 'TOTALTYPE' => $this->getUser() !== null ? 'Total' : 'EstimatedTotal');
     if ($config->get('paypalBillingAgreement') && $this->getUser() !== null) {
         $params['BILLINGTYPE'] = 'MerchantInitiatedBilling';
     }
     if ($config->get('paypalSeamlessCheckout') && !empty($this->session->PaypalAuth)) {
         $params['IDENTITYACCESSTOKEN'] = $this->session->PaypalAuth['access_token'];
     }
     $params = array_merge($params, $this->getBasketParameter());
     $params = array_merge($params, $this->getCustomerParameter());
     $response = $client->setExpressCheckout($params);
     $this->session->PaypalResponse = $response;
     if ($response['ACK'] == 'SuccessWithWarning') {
         $response['ACK'] = 'Success';
     }
     if (!empty($response['ACK']) && $response['ACK'] == 'Success') {
         if (!empty($config->paypalSandbox)) {
             $gatewayUrl = 'https://www.sandbox.paypal.com/';
         } else {
             $gatewayUrl = 'https://www.paypal.com/';
         }
         $gatewayUrl .= 'webscr&cmd=_express-checkout';
         if ($this->getUser() !== null) {
             $gatewayUrl .= '&useraction=commit';
         }
         $gatewayUrl .= '&token=' . urlencode($response['TOKEN']);
         $this->View()->PaypalGatewayUrl = $gatewayUrl;
     } else {
         $this->forward('return');
     }
 }