Tuesday, January 31, 2017

Hosted Payment

Monaris

function PaymentMoneris(insertdata) {
        TsMessage.Show("Redirect to Moneris hosted payment", TsMessage.MessageType.Success);
 
        var url = "https://esqa.moneris.com/HPPDP/index.php"; // sand box
        if (settingsI.MonerisIsTestServer == false) {
            url = "https://www3.moneris.com/HPPDP/index.php"; // original
        }
 
        var postValues = {
            "ps_store_id": settingsI.MonerisID,
            "hpp_key": settingsI.MonerisKey,
            "charge_total": settingsI.TotalAmount.toFixed(2),
            "cust_id""custcode:" + settingsI.Customers + "-id:" + settingsI.userid,
            "order_id""oid" + insertdata.TransId,
            "lang""en-ca",
            "email": settingsI.email,
            "bill_first_name": insertdata.FirstName,
            "bill_last_name": insertdata.LastName,
            "bill_address_one": insertdata.Address1,
            "bill_city": insertdata.City,
            "bill_state_or_province": insertdata.StateProvince,
            "bill_postal_code": insertdata.PostalCodeZIP,
            "bill_country": insertdata.Country,
            "bill_phone": insertdata.Phone,
            "rvar_mode": settingsI.CheckOutType
        };
 
        for (var i = 0; i < insertdata.InvoiceDetails.length; i++) {
            var breakoutdata = insertdata.InvoiceDetails[i];
            var quantity = 1;
            var pos = i + 1;
 
            postValues["id" + pos] = breakoutdata.EventCode;
            postValues["description" + pos] = breakoutdata.EventName;
            postValues["quantity" + pos] = quantity;
            postValues["price" + pos] = breakoutdata.EventAmount;
            postValues["subtotal" + pos] = breakoutdata.EventAmount * quantity;
        }
 
        PostRedirect.redirect(url,
            postValues,
            "POST");
    }
 
parameter description 

settingsI.MonerisID //public key
"ATNEQtore3"
settingsI.MonerisKey // private key
"hpFGG67Q5VJJ"
settingsI.TotalAmount.toFixed(2) // amount
"500.00"
"custcode:" + settingsI.Customers + "-id:" + settingsI.userid // customer id
"custcode:ADAMM002-id:123456789c"
 "oid" + insertdata.TransId // order id (when rederect the page this will pass from gate way to our site)
"oid1149"
settingsI.email
"admintestuser@townsuite.com"
settingsI.CheckOutType
1

payment interface

// sandbox configuration

If you do not have the moneris key and id login at https://esqa.moneris.com/mpg/index.php (Only store 3 supports interac).

Valid credit cards for testing

  • MasterCard 5454545454545454
  • Visa 4242424242424242
  • Amex 373599005095005
  • Diners 36462462742008

Valid debit cards for testing

INTERAC Online Select test bank
Valdid IDEBIT_TRACK2 values
  • 3728024906540591206=01121122334455000
  • 5268051119993326=01121122334455000000
  • 453781122255=011211223344550000000000

Configuration Url

Accept

http://localhost:52469/monerishostedreceipt

accept function C#

public void monerishostedreceipt{
try
           {
               Card = GlobalMethods.RequestParam("card");
 
               if (Card == "P")
               {
                   // interac online
                   IssName = GlobalMethods.RequestParam("ISSNAME");
                   Invoice = GlobalMethods.RequestParam("INVOICE");
                   IssConf = GlobalMethods.RequestParam("ISSCONF");
               }
               else
               {
                   IssName = "";
                   Invoice = "";
                   IssConf = "";
               }
 
               ResponseOrderId = GlobalMethods.RequestParam("response_order_id");
               DateStamp = GlobalMethods.RequestParam("date_stamp");
               TimeStamp = GlobalMethods.RequestParam("time_stamp");
               BankTransactionId = GlobalMethods.RequestParam("bank_transaction_id");
               ChargeTotal = decimal.Parse(GlobalMethods.RequestParam("charge_total"));
               BankApprovalCode = GlobalMethods.RequestParam("bank_approval_code");
               IsoCode = GlobalMethods.RequestParam("iso_code");
               Message = GlobalMethods.RequestParam("message");
               TransName = GlobalMethods.RequestParam("trans_name");
               CardHolder = GlobalMethods.RequestParam("cardholder");
               F4l4 = GlobalMethods.RequestParam("f4l4");
               CardUserFriendly = GetHumanReadableCardType(Card);
               ExpiryDate = GlobalMethods.RequestParam("expiry_date");
               Result = GlobalMethods.RequestParam("result");
               ResponseCode = GlobalMethods.RequestParam("response_code");
               Mode = GlobalMethods.RequestParam("rvar_mode");
 
               ProcessData();
           }
           catch (Exception ex)
           {
               TownSuiteWebPortals.Trace.TrapErrors(ex);
               TownSuiteWebPortals.Messages.Show(this"An unknown error occurred."Messages.MessageType.Error);
           }
}

Reject

http://localhost:65299/monerishosteddeclined

rejected function

public void monerishosteddeclined ()
       {
 
           try
           {
 
               Card = MonerisHostedReceipt.GetHumanReadableCardType(GlobalMethods.RequestParam("card"));
 
               if (Card == "P")
               {
                   // interac online
                   IssName = GlobalMethods.RequestParam("ISSNAME");
                   Invoice = GlobalMethods.RequestParam("INVOICE");
                   IssConf = GlobalMethods.RequestParam("ISSCONF");
               }
               else
               {
                   IssName = "";
                   Invoice = "";
                   IssConf = "";
               }
 
               ResponseOrderId = GlobalMethods.RequestParam("response_order_id");
               DateStamp = GlobalMethods.RequestParam("date_stamp");
               TimeStamp = GlobalMethods.RequestParam("time_stamp");
               BankTransactionId = GlobalMethods.RequestParam("bank_transaction_id");
 
               // On a cancel request this will be an empty string
               decimal cTotal = 0m;
               decimal.TryParse(GlobalMethods.RequestParam("charge_total"), out cTotal);
               ChargeTotal = cTotal;
 
               BankApprovalCode = GlobalMethods.RequestParam("bank_approval_code");
               IsoCode = GlobalMethods.RequestParam("iso_code");
               Message = GlobalMethods.RequestParam("message");
               TransName = GlobalMethods.RequestParam("trans_name");
               CardHolder = GlobalMethods.RequestParam("cardholder");
               F4l4 = GlobalMethods.RequestParam("f4l4");
               ExpiryDate = GlobalMethods.RequestParam("expiry_date");
               Result = GlobalMethods.RequestParam("result");
               ResponseCode = GlobalMethods.RequestParam("response_code");
 
               ProcessData();
           }
           catch (Exception ex)
           {
               TownSuiteWebPortals.Trace.TrapErrors(ex);
               TownSuiteWebPortals.Messages.Show(this"An unknown error occurred."Messages.MessageType.Error);
           }
       }

Configuration page
https://esqa.moneris.com/mpg/admin/hppv3_config/index.php







Tuesday, January 17, 2017

Kendo Datasource

module Example.Datasource {
 
    let ds = new kendo.data.DataSource();
    $(() => {
 
        $('#grid').kendoGrid();
 
        $('#btnFillValues').bind('click', fillValues);
        $('#btnViewData').bind('click', showData);
        $('#btnAddTupple').bind('click', addTupple);
        $('#btnRemoveByIndex').bind('click', removeByIndex);
        $('#txtFileterText').bind('keyup', search);
        $('#btnViewFirstIndex').bind('click', getItemByIndex);
        $('#btnInsert').bind('click', insert);
        $('#btnAddToGrid').bind('click', addToGrid);
        $('#btnDeleteFilterdRows').bind('click', searchAndRemove);
        $('#btnSearchAndUpdate').bind('click', searchAndUpdate);
    });
 
    function fillValues() {
 
        var data = [
            { name: "Jane Doe", age: 30 },
            { name: "Chamith Saranga", age: 33 }
        ];
        ds.data(data);
    }
 
    function showData() {
        var view = ds.view();
        $.each(view, (i, d) => {
            console.log(d.name);
        });
        $('#grid').data('kendoGrid').setDataSource(new kendo.data.DataSource({ data: view }));
    }
    function addTupple() {
        ds.add({ name: 'sajeeka', age: 20 });
    }
 
    function removeByIndex() {
        ds.remove(ds.at(0));
    }
 
    function getItemByIndex() {
        var dataItem: any = ds.at(0);
        alert(dataItem.name);
    }
    function removeMultiple() {
        var val = $('#txtFileterText').val();
        //ds.remove(ds.filter({ field: "name", operator: "startswith", value: val }));
    }
 
    //Inserts a data item in the data source at the specified index.
    function insert() {
        ds.insert(1, { name: "Kasun Chathuranga", age: 20 });
        showData();
    }
 
    function search() {
        var val = $('#txtFileterText').val();
        console.log(val);
        ds.filter({ field: "name", operator: "startswith", value: val });
        showData();
    }
 
    function addToGrid() {
 
        ds.insert(0, { name: $('#txtName').val(), age: Number($('#txtAge').val()) });
        showData();
    }
 
    function searchAndRemove() {
 
        $.each(ds.data(), (i, d) => {
            if (d.name === $('#txtFileterText').val()){
                ds.remove(ds.at(i));
            }
        });
        showData();
    }
 
    function searchAndUpdate() {
        $.each(ds.data(), (i, d) => {
            if (d.name === $('#txtFileterText').val()) {
                d.age = 55;
            }
        });
        showData();
    }
}

////////////////////////////
///HTML
///////////////////////////

<!DOCTYPE html>
<html>
<head>
    <title></title>
 <meta charset="utf-8" />
    <link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.2.607/styles/kendo.common.min.css" />
    <link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.2.607/styles/kendo.rtl.min.css" />
    <link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.2.607/styles/kendo.silver.min.css" />
    <link rel="stylesheet" href="http://kendo.cdn.telerik.com/2016.2.607/styles/kendo.mobile.all.min.css" />
 
    <script src="http://code.jquery.com/jquery-1.12.4.min.js"></script>
    <script src="http://kendo.cdn.telerik.com/2016.2.607/js/kendo.all.min.js"></script>
</head>
<body>
    <input type="button" name="name" value="Fill values" id="btnFillValues" />
    <br />
    <input type="button" name="name" value="Add Tupple" id="btnAddTupple" />
    <br />
    <input type="button" name="name" value="view values" id="btnViewData" />
    <br />
    <input type="button" name="name" value="remove by index" id="btnRemoveByIndex" />
    <br />
    <input type="button" name="name" value="view First Index" id="btnViewFirstIndex" />
    <br />
    <input type="button" name="name" value="Insert" id="btnInsert" />
    <br />
    <input type="button" name="name" value="Remove Filted rows" id="btnDeleteFilterdRows" />
    <br />
    <input type="button" name="name" value="Search And Update" id="btnSearchAndUpdate" />
    <hr />
    <h1>Grid View</h1>
    Name : <input type="text" name="name" value="" id="txtName" /> 
    Age : <input type="number" name="name" value="" id="txtAge"/>
    <input type="button" name="name" value="Add"  id="btnAddToGrid"/>
    <br /><br />
    <input type="text" name="name" value="" id="txtFileterText" placeholder="type something to fileter"/>
    <div id="grid"></div>
</body>
 
<script src="../assets/ts/datasource.js"></script>
</html>



Saturday, January 7, 2017

Routing web api

Routing is how Web API matches a URI to an action

Web API used convention-based routing

https://github.com/api2/github/iamchamith/BestPractices/blob/master/Test.ts


[RoutePrefix("api2")]
   public class RoutingExampleController : ApiController
   { 
       [Route("github/{user}/{repo}/blob/master/{file}")]
       public string GetFile(string user,string repo,string file) {
 
           return $"{user}-> {repo}->{file}";
       }
   }

github is must


Route Constraints

[Route("user/{id:int}")]
       public string GetUser(int id)
       {
 
           return "Chamith " + id;
       }


ConstraintDescriptionExample
alphaMatches uppercase or lowercase Latin alphabet characters (a-z, A-Z){x:alpha}
boolMatches a Boolean value.{x:bool}
datetimeMatches a DateTime value.{x:datetime}
decimalMatches a decimal value.{x:decimal}
doubleMatches a 64-bit floating-point value.{x:double}
floatMatches a 32-bit floating-point value.{x:float}
guidMatches a GUID value.{x:guid}
intMatches a 32-bit integer value.{x:int}
lengthMatches a string with the specified length or within a specified range of lengths.{x:length(6)}
{x:length(1,20)}
longMatches a 64-bit integer value.{x:long}
maxMatches an integer with a maximum value.{x:max(10)}
maxlengthMatches a string with a maximum length.{x:maxlength(10)}
minMatches an integer with a minimum value.{x:min(10)}
minlengthMatches a string with a minimum length.{x:minlength(10)}
rangeMatches an integer within a range of values.{x:range(10,50)}
regexMatches a regular expression.{x:regex(^\d{3}-\d{3}-\d{4}$)}

Optional URI Parameters and Default Values

Default parameter
public class BooksController : ApiController
{
    [Route("api/books/locale/{lcid:int?}")]
    public IEnumerable<Book> GetBooksByLocale(int lcid = 1033) { ... }
}
Url parameter
public class BooksController : ApiController
{
    [Route("api/books/locale/{lcid:int=1033}")]
    public IEnumerable<Book> GetBooksByLocale(int lcid) { ... }
}
Init routing in application startup 
inside Globle.asax

protected void Application_Start()
        {
            RouteConfig.RegisterRoutes(RouteTable.Routes);
        }


Using router table


public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
          // Web API routes
           config.MapHttpAttributeRoutes();
 
           config.Routes.MapHttpRoute(
               name: "DefaultApi",
               routeTemplate: "api/{controller}/{action}/{id}",
               defaults: new { id = RouteParameter.Optional }
           );
     }
}







CS Events