Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

Adding Configurations

Jay edited this page Oct 24, 2017 · 7 revisions

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.

Instructions

First, make a copy of first.php and name it second.php. You could alternatively copy the completed file here : second.php

  1. 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'
      )
);
  1. 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:
[24-10-2017 17:47:52] PayPal\Core\PayPalHttpConnection : INFO: POST https://api.sandbox.paypal.com/v1/oauth2/token
[24-10-2017 17:47:52] PayPal\Core\PayPalHttpConnection : DEBUG: Request Headers 	: POST /v1/oauth2/token HTTP/1.1, Host: api.sandbox.paypal.com, User-Agent: PayPalSDK/PayPal-PHP-SDK 1.12.0 (platform-ver=7.0.22; bit=64; os=Darwin_16.7.0; machine=x86_64; crypto-lib-ver=1.0.2l; curl=7.54.0), Authorization: Basic QVlTcTNSREdzbUJMSkUtb3RUa0J0TS1qQlJkMVRDUXdGZjlSR2Z3ZGROWFd6MHVGVTl6dHlteWxPaFJTOkVHbkhEeERfcVJQZGFMZFp6OGlDcjhON19NekYtWUhQVGtqczZOS1lRdlFTQm5ncDRQVFRWV2tQWlJiTA==, Accept: */*, Content-Length: 29, Content-Type: application/x-www-form-urlencoded, , 
[24-10-2017 17:47:52] PayPal\Core\PayPalHttpConnection : DEBUG: Request Data		: grant_type=client_credentials
--------------------------------------------------------------------------------------------------------------------------------

[24-10-2017 17:47:52] PayPal\Core\PayPalHttpConnection : INFO: Response Status 	: 200
[24-10-2017 17:47:52] PayPal\Core\PayPalHttpConnection : DEBUG: Response Headers	: Date: Tue, 24 Oct 2017 17:47:52 GMT, Server: Apache, paypal-debug-id: 39dd1f7248818, X-PAYPAL-TOKEN-SERVICE: IAAS, HTTP_X_PP_AZ_LOCATOR: sandbox.slc, Paypal-Debug-Id: 39dd1f7248818, Set-Cookie: X-PP-SILOVER=; Expires=Thu, 01 Jan 1970 00:00:01 GMT, Vary: Authorization, Content-Length: 550, Connection: close, Content-Type: application/json, 
[24-10-2017 17:47:52] PayPal\Core\PayPalHttpConnection : DEBUG: Response Data 	: {"scope":"https://uri.paypal.com/services/subscriptions https://api.paypal.com/v1/payments/.* https://api.paypal.com/v1/vault/credit-card https://uri.paypal.com/services/applications/webhooks openid https://uri.paypal.com/payments/payouts https://api.paypal.com/v1/vault/credit-card/.*","nonce":"2017-10-24T17:00:27ZZyCIVYQCdEjZKPN1lHzryE-05SHM7jGHtSEqThCkYSA","access_token":"A21AAEKs0wWl-4pwrn1lSSAc52BnCIZDuG7wvDrfX4dRL3qbwg7IFh-fAJgJtekFMrx6sEBtD6Kefv_6Gh4hMUm0x5gcIyKwg","token_type":"Bearer","app_id":"APP-80W284485P519543T","expires_in":29555}

================================================================================================================================

[24-10-2017 17:47:52] PayPal\Core\PayPalHttpConnection : INFO: POST https://api.sandbox.paypal.com/v1/payments/payment
[24-10-2017 17:47:52] PayPal\Core\PayPalHttpConnection : DEBUG: Request Headers 	: POST /v1/payments/payment HTTP/1.1, Host: api.sandbox.paypal.com, Accept: */*, Content-Type: application/json, User-Agent: PayPalSDK/PayPal-PHP-SDK 1.12.0 (platform-ver=7.0.22; bit=64; os=Darwin_16.7.0; machine=x86_64; crypto-lib-ver=1.0.2l; curl=7.54.0), Authorization: Bearer A21AAEKs0wWl-4pwrn1lSSAc52BnCIZDuG7wvDrfX4dRL3qbwg7IFh-fAJgJtekFMrx6sEBtD6Kefv_6Gh4hMUm0x5gcIyKwg, Content-Length: 247, , 
[24-10-2017 17:47:52] PayPal\Core\PayPalHttpConnection : DEBUG: Request Data		: {"intent":"sale","payer":{"payment_method":"paypal"},"transactions":[{"amount":{"total":"1.00","currency":"USD"}}],"redirect_urls":{"return_url":"https://example.com/your_redirect_url.html","cancel_url":"https://example.com/your_cancel_url.html"}}
--------------------------------------------------------------------------------------------------------------------------------

[24-10-2017 17:47:52] PayPal\Core\PayPalHttpConnection : INFO: Response Status 	: 201
[24-10-2017 17:47:52] PayPal\Core\PayPalHttpConnection : DEBUG: Response Headers	: Date: Tue, 24 Oct 2017 17:47:52 GMT, Server: Apache, paypal-debug-id: 79ab55c07c2dd, Content-Language: *, HTTP_X_PP_AZ_LOCATOR: sandbox.slc, Paypal-Debug-Id: 79ab55c07c2dd, Set-Cookie: X-PP-SILOVER=; Expires=Thu, 01 Jan 1970 00:00:01 GMT, Vary: Authorization, Content-Length: 636, Connection: close, Content-Type: application/json, 
[24-10-2017 17:47:52] PayPal\Core\PayPalHttpConnection : DEBUG: Response Data 	: {"id":"PAY-2784030382179343ELHXXZSA","intent":"sale","state":"created","payer":{"payment_method":"paypal"},"transactions":[{"amount":{"total":"1.00","currency":"USD"},"related_resources":[]}],"create_time":"2017-10-24T17:47:52Z","links":[{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-2784030382179343ELHXXZSA","rel":"self","method":"GET"},{"href":"https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-7CC99266AW953164X","rel":"approval_url","method":"REDIRECT"},{"href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-2784030382179343ELHXXZSA/execute","rel":"execute","method":"POST"}]}

================================================================================================================================

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.

NOTE
  • To reduce redundant code and minimize security risks, you could create a file bootstrap.php and move all your configuration settings there, and just include bootstrap.php.

Next Step