Fix cancel front payment.
[openemr.git] / interface / product_registration / product_registration_controller.php
blob11beb09f5fea84bf425b00f05813713aa7b7705f
1 <?php
2 /**
3 * ProductRegistrationController
5 * LICENSE: This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
16 * @package OpenEMR
17 * @author Matthew Vita <matthewvita48@gmail.com>
18 * @link http://www.open-emr.org
23 $ignoreAuth=true;
24 require_once("../globals.php");
25 require_once($GLOBALS['fileroot'] . "/interface/main/exceptions/invalid_email_exception.php");
26 require_once($GLOBALS['fileroot'] . "/interface/product_registration/exceptions/generic_product_registration_exception.php");
27 require_once($GLOBALS['fileroot'] . "/interface/product_registration/exceptions/duplicate_registration_exception.php");
29 use OpenEMR\Common\Http\HttpResponseHelper;
30 use OpenEMR\Entities\ProductRegistration;
31 use OpenEMR\Services\ProductRegistrationService;
33 class ProductRegistrationController
35 private $productRegistrationService;
37 public function __construct()
39 $this->productRegistrationService = new ProductRegistrationService();
41 // (note this is here until we use Zend Framework)
42 switch ($_SERVER['REQUEST_METHOD']) {
43 case 'POST':
44 $this->post();
45 break;
46 case 'GET':
47 $this->get();
48 break;
52 public function get()
54 $statusPayload = $this->productRegistrationService->getProductStatus();
56 HttpResponseHelper::send(200, $statusPayload, 'JSON');
59 public function post()
61 $response = null;
62 $status = 500;
64 try {
65 $response = new ProductRegistration();
66 $registrationId = $this->productRegistrationService->registerProduct($_POST['email']);
67 $response->setRegistrationId($registrationId);
68 $response->setEmail($_POST['email']);
69 $status = 201;
70 } catch (InvalidEmailException $emailException) {
71 $response = $emailException->errorMessage();
72 } catch (DuplicateRegistrationException $duplicateRegistrationException) {
73 $response = $duplicateRegistrationException->errorMessage();
74 } catch (GenericProductRegistrationException $genericProductRegistrationException) {
75 $response = $genericProductRegistrationException->errorMessage();
78 HttpResponseHelper::send($status, $response, 'JSON');
82 // Initialize self (note this is here until we use Zend Framework)
83 $productRegistrationController = new ProductRegistrationController();