-
Notifications
You must be signed in to change notification settings - Fork 119
Adding Configurations
PayPal-PHP-SDK allows you to configure the SDKs to your need. There are many configurations available. In this step, we will add more configurations to our first.php
that we created when making the first call to PayPal using our SDK.
First, make a copy of first.php
and name it second.php
. You could alternatively copy the completed file here : second.php
-
Open
second.php
and locate the code that creates a new instance of $apiContext. ApiContext object is a context object that holds/relates to configurations that you want to pass to each request to PayPal SDK. Add the following code immediately after that.
// Step 2.1 : Between Step 2 and Step 3
$apiContext->setConfig(
array(
'log.LogEnabled' => true,
'log.FileName' => 'PayPal.log',
'log.LogLevel' => 'DEBUG'
)
);
```
2. Save and run php -f second.php
. This will execute the same code as we saw earlier, with similar output. So, what changed ? Go to your project directory, and you will notice a new file `PayPal.log` has been created. It should look something like this:
```log
[10-01-2015 10:35:52] PayPal\Core\PayPalHttpConnection: INFO: POST https://api.sandbox.paypal.com/v1/vault/credit-card [10-01-2015 10:35:52] PayPal\Core\PayPalHttpConnection: DEBUG: Content-Type: application/json [10-01-2015 10:35:52] PayPal\Core\PayPalHttpConnection: DEBUG: User-Agent: PayPalSDK/PayPal-PHP-SDK 0.16.1 (lang=PHP;v=5.5.14;bit=64;os=Darwin_14.0.0;machine=x86_64;openssl=0.9.8r;curl=7.28.1) [10-01-2015 10:35:52] PayPal\Core\PayPalHttpConnection: DEBUG: Authorization: Bearer xyz123123.... [10-01-2015 10:35:52] PayPal\Core\PayPalHttpConnection: DEBUG: PayPal-Request-Id: xxxxxxxxx [10-01-2015 10:35:52] PayPal\Core\PayPalHttpConnection: DEBUG: Payload : {"type":"visa","number":"4417119669820331","expire_month":"11","expire_year":"2019","cvv2":"012","first_name":"Joe","last_name":"Shopper"}
[10-01-2015 10:35:52] PayPal\Core\PayPalHttpConnection: DEBUG: Response : {"id":"CARD-11Y42351896982736KSYZWOA","state":"ok","type":"visa","number":"xxxxxxxxxxxx0331","expire_month":"11","expire_year":"2019","first_name":"Joe","last_name":"Shopper","valid_until":"2018-01-09T00:00:00Z","create_time":"2015-01-10T21:35:52Z","update_time":"2015-01-10T21:35:52Z","links":[{"href":"https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-11Y42351896982736KSYZWOA","rel":"self","method":"GET"},{"href":"https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-11Y42351896982736KSYZWOA","rel":"delete","method":"DELETE"},{"href":"https://api.sandbox.paypal.com/v1/vault/credit-card/CARD-11Y42351896982736KSYZWOA","rel":"patch","method":"PATCH"}]} ```
Basically, what we did was told SDK to enable
Logging, and write logs with DEBUG
to PayPal.log
. You can change those settings, and achieve desired result.
This is one of the configuration SDK provides. There are many other configurations that would be discussed later in the documentation.
- To reduce redundant code and minimize security risks, you could create a file
bootstrap.php
and move all your configuration settings there, and justinclude
bootstrap.php.
Getting Started
Using Our SDK
Configurations
Extras
External Links