Created TLS Check Sample

- Created Sample to test TLSv1.2 support
- Updated Documentation
- Updated README
This commit is contained in:
Jay Patel
2015-11-13 16:54:19 -06:00
parent 89bc07aa1e
commit 8149b098c4
7 changed files with 277 additions and 2938 deletions

View File

@@ -9,6 +9,11 @@ __Welcome to PayPal PHP SDK__. This repository contains PayPal's PHP SDK and sam
> **Before starting to use the sdk, please be aware of the [existing issues and currently unavailable or upcoming features](https://github.com/paypal/rest-api-sdk-python/wiki/Existing-Issues-and-Unavailable%5CUpcoming-features) for the REST APIs. (which the sdks are based on)**
## Please Note
> **The [PCIv3.1 DSS (PDF)](https://www.pcisecuritystandards.org/documents/PCI_DSS_v3-1.pdf) mandates (p.46) that TLSv1.0 be retired from service by June 30, 2016. All organizations that handle credit card information are required to comply with this standard. As part of this obligation, PayPal is updating it's services to require TLSv1.2 for all HTTPS connections. [Click here](https://github.paypal.com/SDK-R/tls-update) for more information**
> **If you have the SDK v1.6.2 or higher installed, you can easily test this by running the TLSCheck sample.**
## SDK Documentation
[ Our PayPal-PHP-SDK Page ](http://paypal.github.io/PayPal-PHP-SDK/) includes all the documentation related to PHP SDK. Everything from SDK Wiki, to Sample Codes, to Releases. Here are few quick links to get you there faster.

View File

@@ -12,7 +12,7 @@ class PayPalConstants
{
const SDK_NAME = 'PayPal-PHP-SDK';
const SDK_VERSION = '1.6.1';
const SDK_VERSION = '1.6.2';
/**
* Approval URL for Payment

View File

@@ -1,6 +1,11 @@
PayPal PHP SDK release notes
============================
v1.6.2
----
* TLS Check Sample Added
* Updated README
v1.6.1
----
* User Agent Changes

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,48 @@
<!DOCTYPE html><html lang="en"><head><title>tls/TlsCheck</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content="../"><meta name="groc-document-path" content="tls/TlsCheck"><meta name="groc-project-path" content="tls/TlsCheck.php"><link rel="stylesheet" type="text/css" media="all" href="../assets/style.css"><script type="text/javascript" src="../assets/behavior.js"></script><body><div id="meta"><div class="file-path">tls/TlsCheck.php</div></div><div id="document"><div class="segment"><div class="code"><div class="wrapper"><span class="hljs-preprocessor">&lt;?php</span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h1 id="create-payment-using-paypal-as-payment-method">Create Payment using PayPal as payment method</h1>
<p>This sample code demonstrates how you can process a
PayPal Account based Payment.
API used: /v1/payments/payment</p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">require</span> <span class="hljs-keyword">__DIR__</span> . <span class="hljs-string">'/../bootstrap.php'</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Amount</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Details</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Item</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">ItemList</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Payer</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Payment</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">RedirectUrls</span>;
<span class="hljs-keyword">use</span> <span class="hljs-title">PayPal</span>\<span class="hljs-title">Api</span>\<span class="hljs-title">Transaction</span>;</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h2 id="tls-check">TLS Check</h2>
<p>We will add a separate unique endpoint specifically set for testing TLS check instead of using
our conventional sandbox endpoint.
TLS ENDPOINT: <a href="https://test-api.sandbox.paypal.com">https://test-api.sandbox.paypal.com</a>
To test your own implementation to verify it TLS is successfully supported in your application, you can follow
the following steps.</p>
<ol>
<li>Create an APIContext object as usual. (No Change Required).</li>
<li>Add Configs as shown below to your apiContext object</li>
</ol></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$apiContext</span>-&gt;setConfig(<span class="hljs-keyword">array</span>(<span class="hljs-string">'service.EndPoint'</span>=&gt;<span class="hljs-string">"https://test-api.sandbox.paypal.com"</span>));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><ol>
<li>Thats it. Run your code, and see if it works as normal.</li>
<li>You can check sdk logs to verify it is infact pointing to the above URL instead of default sandbox one.</li>
</ol></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="create-a-payment-for-testing">Create a Payment for testing</h3>
<p>We will create a conventional paypal payment to verify its creation</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$payer</span> = <span class="hljs-keyword">new</span> Payer();
<span class="hljs-variable">$payer</span>-&gt;setPaymentMethod(<span class="hljs-string">"paypal"</span>);
<span class="hljs-variable">$amount</span> = <span class="hljs-keyword">new</span> Amount();
<span class="hljs-variable">$amount</span>-&gt;setCurrency(<span class="hljs-string">"USD"</span>)
-&gt;setTotal(<span class="hljs-number">20</span>);
<span class="hljs-variable">$transaction</span> = <span class="hljs-keyword">new</span> Transaction();
<span class="hljs-variable">$transaction</span>-&gt;setAmount(<span class="hljs-variable">$amount</span>);
<span class="hljs-variable">$baseUrl</span> = getBaseUrl();
<span class="hljs-variable">$redirectUrls</span> = <span class="hljs-keyword">new</span> RedirectUrls();
<span class="hljs-variable">$redirectUrls</span>-&gt;setReturnUrl(<span class="hljs-string">"$baseUrl/ExecutePayment.php?success=true"</span>)
-&gt;setCancelUrl(<span class="hljs-string">"$baseUrl/ExecutePayment.php?success=false"</span>);
<span class="hljs-variable">$payment</span> = <span class="hljs-keyword">new</span> Payment();
<span class="hljs-variable">$payment</span>-&gt;setIntent(<span class="hljs-string">"sale"</span>)
-&gt;setPayer(<span class="hljs-variable">$payer</span>)
-&gt;setRedirectUrls(<span class="hljs-variable">$redirectUrls</span>)
-&gt;setTransactions(<span class="hljs-keyword">array</span>(<span class="hljs-variable">$transaction</span>));</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>For Sample Purposes Only.</p></div></div><div class="code"><div class="wrapper"><span class="hljs-variable">$request</span> = <span class="hljs-keyword">clone</span> <span class="hljs-variable">$payment</span>;
<span class="hljs-variable">$curl_info</span> = curl_version();
<span class="hljs-keyword">try</span> {
<span class="hljs-variable">$payment</span>-&gt;create(<span class="hljs-variable">$apiContext</span>);
} <span class="hljs-keyword">catch</span> (<span class="hljs-keyword">Exception</span> <span class="hljs-variable">$ex</span>) {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY</p></div></div><div class="code"><div class="wrapper"> ResultPrinter::printError(<span class="hljs-string">"FAILURE: SECURITY WARNING: TLSv1.2 is not supported on this system. Please upgrade your curl/openssl to enable TLSv1.2. &lt;br /&gt; - Your Current SSL Version is : "</span> . <span class="hljs-variable">$curl_info</span>[<span class="hljs-string">'ssl_version'</span>], <span class="hljs-string">"Payment"</span>, <span class="hljs-keyword">null</span>, <span class="hljs-variable">$request</span>, <span class="hljs-variable">$ex</span>);
<span class="hljs-keyword">exit</span>(<span class="hljs-number">1</span>);
}</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY</p></div></div><div class="code"><div class="wrapper">ResultPrinter::printResult(<span class="hljs-string">"&lt;b&gt;SUCCESS&lt;/b&gt;: Your server supports TLS protocols required for secure connection to PayPal Servers. &lt;br /&gt; - Your Current SSL Version is : "</span> . <span class="hljs-variable">$curl_info</span>[<span class="hljs-string">'ssl_version'</span>], <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>, <span class="hljs-keyword">null</span>, <span class="hljs-string">"SUCCESS. Your system supports TLSv1.2"</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable">$payment</span>;</div></div></div></div></body></html>

View File

@@ -231,6 +231,30 @@ if (PHP_SAPI == 'cli') {
</div>
</div>
<div class="col-md-9 samples">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 id="tls" class="panel-title"><a
href="https://developer.paypal.com/webapps/developer/docs/api/#payments"
target="_blank">TLS CHECK</a></h3>
</div>
<!-- List group -->
<ul class="list-group">
<li class="list-group-item">
<div class="row">
<div class="col-md-8"><h5>Check if your system supports TLSv1.2<h5></div>
<div class="col-md-4">
<a href="tls/TlsCheck.php" class="btn btn-primary pull-left execute"> Try It <i
class="fa fa-play-circle-o"></i></a>
<a href="doc/tls/TlsCheck.html" class="btn btn-default pull-right">Source <i
class="fa fa-file-code-o"></i></a>
<a href="https://github.paypal.com/SDK-R/tls-update/blob/master/readme.md" class="btn btn-default pull-right">Read More <i
class="fa fa-exclamation"></i></a>
</div>
</div>
</li>
</ul>
</div>
<div class="panel panel-primary">
<div class="panel-heading">
<h3 id="payments" class="panel-title"><a

65
sample/tls/TlsCheck.php Normal file
View File

@@ -0,0 +1,65 @@
<?php
// # Create Payment using PayPal as payment method
// This sample code demonstrates how you can process a
// PayPal Account based Payment.
// API used: /v1/payments/payment
require __DIR__ . '/../bootstrap.php';
use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Transaction;
// ## TLS Check
// We will add a separate unique endpoint specifically set for testing TLS check instead of using
// our conventional sandbox endpoint.
// TLS ENDPOINT: https://test-api.sandbox.paypal.com
// To test your own implementation to verify it TLS is successfully supported in your application, you can follow
// the following steps.
// 1. Create an APIContext object as usual. (No Change Required).
// 2. Add Configs as shown below to your apiContext object
$apiContext->setConfig(array('service.EndPoint'=>"https://test-api.sandbox.paypal.com"));
// 3. Thats it. Run your code, and see if it works as normal.
// 4. You can check sdk logs to verify it is infact pointing to the above URL instead of default sandbox one.
// ### Create a Payment for testing
// We will create a conventional paypal payment to verify its creation
$payer = new Payer();
$payer->setPaymentMethod("paypal");
$amount = new Amount();
$amount->setCurrency("USD")
->setTotal(20);
$transaction = new Transaction();
$transaction->setAmount($amount);
$baseUrl = getBaseUrl();
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("$baseUrl/ExecutePayment.php?success=true")
->setCancelUrl("$baseUrl/ExecutePayment.php?success=false");
$payment = new Payment();
$payment->setIntent("sale")
->setPayer($payer)
->setRedirectUrls($redirectUrls)
->setTransactions(array($transaction));
// For Sample Purposes Only.
$request = clone $payment;
$curl_info = curl_version();
try {
$payment->create($apiContext);
} catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printError("FAILURE: SECURITY WARNING: TLSv1.2 is not supported on this system. Please upgrade your curl to atleast 7.34.0.<br /> - Current Curl Version: " . $curl_info['version'] . "<br /> - Current OpenSSL Version:" . $curl_info['ssl_version'], "Payment", null, $request, $ex);
exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("<b>SUCCESS</b>: Your server supports TLS protocols required for secure connection to PayPal Servers. <br /> - Current Curl Version: " . $curl_info['version'] . "<br /> - Current OpenSSL Version:" . $curl_info['ssl_version'], null, null, null, "SUCCESS. Your system supports TLSv1.2");
return $payment;