Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

billon

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

billon - npm Package Compare versions

Comparing version 1.0.5 to 1.0.6

182

index.js

@@ -13,2 +13,6 @@ var billon = {

this.ProductDelivery = function () {
return false;
};
this.ProductDownload = function () {

@@ -18,2 +22,6 @@ return false;

this.PaymentTitle = function () {
return false;
};
this.OnFinishedPayment = function () {

@@ -24,2 +32,4 @@ console.log("Finished some payment.");

// HELPERS
var isFunction = function (func) {

@@ -33,6 +43,47 @@ if (typeof func !== "function") {

var deliveryOptions = {
"NOT_NEEDED": 0,
"OPTIONAL": 1,
"OBLIGATORY": 2
};
var uniqueId = function () {
var text = new Date().getTime()+Math.random(1,500000);
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$%^&*()";
for (var i = 0; i < 5; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
};
// ERRORS
var errs = {
ERR_INVALID_QUERY: {
err: "ERR_INVALID_QUERY",
description: "Missing query."
},
ERR_INVALID_QUERY_DATA: {
err: "ERR_INVALID_QUERY_DATA",
description: "Data must be an object."
},
ERR_INVALID_ITEMS_ID: {
err: "ERR_INVALID_ITEMS_ID",
description: "Data.itemsId must be an object."
},
ERR_INVALID_USER: {
err: "ERR_INVALID_USER",
description: "Data.user must be an object."
},
ERR_INVALID_USER_USERNAME: {
err: "ERR_INVALID_USER_USERNAME",
description: "Data.user.userName must be a string with minimum 4 characters length."
}
};
billon.Shop.prototype = {
merchant: function (func) {
if (!isFunction(func)) {
console.log("billon.merchant parameter must be a function.");
console.log("Shop.merchant parameter must be a function.");
return false;

@@ -46,3 +97,3 @@ }

if (!isFunction(func)) {
console.log("billon.app24 parameter must be a function.");
console.log("Shop.app24 parameter must be a function.");
return false;

@@ -56,3 +107,3 @@ }

if (!isFunction(func)) {
console.log("billon.product parameter must be a function.");
console.log("Shop.product parameter must be a function.");
return false;

@@ -64,5 +115,14 @@ }

},
productDelivery: function (func) {
if (!isFunction(func)) {
console.log("Shop.productDelivery parameter must be a function.");
return false;
}
this.ProductDelivery = func;
return this;
},
productDownload: function (func) {
if (!isFunction(func)) {
console.log("billon.productDownload parameter must be a function.");
console.log("Shop.productDownload parameter must be a function.");
return false;

@@ -74,5 +134,14 @@ }

},
paymentTitle: function (func) {
if (!isFunction(func)) {
console.log("Shop.paymentTitle parameter must be a function.");
return false;
}
this.PaymentTitle = func;
return this;
},
onFinishedPayment: function (func) {
if (!isFunction(func)) {
console.log("billon.onFinishedPayment parameter must be a function.");
console.log("Shop.onFinishedPayment parameter must be a function.");
return false;

@@ -84,4 +153,107 @@ }

},
handle: function (req, res) {
var self = this;
if (typeof req.query !== "object") {
return res.send(errs.ERR_INVALID_QUERY);
}
if (typeof req.query.data !== "object") {
return res.send(errs.ERR_INVALID_QUERY_DATA);
}
var requestData = req.query.data;
if (typeof requestData.itemsId !== "object") {
return res.send(errs.ERR_INVALID_ITEMS_ID);
}
if (typeof requestData.user !== "object") {
return res.send(errs.ERR_INVALID_USER);
}
if (typeof requestData.user.userName !== "string" || requestData.user.userName.length < 4) {
return res.send(errs.ERR_INVALID_USER_USERNAME);
}
var paymentData = {
user: requestData.user,
itemsId: requestData.itemsId,
deliveryId: requestData.deliveryId
};
var document = DocumentScheme();
var itemsId = req.query.data;
var requestInvoiceData = "NOT_NEEDED";
var requestDeliveryData = "NOT_NEEDED";
// Wczytanie produktów.
for (var i = 0; i < itemsId.length; i++) {
var itemId = itemsId[i];
var item = this.Product(itemId);
document.sales_document_data.total_amount_net += item.amount_net * item.quantity;
document.sales_document_data.total_amount_gross += item.amount_gross * item.quantity;
document.sales_document_data.items.push(item);
// Sprawdzenie czy potrzeba danych do faktury lub dostawy.
if (deliveryOptions[item.requestInvoiceData] > deliveryOptions[requestInvoiceData]) {
requestInvoiceData = item.requestInvoiceData;
}
if (deliveryOptions[item.requestDeliveryData] > deliveryOptions[requestDeliveryData]) {
requestDeliveryData = item.requestDeliveryData;
}
}
// Wczytanie opcji dostawy.
document.sales_document_data.delivery_option = self.ProductDelivery(document.sales_document_data.items);
// Wczytanie danych sprzedawcy.
document.seller_data = self.Merchant(document.sales_document_data.items, document.sales_document_data.delivery_option);
var data = {
WUI: self.App24(document.sales_document_data.items, document.sales_document_data.delivery_option),
params: {
type: "NORMAL",
amount: {
amount: document.sales_document_data.total_amount_gross,
currency: "PLN"
},
requestData: {
username: paymentData.user.userName,
uniqueTransferId: uniqueId(),
title: self.PaymentTitle(document.sales_document_data.items, document.sales_document_data.delivery_option),
requestInvoiceData: requestInvoiceData,
requestDeliveryData: requestDeliveryData,
description: JSON.stringify(document)
}
}
};
SoapService.call["requestPaymentInitiation"](data, function(requestResponse){
console.log(requestResponse);
res.json(requestResponse);
if (requestResponse.requestStatus === "SUCCESS") {
var interval = setInterval(function(){
SoapService.call["getTaskStatus"]({
taskId: requestResponse.taskId
}, function(taskResponse){
console.log(taskResponse);
if (taskResponse.status.split("_")[0] === "FINISHED" || taskResponse.progressPercent === 100) {
clearInterval(interval);
}
if (taskResponse.status === "FINISHED_OK") {
self.OnFinishedPayment(document.sales_document_data.items, document.sales_document_data.delivery_option, document);
}
});
}, 5000);
}
});
}
};
module.exports = billon;

2

package.json
{
"name": "billon",
"version": "1.0.5",
"version": "1.0.6",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc