PayPal\Formatter\FormatterFactory::factory PHP Method

factory() public static method

public static factory ( $bindingType )
    public static function factory($bindingType)
    {
        switch ($bindingType) {
            case 'NV':
                return new PPNVPFormatter();
                break;
            case 'SOAP':
                return new PPSOAPFormatter();
                break;
            default:
                throw new \InvalidArgumentException("Invalid value for bindingType. You passed {$bindingType}");
        }
    }

Usage Example

Example #1
0
 public function makeRequest($apiMethod, $params, $apiUsername = null)
 {
     $this->apiMethod = $apiMethod;
     if (is_string($apiUsername) || is_null($apiUsername)) {
         // $apiUsername is optional, if null the default account in config file is taken
         $credMgr = PPCredentialManager::getInstance($this->config);
         $apiCredential = clone $credMgr->getCredentialObject($apiUsername);
     } else {
         $apiCredential = $apiUsername;
         //TODO: Aargh
     }
     if (isset($this->config['accessToken']) && isset($this->config['tokenSecret'])) {
         $apiCredential->setThirdPartyAuthorization(new PPTokenAuthorization($this->config['accessToken'], $this->config['tokenSecret']));
     }
     $request = new PPRequest($params, $this->serviceBinding);
     $request->setCredential($apiCredential);
     $httpConfig = new PPHttpConfig(null, PPHttpConfig::HTTP_POST);
     $this->runHandlers($httpConfig, $request);
     $formatter = FormatterFactory::factory($this->serviceBinding);
     $payload = $formatter->toString($request);
     $connection = PPConnectionManager::getInstance()->getConnection($httpConfig, $this->config);
     $this->logger->info("Request: {$payload}");
     $response = $connection->execute($payload);
     $this->logger->info("Response: {$response}");
     return array('request' => $payload, 'response' => $response);
 }
All Usage Examples Of PayPal\Formatter\FormatterFactory::factory
FormatterFactory