Example #1
0
 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
 }