/**
  * @test
  */
 public function testGetIniPrefix()
 {
     $ret = $this->object->getIniPrefix();
     $this->assertContains('acct1', $ret);
     $this->assertEquals(sizeof($ret), 2);
     $ret = $this->object->getIniPrefix('jb-us-seller_api1.paypal.com');
     $this->assertEquals('acct1', $ret);
 }
Exemplo n.º 2
0
 /**
  * @test
  */
 public function testGetIniPrefix()
 {
     $ret = $this->object->getIniPrefix();
     $this->assertContains('acct1', $ret);
     $this->assertEquals(sizeof($ret), 2);
     $ret = $this->object->getIniPrefix('platfo_1255077030_biz_api1.gmail.com');
     $this->assertEquals('acct1', $ret);
 }
Exemplo n.º 3
0
 public function getConfig()
 {
     if (!isset($this->config)) {
         $this->config = \PPConfigManager::getInstance()->getConfigHashmap();
     }
     return $this->config;
 }
Exemplo n.º 4
0
 public static function getInstance()
 {
     if (!isset(self::$instance)) {
         self::$instance = new PPConfigManager();
     }
     return self::$instance;
 }
 public function getPayPalHeaders($apiCred, $connection, $accessToken = null, $tokenSecret = null, $url = null)
 {
     $config = PPConfigManager::getInstance();
     if (isset($accessToken) && isset($tokenSecret)) {
         $headers_arr[] = "X-PAYPAL-AUTHORIZATION:  " . $this->generateAuthString($apiCred, $accessToken, $tokenSecret, $url);
         //$headers_arr[] = "CLIENT-AUTH: No cert";
     } else {
         if ($apiCred instanceof PPSignatureCredential) {
             $headers_arr[] = "X-PAYPAL-SECURITY-USERID:  " . $apiCred->getUserName();
             $headers_arr[] = "X-PAYPAL-SECURITY-PASSWORD: "******"X-PAYPAL-SECURITY-SIGNATURE: " . $apiCred->getSignature();
         } else {
             if ($apiCred instanceof PPCertificateCredential) {
                 $headers_arr[] = "X-PAYPAL-SECURITY-USERID:  " . $apiCred->getUserName();
                 $headers_arr[] = "X-PAYPAL-SECURITY-PASSWORD: "******"X-PAYPAL-APPLICATION-ID: " . $apiCred->getApplicationId();
     $headers_arr[] = "X-PAYPAL-REQUEST-DATA-FORMAT: " . $config->get('service.Binding');
     $headers_arr[] = "X-PAYPAL-RESPONSE-DATA-FORMAT: " . $config->get('service.Binding');
     $headers_arr[] = "X-PAYPAL-DEVICE-IPADDRESS: " . PPUtils::getLocalIPAddress();
     $headers_arr[] = "X-PAYPAL-REQUEST-SOURCE: " . PPUtils::getRequestSource();
     return $headers_arr;
 }
Exemplo n.º 6
0
 /**
  * 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'
     }
 }
Exemplo n.º 7
0
 public function makeRequest($apiMethod, $params, $apiUsername = null, $accessToken = null, $tokenSecret = null)
 {
     $authentication = new PPAuthenticationManager();
     $connectionMgr = PPConnectionManager::getInstance();
     $connection = $connectionMgr->getConnection();
     $credMgr = PPCredentialManager::getInstance();
     // $apiUsernam is optional, if null the default account in congif file is taken
     $apIPPCredential = $credMgr->getCredentialObject($apiUsername);
     $config = PPConfigManager::getInstance();
     if ($config->get('service.Binding') == 'SOAP') {
         $url = $this->endpoint;
         if (isset($accessToken) && isset($tokenSecret)) {
             $headers = $authentication->getPayPalHeaders($apIPPCredential, $connection, $accessToken, $tokenSecret, $url);
         } else {
             $headers = null;
         }
         $params = $authentication->appendSoapHeader($params, $apIPPCredential, $connection, $accessToken, $tokenSecret, $url);
     } else {
         $url = $this->endpoint . $this->serviceName . '/' . $apiMethod;
         $headers = $authentication->getPayPalHeaders($apIPPCredential, $connection, $accessToken, $tokenSecret, $url);
     }
     $this->logger->info("Request: {$params}");
     $response = $connection->execute($url, $params, $headers);
     $this->logger->info("Response: {$response}");
     return $response;
 }
Exemplo n.º 8
0
 public function makeRequest($apiMethod, $params, $apiUsername = null, $accessToken = null, $tokenSecret = null)
 {
     $config = PPConfigManager::getInstance();
     if (is_string($apiUsername) || is_null($apiUsername)) {
         // $apiUsername is optional, if null the default account in config file is taken
         $credMgr = PPCredentialManager::getInstance();
         $apiCredential = clone $credMgr->getCredentialObject($apiUsername);
     } else {
         $apiCredential = $apiUsername;
         //TODO: Aargh
     }
     if (isset($accessToken) && isset($tokenSecret)) {
         $apiCredential->setThirdPartyAuthorization(new PPTokenAuthorization($accessToken, $tokenSecret));
     }
     if ($this->serviceBinding == 'SOAP') {
         $url = $this->endpoint;
     } else {
         $url = $this->endpoint . $this->serviceName . '/' . $apiMethod;
     }
     $request = new PPRequest($params, $this->serviceBinding);
     $request->setCredential($apiCredential);
     $httpConfig = new PPHttpConfig($url, PPHttpConfig::HTTP_POST);
     $this->runHandlers($httpConfig, $request);
     $formatter = FormatterFactory::factory($this->serviceBinding);
     $payload = $formatter->toString($request);
     $connection = PPConnectionManager::getInstance()->getConnection($httpConfig);
     $this->logger->info("Request: {$payload}");
     $response = $connection->execute($payload);
     $this->logger->info("Response: {$response}");
     return array('request' => $payload, 'response' => $response);
 }
Exemplo n.º 9
0
 private function initCredential()
 {
     $configMgr = PPConfigManager::getInstance();
     $suffix = 1;
     $prefix = "acct";
     $credArr = $configMgr->get($prefix);
     $arrayPartKeys = $configMgr->getIniPrefix();
     if (count($arrayPartKeys) == 0) {
         throw new MissingCredentialException("No valid API accounts have been configured");
     }
     while (in_array($prefix . $suffix, $arrayPartKeys)) {
         if (isset($credArr[$prefix . $suffix . ".Signature"]) && $credArr[$prefix . $suffix . ".Signature"] != null && $credArr[$prefix . $suffix . ".Signature"] != "") {
             $userName = isset($credArr[$prefix . $suffix . '.UserName']) ? $credArr[$prefix . $suffix . '.UserName'] : "";
             $password = isset($credArr[$prefix . $suffix . '.Password']) ? $credArr[$prefix . $suffix . '.Password'] : "";
             $signature = isset($credArr[$prefix . $suffix . '.Signature']) ? $credArr[$prefix . $suffix . '.Signature'] : "";
             $appId = isset($credArr[$prefix . $suffix . '.AppId']) ? $credArr[$prefix . $suffix . '.AppId'] : "";
             $subject = isset($credArr[$prefix . $suffix . '.Subject']) ? $credArr[$prefix . $suffix . '.Subject'] : "";
             $this->credentialHashmap[$userName] = new PPSignatureCredential($userName, $password, $signature, $appId, $subject);
         } elseif (isset($credArr[$prefix . $suffix . ".CertPath"]) && $credArr[$prefix . $suffix . ".CertPath"] != null && $credArr[$prefix . $suffix . ".CertPath"] != "") {
             $userName = isset($credArr[$prefix . $suffix . '.UserName']) ? $credArr[$prefix . $suffix . '.UserName'] : "";
             $password = isset($credArr[$prefix . $suffix . '.Password']) ? $credArr[$prefix . $suffix . '.Password'] : "";
             $passPhrase = isset($credArr[$prefix . $suffix . '.CertKey']) ? $credArr[$prefix . $suffix . '.CertKey'] : "";
             $certPath = isset($credArr[$prefix . $suffix . '.CertPath']) ? $credArr[$prefix . $suffix . '.CertPath'] : "";
             $appId = isset($credArr[$prefix . $suffix . '.AppId']) ? $credArr[$prefix . $suffix . '.AppId'] : "";
             $subject = isset($credArr[$prefix . $suffix . '.Subject']) ? $credArr[$prefix . $suffix . '.Subject'] : "";
             $this->credentialHashmap[$userName] = new PPCertificateCredential($userName, $password, $certPath, $appId, $passPhrase, $subject);
         }
         if ($this->defaultAccountName == null) {
             $this->defaultAccountName = $credArr[$prefix . $suffix . '.UserName'];
         }
         $suffix++;
     }
 }
Exemplo n.º 10
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;
 }
Exemplo n.º 11
0
 public function __construct($loggerName)
 {
     $this->loggerName = $loggerName;
     $config = PPConfigManager::getInstance();
     $this->loggerFile = JPATH_COMPONENT . DS . 'lib' . DS . 'payment' . DS . 'payment.log';
     $loggingEnabled = $config->get('log.LogEnabled');
     $this->isLoggingEnabled = isset($loggingEnabled) ? $loggingEnabled : false;
     $loggingLevel = strtoupper($config->get('log.LogLevel'));
     $this->loggingLevel = isset($loggingLevel) && defined("PPLoggingLevel::{$loggingLevel}") ? constant("PPLoggingLevel::{$loggingLevel}") : PPLoggingManager::DEFAULT_LOGGING_LEVEL;
 }
Exemplo n.º 12
0
 public function __construct($loggerName)
 {
     $this->loggerName = $loggerName;
     $config = PPConfigManager::getInstance();
     $this->loggerFile = $config->get('log.FileName') ? $config->get('log.FileName') : ini_get('error_log');
     $loggingEnabled = $config->get('log.LogEnabled');
     $this->isLoggingEnabled = isset($loggingEnabled) ? $loggingEnabled : false;
     $loggingLevel = strtoupper($config->get('log.LogLevel'));
     $this->loggingLevel = isset($loggingLevel) && defined("PPLoggingLevel::{$loggingLevel}") ? constant("PPLoggingLevel::{$loggingLevel}") : PPLoggingManager::DEFAULT_LOGGING_LEVEL;
 }
 public function handle($httpConfig, $request)
 {
     $config = PPConfigManager::getInstance();
     $httpConfig->addHeader('X-PAYPAL-REQUEST-DATA-FORMAT', $request->getBindingType());
     $httpConfig->addHeader('X-PAYPAL-RESPONSE-DATA-FORMAT', $request->getBindingType());
     $httpConfig->addHeader('X-PAYPAL-DEVICE-IPADDRESS', PPUtils::getLocalIPAddress());
     $httpConfig->addHeader('X-PAYPAL-REQUEST-SOURCE', PPUtils::getRequestSource());
     if (strstr($httpConfig->getUrl(), "/AdaptiveAccounts/") && strstr($httpConfig->getUrl(), "sandbox")) {
         $httpConfig->addHeader('X-PAYPAL-SANDBOX-EMAIL-ADDRESS', $config->get('service.SandboxEmailAddress'));
     }
 }
Exemplo n.º 14
0
 public function __construct($loggerName, $config = null)
 {
     $this->loggerName = $loggerName;
     $config = PPConfigManager::getConfigWithDefaults($config);
     $this->isLoggingEnabled = array_key_exists('log.LogEnabled', $config) && $config['log.LogEnabled'] == '1';
     if ($this->isLoggingEnabled) {
         $this->loggerFile = $config['log.FileName'] ? $config['log.FileName'] : ini_get('error_log');
         $loggingLevel = strtoupper($config['log.LogLevel']);
         $this->loggingLevel = isset($loggingLevel) && defined("PPLoggingLevel::{$loggingLevel}") ? constant("PPLoggingLevel::{$loggingLevel}") : PPLoggingManager::DEFAULT_LOGGING_LEVEL;
     }
 }
Exemplo n.º 15
0
 public function __construct($serviceName, $serviceBinding, $handlers = array(), $config = null)
 {
     $this->serviceName = $serviceName;
     $this->serviceBinding = $serviceBinding;
     $this->handlers = $handlers;
     if ($config == null) {
         $configFile = PPConfigManager::getInstance();
         $this->config = $configFile->getConfigHashmap();
     } else {
         $this->config = PPConfigManager::mergrDefaults($config);
     }
 }
Exemplo n.º 16
0
 public function __construct($loggerName, $config = null)
 {
     $this->loggerName = $loggerName;
     if ($config == null) {
         $config = PPConfigManager::getInstance()->getConfigHashmap();
     }
     $this->isLoggingEnabled = array_key_exists('log.LogEnabled', $config) && $config['log.LogEnabled'] == '1';
     if ($this->isLoggingEnabled) {
         $this->loggerFile = $config['log.FileName'] ? $config['log.FileName'] : ini_get('error_log');
         $loggingLevel = strtoupper($config['log.LogLevel']);
         $this->loggingLevel = isset($loggingLevel) && defined(__NAMESPACE__ . "\\PPLoggingLevel::{$loggingLevel}") ? constant(__NAMESPACE__ . "\\PPLoggingLevel::{$loggingLevel}") : PPLoggingManager::DEFAULT_LOGGING_LEVEL;
     }
 }
Exemplo n.º 17
0
 /**
  * 
  * @param string $method - API method to call
  * @param object $requestObject Request object 
  * @param apiContext $apiContext object containing credential and SOAP headers
  * @param mixed $apiUserName - Optional API credential - can either be
  * 		a username configured in sdk_config.ini or a ICredential object created dynamically 		
  */
 public function call($port, $method, $requestObject, $apiContext, $handlers)
 {
     if ($apiContext == null) {
         $apiContext = new PPApiContext(PPConfigManager::getConfigWithDefaults($this->config));
     }
     if ($apiContext->getConfig() == null) {
         $apiContext->setConfig(PPConfigManager::getConfigWithDefaults($this->config));
     }
     $service = new PPAPIService($port, $this->serviceName, $this->serviceBinding, $apiContext, $handlers);
     $ret = $service->makeRequest($method, new PPRequest($requestObject, $this->serviceBinding));
     $this->lastRequest = $ret['request'];
     $this->lastResponse = $ret['response'];
     return $this->lastResponse;
 }
Exemplo n.º 18
0
 /**
  * This function returns a new PPHttpConnection object
  */
 public function getConnection($httpConfig)
 {
     $configMgr = PPConfigManager::getInstance();
     if ($configMgr->get("http.ConnectionTimeOut")) {
         $httpConfig->setHttpTimeout($configMgr->get("http.ConnectionTimeOut"));
     }
     if ($configMgr->get("http.Proxy")) {
         $httpConfig->setHttpProxy($configMgr->get("http.Proxy"));
     }
     if ($configMgr->get("http.Retry")) {
         $retry = $configMgr->get("http.Retry");
         $httpConfig->setHttpRetryCount($retry);
     }
     return new PPHttpConnection($httpConfig);
 }
Exemplo n.º 19
0
 private function initCredential()
 {
     $configMgr = PPConfigManager::getInstance();
     $suffix = 1;
     $prefix = "acct";
     $credArr = $configMgr->get($prefix);
     $arrayPartKeys = $configMgr->getIniPrefix();
     if (count($arrayPartKeys) == 0) {
         throw new PPMissingCredentialException("No valid API accounts have been configured");
     }
     $key = $prefix . $suffix;
     while (in_array($key, $arrayPartKeys)) {
         if (isset($credArr[$key . ".Signature"]) && $credArr[$key . ".Signature"] != null && $credArr[$key . ".Signature"] != "") {
             $userName = isset($credArr[$key . '.UserName']) ? $credArr[$key . '.UserName'] : "";
             $password = isset($credArr[$key . '.Password']) ? $credArr[$key . '.Password'] : "";
             $signature = isset($credArr[$key . '.Signature']) ? $credArr[$key . '.Signature'] : "";
             $this->credentialHashmap[$userName] = new PPSignatureCredential($userName, $password, $signature);
             if (isset($credArr[$key . '.AppId'])) {
                 $this->credentialHashmap[$userName]->setApplicationId($credArr[$key . '.AppId']);
             }
         } elseif (isset($credArr[$key . ".CertPath"]) && $credArr[$key . ".CertPath"] != null && $credArr[$key . ".CertPath"] != "") {
             $userName = isset($credArr[$key . '.UserName']) ? $credArr[$key . '.UserName'] : "";
             $password = isset($credArr[$key . '.Password']) ? $credArr[$key . '.Password'] : "";
             $certPassPhrase = isset($credArr[$key . '.CertKey']) ? $credArr[$key . '.CertKey'] : "";
             $certPath = isset($credArr[$key . '.CertPath']) ? $credArr[$key . '.CertPath'] : "";
             $this->credentialHashmap[$userName] = new PPCertificateCredential($userName, $password, $certPath, $certPassPhrase);
             if (isset($credArr[$key . '.AppId'])) {
                 $this->credentialHashmap[$userName]->setApplicationId($credArr[$key . '.AppId']);
             }
         } elseif (isset($credArr[$key . ".ClientId"]) && isset($credArr[$key . ".ClientId"])) {
             $userName = $key;
             $this->credentialHashmap[$userName] = array('clientId' => $credArr[$key . ".ClientId"], 'clientSecret' => $credArr[$key . ".ClientSecret"]);
         }
         if ($userName && isset($credArr[$key . ".Subject"]) && trim($credArr[$key . ".Subject"]) != "") {
             $this->credentialHashmap[$userName]->setThirdPartyAuthorization(new PPSubjectAuthorization($credArr[$key . ".Subject"]));
         }
         if ($userName && $this->defaultAccountName == null) {
             if (array_key_exists($key . '.UserName', $credArr)) {
                 $this->defaultAccountName = $credArr[$key . '.UserName'];
             } else {
                 $this->defaultAccountName = $key;
             }
         }
         $suffix++;
         $key = $prefix . $suffix;
     }
 }
Exemplo n.º 20
0
 public function toString($object)
 {
     if ($object == null) {
         throw new PPTransformerException("Empty object");
     }
     $confManager = PPConfigManager::getInstance();
     switch (strtoupper($confManager->get("service.Binding"))) {
         case 'SOAP':
             return $object->toXMLString();
         case 'XML':
         case 'JSON':
             return "";
         case 'NVP':
         default:
             return $object->toNVPString();
     }
 }
Exemplo n.º 21
0
 /**
  *
  * @param string $postData OPTIONAL post data. If null,
  * 				the class automatically reads incoming POST data
  * 				from the input stream
  */
 public function __construct($postData = '', $config = null)
 {
     $this->config = PPConfigManager::getConfigWithDefaults($config);
     if ($postData == '') {
         // reading posted data from directly from $_POST may causes serialization issues with array data in POST
         // reading raw POST data from input stream instead.
         $postData = file_get_contents('php://input');
     }
     $rawPostArray = explode('&', $postData);
     foreach ($rawPostArray as $keyValue) {
         $keyValue = explode('=', $keyValue);
         if (count($keyValue) == 2) {
             $this->ipnData[urldecode($keyValue[0])] = urldecode($keyValue[1]);
         }
     }
     //var_dump($this->ipnData);
 }
Exemplo n.º 22
0
 /**
  * @test
  */
 public function testMergeWithDefaults()
 {
     // Test file based config params and defaults
     $config = PPConfigManager::getInstance()->getConfigWithDefaults(array());
     $this->assertArrayHasKey('mode', $config, 'file config not read when no custom config is passed');
     $this->assertEquals('sandbox', $config['mode']);
     $this->assertEquals(60, $config['http.ConnectionTimeOut']);
     // Test custom config params and defaults
     $config = PPConfigManager::getInstance()->getConfigWithDefaults(array('mode' => 'custom'));
     $this->assertArrayHasKey('mode', $config);
     $this->assertEquals('custom', $config['mode']);
     $this->assertEquals(30, $config['http.ConnectionTimeOut']);
     // Test override for default connection params
     $config = PPConfigManager::getInstance()->getConfigWithDefaults(array('mode' => 'custom', 'http.ConnectionTimeOut' => 100));
     $this->assertArrayHasKey('mode', $config);
     $this->assertEquals('custom', $config['mode']);
     $this->assertEquals(100, $config['http.ConnectionTimeOut']);
 }
Exemplo n.º 23
0
 /**
  * This function returns a new PPHttpConnection object
  */
 public function getConnection()
 {
     $connection = new PPHttpConnection();
     $configMgr = PPConfigManager::getInstance();
     if ($configMgr->get("http.ConnectionTimeOut")) {
         $connection->setHttpTimeout($configMgr->get("http.ConnectionTimeOut"));
     }
     if ($configMgr->get("http.TrustAllConnection")) {
         $connection->setHttpTrustAllConnection($configMgr->get("http.TrustAllConnection"));
     }
     if ($configMgr->get("http.Proxy")) {
         $connection->setHttpProxy($configMgr->get("http.Proxy"));
     }
     if ($configMgr->get("http.Retry")) {
         $retry = $configMgr->get("http.Retry");
         $connection->setHttpRetry($retry);
     }
     return $connection;
 }
Exemplo n.º 24
0
 /**
  * SetExpressCheckout実行
  *
  */
 public function setExpressCheckout()
 {
     global $mts_simple_booking;
     // 予約データと計算書データを取得する
     $booking = $mts_simple_booking->oBooking_form->getBooking();
     $bill = $mts_simple_booking->oBooking_form->make_bill();
     // PayPalアクセス準備
     //$this->_init_paypal_sdk('SetExpressCheckout');
     // Nonceデータを含める
     $this->sess_data = array('page_url' => $this->page_url, 'nonce' => $this->_get_nonce(), 'booking' => $booking);
     // 予約データをセッションテーブルに保存
     $this->sess_name = $this->_save_sessData($this->sess_data);
     // リターンURLを求める
     $params = array('sid' => $this->sess_name, 'nonce' => $this->sess_data['nonce'], 'page_url' => $this->page_url);
     $returnUrl = add_query_arg(array('pp' => 'checkout') + $params, $this->return_url);
     $cancelUrl = add_query_arg(array('pp' => 'cancel') + $params, $this->return_url);
     // Checkout 明細オブジェクト
     $paymentDetails = new PaymentDetailsType();
     $paymentDetails->PaymentAction = 'Sale';
     $currencyCode = $bill->currency_code;
     // 予約品目の料金明細設定
     foreach ($this->type as $type) {
         //($i=0; $i<count($_REQUEST['itemAmount']); $i++) {
         // 人数または料金が0の場合は明細に掲載しない
         if ($bill->number->{$type} == 0 || $bill->amount->{$type} == 0) {
             continue;
         }
         // 明細データ
         $itemDetails = new PaymentDetailsItemType();
         $itemDetails->Name = $bill->article_name . ' ' . apply_filters('booking_form_bill_label', __(ucwords($type), $this->domain));
         $itemDetails->Amount = new BasicAmountType($currencyCode, $bill->amount->{$type});
         $itemDetails->Quantity = $bill->number->{$type};
         $itemDetails->ItemCategory = 'Physical';
         $paymentDetails->PaymentDetailsItem[] = $itemDetails;
     }
     // オプションの料金明細設定
     $option_items = $bill->option_items;
     if (!empty($option_items)) {
         foreach ($option_items as $option_item) {
             $itemDetails = new PaymentDetailsItemType();
             $itemDetails->Name = $option_item['name'];
             $itemDetails->Amount = $option_item['price'];
             $itemDetails->Quantity = $option_item['number'];
             $itemDetails->ItemCategory = 'Physical';
             $paymentDetails->PaymentDetailsItem[] = $itemDetails;
         }
     }
     //$paymentDetails->ShipToAddress = $address;
     $itemTotal = $bill->get_total();
     $taxTotal = $bill->tax_type == 2 ? $bill->get_amount_tax() : 0;
     $paymentDetails->ItemTotal = new BasicAmountType($currencyCode, $itemTotal);
     $paymentDetails->TaxTotal = new BasicAmountType($currencyCode, $taxTotal);
     $paymentDetails->OrderTotal = new BasicAmountType($currencyCode, $itemTotal + $taxTotal);
     //$paymentDetails->HandlingTotal = new BasicAmountType($currencyCode, $bill->total_cost);
     //$paymentDetails->insuranceTotal = new BasicAmountType($currencyCode, $_REQUEST['insuranceTotal']);
     //$paymentDetails->ShippingTotal = new BasicAmountType($currencyCode, $itemTotal);
     // APIデータ設定
     $setECReqDetails = new SetExpressCheckoutRequestDetailsType();
     $setECReqDetails->PaymentDetails[0] = $paymentDetails;
     $setECReqDetails->CancelURL = $cancelUrl;
     $setECReqDetails->ReturnURL = $returnUrl;
     $setECReqDetails->cppheaderimage = $this->logo_url;
     $setECReqDetails->BrandName = $bill->shop_name;
     $setECReqDetails->LocaleCode = 'ja_JP';
     $setECReqDetails->SolutionType = 'Sole';
     $setECReqDeatils->LandingPage = 'Billing';
     $setECReqDetails->BuyerEmail = $booking['client']['email'];
     $setECReqType = new SetExpressCheckoutRequestType();
     $setECReqType->SetExpressCheckoutRequestDetails = $setECReqDetails;
     $setECReq = new SetExpressCheckoutReq();
     $setECReq->SetExpressCheckoutRequest = $setECReqType;
     // セッションデータにリクエストを追加する
     $this->_add_sessData($this->sess_name, array('setECReq' => serialize($setECReq)));
     $paypalService = new PayPalAPIInterfaceServiceService();
     try {
         /* wrap API method calls on the service object with a try catch */
         $setECResponse = $paypalService->SetExpressCheckout($setECReq);
     } catch (Exception $ex) {
         throw $ex;
     }
     // API SetExpressCheckoutの結果を保存する
     $token = '';
     if (isset($setECResponse)) {
         // セッションデータに接続結果を追加する
         $this->_add_sessData($this->sess_name, array('setECResponse' => serialize($setECResponse)));
         // PayPal支払処理へリダイレクトする
         if ($setECResponse->Ack == 'Success') {
             // PayPalへのリダイレクト
             $paypalUrl = PPConfigManager::getInstance()->get('service.RedirectURL') . '_express-checkout&useraction=commit&token=' . $setECResponse->Token;
             //echo "<a href=$paypalUrl><b>Redirect to PayPal to login</b></a><br />";
             //exit();
             header("Location: {$paypalUrl}");
             exit;
         }
     }
     return $setECResponse;
 }
Exemplo n.º 25
0
 private function getOAuthHttpConfiguration()
 {
     $configMgr = \PPConfigManager::getInstance();
     $baseEndpoint = $configMgr->get("oauth.EndPoint") != '' && !is_array($configMgr->get("oauth.EndPoint")) ? $configMgr->get("oauth.EndPoint") : $configMgr->get("service.EndPoint");
     if (is_array($baseEndpoint)) {
         $this->logger->info("Starting logging of baseEndpoint properties --- ");
         $this->logger->info(var_dump($baseEndpoint) . " --- ");
         $this->logger->info("Ending logging of baseEndpoint properties");
         $this->logger->info("Config file still not working properly, defaulting the service.Endpoint to the paypal sandbox api call");
         $baseEndpoint = null;
         $baseEndpoint = "";
         $baseEndpoint = "https://api.sandbox.paypal.com";
     }
     $baseEndpoint = rtrim(trim($baseEndpoint), '/');
     return new \PPHttpConfig($baseEndpoint . "/v1/oauth2/token", "POST");
 }
Exemplo n.º 26
0
 /**
  * use  the default configuration if it is not passed in hashmap
  */
 public static function getConfigWithDefaults($config = null)
 {
     if (!is_array(PPConfigManager::getInstance()->getConfigHashmap()) && $config == null) {
         return PPConfigManager::$defaults;
     }
     return array_merge(PPConfigManager::$defaults, $config != null ? $config : PPConfigManager::getInstance()->getConfigHashmap());
 }
Exemplo n.º 27
0
 public function __construct($config = null)
 {
     $this->config = PPConfigManager::getConfigWithDefaults($config);
 }
Exemplo n.º 28
0
<?php

/*
 * Sample bootstrap file.
*/
// Include the composer autoloader
if (!file_exists(__DIR__ . '/vendor/autoload.php')) {
    echo "The 'vendor' folder is missing. You must run 'composer update' to resolve application dependencies.\nPlease see the README for more information.\n";
    exit(1);
}
require __DIR__ . '/vendor/autoload.php';
use PayPal\Auth\OAuthTokenCredential;
define("PP_CONFIG_PATH", __DIR__);
$configManager = \PPConfigManager::getInstance();
// $cred is used by samples that include this bootstrap file
// This piece of code simply demonstrates how you can
// dynamically pass in a client id/secret instead of using
// the config file. If you do not need a way to pass
// in credentials dynamically, you can skip the
// <Resource>::setCredential($cred) calls that
// you see in the samples.
$cred = new OAuthTokenCredential($configManager->get('acct1.ClientId'), $configManager->get('acct1.ClientSecret'));
/**
 * ### getBaseUrl function
 * // utility function that returns base url for
 * // determining return/cancel urls
 * @return string
 */
function getBaseUrl()
{
    $protocol = 'http';
Exemplo n.º 29
0
 private function getOAuthHttpConfiguration()
 {
     $configMgr = \PPConfigManager::getInstance();
     $baseEndpoint = $configMgr->get("oauth.EndPoint") != '' && !is_array($configMgr->get("oauth.EndPoint")) ? $configMgr->get("oauth.EndPoint") : $configMgr->get("service.EndPoint");
     $baseEndpoint = rtrim(trim($baseEndpoint), '/');
     return new \PPHttpConfig($baseEndpoint . "/v1/oauth2/token", "POST");
 }
Exemplo n.º 30
0
 public static function OAuthTokenCredential($ClientId = null, $ClientSecret = null)
 {
     if (isset($ClientId) && isset($ClientSecret)) {
         return new OAuthTokenCredential($ClientId, $ClientSecret);
     }
     $configManager = \PPConfigManager::getInstance();
     // $cred is used by samples that include this bootstrap file
     // This piece of code simply demonstrates how you can
     // dynamically pass in a client id/secret instead of using
     // the config file. If you do not need a way to pass
     // in credentials dynamically, you can skip the
     // <Resource>::setCredential($cred) calls that
     // you see in the samples.
     $cred = new OAuthTokenCredential($configManager->get('acct1.ClientId'), $configManager->get('acct1.ClientSecret'));
     return $cred;
 }