|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Loevgaard\DandomainAltapayBundle\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Loevgaard\Dandomain\Pay\Helper\ChecksumHelper; |
|
6
|
|
|
use Loevgaard\Dandomain\Pay\Model\Payment; |
|
7
|
|
|
use Loevgaard\DandomainAltapayBundle\Entity\Terminal; |
|
8
|
|
|
use Loevgaard\DandomainAltapayBundle\Form\TestType; |
|
9
|
|
|
use Money\Currency; |
|
10
|
|
|
use Money\Money; |
|
11
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
|
12
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
13
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
14
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
15
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @Route("/test") |
|
19
|
|
|
*/ |
|
20
|
|
|
class TestController extends Controller |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @Method("GET") |
|
24
|
|
|
* @Route("", name="loevgaard_dandomain_altapay_test_index") |
|
25
|
|
|
* |
|
26
|
|
|
* @return Response |
|
27
|
|
|
*/ |
|
28
|
|
|
public function indexAction() |
|
29
|
|
|
{ |
|
30
|
|
|
/** @var Terminal[] $terminals */ |
|
31
|
|
|
$terminals = $this->get('loevgaard_dandomain_altapay.terminal_repository')->findAll(); |
|
32
|
|
|
|
|
33
|
|
|
$form = $this->createForm(TestType::class); |
|
34
|
|
|
|
|
35
|
|
|
return $this->render('@LoevgaardDandomainAltapay/test/index.html.twig', [ |
|
36
|
|
|
'form' => $form->createView(), |
|
37
|
|
|
'shared_key_1' => $this->getParameter('loevgaard_dandomain_altapay.shared_key_1'), |
|
38
|
|
|
'shared_key_2' => $this->getParameter('loevgaard_dandomain_altapay.shared_key_2'), |
|
39
|
|
|
'terminals' => $terminals, |
|
40
|
|
|
]); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @Method("GET") |
|
45
|
|
|
* @Route("/checksum1/{orderId}/{amount}/{sharedKey}/{currency}", name="loevgaard_dandomain_altapay_test_checksum_1") |
|
46
|
|
|
* |
|
47
|
|
|
* @param int $orderId |
|
48
|
|
|
* @param string $amount |
|
49
|
|
|
* @param string $sharedKey |
|
50
|
|
|
* @param int $currency |
|
51
|
|
|
* |
|
52
|
|
|
* @return JsonResponse |
|
53
|
|
|
*/ |
|
54
|
|
|
public function checksum1Action($orderId, $amount, $sharedKey, $currency) |
|
55
|
|
|
{ |
|
56
|
|
|
$amount = Payment::priceStringToInt($amount); |
|
57
|
|
|
$money = new Money($amount, new Currency($currency)); |
|
58
|
|
|
|
|
59
|
|
|
return new JsonResponse(ChecksumHelper::generateChecksum1((int) $orderId, $money, $sharedKey, (int) $currency)); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|