diff --git a/application/controllers/EnrollmentForm.php b/application/controllers/EnrollmentForm.php index 1c9b89a..a500dae 100644 --- a/application/controllers/EnrollmentForm.php +++ b/application/controllers/EnrollmentForm.php @@ -166,6 +166,55 @@ public function makeStripePayment() $this->load->view('stripe.php', $data); } + /** + * When the Polipay payment method is selected. + */ + public function makePoliPayment() + { + log_message('debug', "-- makePoliPayment function called"); + $this->load->model('GoogleSheets_Model'); + $this->load->model('Verification_Model'); + + // Receive data from form, method=POST + $data['email'] = $this->input->post('email'); + [$data['name'], $data['upi']] = $this->Verification_Model->getMemberInfo($data["email"]); + + // Stopping direct access to this method + if (!isset($data['name']) || !isset($data['email'])) { + show_error("Sorry, this page you are requesting is either not found or you don't have permission to access this page. Error Code:001", + "404"); + } + + if (CHECK_MEMBERSHIP_PAYMENT) { + $paid_member = ($this->Verification_Model->hasUserPaidMembership($data['email'])); + if (!$paid_member) { + show_error("Something went wrong, your email was not found in the ASPA member list or haven't paid. Error Code: 002", "500"); + } + } + + // Only record if the email is not found + if (!($this->Verification_Model->isEmailOnSheet($data['email'], REGISTRATION_SPREADSHEET_ID, $this->eventData['gsheet_name']))) { + $this->GoogleSheets_Model->addNewRecord($data['email'], $data['name'], $data['upi'], 'Polipay'); + } else { + // Email is found, so find the cell + // Then edit the "How would you like your payment" to be of Stripe payment + // Get the row of the specific email from google sheets + $cell = $this->GoogleSheets_Model->getCellCoordinate($data['email'], 'B'); + if (!isset($cell)) { + show_error("Something went wrong, your email was not found in the ASPA member list.Error Code: 002", "500"); + } + + // Split up the cell column and row + list(, $row) = $this->GoogleSheets_Model->convertCoordinateToArray($cell); + // Edit Payment method column (Column F) + $this->GoogleSheets_Model->updatePaymentMethod($row, 'Polipay'); + } + + $this->load->model('Polipay_Model'); + + $this->Polipay_Model->makePolipayPayment($data['email'], $this->eventData); + } + /** * When an "offline" payment method (i.e. cash and bank transfer) was selected. */ diff --git a/application/models/Polipay_Model.php b/application/models/Polipay_Model.php new file mode 100644 index 0000000..73ee49e --- /dev/null +++ b/application/models/Polipay_Model.php @@ -0,0 +1,53 @@ +request('POST', 'https://poliapi.apac.paywithpoli.com/api/v2/Transaction/Initiate', [ + 'Amount' => (float) $eventData["price"] * 100, + 'CurrencyCode' => 'NZD', + 'MerchantReference' => $customer_email, //probably use customer_email + 'MerchantData' => '', + 'MerchantHomepageURL' => 'aspa.wdcc.co.nz', + 'CancellationURL' => '', + 'SuccessURL' => '', + 'FailureURL' => '' + ]); + echo $res->getStatusCode(); + // "200" + echo $res->getHeader('content-type')[0]; + // 'application/json; charset=utf8' + echo $res->getBody(); + // {"type":"User"...' + + $navigationUrl = $res->getBody()["NavigationURL"]; + if(isset($navigationUrl)) { + redirect($navigationUrl); + } else { + show_error("error"); + } + } + + Public function polipaySuccessful() { + $email = $this->input->get("email"); + $token = $this->input->get("token"); + + $client = new GuzzleHttp\Client(); + + $res = $client->request('GET', 'https://poliapi.apac.paywithpoli.com/api/v2/Transaction/GetTransaction?token='. $token); + + if($res->TransactionStatusCode == "Completed") { + echo "polipay success"; + } else { + echo "payment not successful"; + } + } + +} \ No newline at end of file diff --git a/assets/js/enrollmentForm.js b/assets/js/enrollmentForm.js index d70e798..ebb388c 100644 --- a/assets/js/enrollmentForm.js +++ b/assets/js/enrollmentForm.js @@ -337,7 +337,7 @@ function showWarning() { // ========================================== // Buttons which are to be temporarily disabled -const disabledButtons = [payWeChat, payAli, payPoli]; +const disabledButtons = [payWeChat, payAli]; /* sets up event listener for button click except for the buttons which are disabled @@ -443,6 +443,13 @@ proceedPayment.onclick = function() { ); document.getElementById("enrollment-form").submit(); //window.open('http://localhost/ASPA-EnrollmentForm/EnrollmentForm/MakeStripePayment?email='); + } else if (toggled_index == 5) { + //Polipay payment + $("#enrollment-form").attr( + "action", + base_url + "EnrollmentForm/MakePoliPayment" + ); + document.getElementById("enrollment-form").submit(); } else { //IEpay }