private function _getRecurringFrequency(Payment_Invoice_Subscription $recurrenceInfo)
 {
     switch ($recurrenceInfo->getCycle()) {
         case 'D':
             $t = 'days';
             break;
         case 'W':
             $t = 'week';
             break;
         case 'M':
             $t = 'month';
             break;
         case 'Y':
             $t = 'year';
             break;
         default:
             $t = 'month';
             break;
     }
     return $recurrenceInfo->getCycle() . ' ' . $t;
 }
Esempio n. 2
0
 /**
  * @param \Model_Invoice $invoice
  * @param bool $subscribe
  * @return \Payment_Invoice
  */
 public function getPaymentInvoice(\Model_Invoice $invoice, $subscribe = false)
 {
     $proforma = $this->toApiArray($invoice);
     $client = $this->getBuyer($invoice);
     $buyer = new \Payment_Invoice_Buyer();
     $buyer->setEmail($client['email'])->setFirstName($client['first_name'])->setLastName($client['last_name'])->setCompany($client['company'])->setAddress($client['address'])->setCity($client['city'])->setState($client['state'])->setZip($client['zip'])->setPhone($client['phone'])->setPhoneCountryCode($client['phone_cc'])->setCountry($client['country']);
     $first_title = null;
     $items = array();
     foreach ($proforma['lines'] as $item) {
         $pi = new \Payment_Invoice_Item();
         $pi->setId($item['id'])->setTitle($item['title'])->setDescription($item['title'])->setPrice($item['price'])->setTax($item['tax'])->setQuantity($item['quantity']);
         $items[] = $pi;
         if (is_null($first_title) && count($proforma['lines']) == 1) {
             $first_title = $item['title'];
         }
     }
     $params = array(':id' => sprintf('%05s', $proforma['nr']), ':serie' => $proforma['serie'], ':title' => $first_title);
     if ($first_title) {
         $title = __('Payment for invoice :serie:id [:title]', $params);
     } else {
         $title = __('Payment for invoice :serie:id', $params);
     }
     $mpi = new \Payment_Invoice();
     $mpi->setId($invoice->id);
     $mpi->setNumber($proforma['nr']);
     $mpi->setBuyer($buyer);
     $mpi->setCurrency($proforma['currency']);
     $mpi->setTitle($title);
     $mpi->setItems($items);
     $subscribeService = $this->di['mod_service']('Invoice', 'Subscription');
     // can subscribe only if proforma has one item with defined period
     if ($subscribe && $subscribeService->isSubscribable($invoice->id)) {
         $subitem = $invoice->InvoiceItem->getFirst();
         $period = $this->di['period']($subitem->period);
         $bs = new \Payment_Invoice_Subscription();
         $bs->setId($proforma['id']);
         $bs->setAmount($mpi->getTotalWithTax());
         $bs->setCycle($period->getQty());
         $bs->setUnit($period->getUnit());
         $mpi->setSubscription($bs);
         $mpi->setTitle('Subscription for ' . $subitem->title);
     }
     return $mpi;
 }