/**
  * 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));
 }
Beispiel #2
0
 /**
  * This function is run when subscription is created and new order creates
  * @todo Add check for length of subscription period. If it is longer than 12 month, we have to fail subscription due to PayFlow reference transactions limitation
  * @param AW_Sarp_Model_Subscription $Subscription
  * @param Mage_Sales_Model_Order     $Order
  * @param Mage_Sales_Model_Quote     $Quote
  * @return AW_Sarp_Model_Payment_Method_PaypalUk_Direct
  */
 public function onSubscriptionCreate(AW_Sarp_Model_Subscription $Subscription, Mage_Sales_Model_Order $Order, Mage_Sales_Model_Quote $Quote)
 {
     // Get pnref and authcode and save that to payment
     if (!self::$_pnref) {
         throw new AW_Sarp_Exception("No PNRef set for subscription#%s", $Subscription->getId());
     }
     $Subscription->setRealId(self::$_pnref)->setRealPaymentId(self::$_authcode)->save();
     return $this;
 }