Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions application/controllers/EnrollmentForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
53 changes: 53 additions & 0 deletions application/models/Polipay_Model.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php



defined('BASEPATH') OR exit('No direct script access allowed');

class Polipay_Model extends CI_Model {

Public function makePolipayPayment($customer_email, $eventData) {

$client = new GuzzleHttp\Client();

$res = $client->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";
}
}

}
9 changes: 8 additions & 1 deletion assets/js/enrollmentForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down