Skip to content

Commit

Permalink
Formatting fixes + camelcase variables
Browse files Browse the repository at this point in the history
  • Loading branch information
overint committed Jun 27, 2018
1 parent 0b724ca commit 635af4c
Showing 1 changed file with 24 additions and 43 deletions.
67 changes: 24 additions & 43 deletions src/PaypalIPN.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
<?php
<?php

namespace overint;

use \Exception
use \Exception;

class PaypalIPN
{

/**
* @var bool $use_sandbox Indicates if the sandbox endpoint is used.
*/
private $use_sandbox = false;
/**
* @var bool $use_local_certs Indicates if the local certificates are used.
*/
private $use_local_certs = true;
/** @var bool $useSandbox Indicates if the sandbox endpoint is used. */
private $useSandbox = false;
/** @var bool $useLocalCerts Indicates if the local certificates are used. */
private $useLocalCerts = true;

/** Production Postback URL */
const VERIFY_URI = 'https://ipnpb.paypal.com/cgi-bin/webscr';
Expand All @@ -35,7 +30,7 @@ class PaypalIPN
*/
public function useSandbox()
{
$this->use_sandbox = true;
$this->useSandbox = true;
}

/**
Expand All @@ -45,7 +40,7 @@ public function useSandbox()
*/
public function usePHPCerts()
{
$this->use_local_certs = false;
$this->useLocalCerts = false;
}


Expand All @@ -55,7 +50,7 @@ public function usePHPCerts()
*/
public function getPaypalUri()
{
if ($this->use_sandbox) {
if ($this->useSandbox) {
return self::SANDBOX_VERIFY_URI;
} else {
return self::VERIFY_URI;
Expand All @@ -72,23 +67,18 @@ public function getPaypalUri()
*/
function verifyIPN()
{
if ( ! count($_POST))
{
if (!count($_POST)) {
throw new Exception("Missing POST Data");
}

$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$myPost = [];
foreach ($raw_post_array as $keyval)
{
foreach ($raw_post_array as $keyval) {
$keyval = explode('=', $keyval);
if (count($keyval) == 2)
{
if ($keyval[0] === 'payment_date')
{
if (substr_count($keyval[1], '+') === 1)
{
if (count($keyval) == 2) {
if ($keyval[0] === 'payment_date') {
if (substr_count($keyval[1], '+') === 1) {
$keyval[1] = str_replace('+', '%2B', $keyval[1]);
}
}
Expand All @@ -97,17 +87,13 @@ function verifyIPN()
}
$req = 'cmd=_notify-validate';
$get_magic_quotes_exists = false;
if (function_exists('get_magic_quotes_gpc'))
{
if (function_exists('get_magic_quotes_gpc')) {
$get_magic_quotes_exists = true;
}
foreach ($myPost as $key => $value)
{
if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1)
{
foreach ($myPost as $key => $value) {
if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
$value = urlencode(stripslashes($value));
} else
{
} else {
$value = urlencode($value);
}
$req .= "&$key=$value";
Expand All @@ -121,35 +107,30 @@ function verifyIPN()
curl_setopt($ch, CURLOPT_SSLVERSION, 6);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
if ($this->use_local_certs)
{
if ($this->useLocalCerts) {
curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . "/cert/cacert.pem");
}
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Connection: Close' ]);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Connection: Close']);
$res = curl_exec($ch);
$info = curl_getinfo($ch);
$http_code = $info['http_code'];

if ($http_code != 200)
{
if ($http_code != 200) {
throw new Exception("PayPal responded with http code $http_code");
}

if ( ! ( $res ))
{
if (!($res)) {
$errno = curl_errno($ch);
$errstr = curl_error($ch);
curl_close($ch);
throw new Exception("cURL error: [$errno] $errstr");
}
curl_close($ch);
if ($res == self::VALID)
{
if ($res == self::VALID) {
return true;
} else
{
} else {
return false;
}
}
Expand Down

0 comments on commit 635af4c

Please sign in to comment.