diff --git a/src/lemonway/includes/class-wc-gateway-lemonway-ideal-request.php b/src/lemonway/includes/class-wc-gateway-lemonway-ideal-request.php index 0f78118..303bcd6 100644 --- a/src/lemonway/includes/class-wc-gateway-lemonway-ideal-request.php +++ b/src/lemonway/includes/class-wc-gateway-lemonway-ideal-request.php @@ -2,65 +2,65 @@ require_once('class-wc-gateway-lemonway-request.php'); class WC_Gateway_Lemonway_Ideal_Request extends WC_Gateway_Lemonway_Request { - /** - * Constructor. - * @param WC_Gateway_Lemonway_Ideal $gateway - */ - public function __construct( $gateway ) { - $this->gateway = $gateway; - $this->notify_url = WC()->api_request_url( 'WC_Gateway_Lemonway_Ideal' ); - } + /** + * Constructor. + * @param WC_Gateway_Lemonway_Ideal $gateway + */ + public function __construct( $gateway ) { + $this->gateway = $gateway; + $this->notify_url = WC()->api_request_url( 'WC_Gateway_Lemonway_Ideal' ); + } - /** - * Get the Lemonway Webkit request URL for an order. - * @param WC_Order $order - * @return string - */ - public function get_request_url( $order) { - //Build args with the order - $amount = $order->get_total(); - //$amountCom = $amount; + /** + * Get the Lemonway Webkit request URL for an order. + * @param WC_Order $order + * @return string + */ + public function get_request_url( $order) { + //Build args with the order + $amount = $order->get_total(); + //$amountCom = $amount; $amountCom = 0; - $issuerId = $_POST['issuerId']; - - /*if( function_exists( 'is_plugin_active' ) ) { - if ( is_plugin_active( 'lemonwaymkt/lemonwaymkt.php' ) ) { - //@TODO manage mixted cart - - //Keep only subtotal for vendors because webkul plugin work like this :-( - $amountCom = $order->get_total() - $order->get_subtotal(); - } - }*/ - - $comment = get_bloginfo( 'name' ) . " - " . sprintf(__('Order #%s by %s %s %s', LEMONWAY_IDEAL_TEXT_DOMAIN), $order->get_order_number(), $order->billing_last_name, $order->billing_first_name, $order->billing_email); - $returnUrl = ''; - $params = array( - 'wallet' => $this->gateway->getMerchantWalletId(), - 'amountTot' => $this->formatAmount($amount), - 'amountCom' => $this->formatAmount($amountCom), - 'issuerId' => $issuerId, - 'comment' => $comment, - 'returnUrl' => $this->notify_url, - 'autoCommission' => 1 - ); + $issuerId = $_POST['issuerId']; + + /*if( function_exists( 'is_plugin_active' ) ) { + if ( is_plugin_active( 'lemonwaymkt/lemonwaymkt.php' ) ) { + //@TODO manage mixted cart + + //Keep only subtotal for vendors because webkul plugin work like this :-( + $amountCom = $order->get_total() - $order->get_subtotal(); + } + }*/ + + $comment = get_bloginfo( 'name' ) . " - " . sprintf(__('Order #%s by %s %s %s',LEMONWAY_IDEAL_TEXT_DOMAIN),$order->get_order_number(), $order->billing_last_name,$order->billing_first_name,$order->billing_email); + $returnUrl = ''; + $params = array( + 'wallet' => $this->gateway->getMerchantWalletId(), + 'amountTot' => $this->formatAmount($amount), + 'amountCom' => $this->formatAmount($amountCom), + 'issuerId' => $issuerId, + 'comment' => $comment, + 'returnUrl' => $this->notify_url, + 'autoCommission' => 1 + ); - WC_Gateway_Lemonway_Ideal::log(print_r($params, true)); - - //Call APi MoneyInIdealInit in correct MODE with the args - $idealInit = $this->gateway->getDirectkit()->MoneyInIdealInit($params); - - WC_Gateway_Lemonway_Ideal::log(print_r($idealInit, true)); + WC_Gateway_Lemonway_Ideal::log(print_r($params, true)); + + //Call APi MoneyInIdealInit in correct MODE with the args + $idealInit = $this->gateway->getDirectkit()->MoneyInIdealInit($params); + + WC_Gateway_Lemonway_Ideal::log(print_r($idealInit, true)); - global $wpdb; + global $wpdb; - $sql = "INSERT INTO `" . $wpdb->prefix . "lemonway_wktoken` (`wktoken`, `id_cart`) VALUES (%s, %d) ON DUPLICATE KEY UPDATE wktoken = %s"; - $sql = $wpdb->prepare($sql, $idealInit->ID, $order->get_order_number(), $idealInit->ID); - $wpdb->query($sql); + $sql = "INSERT INTO `" . $wpdb->prefix . "lemonway_wktoken` (`wktoken`, `id_cart`) VALUES (%s, %d) ON DUPLICATE KEY UPDATE wktoken = %s"; + $sql = $wpdb->prepare($sql, $idealInit->ID, $order->get_order_number(), $idealInit->ID); + $wpdb->query($sql); - $returnUrl = urldecode($idealInit->actionUrl); - - //Return redirect url - return $returnUrl; - } + $returnUrl = urldecode($idealInit->actionUrl); + + //Return redirect url + return $returnUrl; + } } ?> \ No newline at end of file diff --git a/src/lemonway/includes/class-wc-gateway-lemonway-request.php b/src/lemonway/includes/class-wc-gateway-lemonway-request.php index bfe45ce..b6a8452 100644 --- a/src/lemonway/includes/class-wc-gateway-lemonway-request.php +++ b/src/lemonway/includes/class-wc-gateway-lemonway-request.php @@ -1,143 +1,144 @@ gateway = $gateway; - $this->notify_url = WC()->api_request_url( 'WC_Gateway_Lemonway' ); - } - - - /** - * Get the Lemonway Webkit request URL for an order. - * @param WC_Order $order - * @param bool $isTestMode - * @return string - */ - public function get_request_url( $order) { - - $registerCard = $useRegisteredCard = 0; - $useCard = 0; - if(isset($_POST['oneclic'])){ - $oneclic = $_POST['oneclic']; - - switch($oneclic){ - case 'register_card': - $registerCard = $useRegisteredCard = 1; - break; - case 'use_card': - $useCard = 1; - break; - } - } - - //Build args with the order + + /** + * Pointer to gateway making the request. + * @var WC_Gateway_Lemonway + */ + protected $gateway; + + /** + * Endpoint for notification from Lemonway. + * @var string + */ + protected $notify_url; + + /** + * Constructor. + * @param WC_Gateway_Lemonway $gateway + */ + public function __construct( $gateway ) { + $this->gateway = $gateway; + $this->notify_url = WC()->api_request_url( 'WC_Gateway_Lemonway' ); + } + + /** + * Get the Lemonway Webkit request URL for an order. + * @param WC_Order $order + * @param bool $isTestMode + * @return string + */ + public function get_request_url( $order ) { + + $registerCard = $useRegisteredCard = 0; + $useCard = 0; + if (isset($_POST['oneclic'])) { + $oneclic = wc_clean( $_POST['oneclic'] ); + + switch($oneclic) { + case 'register_card': + $registerCard = $useRegisteredCard = 1; + break; + case 'use_card': + $useCard = 1; + break; + } + } + + //Build args with the order - $amount = $order->get_total(); - //$amountCom = $amount; + $amount = $order->get_total(); + //$amountCom = $amount; $amountCom = 0; + + /*if( function_exists( 'is_plugin_active' ) ) { + if ( is_plugin_active( 'lemonwaymkt/lemonwaymkt.php' ) ) { + //@TODO manage mixted cart + + //Keep only subtotal for vendors because webkul plugin work like this :-( + $amountCom = $order->get_total() - $order->get_subtotal(); + } + }*/ + + $comment = get_bloginfo( 'name' ) . " - " . sprintf(__('Order #%s by %s %s %s', LEMONWAY_TEXT_DOMAIN), $order->get_order_number(), $order->billing_last_name, $order->billing_first_name, $order->billing_email); + $returnUrl = ''; - /*if( function_exists( 'is_plugin_active' ) ) { - if ( is_plugin_active( 'lemonwaymkt/lemonwaymkt.php' ) ) { - //@TODO manage mixted cart - - //Keep only subtotal for vendors because webkul plugin work like this :-( - $amountCom = $order->get_total() - $order->get_subtotal(); - } - }*/ - - $comment = get_bloginfo( 'name' ) . " - " . sprintf(__('Order #%s by %s %s %s',LEMONWAY_TEXT_DOMAIN),$order->get_order_number(), $order->billing_last_name, $order->billing_first_name, $order->billing_email); - $returnUrl = ''; + if (!$useCard) { + $params = array( + 'wkToken' => $order->id, + 'wallet' => $this->gateway->get_option(WC_Gateway_Lemonway::WALLET_MERCHANT_ID), + 'amountTot' => $this->formatAmount($amount), + 'amountCom' => $this->formatAmount($amountCom), + 'autoCommission' => 1, + 'comment' => $comment, + 'returnUrl' => $this->notify_url, //esc_url_raw( $this->gateway->get_return_url( $order )), + 'cancelUrl' => esc_url_raw( $order->get_cancel_order_url_raw() ), + 'errorUrl' => esc_url_raw( $order->get_cancel_order_url_raw() ), //@TODO change for a specific error url + 'registerCard' => $registerCard, //For Atos + 'useRegisteredCard' => $useRegisteredCard, //For payline + ); + + WC_Gateway_Lemonway::log(print_r($params, true)); + + //Call APi MoneyInWebInit in correct MODE with the args + $moneyInWeb = $this->gateway->getDirectkit()->MoneyInWebInit($params); + + //Save card ID + if($registerCard || $useRegisteredCard){ + update_user_meta( get_current_user_id(), '_lw_card_id', $moneyInWeb->CARD->ID ); + update_post_meta( $order->id, '_register_card', true ); + WC_Gateway_Lemonway::log(sprintf(__("Card Saved for customer Id %s", LEMONWAY_TEXT_DOMAIN), get_current_user_id())); + } + + WC_Gateway_Lemonway::log(print_r($moneyInWeb, true)); + $returnUrl = $this->gateway->getDirectkit()->formatMoneyInUrl($moneyInWeb->TOKEN, $this->gateway->get_option(WC_Gateway_Lemonway::CSS_URL)); + } + else { //Customer want to use his last card, so we call MoneyInWithCardID directly + + $cardId = get_user_meta(get_current_user_id(), '_lw_card_id', true); + + //call directkit for MoneyInWithCardId + $params = array( - if (!$useCard) { - - - $params = array( - 'wkToken' => $order->id, - 'wallet' => $this->gateway->get_option(WC_Gateway_Lemonway::WALLET_MERCHANT_ID), - 'amountTot' => $this->formatAmount($amount), - 'amountCom' => $this->formatAmount($amountCom), - 'comment' => $comment, - 'returnUrl' => $this->notify_url, //esc_url_raw( $this->gateway->get_return_url( $order )), - 'cancelUrl' => esc_url_raw( $order->get_cancel_order_url_raw() ), - 'errorUrl' => esc_url_raw( $order->get_cancel_order_url_raw() ), //@TODO change for a specific error url - 'autoCommission' => 1, - 'registerCard' => $registerCard, //For Atos - 'useRegisteredCard' => $useRegisteredCard, //For payline - ); - - WC_Gateway_Lemonway::log(print_r($params,true)); - - //Call APi MoneyInWebInit in correct MODE with the args - $moneyInWeb = $this->gateway->getDirectkit()->MoneyInWebInit($params); - - //Save card ID - if($registerCard || $useRegisteredCard){ - update_user_meta( get_current_user_id(), '_lw_card_id', $moneyInWeb->CARD->ID ); - update_post_meta( $order->id, '_register_card', true ); - WC_Gateway_Lemonway::log(sprintf(__("Card Saved for customer Id %s", LEMONWAY_TEXT_DOMAIN), get_current_user_id())); - } - - WC_Gateway_Lemonway::log(print_r($moneyInWeb,true)); - $returnUrl = $this->gateway->getDirectkit()->formatMoneyInUrl($moneyInWeb->TOKEN,$this->gateway->get_option(WC_Gateway_Lemonway::CSS_URL)); - } - else{ //Customer want to use his last card, so we call MoneyInWithCardID directly - - $cardId = get_user_meta(get_current_user_id(),'_lw_card_id',true); - - //call directkit for MoneyInWithCardId - $params = array( - 'wkToken' => $order->id, - 'wallet' => $this->gateway->get_option(WC_Gateway_Lemonway::WALLET_MERCHANT_ID), - 'amountTot' => $this->formatAmount($amount), - 'amountCom' => $this->formatAmount($amountCom), - 'comment' => $comment . " -- " .sprintf(__('Oneclic mode (card id: %s)', LEMONWAY_TEXT_DOMAIN), $cardId), - 'autoCommission' => 1, - 'cardId' => $cardId - ); - - WC_Gateway_Lemonway::log(print_r($params,true)); - - $operation = $this->gateway->getDirectkit()->MoneyInWithCardId($params); - - WC_Gateway_Lemonway::log(print_r($operation,true)); - - if($operation->STATUS == "3"){ - $returnUrl = $this->gateway->get_return_url($order); - } - else{ - throw new Exception(__('Error during payment',LEMONWAY_TEXT_DOMAIN)); - } - - - } - - //Return redirect url - return $returnUrl; - - - } - - protected function formatAmount($amount){ - return sprintf("%.2f" ,(float)$amount); - } - + 'wkToken' => $order->id, + 'wallet' => $this->gateway->get_option(WC_Gateway_Lemonway::WALLET_MERCHANT_ID), + 'amountTot' => $this->formatAmount($amount), + 'amountCom' => $this->formatAmount($amountCom), + 'autoCommission' => 1, + 'comment' => $comment . " -- " . sprintf(__('Oneclic mode (card id: %s)', LEMONWAY_TEXT_DOMAIN), $cardId), + 'cardId' => $cardId + ); + + WC_Gateway_Lemonway::log(print_r($params, true)); + + $operation = $this->gateway->getDirectkit()->MoneyInWithCardId($params); + + WC_Gateway_Lemonway::log(print_r($operation, true)); + + if($operation->STATUS == "3") { + + $transaction_id = $operation->ID; + //Set transaction id to POST array. Needed on notif handler + + $_POST['response_transactionId'] = $transaction_id; + + //Process order status + $this->gateway->getNotifhandler()->valid_response($order); + + //Return to original wc success page + $returnUrl = $this->gateway->get_return_url($order); + } + else { + throw new Exception(__('Error during payment', LEMONWAY_TEXT_DOMAIN)); + } + } + + //Return redirect url + return $returnUrl; + } + + protected function formatAmount($amount){ + return sprintf("%.2f", (float)$amount); + } } \ No newline at end of file diff --git a/src/lemonway/includes/class-wc-gateway-lemonway-sofort-request.php b/src/lemonway/includes/class-wc-gateway-lemonway-sofort-request.php index 6b80748..03e7fd6 100644 --- a/src/lemonway/includes/class-wc-gateway-lemonway-sofort-request.php +++ b/src/lemonway/includes/class-wc-gateway-lemonway-sofort-request.php @@ -2,59 +2,59 @@ require_once('class-wc-gateway-lemonway-request.php'); class WC_Gateway_Lemonway_Sofort_Request extends WC_Gateway_Lemonway_Request { - /** - * Constructor. - * @param WC_Gateway_Lemonway_Sofort $gateway - */ - public function __construct( $gateway ) { - $this->gateway = $gateway; - $this->notify_url = WC()->api_request_url( 'WC_Gateway_Lemonway_Sofort' ); - } + /** + * Constructor. + * @param WC_Gateway_Lemonway_Sofort $gateway + */ + public function __construct( $gateway ) { + $this->gateway = $gateway; + $this->notify_url = WC()->api_request_url( 'WC_Gateway_Lemonway_Sofort' ); + } - /** - * Get the Lemonway Webkit request URL for an order. - * @param WC_Order $order - * @return string - */ - public function get_request_url( $order) { - //Build args with the order - $amount = $order->get_total(); - //$amountCom = $amount; + /** + * Get the Lemonway Webkit request URL for an order. + * @param WC_Order $order + * @return string + */ + public function get_request_url( $order) { + //Build args with the order + $amount = $order->get_total(); + //$amountCom = $amount; $amountCom = 0; + + /*if( function_exists( 'is_plugin_active' ) ) { + if ( is_plugin_active( 'lemonwaymkt/lemonwaymkt.php' ) ) { + //@TODO manage mixted cart + + //Keep only subtotal for vendors because webkul plugin work like this :-( + $amountCom = $order->get_total() - $order->get_subtotal(); + } + }*/ + + $comment = get_bloginfo( 'name' ) . " - " . sprintf(__('Order #%s by %s %s %s', LEMONWAY_SOFORT_TEXT_DOMAIN), $order->get_order_number(), $order->billing_last_name, $order->billing_first_name, $order->billing_email); + $returnUrl = ''; - /*if( function_exists( 'is_plugin_active' ) ) { - if ( is_plugin_active( 'lemonwaymkt/lemonwaymkt.php' ) ) { - //@TODO manage mixted cart - - //Keep only subtotal for vendors because webkul plugin work like this :-( - $amountCom = $order->get_total() - $order->get_subtotal(); - } - }*/ - - $comment = get_bloginfo( 'name' ) . " - " . sprintf(__('Order #%s by %s %s %s', LEMONWAY_SOFORT_TEXT_DOMAIN), $order->get_order_number(), $order->billing_last_name, $order->billing_first_name, $order->billing_email); - $returnUrl = ''; + $params = array( + 'wkToken' => $order->id, + 'wallet' => $this->gateway->getMerchantWalletId(), + 'amountTot' => $this->formatAmount($amount), + 'amountCom' => $this->formatAmount($amountCom), + 'comment' => $comment, + 'returnUrl' => $this->notify_url, + 'autoCommission' => 1 + ); - $params = array( - 'wkToken' => $order->id, - 'wallet' => $this->gateway->getMerchantWalletId(), - 'amountTot' => $this->formatAmount($amount), - 'amountCom' => $this->formatAmount($amountCom), - 'comment' => $comment, - 'returnUrl' => $this->notify_url, - 'autoCommission' => 1 - ); + WC_Gateway_Lemonway_Sofort::log(print_r($params, true)); + + //Call APi MoneyInSofortInit in correct MODE with the args + $sofortInit = $this->gateway->getDirectkit()->MoneyInSofortInit($params); + + WC_Gateway_Lemonway_Sofort::log(print_r($sofortInit, true)); - WC_Gateway_Lemonway_Sofort::log(print_r($params, true)); - - //Call APi MoneyInSofortInit in correct MODE with the args - $sofortInit = $this->gateway->getDirectkit()->MoneyInSofortInit($params); - - WC_Gateway_Lemonway_Sofort::log(print_r($sofortInit, true)); - - $returnUrl = urldecode($sofortInit->actionUrl); - - //Return redirect url - return $returnUrl; - } + $returnUrl = urldecode($sofortInit->actionUrl); + + //Return redirect url + return $returnUrl; + } } ?> \ No newline at end of file diff --git a/src/lemonway/lemonway.php b/src/lemonway/lemonway.php index 4f91692..b12a9db 100644 --- a/src/lemonway/lemonway.php +++ b/src/lemonway/lemonway.php @@ -3,7 +3,7 @@ Plugin Name: Lemonway Plugin URI: https://www.lemonway.com Description: Secured payment solutions for Internet marketplaces, eCommerce, and crowdfunding. Payment API. BackOffice management. Compliance. Regulatory reporting. - Version: 1.1.0 + Version: 1.1.1 Author: Kassim Belghait Author URI: http://www.sirateck.com License: GPL2 @@ -12,23 +12,23 @@ if(!defined('ABSPATH')) exit; // Exit if accessed directly final class Lemonway { - - - /** - * @var Lemonway The single instance of the class - */ - protected static $_instance = null; - - protected $name = "Secured payment solutions for Internet marketplaces, eCommerce, and crowdfunding. Payment API. BackOffice management. Compliance. Regulatory reporting."; - protected $slug = 'lemonway'; - - /** - * Pointer to gateway making the request. - * @var WC_Gateway_Lemonway - */ - protected $gateway; - - const DB_VERSION = '1.0.0'; + + + /** + * @var Lemonway The single instance of the class + */ + protected static $_instance = null; + + protected $name = "Secured payment solutions for Internet marketplaces, eCommerce, and crowdfunding. Payment API. BackOffice management. Compliance. Regulatory reporting."; + protected $slug = 'lemonway'; + + /** + * Pointer to gateway making the request. + * @var WC_Gateway_Lemonway + */ + protected $gateway; + + const DB_VERSION = '1.0.0'; /** @@ -36,45 +36,47 @@ final class Lemonway { */ public function __construct(){ - // Define constants - $this->define_constants(); - - // Check plugin requirements - $this->check_requirements(); - - register_activation_hook( __FILE__, array($this,'lw_install') ); - - add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); - add_action( 'plugins_loaded', array( $this, 'init_gateway' ), 0 ); - add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateway' ) ); - - //Add menu elements - add_action('admin_menu', array($this, 'add_admin_menu'), 57); + // Define constants + $this->define_constants(); + + // Check plugin requirements + $this->check_requirements(); + + register_activation_hook( __FILE__, array($this,'lw_install') ); + + add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'plugin_action_links' ) ); + add_action( 'plugins_loaded', array( $this, 'init_gateway' ), 0 ); + add_filter( 'woocommerce_payment_gateways', array( $this, 'add_gateway' ) ); + + //Add menu elements + add_action('admin_menu', array($this, 'add_admin_menu'), 57); - $this->load_plugin_textdomain(); - + $this->load_plugin_textdomain(); + } /** * Add menu Lemonway */ public function add_admin_menu(){ - add_menu_page( __( 'Lemonway', LEMONWAY_TEXT_DOMAIN ),__( 'Lemonway ', LEMONWAY_TEXT_DOMAIN ), 'manage_product_terms', $this->slug, null, null, '58' ); - add_submenu_page($this->slug, __( 'Moneyout ', LEMONWAY_TEXT_DOMAIN ), __( 'Moneyout ', LEMONWAY_TEXT_DOMAIN ), 'manage_product_terms', $this->slug, array($this, 'moneyout_html')); - add_submenu_page($this->slug, __( 'Configuration ', LEMONWAY_TEXT_DOMAIN ), __( 'Configuration ', LEMONWAY_TEXT_DOMAIN ), 'manage_product_terms', $this->slug . 'configuration', array($this, 'redirect_configuration')); + + add_menu_page( __( 'Lemonway',LEMONWAY_TEXT_DOMAIN ),__( 'Lemonway ',LEMONWAY_TEXT_DOMAIN ), 'manage_product_terms', $this->slug, null, null, '58' ); + add_submenu_page($this->slug, __( 'Moneyout ',LEMONWAY_TEXT_DOMAIN ), __( 'Moneyout ',LEMONWAY_TEXT_DOMAIN ), 'manage_product_terms', $this->slug, array($this, 'moneyout_html')); + add_submenu_page($this->slug, __( 'Configuration ',LEMONWAY_TEXT_DOMAIN ), __( 'Configuration ',LEMONWAY_TEXT_DOMAIN ), 'manage_product_terms', $this->slug . 'configuration', array($this, 'redirect_configuration')); + } /** * Init Gateway */ public function init_gateway() { - if ( ! class_exists( 'WC_Payment_Gateway' ) ) { - return; - } + if ( ! class_exists( 'WC_Payment_Gateway' ) ) { + return; + } - // Includes - include_once( 'includes/class-wc-gateway-lemonway.php' ); - $this->gateway = new WC_Gateway_Lemonway(); + // Includes + include_once( 'includes/class-wc-gateway-lemonway.php' ); + $this->gateway = new WC_Gateway_Lemonway(); } /** @@ -88,219 +90,210 @@ public function init_gateway() { * - WP_LANG_DIR/plugins/lemonway-LOCALE.mo */ public function load_plugin_textdomain() { - $locale = apply_filters( 'plugin_locale', get_locale(), LEMONWAY_TEXT_DOMAIN ); - $dir = trailingslashit( WP_LANG_DIR ); + $locale = apply_filters( 'plugin_locale', get_locale(), LEMONWAY_TEXT_DOMAIN ); + $dir = trailingslashit( WP_LANG_DIR ); - load_textdomain( LEMONWAY_TEXT_DOMAIN, $dir . 'lemonway/lemonway-' . $locale . '.mo' ); - load_plugin_textdomain( LEMONWAY_TEXT_DOMAIN, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); + load_textdomain( LEMONWAY_TEXT_DOMAIN, $dir . 'lemonway/lemonway-' . $locale . '.mo' ); + load_plugin_textdomain( LEMONWAY_TEXT_DOMAIN, false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); } /** * Add the gateway to methods */ public function add_gateway( $methods ) { - $methods[] = 'WC_Gateway_Lemonway'; - return $methods; + $methods[] = 'WC_Gateway_Lemonway'; + return $methods; } public function redirect_configuration(){ - wp_redirect(admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=wc_gateway_lemonway' ), 301); + wp_redirect(admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=wc_gateway_lemonway' ),301); } public function moneyout_html(){ - echo '

'.get_admin_page_title().'

'; - - $walletId = $this->gateway->getMerchantWalletId(); - if(empty($walletId)){ - echo __('You need to enter your Wallet Id in', LEMONWAY_TEXT_DOMAIN) . '' . __( 'Settings', LEMONWAY_TEXT_DOMAIN ) . ''; - return; - } - - $this->displayFormMoneyout($walletId); - } - - public function displayFormMoneyout($walletId){ - - try { - /** @var $wallet Wallet **/ - $wallet = $this->getWalletDetails($walletId); - } catch (Exception $e) { - echo $e->getMessage(); - return; - } - - if(isset($_POST['amountToPay'])){ - - $amountToPay = (float)str_replace(",", ".", $_POST['amountToPay']); - - if($amountToPay > $wallet->BAL){ - $message = sprintf(__("You can't paid amount upper of your balance amount: %s", LEMONWAY_TEXT_DOMAIN),wc_price($wallet->BAL)); - echo '

' . $message. '

'; - } - elseif($amountToPay <= 0){ - $message = __("Amount must be greater than 0", LEMONWAY_TEXT_DOMAIN); - echo '

' . $message. '

'; - - } - else - { - - $ibanId = 0; - - if(isset($_POST['iban_id']) && is_array($_POST['iban_id'])){ - $ibanId = current($_POST['iban_id']); - $iban = $_POST['iban_' . $ibanId]; - - try { - $params = array( - "wallet" => $wallet->ID, - "amountTot" => sprintf("%.2f" ,$amountToPay), - "amountCom" => sprintf("%.2f" ,(float)0), - "message" => get_bloginfo( 'name' ) . " - " . __("Moneyout from Wordpress module", LEMONWAY_TEXT_DOMAIN), - "ibanId" => $ibanId, - "autoCommission" => 0, - ); - - $op = $this->gateway->getDirectkit()->MoneyOut($params); - - if($op->STATUS == "3"){ - $wallet->BAL = $wallet->BAL - $amountToPay; - $message = sprintf(__("You paid %s to your Iban %s from your wallet %s", LEMONWAY_TEXT_DOMAIN),wc_price($amountToPay),$iban,$wallet->ID); - echo '

' . $message . '

'; - - } - else{ - $message = __("An error occurred. Please contact support.", LEMONWAY_TEXT_DOMAIN); - echo '

' . $message. '

'; - - } - - } catch (Exception $e) { - - echo '

' . $e->getMessage(). '

'; - - } - } - else{ - $message = __('Please select an IBAN at least', LEMONWAY_TEXT_DOMAIN) ; - echo '

' . $message. '

'; - } - } - - } - - - ?> -
-
-

- - - - - - - - - - - - - - - - - - - - - -
- ID ?> -
- BAL)?> -
- NAME ?> -
- EMAIL ?> -
- getStatusLabel() ?> -
-
-
-

- ibans)) :?> - - - ibans as $_iban) : /** @var $_iban Iban */?> - - - - - -
- - - -
- -
-

- %s in Lemonway BO .', LEMONWAY_TEXT_DOMAIN),$wallet->ID,"https://www.lemonway.fr/MbDev/bo") ?> -
- -
- - ibans) && (float)$wallet->BAL > 0) :?> -
-

- - - - - - - - -
- -
- - -
- -
- gateway->getDirectkit(); - - try { - - return $kit->GetWalletDetails(array('wallet' => $walletId)); - - } catch (Exception $e) { - - throw $e; - - } - } + echo '

'.get_admin_page_title().'

'; + + $walletId = $this->gateway->getMerchantWalletId(); + if(empty($walletId)){ + echo __('You need to enter your Wallet Id in',LEMONWAY_TEXT_DOMAIN) . '' . __( 'Settings', LEMONWAY_TEXT_DOMAIN ) . ''; + return; + } + + + $this->displayFormMoneyout($walletId); + + + } + + public function displayFormMoneyout($walletId){ + + try { + /** @var $wallet Wallet **/ + $wallet = $this->getWalletDetails($walletId); + } catch (Exception $e) { + echo esc_html( $e->getMessage() ); + return; + } + + if ( isset( $_POST['amountToPay'] ) && check_admin_referer( 'moneyout_' . $walletId ) ) { + + $amountToPay = (float)str_replace(",", ".", wc_clean( $_POST['amountToPay'] ) ); + + if ($amountToPay > $wallet->BAL) { + $message = sprintf(__("You can't paid amount upper of your balance amount: %s",LEMONWAY_TEXT_DOMAIN), wc_price($wallet->BAL)); + echo '

' . $message. '

'; + } + elseif($amountToPay <= 0) { + $message = __("Amount must be greater than 0",LEMONWAY_TEXT_DOMAIN); + echo '

' . esc_html( $message ). '

'; + + } + else + { + $ibanId = 0; + + if( isset( $_POST['iban_id'] ) && is_array( $_POST['iban_id'] ) && check_admin_referer( 'moneyout_' . $walletId ) ) { + $ibanId = current(wc_clean( $_POST['iban_id'] ) ); + $iban = wc_clean( $_POST['iban_' . $ibanId] ); + + try { + $params = array( + "wallet" => $wallet->ID, + "amountTot" => sprintf("%.2f", $amountToPay), + "amountCom" => sprintf("%.2f", (float)0), + "message" => __("Moneyout from Wordpress Woocommerce module", LEMONWAY_TEXT_DOMAIN), + "ibanId" => $ibanId, + ); + + $op = $this->gateway->getDirectkit()->MoneyOut($params); + + if($op->STATUS == "3"){ + $wallet->BAL = $wallet->BAL - $amountToPay; + $message = sprintf(__("You paid %s to your Iban %s from your wallet %s",LEMONWAY_TEXT_DOMAIN),wc_price($amountToPay), $iban, $wallet->ID); + echo '

' . $message . '

'; + + } + else { + $message = __("An error occurred. Please contact support.",LEMONWAY_TEXT_DOMAIN); + echo '

' . esc_html( $message ) . '

'; + } + + } catch (Exception $e) { + echo '

' . esc_html( $e->getMessage() ) . '

'; + } + } + else { + $message = __('Please select an IBAN at least',LEMONWAY_TEXT_DOMAIN) ; + echo '

' . esc_html( $message ) . '

'; + } + } + } + ?> +
+ ID); ?> +
+

+ + + + + + + + + + + + + + + + + + + + + +
+ ID ) ?> +
+ BAL ) ) ?> +
+ NAME ) ?> +
+ EMAIL ) ?> +
+ getStatusLabel() ) ?> +
+
+
+

+ ibans)) :?> + + + ibans as $_iban) : /** @var $_iban Iban */?> + + + + + +
+ + + +
+ +
+

+ %s in Lemonway BO.', LEMONWAY_TEXT_DOMAIN), esc_html( $wallet->ID )) ?> +
+ +
+ + ibans) && (float)$wallet->BAL > 0) :?> +
+

+ + + + + + + + +
+ +
+ + +
+ +
+ gateway->getDirectkit(); + + try { + return $kit->GetWalletDetails(array('wallet' => $walletId)); + } catch (Exception $e) { + throw $e; + } + } /** * Add relevant links to plugins page @@ -309,10 +302,10 @@ public function getWalletDetails($walletId){ */ public function plugin_action_links( $links ) { - $plugin_links = array( - '' . __( 'Settings', LEMONWAY_TEXT_DOMAIN ) . '', - ); - return array_merge( $plugin_links, $links ); + $plugin_links = array( + '' . __( 'Settings', LEMONWAY_TEXT_DOMAIN ) . '', + ); + return array_merge( $plugin_links, $links ); } /** @@ -325,10 +318,10 @@ public function plugin_action_links( $links ) { * @return Lemonway - Main instance */ public static function instance() { - if ( is_null( self::$_instance ) ) { - self::$_instance = new self(); - } - return self::$_instance; + if ( is_null( self::$_instance ) ) { + self::$_instance = new self(); + } + return self::$_instance; } /** @@ -338,10 +331,10 @@ public static function instance() { */ private function define_constants() { - $woo_version_installed = get_option('woocommerce_version'); - define( 'LEMONWAY_WOOVERSION', $woo_version_installed ); - define( 'LEMONWAY_NAME', $this->name ); - define( 'LEMONWAY_TEXT_DOMAIN', $this->slug ); + $woo_version_installed = get_option('woocommerce_version'); + define( 'LEMONWAY_WOOVERSION', $woo_version_installed ); + define( 'LEMONWAY_NAME', $this->name ); + define( 'LEMONWAY_TEXT_DOMAIN', $this->slug ); } @@ -353,20 +346,20 @@ private function define_constants() { * @return boolean */ private function check_requirements() { - //global $wp_version, $woocommerce; + //global $wp_version, $woocommerce; - require_once(ABSPATH.'/wp-admin/includes/plugin.php'); + require_once(ABSPATH.'/wp-admin/includes/plugin.php'); - //@TODO version compare + //@TODO version compare - if( function_exists( 'is_plugin_active' ) ) { - if ( !is_plugin_active( 'woocommerce/woocommerce.php' ) ) { - add_action('admin_notices', array( &$this, 'alert_woo_not_active' ) ); - return false; - } - } + if( function_exists( 'is_plugin_active' ) ) { + if ( !is_plugin_active( 'woocommerce/woocommerce.php' ) ) { + add_action('admin_notices', array( &$this, 'alert_woo_not_active' ) ); + return false; + } + } - return true; + return true; } @@ -376,9 +369,9 @@ private function check_requirements() { * @access static */ static function alert_woo_not_active() { - echo '

'; - echo sprintf( __('Sorry, %s requires WooCommerce to be installed and activated first. Please install WooCommerce first.', LEMONWAY_TEXT_DOMAIN), LEMONWAY_NAME, admin_url('plugin-install.php?tab=search&type=term&s=WooCommerce') ); - echo '

'; + echo '

'; + echo sprintf( __('Sorry, %s requires WooCommerce to be installed and activated first. Please install WooCommerce first.', LEMONWAY_TEXT_DOMAIN), LEMONWAY_NAME, admin_url('plugin-install.php?tab=search&type=term&s=WooCommerce') ); + echo '

'; } /** @@ -386,118 +379,113 @@ static function alert_woo_not_active() { */ function lw_install(){ - global $wpdb; - $charset_collate = $wpdb->get_charset_collate(); + global $wpdb; + $charset_collate = $wpdb->get_charset_collate(); - $sql = array(); + $sql = array(); - $sql[] = 'CREATE TABLE IF NOT EXISTS `'.$wpdb->prefix.'lemonway_oneclic` ( - `id_oneclic` int(11) NOT NULL AUTO_INCREMENT, - `id_customer` int(11) NOT NULL, - `id_card` int(11) NOT NULL, - `card_num` varchar(30) NOT NULL, - `card_exp` varchar(8) NOT NULL DEFAULT \'\', - `card_type` varchar(20) NOT NULL DEFAULT \'\', - `date_add` datetime NOT NULL, - `date_upd` datetime NOT NULL, - PRIMARY KEY (`id_oneclic`) - ) ENGINE=InnoDB '.$charset_collate.';'; - - $sql[] = 'CREATE TABLE IF NOT EXISTS `'.$wpdb->prefix.'lemonway_moneyout` ( - `id_moneyout` int(11) NOT NULL AUTO_INCREMENT, - `id_lw_wallet` varchar(255) NOT NULL, - `id_customer` int(11) NOT NULL DEFAULT 0, - `id_employee` int(11) NOT NULL DEFAULT 0, - `is_admin` tinyint(1) NOT NULL DEFAULT 0, - `id_lw_iban` int(11) NOT NULL, - `prev_bal` decimal(20,6) NOT NULL, - `new_bal` decimal(20,6) NOT NULL, - `iban` varchar(34) NOT NULL, - `amount_to_pay` decimal(20,6) NOT NULL, - `date_add` datetime NOT NULL, - `date_upd` datetime NOT NULL, - PRIMARY KEY (`id_moneyout`) - ) ENGINE=InnoDB '.$charset_collate.';'; - - $sql[] = 'CREATE TABLE IF NOT EXISTS `'.$wpdb->prefix.'lemonway_iban` ( - `id_iban` int(11) NOT NULL AUTO_INCREMENT, - `id_lw_iban` int(11) NOT NULL, - `id_customer` int(11) NOT NULL, - `id_wallet` varchar(255) NOT NULL, - `holder` varchar(100) NOT NULL, - `iban` varchar(34) NOT NULL, - `bic` varchar(50) NOT NULL DEFAULT \'\', - `dom1` text NOT NULL DEFAULT \'\', - `dom2` text NOT NULL DEFAULT \'\', - `comment` text NOT NULL DEFAULT \'\', - `id_status` int(2) DEFAULT NULL, - `date_add` datetime NOT NULL, - `date_upd` datetime NOT NULL, - PRIMARY KEY (`id_iban`), - UNIQUE KEY (`id_lw_iban`) - ) ENGINE=InnoDB '.$charset_collate.';'; - - $sql[] = "CREATE TABLE IF NOT EXISTS `".$wpdb->prefix."lemonway_wallet` ( - `id_wallet` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Wallet ID', - `id_lw_wallet` varchar(190) NOT NULL COMMENT 'Lemonway Wallet ID', - `id_customer` int(11) NOT NULL COMMENT 'Customer ID', - `is_admin` smallint(6) NOT NULL COMMENT 'Is Admin', - `customer_email` varchar(255) NOT NULL COMMENT 'Email', - `customer_prefix` varchar(100) NOT NULL DEFAULT '' COMMENT 'Prefix', - `customer_firstname` varchar(255) NOT NULL COMMENT 'Firstname', - `customer_lastname` varchar(255) NOT NULL COMMENT 'Lastname', - `billing_address_street` varchar(255) DEFAULT NULL COMMENT 'Street', - `billing_address_postcode` varchar(255) DEFAULT NULL COMMENT 'Postcode', - `billing_address_city` varchar(255) DEFAULT NULL COMMENT 'City', - `billing_address_country` varchar(2) DEFAULT NULL COMMENT 'Country', - `billing_address_phone` varchar(255) DEFAULT NULL COMMENT 'Phone Number', - `billing_address_mobile` varchar(255) DEFAULT NULL COMMENT 'Mobile Number', - `customer_dob` datetime DEFAULT NULL COMMENT 'Dob', - `is_company` smallint(6) DEFAULT NULL COMMENT 'Is company', - `company_name` varchar(255) NOT NULL COMMENT 'Company name', - `company_website` varchar(255) NOT NULL COMMENT 'Company website', - `company_description` text COMMENT 'Company description', - `company_id_number` varchar(255) DEFAULT NULL COMMENT 'Company ID number', - `is_debtor` smallint(6) DEFAULT NULL COMMENT 'Is debtor', - `customer_nationality` varchar(2) DEFAULT NULL COMMENT 'Nationality', - `customer_birth_city` varchar(255) DEFAULT NULL COMMENT 'City of Birth', - `customer_birth_country` varchar(2) DEFAULT NULL COMMENT 'Birth country', - `payer_or_beneficiary` int(11) DEFAULT NULL COMMENT 'Payer or beneficiary', - `is_onetime_customer` smallint(6) NOT NULL COMMENT 'Is One time customer', - `is_default` smallint(6) NOT NULL COMMENT 'Is default', - `status` smallint(6) DEFAULT NULL COMMENT 'Enabled', - `date_add` datetime NOT NULL COMMENT 'Wallet Creation Time', - `date_upd` datetime NOT NULL COMMENT 'Wallet Modification Time', - PRIMARY KEY (`id_wallet`), - UNIQUE KEY (`id_lw_wallet`) - ) ENGINE=InnoDB ".$charset_collate." ;"; - - $sql[] = 'CREATE TABLE IF NOT EXISTS `'.$wpdb->prefix.'lemonway_wktoken` ( - `id_cart_wktoken` int(11) NOT NULL AUTO_INCREMENT, - `id_cart` int(11) NOT NULL, - `wktoken` varchar(190) NOT NULL, - PRIMARY KEY (`id_cart_wktoken`), - UNIQUE KEY `wktoken` (`wktoken`), - UNIQUE KEY `id_cart` (`id_cart`) - ) ENGINE=InnoDB '.$charset_collate.';'; - - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); - - foreach($sql as $q){ - dbDelta( $q ); - } - - add_option( 'lw_db_version', self::DB_VERSION); - - } + $sql[] = 'CREATE TABLE IF NOT EXISTS `'.$wpdb->prefix.'lemonway_oneclic` ( + `id_oneclic` int(11) NOT NULL AUTO_INCREMENT, + `id_customer` int(11) NOT NULL, + `id_card` int(11) NOT NULL, + `card_num` varchar(30) NOT NULL, + `card_exp` varchar(8) NOT NULL DEFAULT \'\', + `card_type` varchar(20) NOT NULL DEFAULT \'\', + `date_add` datetime NOT NULL, + `date_upd` datetime NOT NULL, + PRIMARY KEY (`id_oneclic`) + ) ENGINE=InnoDB '.$charset_collate.';'; + + $sql[] = 'CREATE TABLE IF NOT EXISTS `'.$wpdb->prefix.'lemonway_moneyout` ( + `id_moneyout` int(11) NOT NULL AUTO_INCREMENT, + `id_lw_wallet` varchar(255) NOT NULL, + `id_customer` int(11) NOT NULL DEFAULT 0, + `id_employee` int(11) NOT NULL DEFAULT 0, + `is_admin` tinyint(1) NOT NULL DEFAULT 0, + `id_lw_iban` int(11) NOT NULL, + `prev_bal` decimal(20,6) NOT NULL, + `new_bal` decimal(20,6) NOT NULL, + `iban` varchar(34) NOT NULL, + `amount_to_pay` decimal(20,6) NOT NULL, + `date_add` datetime NOT NULL, + `date_upd` datetime NOT NULL, + PRIMARY KEY (`id_moneyout`) + ) ENGINE=InnoDB '.$charset_collate.';'; + + $sql[] = 'CREATE TABLE IF NOT EXISTS `'.$wpdb->prefix.'lemonway_iban` ( + `id_iban` int(11) NOT NULL AUTO_INCREMENT, + `id_lw_iban` int(11) NOT NULL, + `id_customer` int(11) NOT NULL, + `id_wallet` varchar(255) NOT NULL, + `holder` varchar(100) NOT NULL, + `iban` varchar(34) NOT NULL, + `bic` varchar(50) NOT NULL DEFAULT \'\', + `dom1` text NOT NULL DEFAULT \'\', + `dom2` text NOT NULL DEFAULT \'\', + `comment` text NOT NULL DEFAULT \'\', + `id_status` int(2) DEFAULT NULL, + `date_add` datetime NOT NULL, + `date_upd` datetime NOT NULL, + PRIMARY KEY (`id_iban`), + UNIQUE KEY (`id_lw_iban`) + ) ENGINE=InnoDB '.$charset_collate.';'; + + $sql[] = "CREATE TABLE IF NOT EXISTS `".$wpdb->prefix."lemonway_wallet` ( + `id_wallet` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Wallet ID', + `id_lw_wallet` varchar(190) NOT NULL COMMENT 'Lemonway Wallet ID', + `id_customer` int(11) NOT NULL COMMENT 'Customer ID', + `is_admin` smallint(6) NOT NULL COMMENT 'Is Admin', + `customer_email` varchar(255) NOT NULL COMMENT 'Email', + `customer_prefix` varchar(100) NOT NULL DEFAULT '' COMMENT 'Prefix', + `customer_firstname` varchar(255) NOT NULL COMMENT 'Firstname', + `customer_lastname` varchar(255) NOT NULL COMMENT 'Lastname', + `billing_address_street` varchar(255) DEFAULT NULL COMMENT 'Street', + `billing_address_postcode` varchar(255) DEFAULT NULL COMMENT 'Postcode', + `billing_address_city` varchar(255) DEFAULT NULL COMMENT 'City', + `billing_address_country` varchar(2) DEFAULT NULL COMMENT 'Country', + `billing_address_phone` varchar(255) DEFAULT NULL COMMENT 'Phone Number', + `billing_address_mobile` varchar(255) DEFAULT NULL COMMENT 'Mobile Number', + `customer_dob` datetime DEFAULT NULL COMMENT 'Dob', + `is_company` smallint(6) DEFAULT NULL COMMENT 'Is company', + `company_name` varchar(255) NOT NULL COMMENT 'Company name', + `company_website` varchar(255) NOT NULL COMMENT 'Company website', + `company_description` text COMMENT 'Company description', + `company_id_number` varchar(255) DEFAULT NULL COMMENT 'Company ID number', + `is_debtor` smallint(6) DEFAULT NULL COMMENT 'Is debtor', + `customer_nationality` varchar(2) DEFAULT NULL COMMENT 'Nationality', + `customer_birth_city` varchar(255) DEFAULT NULL COMMENT 'City of Birth', + `customer_birth_country` varchar(2) DEFAULT NULL COMMENT 'Birth country', + `payer_or_beneficiary` int(11) DEFAULT NULL COMMENT 'Payer or beneficiary', + `is_onetime_customer` smallint(6) NOT NULL COMMENT 'Is One time customer', + `is_default` smallint(6) NOT NULL COMMENT 'Is default', + `status` smallint(6) DEFAULT NULL COMMENT 'Enabled', + `date_add` datetime NOT NULL COMMENT 'Wallet Creation Time', + `date_upd` datetime NOT NULL COMMENT 'Wallet Modification Time', + PRIMARY KEY (`id_wallet`), + UNIQUE KEY (`id_lw_wallet`) + ) ENGINE=InnoDB ".$charset_collate." ;"; + + $sql[] = 'CREATE TABLE IF NOT EXISTS `'.$wpdb->prefix.'lemonway_wktoken` ( + `id_cart_wktoken` int(11) NOT NULL AUTO_INCREMENT, + `id_cart` int(11) NOT NULL, + `wktoken` varchar(190) NOT NULL, + PRIMARY KEY (`id_cart_wktoken`), + UNIQUE KEY `wktoken` (`wktoken`), + UNIQUE KEY `id_cart` (`id_cart`) + ) ENGINE=InnoDB '.$charset_collate.';'; - + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); + foreach($sql as $q){ + dbDelta( $q ); + } + add_option( 'lw_db_version', self::DB_VERSION); + } } function LW(){ - return Lemonway::instance(); + return Lemonway::instance(); } LW(); \ No newline at end of file diff --git a/src/lemonway/lemonway_ideal.php b/src/lemonway/lemonway_ideal.php index cfd8666..58b345e 100644 --- a/src/lemonway/lemonway_ideal.php +++ b/src/lemonway/lemonway_ideal.php @@ -3,7 +3,7 @@ Plugin Name: Lemonway IDeal Plugin URI: https://www.lemonway.com Description: Secured payment solutions for Internet marketplaces, eCommerce, and crowdfunding. Payment API. BackOffice management. Compliance. Regulatory reporting. - Version: 1.1.0 + Version: 1.1.1 Author: Dat Pham Author URI: https://www.lemonway.com License: GPL2 diff --git a/src/lemonway/lemonway_sofort.php b/src/lemonway/lemonway_sofort.php index 8139686..e7cfc1b 100644 --- a/src/lemonway/lemonway_sofort.php +++ b/src/lemonway/lemonway_sofort.php @@ -1,9 +1,9 @@ Author URI: https://www.lemonway.com License: GPL2