<commit_before>/*** @license
 * Copyright 2016 Nexstream Sdn Bhd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
***/


"use strict"

window.KonnectedPay = window.KonnectedPay || {}
;(function () { // file-local scope...

// Helpers ---------------------------------------------------------------------

var validateConfig = function (config)
{
    var required = function (name)
    {
        if(config[name] == null) throw new Error(name+" is required!")
    }

    var numeric = function (name)
    {
        // Note: numbers which have exponents after .toString() are also invalid
        if(!/^[0-9]+(\.?[0-9]+)$/.test(config[name])) {
            throw new Error(name+" must be a valid number!")
        }
    }

    required("merchantId")
    required("clientSecret")
    required("amount")
    required("transId")
    required("currencyCode")
    required("fullName")
    required("email")
    required("userId")

    numeric("amount")
}

var keyValStr2Object = function (s)
{
    var pairs = s.split("&")
    var values = {}
    for(var i=0; i<pairs.length; i++) {
        var keyVal = pairs[i].split("=")
        var key = decodeURIComponent(keyVal[0])
        if(keyVal.length > 1) values[key] = decodeURIComponent(keyVal[1])
        else values[key] = true
    }
    return values
}

var getParams = function ()
{
    var getMatches = location.href.match(/^[^?]+\?([^#]+)/)
    if(!getMatches) return {}
    else return keyValStr2Object(getMatches[1])
}

var hashParams = function ()
{
    var hash = location.hash
    if(!hash) return {}
    else return keyValStr2Object(hash.substr(1))
}

// Public API ------------------------------------------------------------------

KonnectedPay.VERSION = "0.1.0-alpha"

KonnectedPay.requestPayment = function (config, blank)
{
    validateConfig(config)

    var url = "https://pay.appxtream.com/payment"
            + "?tranId="+encodeURIComponent(config.transId)
            + "&amount="+encodeURIComponent(config.amount)
            + "&currencyCode="+encodeURIComponent(config.currencyCode)
            + "&merchantId="+encodeURIComponent(config.merchantId)
            + "&device="+encodeURIComponent()
            + "&os="+encodeURIComponent()
            + "&fullname="+encodeURIComponent(config.fullName)
            + "&email="+encodeURIComponent(config.email)
            + "&userId="+encodeURIComponent(config.userId)

    if(config.rememberCard != null) {
        url += "&rememberCard=" + (config.rememberCard ? "true" : "false")
    }
    if(config.returnUrl != null) {
        url += "&return="+encodeURIComponent(config.returnUrl)
    }
    if(config.responseMethod != null) {
        url += "&returnMethod="+encodeURIComponent(config.responseMethod)
    }

    if(blank != "_blank") {
        location.assign(url)
    } else {
        window.open(
            url,
            "_blank",
            "menubar=no,toolbar=no,location=no,personalbar=no,directories=no"<commit_msg>Fixed: Missing OS and Device info when calling KonnectedPay API<commit_after>/*** @license
 * Copyright 2016 Nexstream Sdn Bhd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
***/


"use strict"

window.KonnectedPay = window.KonnectedPay || {}
;(function () { // file-local scope...

// Helpers ---------------------------------------------------------------------

var validateConfig = function (config)
{
    var required = function (name)
    {
        if(config[name] == null) throw new Error(name+" is required!")
    }

    var numeric = function (name)
    {
        // Note: numbers which have exponents after .toString() are also invalid
        if(!/^[0-9]+(\.?[0-9]+)$/.test(config[name])) {
            throw new Error(name+" must be a valid number!")
        }
    }

    required("merchantId")
    required("clientSecret")
    required("amount")
    required("transId")
    required("currencyCode")
    required("fullName")
    required("email")
    required("userId")

    numeric("amount")
}

var keyValStr2Object = function (s)
{
    var pairs = s.split("&")
    var values = {}
    for(var i=0; i<pairs.length; i++) {
        var keyVal = pairs[i].split("=")
        var key = decodeURIComponent(keyVal[0])
        if(keyVal.length > 1) values[key] = decodeURIComponent(keyVal[1])
        else values[key] = true
    }
    return values
}

var getParams = function ()
{
    var getMatches = location.href.match(/^[^?]+\?([^#]+)/)
    if(!getMatches) return {}
    else return keyValStr2Object(getMatches[1])
}

var hashParams = function ()
{
    var hash = location.hash
    if(!hash) return {}
    else return keyValStr2Object(hash.substr(1))
}

// Public API ------------------------------------------------------------------

KonnectedPay.VERSION = "0.1.0-alpha"

KonnectedPay.requestPayment = function (config, blank)
{
    validateConfig(config)

    var url = "https://pay.appxtream.com/payment"
            + "?tranId="+encodeURIComponent(config.transId)
            + "&amount="+encodeURIComponent(config.amount)
            + "&currencyCode="+encodeURIComponent(config.currencyCode)
            + "&merchantId="+encodeURIComponent(config.merchantId)
            + "&device="+encodeURIComponent(navigator.userAgent)
            + "&os=browser"
            + "&fullname="+encodeURIComponent(config.fullName)
            + "&email="+encodeURIComponent(config.email)
            + "&userId="+encodeURIComponent(config.userId)

    if(config.rememberCard != null) {
        url += "&rememberCard=" + (config.rememberCard ? "true" : "false")
    }
    if(config.returnUrl != null) {
        url += "&return="+encodeURIComponent(config.returnUrl)
    }
    if(config.responseMethod != null) {
        url += "&returnMethod="+encodeURIComponent(config.responseMethod)
    }

    if(blank != "_blank") {
        location.assign(url)
    } else {
        window.open(
            url,
            "_blank",
            "menubar=no,toolbar=no,location=no,personalbar=no,directories=no"
{'fraction_non_alphanumeric': 0.1738194344768193, 'fraction_numerical': 0.006889622506100187, 'mean_word_length': 2.5641943734015347, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1160179', 'n_tokens_mistral': 2033, 'n_tokens_neox': 2062, 'n_words': 476}