function getRequestParameters()
 {
     $params = $this->getRawParameters();
     $params['requestFingerprint'] = Fingerprint::fromParameters($params)->setContext($this->getContext())->setFingerprintOrder(array_merge(['customerId', 'shopId', 'toolkitPassword', 'secret', 'command', 'language'], $this->fingerprintOrder));
     $this->assertParametersAreValid($params, array_merge(['customerId', 'requestFingerprint', 'toolkitPassword', 'language'], $this->requiredParameters));
     return $params;
 }
 /**
  * @test
  */
 function dispatchesConfirmPaymentEventAndRespondWithError()
 {
     $kernel = static::createKernel();
     $kernel->boot();
     $client = new Client($kernel);
     $listener = function (ConfirmPaymentEvent $event) {
         $this->assertTrue($event->isPaymentState(ConfirmPaymentEvent::FAILURE));
         $event->respondWithError('Failure', 1234);
     };
     $kernel->getContainer()->get('event_dispatcher')->addListener(ConfirmPaymentEvent::NAME, $listener);
     $fingerprintOrder = ['paymentState'];
     $responseParameters = ['paymentState' => ConfirmPaymentEvent::FAILURE, 'responseFingerprintOrder' => join(',', $fingerprintOrder)];
     $responseParameters['responseFingerprint'] = (string) Fingerprint::fromParameters($responseParameters)->setFingerprintOrder($fingerprintOrder)->setContext($kernel->getContainer()->get('hochstrasser_wirecard.context'));
     $client->request('POST', '/wirecard/confirm', $responseParameters);
     $this->assertEquals('{"status":"NOK","errorCodes":1234,"QPAY-CONFIRMATION-RESPONSE":{"result":"NOK","message":"Failure"}}', $client->getResponse()->getContent());
 }
 /**
  * Controller action for confirm requests sent "server-to-server" from Wirecard
  *
  * Handles verification of the responseFingerprint and triggers the ConfirmPaymentEvent.
  * Handle the event to decide wether the controller should respond to the confirmation
  * with a success or an error message.
  *
  * @param Request $request
  * @return Response
  */
 function confirmAction(Request $request)
 {
     if (!$request->isMethod('POST')) {
         return new Response("", Response::HTTP_METHOD_NOT_ALLOWED);
     }
     if (!$request->request->has('responseFingerprintOrder')) {
         return new Response("responseFingerprintOrder missing", Response::HTTP_BAD_REQUEST);
     }
     $fingerprint = Fingerprint::fromResponseParameters($request->request->all(), $this->context);
     $fingerprintIsValid = hash_equals((string) $fingerprint, $request->request->get('responseFingerprint'));
     if ($fingerprintIsValid === false) {
         return new Response("Fingerprint not valid", Response::HTTP_FORBIDDEN);
     }
     $event = new Event\ConfirmPaymentEvent($request->request->all());
     $this->eventDispatcher->dispatch(Event\ConfirmPaymentEvent::NAME, $event);
     if (!$event->isPropagationStopped() || $event->getState() === Event\ConfirmPaymentEvent::RESPOND_WITH_SUCCESS) {
         return new JsonResponse(['status' => 'OK', 'errorCodes' => null, 'QPAY-CONFIRMATION-RESPONSE' => ['result' => 'OK']]);
     }
     return new JsonResponse(['status' => 'NOK', 'errorCodes' => $event->getErrorCode(), 'QPAY-CONFIRMATION-RESPONSE' => ['result' => 'NOK', 'message' => $event->getErrorMessage()]]);
 }
Exemplo n.º 4
0
<?php

require __DIR__ . '/../../vendor/autoload.php';
use Hochstrasser\Wirecard\Fingerprint;
use Hochstrasser\Wirecard\Context;
$context = new Context(['customer_id' => 'D200001', 'secret' => 'B8AKTPWBRMNBV455FG6M2DANE99WU2', 'language' => 'de', 'shop_id' => 'qmore']);
$fingerprint = Fingerprint::fromResponseParameters($_POST, $context);
$fingerprintIsValid = hash_equals((string) $fingerprint, $_POST['responseFingerprint']);
if ($_POST) {
    ?>
<h3>Response Parameters</h3>
<pre><code><?php 
    var_dump($_POST);
    ?>
</code></pre>
<?php 
}
?>

<h3>Fingerprint</h3>

<p>
    Fingerprint is <?php 
echo $fingerprintIsValid ? '<strong style="color: green;">valid</strong>' : '<strong style="color: red;">invalid</strong>';
?>
</p>

<div>Expected:</div>
<div>
    <code><?php 
echo $fingerprint;
 function getRequestParameters()
 {
     $params = $this->getRawParameters();
     $requestFingerprintOrder = array_merge(array_keys($params), ['requestFingerprintOrder', 'secret']);
     $params['requestFingerprintOrder'] = join(',', $requestFingerprintOrder);
     $params['requestFingerprint'] = Fingerprint::fromParameters($params)->setContext($this->getContext())->setFingerprintOrder($requestFingerprintOrder);
     $this->assertParametersAreValid($params, array_merge(['customerId', 'requestFingerprint'], $this->requiredParameters));
     return $params;
 }