Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
19 / 19 |
| NotificationProcess | |
100.00% |
1 / 1 |
|
100.00% |
3 / 3 |
5 | |
100.00% |
19 / 19 |
| __construct( SerializerInterface $serializer, SignatureValidatorInterface $signatureValidator ) | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
| process( CredentialsInterface $credentials, $data, $signatureHeader = null ) | |
100.00% |
1 / 1 |
2 | |
100.00% |
5 / 5 |
|||
| validateSignature( CredentialsInterface $credentials, $data, $signatureHeader ) | |
100.00% |
1 / 1 |
2 | |
100.00% |
11 / 11 |
|||
| <?php | |
| /** | |
| * @author Krzysztof Gzocha <krzysztof.gzocha@xsolve.pl> | |
| */ | |
| namespace Team3\PayU\Communication\Process\NotificationProcess; | |
| use Team3\PayU\Communication\Notification\OrderNotification; | |
| use Team3\PayU\Configuration\Credentials\CredentialsInterface; | |
| use Team3\PayU\Serializer\SerializerInterface; | |
| use Team3\PayU\SignatureCalculator\Validator\SignatureValidatorInterface; | |
| /** | |
| * This class will help in notification's receiving process. | |
| * | |
| * Class NotificationProcess | |
| * @package Team3\PayU\Communication\Process\NotificationProcess | |
| */ | |
| class NotificationProcess | |
| { | |
| const ORDER_NOTIFICATION_CLASS = 'Team3\PayU\Communication\Notification\OrderNotification'; | |
| /** | |
| * @var SerializerInterface | |
| */ | |
| private $serializer; | |
| /** | |
| * @var SignatureValidatorInterface | |
| */ | |
| private $signatureValidator; | |
| /** | |
| * @param SerializerInterface $serializer | |
| * @param SignatureValidatorInterface $signatureValidator | |
| */ | |
| public function __construct( | |
| SerializerInterface $serializer, | |
| SignatureValidatorInterface $signatureValidator | |
| ) { | |
| $this->serializer = $serializer; | |
| $this->signatureValidator = $signatureValidator; | |
| } | |
| /** | |
| * @param CredentialsInterface $credentials | |
| * @param string $data | |
| * @param string|null $signatureHeader Signature can be null when notifyUrl starts with https | |
| * | |
| * @return OrderNotification | |
| */ | |
| public function process( | |
| CredentialsInterface $credentials, | |
| $data, | |
| $signatureHeader = null | |
| ) { | |
| if (null !== $signatureHeader) { | |
| $this->validateSignature($credentials, $data, $signatureHeader); | |
| } | |
| return $this | |
| ->serializer | |
| ->fromJson($data, self::ORDER_NOTIFICATION_CLASS); | |
| } | |
| /** | |
| * @param CredentialsInterface $credentials | |
| * @param string $data | |
| * @param string $signatureHeader | |
| * | |
| * @throws NotificationProcessException | |
| */ | |
| private function validateSignature( | |
| CredentialsInterface $credentials, | |
| $data, | |
| $signatureHeader | |
| ) { | |
| $isSignatureValid = $this | |
| ->signatureValidator | |
| ->isSignatureValid( | |
| $data, | |
| $signatureHeader, | |
| $credentials | |
| ); | |
| if (!$isSignatureValid) { | |
| throw new NotificationProcessException(sprintf( | |
| 'Signature header "%s" for data "%s" is not correct.', | |
| $signatureHeader, | |
| $data | |
| )); | |
| } | |
| } | |
| } |