Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing receive #12

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ protected/qrcodes/*
protected/uploads/*
*.log
*.db

version.txt
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
# Napay POS - Point of sale
# Fidelity POS
This is a fork of Napay POS

A POS (Point of sale) is all you need to start earning bitcoins.

[![Screenshot of NaPay PWA app](css/images/screenshot.png)](https://napay.napoliblockchain.it)

A POS (Point of sale) is all you need to start earning bitcoins.


## Authors
Made with ❤️ by [Sergio Casizzone](https://sergiocasizzone.altervista.org)


**Features**
- [x] Mobile & Desktop Layout
- [x] Bitcoin Transactions list & details
- [x] Token (TTS) Transactions list & details
- [x] Bitcoin (Lightning) & Token receive
- [x] Print receipts
- [x] Mobile & Desktop Layout
- [x] Bitcoin Transactions list & details
- [x] Token (TTS) Transactions list & details
- [x] Bitcoin (Lightning) & Token receive
- [x] Print receipts


**PWA**
- [x] Service Worker
- [x] indexedDB
- [x] static precache & dynamic cache
- [x] Service Worker
- [x] indexedDB
- [x] static precache & dynamic cache
Binary file modified css/favicon.ico
Binary file not shown.
1,023 changes: 0 additions & 1,023 deletions css/images/BG.svg

This file was deleted.

Binary file removed css/images/anb-chiaro.png
Binary file not shown.
Binary file removed css/images/anb-dark.png
Binary file not shown.
Binary file removed css/images/anb-trasparente-single.png
Binary file not shown.
Binary file removed css/images/anb-trasparente-single2.png
Binary file not shown.
Binary file removed css/images/anb-trasparente.png
Binary file not shown.
Binary file removed css/images/anb-trasparente.xcf
Binary file not shown.
Binary file removed css/images/anb-trasparente1.png
Binary file not shown.
Binary file removed css/images/anb-trasparente2.png
Binary file not shown.
Binary file removed css/images/bitcoin_e_comune.png
Binary file not shown.
77 changes: 0 additions & 77 deletions css/images/bitcoin_e_comune.svg

This file was deleted.

Binary file modified css/images/favicon.ico
Binary file not shown.
Binary file removed css/images/favicon.png
Binary file not shown.
Binary file added css/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed css/images/logo_comune_trasparente.png
Binary file not shown.
Binary file removed css/images/logo_napoli_comune.png
Binary file not shown.
Binary file removed css/images/logocomune.png
Binary file not shown.
Binary file removed css/images/logonapay.png
Binary file not shown.
Binary file removed css/images/napay-bianco.png
Binary file not shown.
Binary file removed css/images/napay-yellow.png
Binary file not shown.
Binary file removed css/images/npay-anb-trasparente.png
Binary file not shown.
Binary file removed css/images/npay-anb-trasparente0.png
Binary file not shown.
Binary file removed css/images/npay-anb.png
Binary file not shown.
Binary file removed css/images/npay-anb.xcf
Binary file not shown.
Binary file removed css/images/npay-chiaro.png
Binary file not shown.
Binary file removed css/images/npay-chiaro.xcf
Binary file not shown.
Binary file removed css/images/npay-trasparente.png
Binary file not shown.
Binary file removed css/images/parthenope.png
Binary file not shown.
Binary file removed css/images/vesuvio.jpg
Binary file not shown.
4 changes: 3 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php
// $yiiVersion = 'yii';
$yiiVersion = 'yii-1.1.22';

// change the following paths if necessary
$yii=dirname(__FILE__).'/../yii/framework/yii.php';
$yii=dirname(__FILE__).'/../'.$yiiVersion.'/framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';

// remove the following lines when in production mode
Expand Down
123 changes: 0 additions & 123 deletions jquery/___numpad/easy-numpad.js

This file was deleted.

Empty file.
6 changes: 3 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Napay POS - Point of sale",
"short_name": "Napay POS",
"name": "Fidelity POS",
"short_name": "Fidelity POS",
"icons": [
{
"src": "src/images/icons/app-icon-48x48.png",
Expand Down Expand Up @@ -44,7 +44,7 @@
"orientation": "portrait-primary",
"background_color": "#fff",
"theme_color": "#3f51b5",
"description": "A web application using Bitcoin & Naples Payment Token, implementing a lot of PWA love.",
"description": "A web application using ERC20 Token, implementing a lot of PWA love.",
"dir": "ltr",
"lang": "it-IT"
}
54 changes: 28 additions & 26 deletions protected/commands/ReceiveCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
<?php
Yii::import('libs.crypt.crypt');
Yii::import('libs.NaPacks.Settings');
Yii::import('libs.NaPacks.WebApp');
Yii::import('libs.NaPacks.SaveModels');
Yii::import('libs.NaPacks.Save');
Yii::import('libs.NaPacks.Push');
Yii::import('libs.NaPacks.Notifi');
Yii::import('libs.ethereum.eth');
Yii::import('libs.Utils.Utils');
Yii::import('libs.webRequest.webRequest');

class ReceiveCommand extends CConsoleCommand
{
public $logfilehandle = null;
Expand Down Expand Up @@ -60,26 +71,19 @@ private function setLogFile($file){
private function getLogFile(){
return $this->logfilehandle;
}

//scrive a video e nel file log le informazioni richieste
private function log($text){
$save = new Save;
$save->WriteLog('pos','commands','receive',$text);
$save->WriteLog('pos','commands','receive', $text);
echo "\r\n" .date('Y/m/d h:i:s a - ', time()) .$text;
}

public function actionIndex($id){
set_time_limit(0); //imposto il time limit unlimited
$seconds = 1;
$events = true;

// preparo il log file
$nomeLogFile = Yii::app()->basePath."/log/pos-receive.log";
// if (!is_writable($nomeLogFile)){
// chmod($nomeLogFile, 0755); // octal; correct value of mode
// }

//non c'è output, pertanto salvo gli errori nel log file
$myfile = fopen($nomeLogFile, "a");
$this->setLogFile($myfile);
$this->log("Start Check invoice #: $id");

//carico l'invoice
Expand All @@ -92,21 +96,20 @@ public function actionIndex($id){

while(true){
$ipnflag = false;
if ($invoice->status == 'new'){ //se il valore è new proseguo
if ($invoice->status == 'new' || $invoice->status == 'expired'){ //se il valore è new proseguo
// cerco le transazioni su bolt_tokens in pending
$criteria=new CDbCriteria;

$criteria->compare('type','token',true);
$criteria->compare('type','token');
//$criteria->compare('status','new',true);
$criteria->compare('item_desc','wallet',true);
$criteria->compare('to_address',$invoice->to_address,true);
$criteria->compare('item_desc','wallet');
$criteria->compare('to_address',$invoice->to_address);
$criteria->addCondition("invoice_timestamp > " .$invoice->invoice_timestamp);
$criteria->addCondition("blocknumber > " .$invoice->blocknumber);
$criteria->compare('token_price',$invoice->token_price,true); // false -> valore identico

$transactions = Tokens::model()->findAll($criteria);

// echo '<pre>'.print_r($transactions,true).'</pre>';
$this->log("Ricerca Transazioni: ".'<pre>'.print_r($transactions,true).'</pre>');
//echo '<pre>'.print_r($transactions,true).'</pre>';
//exit;

if (!empty($transactions))
Expand All @@ -117,6 +120,7 @@ public function actionIndex($id){
$this->log("Transazione n. $transaction->id_token");
if ($transaction->status <> 'new'){
$this->log("Transazione n. $transaction->id_token COMPLETATA.");
$this->log('<pre>'.print_r($transaction->attributes,true).'</pre>');
$invoice->status = $transaction->status;
$invoice->token_ricevuti = $transaction->token_price;
$invoice->from_address = $transaction->from_address;
Expand Down Expand Up @@ -144,7 +148,7 @@ public function actionIndex($id){
}
}//foreach loop
}
if ($expiring_seconds < 0){//invoice expired
if ($ipnflag === false && $expiring_seconds < 0){//invoice expired
$invoice->status = 'expired';
$ipnflag = true;
}
Expand All @@ -156,7 +160,9 @@ public function actionIndex($id){
#fwrite($this->getLogFile(), date('Y/m/d h:i:s a', time()) . " : <pre>".print_r($tokens->attributes,true)."</pre>\n");
//echo '<pre>'.print_r($invoice->attributes,true).'</pre>';
if ($invoice->save()){
$this->log("End : invoice #: $id, Status: $invoice->status, Received: $invoice->token_ricevuti");
$this->log("Invoice n. $invoice->id_token SALVATA.");
$this->log('<pre>'.print_r($invoice->attributes,true).'</pre>');
//$this->log("End : invoice #: $id, Status: $invoice->status, Received: $invoice->token_ricevuti");
$this->sendIpn($invoice->attributes);
}else{
$this->log("Error : Cannot save invoice #. $id, Status: $invoice->status.");
Expand All @@ -166,19 +172,15 @@ public function actionIndex($id){
}

//conto alla rovescia fino alla scadenza dell'invoice
#fwrite($this->getLogFile(), date('Y/m/d h:i:s a', time()) . " : '.$ReceivingType.' Status: ".$tokens->status.", Seconds: ".$expiring_seconds."\n");
$this->log("Invoice: $id, Status: ".$invoice->status.", Seconds: ".$expiring_seconds."\n");
//echo chr(32).$expiring_seconds;
$this->log("remaining seconds... $expiring_seconds");
// $this->log("remaining seconds... $expiring_seconds");
$expiring_seconds --;
sleep(1);
}
}

private function sendIpn($ipn){
$nomeLogFile = Yii::app()->basePath."/log/pos-ipn.log";
$myfile = fopen($nomeLogFile, "a");
$this->setLogFile($myfile);
//
$tokens = (object) $ipn;

if (true === empty($tokens)) {
Expand All @@ -205,7 +207,7 @@ private function sendIpn($ipn){
Push::Send($save->Notification($notification,true),'dashboard');

//ADESSO POSSO USCIRE CON UN MESSAGGIO POSITIVO ;^)
$this->log("IPN received for Invoice #: ".crypt::Encrypt($tokens->id_token).", Status=" .$tokens->status.", Price=". $tokens->token_price);
$this->log("IPN received for Invoice #: ".crypt::Encrypt($tokens->id_token).", Status=" .$tokens->status.", Price=". $tokens->token_price.", Received: ".$tokens->token_ricevuti);
}
}
?>
34 changes: 0 additions & 34 deletions protected/components/POSIdentity.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
class POSIdentity extends CUserIdentity
{
const ERROR_USERNAME_NOT_MEMBER = 4;
const ERROR_USERNAME_NOT_PAYER = 6;

private $_id;
/**
Expand Down Expand Up @@ -50,39 +49,6 @@ public function authenticatePOS()
$merchants=Merchants::model()->findByPk($pos->id_merchant);
$users=Users::model()->findByPk($merchants->id_user);

//$NomePOS .= chr(32).$stores->denomination;
//$NomePOS .= chr(32).$merchants->denomination;

/*
* VERIFICA SE IL SOCIO HA PAGATO LA QUOTA D'ISCRIZIONE
*/
$timestamp = time();
$criteria = new CDbCriteria();
$criteria->compare('id_user',$merchants->id_user, false);

$provider = Pagamenti::model()->Paid()->OrderByIDDesc()->findAll($criteria);
if ($provider === null){
//$expiration_membership = $timestamp;
$this->errorCode=self::ERROR_USERNAME_NOT_PAYER;
$save->WriteLog('pos','useridentity','authenticate','User not payer: '.$this->username);
return !$this->errorCode;
}else{
$provider = (array) $provider;
if (count($provider) == 0)
$expiration_membership = 1;
else
$expiration_membership = strtotime($provider[0]->data_scadenza);
}
// scadenza entro il 31 gennaio per provvedere all'iscrizione (se la data_scadenza
// è al 31 dicembre)
// temporaneamente posticipato al 28 febbraio
$expiration_membership += (31+28) *24*60*60;
if ($expiration_membership <= $timestamp){
$this->errorCode=self::ERROR_USERNAME_NOT_MEMBER;
$save->WriteLog('pos','useridentity','authenticate','User not member: '.$this->username);
return !$this->errorCode;
}

$save->WriteLog('pos','useridentity','authenticate','User '.$this->username. ' logged in.');

$this->setState('objUser', array(
Expand Down
1 change: 1 addition & 0 deletions protected/config/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
main.php
database.php
console.php
Loading