本文整理匯總了PHP中PayPal\Rest\ApiContext::setConfig方法的典型用法代碼示例。如果您正苦於以下問題:PHP ApiContext::setConfig方法的具體用法?PHP ApiContext::setConfig怎麽用?PHP ApiContext::setConfig使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PayPal\Rest\ApiContext
的用法示例。
在下文中一共展示了ApiContext::setConfig方法的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;
}
示例2: testGetEndpoint
/**
* @dataProvider modeProvider
* @param $configs
*/
public function testGetEndpoint($configs)
{
$config = $configs + array('cache.enabled' => true, 'http.headers.header1' => 'header1value');
$this->apiContext->setConfig($config);
$this->httpConfig = new PayPalHttpConfig(null, 'POST', $config);
$this->handler = new OauthHandler($this->apiContext);
$this->handler->handle($this->httpConfig, null, $this->config);
}
示例3: 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;
}
示例4: 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.');
}
}
示例5: 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;
}
示例6: changeEnvironment
/**
* @param $environment
* @return ApiContext
*/
public function changeEnvironment($environment)
{
$endpoint = '';
switch ($environment) {
case GeneralConst::ENVIRONMENT_SANDBOX:
$endpoint = GeneralConst::ENDPOING_SANDBOX;
break;
case GeneralConst::ENVIRONMENT_PROD:
$endpoint = GeneralConst::ENDPOINT_PROD;
break;
}
$config['service.EndPoint'] = $endpoint;
$config['mode'] = $environment;
$this->apiContext->setConfig($config);
return $this->apiContext;
}
示例7: getApiContext
public function getApiContext($clientId, $clientSecret)
{
$oauthCredentials = new OAuthTokenCredential($clientId, $clientSecret);
$apiContext = new ApiContext($oauthCredentials);
$apiContext->setConfig($this->config);
return $apiContext;
}
示例8: 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;
}
示例9: setApiContext
private function setApiContext()
{
$settings = ClientHelper::getPaymentGatewayInfo('paypal');
$client_id = $settings->sandbox_mode ? $settings->test_client_id : $settings->client_id;
$secret = $settings->sandbox_mode ? $settings->test_secret : $settings->secret;
$this->apiContext = new ApiContext(new OAuthTokenCredential($client_id, $secret));
$this->apiContext->setConfig(['mode' => $settings->sandbox_mode ? 'sandbox' : 'live', 'log.FileName' => './storage/logs/paypal.log', 'log.LogLevel' => $settings->sandbox_mode ? 'DEBUG' : 'INFO', 'cache.enabled' => false]);
}
示例10: setConfig
/**
* @inheritdoc
*/
private function setConfig()
{
$this->_apiContext = new ApiContext(new OAuthTokenCredential($this->clientId, $this->clientSecret));
$logFileName = \Yii::getAlias('@runtime/logs/paypal.log');
if (isset($this->config['log.FileName']) && isset($this->config['log.LogEnabled']) && $this->config['log.LogEnabled']) {
$logFileName = \Yii::getAlias($this->config['log.FileName']);
if ($logFileName) {
if (!file_exists($logFileName)) {
if (!touch($logFileName)) {
throw new ErrorException($logFileName . ' for paypal not created!');
}
}
}
$this->config['log.FileName'] = $logFileName;
}
$this->_apiContext->setConfig(ArrayHelper::merge(['mode' => self::MODE_SANDBOX, 'http.ConnectionTimeOut' => 30, 'http.Retry' => 1, 'log.LogEnabled' => YII_DEBUG ? 1 : 0, 'log.FileName' => $logFileName, 'log.LogLevel' => self::LOG_LEVEL_FINE, 'validation.level' => 'log', 'cache.enabled' => 'true'], $this->config));
return $this->_apiContext;
}
示例11: 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;
}
示例12: 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;
}
示例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;
}
示例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;
}
示例15: 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;
}