示例#1
0
 public function configure()
 {
     if (null !== ($response = $this->checkAuth(array(AdminResources::MODULE), array('Paypal'), AccessManager::UPDATE))) {
         return $response;
     }
     $conf = new PaypalConfig();
     $one_is_done = 0;
     $tab = "";
     // Case form is paypal.configure
     $form = new \Paypal\Form\ConfigurePaypal($this->getRequest());
     try {
         $vform = $this->validateForm($form);
         $conf->setLogin($vform->get('login')->getData())->setPassword($vform->get('password')->getData())->setSignature($vform->get('signature')->getData())->write();
         $one_is_done = 1;
         $tab = "configure_account";
     } catch (\Exception $e) {
     }
     // Case form is paypal.configure.sandbox
     $form = new \Paypal\Form\ConfigureSandboxPaypal($this->getRequest());
     try {
         $vform = $this->validateForm($form);
         $tab = "configure_sandbox";
         $conf->setLoginSandbox($vform->get('login')->getData())->setPasswordSandbox($vform->get('password')->getData())->setSignatureSandbox($vform->get('signature')->getData())->setSandbox($vform->get('sandbox')->getData() ? "true" : "");
         $conf->write();
     } catch (\Exception $e) {
     }
     //Redirect to module configuration page
     $this->redirectToRoute("admin.module.configure", array(), array('module_code' => Paypal::getModCode(true), 'current_tab' => $tab, '_controller' => 'Thelia\\Controller\\Admin\\ModuleController::configureAction'));
 }
示例#2
0
 public function update_status(OrderEvent $event)
 {
     if ($event->getOrder()->getPaymentModuleId() === Paypal::getModCode()) {
         if ($event->getOrder()->isPaid()) {
             $contact_email = ConfigQuery::read('store_email');
             if ($contact_email) {
                 $message = MessageQuery::create()->filterByName('payment_confirmation_paypal')->findOne();
                 if (false === $message) {
                     throw new \Exception("Failed to load message 'payment_confirmation_paypal'.");
                 }
                 $order = $event->getOrder();
                 $customer = $order->getCustomer();
                 $this->parser->assign('order_id', $order->getId());
                 $this->parser->assign('order_ref', $order->getRef());
                 $message->setLocale($order->getLang()->getLocale());
                 $instance = \Swift_Message::newInstance()->addTo($customer->getEmail(), $customer->getFirstname() . " " . $customer->getLastname())->addFrom($contact_email, ConfigQuery::read('store_name'));
                 // Build subject and body
                 $message->buildMessage($this->parser, $instance);
                 $this->getMailer()->send($instance);
             }
         }
     }
 }
示例#3
0
 public function go($order_id)
 {
     /*
      * vars used for setExpressCheckout
      * $order Order The order object, which is used to get products and prices
      * $config ConfigInterface Object that contains configuration
      * $api PaypalApiCredentials Class used by the library to store and use 3T login(username, password, signature)
      * $redirect_api PaypalApiManager Instance of PaypalApiManager, only used to get checkout url ( and redirect to paypal )
      * $sandbox bool true if sandbox is enabled
      * $products array(array) 2D array that stores products in usable NVP format.
      * $i int counter
      * $logger PaypalApiLogManager used to log transactions with paypal
      */
     $order = OrderQuery::create()->findPk($order_id);
     $config = new PaypalConfig();
     $config->pushValues();
     $api = new PaypalApiCredentials($config);
     $redirect_api = new PaypalApiManager($config);
     $sandbox = $api->getConfig()->getSandbox();
     $products = array(array());
     $i = 0;
     $logger = new PaypalApiLogManager();
     /*
      * Store products into 2d array $products
      */
     $products_amount = 0;
     foreach ($order->getOrderProducts() as $product) {
         if ($product !== null) {
             $amount = floatval($product->getWasInPromo() ? $product->getPromoPrice() : $product->getPrice());
             foreach ($product->getOrderProductTaxes() as $tax) {
                 $amount += $product->getWasInPromo() ? $tax->getPromoAmount() : $tax->getAmount();
             }
             $products_amount += $amount * $product->getQuantity();
             $products[0]["NAME" . $i] = urlencode($product->getTitle());
             $products[0]["AMT" . $i] = urlencode(round($amount, 2));
             $products[0]["QTY" . $i] = urlencode($product->getQuantity());
             $i++;
         }
     }
     /*
      * Compute difference between prodcts total and cart amount
      * -> get Coupons.
      */
     $delta = round($products_amount - $order->getTotalAmount($useless, false), 2);
     if ($delta > 0) {
         $products[0]["NAME" . $i] = Translator::getInstance()->trans("Discount");
         $products[0]["AMT" . $i] = -$delta;
         $products[0]["QTY" . $i] = 1;
     }
     /*
      * Create setExpressCheckout request
      */
     $setExpressCheckout = new PaypalNvpOperationsSetExpressCheckout($api, round($order->getTotalAmount(), 2), $order->getCurrency()->getCode(), Paypal::getPaypalURL('paiement', $order_id), Paypal::getPaypalURL('cancel', $order_id), 0, array("L_PAYMENTREQUEST" => $products, "PAYMENTREQUEST" => array(array("SHIPPINGAMT" => round($order->getPostage(), 2), "ITEMAMT" => round($order->getTotalAmount($useless, false), 2)))));
     /*
      * Try to get customer's delivery address
      */
     $address = OrderAddressQuery::create()->findPk($order->getDeliveryOrderAddressId());
     if ($address !== null) {
         /*
          * If address is found, set address in setExpressCheckout request
          */
         $setExpressCheckout->setCustomerDeliveryAddress($address->getLastname(), $address->getAddress1(), $address->getAddress2(), $address->getCity(), "", $address->getZipcode(), CountryQuery::create()->findPk($address->getCountryId())->getIsoalpha2());
         /*
          * $sender PaypalNvpMessageSender Instance of the class that sends requests
          * $response string NVP response of paypal for setExpressCheckout request
          * $req array array cast of NVP response
          */
         $sender = new PaypalNvpMessageSender($setExpressCheckout, $sandbox);
         $response = $sender->send();
         $logger->logTransaction($response);
         $response = PaypalApiManager::nvpToArray($response);
         /*
          * if setExpressCheckout is correct, store values in the session & redirect to paypal checkout page
          * else print error. ( return $this->render ... )
          */
         if (isset($response['ACK']) && $response['ACK'] === "Success" && isset($response['TOKEN']) && !empty($response['TOKEN'])) {
             $sess = $this->getRequest()->getSession();
             $sess->set("Paypal.token", $response['TOKEN']);
             return new RedirectResponse($redirect_api->getExpressCheckoutUrl($response['TOKEN']));
         }
     }
     return $this->render("gotopaypalfail", array(), 500);
 }
示例#4
0
 /**
  * @return int
  */
 public static function getModCode($flag = false)
 {
     $obj = new Paypal();
     $mod_code = $obj->getCode();
     if ($flag) {
         return $mod_code;
     }
     $search = ModuleQuery::create()->findOneByCode($mod_code);
     return $search->getId();
 }