public function getBankAccountForDebitor($debitor, $paymentMethod = null) { if (!$debitor instanceof Billing_Model_Debitor) { $debitor = $this->get($debitor); } $bankAccount = Billing_Api_BankAccount::createEmpty(); $contact = $debitor->getForeignRecord('contact_id', Addressbook_Controller_Contact::getInstance()); $memberships = Membership_Controller_SoMember::getInstance()->getByContactId($contact->getId()); foreach ($memberships as $membership) { $bankAccount = Billing_Api_BankAccount::getFromSoMember($membership); // if($bankAccount->isValidForPaymentMethod($paymentMethod)){ if ($bankAccount->isValid()) { break; } } //if(!$bankAccount->isValidForPaymentMethod($paymentMethod)){ if (!$bankAccount->isValid()) { try { $fundMaster = Donator_Controller_FundMaster::getInstance()->getByContactId($contact->getId()); $bankAccount = Billing_Api_BankAccount::getFromFundMaster($fundMaster); } catch (Exception $e) { } } if (!$bankAccount->isValid()) { $bankAccount = Billing_Api_BankAccount::getFromContact($contact); } //if(!$bankAccount->isValidForPaymentMethod($paymentMethod)){ /*if(!$bankAccount->isValid()){ throw new Billing_Exception_BankAccountInvalidForPaymentMethod('No valid bankaccount for debitor '.$debitor->getId(). ' and payment method '.$paymentMethod. ' log: '.$log); }*/ return $bankAccount; }