當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Rest\ApiContext類代碼示例

本文整理匯總了PHP中PayPal\Rest\ApiContext的典型用法代碼示例。如果您正苦於以下問題:PHP ApiContext類的具體用法?PHP ApiContext怎麽用?PHP ApiContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ApiContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: setConfig

 /**
  * @inheritdoc
  */
 private function setConfig()
 {
     // ### Api context
     // Use an ApiContext object to authenticate
     // API calls. The clientId and clientSecret for the
     // OAuthTokenCredential class can be retrieved from
     // developer.paypal.com
     $this->_apiContext = new ApiContext(new OAuthTokenCredential($this->clientId, $this->clientSecret));
     // #### SDK configuration
     // Comment this line out and uncomment the PP_CONFIG_PATH
     // 'define' block if you want to use static file
     // based configuration
     $this->_apiContext->setConfig(ArrayHelper::merge(['mode' => self::MODE_SANDBOX, 'http.ConnectionTimeOut' => 30, 'http.Retry' => 1, 'log.LogEnabled' => YII_DEBUG ? 1 : 0, 'log.FileName' => Yii::getAlias('@runtime/logs/paypal.log'), 'log.LogLevel' => self::LOG_LEVEL_FINE, 'validation.level' => 'log', 'cache.enabled' => 'true'], $this->config));
     // Set file name of the log if present
     if (isset($this->config['log.FileName']) && isset($this->config['log.LogEnabled']) && (bool) $this->config['log.LogEnabled'] == true) {
         $logFileName = \Yii::getAlias($this->config['log.FileName']);
         if ($logFileName) {
             if (!file_exists($logFileName)) {
                 if (!touch($logFileName)) {
                     throw new ErrorException('Can\'t create paypal.log file at: ' . $logFileName);
                 }
             }
         }
         $this->config['log.FileName'] = $logFileName;
     }
     return $this->_apiContext;
 }
開發者ID:kongoon,項目名稱:yii2-paypal,代碼行數:30,代碼來源:Paypal.php

示例2: getApiContext

function getApiContext($clientId, $clientSecret)
{
    // #### SDK configuration
    // Register the sdk_config.ini file in current directory
    // as the configuration source.
    /*
    if(!defined("PP_CONFIG_PATH")) {
        define("PP_CONFIG_PATH", __DIR__);
    }
    */
    // ### Api context
    // Use an ApiContext object to authenticate
    // API calls. The clientId and clientSecret for the
    // OAuthTokenCredential class can be retrieved from
    // developer.paypal.com
    $apiContext = new ApiContext(new OAuthTokenCredential($clientId, $clientSecret));
    // Comment this line out and uncomment the PP_CONFIG_PATH
    // 'define' block if you want to use static file
    // based configuration
    $apiContext->setConfig(array('mode' => 'sandbox', 'log.LogEnabled' => true, 'log.FileName' => APPLICATION_PATH . '/../logs/PayPal.log', 'log.LogLevel' => 'FINE', 'validation.level' => 'log', 'cache.enabled' => true));
    // Partner Attribution Id
    // Use this header if you are a PayPal partner. Specify a unique BN Code to receive revenue attribution.
    // To learn more or to request a BN Code, contact your Partner Manager or visit the PayPal Partner Portal
    // $apiContext->addRequestHeader('PayPal-Partner-Attribution-Id', '123123123');
    return $apiContext;
}
開發者ID:cioionut,項目名稱:products-webEcommerce,代碼行數:26,代碼來源:paypal_bootstrap.php

示例3: getApiContext

 public function getApiContext($clientId, $clientSecret)
 {
     $oauthCredentials = new OAuthTokenCredential($clientId, $clientSecret);
     $apiContext = new ApiContext($oauthCredentials);
     $apiContext->setConfig($this->config);
     return $apiContext;
 }
開發者ID:blozixdextr,項目名稱:tuasist2,代碼行數:7,代碼來源:PaypalPaymentService.php

示例4: getApiContext

/**
 * Helper method for getting an APIContext for all calls
 *
 * @return PayPal\Rest\ApiContext
 */
function getApiContext()
{
    // ### Api context
    // Use an ApiContext object to authenticate
    // API calls. The clientId and clientSecret for the
    // OAuthTokenCredential class can be retrieved from
    // developer.paypal.com
    /*	
    	// sandbox
    	$apiContext = new ApiContext(
    		new OAuthTokenCredential(
    			'AafDsxDBf3aFlXShFlPBWjIYLWlpffOjQ_YVySCcGBrAWsgfJaJ_TJiszPi7',
    			'EE2lCxCSyGfI8TPKHRPALfhxcBfqWk6UBeyLSGtLLJWEYSo0xJOsxtApcFd_'
    		)
    	);
    */
    // live
    $apiContext = new ApiContext(new OAuthTokenCredential('AXh7hxAI5NHnEklbfdA9vJsYRZy1U2u5HfcELrXlPyMSNCJAQ7D6UBaLI8jc', 'EDGVlhCrtFADL5v3CJz-ejRchN8PvYrotuwiMM-ds9BVEXQP5LlNsBZW2hA6'));
    // #### SDK configuration
    // Comment this line out and uncomment the PP_CONFIG_PATH
    // 'define' block if you want to use static file
    // based configuration
    $apiContext->setConfig(array('mode' => 'live', 'http.ConnectionTimeOut' => 30, 'log.LogEnabled' => true, 'log.FileName' => '../PayPal.log', 'log.LogLevel' => 'FINE'));
    /*
    // Register the sdk_config.ini file in current directory
    // as the configuration source.
    if(!defined("PP_CONFIG_PATH")) {
    	define("PP_CONFIG_PATH", __DIR__);
    }
    */
    return $apiContext;
}
開發者ID:fur81,項目名稱:zofaxiopeu,代碼行數:37,代碼來源:bootstrap.php

示例5: check

 /**
  * @param PaymentInterface $payment
  * @throws InvalidPaymentException
  */
 public function check(PaymentInterface $payment)
 {
     if ($payment->getTransaction()) {
         throw new InvalidPaymentException('Payment has already been received.');
     }
     $credentials = new OAuthTokenCredential($this->options['client_id'], $this->options['secret']);
     $apiContext = new ApiContext($credentials);
     $apiContext->setConfig(['mode' => $this->options['mode']]);
     $paypalPayment = Payment::get($payment->getExtraData('paypal_payment_id'), $apiContext);
     $payer = $paypalPayment->getPayer();
     if (!$payer || 'verified' !== strtolower($payer->getStatus())) {
         throw new InvalidPaymentException('Payer not verified.');
     }
     if ('created' == $paypalPayment->getState()) {
         $execution = new PaymentExecution();
         $execution->setPayerId($paypalPayment->getPayer()->getPayerInfo()->getPayerId());
         $paypalPayment->execute($execution, $apiContext);
     }
     if ('approved' != $paypalPayment->getState()) {
         throw new InvalidPaymentException('Invalid payment state.');
     }
     $math = new NativeMath();
     $controlSum = 0;
     foreach ($paypalPayment->getTransactions() as $transaction) {
         if ($transaction->getAmount()->getCurrency() != $payment->getAccount()->getCurrency()) {
             throw new InvalidPaymentException('Invalid payment currency.');
         }
         $controlSum = $math->sum($controlSum, $transaction->getAmount()->getTotal());
     }
     if (!$math->eq($payment->getPaymentSum(), $controlSum)) {
         throw new InvalidPaymentException('Invalid payment sum.');
     }
 }
開發者ID:moriony,項目名稱:payment-gateway,代碼行數:37,代碼來源:PayPalHandler.php

示例6: setApiContext

 /**
  * Set api context
  *
  * @param $website
  * @return $this
  */
 public function setApiContext($website = null)
 {
     $this->_apiContext = new ApiContext(new OAuthTokenCredential(Mage::getStoreConfig('iways_paypalplus/api/client_id', $website), Mage::getStoreConfig('iways_paypalplus/api/client_secret', $website)));
     $this->_mode = Mage::getStoreConfig('iways_paypalplus/api/mode', $website);
     $this->_apiContext->setConfig(array('http.ConnectionTimeOut' => 30, 'http.Retry' => 1, 'mode' => $this->_mode, 'log.LogEnabled' => Mage::getStoreConfig('dev/log/active', $website), 'log.FileName' => Mage::getBaseDir('log') . DS . 'PayPal.log', 'log.LogLevel' => 'INFO'));
     $this->_apiContext->addRequestHeader('PayPal-Partner-Attribution-Id', 'Magento_Cart_PayPalPlus');
     return $this;
 }
開發者ID:sickdaflip,項目名稱:Iways_PayPalPlus-1.4.5,代碼行數:14,代碼來源:Api.php

示例7: getLogoutUrl

 /**
  * Returns the URL to which the user must be redirected to
  * logout from the OpenID provider (i.e. PayPal)
  *
  * @param string     $redirectUri   Uri on merchant website to where
  *                                  the user must be redirected to post logout
  * @param string     $idToken       id_token from the TokenInfo object
  * @param ApiContext $apiContext    Optional API Context
  * @return string logout URL
  */
 public static function getLogoutUrl($redirectUri, $idToken, $apiContext = null)
 {
     if (is_null($apiContext)) {
         $apiContext = new ApiContext();
     }
     $config = $apiContext->getConfig();
     $params = array('id_token' => $idToken, 'redirect_uri' => $redirectUri, 'logout' => 'true');
     return sprintf("%s/webapps/auth/protocol/openidconnect/v1/endsession?%s", self::getBaseUrl($config), http_build_query($params));
 }
開發者ID:paypal,項目名稱:rest-api-sdk-php,代碼行數:19,代碼來源:OpenIdSession.php

示例8: getApiContext

 public function getApiContext()
 {
     /*$apiContext = new ApiContext(new OAuthTokenCredential(
         'AbxhksgjlQREXW6DXFywwhHj-WYBZKojDMc1il3WlpF7OU_yR8R7J8pZKOP1PT5f4UP7OXFoCHO4L-Zq',
         'ELp7381HZADMafiEvmpTiIsuEzQEhNvm3WTcA6n-kiAg4MvSoCei4Ob0jikeekgcIsXSHTS0cBf1-TVG'
       ));*/
     $apiContext = new ApiContext(new OAuthTokenCredential('AViZLEV_4q3zxbXnCZkorEW_ZQjjBaMBveSt0EZHoNEicnFarwU1GXvRh0xx-ZBqfFgNTVKiYgMnTySM', 'EJybFEJ8EOhrAeo93llf3u-SwLSeIhVk2LFPZCsGp_VLumj0gRA4hwRgOhWFaU1tLBo_eDdt1E_Jzeus'));
     $apiContext->setConfig(array('http.ConnectionTimeOut' => 30, 'http.Retry' => 1, 'mode' => 'live', 'log.LogEnabled' => true, 'log.FileName' => '../PayPal.log', 'log.LogLevel' => 'INFO'));
     return $apiContext;
 }
開發者ID:juanazareno,項目名稱:joan-cornella,代碼行數:10,代碼來源:paypalmodel.php

示例9: get_api_context

 public function get_api_context()
 {
     if (PAYPAL_MODE == 'sandbox') {
         $apiContext = new ApiContext(new OAuthTokenCredential(PAYPAL_DEVID, PAYPAL_DEVSECRET));
     } else {
         $apiContext = new ApiContext(new OAuthTokenCredential(PAYPAL_LIVEID, PAYPAL_LIVESECRET));
     }
     $apiContext->setConfig(array('mode' => PAYPAL_MODE, 'http.ConnectionTimeOut' => 30, 'log.LogEnabled' => true, 'log.FileName' => 'app/PayPal.log', 'log.LogLevel' => 'FINE'));
     return $apiContext;
 }
開發者ID:Hova10,項目名稱:novosite,代碼行數:10,代碼來源:m_payments.php

示例10: getPayPal

 public function getPayPal()
 {
     if (!$this->payPalClientId) {
         throw new RuntimeException('Paypal clientId is missing');
     }
     if (!$this->payPalClientSecret) {
         throw new RuntimeException('Paypal clientSecret is missing');
     }
     $apiContext = new ApiContext(new OAuthTokenCredential($this->payPalClientId, $this->payPalClientSecret));
     $apiContext->setConfig(array('mode' => $this->developmentMode ? 'sandbox' : 'live', 'log.LogEnabled' => true, 'log.FileName' => '/tmp/PayPal.log', 'log.LogLevel' => $this->developmentMode ? 'DEBUG' : 'FINE', 'cache.enabled' => true, 'cache.FileName' => 'data/paypal.cache'));
     return $apiContext;
 }
開發者ID:milqmedia,項目名稱:mq-payments,代碼行數:12,代碼來源:PaypalProvider.php

示例11: getApiContext

 private function getApiContext($clientId, $clientSecret)
 {
     global $tmpdir, $config;
     $payconf = $config['PayPal'];
     if ($payconf['enable'] === 'no') {
         echo "FATAL ERROR: PayPal not configured.";
         exit(2);
     }
     $apiContext = new ApiContext(new OAuthTokenCredential($clientId, $clientSecret));
     $apiContext->setConfig(array('mode' => $payconf['enable'] == 'prod' ? 'live' : 'sandbox', 'log.LogEnabled' => false, 'log.FileName' => $tmpdir . '/PayPal.log', 'log.LogLevel' => 'INFO', 'cache.enabled' => true, 'cache.FileName' => $tmpdir . 'paypal.cache'));
     return $apiContext;
 }
開發者ID:bontiv,項目名稱:intrateb,代碼行數:12,代碼來源:caddie_paie.php

示例12: SetUpForFunctionalTests

 public static function SetUpForFunctionalTests(\PHPUnit_Framework_TestCase &$test)
 {
     $context = new ApiContext();
     $context->setConfig(array('mode' => 'sandbox', 'http.ConnectionTimeOut' => 30, 'log.LogEnabled' => true, 'log.FileName' => '../PayPal.log', 'log.LogLevel' => 'FINE', 'validation.level' => 'warning'));
     PayPalCredentialManager::getInstance()->setCredentialObject(PayPalCredentialManager::getInstance()->getCredentialObject('acct1'));
     self::$mode = getenv('REST_MODE') ? getenv('REST_MODE') : 'mock';
     if (self::$mode != 'sandbox') {
         // Mock PayPalRest Caller if mode set to mock
         $test->mockPayPalRestCall = $test->getMockBuilder('\\PayPal\\Transport\\PayPalRestCall')->disableOriginalConstructor()->getMock();
         $test->mockPayPalRestCall->expects($test->any())->method('execute')->will($test->returnValue($test->response));
     }
 }
開發者ID:johnmicahmiguel,項目名稱:yodaphp,代碼行數:12,代碼來源:Setup.php

示例13: getApiContext

 public static function getApiContext()
 {
     // ### Api context
     // Use an ApiContext object to authenticate
     // API calls. The clientId and clientSecret for the
     // OAuthTokenCredential class can be retrieved from
     // developer.paypal.com
     $apiContext = new ApiContext(new OAuthTokenCredential($_ENV['PAYPAL_CLIENT_ID'], $_ENV['PAYPAL_SECRET']));
     // setting some configurations
     $apiContext->setConfig(array('mode' => $_ENV['PAYPAL_MODE'], 'log.LogEnabled' => true, 'log.FileName' => base_path('storage/logs/paypal.log'), 'log.LogLevel' => 'DEBUG', 'cache.enabled' => true));
     return $apiContext;
 }
開發者ID:alfchee,項目名稱:PaypalTest,代碼行數:12,代碼來源:PaypalBootstrap.php

示例14: getApiContext

 /**
  * Getting the API context for the application
  * change the clientID and clientSecret accordingly
  *
  * @return boolean
  */
 public static function getApiContext()
 {
     // setting api codes
     $client_id = "AY1PlRC0yK6SExlx8aRDW-hF2REkl90Qmza0Ak5LUacd-LFAczGmXfanQYK-";
     $client_secret = "EBXUZxD6PobEUtc-WldtZgbG8eUzl4IkOFAeMxpAGhNDt-mESoj3a3QRRIGw";
     // getting the ApiContext from oauths
     $api_context = new ApiContext(new OAuthTokenCredential($client_id, $client_secret));
     // setting api contextd
     $api_context->setConfig(array('mode' => 'sandbox', 'http.ConnectionTimeOut' => 30, 'log.LogEnabled' => true, 'log.FileName' => '../PayPal.log', 'log.LogLevel' => 'FINE', 'validation.level' => 'log', 'cache.enabled' => 'true'));
     // returning api context
     return $api_context;
 }
開發者ID:raschan,項目名稱:fruit-dashboard,代碼行數:18,代碼來源:PayPalHelper.php

示例15: testGetAccessTokenUnit

 public function testGetAccessTokenUnit()
 {
     $config = array('mode' => 'sandbox', 'cache.enabled' => true, 'cache.FileName' => AuthorizationCacheTest::CACHE_FILE);
     $cred = new OAuthTokenCredential('clientId', 'clientSecret');
     //{"clientId":{"clientId":"clientId","accessToken":"accessToken","tokenCreateTime":1421204091,"tokenExpiresIn":288000000}}
     AuthorizationCache::push($config, 'clientId', $cred->encrypt('accessToken'), 1421204091, 288000000);
     $apiContext = new ApiContext($cred);
     $apiContext->setConfig($config);
     $this->assertEquals('clientId', $cred->getClientId());
     $this->assertEquals('clientSecret', $cred->getClientSecret());
     $result = $cred->getAccessToken($config);
     $this->assertNotNull($result);
 }
開發者ID:omasterdesign,項目名稱:omasterdefault,代碼行數:13,代碼來源:OAuthTokenCredentialTest.php


注:本文中的PayPal\Rest\ApiContext類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。