/**
  * Validates a IPN message
  * 
  * @return boolean
  */
 public function validate()
 {
     if (isset($this->isIpnVerified)) {
         return $this->isIpnVerified;
     } else {
         $request = self::IPN_CMD;
         if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() == 1) {
             $get_magic_quotes_exists = true;
         } else {
             $get_magic_quotes_exists = false;
         }
         foreach ($this->ipnData as $key => $value) {
             if ($get_magic_quotes_exists) {
                 $value = urlencode(stripslashes($value));
             } else {
                 $value = urlencode($value);
             }
             $request .= "&{$key}={$value}";
         }
         $httpConfig = new PPHttpConfig(PPConfigManager::getInstance()->get('service.EndPoint.IPN'));
         $httpConfig->addCurlOption(CURLOPT_FORBID_REUSE, 1);
         $httpConfig->addCurlOption(CURLOPT_HTTPHEADER, array('Connection: Close'));
         $connection = PPConnectionManager::getInstance()->getConnection($httpConfig);
         $response = $connection->execute($request);
         if ($response == 'VERIFIED') {
             $this->isIpnVerified = true;
             return true;
         }
         $this->isIpnVerified = false;
         return false;
         // value is 'INVALID'
     }
 }
Esempio n. 2
0
 /**
  *
  * @param string $path
  * @param string $data
  * @param PayPal/Rest/ApiContext $apiContext
  * @param array $headers
  */
 public function execute($path, $method, $data = '', $apiContext, $headers = array())
 {
     $configMgr = \PPConfigManager::getInstance();
     $credential = $apiContext->getCredential();
     if ($credential == NULL) {
         // Try picking credentials from the config file
         $credMgr = \PPCredentialManager::getInstance();
         $credValues = $credMgr->getCredentialObject();
         if (!is_array($credValues)) {
             throw new \PPMissingCredentialException("Empty or invalid credentials passed");
         }
         $credential = new OAuthTokenCredential($credValues['clientId'], $credValues['clientSecret']);
     }
     if ($credential == NULL || !$credential instanceof OAuthTokenCredential) {
         throw new \PPInvalidCredentialException("Invalid credentials passed");
     }
     $resourceUrl = rtrim(trim($configMgr->get('service.EndPoint')), '/') . $path;
     $config = new \PPHttpConfig($resourceUrl, $method);
     $headers += array('Content-Type' => 'application/json', 'User-Agent' => UserAgent::getValue());
     if (!is_null($credential) && $credential instanceof OAuthTokenCredential) {
         $headers['Authorization'] = "Bearer " . $credential->getAccessToken();
     }
     if ($method == 'POST' || $method == 'PUT') {
         $headers['PayPal-Request-Id'] = $apiContext->getRequestId();
     }
     $config->setHeaders($headers);
     $connection = new \PPHttpConnection($config);
     $response = $connection->execute($data);
     $this->logger->fine($response);
     return $response;
 }
Esempio n. 3
0
 /**
  * @param array $handlers array of handlers
  * @param string $path   Resource path relative to base service endpoint
  * @param string $method HTTP method - one of GET, POST, PUT, DELETE, PATCH etc
  * @param string $data   Request payload
  * @param array $headers HTTP headers
  */
 public function execute($handlers, $path, $method, $data = '', $headers = array())
 {
     $config = $this->apiContext->getConfig();
     $httpConfig = new PPHttpConfig(null, $method);
     $httpConfig->setHeaders($headers + array('Content-Type' => 'application/json'));
     foreach ($handlers as $handler) {
         $handler->handle($httpConfig, $data, array('path' => $path, 'apiContext' => $this->apiContext));
     }
     $connection = new PPHttpConnection($httpConfig, $config);
     $response = $connection->execute($data);
     $this->logger->fine($response);
     return $response;
 }
Esempio n. 4
0
 /**
  * Execute an api call
  *
  * @param string $apiMethod	Name of the API operation (such as 'Pay')
  * @param PPRequest $params Request object
  * @return array containing request and response
  */
 public function makeRequest($apiMethod, $request)
 {
     $this->apiMethod = $apiMethod;
     $httpConfig = new PPHttpConfig(null, PPHttpConfig::HTTP_POST);
     if ($this->apiContext->getHttpHeaders() != null) {
         $httpConfig->setHeaders($this->apiContext->getHttpHeaders());
     }
     $this->runHandlers($httpConfig, $request);
     // Serialize request object to a string according to the binding configuration
     $formatter = FormatterFactory::factory($this->serviceBinding);
     $payload = $formatter->toString($request);
     // Execute HTTP call
     $connection = PPConnectionManager::getInstance()->getConnection($httpConfig, $this->apiContext->getConfig());
     $this->logger->info("Request: {$payload}");
     $response = $connection->execute($payload);
     $this->logger->info("Response: {$response}");
     return array('request' => $payload, 'response' => $response);
 }
 /**
  * Execute an api call
  *
  * @param string $apiMethod	Name of the API operation (such as 'Pay')
  * @param PPRequest $params Request object
  * @return array containing request and response
  */
 public function makeRequest($apiMethod, $request)
 {
     $this->apiMethod = $apiMethod;
     $httpConfig = new PPHttpConfig(null, PPHttpConfig::HTTP_POST);
     if ($this->apiContext->getHttpHeaders() != null) {
         $httpConfig->setHeaders($this->apiContext->getHttpHeaders());
     }
     $this->runHandlers($httpConfig, $request);
     // Serialize request object to a string according to the binding configuration
     $formatter = FormatterFactory::factory($this->serviceBinding);
     $payload = $formatter->toString($request);
     //var_dump("<pre>", $payload); die();
     //requestEnvelope.errorLanguage=en_US&actionType=PAY&cancelUrl=http%3A%2F%2Fcusa-local%2Fsignup&currencyCode=USD&receiverList.receiver.amount=240&receiverList.receiver.email=JulianIWetmore%40armyspy.com&returnUrl=http%3A%2F%2Fcusa-local%2Fsignup-paypal-success%2F%3Fpay_chk%3D1799557580%26
     // Execute HTTP call
     $connection = PPConnectionManager::getInstance()->getConnection($httpConfig, $this->apiContext->getConfig());
     $this->logger->info("Request: {$payload}");
     $response = $connection->execute($payload);
     $this->logger->info("Response: {$response}");
     return array('request' => $payload, 'response' => $response);
 }
 /**
  * @test
  */
 public function testProxyOpts()
 {
     $proxy = 'http://*****:*****@hostname:8081';
     $o = new PPHttpConfig();
     $o->setHttpProxy($proxy);
     $curlOpts = $o->getCurlOptions();
     $this->assertEquals('hostname:8081', $curlOpts[CURLOPT_PROXY]);
     $this->assertEquals('me:secret', $curlOpts[CURLOPT_PROXYUSERPWD]);
     $this->setExpectedException('PPConfigurationException');
     $o->setHttpProxy('invalid string');
 }