forked from LiveCarta/PayPal-PHP-SDK
Moving apiContext creation to a function
This commit is contained in:
@@ -13,39 +13,58 @@ if(!file_exists(__DIR__ .'/vendor/autoload.php')) {
|
|||||||
|
|
||||||
require __DIR__ . '/vendor/autoload.php';
|
require __DIR__ . '/vendor/autoload.php';
|
||||||
require __DIR__ . '/common.php';
|
require __DIR__ . '/common.php';
|
||||||
|
|
||||||
use PayPal\Rest\ApiContext;
|
use PayPal\Rest\ApiContext;
|
||||||
use PayPal\Auth\OAuthTokenCredential;
|
use PayPal\Auth\OAuthTokenCredential;
|
||||||
|
|
||||||
|
$apiContext = getApiContext();
|
||||||
|
|
||||||
|
|
||||||
// ### Api context
|
/**
|
||||||
// Pass in a `PayPal\Rest\ApiContext` object to authenticate
|
* Helper method for getting an APIContext for all calls
|
||||||
// API calls. The clientId and clientSecret for the
|
*
|
||||||
// OAuthTokenCredential class can be retrieved from
|
* @return PayPal\Rest\ApiContext
|
||||||
// developer.paypal.com
|
*/
|
||||||
|
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(
|
$apiContext = new ApiContext(
|
||||||
new OAuthTokenCredential(
|
new OAuthTokenCredential(
|
||||||
'EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM',
|
'EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM',
|
||||||
'EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM'
|
'EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// #### SDK configuration
|
// #### SDK configuration
|
||||||
// Comment this line out and uncomment the PP_CONFIG_PATH
|
|
||||||
// 'define' if you want to use a static file based configuration
|
// Comment this line out and uncomment the PP_CONFIG_PATH
|
||||||
|
// 'define' block if you want to use static file
|
||||||
|
// based configuration
|
||||||
|
|
||||||
$apiContext->setConfig(
|
$apiContext->setConfig(
|
||||||
array(
|
array(
|
||||||
'mode' => 'sandbox',
|
'mode' => 'sandbox',
|
||||||
'http.ConnectionTimeOut' => 30,
|
'http.ConnectionTimeOut' => 30,
|
||||||
'log.LogEnabled' => true,
|
'log.LogEnabled' => true,
|
||||||
'log.FileName' => '../PayPal.log',
|
'log.FileName' => '../PayPal.log',
|
||||||
'log.LogLevel' => 'FINE'
|
'log.LogLevel' => 'FINE'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
// Register the sdk_config.ini file in current directory
|
|
||||||
// as the configuration source.
|
/*
|
||||||
// define("PP_CONFIG_PATH", __DIR__);
|
// 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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ $refund->setAmount($amt);
|
|||||||
try {
|
try {
|
||||||
// Create a new apiContext object so we send a new
|
// Create a new apiContext object so we send a new
|
||||||
// PayPal-Request-Id (idempotency) header for this resource
|
// PayPal-Request-Id (idempotency) header for this resource
|
||||||
$apiContext = new ApiContext($apiContext->getCredential());
|
$apiContext = getApiContext();
|
||||||
|
|
||||||
$captureRefund = $capture->refund($refund, $apiContext);
|
$captureRefund = $capture->refund($refund, $apiContext);
|
||||||
} catch (PayPal\Exception\PPConnectionException $ex) {
|
} catch (PayPal\Exception\PPConnectionException $ex) {
|
||||||
|
|||||||
Reference in New Issue
Block a user