11<?php
2-
32namespace Fondy \Fondy \Controller \Url ;
43
54use Magento \Framework \App \Action \Action ;
65use Magento \Sales \Model \Order ;
6+ use Symfony \Component \Config \Definition \Exception \Exception ;
77
88class FondySuccess extends Action
99{
1010 /** @var \Magento\Framework\View\Result\PageFactory */
1111 protected $ resultPageFactory ;
12+ /**
13+ * @var \Magento\Framework\Controller\Result\JsonFactory
14+ */
15+ protected $ jsonResultFactory ;
1216
13-
17+ /**
18+ * FondySuccess constructor.
19+ * @param \Magento\Framework\App\Action\Context $context
20+ * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
21+ * @param \Magento\Framework\Controller\Result\JsonFactory $jsonResultFactory
22+ *
23+ */
1424 public function __construct (
1525 \Magento \Framework \App \Action \Context $ context ,
16- \Magento \Framework \View \Result \PageFactory $ resultPageFactory
17- )
18- {
26+ \Magento \Framework \View \Result \PageFactory $ resultPageFactory,
27+ \ Magento \ Framework \ Controller \ Result \ JsonFactory $ jsonResultFactory
28+ ) {
1929 $ this ->resultPageFactory = $ resultPageFactory ;
30+ $ this ->jsonResultFactory = $ jsonResultFactory ;
2031 parent ::__construct ($ context );
2132 }
2233
@@ -32,8 +43,8 @@ public function execute()
3243 $ data = $ this ->getRequest ()->getPostValue ();
3344 if (empty ($ data )) {
3445 $ callback = json_decode (file_get_contents ("php://input " ));
35- if (empty ($ callback ))
36- die ( );
46+ if (empty ($ callback ))
47+ throw new Exception ( __ ( ' Request Parameter is not matched. ' ) );
3748 $ data = array ();
3849 foreach ($ callback as $ key => $ val ) {
3950 $ data [$ key ] = $ val ;
@@ -44,7 +55,10 @@ public function execute()
4455 */
4556 $ model = 'Fondy\Fondy\Model\Fondy ' ;
4657 $ paymentMethod = $ this ->_objectManager ->create ($ model );
47- $ paymentMethod ->processResponse ($ data );
58+ $ response = $ paymentMethod ->processResponse ($ data );
59+ $ result = $ this ->jsonResultFactory ->create ();
60+ $ result ->setData (['Result ' => $ response ]);
61+ return $ result ;
4862 }
4963
5064}
0 commit comments