Ejemplo n.º 1
0
 function __construct(Am_Paysystem_Transaction_Interface $transaction)
 {
     $this->Amount = $transaction->getAmount();
     $this->PaysysId = $transaction->getPaysysId();
     $this->ReceiptId = $transaction->getReceiptId();
     $this->RecurringType = $transaction->getRecurringType();
     $this->Time = $transaction->getTime()->format('Y-m-d H:i:s');
     $this->TimeZone = $transaction->getTime()->getTimezone()->getName();
     $this->UniqId = $transaction->getUniqId();
 }
Ejemplo n.º 2
0
 public function setFromTransaction(Invoice $invoice, Am_Paysystem_Transaction_Interface $transaction, $refundType)
 {
     $this->dattm = $transaction->getTime()->format('Y-m-d H:i:s');
     $this->invoice_id = $invoice->invoice_id;
     $this->invoice_public_id = $invoice->public_id;
     $this->user_id = $invoice->user_id;
     $this->currency = $invoice->currency;
     $this->amount = $transaction->getAmount();
     $this->paysys_id = $transaction->getPaysysId();
     $this->receipt_id = $transaction->getReceiptId();
     $this->transaction_id = $transaction->getUniqId();
     $this->refund_type = $refundType;
     return $this;
 }
Ejemplo n.º 3
0
 public function setFromTransaction(Invoice $invoice, Am_Paysystem_Transaction_Interface $transaction)
 {
     $this->dattm = $transaction->getTime()->format('Y-m-d H:i:s');
     $this->invoice_id = $invoice->invoice_id;
     $this->invoice_public_id = $invoice->public_id;
     $this->user_id = $invoice->user_id;
     $this->currency = $invoice->currency;
     $this->paysys_id = $transaction->getPaysysId();
     $this->receipt_id = $transaction->getReceiptId();
     $this->transaction_id = $transaction->getUniqId();
     /// get from invoice
     $isFirst = !(doubleval($invoice->first_total) === 0.0 || $invoice->getPaymentsCount());
     $amount = $transaction->getAmount();
     if ($amount <= 0) {
         $amount = $isFirst ? $invoice->first_total : $invoice->second_total;
     }
     $this->amount = (double) $amount;
     $this->discount = $isFirst ? $invoice->first_discount : $invoice->second_discount;
     $this->tax = $isFirst ? $invoice->first_tax : $invoice->second_tax;
     $this->shipping = $isFirst ? $invoice->first_shipping : $invoice->second_shipping;
     return $this;
 }
Ejemplo n.º 4
0
 /**
  * Add access period for current product based on information from incoming paysystem transaction
  * @throws Am_Exception_Db_NotUnique
  */
 public function addAccessPeriod($isFirstPayment, Invoice $invoice, Am_Paysystem_Transaction_Interface $transaction, $beginDate, $invoicePaymentId)
 {
     if ($this->item_type != 'product') {
         return;
     }
     // if that is not a product then no access
     $a = $this->getDi()->accessRecord;
     $a->setDisableHooks(true);
     $a->begin_date = $beginDate;
     $p = new Am_Period($isFirstPayment ? $this->first_period : $this->second_period);
     $a->invoice_id = $this->invoice_id;
     $a->invoice_public_id = $this->invoice_public_id;
     $recurringType = $transaction->getRecurringType();
     if (in_array($recurringType, array(Am_Paysystem_Abstract::REPORTS_EOT, Am_Paysystem_Abstract::REPORTS_NOTHING))) {
         $a->expire_date = Am_Period::RECURRING_SQL_DATE;
     } else {
         $a->expire_date = $p->addTo($a->begin_date);
     }
     $a->product_id = $this->item_id;
     $a->user_id = $invoice->user_id;
     $a->transaction_id = $transaction->getUniqId();
     $a->invoice_payment_id = $invoicePaymentId;
     $a->invoice_item_id = $this->pk();
     $a->qty = $this->qty;
     $a->insert();
 }
Ejemplo n.º 5
0
 /** @return Invoice_Payment */
 protected function addPaymentWithoutAccessPeriod(Am_Paysystem_Transaction_Interface $transaction)
 {
     $c = $this->getPaymentsCount();
     if ($c >= $this->getExpectedPaymentsCount()) {
         $rt = (int) $this->rebill_times;
         if ($this->rebill_times) {
             throw new Am_Exception_Paysystem("Existing payments count [{$c}] exceeds number of allowed rebills [{$rt}]+1, could not add new payment");
         } else {
             // if that is not a recurring transaction, it is already handled for sure
             $paysys_id = $transaction->getPaysysId();
             $transaction_id = $transaction->getUniqId();
             throw new Am_Exception_Paysystem_TransactionAlreadyHandled("Transaction {$paysys_id}-{$transaction_id} is already handled");
         }
     }
     $p = $this->getDi()->invoicePaymentRecord;
     $p->setFromTransaction($this, $transaction);
     $p->_setInvoice($this);
     // caching
     try {
         $p->insert();
     } catch (Am_Exception_Db_NotUnique $e) {
         if ($e->getTable() == '?_invoice_payment') {
             throw new Am_Exception_Paysystem_TransactionAlreadyHandled("Transaction {$p->paysys_id}-{$p->transaction_id} is already handled");
         } else {
             throw $e;
         }
     }
     $records = $this->getAccessRecords();
     $isFirstPeriod = !$records;
     $this->addToRebillDate($isFirstPeriod);
     $this->updateStatus();
     return $p;
 }