Пример #1
0
 public static function getNewInstance(CustomerOrder $order, TransactionResult $result)
 {
     $instance = parent::getNewInstance(__CLASS__);
     $instance->order->set($order);
     $instance->gatewayTransactionID->set($result->gatewayTransactionID->get());
     // determine currency
     if ($result->currency->get()) {
         $instance->realCurrency->set(Currency::getInstanceById($result->currency->get()));
     } else {
         $instance->realCurrency->set($order->currency->get());
     }
     // amount
     $instance->realAmount->set($result->amount->get());
     // different currency than initial order currency?
     if ($order->currency->get()->getID() != $result->currency->get()) {
         $instance->amount->set($order->currency->get()->convertAmount($instance->realCurrency->get(), $instance->realAmount->get()));
         $instance->currency->set($order->currency->get());
         // test if some amount is not missing due to currency conversion rounding (a difference of 0.01, etc)
         $total = $order->totalAmount->get();
         if ($instance->amount->get() < $total) {
             $largerAmount = $order->currency->get()->convertAmount($instance->realCurrency->get(), 0.01 + $instance->realAmount->get());
             if ($largerAmount >= $total) {
                 $instance->amount->set($total);
             }
         }
     }
     // transaction type
     $instance->type->set($result->getTransactionType());
     if ($instance->type->get() != self::TYPE_AUTH) {
         $instance->isCompleted->set(true);
     }
     if ($result->details->get()) {
         $instance->comment->set($result->details->get());
     }
     return $instance;
 }