Files
WooCommerce-Payment-Methods/classes/class-wc-payment-methods.php
T

548 lines
14 KiB
PHP
Raw Normal View History

2014-09-08 02:23:45 +02:00
<?php
/**
2014-10-23 18:16:47 +02:00
* Payment Methods
*
* @package vendocrat
* @subpackage Payment Methods
*
* @since 2014-09-08
2014-12-17 03:36:41 +01:00
* @version 2014-12-17
2014-10-23 18:16:47 +02:00
*
* @author Poellmann Alexander Manfred <alex@vendocr.at>
* @copyright Copyright 2014 vendocrat. All Rights Reserved.
* @link http://vendocr.at/
2014-09-08 02:23:45 +02:00
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2014-10-23 18:16:47 +02:00
if ( ! class_exists( 'vendocrat_WC_Payment_Methods' ) ) :
2014-09-08 02:23:45 +02:00
2014-10-23 18:16:47 +02:00
class vendocrat_WC_Payment_Methods {
2014-09-08 02:23:45 +02:00
2014-10-23 18:16:47 +02:00
/* File var */
private $file;
2014-09-08 02:23:45 +02:00
2014-10-23 18:16:47 +02:00
/* Basic vars */
public $version;
public $plugin_url;
public $plugin_dir;
/* Payment methods */
public $available_methods;
2014-09-22 01:02:13 +02:00
2014-09-08 02:23:45 +02:00
/**
* Constructor
*
* @since 2014-08-15
2014-09-22 01:02:13 +02:00
* @version 2014-09-22
2014-09-08 02:23:45 +02:00
**************************************************/
2014-10-23 18:16:47 +02:00
function __construct( $file ) {
// setup dir/uri
$this->file = $file;
$this->plugin_url = trailingslashit( plugins_url( '', $plugin = $file ) );
$this->plugin_dir = trailingslashit( dirname( $file ) );
2014-09-08 02:23:45 +02:00
2014-10-23 18:16:47 +02:00
// definitions
$this->defines();
2014-09-08 02:23:45 +02:00
2014-10-23 18:16:47 +02:00
// load functions and classes
2014-09-08 02:23:45 +02:00
$this->load_functions();
$this->load_classes();
// load text domain
2014-10-23 18:16:47 +02:00
$this->load_plugin_textdomain();
2014-09-08 02:23:45 +02:00
2014-10-23 18:16:47 +02:00
$this->available_methods = array(
'amazon' => 'Amazon',
'american-express' => 'American Express',
'atm' => 'ATM',
'bank-transfer' => __( 'Bank Transfer', 'woocommerce-payment-methods' ),
'bankomat' => 'Bankomat',
'bitcoin' => 'Bitcoin',
'braintree' => 'Braintree',
'carta-si' => 'Carta Si',
'cash' => __( 'Cash', 'woocommerce-payment-methods' ),
'cash-on-delivery' => __( 'Cash on Delivery', 'woocommerce-payment-methods' ),
'cb' => 'CB',
'cirrus' => 'Cirrus',
2014-12-17 03:36:41 +01:00
// 'cheque' => __( 'Pay with Cheque', 'woocommerce-payment-methods' ),
2014-10-23 18:16:47 +02:00
'clickandbuy' => 'ClickAndBuy',
'credit-card' => __( 'Credit Card', 'woocommerce-payment-methods' ),
'diners' => 'Diners Club',
'discover' => 'Discover',
'ec' => 'EC (Electronic Cash)',
'eps' => 'Eps',
'fattura' => __( 'Invoice', 'woocommerce-payment-methods' ),
'facture' => __( 'Invoice', 'woocommerce-payment-methods' ),
'flattr' => 'Flattr',
'giropay' => 'Giropay',
'gittip' => 'Gittip',
'google-wallet' => 'Google Wallet',
'ideal' => 'Ideal',
'invoice' => __( 'Invoice', 'woocommerce-payment-methods' ),
'jcb' => 'JCB',
'maestro' => 'Maestro',
'mastercard' => 'MasterCard',
'mastercard-securecode' => 'MasterCard Securecode',
'ogone' => 'Ogone',
'paybox' => 'Paybox',
'paylife' => 'Paylife',
2014-11-17 09:48:25 +00:00
'paymill' => 'Paymill',
2014-10-23 18:16:47 +02:00
'paypal' => 'PayPal',
'paysafecard' => 'paysafecard',
'postepay' => 'postepay',
'quick' => 'Quick',
'invoice' => __( 'Invoice', 'woocommerce-payment-methods' ),
'ripple' => 'Ripple',
'skrill' => 'Skrill',
'sofort' => 'SofortÜberweisung',
'square' => 'Square',
'stripe' => 'Stripe',
'truste' => 'Truste',
'unionpay' => 'Unionpay',
'verified-by-visa' => 'Verified By Visa',
'verisign' => 'Verisign',
'visa' => 'Visa',
'visa-electron' => 'Visa Electron',
'western-union' => 'Western Union',
'wirecard' => 'Wirecard',
);
2014-09-22 01:02:13 +02:00
2014-09-08 02:23:45 +02:00
// scripts and styles
if ( ! is_admin() ) :
add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_styles' ) );
add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
endif;
// register widgets
add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
// add shortcode
add_shortcode( 'v_woo_payment_methods', array( &$this, 'get_payment_methods' ) );
2014-10-26 03:42:48 +01:00
add_shortcode( 'wc_payment_methods', array( &$this, 'get_payment_methods' ) );
2014-09-08 02:23:45 +02:00
}
/**
2014-10-23 18:16:47 +02:00
* Definitions
2014-09-08 02:23:45 +02:00
*
* @return void
2014-10-23 18:16:47 +02:00
*
* @since 2014-09-22
* @version 2014-09-22
2014-09-08 02:23:45 +02:00
**************************************************/
2014-10-23 18:16:47 +02:00
function defines() {
// Plugin
define( 'WC_PAYMENT_METHODS_DIR', $this->plugin_dir );
define( 'WC_PAYMENT_METHODS_URI', $this->plugin_url );
// Assets
define( 'WC_PAYMENT_METHODS_CSS_URI', trailingslashit( WC_PAYMENT_METHODS_URI . 'assets/css' ) );
define( 'WC_PAYMENT_METHODS_IMG_URI', trailingslashit( WC_PAYMENT_METHODS_URI . 'assets/img' ) );
2014-09-08 02:23:45 +02:00
}
/**
2014-10-23 18:16:47 +02:00
* Load functions
2014-09-08 02:23:45 +02:00
*
* @return void
*
* @since 2014-09-07
* @version 2014-09-07
**************************************************/
function load_functions() {}
/**
2014-10-23 18:16:47 +02:00
* Load classes
2014-09-08 02:23:45 +02:00
*
* @return void
*
* @since 2014-09-07
* @version 2014-09-07
**************************************************/
function load_classes() {}
2014-10-23 18:16:47 +02:00
/**
* Load theme textdomain
*
* @return void
*
* @since 2014-09-08
2014-10-23 18:51:37 +02:00
* @version 2014-10-23
2014-10-23 18:16:47 +02:00
**************************************************/
public function load_plugin_textdomain() {
$locale = apply_filters( 'plugin_locale', get_locale(), 'woocommerce-payment-methods' );
$dir = trailingslashit( WP_LANG_DIR );
/**
* Frontend/global Locale. Looks in:
* - WP_LANG_DIR/woocommerce-payment-methods/woocommerce-payment-methods-LOCALE.mo
* - woocommerce-payment-methods/languages/woocommerce-payment-methods-LOCALE.mo (which if not found falls back to:)
* - WP_LANG_DIR/plugins/woocommerce-payment-methods-LOCALE.mo
*/
load_textdomain( 'woocommerce-payment-methods', $dir .'woocommerce-payment-methods/woocommerce-payment-methods-'. $locale .'.mo' );
load_plugin_textdomain( 'woocommerce-payment-methods', false, plugin_basename( $this->plugin_dir ) .'/languages/' );
}
2014-09-08 02:23:45 +02:00
/**
* Enqueue Styles
*
* @return void
*
* @since 2014-09-07
2014-09-22 01:02:13 +02:00
* @version 2014-09-21
2014-09-08 02:23:45 +02:00
**************************************************/
function enqueue_styles() {
2014-09-22 01:02:13 +02:00
if ( ! wp_style_is( 'vendocrat-paymentfont', 'registered' ) ) {
2014-10-23 18:16:47 +02:00
wp_register_style( 'vendocrat-paymentfont', WC_PAYMENT_METHODS_CSS_URI .'paymentfont.min.css', array(), false, 'all' );
2014-09-08 02:23:45 +02:00
}
2014-09-22 01:02:13 +02:00
wp_enqueue_style( 'vendocrat-paymentfont' );
2014-09-08 02:23:45 +02:00
2014-12-17 03:36:41 +01:00
wp_register_style( 'payment-methods', WC_PAYMENT_METHODS_CSS_URI .'payment-methods.min.css', array(), false, 'all' );
2014-09-22 01:02:13 +02:00
wp_enqueue_style( 'payment-methods' );
2014-09-08 02:23:45 +02:00
}
/**
* Enqueue Scripts
*
* @return void
*
* @since 2014-09-07
* @version 2014-09-07
**************************************************/
function enqueue_scripts() {}
/**
* Register Widgets
*
* @return void
*
* @since 2014-09-07
* @version 2014-09-08
**************************************************/
function register_widgets() {
2014-10-23 18:16:47 +02:00
require_once WC_PAYMENT_METHODS_DIR .'classes/class-widget-wc-payment-methods.php';
register_widget( 'vendocrat_Widget_WC_Payment_Methods' );
2014-09-22 01:02:13 +02:00
}
2014-09-08 02:23:45 +02:00
/**
* Woo Accepted Payment Methods
*
* @since 2014-09-07
2014-09-22 01:02:13 +02:00
* @version 2014-09-21
2014-09-08 02:23:45 +02:00
**************************************************/
function get_payment_methods( $atts = array(), $content = null ) {
extract(
shortcode_atts(
array(
2014-09-22 01:02:13 +02:00
'methods' => false, // comma separated list of payment methods icon slugs to be displayed, see http://paymentfont.io for available icons (new since 0.2.0)
2014-09-15 03:19:28 +02:00
'style' => 'default', // default, inverse, o/outline
'tooltip' => false, // adds data attributes to icon to be used for diplaying tooltips (made for Bootstrap)
'placement' => 'bottom', // set tooltip placement (new since 0.1.2)
'xclass' => false, // add any extra classes, seperated by a space
2014-09-08 02:23:45 +02:00
), $atts
)
);
$class = 'payment-methods';
$class.= ($style) ? ' payment-methods-'. $style : '';
$class.= ($xclass) ? ' '. $xclass : '';
// use the passed methods array if it's not empty, otherwhise use available gateways/methods
2014-09-22 01:02:13 +02:00
if ( ! $methods ) {
2014-09-08 02:23:45 +02:00
$gateways = $this->get_available_gateways();
2014-09-22 01:02:13 +02:00
$methods = $gateways['methods'];
2014-09-08 02:23:45 +02:00
}
2014-09-22 01:02:13 +02:00
if ( $methods ) {
$methods = explode( ',', $methods );
foreach ( $methods as $key => $slug ) {
if ( $slug )
$methods[$slug] = $slug;
2014-09-08 02:23:45 +02:00
}
2014-09-22 01:02:13 +02:00
$methods = array_flip( $methods );
2014-09-08 02:23:45 +02:00
}
2014-09-22 01:02:13 +02:00
if ( count($methods) > 0 ) {
// remove duplicate methods
$methods = array_unique($methods);
2014-09-08 02:23:45 +02:00
2014-09-22 01:02:13 +02:00
// sort array
ksort($methods);
// let the magic happen
$icons = '';
foreach ( $methods as $slug ) {
$icon = '';
// continue if we have no corresponding icon
2014-10-23 18:16:47 +02:00
if ( ! array_key_exists ( $slug, $this->available_methods ) )
2014-09-22 01:02:13 +02:00
continue;
// retrieve title
2014-10-23 18:16:47 +02:00
$title = $this->available_methods[$slug];
2014-09-22 01:02:13 +02:00
// build icon class
$iclass = 'pf pf-'. $slug .' '. $slug;
// icon markup
$icon = '<i';
$icon.= ($iclass) ? ' class="'. esc_attr( trim($iclass) ) .'"' : '';
$icon.= ($title) ? ' title="'. esc_attr( trim($title) ) .'"' : '';
$icon.= ($tooltip AND $placement) ? ' data-toggle="tooltip" data-placement="'. $placement .'"' : '';
$icon.= '></i>';
// wrap in list item tags and append to $icons
$icons.= '<li>'. $icon .'</li>';
}
// return $output if we have icons
if ( $icons ) {
$output = '<ul';
$output.= ($class) ? ' class="'. esc_attr( trim($class) ) .'"' : '';
$output.= '>'. $icons .'</ul>';
return $output;
}
}
2014-09-08 02:23:45 +02:00
}
/**
* Get available gateways
*
* @since 2014-09-07
* @version 2014-09-08
**************************************************/
function get_available_gateways() {
$gateways = array();
2014-09-22 01:02:13 +02:00
$methods = '';
2014-09-08 02:23:45 +02:00
if ( $available_gateways = WC()->payment_gateways->get_available_payment_gateways() ) {
foreach ( $available_gateways as $gateway ) {
$gateway_id = $gateway->id;
$gateway_title = $gateway->get_title();
$gateway_desc = $gateway->get_description();
$gateway_icon = $gateway->get_icon();
switch ( $gateway_id ) {
case 'bacs' :
2014-09-22 01:02:13 +02:00
$methods.= ' bank-transfer';
2014-09-08 02:23:45 +02:00
break;
case 'cheque' :
2014-09-22 01:02:13 +02:00
$methods.= ' cheque';
2014-09-08 02:23:45 +02:00
break;
2014-11-17 09:48:25 +00:00
case 'paymill' :
$methods.= ' paymill';
$methods.= ' credit-card';
$methods.= ' visa';
$methods.= ' mastercard';
$methods.= ' american-express';
$methods.= ' discover';
$methods.= ' diners';
$methods.= ' jcb';
break;
2014-09-08 02:23:45 +02:00
case 'paypal' :
2014-10-23 18:16:47 +02:00
$methods.= ' credit-card';
2014-09-22 01:02:13 +02:00
$methods.= ' paypal';
$methods.= ' visa';
$methods.= ' mastercard';
$methods.= ' american-express';
$methods.= ' discover';
$methods.= ' diners';
$methods.= ' jcb';
2014-09-08 02:23:45 +02:00
break;
case 'stripe' :
2014-09-22 01:02:13 +02:00
$methods.= ' stripe';
$methods.= ' visa';
$methods.= ' mastercard';
$methods.= ' american-express';
$methods.= ' discover';
$methods.= ' diners';
$methods.= ' jcb';
2014-09-08 02:23:45 +02:00
break;
case 'wirecard' :
2014-10-23 18:16:47 +02:00
$options = get_option('woocommerce_wirecard_settings');
2014-12-17 03:36:41 +01:00
if ( array_key_exists( 'paymenttype_available', $options ) AND is_array( $options['paymenttype_available'] ) ) {
2014-10-23 18:16:47 +02:00
$wirecard_gateways = $options['paymenttype_available'];
} else {
$wirecard_gateways = array();
}
2014-12-17 03:36:41 +01:00
if ( array_key_exists( 'subs_paymenttype_options', $options ) AND is_array( $options['subs_paymenttype_options'] ) ) {
2014-10-23 18:16:47 +02:00
$wirecard_gateways_subscription = $options['subs_paymenttype_options'];
} else {
$wirecard_gateways_subscription = array();
}
2014-11-17 09:48:25 +00:00
2014-10-23 18:16:47 +02:00
$wirecard_gateways = array_merge( $wirecard_gateways, $wirecard_gateways_subscription );
if ( count($wirecard_gateways) > 0 ) {
foreach ( $wirecard_gateways as $wirecard_gateway ) {
$wirecard_gateway = strtolower( $wirecard_gateway );
switch ( $wirecard_gateway ) {
case 'select' :
break;
case 'ccard' :
$methods.= ' credit-card';
$methods.= ' visa';
$methods.= ' mastercard';
break;
case 'idl' :
$methods.= ' ideal';
break;
2014-11-17 09:48:25 +00:00
case 'paymill' :
$methods.= ' paymill';
$methods.= ' credit-card';
$methods.= ' visa';
$methods.= ' mastercard';
$methods.= ' american-express';
$methods.= ' discover';
$methods.= ' diners';
$methods.= ' jcb';
break;
2014-10-23 18:16:47 +02:00
case 'paypal' :
$methods.= ' credit-card';
$methods.= ' paypal';
$methods.= ' visa';
$methods.= ' mastercard';
$methods.= ' american-express';
$methods.= ' discover';
$methods.= ' diners';
$methods.= ' jcb';
break;
case 'pbx' :
$methods.= ' paybox';
break;
case 'psc' :
$methods.= ' paysafecard';
break;
case 'skrilldirect' :
case 'skrillwallet' :
$methods.= ' skrill';
break;
case 'sofortueberweisung' :
$methods.= ' sofort';
$methods.= ' bank-transfer';
break;
case 'elv' :
case 'przelewy24' :
case 'moneta' :
case 'c2p' :
case 'bancontact_mistercash' :
case 'przelewy24' :
case 'installment' :
case 'poli' :
case 'ekonto' :
case 'instantbank' :
case 'mpass' :
break;
default :
$methods.= ' '. $wirecard_gateway;
break;
}
}
}
2014-09-08 02:23:45 +02:00
break;
case 'ClickAndBuy' :
case 'clickandbuy' :
2014-09-22 01:02:13 +02:00
$methods.= ' clickandbuy';
$methods.= ' bank-transfer';
2014-09-08 02:23:45 +02:00
break;
case 'sofortgateway' :
2014-09-22 01:02:13 +02:00
$methods.= ' sofort';
$methods.= ' bank-transfer';
2014-09-08 02:23:45 +02:00
break;
case 'amazon' :
2014-12-17 03:36:41 +01:00
case 'amazon_fps' :
2014-09-22 01:02:13 +02:00
$methods.= ' amazon';
2014-09-08 02:23:45 +02:00
break;
case 'google' :
case 'wallet' :
case 'google-wallet' :
2014-09-22 01:02:13 +02:00
$methods.= ' clickandbuy';
2014-09-08 02:23:45 +02:00
break;
case 'bitpay' :
case 'coinbase' :
case 'bitcoin' :
2014-09-22 01:02:13 +02:00
$methods.= ' bitcoin';
2014-09-08 02:23:45 +02:00
break;
case 'cash_on_delivery' :
2014-09-22 01:02:13 +02:00
$methods.= ' cash-on-delivery';
2014-09-08 02:23:45 +02:00
break;
default :
break;
}
2014-09-22 01:02:13 +02:00
$methods = str_replace( ' ', ',', trim($methods) );
2014-09-08 02:23:45 +02:00
$gateways[$gateway_id] = array(
'id' => $gateway_id,
'title' => $gateway_title,
'desc' => $gateway_desc,
'icon' => $gateway_icon,
);
}
}
// add methods array to gateways array
$gateways['methods'] = $methods;
return $gateways;
}
} // END Class
2014-10-23 18:16:47 +02:00
/**
* Output payment methods
*
* @since 2014-09-08
* @version 2014-10-23
**************************************************/
function wc_payment_methods( $atts = array() ) {
global $vendocrat_wc_payment_methods;
echo $vendocrat_wc_payment_methods->get_payment_methods( $atts );
}
2014-09-08 02:23:45 +02:00
/**
* Output payment methods
*
2014-10-23 18:16:47 +02:00
* @deprecated 2014-10-23
2014-09-08 02:23:45 +02:00
* @since 2014-09-08
* @version 2014-09-08
**************************************************/
function v_woo_payment_methods( $atts = array() ) {
2014-10-23 18:16:47 +02:00
wc_payment_methods( $atts );
2014-09-08 02:23:45 +02:00
}
endif;
/*
2014-09-22 01:28:22 +02:00
* E fatto!
2014-09-08 02:23:45 +02:00
*/