- ProviderInterface/AbstractProvider: Vorgang mit Uhrzeit+Session (payment_transactions), Mail und Warenkorb erst nach Zahlung, idempotentes markPaid, Betragsabgleich, shop_event + PG payment_log - Secrets verschluesselt (libsodium) in MySQL, Schluessel ausserhalb Docroot - Cashdesk: ?payment_return/?payment_cancel, Pending-Riegel, zahlung_erst_spaeter() - Backend Zahlart-Editor: Einstellungen speichern (war ohne Empfaenger), Secret-Felder - payment_webhook.php (Standalone), cli.php (init-key, secret, reconcile, status) - PayPal-v2-Blaupause vom Juli entfernt
191 lines
6.6 KiB
PHP
191 lines
6.6 KiB
PHP
<?php
|
|
/**
|
|
* @version $Id: admin_payment_method_editor.php
|
|
* @package Easyshop
|
|
* @copyright Copyright (C) 2005 - 2011 TA-EDV
|
|
* @license proprietary
|
|
* @author Richard Kammermayer <rk@ta-edv.de>
|
|
* Easyshop is a web shop system
|
|
*/
|
|
|
|
include_once './core/payment_method.class.php';
|
|
include_once './modules/list_and_edit.class.php';
|
|
|
|
class admin_payment_method_editor {
|
|
private $base_object;
|
|
private $config;
|
|
|
|
function __construct($base_object, $layout_object) {
|
|
$this->base_object = $base_object;
|
|
$this->config = $base_object->config;
|
|
$this->layout_object = $layout_object;
|
|
$this->list_object = new ListAndEdit($base_object, $layout_object);
|
|
}
|
|
|
|
function run() {
|
|
//$this->setup_info();
|
|
|
|
//var_dump($GLOBALS);
|
|
|
|
if(isset($_GET['id']) && $_GET['id']) {
|
|
$has_id = true;
|
|
} else if(isset($_POST['id']) && $_POST['id']) {
|
|
$has_id = true;
|
|
} else {
|
|
$has_id = false;
|
|
}
|
|
|
|
if(isset($_POST['submit'])) {
|
|
$is_submitted = true;
|
|
} else {
|
|
$is_submitted = false;
|
|
}
|
|
|
|
// 13.09.2026: Reiter "Einstellungen" speichern (Konfigurationsgruppe + Secrets).
|
|
// Vorher hatte dieses Formular keinen Empfaenger -- es postete ins Leere.
|
|
if (isset($_POST['payment_config_save']) && $has_id) {
|
|
$this->save_provider_config((int)$_POST['id']);
|
|
$is_submitted = false;
|
|
$_GET['id'] = (int)$_POST['id'];
|
|
}
|
|
|
|
// decide what CRUD method to call and call it in ListAndEdit
|
|
// create
|
|
$payment_method_object = new Payment_method($this->base_object);
|
|
if($is_submitted && !$has_id) {
|
|
$form_data = $payment_method_object->data_filter($_POST['form_field']);
|
|
if (isset($form_data['active'])) {
|
|
$form_data['active'] = '1';
|
|
} else {
|
|
$form_data['active'] = '0';
|
|
}
|
|
$payment_method_object->create($form_data);
|
|
$payment_method_data = $payment_method_object->get_data();
|
|
$this->layout_object->assign('form_data', $payment_method_data);
|
|
|
|
// configuration data
|
|
if ($payment_method_data->configuration_group_id) {
|
|
$config_data = $this->config->get_config_elements($payment_method_data->configuration_group_id);
|
|
$this->layout_object->assign('config_data', $config_data);
|
|
}
|
|
$this->assign_provider($payment_method_data);
|
|
}// read
|
|
elseif($has_id && !$is_submitted && $_GET['mod'] != 'delete') {
|
|
// template variable name
|
|
$payment_method_object->id = $_GET['id'];
|
|
$payment_method_data = $payment_method_object->get_data();
|
|
$this->layout_object->assign('form_data', $payment_method_data);
|
|
|
|
// configuration data
|
|
if ($payment_method_data->configuration_group_id) {
|
|
$config_data = $this->config->get_config_elements($payment_method_data->configuration_group_id);
|
|
$this->layout_object->assign('config_data', $config_data);
|
|
}
|
|
$this->assign_provider($payment_method_data);
|
|
} // update
|
|
elseif($has_id && $is_submitted && $_GET['mod'] != 'delete') {
|
|
$payment_method_object->id = $_POST['id'];
|
|
$form_data = $payment_method_object->data_filter($_POST['form_field']);
|
|
if (isset($form_data['active'])) {
|
|
$form_data['active'] = '1';
|
|
} else {
|
|
$form_data['active'] = '0';
|
|
}
|
|
$payment_method_object->update($form_data);
|
|
|
|
// payment method data
|
|
$payment_method_data = $payment_method_object->get_data();
|
|
$this->layout_object->assign('form_data', $payment_method_data);
|
|
|
|
// configuration data
|
|
if ($payment_method_data->configuration_group_id) {
|
|
$config_data = $this->config->get_config_elements($payment_method_data->configuration_group_id);
|
|
$this->layout_object->assign('config_data', $config_data);
|
|
}
|
|
$this->assign_provider($payment_method_data);
|
|
} // delete
|
|
elseif($has_id && isset($_GET['mod']) && $_GET['mod'] == 'delete'){
|
|
$payment_method_object->id = $_GET['id'];
|
|
$payment_method_object->delete();
|
|
}
|
|
else {
|
|
|
|
}
|
|
|
|
return $this->layout_object->fetch('admin_payment_method_editor.tpl');
|
|
}
|
|
|
|
/**
|
|
* 13.09.2026 -- Zahlungsanbieter aus core/payments: Secret-Felder fuers Template.
|
|
* Klartext wird nie ausgeliefert, nur "hinterlegt seit".
|
|
*/
|
|
private function assign_provider($payment_method_data) {
|
|
if (!is_object($payment_method_data) || empty($payment_method_data->module)) {
|
|
return;
|
|
}
|
|
include_once './core/payments/Registry.php';
|
|
if (!\Payments\Registry::has((string)$payment_method_data->module)) {
|
|
return;
|
|
}
|
|
try {
|
|
$provider = \Payments\Registry::get((string)$payment_method_data->module, $this->base_object);
|
|
} catch (Throwable $e) {
|
|
$this->layout_object->assign('provider_error', $e->getMessage());
|
|
return;
|
|
}
|
|
if (!$provider) {
|
|
return;
|
|
}
|
|
$key_ok = \Payments\Secrets::keyAvailable();
|
|
$status = $key_ok ? \Payments\Secrets::status($this->base_object->db, $provider->module()) : array();
|
|
$fields = array();
|
|
foreach ($provider->secretFields() as $name => $label) {
|
|
$fields[] = array(
|
|
'name' => $name,
|
|
'label' => $label,
|
|
'since' => isset($status[$name]) ? $status[$name] : '',
|
|
);
|
|
}
|
|
$this->layout_object->assign('provider_label', $provider->label());
|
|
$this->layout_object->assign('provider_module', $provider->module());
|
|
$this->layout_object->assign('provider_key_ok', $key_ok ? 1 : 0);
|
|
$this->layout_object->assign('provider_key_path', \Payments\Secrets::keyPath());
|
|
$this->layout_object->assign('provider_secrets', $fields);
|
|
$this->layout_object->assign('provider_webhook_url', rtrim(MAIN_URL, '/').'/payment_webhook.php?p='.$provider->module());
|
|
}
|
|
|
|
/** Einstellungen (configuration-Gruppe) und Secrets aus dem Reiter "Einstellungen" speichern. */
|
|
private function save_provider_config($payment_method_id) {
|
|
$pm_object = new Payment_method($this->base_object);
|
|
$pm_object->id = $payment_method_id;
|
|
$pm = $pm_object->get_data();
|
|
if (!$pm) {
|
|
return;
|
|
}
|
|
if (!empty($pm->configuration_group_id) && isset($_POST['form_field']) && is_array($_POST['form_field'])) {
|
|
$clean = array();
|
|
foreach ($_POST['form_field'] as $k => $v) {
|
|
$clean[$k] = $this->base_object->db->real_escape_string((string)$v);
|
|
}
|
|
$this->config->update($pm->configuration_group_id, $clean);
|
|
}
|
|
if (!empty($pm->module) && isset($_POST['secret_field']) && is_array($_POST['secret_field'])) {
|
|
include_once './core/payments/Registry.php';
|
|
if (\Payments\Registry::has((string)$pm->module) && \Payments\Secrets::keyAvailable()) {
|
|
$provider = \Payments\Registry::get((string)$pm->module, $this->base_object);
|
|
$allowed = $provider ? $provider->secretFields() : array();
|
|
foreach ($_POST['secret_field'] as $name => $value) {
|
|
$value = trim((string)$value);
|
|
if ($value === '' || !isset($allowed[$name])) {
|
|
continue; // leer = unveraendert lassen
|
|
}
|
|
\Payments\Secrets::set($this->base_object->db, $provider->module(), (string)$name, $value);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
?>
|