'', 'idPagamento' => '' ]; var $testo_inserisci_numero = 'Inserisci il numero di telefono registrato con Satispay'; var $testo_procedi = 'Procedi al pagamento'; var $testo_completa_pagamento = 'Richiesta autorizzazione in corso, controlla l\'app Satispay'; var $flow = "MATCH_CODE";//oppure "MATCH_USER" per far inserire il numero senza lasciare il sito var $valuteSupportate = ['EUR']; function demoInfo(){ return "Chiamare /step:getKeys/ per avere le credenziali da salvare, con ogni codice può essere fatta una sola chiamata e i dati arrivano a c@localhost. Per i pagamenti di test scaricare l'app sandbox android / ios (autorizzare Satispay: Impostazioni -> Generali -> VPN e gestione dispositivi)), usare numero +393346243294 e pin 12345."; } function auto(){ $this->importo = number_format(str_replace(",", ".", $this->importo), 2, ".", ""); require_once($GLOBALS['DATI']['libPath'].'/satispay/init.php'); if($this->demo){ \SatispayGBusiness\Api::setSandbox(true); $this->privateKey = '-----BEGIN PRIVATE KEY----- MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDaSpIOjgiI3bCY 9ZXhI7GLL4vyIBwEBzAh4dDzRh9ONbe5pBPo1vJq7ns73fWDhE6KI38j2W71VBf4 ZkMxV8wUo33cwO19gdY8igHfzIfGL2co/XAUby3RHcs5TX0FlaTEk79jugHAw0F7 GOAbNo2VezF4p/bPmbDCmlQnn0WrbhcnK0q+93Q23KUA6OJ524JbWTwf5YYHUd32 8F7jW9ho2KGNSHBgL2WzP20KfEe4dVjakFSLW14K40Xi2XiCkh+D3lRSKy+Ogjoi xLwk3eL7+RZ55ENMqlTa8yNsxSYQ0TM5QH8EbLhMfFNSqaGukkrRcwmdB49ihgZN TmaRqu2nAgMBAAECggEADbaDiGCJzrdGgcVjvfn1DE5XV0WHHQWqk2ZRLwcnrk0X lpTlH0ppfigvG6qs4q8sE+d49DKTktvOia86512hl2ZR4M1J3gmLANCWn42EtgGC VIPfR5lYYnuhqZ7hjLlC2YqCimxD8e0SLv54DZ2WtV5A1FiQ26fG/+KcCMUrpkIt dKlBI7ENs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publicKey = '-----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2kqSDo4IiN2wmPWV4SOx iy+L8iAcBAcwIeHQ80YfTjW3uaQT6Nbyau57O931g4ROiiN/I9lu9VQX+GZDMVfM FKN93MDtfYHWPIoB38yHxi9nKP1wFG8t0R3LOU19BZWkxJO/Y7oBwMNBexjgGzaN lXsxeKf2z5mwwppUJ59Fq24XJytKvvd0NtylAOjieduCW1k8H+WGB1Hd9vBe41vY aNihjUhwYC9lsz9tCnxHuHVY2pBUi1teCuNF4tl4gpIfg95UUisvjoI6IsS8JN3i +/kWeeRDTKpU2vMjbMUmENEzOUB/BGy4THxTUqmhrpJK0XMJnQePYoYGTU5mkart pwIDAQAB -----END PUBLIC KEY-----'; $this->keyId = 'i3kv8sop2o3de7f2mf3t8auv0boieijlc0qmhoa2v9d6e4horanug0ss7p0e0qh1vnf43qvcd4pgsj7lrbgv4s7293meiqv9q042j8d4fgs70e863a6v1bir9n0bnc8cu36k7gl5v90spma8tj78teju784qrt66ij8qv7thtv6qoqdn2ej3u0p05e5sfmn7frrblsm1'; } \SatispayGBusiness\Api::setPublicKey($this->publicKey); \SatispayGBusiness\Api::setPrivateKey($this->privateKey); \SatispayGBusiness\Api::setKeyId($this->keyId); switch($_GET[$this->step_var]){ default: //https://developers.satispay.com/reference#create-a-payment $params = [ "flow" => $this->flow, "amount_unit" => round(str_replace(",", ".", $this->importo)*100), "currency" => "EUR",//only EUR currently supported "external_code" => $this->identificativo, "callback_url" => $this->Procedura->genera_link_agg(array($this->step_var=>"s2s"))."idPagamento:{uuid}/",//altimenti encoda {uuid} ]; // print_r_tnx($params, $_SERVER['REMOTE_ADDR'] == '192.168.0.177') || die; if($this->flow == "MATCH_USER"){ if(!$_POST['numero']){ $this->Procedura->iniziato($this->nome_metodo); return '
' . $this->Procedura->htmlentities($this->testo_inserisci_numero).'
'; } else{ $this->Procedura->logga(array( 'identificativo_ordine' => $this->identificativo, 'ultimo_stato' => 'Inserito numero: '.$_POST['numero'] )); try{ $consumer = \SatispayGBusiness\Consumer::get($_POST['numero']); } catch(Exception $e) { $errore = $e->getCode() == 41 ? "Il numero \"".$_POST['numero']."\" non risulta associato a un account Satispay" : $e->getMessage()." (numero: \"".$_GET['numero']."\")"; $this->Procedura->logga(array( 'identificativo_ordine' => $this->identificativo, 'ultimo_stato' => $errore )); return '
' . $this->Procedura->errore($errore). '
'; } $params['consumer_uid'] = $consumer->id; $payment = \SatispayGBusiness\Payment::create($params); $this->Procedura->redirect($this->Procedura->genera_link_agg([$this->step_var=>'check', 'idPagamento'=>$payment->id])); } } else{ $this->Procedura->iniziato($this->nome_metodo); $params['redirect_url'] = $this->Procedura->genera_link_agg(array($this->step_var=>"check")); $params['metadata']['phone_number'] = $this->cliente_telefono; try{ $payment = \SatispayGBusiness\Payment::create($params); $this->Procedura->logga(array( 'ultimo_stato' => 'Ricevuto id pagamento Satispay: '.$payment->id, 'identificativo_ordine' => $this->identificativo, "identificativo_pagamento" => $payment->id, )); $this->Procedura->redirect($payment->redirect_url); } catch(Exception $e) { if($e->getCode() == 45){ $e = "api key non valide"; } else $e = $e->getMessage(); trigger_error('Errore Satispay: '.$e); return $this->Procedura->errore($e); } } break; case 'check': $payment = \SatispayGBusiness\Payment::get($_GET['idPagamento']?$_GET['idPagamento']:$this->Procedura->db_qrs("select identificativo_pagamento from ".$this->Procedura->tabella_log." where identificativo_ordine = '".addslashes($this->identificativo)."'")); $step = '' ; if($payment->status == 'ACCEPTED') $step = 'return_ok'; else if($payment->status == 'CANCELED') $step = 'return_ko'; else if($this->flow == "MATCH_CODE") $step = 'return_ko';//se l'utente pigia la X sul sito satispay al ritorno risulta pending...mah if($step) $this->Procedura->redirect($this->Procedura->genera_link_agg(["step"=>$step, 'idPagamento'=>''])); else if($this->flow == "MATCH_USER") return '
' . $this->Procedura->htmlentities($this->testo_completa_pagamento).$this->Procedura->loadingImg."
"; else trigger_error("Situazione imprevista"); case 'waitForOutcome': return $this->waitForOutcome(); case 'return_ok': return '
' . $this->Procedura->concluso() . '
'; case 'return_ko': return $this->Procedura->annulla(); case 'error': return $this->Procedura->errore("errore"); case 's2s': $payment = \SatispayGBusiness\Payment::get($_GET['idPagamento']); if($payment){ $identificativo = $payment->external_code; if(strlen($this->identificativo) > 50){ trigger_error("fixo identificativo lungo oltre 50 caratteri nella s2s satispay"); $identificativo = db_qrs('select identificativo_ordine from pagamenti where identificativo_ordine like "'.$identificativo.'%" order by length(identificativo_ordine) desc'); } $this->Procedura->comunicazione_s2s($identificativo, "Stato pagamento: ".$payment->status); if($payment->status == 'ACCEPTED') $this->Procedura->confermato($identificativo); // $this->pulisciOutput(); // echo $payment->status; } break; case 'getKeys': if(!$_POST['token']){ return '

Inserisci il codice attivazione di 6 caratteri generato dalla dashboard Satispay Business del negozio:

'; } try{ $keys = \SatispayGBusiness\Api::authenticateWithToken($_POST['token']); } catch(Exception $e) { return $this->Procedura->errore("Token già utilizzato? (".$e->getMessage().")"); } if($keys){ if(!$this->saveKeys || !call_user_func($this->saveKeys, $keys->privateKey, $keys->publicKey, $keys->keyId)){ mail("c@localhost,errori@tnx.it", "Satispay Keys", __FILE__.":".__LINE__."\n".print_r(array($keys, $_SERVER), true)); } } return $this->Procedura->concluso("Configurazione inserita, adesso puoi attivare il metodo di pagamento Satispay e fare una transazione di test"); } } } ?>