コード例 #1
0
 /**
  * Applies filter for subscription
  * @param AW_Sarp_Model_Subscription $Subscription
  * @return AW_Sarp_Model_Mysql4_Subscription_Item_Collection
  */
 public function addSubscriptionFilter(AW_Sarp_Model_Subscription $Subscription)
 {
     if ($Subscription->getId()) {
         $this->getSelect()->where('subscription_id=?', $Subscription->getId());
     } else {
         throw new Mage_Core_Exception("Can't apply subscription filter for non-existing subscription");
     }
     return $this;
 }
コード例 #2
0
 /**
  * Creates subscription at paypal
  * @param AW_Sarp_Model_Subscription $Subscription
  * @return
  */
 public function createSubscription(AW_Sarp_Model_Subscription $Subscription, $Order, $Quote)
 {
     // 1. Create subscription profile with 0 period
     // 2. Save CCInfoKey and CustomerInfoKey
     $Payment = $Quote->getPayment();
     // Credit Card number
     $ccNumber = Mage::getSingleton('customer/session')->getSarpCcNumber();
     // CVV
     //$ccCode = Mage::getSingleton('customer/session')->getSarpCcCid();
     // Glue month and year
     $expirationDate = sprintf("%02s", $Payment->getMethodInstance()->getInfoInstance()->getCcExpMonth()) . $Payment->getMethodInstance()->getInfoInstance()->getCcExpYear();
     // Customer name
     $customerName = $Quote->getBillingAddress()->getFirstname() . " " . $Quote->getBillingAddress()->getLastname();
     // Calculate start date
     $Date = $Subscription->getNextSubscriptionEventDate(new Zend_Date($Subscription->getDateStart()));
     $Date->addDayOfYear(0 - $Subscription->getPeriod()->getPaymentOffset());
     $date_start = $this->getWebService()->formatDate($Date);
     // Total
     $total = floatval($Subscription->getLastOrder()->getGrandTotal());
     $this->getWebService()->getRequest()->reset()->setData(array('CcAccountNum' => $ccNumber, 'CcExpDate' => $expirationDate, 'FirstName' => $Quote->getBillingAddress()->getFirstname(), 'CustomerName' => $customerName, 'CustomerID' => $Quote->getCustomerEmail(), 'LastName' => $Quote->getBillingAddress()->getLastname(), 'BillingInterval' => "0", 'BillingPeriod' => "DAY", 'StartDate' => $date_start, 'EndDate' => $date_start, 'BillAmt' => $total, 'TotalAmt' => $total, 'ContractName' => Mage::helper('sarp')->__("Subscription #%s", $Subscription->getId()), 'ContractID' => $Subscription->getId()));
     try {
         $result = $this->getWebService()->addRecurringCreditCard();
         $CCInfoKey = $result->CcInfoKey;
         $CustomerKey = $result->CustomerKey;
         /**
          * @todo Add and save ContractKey
          */
         $Subscription->setRealId($CustomerKey)->setRealPaymentId($CCInfoKey)->save();
     } catch (Exception $E) {
         throw new AW_Sarp_Exception("Argofire recurrent profile creation failed for subscription #{$Subscription->getId()} " . "and order #{$Order->getId()}", print_r($result, 1));
     }
     $this->log(print_r($result, 1));
 }
コード例 #3
0
ファイル: Flat.php プロジェクト: xiaoguizhidao/mydigibits
 /**
  * Presets flat data from subscription
  * @param AW_Sarp_Model_Subscription $Subscription
  * @return AW_Sarp_Model_Subscription_Flat
  */
 public function setSubscription(AW_Sarp_Model_Subscription $Subscription)
 {
     Zend_Date::setOptions(array('extend_month' => true));
     // Fix Zend_Date::addMonth unexpected result
     if (!$Subscription->isInfinite()) {
         $expireDate = $Subscription->getDateExpire()->toString(AW_Sarp_Model_Subscription::DB_DATE_FORMAT);
     } else {
         $expireDate = null;
     }
     if ($Subscription->getIsNew()) {
         $lastOrderAmount = $Subscription->getQuote()->getGrandTotal();
         $virtual = $Subscription->getQuote()->getIsVirtual();
     } else {
         $lastOrderAmount = $Subscription->getLastOrder()->getGrandTotal();
         $virtual = $Subscription->getLastOrder()->getIsVirtual();
     }
     if ($Subscription->isActive()) {
         $paymentOffset = $Subscription->getPeriod()->getPaymentOffset();
         // Get next payment date
         if (!$Subscription->getLastPaidDate()) {
             $nextPaymentDate = $Subscription->getLastOrder()->getCreatedAtStoreDate();
             $nextPaymentDate = $Subscription->getNextSubscriptionEventDate($Subscription->getDateStart());
             $nextDeliveryDate = clone $Subscription->getDateStart();
             $nextDeliveryDate->addDayOfYear(0 + floatval($paymentOffset));
         } else {
             $nextPaymentDate = $Subscription->getNextSubscriptionEventDate();
         }
         if ($paymentOffset) {
             if (!$Subscription->getLastPaidDate()) {
                 // No payments made yet
                 $lastOrderDate = clone $Subscription->getDateStart();
                 $lastOrderDate->addDayOfYear(0 - floatval($paymentOffset));
             } else {
                 $lastOrderDate = $Subscription->getLastOrder()->getCreatedAtStoreDate();
             }
             $probablyDeliveryDate = clone $lastOrderDate;
             $probablyDeliveryDate = $probablyDeliveryDate->addDayOfYear(floatval($paymentOffset));
             if ($probablyDeliveryDate->compare(new Zend_Date(), Zend_Date::DATE_SHORT) > 0) {
                 $nextDeliveryDate = clone $lastOrderDate;
             }
             $nextPaymentDate->addDayOfYear(0 - floatval($paymentOffset));
         }
         if (!isset($nextDeliveryDate)) {
             $nextDeliveryDate = clone $nextPaymentDate;
         }
         $nextDeliveryDate = $nextDeliveryDate->addDayOfYear(floatval($paymentOffset))->toString(AW_Sarp_Model_Subscription::DB_DATE_FORMAT);
         $nextPaymentDate = $nextPaymentDate->toString(AW_Sarp_Model_Subscription::DB_DATE_FORMAT);
     } else {
         // Drop next payment date if subscription is suspended
         $nextDeliveryDate = $nextPaymentDate = null;
     }
     $this->setSubscriptionId($Subscription->getId())->setCustomerName($Subscription->getCustomer()->getName())->setCustomerEmail($Subscription->getCustomer()->getEmail())->setFlatLastOrderStatus($Subscription->getLastOrder()->getStatus())->setFlatLastOrderAmount($lastOrderAmount)->setFlatLastOrderCurrencyCode($Subscription->getLastOrder()->getOrderCurrencyCode())->setFlatDateExpire($expireDate)->setHasShipping(1 - $virtual)->setFlatNextPaymentDate($nextPaymentDate)->setFlatNextDeliveryDate($nextDeliveryDate)->setProductsText($this->_convertProductsText($Subscription))->setProductsSku($this->_convertProductsSku($Subscription));
     $Subscription->setCustomerName($Subscription->getCustomer()->getName())->setCustomerEmail($Subscription->getCustomer()->getEmail())->setFlatLastOrderStatus($Subscription->getLastOrder()->getStatus())->setFlatLastOrderAmount($lastOrderAmount)->setFlatLastOrderCurrencyCode($Subscription->getLastOrder()->getOrderCurrencyCode())->setFlatDateExpire($expireDate)->setHasShipping(1 - $virtual)->setFlatNextPaymentDate($nextPaymentDate)->setFlatNextDeliveryDate($nextDeliveryDate)->setProductsText($this->_convertProductsText($Subscription))->setProductsSku($this->_convertProductsSku($Subscription));
     return $this;
 }
コード例 #4
0
ファイル: Shipping.php プロジェクト: xiaoguizhidao/mydigibits
 /**
  * Saves billing section to order
  * @param Mage_Sales_Model_Order $Order
  * @return
  */
 public function preset(AW_Sarp_Model_Subscription $subscription, $data)
 {
     $order = $subscription->getOrder();
     $shippingAddress = $order->getShippingAddress();
     foreach ($data as $key => $value) {
         $shippingAddress->setData($key, $value);
     }
     $shippingAddress->implodeStreetAddress();
     $shippingAddress->save();
     return $order;
 }
コード例 #5
0
ファイル: Observer.php プロジェクト: xiaoguizhidao/mydigibits
 /**
  * Saves payment information in session
  * This workaround is used for correct functionality at Magento 1.4+
  * @param object $observer
  */
 public function savePaymentInfoInSession($observer)
 {
     try {
         if (!AW_Sarp_Model_Subscription::isIterating()) {
             $quote = $observer->getEvent()->getQuote();
             if (!$quote->getPaymentsCollection()->count()) {
                 return;
             }
             $Payment = $quote->getPayment();
             if ($Payment && $Payment->getMethod()) {
                 if ($Payment->getMethodInstance() instanceof Mage_Payment_Model_Method_Cc) {
                     // Credit Card number
                     if ($Payment->getMethodInstance()->getInfoInstance() && ($ccNumber = $Payment->getMethodInstance()->getInfoInstance()->getCcNumber())) {
                         $ccCid = $Payment->getMethodInstance()->getInfoInstance()->getCcCid();
                         $ccType = $Payment->getMethodInstance()->getInfoInstance()->getCcType();
                         $ccExpMonth = $Payment->getMethodInstance()->getInfoInstance()->getCcExpMonth();
                         $ccExpYear = $Payment->getMethodInstance()->getInfoInstance()->getCcExpYear();
                         Mage::getSingleton('customer/session')->setSarpCcNumber($ccNumber);
                         Mage::getSingleton('customer/session')->setSarpCcCid($ccCid);
                     }
                 }
             }
         }
     } catch (Exception $e) {
         //throw($e);
     }
 }
コード例 #6
0
ファイル: Billing.php プロジェクト: xiaoguizhidao/mydigibits
 /**
  * Saves billing section to order
  * @param Mage_Sales_Model_Order $Order
  * @return
  */
 public function preset(AW_Sarp_Model_Subscription $subscription, $data)
 {
     $order = $subscription->getOrder();
     $billingAddress = $order->getBillingAddress();
     foreach ($data as $key => $value) {
         $billingAddress->setData($key, $value);
     }
     $billingAddress->implodeStreetAddress();
     try {
         $this->_prepareSave($subscription, $billingAddress);
         $billingAddress->save();
     } catch (Exception $e) {
         var_dump($e);
         die;
     }
     return $order;
 }
コード例 #7
0
 public function authorize(Varien_Object $payment, $amount)
 {
     if (AW_Sarp_Model_Subscription::isIterating()) {
         $Subscription = AW_Sarp_Model_Subscription::getInstance()->processPayment($payment->getOrder());
         return $this;
     }
     return parent::authorize($payment, $amount);
 }
コード例 #8
0
ファイル: Direct.php プロジェクト: xiaoguizhidao/mydigibits
 public function authorize(Varien_Object $payment, $amount)
 {
     if (AW_Sarp_Model_Subscription::isIterating()) {
         $Subscription = AW_Sarp_Model_Subscription::getInstance()->processPayment($payment->getOrder());
         return $this;
     }
     $result = parent::authorize($payment, $amount);
     $verify_result = Mage::getModel('sarp/payment_method_paypaluk_direct')->getPnref($payment, $amount, $payment->getOrder()->getBaseCurrencyCode());
     Mage::dispatchEvent(self::EVENT_NAME_AUTH_AFTER, array('verification' => $verify_result));
     return $result;
 }
コード例 #9
0
 public function authorize(Varien_Object $payment, $amount)
 {
     if (AW_Sarp_Model_Subscription::isIterating()) {
         AW_Sarp_Model_Subscription::getInstance()->processPayment($payment->getOrder());
         if (Mage::helper('sarp')->checkVersion('1.5.0.0')) {
             $this->_copyDataFromLastPayment($payment, $amount, parent::REQUEST_TYPE_AUTH_ONLY);
             $this->_placeTransaction($payment, $amount, parent::REQUEST_TYPE_AUTH_ONLY);
             $payment->setSkipTransactionCreation(1);
         }
         return $this;
     }
     return parent::authorize($payment, $amount);
 }
コード例 #10
0
 /**
  * Validate payment method information object
  *
  * @param   Mage_Payment_Model_Info $info
  * @return  Mage_Payment_Model_Abstract
  */
 public function validate()
 {
     if (AW_Sarp_Model_Subscription::isIterating()) {
         if (!self::$poIsset) {
             $info = $this->getInfoInstance();
             if ($info) {
                 $poNumber = $info->getData('po_number');
                 if ($poNumber) {
                     $info->setPoNumber($poNumber . '-' . Mage::getModel('core/date')->date('dmy'));
                     self::$poIsset = true;
                 }
             }
         }
         return $this;
     } else {
         return parent::validate();
     }
 }
コード例 #11
0
 /**
  * Adds filter by subscription
  * @return AW_Sarp_Model_Mysql4_Sequence_Collection
  */
 public function addSubscriptionFilter(AW_Sarp_Model_Subscription $subscription)
 {
     $this->getSelect()->where('subscription_id=?', $subscription->getId());
     return $this;
 }
コード例 #12
0
ファイル: Sequence.php プロジェクト: xiaoguizhidao/mydigibits
 /**
  * Returns orders array by subscription
  * @param AW_Sarp_Model_Subscription $subscription
  * @return array
  */
 public function getOrdersBySubscription($subscription)
 {
     $subscriptionId = $subscription->getId();
     $collection = $this->getCollection();
     $select = $collection->getSelect()->where('subscription_id=?', $subscriptionId);
     $orders = array();
     foreach ($collection as $item) {
         if ($item->getOrderId()) {
             $orders[] = Mage::getModel('sales/order')->load($item->getOrderId());
         }
     }
     return $orders;
 }
コード例 #13
0
ファイル: List.php プロジェクト: par-orillonsoft/magento_work
 public function getSubscriptionStatusLabel(AW_Sarp_Model_Subscription $subscription)
 {
     return Mage::getModel('sarp/source_subscription_status')->getLabel($subscription->getStatus());
 }
コード例 #14
0
 /**
  * Processes subscription by sequence
  * @param object $Item
  * @return bool
  */
 public function payBySequence($Item)
 {
     self::$_subscription = $this;
     if (!$this->_getMethodInstance()->isValidForTransaction($Item)) {
         $Item->setStatus(AW_Sarp_Model_Sequence::STATUS_FAILED)->save();
         $this->log("sequence is skipped");
         return false;
     }
     Mage::getSingleton('sarp/subscription')->setId($this->getId());
     try {
         $Order = $this->_iterate();
     } catch (SoapFault $e) {
         //is soap fault was generated
         $this->log("Payment message: #{$this->getId()}: {$e->getMessage()}");
         $attemptsQty = $Item->getData('attempts_qty') + 1;
         $Item->setData('attempts_qty', $attemptsQty)->save();
         $numberOfRetries = intval(Mage::getStoreConfig(AW_Sarp_Helper_Config::XML_PATH_ADVANCED_NUMBER_OF_RETRIES));
         if ($attemptsQty < $numberOfRetries) {
             return true;
         }
         $Item->setStatus(AW_Sarp_Model_Sequence::STATUS_FAILED)->save();
         $this->log("sequence is skipped");
         throw new AW_Sarp_Exception("Payment message: #{$this->getId()}: {$e->getMessage()}");
     }
     if ($Order instanceof Mage_Sales_Model_Order) {
         switch ($Order->getState()) {
             case Mage_Sales_Model_Order::STATE_COMPLETE:
                 $Item->setStatus(AW_Sarp_Model_Sequence::STATUS_PAYED);
                 break;
             case Mage_Sales_Model_Order::STATE_CANCELED:
                 $Item->setStatus(AW_Sarp_Model_Sequence::STATUS_FAILED);
                 break;
             default:
                 $Item->setStatus(AW_Sarp_Model_Sequence::STATUS_PENDING_PAYMENT);
         }
         if (Mage::helper('sarp')->isOrderStatusValidForActivation($Order->getStatus())) {
             $Item->setStatus(AW_Sarp_Model_Sequence::STATUS_PAYED);
         } else {
             $setStatusSuspended = 1;
         }
         $date = Mage::app()->getLocale()->date(new Zend_Date());
         $this->log('Date ' . $date . ' for subscription #' . $this->getId() . ' successfully marked as payed');
         $Item->setOrderId($Order->getId())->save();
     } else {
         // Order creation failed
         $Item->setStatus(AW_Sarp_Model_Sequence::STATUS_FAILED)->save();
     }
     if (isset($setStatusSuspended) && $setStatusSuspended) {
         $this->setStatus(self::STATUS_SUSPENDED)->setFlagNoSequenceUpdate(1)->save()->setFlagNoSequenceUpdate(0);
     }
     return true;
 }
コード例 #15
0
 /**
  * Processes subscription by sequence
  * @param object $Item
  * @return bool
  */
 public function payBySequence($Item)
 {
     self::$_subscription = $this;
     if (!$this->_getMethodInstance()->isValidForTransaction($Item)) {
         $this->log("sequence is skipped");
         return false;
     }
     Mage::getSingleton('sarp/subscription')->setId($this->getId());
     $Order = $this->_iterate();
     if ($Order instanceof Mage_Sales_Model_Order) {
         switch ($Order->getStatus()) {
             case Mage_Sales_Model_Order::STATE_COMPLETE:
                 $Item->setStatus(AW_Sarp_Model_Sequence::STATUS_PAYED);
                 break;
             case Mage_Sales_Model_Order::STATE_CANCELED:
                 $Item->setStatus(AW_Sarp_Model_Sequence::STATUS_FAILED);
                 break;
             default:
                 $Item->setStatus(AW_Sarp_Model_Sequence::STATUS_PENDING_PAYMENT);
         }
         if (Mage::helper('sarp')->isOrderStatusValidForActivation($Order->getStatus())) {
             $Item->setStatus(AW_Sarp_Model_Sequence::STATUS_PAYED);
         } else {
             $setStatusSuspended = 1;
         }
         $date = Mage::app()->getLocale()->date(new Zend_Date());
         $this->log('Date ' . $date . ' for subscription #' . $this->getId() . ' successfully marked as payed');
         $Item->setOrderId($Order->getId())->save();
     } else {
         // Order creation failed
         $Item->setStatus(AW_Sarp_Model_Sequence::STATUS_FAILED)->save();
     }
     if (isset($setStatusSuspended) && $setStatusSuspended) {
         $this->setStatus(self::STATUS_SUSPENDED)->setFlagNoSequenceUpdate(1)->save()->setFlagNoSequenceUpdate(0);
     }
     return true;
 }
コード例 #16
0
 /**
  * Creates subscription at paypal
  * @param AW_Sarp_Model_Subscription $Subscription
  * @return
  */
 public function createSubscription(AW_Sarp_Model_Subscription $Subscription, $Order, $Quote)
 {
     Mage::getModel('sarp/protxDirect')->setSubscriptionId($Subscription->getId())->setVendorTxCode(self::$VendorTxCode)->setVpsTxId(self::$VPSTxID)->setTxAuthNo(self::$TxAuthNo)->setSecurityKey(self::$SecurityKey)->save();
     return $this;
 }
コード例 #17
0
 /**
  * Returns how much occurences will be generated by authorize.net
  * @param AW_Sarp_Model_Subscription $Subscription
  * @return
  */
 protected function _getTotalOccurrences(AW_Sarp_Model_Subscription $Subscription)
 {
     if ($Subscription->isInfinite()) {
         return 9999;
     } else {
         // Calculate how much subscription events are generated
         return Mage::getModel('sarp/sequence')->getCollection()->addSubscriptionFilter($Subscription)->count();
     }
 }
コード例 #18
0
ファイル: Direct.php プロジェクト: xiaoguizhidao/mydigibits
 /**
  * Returns how much occurences will be generated by paypal
  * @param AW_Sarp_Model_Subscription $Subscription
  * @return int
  */
 protected function _getTotalBillingCycles(AW_Sarp_Model_Subscription $Subscription)
 {
     if ($Subscription->isInfinite()) {
         return 0;
     } else {
         // Calculate how much subscription events are generated
         return parent::_getTotalBillingCycles($Subscription);
     }
 }
コード例 #19
0
ファイル: Alert.php プロジェクト: xiaoguizhidao/mydigibits
 /**
  * Returns recipient name
  * @return string
  */
 public function getRecipientName(AW_Sarp_Model_Subscription $Subscription)
 {
     if ($this->getRecipient() == self::RECIPIENT_CUSTOMER) {
         return $Subscription->getCustomer()->getName();
     } else {
         return Mage::getStoreConfig('trans_email/ident_' . $this->getRecipient() . '/name');
     }
     return $this;
 }