Skip to content

Commit

Permalink
#17 Add support request page, handle request form
Browse files Browse the repository at this point in the history
  • Loading branch information
rinnhofer committed May 4, 2017
1 parent 91b8752 commit 3ed2cd7
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@
*/
class WC_Gateway_Wirecard_Checkout_Seamless_Admin {

protected $_settings;

/**
* constructor
*
* @param $settings
*/
public function __construct( $settings ) {
$this->_settings = $settings;
}

/**
* Handles form output for admin panel
*
Expand All @@ -52,7 +63,7 @@ function print_admin_form_fields( $gateway ){
<?= __( 'Transaction Overview', 'woocommerce-wirecard-checkout-seamless' ) ?>
</a>

<a class="button-primary" href="javascript:void(0);">
<a class="button-primary" href="?page=wirecard_support_request">
<?= __( 'Contact support', 'woocommerce_wirecard_checkout_seamless' ) ?>
</a>
</div>
Expand Down Expand Up @@ -190,7 +201,7 @@ function include_backend_header( $gateway ){
function print_transaction_table( $transaction, $start ) {
?>
<div class="woo-wcs-backend-links">
<a class="button-primary woocommerce-save-button" href="?page=wc-settings&tab=checkout&section=woocommerce_wcs">
<a class="button-primary" href="?page=wc-settings&tab=checkout&section=woocommerce_wcs">
<?= __( 'Back to Settings', 'woocommerce-wirecard-checkout-seamless' ) ?>
</a>
</div>
Expand All @@ -209,14 +220,14 @@ function print_transaction_table( $transaction, $start ) {
<?php
if ( $start > 20 ){
?>
<a class="button-primary woocommerce-save-button" href="?page=wc-settings&tab=checkout&section=woocommerce_wcs&transaction_start=<?php echo ($start-20); ?>">
<a class="button-primary" href="?page=wc-settings&tab=checkout&section=woocommerce_wcs&transaction_start=<?php echo ($start-20); ?>">
<?= __( 'Back', 'woocommerce-wirecard-checkout-seamless' ) ?>
</a>
<?php
}
if( $start + 20 < $more ){
?>
<a class="button-primary woocommerce-save-button" href="?page=wc-settings&tab=checkout&section=woocommerce_wcs&transaction_start=<?php echo ($start+20); ?>">
<a class="button-primary" href="?page=wc-settings&tab=checkout&section=woocommerce_wcs&transaction_start=<?php echo ($start+20); ?>">
<?= __( 'Next', 'woocommerce-wirecard-checkout-seamless' ) ?>
</a>

Expand All @@ -229,7 +240,7 @@ function setStartValue(data){
document.getElementById("wcs-transaction-start").setAttribute("href", start);
}
</script>
<a class="button-primary woocommerce-save-button" id="wcs-transaction-start" href="?page=wc-settings&tab=checkout&section=woocommerce_wcs&transaction_start=1">
<a class="button-primary" id="wcs-transaction-start" href="?page=wc-settings&tab=checkout&section=woocommerce_wcs&transaction_start=1">
<?= __( 'Get transactions starting at ', 'woocommerce-wirecard-checkout-seamless' ) ?>
</a>
<?php
Expand All @@ -246,4 +257,103 @@ function setStartValue(data){
<?php
}

/**
* Handles support requests
*
* @since 1.0.0
*/
function print_support_form() {
?>
<div class="woo-wcs-backend-links">
<a class="button-primary" href="?page=wc-settings&tab=checkout&section=woocommerce_wcs">
<?= __( 'Back to Settings', 'woocommerce-wirecard-checkout-seamless' ) ?>
</a>
</div>

<h2><?= __( 'Support Request', 'woocommerce-wirecard-checkout-seamless' ) ?></h2>
<br/>
<?php
if( isset($_POST['send-request'])){
$this->create_support_request();
echo '<br/>';
}
?>
<form action="?page=wirecard_support_request" method="post" name="support-request-form">
<table>
<tr>
<td><label for="support-mail"><?= __( 'To:', 'woocommerce-wirecard-checkout-seamless' ) ?></label></td>
<td><select name="support-mail">
<option value="[email protected]"><?= __( 'Support Team Wirecard CEE, Austria',
'woocommerce-wirecard-checkout-seamless' ) ?></option>
<option value="[email protected]"><?= __( 'Support Team Wirecard AG, Germany',
'woocommerce-wirecard-checkout-seamless' ) ?></option>
<option value="[email protected]"><?= __( 'Support Team Wirecard Singapore',
'woocommerce-wirecard-checkout-seamless' ) ?></option>
</select>
</td>
</tr>
<tr>
<td><label for="customer-mail"><?= __( 'Your e-mail address:',
'woocommerce-wirecard-checkout-seamless' ) ?></label></td>
<td><input type="email" name="customer-mail"/></td>
</tr>
<tr>
<td><label for="support-message"><?= __( 'Your message:',
'woocommerce-wirecard-checkout-seamless' ) ?></label></td>
<td><textarea rows="5" cols="70" name="support-message"></textarea></td>
</tr>
</table>
<br/>
<input type="submit" class="button-primary" name="send-request"
value="<?= __( 'Send your request', 'woocommerce-wirecard-checkout-seamless' ) ?>"/>
</form>
<?php
}

/**
* Create support request with config data
*
* @since 1.0.0
*/
function create_support_request() {
global $wp_version;
$postdata = $_POST;

$message = "WordPress: " . $wp_version . "\n";
$message .= "WooCommerce: " . WC()->version . "\n";
$message .= "PHP: " . phpversion() . "\n";
$message .= "Pluginname: " . WOOCOMMERCE_GATEWAY_WCS_NAME . "\n";
$message .= "Pluginversion: " . WOOCOMMERCE_GATEWAY_WCS_VERSION . "\n";
$message .= "-----------------------------------------\n";
$message .= "Message: \n" . strip_tags( $postdata['support-message'] ) . "\n";
$message .= "-----------------------------------------\n";

foreach ( $this->get_settings_fields() as $group => $fields ) {
foreach ( $fields as $key => $field ) {
$message .= $field['title'] . ": ";
$message .= $this->_settings[ $key ] . "\n";
}
}

$send_to = $postdata['support-mail'];
$from = $postdata['customer-mail'];
$headers = 'From: <' . $from . '>';
$subject = 'WooCommerce Support Request';

$send = wp_mail( $send_to, $subject, $message, $headers );
?>

<div class="updated inline">
<p><strong>
<?php if ( $send ) {
echo __( 'Your request has been sent', 'woocommerce-wirecard-checkout-seamless' );
} else {
echo __( 'Your request could not be sent', 'woocommerce-wirecard-checkout-seamless' );
}
?>
</strong>
</p>
</div>
<?php
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ public function __construct() {
$this->init_settings();

$this->_logger = new WC_Logger();
$this->_admin = new WC_Gateway_Wirecard_Checkout_Seamless_Admin();
$this->_admin = new WC_Gateway_Wirecard_Checkout_Seamless_Admin( $this->settings );
$this->_config = new WC_Gateway_Wirecard_Checkout_Seamless_Config( $this->settings );
$this->_transaction = new WC_Gateway_Wirecard_Checkout_Seamless_Transaction();

// if any of the payment types are enabled, set this to "yes", otherwise "no"
$this->enabled = count( $this->get_enabled_payment_types( false ) ) > 0 ? "yes" : "no";
$this->title = 'Wirecard Checkout Seamless';


add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array(
Expand Down Expand Up @@ -248,12 +249,14 @@ class="<?php echo esc_attr( $data['css'] ); ?>" type="checkbox"
*/
public function admin_options() {
$this->_admin->include_backend_header( $this );
if ( ! isset( $_GET['transaction_start'] ) ) {
$this->_admin->print_admin_form_fields( $this );
} else {

if ( isset( $_GET['transaction_start'] ) ) {
$this->_admin->print_transaction_table( $this->_transaction, $_GET['transaction_start'] );
unset( $_GET['transaction_start'] );
}
else {
$this->_admin->print_admin_form_fields( $this );
}

}

Expand Down Expand Up @@ -735,4 +738,14 @@ function datastorage_return() {
die( require_once 'includes/datastorage_fallback.php' );
}

/**
* Opens the support request form
*
* @since 1.0.0
*/
function do_support_request() {
$this->_admin->include_backend_header( $this );
$this->_admin->print_support_form();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
);

add_action( 'plugins_loaded', 'init_woocommerce_wcs_gateway' );
add_action( 'admin_menu', 'add_wirecard_support_request_page' );

/**
* Intialize the Wirecard payment gateway
Expand Down Expand Up @@ -134,3 +135,19 @@ function woocommerce_install_wirecard_checkout_seamless() {
dbDelta( $sql );

}

/**
* Add extra page for wirecard support request
*
* @since 1.0.0
*/
function add_wirecard_support_request_page() {
add_submenu_page(
null,
__( 'Wirecard Support Request', 'woocommerce-wirecard-checkout-seamless' ),
__( 'Wirecard Support Request', 'woocommerce-wirecard-checkout-seamless' ),
'manage_options',
'wirecard_support_request',
array( new WC_Gateway_Wirecard_Checkout_Seamless(), 'do_support_request')
);
}

0 comments on commit 3ed2cd7

Please sign in to comment.