38 lines
3.1 KiB
PHP
38 lines
3.1 KiB
PHP
<?php
|
|
if(!defined('ABSPATH')) exit;
|
|
class WMF_Service_PayPal extends WMF_Service {
|
|
public $id='paypal'; public $label='PayPal'; public $group='payments';
|
|
protected $credentials=array('mode'=>'sandbox','live_client'=>'','live_secret'=>'','sandbox_client'=>'','sandbox_secret'=>'');
|
|
public function is_connected(){$m=$this->credentials['mode']??'sandbox';return($m==='live')?!empty($this->credentials['live_secret']):!empty($this->credentials['sandbox_secret']);}
|
|
public function admin_widget($prev=array()){
|
|
$c=$this->get_credentials();
|
|
$int=wmf_get_integrations();
|
|
$act=$int->action_update;
|
|
$nonce=wp_create_nonce($act);
|
|
$m=$c['mode']??'sandbox';
|
|
$conn=$this->is_connected();
|
|
echo '<div class="wmf-widget-body">';
|
|
if($conn) echo '<div class="wmf-connected-badge">✓ Verbunden ('.($m==='live'?'Live':'Sandbox').')</div>';
|
|
echo '<form class="wmf-int-form">';
|
|
echo '<input type="hidden" name="_wpnonce" value="'.esc_attr($nonce).'">';
|
|
echo '<input type="hidden" name="action" value="'.esc_attr($act).'">';
|
|
echo '<input type="hidden" name="services[]" value="paypal">';
|
|
echo '<div class="wmf-mode-switch">';
|
|
echo '<label class="wmf-mode-btn '.($m==='sandbox'?'active':'').'"><input type="radio" name="credentials[paypal][mode]" value="sandbox" '.checked($m,'sandbox',false).' onchange="wmfPaypalMode(this)"> Sandbox</label>';
|
|
echo '<label class="wmf-mode-btn '.($m==='live'?'active':'').'"><input type="radio" name="credentials[paypal][mode]" value="live" '.checked($m,'live',false).' onchange="wmfPaypalMode(this)"> Live</label>';
|
|
echo '</div>';
|
|
echo '<div id="wmf-paypal-sandbox" '.($m==='live'?'style="display:none"':'').'>';
|
|
echo '<p><label>Sandbox Client-ID</label><input type="text" name="credentials[paypal][sandbox_client]" value="'.esc_attr($c['sandbox_client']??'').'" class="widefat"></p>';
|
|
echo '<p><label>Sandbox Secret</label><input type="password" name="credentials[paypal][sandbox_secret]" value="'.esc_attr($c['sandbox_secret']??'').'" class="widefat"></p>';
|
|
echo '</div>';
|
|
echo '<div id="wmf-paypal-live" '.($m==='sandbox'?'style="display:none"':'').'>';
|
|
echo '<p><label>Live Client-ID</label><input type="text" name="credentials[paypal][live_client]" value="'.esc_attr($c['live_client']??'').'" class="widefat"></p>';
|
|
echo '<p><label>Live Secret</label><input type="password" name="credentials[paypal][live_secret]" value="'.esc_attr($c['live_secret']??'').'" class="widefat"></p>';
|
|
echo '</div>';
|
|
echo '<p class="description"><a href="https://developer.paypal.com/dashboard/applications" target="_blank">PayPal Developer Dashboard →</a></p>';
|
|
echo '<p><button type="submit" class="button button-primary">Speichern</button></p>';
|
|
echo '</form>';
|
|
echo '<script>function wmfPaypalMode(el){document.getElementById("wmf-paypal-sandbox").style.display=el.value==="sandbox"?"":"none";document.getElementById("wmf-paypal-live").style.display=el.value==="live"?"":"none";}</script>';
|
|
echo '</div>';
|
|
}
|
|
} |