Esempio n. 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
 }
Esempio n. 2
0
 public function setValue($value)
 {
     if (is_string($value)) {
         $value = Am_Controller::decodeJson($value);
     }
     $this->value = (array) $value;
     foreach ($this->value as &$row) {
         if (empty($row['id'])) {
             continue;
         }
         if (isset($row['config']) && is_string($row['config'])) {
             parse_str($row['config'], $c);
             if (get_magic_quotes_gpc()) {
                 $c = Am_Request::ss($c);
             }
             // remove quotes
             $row['config'] = $c;
         }
         if ($brick = $this->getBrick($row['class'], $row['id'])) {
             $brick->setFromRecord($row);
         }
     }
     // handle special case - where there is a "multiple" brick and that is enabled
     // we have to insert additional brick to "disabled", so new bricks of same
     // type can be added in editor
     $disabled = $this->getBricks(self::DISABLED);
     foreach ($this->getBricks(self::ENABLED) as $brick) {
         if (!$brick->isMultiple()) {
             continue;
         }
         $found = false;
         foreach ($disabled as $dBrick) {
             if ($dBrick->getClass() == $brick->getClass()) {
                 $found = true;
                 break;
             }
         }
         // create new disabled brick of same class
         if (!$found) {
             $this->getBrick($brick->getClass(), null);
         }
     }
 }
Esempio n. 3
0
 /**
  * Retrieves an access token for the given authorization code
  * (previously generated from www.facebook.com on behalf of
  * a specific user).  The authorization code is sent to graph.facebook.com
  * and a legitimate access token is generated provided the access token
  * and the user for which it was generated all match, and the user is
  * either logged in to Facebook or has granted an offline access permission.
  *
  * @param string $code An authorization code.
  * @return mixed An access token exchanged for the authorization code, or
  *               false if an access token could not be generated.
  */
 protected function getAccessTokenFromCode($code, $redirect_uri = null)
 {
     if (empty($code)) {
         return false;
     }
     if ($redirect_uri === null) {
         $redirect_uri = $this->getCurrentUrl();
     }
     try {
         // need to circumvent json_decode by calling _oauthRequest
         // directly, since response isn't JSON format.
         $access_token_response = $this->_oauthRequest($this->getUrl('graph', '/oauth/access_token'), $params = array('client_id' => $this->getAppId(), 'client_secret' => $this->getApiSecret(), 'redirect_uri' => $redirect_uri, 'code' => $code));
     } catch (FacebookApiException $e) {
         // most likely that user very recently revoked authorization.
         // In any event, we don't have an access token, so say so.
         return false;
     }
     if (empty($access_token_response)) {
         return false;
     }
     $response_params = array();
     parse_str($access_token_response, $response_params);
     if (get_magic_quotes_gpc()) {
         $response_params = Am_Request::ss($response_params);
     }
     if (!isset($response_params['access_token'])) {
         return false;
     }
     return $response_params['access_token'];
 }
Esempio n. 4
0
 public function parseResponse()
 {
     parse_str($this->response->getBody(), $this->vars);
     if (get_magic_quotes_gpc()) {
         $this->vars = Am_Request::ss($this->vars);
     }
 }
Esempio n. 5
0
 function renderVars($body)
 {
     $str = urldecode($body);
     parse_str($str, $arr);
     if (get_magic_quotes_gpc()) {
         $arr = Am_Request::ss($arr);
     }
     if (!count($arr)) {
         return "";
     }
     return print_r($arr, true);
 }