Пример #1
0
 public function expressReturn()
 {
     $class = $this->request->get('id');
     $this->order->setPaymentMethod($class);
     $handler = $this->application->getExpressPaymentHandler($class, $this->getTransaction());
     $handler->setOrder($this->order);
     $details = $handler->getTransactionDetails($this->request->toArray());
     $address = UserAddress::getNewInstanceByTransaction($details);
     $address->save();
     $paymentData = array_diff_key($this->request->toArray(), array_flip(array('controller', 'action', 'id', 'route', 'PHPSESSID')));
     // @todo - determine if the order is new or completed earlier, but unpaid
     // for now only new orders can be paid with express checkout methods
     $order = $this->getPaymentOrder();
     $express = ExpressCheckout::getNewInstance($order, $handler);
     $express->address->set($address);
     $express->paymentData->set(serialize($paymentData));
     $express->save();
     // auto-login user if anonymous
     if ($this->user->isAnonymous()) {
         // create new user account if it doesn't exist
         if (!($user = User::getInstanceByEmail($details->email->get()))) {
             $user = User::getNewInstance($details->email->get());
             $user->firstName->set($details->firstName->get());
             $user->lastName->set($details->lastName->get());
             $user->companyName->set($details->companyName->get());
             $user->isEnabled->set(true);
             $user->save();
         }
         SessionUser::setUser($user);
         $order->setUser($user);
     }
     $order->billingAddress->set($address);
     if ($order->isShippingRequired()) {
         $order->shippingAddress->set($address);
     }
     $order->save();
     return new ActionRedirectResponse('checkout', 'shipping');
 }