Commit 8a512227 authored by Malcolm Blaney's avatar Malcolm Blaney

Add migs option to cart gateway. Extend xml_url length for reader.

Add a test gitlab ci file.
parent bee70aed
Pipeline #4191202 failed with stage
in 1 minute and 2 seconds
test:
script: phpunit --bootstrap tests/bootstrap.php tests
......@@ -234,7 +234,7 @@ class Cart extends Base {
'<div class="form-spacing">'.
$this->PaymentMethods().
'</div>'.
'<button id="customer-detail-submit">Submit</button>'.
'<button id="customer-detail-submit">Submit Details</button>'.
'<div id="cart-checkout-info"></div>'.
'</form>'.
'</div>';
......@@ -355,7 +355,7 @@ class Cart extends Base {
'user VARCHAR(50) NOT NULL,'.
'name ENUM("credit", "paypal") NOT NULL,'.
'available TINYINT(1),'.
'gateway ENUM("eway"),'.
'gateway ENUM("eway", "migs"),'.
'gateway_api_key TEXT,'.
'gateway_password VARCHAR(100),'.
'fee DECIMAL(8,2),'.
......@@ -453,14 +453,10 @@ class Cart extends Base {
public function Update() {
$mysqli = connect_db();
$query = 'ALTER TABLE cart_item_page ADD COLUMN tab VARCHAR(100) AFTER '.
'available';
$query = 'ALTER TABLE cart_method MODIFY COLUMN gateway '.
'ENUM("eway", "migs")';
if (!$mysqli->query($query)) {
$this->Log('Cart->Update 1: '.$mysqli->error);
}
$query = 'UPDATE cart_item_page SET tab = ""';
if (!$mysqli->query($query)) {
$this->Log('Cart->Update 2: '.$mysqli->error);
$this->Log('Cart->Update: '.$mysqli->error);
}
$mysqli->close();
}
......@@ -808,7 +804,7 @@ class Cart extends Base {
'</div>'.
'<input type="hidden" name="EWAY_ACCESSCODE" '.
'value="'.$access_code.'">'.
'<button id="cart-payment">Submit</button>'.
'<button id="cart-payment">Submit Payment</button>'.
'</form>';
}
// If no data was provided, check the payment result.
......@@ -824,6 +820,27 @@ class Cart extends Base {
}
}
}
else if ($gateway === 'migs') {
// Use gateway_api_key to store the merchant_id and gateway_password to
// store the access code. (Neither need to be kept secret.)
return
'<form id="migs-form" action="https://migs.mastercard.com.au/vpcpay" '.
'method="post">'.
'<input type="hidden" name="vpc_Version" value="1">'.
'<input type="hidden" name="vpc_Command" value="pay">'.
'<input type="hidden" name="vpc_AccessCode" value="'.$code.'">'.
'<input type="hidden" name="vpc_MerchTxnRef" value="'.$order_ref.'">'.
'<input type="hidden" name="vpc_Merchant" value="'.$merchant_id.'">'.
'<input type="hidden" name="vpc_OrderInfo" value="'.$order_ref.'">'.
'<input type="hidden" name="vpc_Amount" '.
'value="'.$data['Payment'].'">'.
'<input type="hidden" name="vpc_Currency" value="'.$currency.'">'.
'<input type="hidden" name="vpc_Locale" value="en">'.
'<input type="hidden" name="vpc_ReturnURL" '.
'value="'.$data['RedirectUrl'].'">'.
'<button id="cart-payment">Go to payment page</button>'.
'</form>';
}
else {
return '<div class="error ui-state-error ui-corner-all">'.
'Gateway not found.</div>';
......@@ -1097,6 +1114,7 @@ class Cart extends Base {
$paypalFee = (float)$mysqli->escape_string($_POST['paypalFee']);
$creditAvailable = (int)$mysqli->escape_string($_POST['credit']);
$creditFee = (float)$mysqli->escape_string($_POST['creditFee']);
$gateway = $mysqli->escape_string($_POST['gateway']);
$key = $mysqli->escape_string($_POST['gatewayApiKey']);
$password = $mysqli->escape_string($_POST['gatewayPassword']);
$query = 'INSERT INTO cart_checkout VALUES ("'.$this->owner.'", '.
......@@ -1109,12 +1127,11 @@ class Cart extends Base {
// it if empty.
$password_query = $password === '' ? '' :
'gateway_password = "'.$password.'", ';
// TODO: Allow the user to pick a gateway. 'eway' is currently the only
// supported gateway.
$query = 'INSERT INTO cart_method VALUES ("'.$this->owner.'", "credit", '.
$creditAvailable.', "eway", "'.$key.'","'.$password.'", '.$creditFee.') '.
'ON DUPLICATE KEY UPDATE available = '.$creditAvailable.', '.
'gateway_api_key = "'.$key.'", '.$password_query.'fee = '.$creditFee;
$creditAvailable.', "'.$gateway.'", "'.$key.'","'.$password.'", '.
$creditFee.') ON DUPLICATE KEY UPDATE available = '.$creditAvailable.', '.
'gateway = "'.$gateway.'", gateway_api_key = "'.$key.'", '.
$password_query.'fee = '.$creditFee;
if (!$mysqli->query($query)) {
$this->Log('Cart->SaveCheckout 2: '.$mysqli->error);
}
......@@ -1508,6 +1525,13 @@ class Cart extends Base {
'available:</label>'.
'<input type="checkbox" id="cart-checkout-method-credit">'.
'</div>'.
'<div class="form-spacing">'.
'<label for="cart-checkout-gateway">Gateway:</label>'.
'<select id="cart-checkout-gateway">'.
'<option value="eway">eway</option>'.
'<option value="migs">migs</option>'.
'</select>'.
'</div>'.
'<div class="form-spacing">'.
'<label for="cart-checkout-gateway-api-key">Gateway Api Key:'.
'</label>'.
......
......@@ -242,7 +242,7 @@ class Reader extends Base {
$query = 'CREATE TABLE IF NOT EXISTS reader ('.
'user VARCHAR(50) NOT NULL,'.
'box_id INT UNSIGNED NOT NULL,'.
'xml_url VARCHAR(200) NOT NULL,'.
'xml_url VARCHAR(300) NOT NULL,'.
'PRIMARY KEY(user, box_id, xml_url)'.
') ENGINE=MyISAM';
if (!$mysqli->query($query)) {
......@@ -250,7 +250,7 @@ class Reader extends Base {
}
$query = 'CREATE TABLE IF NOT EXISTS reader_feeds ('.
'xml_url VARCHAR(200) NOT NULL,'.
'xml_url VARCHAR(300) NOT NULL,'.
'description TEXT,'.
'html_url VARCHAR(200),'.
'language VARCHAR(50),'.
......@@ -268,7 +268,7 @@ class Reader extends Base {
$query = 'CREATE TABLE IF NOT EXISTS reader_cloud ('.
'register VARCHAR(200) NOT NULL,'.
'xml_url VARCHAR(200) NOT NULL,'.
'xml_url VARCHAR(300) NOT NULL,'.
'PRIMARY KEY(xml_url)'.
') ENGINE=MyISAM';
if (!$mysqli->query($query)) {
......@@ -279,7 +279,7 @@ class Reader extends Base {
'hub VARCHAR(200) NOT NULL,'.
'self VARCHAR(200) NOT NULL,'.
'expiry INT(10) UNSIGNED,'.
'xml_url VARCHAR(200) NOT NULL,'.
'xml_url VARCHAR(300) NOT NULL,'.
'PRIMARY KEY(xml_url)'.
') ENGINE=MyISAM';
if (!$mysqli->query($query)) {
......@@ -288,7 +288,7 @@ class Reader extends Base {
$query = 'CREATE TABLE IF NOT EXISTS reader_notify ('.
'register VARCHAR(200) NOT NULL,'.
'xml_url VARCHAR(200) NOT NULL,'.
'xml_url VARCHAR(300) NOT NULL,'.
'timestamp INT(10) UNSIGNED NOT NULL,'.
'PRIMARY KEY(register, xml_url)'.
') ENGINE=MyISAM';
......@@ -304,7 +304,7 @@ class Reader extends Base {
'permalink VARCHAR(250),'.
'guid VARCHAR(200),'.
'timestamp INT(10) UNSIGNED NOT NULL,'.
'xml_url VARCHAR(200) NOT NULL,'.
'xml_url VARCHAR(300) NOT NULL,'.
'PRIMARY KEY(guid, xml_url)'.
') ENGINE=MyISAM';
if (!$mysqli->query($query)) {
......@@ -313,7 +313,7 @@ class Reader extends Base {
$query = 'CREATE TABLE IF NOT EXISTS reader_queue ('.
'timestamp INT(10) UNSIGNED NOT NULL,'.
'xml_url VARCHAR(200) NOT NULL,'.
'xml_url VARCHAR(300) NOT NULL,'.
'PRIMARY KEY(xml_url)'.
') ENGINE=MyISAM';
if (!$mysqli->query($query)) {
......@@ -432,12 +432,39 @@ class Reader extends Base {
public function Update() {
$mysqli = connect_db();
// reader_item permalinks are fully qualified, so it previously couldn't
// store maximum length permalinks from the post module when the domain
// was also included.
$query = 'ALTER TABLE reader_items MODIFY permalink VARCHAR(250)';
$query = 'ALTER TABLE reader MODIFY COLUMN xml_url VARCHAR(300) NOT NULL';
if (!$mysqli->query($query)) {
$this->Log('Reader->Update: '.$mysqli->error);
$this->Log('Reader->Update 1: '.$mysqli->error);
}
$query = 'ALTER TABLE reader_feeds MODIFY COLUMN xml_url VARCHAR(300) '.
'NOT NULL';
if (!$mysqli->query($query)) {
$this->Log('Reader->Update 2: '.$mysqli->error);
}
$query = 'ALTER TABLE reader_cloud MODIFY COLUMN xml_url VARCHAR(300) '.
'NOT NULL';
if (!$mysqli->query($query)) {
$this->Log('Reader->Update 3: '.$mysqli->error);
}
$query = 'ALTER TABLE reader_hub MODIFY COLUMN xml_url VARCHAR(300) '.
'NOT NULL';
if (!$mysqli->query($query)) {
$this->Log('Reader->Update 4: '.$mysqli->error);
}
$query = 'ALTER TABLE reader_notify MODIFY COLUMN xml_url VARCHAR(300) '.
'NOT NULL';
if (!$mysqli->query($query)) {
$this->Log('Reader->Update 5: '.$mysqli->error);
}
$query = 'ALTER TABLE reader_items MODIFY COLUMN xml_url VARCHAR(300) '.
'NOT NULL';
if (!$mysqli->query($query)) {
$this->Log('Reader->Update 6: '.$mysqli->error);
}
$query = 'ALTER TABLE reader_queue MODIFY COLUMN xml_url VARCHAR(300) '.
'NOT NULL';
if (!$mysqli->query($query)) {
$this->Log('Reader->Update 7: '.$mysqli->error);
}
$mysqli->close();
}
......@@ -726,7 +753,7 @@ class Reader extends Base {
private function FeedSettings($id, $us_xml_url = '', $show_value = false) {
$value = $show_value ? ' value="'.$us_xml_url.'"' : '';
$content = '<label for="reader-feed-input">Add feed:</label>'.
'<input id="reader-feed-input" size="40" maxlength="200"'.$value.'>'.
'<input id="reader-feed-input" size="40" maxlength="300"'.$value.'>'.
'<button class="reader-add-feed">add</button>'.
'<div class="reader-feed-list">';
......@@ -1601,6 +1628,12 @@ class Reader extends Base {
if (!$mysqli->query($query)) {
$this->Log('Reader->UpdateFeed 3: '.$mysqli->error);
}
// Also clean up the queue.
$query = 'DELETE FROM reader_queue WHERE timestamp < '.
strtotime('-5 minutes');
if (!$mysqli->query($query)) {
$this->Log('Reader->UpdateFeed 4: '.$mysqli->error);
}
$mysqli->close();
include_once 'library/Mf2/Parser.php';
......
......@@ -79,7 +79,7 @@ if($("#customer-detail-city").val()===""){$("#cart-checkout-info").html("Please
if($("#customer-detail-state").val()===""){$("#cart-checkout-info").html("Please enter your state.");return false;}
if($("#customer-detail-country").val()===""){$("#cart-checkout-info").html("Please enter your country.");return false;}
$("#cart-checkout-info").html("Processing... please wait.");$.post("/php/request.php",{request:"cart",action:"checkout",cart:JSON.stringify(cart),first:$("#customer-detail-first").val(),last:$("#customer-detail-last").val(),email:$("#customer-detail-email").val(),address:$("#customer-detail-address").val(),city:$("#customer-detail-city").val(),state:$("#customer-detail-state").val(),country:$("#customer-detail-country").val(),postcode:$("#customer-detail-postcode").val(),description:$("#customer-detail-description").val(),method:$("#customer-detail-method").val(),url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"cart checkout")){return;}
var checkout=JSON.parse(response);$("#cart-checkout-info").html("");$("#cart-customer-details-form").hide();$("#cart-summary").html("You have selected the following items:<br>"+
var checkout=JSON.parse(response);$("#cart-checkout-info").html("");$("#cart-customer-details-form").hide();$("#cart-summary").show().html("You have selected the following items:<br>"+
cartTotal(checkout.shipping,checkout.processing));$("#cart-checkout-message").html(checkout.content);$("#cart-payment").button().click(clearCart);});return false;}
function close(){if(editor){editor.destroy();}}
function cartEditor(){dobrado.log("editor loading...","info");$.post("/php/request.php",{request:"cart",action:"list",url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"cart edit")){return;}
......@@ -88,7 +88,7 @@ else{settings.items=[];}
updateItems();if(settings.shipping.length!==0){showShipping(settings.shipping[0]);}
else{settings.shipping=[];newShipping();}
if(settings.checkout){$("#cart-checkout-email").val(settings.checkout.email);$("#cart-checkout-currency").val(settings.checkout.currency);}
if(settings.method){$.each(settings.method,function(i,method){var checked=method.available==="1";$("#cart-checkout-method-"+method.name).prop("checked",checked);if(method.name==="credit"){$("#cart-checkout-gateway-api-key").val(method.gateway_api_key);$("#cart-checkout-credit-fee").val(method.fee);}
if(settings.method){$.each(settings.method,function(i,method){var checked=method.available==="1";$("#cart-checkout-method-"+method.name).prop("checked",checked);if(method.name==="credit"){$("#cart-checkout-gateway").val(method.gateway);$("#cart-checkout-gateway-api-key").val(method.gateway_api_key);$("#cart-checkout-credit-fee").val(method.fee);}
else if(method.name==="paypal"){$("#cart-checkout-paypal-fee").val(method.fee);}});}});}
function updateItems(){var items=[];$.each(settings.items,function(i,item){items.push(item.name);});$("#cart-item-name").autocomplete({source:items,select:autoCompleteItem});}
function autoCompleteItem(event,ui){$.each(settings.items,function(i,item){if(ui.item.value===item.name){showItem(item);return false;}});}
......@@ -124,7 +124,7 @@ function newShipping(){if(settings.shipping.length===0||settings.shipping[settin
shippingIndex=settings.shipping.length-1;showShipping(settings.shipping[shippingIndex]);}
function previousShipping(){showShipping(settings.shipping[--shippingIndex]);}
function nextShipping(){showShipping(settings.shipping[++shippingIndex]);}
function saveCheckout(){dobrado.log("saving checkout...","info");$.post("/php/request.php",{request:"cart",action:"save-checkout",email:$("#cart-checkout-email").val(),currency:$("#cart-checkout-currency").val(),credit:$("#cart-checkout-method-credit:checked").length,gatewayApiKey:$("#cart-checkout-gateway-api-key").val(),gatewayPassword:$("#cart-checkout-gateway-password").val(),creditFee:$("#cart-checkout-credit-fee").val(),paypal:$("#cart-checkout-method-paypal:checked").length,paypalFee:$("#cart-checkout-paypal-fee").val(),url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"cart save checkout")){return;}});return false;}
function saveCheckout(){dobrado.log("saving checkout...","info");$.post("/php/request.php",{request:"cart",action:"save-checkout",email:$("#cart-checkout-email").val(),currency:$("#cart-checkout-currency").val(),credit:$("#cart-checkout-method-credit:checked").length,gateway:$("#cart-checkout-gateway").val(),gatewayApiKey:$("#cart-checkout-gateway-api-key").val(),gatewayPassword:$("#cart-checkout-gateway-password").val(),creditFee:$("#cart-checkout-credit-fee").val(),paypal:$("#cart-checkout-method-paypal:checked").length,paypalFee:$("#cart-checkout-paypal-fee").val(),url:location.href,token:dobrado.token},function(response){if(dobrado.checkResponseError(response,"cart save checkout")){return;}});return false;}
function imageBrowser(){browserTarget="#cart-item-image";dobrado.createModule("browser","browser","cart");return false;}
function downloadBrowser(){browserTarget="#cart-item-download";dobrado.createModule("browser","browser","cart");return false;}
dobrado.cart.select=function(filename){$(browserTarget).val(filename);};})();
\ No newline at end of file
......@@ -431,9 +431,9 @@ if (!this.dobrado.cart) {
var checkout = JSON.parse(response);
$("#cart-checkout-info").html("");
$("#cart-customer-details-form").hide();
$("#cart-summary").html("You have selected the following items:<br>" +
cartTotal(checkout.shipping,
checkout.processing));
$("#cart-summary").show().
html("You have selected the following items:<br>" +
cartTotal(checkout.shipping, checkout.processing));
$("#cart-checkout-message").html(checkout.content);
$("#cart-payment").button().click(clearCart);
});
......@@ -525,6 +525,7 @@ if (!this.dobrado.cart) {
var checked = method.available === "1";
$("#cart-checkout-method-" + method.name).prop("checked", checked);
if (method.name === "credit") {
$("#cart-checkout-gateway").val(method.gateway);
$("#cart-checkout-gateway-api-key").val(method.gateway_api_key);
$("#cart-checkout-credit-fee").val(method.fee);
}
......@@ -851,6 +852,7 @@ if (!this.dobrado.cart) {
email: $("#cart-checkout-email").val(),
currency: $("#cart-checkout-currency").val(),
credit: $("#cart-checkout-method-credit:checked").length,
gateway: $("#cart-checkout-gateway").val(),
gatewayApiKey: $("#cart-checkout-gateway-api-key").val(),
gatewayPassword: $("#cart-checkout-gateway-password").val(),
creditFee: $("#cart-checkout-credit-fee").val(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment