Esempio n. 1
0
 public function render()
 {
     // TODO there used to be a caching mechanism here
     // @see Cacher::useCache, Cacher::writeCache
     if (!$this->perform($this->action, $this->stage) && ($this->stage == Stage::PERFORM || $this->stage == Stage::VALIDATE)) {
         $this->perform($this->action, Stage::VIEW);
     }
     $page = Site::getPage();
     $page->addToBuffer('content', $this);
 }
Esempio n. 2
0
 public function purchase()
 {
     if ($this->live) {
         $auth_net_url = "https://secure.authorize.net/gateway/transact.dll";
     } else {
         $auth_net_url = "https://test.authorize.net/gateway/transact.dll";
     }
     $authnet_values = array("x_login" => $this->apiUsername, "x_version" => "3.1", "x_delim_char" => "|", "x_delim_data" => "TRUE", "x_url" => "FALSE", "x_type" => "AUTH_CAPTURE", "x_method" => "CC", "x_tran_key" => $this->apiPassword, "x_relay_response" => "FALSE", "x_card_num" => $this->creditCardNumber, "x_exp_date" => $this->expirationMonth . $this->expirationYear, "x_description" => "LMS Services", "x_amount" => $this->amount, "x_first_name" => $this->firstName, "x_last_name" => $this->lastName, "x_address" => $this->address1, "x_city" => $this->city, "x_state" => $this->state, "x_zip" => $this->zip, "CustomerBirthMonth" => "Customer Birth Month: " . $this->customerBirthMonth, "CustomerBirthDay" => "Customer Birth Day: " . $this->customerBirthDay, "CustomerBirthYear" => "Customer Birth Year: " . $this->customerBirthYear, "SpecialCode" => "None");
     $fields = "";
     foreach ($authnet_values as $key => $value) {
         $fields .= "{$key}=" . urlencode($value) . "&";
     }
     if ($this->live) {
         $ch = curl_init("https://secure.authorize.net/gateway/transact.dll");
     } else {
         $ch = curl_init("https://test.authorize.net/gateway/transact.dll");
     }
     curl_setopt($ch, CURLOPT_HEADER, 0);
     // set to 0 to eliminate header info from response
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     // Returns response data instead of TRUE(1)
     curl_setopt($ch, CURLOPT_POSTFIELDS, rtrim($fields, "& "));
     // use HTTP POST to send form data
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
     // uncomment this line if you get no gateway response. ###
     $resptext = curl_exec($ch);
     //execute post and get results
     curl_close($ch);
     $resp = array();
     $text = $resptext;
     $tok = strtok($text, "|");
     while (!($tok === false)) {
         array_push($resp, $tok);
         $tok = strtok("|");
     }
     $resp;
     if ($resp[0] == 1) {
         return true;
     }
     Site::getPage()->addWarning($resp[3]);
     return false;
 }
Esempio n. 3
0
 /**
  * Process current request
  * @return boolean TRUE if routing has succeeded, FALSE otherwise
  */
 function routeRequest()
 {
     # Routing stuff, first get the site url
     $site_url = trim($this->base_url, '/');
     # Remove the protocol from it
     $domain = preg_replace('/^(http|https):\\/\\//', '', $site_url);
     # Now remove the path
     $segments = explode('/', $domain, 2);
     if (count($segments) > 1) {
         $domain = array_pop($segments);
     }
     # Get the request and remove the domain
     $request = trim($_SERVER['REQUEST_URI'], '/');
     $request = preg_replace("/" . str_replace('/', '\\/', $domain) . "/", '', $request, 1);
     $request = ltrim($request, '/');
     # Get the parameters
     $segments = explode('?', $request);
     if (count($segments) > 1) {
         $params_str = array_pop($segments);
         parse_str($params_str, $this->params);
     }
     # And the segments
     $cur_route = array_shift($segments);
     $segments = explode('/', $cur_route);
     # Now make sure the current route begins with '/' and doesn't end with '/'
     $cur_route = '/' . $cur_route;
     $cur_route = rtrim($cur_route, '/');
     # Make sure we have a valid route
     if (empty($cur_route)) {
         $cur_route = $this->default_route;
     }
     if (!$this->matchRoute($cur_route)) {
         # Nothing was found, show a 404 page
         Site::getPage('404');
         return false;
     } else {
         return true;
     }
 }
Esempio n. 4
0
 /**
  * Validates the given keys. The keys used may be in dotted (or colon)
  * format, indicating an object property on the given object.
  *
  * @param mixed $mixed an object or associtive array on which to validate
  * @param array $validation an associtive array of key/warning pairs.
  * The warning may be an array which holds other arrays
  * where the first element specifies how to
  * validate the key, and the second element is the warning.
  * which parameters were invalid.
  * @return boolean true if we passed validation, false otherwise
  */
 public static function validate(&$mixed, $validation)
 {
     $passed = true;
     $array = is_object($mixed) ? get_object_vars($mixed) : $mixed;
     foreach ($validation as $key => $deep) {
         $deep = is_array($deep) ? $deep : array(array(Params::VALIDATE_EMPTY, $deep));
         foreach ($deep as $specification) {
             list($type, $message) = $specification;
             $value = null;
             $m = array();
             if (preg_match('/^(\\w+)[:.](\\w+)/', $key, $m)) {
                 $o = $m[1];
                 $p = $m[2];
                 if (!is_object($array[$o]) || !property_exists($array[$o], $p)) {
                     throw new InvalidArgumentException("bad param for key {$key}");
                 }
                 $value = $array[$o]->{$p};
             } else {
                 $value = $array[$key];
             }
             switch ($type) {
                 case Params::VALIDATE_EMPTY:
                     if (!trim($value)) {
                         Site::getPage()->addWarning($message, $key);
                         $passed = false;
                         continue;
                     }
                     break;
                 case Params::VALIDATE_EMPTY_STRICT:
                     if (null === $value) {
                         Site::getPage()->addWarning($message, $key);
                         $passed = false;
                         continue;
                     }
                     break;
                 case Params::VALIDATE_NUMERIC:
                     if ($value && !is_numeric($value)) {
                         Site::getPage()->addWarning($message, $key);
                         $passed = false;
                         continue;
                     }
                     break;
                 case Params::VALIDATE_EMAIL:
                     if ($value && !Email::IsValid($value)) {
                         Site::getPage()->addWarning($message, $key);
                         $passed = false;
                         continue;
                     }
                     break;
                 case Params::VALIDATE_EMAIL_BLACKLIST:
                     if ($value && Email::IsValid($value) && Email::IsBlackListed($value)) {
                         Site::getPage()->addWarning($message, $key);
                         $passed = false;
                         continue;
                     }
                     break;
             }
         }
     }
     return $passed;
 }
Esempio n. 5
0
 public function purchase()
 {
     // Note, we used to add extensions/ to include_path here, that should either
     // be standardized in Loader or we need to load more files here to make
     // up for whatever the PayPal code would otherwise try to load
     require_once 'extensions/PayPal.php';
     require_once 'extensions/PayPal/Profile/Handler/Array.php';
     require_once 'extensions/PayPal/Profile/API.php';
     require_once 'extensions/PayPal/Type/DoDirectPaymentRequestType.php';
     require_once 'extensions/PayPal/Type/DoDirectPaymentRequestDetailsType.php';
     require_once 'extensions/PayPal/Type/DoDirectPaymentResponseType.php';
     //  Add all of the types
     require_once 'extensions/PayPal/Type/BasicAmountType.php';
     require_once 'extensions/PayPal/Type/PaymentDetailsType.php';
     require_once 'extensions/PayPal/Type/AddressType.php';
     require_once 'extensions/PayPal/Type/CreditCardDetailsType.php';
     require_once 'extensions/PayPal/Type/PayerInfoType.php';
     require_once 'extensions/PayPal/Type/PersonNameType.php';
     require_once 'extensions/PayPal/CallerServices.php';
     $environment = $this->live ? 'live' : 'sandbox';
     $dp_request = new DoDirectPaymentRequestType();
     $OrderTotal = new BasicAmountType();
     $OrderTotal->setattr('currencyID', 'USD');
     $OrderTotal->setval($this->amount, 'iso-8859-1');
     $PaymentDetails = new PaymentDetailsType();
     $PaymentDetails->setOrderTotal($OrderTotal);
     $shipTo = new AddressType();
     $shipTo->setName($this->firstName . ' ' . $this->lastName);
     $shipTo->setStreet1($this->address1);
     $shipTo->setStreet2($this->address2);
     $shipTo->setCityName($this->city);
     $shipTo->setStateOrProvince($this->state);
     $shipTo->setCountry('US');
     $shipTo->setPostalCode($this->zip);
     $PaymentDetails->setShipToAddress($shipTo);
     $dp_details = new DoDirectPaymentRequestDetailsType();
     $dp_details->setPaymentDetails($PaymentDetails);
     // Credit Card info
     $card_details = new CreditCardDetailsType();
     $card_details->setCreditCardType($this->creditCardType);
     $card_details->setCreditCardNumber($this->creditCardNumber);
     $card_details->setExpMonth($this->expirationMonth);
     $card_details->setExpYear($this->expirationYear);
     $card_details->setCVV2($this->cvv2Number);
     $payer = new PayerInfoType();
     $person_name = new PersonNameType();
     $person_name->setFirstName($this->firstName);
     $person_name->setLastName($this->lastName);
     $payer->setPayerName($person_name);
     $payer->setPayerCountry('US');
     $payer->setAddress($shipTo);
     $card_details->setCardOwner($payer);
     $dp_details->setCreditCard($card_details);
     $dp_details->setIPAddress($_SERVER['SERVER_ADDR']);
     $dp_details->setPaymentAction('Sale');
     $dp_request->setDoDirectPaymentRequestDetails($dp_details);
     $handler = ProfileHandler_Array::getInstance(array('username' => $this->apiUsername, 'certificateFile' => null, 'subject' => null, 'environment' => $environment));
     $pid = ProfileHandler::generateID();
     $profile = new APIProfile($pid, $handler);
     $profile->setAPIUsername($this->apiUsername);
     $profile->setAPIPassword($this->apiPassword);
     $profile->setSignature($this->apiSignature);
     $profile->setEnvironment($environment);
     $caller = new CallerServices($profile);
     $response = $caller->DoDirectPayment($dp_request);
     if (PayPal::isError($response)) {
         Site::getPage()->addWarning($response->message);
         return false;
     }
     if ($response->Ack == 'Success') {
         return true;
     }
     if (is_array($response->Errors)) {
         foreach ($response->Errors as $error) {
             Site::getPage()->addWarning($error->LongMessage);
         }
     } else {
         Site::getPage()->addWarning($response->Errors->LongMessage);
     }
     return false;
 }