Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
srmklive committed Jan 6, 2017
1 parent f31748f commit 95e41e7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ Suppose you have set IPN URL to **http://example.com/ipn/notify/** in PayPal. To
'ipn/notify'
```

* Then in the controller where you are handling IPN, do the following:
* Then in the controller where you are handling IPN, write the following:

```
// Put this above controller definition
Expand All @@ -341,7 +341,7 @@ Suppose you have set IPN URL to **http://example.com/ipn/notify/** in PayPal. To
use PayPalIPN;
```

* The above step saves the PayPal IPN response as **ipn** in session. Following is the code you can change to your own requirements for handling IPN:
* Write the following code in the function where you will parse IPN response:

```php
/**
Expand All @@ -353,7 +353,9 @@ Suppose you have set IPN URL to **http://example.com/ipn/notify/** in PayPal. To
{
$response = $this->parsePayPalIPN($request);

// Parse IPN response accordingly to your requirements.
if ($response === 'VERIFIED') {
// Your code goes here ...
}
}
```

Expand Down
3 changes: 1 addition & 2 deletions src/Services/AdaptivePayments.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,8 @@ private function doPayPalRequest($method, $params)
]);

$response = $request->getBody(true);
$response = \GuzzleHttp\json_decode($response, true);

return $response;
return \GuzzleHttp\json_decode($response, true);
} catch (ClientException $e) {
throw new \Exception($e->getRequest().' '.$e->getResponse());
} catch (ServerException $e) {
Expand Down
14 changes: 4 additions & 10 deletions src/Traits/PayPalRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,8 @@ private function doPayPalRequest($method, $params)
]);

$response = $request->getBody(true);
$response = $this->retrieveData($response);

return $response;
return ($method == 'verifyipn') ? $response : $this->retrieveData($response);
} catch (ClientException $e) {
throw new \Exception($e->getRequest().' '.$e->getResponse());
} catch (ServerException $e) {
Expand All @@ -306,18 +305,13 @@ private function doPayPalRequest($method, $params)
/**
* Parse PayPal NVP Response.
*
* @param string|\GuzzleHttp\Psr7\Request $request
* @param string $request
* @param array $response
*
* @return array
*/
private function retrieveData($request)
private function retrieveData($request, array $response = null)
{
$response = [];

if ($request instanceof \GuzzleHttp\Psr7\Request) {
$request = \GuzzleHttp\Psr7\Str($request);
}

parse_str($request, $response);

return $response;
Expand Down

5 comments on commit 95e41e7

@dann95
Copy link

@dann95 dann95 commented on 95e41e7 Jan 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yo @srmklive im not the "best practices guy", but

\GuzzleHttp\json_decode($response, true);

is not used anymore, Guzzle in new versions do not support json decode in response

as you can see here:
https://github.com/guzzle/guzzle/blob/5.3/src/Message/Response.php#L138
https://github.com/guzzle/psr7/blob/master/src/Response.php

maybe its good refactor that, for any composer problem with old versions of guzzle =p

if u want i can help with it, but its just use the json_decode() from Php lib.

cya!

@srmklive
Copy link
Owner Author

@srmklive srmklive commented on 95e41e7 Jan 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dann95 json_encode is actually available in the latest versions ... https://github.com/guzzle/guzzle/blob/master/src/functions.php

@dann95
Copy link

@dann95 dann95 commented on 95e41e7 Jan 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@srmklive as a helper, not anymore as api. Before you just call like $res->json(); but now guzzle follows the PSR-7 interface, and is not responsability of the "client" decode information. Was just a comment.

cya 👍 😄

@srmklive
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dann95 I know that 😄. But if you can come up with a solution for it as per your original comment. That will be great 👍

@dann95
Copy link

@dann95 dann95 commented on 95e41e7 Jan 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @srmklive my friend! 😄 , i try alaways help this repo, you are alaways so polite 😄

Please sign in to comment.