public function _process(Invoice $invoice, Am_Request $request, Am_Paysystem_Result $result) { $log = $this->getDi()->invoiceLogRecord; $log->title = "SetExpressCheckout"; $log->paysys_id = $this->getId(); $log->setInvoice($invoice); $apireq = new Am_Paysystem_PaypalApiRequest($this); $apireq->setExpressCheckout($invoice); $apireq->addPostParameter('LOCALECODE', $this->getConfig('localecode', 'US')); if ($this->getConfig('brandname')) { $apireq->addPostParameter('BRANDNAME', $this->getConfig('brandname')); } if ($this->getConfig('landingpage_login')) { $apireq->addPostParameter('LANDINGPAGE', 'Login'); } $log->add($apireq); $response = $apireq->send(); $log->add($response); if ($response->getStatus() != 200) { throw new Am_Exception_Paysystem("Error while communicating to PayPal server, please try another payment processor"); } parse_str($response->getBody(), $vars); if (get_magic_quotes_gpc()) { $vars = Am_Request::ss($vars); } if (empty($vars['TOKEN'])) { throw new Am_Exception_Paysystem("Error while communicating to PayPal server, no token received, please try another payment processor"); } $invoice->data()->set(self::PAYPAL_EXPRESS_TOKEN, $vars['TOKEN']); $action = new Am_Paysystem_Action_Redirect($this->getConfig('testing') ? self::SANDBOX_URL : self::LIVE_URL); $action->cmd = '_express-checkout'; $action->token = $vars['TOKEN']; $log->add($action); $result->setAction($action); $this->getDi()->session->paypal_invoice_id = $invoice->getSecureId('paypal'); // if express-checkout chosen, hide and don't require // fields for login, password, email, name and address // if that is new user, // save user info and invoice into temporary storage not to user table // call setExpressCheckout // redirect to paypal // then get back from paypal to am/payment/paypal-express/review // on confirm key pressed, make payment, finish checkout, fill-in fields }
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(); } }