From a3e0e8b1d1d3b519f274becb63cebea53468b440 Mon Sep 17 00:00:00 2001
From: aydiv
Date: Mon, 26 Aug 2013 13:01:39 +0530
Subject: [PATCH 1/3] Updating samples to use dynamic SDK configuration
---
sample/bootstrap.php | 61 +++++++++++++++++++++++++------------------
sample/sdk_config.ini | 13 ++++++---
2 files changed, 46 insertions(+), 28 deletions(-)
diff --git a/sample/bootstrap.php b/sample/bootstrap.php
index eb9fed9..f73e2a6 100644
--- a/sample/bootstrap.php
+++ b/sample/bootstrap.php
@@ -1,40 +1,51 @@
setConfig(array(
- 'mode' => 'sandbox',
- 'http.ConnectionTimeOut' => 30,
- 'log.LogEnabled' => true,
- 'log.FileName' => '../PayPal.log',
- 'log.LogLevel' => 'FINE'
-));
-*/
-
+
+// ### Api context
+// Pass in a `PayPal\Rest\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(
+ 'EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM',
+ 'EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM'
+ )
+);
+
+
+
+// #### SDK configuration
+// Comment this line out and uncomment the PP_CONFIG_PATH
+// 'define' if you want to use a static file based configuration
+
+$apiContext->setConfig(
+ array(
+ 'mode' => 'sandbox',
+ '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.
+// define("PP_CONFIG_PATH", __DIR__);
diff --git a/sample/sdk_config.ini b/sample/sdk_config.ini
index 4906f19..22de6fb 100644
--- a/sample/sdk_config.ini
+++ b/sample/sdk_config.ini
@@ -1,9 +1,16 @@
+
+
+## This is an example configuration file for the SDK.
+## The sample scripts configure the SDK dynamically
+## but you can choose to go for file based configuration
+## in simpler apps (See bootstrap.php for more).
+
+
;Connection Information
[Http]
http.ConnectionTimeOut = 30
http.Retry = 1
-;http.Proxy=http://[username:password]@hostname[:port][/path]
-
+;http.Proxy=http://[username:password]@hostname[:port]
;Service Configuration
[Service]
@@ -23,4 +30,4 @@ log.FileName=../PayPal.log
# Logging level can be one of FINE, INFO, WARN or ERROR
# Logging is most verbose in the 'FINE' level and
# decreases as you proceed towards ERROR
-log.LogLevel=FINE
\ No newline at end of file
+log.LogLevel=FINE
From 9dd6cd07bc66cac66d5b59fea7833bd1f0201fd5 Mon Sep 17 00:00:00 2001
From: aydiv
Date: Mon, 26 Aug 2013 14:20:25 +0530
Subject: [PATCH 2/3] Moving apiContext creation to a function
---
sample/bootstrap.php | 71 ++++++++++++++++++++-----------
sample/payments/RefundCapture.php | 2 +-
2 files changed, 46 insertions(+), 27 deletions(-)
diff --git a/sample/bootstrap.php b/sample/bootstrap.php
index f73e2a6..4d37165 100644
--- a/sample/bootstrap.php
+++ b/sample/bootstrap.php
@@ -13,39 +13,58 @@ if(!file_exists(__DIR__ .'/vendor/autoload.php')) {
require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/common.php';
+
use PayPal\Rest\ApiContext;
use PayPal\Auth\OAuthTokenCredential;
+$apiContext = getApiContext();
-// ### Api context
-// Pass in a `PayPal\Rest\ApiContext` object to authenticate
-// API calls. The clientId and clientSecret for the
-// OAuthTokenCredential class can be retrieved from
-// developer.paypal.com
+/**
+ * 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
-$apiContext = new ApiContext(
- new OAuthTokenCredential(
- 'EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM',
- 'EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM'
- )
-);
+ $apiContext = new ApiContext(
+ new OAuthTokenCredential(
+ 'EBWKjlELKMYqRNQ6sYvFo64FtaRLRR5BdHEESmha49TM',
+ 'EO422dn3gQLgDbuwqTjzrFgFtaRLRR5BdHEESmha49TM'
+ )
+ );
-// #### SDK configuration
-// Comment this line out and uncomment the PP_CONFIG_PATH
-// 'define' if you want to use a static file based configuration
+ // #### 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' => 'sandbox',
- '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.
-// define("PP_CONFIG_PATH", __DIR__);
+ $apiContext->setConfig(
+ array(
+ 'mode' => 'sandbox',
+ '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;
+}
diff --git a/sample/payments/RefundCapture.php b/sample/payments/RefundCapture.php
index 7c234a3..55a9be8 100644
--- a/sample/payments/RefundCapture.php
+++ b/sample/payments/RefundCapture.php
@@ -48,7 +48,7 @@ $refund->setAmount($amt);
try {
// Create a new apiContext object so we send a new
// PayPal-Request-Id (idempotency) header for this resource
- $apiContext = new ApiContext($apiContext->getCredential());
+ $apiContext = getApiContext();
$captureRefund = $capture->refund($refund, $apiContext);
} catch (PayPal\Exception\PPConnectionException $ex) {
From e927298a40358ea73030504df16d8b99486c09a5 Mon Sep 17 00:00:00 2001
From: aydiv
Date: Mon, 26 Aug 2013 14:21:28 +0530
Subject: [PATCH 3/3] Minor text changes in sample code comments
---
sample/payments/CreatePayment.php | 4 ++--
sample/source/CreatePayment.html | 6 +++---
sample/source/DeleteCreditCard.html | 4 ++--
sample/vault/DeleteCreditCard.php | 2 +-
4 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/sample/payments/CreatePayment.php b/sample/payments/CreatePayment.php
index ccbfa76..5c17c7e 100644
--- a/sample/payments/CreatePayment.php
+++ b/sample/payments/CreatePayment.php
@@ -81,8 +81,8 @@ $payment->setIntent("sale")
->setTransactions(array($transaction));
// ### Create Payment
-// Create a payment by posting to the APIService
-// using a valid ApiContext (See bootstrap.php for more on `ApiContext`)
+// Create a payment by calling the payment->create() method
+// with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
// The return object contains the state.
try {
$payment->create($apiContext);
diff --git a/sample/source/CreatePayment.html b/sample/source/CreatePayment.html
index e3f1073..e1c57d2 100644
--- a/sample/source/CreatePayment.html
+++ b/sample/source/CreatePayment.html
@@ -60,8 +60,8 @@ the above types and intent set to sale 'sale'
<
->setPayer($payer)
->setTransactions(array($transaction));
try {
$payment->create($apiContext);
} catch (PayPal\Exception\PPConnectionException $ex) {
@@ -82,4 +82,4 @@ The return object contains the state.
<pre><?php var_dump($payment->toArray());?></pre>
<a href='../index.html'>Back</a>
</body>
-</html>
Create Payment
-Create a payment by posting to the APIService -using a valid ApiContext (See bootstrap.php for more on
ApiContext) +Create a payment by calling the payment->create() method +with a valid ApiContext (See bootstrap.php for more on
ApiContext) The return object contains the state.