Пример #1
0
 /**
  * Automatic Payout for Affiliate (using API)
  * 
  * @param Magestore_Affiliateplus_Model_Account $account
  * @param float $amount
  * @param Mage_Core_Model_Store $store
  * @return array (account, payment) | false
  */
 public function automaticPayout($account, $amount, $store)
 {
     //Changed By Adam 28/07/2014
     if (!Mage::helper('affiliateplus')->isAffiliateModuleEnabled()) {
         return;
     }
     if (!Mage::getStoreConfig('affiliateplus_payment/recurring/auto_complete', $store)) {
         $payment = Mage::getModel('affiliateplus/payment')->setPaymentMethod($account->getData('recurring_method'))->setAmount($amount)->setAccountId($account->getId())->setAccountName($account->getName())->setAccountEmail($account->getEmail())->setStoreIds($store->getId())->setIsPayerFee(0)->setRequestTime(now())->setStatus(1)->setData('is_created_by_recurring', 1)->setData('is_recurring', 1)->setIsRequest(0);
         if (Mage::getStoreConfig('affiliateplus/payment/who_pay_fees', $store) == 'payer') {
             $payment->setIsPayerFee(1);
         }
         $payment->setData('affiliateplus_account', $account);
         try {
             $payment->save();
             $payment->getPayment()->setEmail($account->getData($account->getData('recurring_method') . '_email'))->savePaymentMethodInfo();
             self::sendEmailToAccount($payment, $account, $store);
         } catch (Exception $e) {
             return false;
         }
         return array('account' => $account, 'payment' => $payment);
     }
     if ($account->getData('recurring_method') == 'paypal') {
         // Paypal Recurring Payment
         $payment = Mage::helper('affiliatepluspayment/paypal')->payoutByApi($account, $amount, $store->getId());
         if ($payment && $payment->getId()) {
             self::sendEmailToAccount($payment, $account, $store);
             return array('account' => $account, 'payment' => $payment);
         }
     } elseif ($account->getData('recurring_method') == 'moneybooker') {
         // Moneybooker Recurring Payment
         $payment = Mage::helper('affiliatepluspayment/moneybooker')->payoutByApi($account, $amount, $store->getId());
         if ($payment && $payment->getId()) {
             self::sendEmailToAccount($payment, $account, $store);
             return array('account' => $account, 'payment' => $payment);
         }
     }
     return false;
 }