public function storeCreditCard(CcRecord $cc, Am_Paysystem_Result $result) { $profiles = array(); //Find all profiles which should be updated. foreach ($this->getDi()->db->selectPage($total, "\n SELECT d.value, i.invoice_id \n FROM ?_data d LEFT JOIN ?_invoice i \n ON d.`table` = 'invoice' AND d.`key` = ? AND d.id = i.invoice_id \n WHERE i.user_id = ? AND i.status = ?", self::PAYPAL_PROFILE_ID, $cc->user_id, Invoice::RECURRING_ACTIVE) as $profile) { $profiles[$profile['value']] = $profile['invoice_id']; } $failures = array(); foreach ($profiles as $profile_id => $invoice_id) { $request = new Am_Paysystem_PaypalApiRequest($this); $request->setCc($invoice = $this->getDi()->invoiceTable->load($invoice_id), $cc); $request->addPostParameter('METHOD', 'UpdateRecurringPaymentsProfile'); $request->addPostParameter('PROFILEID', $profile_id); $request->addPostParameter('NOTE', 'Update CC info, customer IP: ' . Zend_Controller_Front::getInstance()->getRequest()->getHttpHost()); $log = Am_Di::getInstance()->invoiceLogRecord; $log->title = "updateRecurringPaymentsProfile"; $log->paysys_id = $this->getId(); $res = $request->sendRequest($log); $log->setInvoice($invoice); $log->update(); if ($res['ACK'] != 'Success') { $failures[] = sprintf('CC info was not updated for profile: %s. Got error from paypal: %s', $profile_id, $res['L_SHORTMESSAGE0']); } } if (count($failures)) { $result->setFailed($failures); } else { $result->setSuccess(); } }