Skip to content

Commit

Permalink
Merge pull request #3 from baptiste-dulac/dev
Browse files Browse the repository at this point in the history
Version 0.2.0 : Payments handler
  • Loading branch information
baptiste-dulac committed Dec 1, 2014
2 parents 05280a5 + 1fdd8a3 commit 7c7e9d3
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 19 deletions.
18 changes: 9 additions & 9 deletions src/Tlconseil/SystempayBundle/Entity/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class Transaction
private $id;

/**
* @var int
* @ORM\Column(name="status_code", type="integer")
* @var string
* @ORM\Column(name="status_code", type="string", length=255, nullable=true)
*/
private $statusCode;
private $status;

/**
* @var int
Expand Down Expand Up @@ -181,19 +181,19 @@ public function setRefunded($refunded)
}

/**
* @return int
* @return string
*/
public function getStatusCode()
public function getStatus()
{
return $this->statusCode;
return $this->status;
}

/**
* @param int $statusCode
* @param string $status
*/
public function setStatusCode($statusCode)
public function setStatus($status)
{
$this->statusCode = $statusCode;
$this->status = $status;
}

/**
Expand Down
58 changes: 48 additions & 10 deletions src/Tlconseil/SystempayBundle/Service/SystemPay.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private function newTransaction($currency, $amount)
$transaction->setUpdatedAt(new \DateTime());
$transaction->setPaid(false);
$transaction->setRefunded(false);
$transaction->setStatusCode(-1);
$transaction->setStatus("");
$this->entityManager->persist($transaction);
$this->entityManager->flush();
return $transaction;
Expand Down Expand Up @@ -115,26 +115,59 @@ public function setOptionnalFields($fields)
return $this;
}


/**
* @return array
*/
public function getResponse()
{
$this->mandatoryFields['signature'] = $this->getSignature();
return $this->mandatoryFields;
}

/**
* @param Request $request
* @return bool
*/
public function responseHandler(Request $request)
{
file_put_contents(__DIR__.'/../Resources/test.txt', json_encode($request->request->all()));
$transactionId = $request->get('vads_trans_id');
$transaction = $this->entityManager->getRepository('TlconseilSystempayBundle:Transaction')->find($transactionId);
$transaction->setLogResponse(json_encode($request->request->all()));
$query = $request->request->all();

// Check signature
if (!empty($query['signature']))
{
$signature = $query['signature'];
unset ($query['signature']);
if ($signature == $this->getSignature($query))
{
$transaction = $this->entityManager->getRepository('TlconseilSystempayBundle:Transaction')->find($query['vads_trans_id']);
$transaction->setStatus($query['vads_trans_status']);
if ($query['vads_trans_status'] == "AUTHORISED")
$transaction->setPaid(true);
$transaction->setUpdatedAt(new \DateTime());
$transaction->setLogResponse(json_encode($query));
$this->entityManager->flush();
return true;
}
}
return false;
}

/**
* @return string
*/
public function getPaymentUrl()
{
return $this->paymentUrl;
}

/**
* @return Transaction
*/
public function getTransaction()
{
return $this->transaction;
}

/**
* @param array $fields
* @return array
Expand All @@ -147,12 +180,17 @@ private function setPrefixToFields(array $fields)
return $newTab;
}

private function getSignature()
/**
* @param null $fields
* @return string
*/
private function getSignature($fields = null)
{
$this->mandatoryFields = $this->setPrefixToFields($this->mandatoryFields);
ksort($this->mandatoryFields);
if (!$fields)
$fields = $this->mandatoryFields = $this->setPrefixToFields($this->mandatoryFields);
ksort($fields);
$contenu_signature = "";
foreach ($this->mandatoryFields as $field => $value)
foreach ($fields as $field => $value)
$contenu_signature .= $value."+";
$contenu_signature .= $this->key;
$signature = sha1($contenu_signature);
Expand Down

0 comments on commit 7c7e9d3

Please sign in to comment.