From bbcdb0e9b7aa021ffe53fd1dbb7301c37b9f8dc0 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Fri, 25 May 2018 16:11:45 +0200 Subject: [PATCH 01/41] (WOO-5) Feature CC/DC: restructured filesystem for scripts and css files. Enabled CSS-File for iFrames. Enabled bookingmodes for CC and DC. --- assets/css/creditCardFrame.css | 43 +++++++++++++++++++ {includes => assets}/js/creditCardFrame.js | 0 .../abstract-wc-heidelpay-payment-gateway.php | 32 +++++++++++--- .../class-wc-heidelpay-gateway-cc.php | 29 ++++++++++--- .../class-wc-heidelpay-gateway-dc.php | 26 ++++++++--- 5 files changed, 114 insertions(+), 16 deletions(-) create mode 100644 assets/css/creditCardFrame.css rename {includes => assets}/js/creditCardFrame.js (100%) diff --git a/assets/css/creditCardFrame.css b/assets/css/creditCardFrame.css new file mode 100644 index 0000000..4d584bc --- /dev/null +++ b/assets/css/creditCardFrame.css @@ -0,0 +1,43 @@ +#paymentFrameForm { + background-color: pink; +} + +.form-row { + +} + +.form-label { + +} + +.verificationInlineHintWrapper { + +} + +.form-input fullWidth { + +} + +.form-select fullWidth { + +} + +.creditCardSymbols { + +} + +.creditCardImage { + +} + +.fillWidth { + +} + +.halfWidth { + +} + + + + diff --git a/includes/js/creditCardFrame.js b/assets/js/creditCardFrame.js similarity index 100% rename from includes/js/creditCardFrame.js rename to assets/js/creditCardFrame.js diff --git a/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php b/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php index e6d92ef..979f638 100644 --- a/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php +++ b/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php @@ -7,7 +7,9 @@ abstract class WC_Heidelpay_Payment_Gateway extends WC_Payment_Gateway { - + /** + * @var $payMethod + */ public $payMethod; protected $name; @@ -31,7 +33,7 @@ public function __construct() // Actions add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); add_action('woocommerce_api_' . strtolower(get_class($this)), array($this, 'callback_handler')); - add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts')); + add_action('wp_enqueue_scripts', array($this, 'enqueue_assets')); } /** @@ -122,16 +124,17 @@ public function init_form_fields() ); } - public function enqueue_scripts() + public function enqueue_assets() { wp_register_script('heidelpay-iFrame', - WC_HEIDELPAY_PLUGIN_URL . '/includes/js/creditCardFrame.js', + WC_HEIDELPAY_PLUGIN_URL . '/assets/js/creditCardFrame.js', [], false, true ); - - wp_enqueue_script('heidelpay-iFrame'); + /*wp_register_style('heidelpay-iFrame', + WC_HEIDELPAY_PLUGIN_URL . '/assets/css/creditCardFrame.css' + );*/ } public function process_payment($order_id) @@ -232,4 +235,21 @@ public function callback_handler() } exit(); } + + /** + * @return array + */ + protected function getBookingSelection () { + return array( + 'title' => __('Bookingmode', 'woocommerce-heidelpay'), + 'type' => 'select', + 'options' => array( + 'DB' => __('Direct debit', 'woocommerce-heidelpay'), + 'PA' => __('Reservation', 'woocommerce-heidelpay') + ), + 'id' => $this->id . '_bookingmode', + 'label' => __('Choose a bookingmode', 'woocommerce-heidelpay'), + 'default' => 'DB' + ); + } } diff --git a/includes/gateways/class-wc-heidelpay-gateway-cc.php b/includes/gateways/class-wc-heidelpay-gateway-cc.php index 264b3bb..7e7ebcc 100644 --- a/includes/gateways/class-wc-heidelpay-gateway-cc.php +++ b/includes/gateways/class-wc-heidelpay-gateway-cc.php @@ -60,6 +60,8 @@ public function init_form_fields() $this->form_fields['user_login']['default'] = '31ha07bc8142c5a171744e5aef11ffd3'; $this->form_fields['user_password']['default'] = '93167DE7'; $this->form_fields['transaction_channel']['default'] = '31HA07BC8142C5A171744F3D6D155865'; + + $this->form_fields['bookingmode'] = $this->getBookingSelection(); } public function payment_fields() @@ -76,6 +78,12 @@ public function after_pay() } } + /** + * @param $order_id + * @param $order + * @throws \Heidelpay\PhpPaymentApi\Exceptions\PaymentFormUrlException + * @throws \Heidelpay\PhpPaymentApi\Exceptions\UndefinedTransactionModeException + */ protected function getIFrame($order_id, $order) { wp_enqueue_script('heidelpay-iFrame'); @@ -86,11 +94,22 @@ protected function getIFrame($order_id, $order) $this->setBasket($order_id); $protocol = $_SERVER['HTTPS'] ? 'https' : 'http'; - - $this->payMethod->debit( - $protocol . '://' . $_SERVER['SERVER_NAME'], // PaymentFrameOrigin - uri of your application like https://dev.heidelpay.com - 'FALSE' - ); + $host = $protocol.'://'.$_SERVER['SERVER_NAME']; + $cssPath = WC_HEIDELPAY_PLUGIN_URL . '/assets/css/creditCardFrame.css'; + + if($this->get_option('bookingmode') === 'PA') { + $this->payMethod->authorize( + $host, // PaymentFrameOrigin - uri of your application like https://dev.heidelpay.com + 'FALSE', + $cssPath + ); + } else { + $this->payMethod->debit( + $host, // PaymentFrameOrigin - uri of your application like https://dev.heidelpay.com + 'FALSE', + $cssPath + ); + } echo '
'; if ($this->payMethod->getResponse()->isSuccess()) { diff --git a/includes/gateways/class-wc-heidelpay-gateway-dc.php b/includes/gateways/class-wc-heidelpay-gateway-dc.php index af90212..2284338 100644 --- a/includes/gateways/class-wc-heidelpay-gateway-dc.php +++ b/includes/gateways/class-wc-heidelpay-gateway-dc.php @@ -45,6 +45,8 @@ public function init_form_fields() { $this->form_fields['user_login']['default'] = '31ha07bc8142c5a171744e5aef11ffd3'; $this->form_fields['user_password']['default'] = '93167DE7'; $this->form_fields['transaction_channel']['default'] = '31HA07BC8142C5A171744F3D6D155865'; + + $this->form_fields['bookingmode'] = $this->getBookingSelection(); } public function payment_fields() @@ -69,12 +71,26 @@ protected function getIFrame($order_id, $order) { $this->setBasket($order_id); $this->setBasket($order_id); - $protokoll = $protokoll = $_SERVER['HTTPS']?'https':'http'; + $protocol = $_SERVER['HTTPS'] ? 'https' : 'http'; + $host = $protocol.'://'.$_SERVER['SERVER_NAME']; + $cssPath = WC_HEIDELPAY_PLUGIN_URL . '/assets/css/creditCardFrame.css'; + + + if($this->get_option('bookingmode') === 'PA') { + $this->payMethod->authorize( + $host, // PaymentFrameOrigin - uri of your application like https://dev.heidelpay.com + 'FALSE', + $cssPath + ); + } else { + $this->payMethod->debit( + $host, // PaymentFrameOrigin - uri of your application like https://dev.heidelpay.com + 'FALSE', + $cssPath + ); + } + - $this->payMethod->debit( - $protokoll.'://'.$_SERVER['SERVER_NAME'], // PaymentFrameOrigin - uri of your application like https://dev.heidelpay.com - 'FALSE' - ); echo ''; if ($this->payMethod->getResponse()->isSuccess()) { From 744739d7f2cc61bc0e67cd1f5218cb7fe850ebd5 Mon Sep 17 00:00:00 2001 From: Florian Evertz Date: Mon, 28 May 2018 16:39:07 +0200 Subject: [PATCH 02/41] add min/max value fields to setting --- .../gateways/class-wc-heidelpay-gateway-ivpg.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/includes/gateways/class-wc-heidelpay-gateway-ivpg.php b/includes/gateways/class-wc-heidelpay-gateway-ivpg.php index 2c66032..477e320 100644 --- a/includes/gateways/class-wc-heidelpay-gateway-ivpg.php +++ b/includes/gateways/class-wc-heidelpay-gateway-ivpg.php @@ -38,6 +38,22 @@ public function init_form_fields() $this->form_fields['user_login']['default'] = '31ha07bc8142c5a171744e5aef11ffd3'; $this->form_fields['user_password']['default'] = '93167DE7'; $this->form_fields['transaction_channel']['default'] = '31HA07BC81856CAD6D8E05CDDE7E2AC8'; + + $this->form_fields['min'] = array( + 'title' => __('Minimum Value', 'woocommerce-heidelpay'), + 'type' => 'text', + 'default' => 100, + 'desc_tip' => true, + + ); + + $this->form_fields['max'] = array( + 'title' => __('Maxmimum Value', 'woocommerce-heidelpay'), + 'type' => 'text', + 'default' => 1000, + 'desc_tip' => true, + ); + } public function payment_fields() From ce6b7427a5f97759858d3045049bb73a2d00cdd9 Mon Sep 17 00:00:00 2001 From: Florian Evertz Date: Wed, 30 May 2018 10:37:03 +0200 Subject: [PATCH 03/41] add restrictions to IVPG - add filter for available payment gateways - remove some deprecated code --- .../abstract-wc-heidelpay-payment-gateway.php | 8 +++-- .../class-wc-heidelpay-gateway-ivpg.php | 31 +++++++++++++++++++ woocommerce-heidelpay.php | 1 - 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php b/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php index 9bbb172..8cfec28 100644 --- a/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php +++ b/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php @@ -29,9 +29,11 @@ public function __construct() $this->instructions = $this->get_option('instructions'); // Actions + add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); add_action('woocommerce_api_' . strtolower(get_class($this)), array($this, 'callback_handler')); add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts')); + } /** @@ -122,6 +124,8 @@ public function init_form_fields() ); } + + public function enqueue_scripts() { wp_register_script('heidelpay-iFrame', @@ -165,8 +169,6 @@ protected function setAuthentification() */ protected function setAsync() { - - wc_get_logger()->log(WC_Log_Levels::DEBUG, $this->getLanguage()); $this->payMethod->getRequest()->async( $this->getLanguage(), // Language code for the Frame get_permalink(wc_get_page_id('shop')) . 'wc-api/' . strtolower(get_class($this)) @@ -232,4 +234,6 @@ public function callback_handler() } exit(); } + + } diff --git a/includes/gateways/class-wc-heidelpay-gateway-ivpg.php b/includes/gateways/class-wc-heidelpay-gateway-ivpg.php index 477e320..e1dc3cc 100644 --- a/includes/gateways/class-wc-heidelpay-gateway-ivpg.php +++ b/includes/gateways/class-wc-heidelpay-gateway-ivpg.php @@ -21,6 +21,8 @@ public function __construct() parent::__construct(); add_action('woocommerce_email_before_order_table', array($this, 'email_instructions'), 10, 3); + + add_filter('woocommerce_available_payment_gateways', array($this, 'unsetIVPG')); } /** @@ -53,7 +55,36 @@ public function init_form_fields() 'default' => 1000, 'desc_tip' => true, ); + } + + public function unsetIVPG($available_gateways) + { + $security = true; + if (!empty(wc()->customer->get_billing_company())) { + $security = false; + } + + if (wc()->customer->get_billing_country() !== 'DE') { + $security = false; + } + + if (wc()->customer->get_billing_address_1() !== wc()->customer->get_shipping_address_1() || + wc()->customer->get_billing_address_2() !== wc()->customer->get_shipping_address_2() || + wc()->customer->get_billing_city() !== wc()->customer->get_shipping_city() || + wc()->customer->get_billing_postcode() !== wc()->customer->get_shipping_postcode() + ) { + $security = false; + } + if (wc()->cart->get_totals()['total'] > $this->settings['max'] || + wc()->cart->get_totals()['total'] < $this->settings['min']) { + $security = false; + } + + if (!$security) { + unset($available_gateways['hp_ivpg']); + } + return $available_gateways; } public function payment_fields() diff --git a/woocommerce-heidelpay.php b/woocommerce-heidelpay.php index 1411fe6..45ae829 100644 --- a/woocommerce-heidelpay.php +++ b/woocommerce-heidelpay.php @@ -132,7 +132,6 @@ public function init() add_filter('woocommerce_payment_gateways', array($this, 'add_gateways')); add_filter('plugin_action_links_' . plugin_basename(__FILE__), array($this, 'plugin_action_links')); - add_filter('woocommerce_get_sections_checkout', array($this, 'filter_gateway_order_admin')); } /** From 499e70f3bbf051d4d30659f649086af53797c36d Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Wed, 30 May 2018 11:19:19 +0200 Subject: [PATCH 04/41] (WOO-5) Feature CC/DC: refactored Creditcard and debitcard. Add iDeal and Paypal --- .../abstract-wc-heidelpay-iframe-gateway.php | 108 ++++++++++++++ .../abstract-wc-heidelpay-payment-gateway.php | 29 ++-- .../class-wc-heidelpay-gateway-cc.php | 136 +----------------- .../class-wc-heidelpay-gateway-dc.php | 126 +--------------- .../class-wc-heidelpay-gateway-idl.php | 116 +++++++++++++++ .../class-wc-heidelpay-gateway-va.php | 76 ++++++++++ woocommerce-heidelpay.php | 10 +- 7 files changed, 329 insertions(+), 272 deletions(-) create mode 100644 includes/abstracts/abstract-wc-heidelpay-iframe-gateway.php create mode 100644 includes/gateways/class-wc-heidelpay-gateway-idl.php create mode 100644 includes/gateways/class-wc-heidelpay-gateway-va.php diff --git a/includes/abstracts/abstract-wc-heidelpay-iframe-gateway.php b/includes/abstracts/abstract-wc-heidelpay-iframe-gateway.php new file mode 100644 index 0000000..904a4d7 --- /dev/null +++ b/includes/abstracts/abstract-wc-heidelpay-iframe-gateway.php @@ -0,0 +1,108 @@ +bookingModes = array( + 'PA' => 'authorize', + 'DB' => 'debit' + ); + } + + public function process_payment($order_id) + { + return $this->performRequest($order_id); + } + + protected function performRequest($order_id) + { + $order = wc_get_order($order_id); + + $order->update_status('pending', __('Awaiting payment', 'woocommerce-heidelpay')); + return [ + 'result' => 'success', + 'redirect' => $order->get_checkout_payment_url(true) + ]; + } + + /** + * Initialise Gateway Settings Form Fields. + */ + public function init_form_fields() + { + parent::init_form_fields(); + + $this->form_fields['security_sender']['default'] = '31HA07BC8142C5A171745D00AD63D182'; + $this->form_fields['user_login']['default'] = '31ha07bc8142c5a171744e5aef11ffd3'; + $this->form_fields['user_password']['default'] = '93167DE7'; + $this->form_fields['transaction_channel']['default'] = '31HA07BC8142C5A171744F3D6D155865'; + + $this->form_fields['bookingmode'] = $this->getBookingSelection(); + } + + public function after_pay() + { + $order_id = wc_get_order_id_by_order_key($_GET['key']); + $order = wc_get_order($order_id); + + if ($order->get_payment_method() === $this->id) { + $this->getIFrame($order_id, $order); + } + } + + /** + * @param $order_id + * @param $order + * @throws \Heidelpay\PhpPaymentApi\Exceptions\PaymentFormUrlException + * @throws \Heidelpay\PhpPaymentApi\Exceptions\UndefinedTransactionModeException + */ + protected function getIFrame( WC_Order $order) + { + wp_enqueue_script('heidelpay-iFrame'); + + $this->setAuthentification(); + $this->setAsync(); + $this->setCustomer($order); + $this->setBasket($order->get_id()); + + $protocol = $_SERVER['HTTPS'] ? 'https' : 'http'; + $host = $protocol . '://' . $_SERVER['SERVER_NAME']; + $cssPath = WC_HEIDELPAY_PLUGIN_URL . '/assets/css/creditCardFrame.css'; + + $bookingaction = $this->getBookingAction(); + + $this->payMethod->$bookingaction( + $host, // PaymentFrameOrigin - uri of your application like https://dev.heidelpay.com + 'FALSE', + $cssPath + ); + + echo ''; + if ($this->payMethod->getResponse()->isSuccess()) { + echo '
'; + } else { + echo get_home_url() . '/wp-content/plugins/woocommerce-heidelpay/vendor/'; + echo '
' . print_r($this->payMethod->getResponse()->getError(), 1) . '
'; + } + echo ''; + echo ''; + } + + public function getBookingAction() { + return $this->bookingModes[$this->get_option('bookingmode')]; + } +} diff --git a/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php b/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php index 206d915..e43727c 100644 --- a/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php +++ b/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php @@ -132,21 +132,29 @@ public function enqueue_assets() false, true ); - /*wp_register_style('heidelpay-iFrame', - WC_HEIDELPAY_PLUGIN_URL . '/assets/css/creditCardFrame.css' - );*/ } + /** + * @param int $order_id + * @return array|mixed + */ public function process_payment($order_id) { $order = wc_get_order($order_id); + $this->prepareRequest($order); + return $this->performRequest($order_id); + } + + /** + * @param $order WC_Order + */ + public function prepareRequest(WC_Order $order) + { $this->setAuthentification(); $this->setAsync(); $this->setCustomer($order); - $this->setBasket($order_id); - - return $this->performRequest($order_id); + $this->setBasket($order->get_id()); } /** @@ -168,8 +176,6 @@ protected function setAuthentification() */ protected function setAsync() { - - wc_get_logger()->log(WC_Log_Levels::DEBUG, $this->getLanguage()); $this->payMethod->getRequest()->async( $this->getLanguage(), // Language code for the Frame get_permalink(wc_get_page_id('shop')) . 'wc-api/' . strtolower(get_class($this)) @@ -184,7 +190,7 @@ public function getLanguage() return 'en'; } - protected function setCustomer($order) + protected function setCustomer(WC_Order $order) { $this->payMethod->getRequest()->customerAddress( $order->get_billing_first_name(), // Given name @@ -236,16 +242,13 @@ public function callback_handler() exit(); } - /** - * @return array - */ protected function getBookingSelection () { return array( 'title' => __('Bookingmode', 'woocommerce-heidelpay'), 'type' => 'select', 'options' => array( 'DB' => __('Direct debit', 'woocommerce-heidelpay'), - 'PA' => __('Reservation', 'woocommerce-heidelpay') + 'PA' => __('Authorization', 'woocommerce-heidelpay') ), 'id' => $this->id . '_bookingmode', 'label' => __('Choose a bookingmode', 'woocommerce-heidelpay'), diff --git a/includes/gateways/class-wc-heidelpay-gateway-cc.php b/includes/gateways/class-wc-heidelpay-gateway-cc.php index 7e7ebcc..4179214 100644 --- a/includes/gateways/class-wc-heidelpay-gateway-cc.php +++ b/includes/gateways/class-wc-heidelpay-gateway-cc.php @@ -7,148 +7,16 @@ /** * credit card */ -require_once(WC_HEIDELPAY_PLUGIN_PATH . '/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php'); +require_once(WC_HEIDELPAY_PLUGIN_PATH . '/includes/abstracts/abstract-wc-heidelpay-iframe-gateway.php'); use Heidelpay\PhpPaymentApi\PaymentMethods\CreditCardPaymentMethod; -class WC_Gateway_HP_CC extends WC_Heidelpay_Payment_Gateway +class WC_Gateway_HP_CC extends WC_Heidelpay_IFrame_Gateway { - - /** @var array Array of locales */ - public $locale; - - public function __construct() - { - parent::__construct(); - add_action('after_woocommerce_pay', array($this, 'after_pay')); - - //add_plugins_page( 'hp_card_payment', 'card payment', 'None', 'None', 'form'); - } - - public function process_payment($order_id) - { - return $this->performRequest($order_id); - } - - protected function performRequest($order_id) - { - $order = wc_get_order($order_id); - - $order->update_status('pending', __('Awaiting payment', 'woocommerce-heidelpay')); - return [ - 'result' => 'success', - 'redirect' => $order->get_checkout_payment_url(true) - ]; - } - public function setPayMethod() { $this->payMethod = new CreditCardPaymentMethod(); $this->id = 'hp_cc'; $this->name = __('Credit Card', 'woocommerce-heidelpay'); } - - /** - * Initialise Gateway Settings Form Fields. - */ - public function init_form_fields() - { - - parent::init_form_fields(); - - $this->form_fields['security_sender']['default'] = '31HA07BC8142C5A171745D00AD63D182'; - $this->form_fields['user_login']['default'] = '31ha07bc8142c5a171744e5aef11ffd3'; - $this->form_fields['user_password']['default'] = '93167DE7'; - $this->form_fields['transaction_channel']['default'] = '31HA07BC8142C5A171744F3D6D155865'; - - $this->form_fields['bookingmode'] = $this->getBookingSelection(); - } - - public function payment_fields() - { - } - - public function after_pay() - { - $order_id = wc_get_order_id_by_order_key($_GET['key']); - $order = wc_get_order($order_id); - - if ($order->get_payment_method() === $this->id) { - $this->getIFrame($order_id, $order); - } - } - - /** - * @param $order_id - * @param $order - * @throws \Heidelpay\PhpPaymentApi\Exceptions\PaymentFormUrlException - * @throws \Heidelpay\PhpPaymentApi\Exceptions\UndefinedTransactionModeException - */ - protected function getIFrame($order_id, $order) - { - wp_enqueue_script('heidelpay-iFrame'); - - $this->setAuthentification(); - $this->setAsync(); - $this->setCustomer($order); - $this->setBasket($order_id); - - $protocol = $_SERVER['HTTPS'] ? 'https' : 'http'; - $host = $protocol.'://'.$_SERVER['SERVER_NAME']; - $cssPath = WC_HEIDELPAY_PLUGIN_URL . '/assets/css/creditCardFrame.css'; - - if($this->get_option('bookingmode') === 'PA') { - $this->payMethod->authorize( - $host, // PaymentFrameOrigin - uri of your application like https://dev.heidelpay.com - 'FALSE', - $cssPath - ); - } else { - $this->payMethod->debit( - $host, // PaymentFrameOrigin - uri of your application like https://dev.heidelpay.com - 'FALSE', - $cssPath - ); - } - - echo '
'; - if ($this->payMethod->getResponse()->isSuccess()) { - echo '
'; - } else { - echo get_home_url() . '/wp-content/plugins/woocommerce-heidelpay/vendor/'; - echo '
' . print_r($this->payMethod->getResponse()->getError(), 1) . '
'; - } - echo ''; - echo '
'; - } - - /** - * Output for the order received page. - * - * @param int $order_id - */ - public function thankyou_page($order_id) - { - - if ($this->instructions) { - echo wpautop(wptexturize(wp_kses_post($this->instructions))); - } - $this->bank_details($order_id); - } - - /** - * Add content to the WC emails. - */ - public function email_instructions($order, $sent_to_admin, $plain_text = false) - { - - if (!$sent_to_admin && 'hp_cc' === $order->get_payment_method() && $order->has_status('on-hold')) { - if ($this->instructions) { - echo wpautop(wptexturize($this->instructions)) . PHP_EOL; - } - $this->bank_details($order->get_id()); - } - } } diff --git a/includes/gateways/class-wc-heidelpay-gateway-dc.php b/includes/gateways/class-wc-heidelpay-gateway-dc.php index 2284338..bcd8c73 100644 --- a/includes/gateways/class-wc-heidelpay-gateway-dc.php +++ b/includes/gateways/class-wc-heidelpay-gateway-dc.php @@ -7,25 +7,11 @@ /** * debit card */ -require_once (WC_HEIDELPAY_PLUGIN_PATH.'/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php'); +require_once(WC_HEIDELPAY_PLUGIN_PATH . '/includes/abstracts/abstract-wc-heidelpay-iframe-gateway.php'); use Heidelpay\PhpPaymentApi\PaymentMethods\DebitCardPaymentMethod; -class WC_Gateway_HP_DC extends WC_Heidelpay_Payment_Gateway { - - /** @var array Array of locales */ - public $locale; - - public function __construct() - { - parent::__construct(); - add_action('after_woocommerce_pay', array($this,'after_pay')); - } - - public function process_payment($order_id) - { - return $this->performRequest($order_id); - } +class WC_Gateway_HP_DC extends WC_Heidelpay_IFrame_Gateway { public function setPayMethod() { @@ -33,112 +19,4 @@ public function setPayMethod() $this->id = 'hp_dc'; $this->name = __('Debit Card', 'woocommerce-heidelpay'); } - - /** - * Initialise Gateway Settings Form Fields. - */ - public function init_form_fields() { - - parent::init_form_fields(); - - $this->form_fields['security_sender']['default'] = '31HA07BC8142C5A171745D00AD63D182'; - $this->form_fields['user_login']['default'] = '31ha07bc8142c5a171744e5aef11ffd3'; - $this->form_fields['user_password']['default'] = '93167DE7'; - $this->form_fields['transaction_channel']['default'] = '31HA07BC8142C5A171744F3D6D155865'; - - $this->form_fields['bookingmode'] = $this->getBookingSelection(); - } - - public function payment_fields() - { - } - - public function after_pay() { - $order_id = wc_get_order_id_by_order_key($_GET['key']); - $order = wc_get_order($order_id); - - if ($order->get_payment_method() === $this->id) { - $this->getIFrame($order_id, $order); - } - } - - protected function getIFrame($order_id, $order) { - wp_enqueue_script('heidelpay-iFrame'); - - $this->setAuthentification(); - $this->setAsync(); - $this->setCustomer($order); - $this->setBasket($order_id); - $this->setBasket($order_id); - - $protocol = $_SERVER['HTTPS'] ? 'https' : 'http'; - $host = $protocol.'://'.$_SERVER['SERVER_NAME']; - $cssPath = WC_HEIDELPAY_PLUGIN_URL . '/assets/css/creditCardFrame.css'; - - - if($this->get_option('bookingmode') === 'PA') { - $this->payMethod->authorize( - $host, // PaymentFrameOrigin - uri of your application like https://dev.heidelpay.com - 'FALSE', - $cssPath - ); - } else { - $this->payMethod->debit( - $host, // PaymentFrameOrigin - uri of your application like https://dev.heidelpay.com - 'FALSE', - $cssPath - ); - } - - - - echo '
'; - if ($this->payMethod->getResponse()->isSuccess()) { - echo '
'; - } else { - echo get_home_url() . '/wp-content/plugins/woocommerce-heidelpay/vendor/'; - echo '
' . print_r($this->payMethod->getResponse()->getError(), 1) . '
'; - } - echo ''; - echo '
'; - } - - /** - * Output for the order received page. - * - * @param int $order_id - */ - public function thankyou_page($order_id) { - - if ($this->instructions) { - echo wpautop(wptexturize(wp_kses_post($this->instructions))); - } - $this->bank_details($order_id); - } - - /** - * Add content to the WC emails. - */ - public function email_instructions( $order, $sent_to_admin, $plain_text = false ) { - - if ( ! $sent_to_admin && 'hp_dc' === $order->get_payment_method() && $order->has_status( 'on-hold' ) ) { - if ( $this->instructions ) { - echo wpautop( wptexturize( $this->instructions ) ) . PHP_EOL; - } - $this->bank_details( $order->get_id() ); - } - } - - protected function performRequest($order_id) { - - $order = wc_get_order($order_id); - - $order->update_status( 'pending', __( 'Awaiting payment', 'woocommerce-heidelpay' ) ); - return [ - 'result' => 'success', - 'redirect' => $order->get_checkout_payment_url(true) - ]; - } } diff --git a/includes/gateways/class-wc-heidelpay-gateway-idl.php b/includes/gateways/class-wc-heidelpay-gateway-idl.php new file mode 100644 index 0000000..38a70ad --- /dev/null +++ b/includes/gateways/class-wc-heidelpay-gateway-idl.php @@ -0,0 +1,116 @@ +payMethod = new IDealPaymentMethod(); + $this->id = 'hp_idl'; + $this->name = __('iDeal', 'woocommerce-heidelpay'); + $this->has_fields = true; + + $this->bookingModes = array( + 'PA' => 'authorize', + 'DB' => 'debit' + ); + } + + /** + * Initialise Gateway Settings Form Fields. + */ + public function init_form_fields() + { + parent::init_form_fields(); + + $this->form_fields['security_sender']['default'] = '31HA07BC8142C5A171745D00AD63D182'; + $this->form_fields['user_login']['default'] = '31ha07bc8142c5a171744e5aef11ffd3'; + $this->form_fields['user_password']['default'] = '93167DE7'; + $this->form_fields['transaction_channel']['default'] = '31HA07BC8142C5A171744B56E61281E5'; + + $this->form_fields['bookingmode'] = $this->getBookingSelection(); + } + + /** + * @throws \Heidelpay\PhpPaymentApi\Exceptions\UndefinedTransactionModeException + */ + public function payment_fields() + { + // declare text + $accountHolderLabel = __('Account Holder', 'woocommerce-heidelpay'); + $bankNameLabel = __('Bank', 'woocommerce-heidelpay'); + // Performe Authorize request to get paymethod config + $this->setAuthentification(); + $this->setAsync(); + $this->payMethod->authorize(); + + $brands = (array) $this->payMethod->getResponse()->getConfig()->getBrands(); + + /* wc_get_logger()->log(WC_Log_Levels::DEBUG, 'form-request response: ' + . print_r($this->payMethod->getResponse(), 1));*/ + + echo '
'; + echo ''; + echo ''; + echo '
'; + echo ''; + echo ''; + echo '
'; + } + + protected function performRequest($order_id) + { + wc_get_logger()->log(WC_Log_Levels::DEBUG, 'post data' . print_r($_POST, 1)); + //TODO: get bankname dynamically + $this->payMethod->getRequest()->getAccount()->setBankName($_POST['bankname']); + + try { + $this->payMethod->authorize(); + } catch (\Exception $exception) { + wc_get_logger()->log(WC_Log_Levels::DEBUG, print_r('Paymethod not found', 1)); + } + + wc_get_logger()->log(WC_Log_Levels::DEBUG,'iDeal request ' . print_r( $this->payMethod->getResponse(),1)); + + if ($this->payMethod->getResponse()->isSuccess()) { + return [ + 'result' => 'success', + 'redirect' => $this->payMethod->getResponse()->getPaymentFormUrl() + ]; + } + + wc_add_notice( + __('Payment error: ', 'woocommerce-heidelpay') . $this->payMethod->getResponse()->getError()['message'], + 'error' + ); + + return null; + } + + public function getBookingAction() { + return $this->bookingModes[$this->get_option('bookingmode')]; + } +} diff --git a/includes/gateways/class-wc-heidelpay-gateway-va.php b/includes/gateways/class-wc-heidelpay-gateway-va.php new file mode 100644 index 0000000..6e69eae --- /dev/null +++ b/includes/gateways/class-wc-heidelpay-gateway-va.php @@ -0,0 +1,76 @@ +payMethod = new PayPalPaymentMethod(); + $this->id = 'hp_va'; + $this->name = 'PayPal'; + + $this->bookingModes = array( + 'PA' => 'authorize', + 'DB' => 'debit' + ); + } + + /** + * Initialise Gateway Settings Form Fields. + */ + public function init_form_fields() + { + parent::init_form_fields(); + + $this->form_fields['security_sender']['default'] = '31HA07BC8142C5A171745D00AD63D182'; + $this->form_fields['user_login']['default'] = '31ha07bc8142c5a171744e5aef11ffd3'; + $this->form_fields['user_password']['default'] = '93167DE7'; + $this->form_fields['transaction_channel']['default'] = '31HA07BC8124365CA41D4BDA79CCCD22'; + + $this->form_fields['bookingmode'] = $this->getBookingSelection(); + } + + protected function performRequest($order_id) + { + $bookingAction = $this->getBookingAction(); + + try { + $this->payMethod->$bookingAction(); + } catch (\Exception $exception) { + wc_get_logger()->logger->log(WC_Log_Levels::DEBUG, print_r('Paymethod not found', 1)); + } + + if ($this->payMethod->getResponse()->isSuccess()) { + return [ + 'result' => 'success', + 'redirect' => $this->payMethod->getResponse()->getPaymentFormUrl() + ]; + } + + wc_add_notice( + __('Payment error: ', 'woocommerce-heidelpay') . $this->payMethod->getResponse()->getError()['message'], + 'error' + ); + + return null; + } + + public function getBookingAction() { + return $this->bookingModes[$this->get_option('bookingmode')]; + } +} diff --git a/woocommerce-heidelpay.php b/woocommerce-heidelpay.php index 331b0d5..30bfa9e 100644 --- a/woocommerce-heidelpay.php +++ b/woocommerce-heidelpay.php @@ -126,8 +126,10 @@ public function init() require_once(dirname(__FILE__) . '/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php'); require_once(dirname(__FILE__) . '/includes/gateways/class-wc-heidelpay-gateway-cc.php'); require_once(dirname(__FILE__) . '/includes/gateways/class-wc-heidelpay-gateway-dc.php'); + require_once(dirname(__FILE__) . '/includes/gateways/class-wc-heidelpay-gateway-idl.php'); require_once(dirname(__FILE__) . '/includes/gateways/class-wc-heidelpay-gateway-ivpg.php'); require_once(dirname(__FILE__) . '/includes/gateways/class-wc-heidelpay-gateway-so.php'); + require_once(dirname(__FILE__) . '/includes/gateways/class-wc-heidelpay-gateway-va.php'); require_once(dirname(__FILE__) . '/includes/class-wc-heidelpay-response.php'); add_filter('woocommerce_payment_gateways', array($this, 'add_gateways')); @@ -142,8 +144,10 @@ public function add_gateways($methods) { $methods[] = 'WC_Gateway_HP_CC'; $methods[] = 'WC_Gateway_HP_DC'; + $methods[] = 'WC_Gateway_HP_IDL'; $methods[] = 'WC_Gateway_HP_IVPG'; $methods[] = 'WC_Gateway_HP_SO'; + $methods[] = 'WC_Gateway_HP_VA'; return $methods; } @@ -155,13 +159,17 @@ public function filter_gateway_order_admin($sections) { unset($sections['hp_cc']); unset($sections['hp_dc']); - unset($sections['hp_so']); + unset($sections['hp_idl']); unset($sections['hp_ivpg']); + unset($sections['hp_so']); + unset($sections['hp_va']); $sections['hp_cc'] = __('heidelpay CC', 'woocommerce-heidelpay'); $sections['hp_dc'] = __('heidelpay DC', 'woocommerce-heidelpay'); + $sections['hp_idl'] = __('heidelpay IDL', 'woocommerce-heidelpay'); $sections['hp_ivpg'] = __('heidelpay IVPG', 'woocommerce-heidelpay'); $sections['hp_so'] = __('heidelpay SO', 'woocommerce-heidelpay'); + $sections['hp_va'] = __('heidelpay VA', 'woocommerce-heidelpay'); return $sections; } From 6ee98dbab20c527e97d282dabbe074ff45edb095 Mon Sep 17 00:00:00 2001 From: Florian Evertz Date: Wed, 30 May 2018 13:22:13 +0200 Subject: [PATCH 05/41] add javascript --- includes/js/securedInvoice.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 includes/js/securedInvoice.js diff --git a/includes/js/securedInvoice.js b/includes/js/securedInvoice.js new file mode 100644 index 0000000..d82cd48 --- /dev/null +++ b/includes/js/securedInvoice.js @@ -0,0 +1,14 @@ +/** + * SUMMARY + * + * DESC + * + * @license Use of this software requires acceptance of the License Agreement. See LICENSE file. + * @copyright Copyright © 2016-present heidelpay GmbH. All rights reserved. + * @author Florian Evertz + * @category WOOCOMMERCE + */ + +function( + +); \ No newline at end of file From 9fe5b6e67b64e84085e263409f0cbb3492b125c9 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Wed, 30 May 2018 16:14:05 +0200 Subject: [PATCH 06/41] (WOO-5) Feature CC/DC: iDeal is only available for Netherlands now. moved the filter 'woocommerce_available_payment_gateways' to the abstract class. It calls the function "setAvailability()" now. --- composer.json | 3 +++ .../abstract-wc-heidelpay-iframe-gateway.php | 7 +++-- .../abstract-wc-heidelpay-payment-gateway.php | 8 ++++++ .../class-wc-heidelpay-gateway-idl.php | 26 ++++++++++++++----- .../class-wc-heidelpay-gateway-ivpg.php | 12 ++++----- 5 files changed, 40 insertions(+), 16 deletions(-) diff --git a/composer.json b/composer.json index 1452028..a44d2b6 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,9 @@ { "name": "Florian Evertz", "email": "florian.evertz@googlemail.com" + }, + { + "name": "David Owusu" } ] } diff --git a/includes/abstracts/abstract-wc-heidelpay-iframe-gateway.php b/includes/abstracts/abstract-wc-heidelpay-iframe-gateway.php index 904a4d7..213f124 100644 --- a/includes/abstracts/abstract-wc-heidelpay-iframe-gateway.php +++ b/includes/abstracts/abstract-wc-heidelpay-iframe-gateway.php @@ -7,7 +7,6 @@ abstract class WC_Heidelpay_IFrame_Gateway extends WC_Heidelpay_Payment_Gateway { - public $locale; protected $bookingModes; public function __construct() @@ -52,13 +51,17 @@ public function init_form_fields() $this->form_fields['bookingmode'] = $this->getBookingSelection(); } + /** + * @throws \Heidelpay\PhpPaymentApi\Exceptions\PaymentFormUrlException + * @throws \Heidelpay\PhpPaymentApi\Exceptions\UndefinedTransactionModeException + */ public function after_pay() { $order_id = wc_get_order_id_by_order_key($_GET['key']); $order = wc_get_order($order_id); if ($order->get_payment_method() === $this->id) { - $this->getIFrame($order_id, $order); + $this->getIFrame($order); } } diff --git a/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php b/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php index f583497..de01acf 100644 --- a/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php +++ b/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php @@ -32,6 +32,9 @@ public function __construct() add_action('woocommerce_update_options_payment_gateways_' . $this->id, array($this, 'process_admin_options')); add_action('woocommerce_api_' . strtolower(get_class($this)), array($this, 'callback_handler')); add_action('wp_enqueue_scripts', array($this, 'enqueue_assets')); + + // Filter + add_filter('woocommerce_available_payment_gateways', array($this, 'setAvailability')); } /** @@ -240,6 +243,11 @@ public function callback_handler() exit(); } + public function setAvailability($available_gateways) + { + return $available_gateways; + } + protected function getBookingSelection () { return array( 'title' => __('Bookingmode', 'woocommerce-heidelpay'), diff --git a/includes/gateways/class-wc-heidelpay-gateway-idl.php b/includes/gateways/class-wc-heidelpay-gateway-idl.php index 38a70ad..64b550a 100644 --- a/includes/gateways/class-wc-heidelpay-gateway-idl.php +++ b/includes/gateways/class-wc-heidelpay-gateway-idl.php @@ -54,6 +54,10 @@ public function init_form_fields() */ public function payment_fields() { + $countries = new WC_Countries(); + + $billingCountry = $countries->get_address_fields( $countries->get_base_country(),'billing_'); + // declare text $accountHolderLabel = __('Account Holder', 'woocommerce-heidelpay'); $bankNameLabel = __('Bank', 'woocommerce-heidelpay'); @@ -64,9 +68,6 @@ public function payment_fields() $brands = (array) $this->payMethod->getResponse()->getConfig()->getBrands(); - /* wc_get_logger()->log(WC_Log_Levels::DEBUG, 'form-request response: ' - . print_r($this->payMethod->getResponse(), 1));*/ - echo '
'; echo ''; echo ''; @@ -83,8 +84,6 @@ public function payment_fields() protected function performRequest($order_id) { - wc_get_logger()->log(WC_Log_Levels::DEBUG, 'post data' . print_r($_POST, 1)); - //TODO: get bankname dynamically $this->payMethod->getRequest()->getAccount()->setBankName($_POST['bankname']); try { @@ -93,8 +92,6 @@ protected function performRequest($order_id) wc_get_logger()->log(WC_Log_Levels::DEBUG, print_r('Paymethod not found', 1)); } - wc_get_logger()->log(WC_Log_Levels::DEBUG,'iDeal request ' . print_r( $this->payMethod->getResponse(),1)); - if ($this->payMethod->getResponse()->isSuccess()) { return [ 'result' => 'success', @@ -110,6 +107,21 @@ protected function performRequest($order_id) return null; } + public function setAvailability($available_gateways) + { + $available = true; + + if (wc()->customer->get_billing_country() !== 'NL') { + $available = false; + } + + if (!$available) { + unset($available_gateways[$this->id]); + } + + return $available_gateways; + } + public function getBookingAction() { return $this->bookingModes[$this->get_option('bookingmode')]; } diff --git a/includes/gateways/class-wc-heidelpay-gateway-ivpg.php b/includes/gateways/class-wc-heidelpay-gateway-ivpg.php index e1dc3cc..84f0535 100644 --- a/includes/gateways/class-wc-heidelpay-gateway-ivpg.php +++ b/includes/gateways/class-wc-heidelpay-gateway-ivpg.php @@ -21,8 +21,6 @@ public function __construct() parent::__construct(); add_action('woocommerce_email_before_order_table', array($this, 'email_instructions'), 10, 3); - - add_filter('woocommerce_available_payment_gateways', array($this, 'unsetIVPG')); } /** @@ -57,7 +55,7 @@ public function init_form_fields() ); } - public function unsetIVPG($available_gateways) + public function setAvailability($available_gateways) { $security = true; if (!empty(wc()->customer->get_billing_company())) { @@ -76,13 +74,13 @@ public function unsetIVPG($available_gateways) $security = false; } - if (wc()->cart->get_totals()['total'] > $this->settings['max'] || - wc()->cart->get_totals()['total'] < $this->settings['min']) { + if (wc()->cart->get_totals()['total'] > $this->get_option('max') || + wc()->cart->get_totals()['total'] < $this->get_option('min')) { $security = false; } if (!$security) { - unset($available_gateways['hp_ivpg']); + unset($available_gateways[$this->id]); } return $available_gateways; } @@ -144,7 +142,7 @@ protected function performRequest($order_id) $this->payMethod->authorize(); } catch (Exception $e) { wc_get_logger()->log(WC_Log_Levels::DEBUG, print_r($e->getMessage(), 1)); - // TODO: redirect to errorpage + wc_add_notice( __('Payment error: ', 'woocommerce-heidelpay') . $this->payMethod->getResponse()->getError()['message'], 'error' From 79a22993a34f1e8be73580697a0350ec7d66748e Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Wed, 30 May 2018 17:08:04 +0200 Subject: [PATCH 07/41] (WOO-5) Feature iDeal: remove bookingmode from iDeal --- includes/gateways/class-wc-heidelpay-gateway-idl.php | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/includes/gateways/class-wc-heidelpay-gateway-idl.php b/includes/gateways/class-wc-heidelpay-gateway-idl.php index 64b550a..7d2918c 100644 --- a/includes/gateways/class-wc-heidelpay-gateway-idl.php +++ b/includes/gateways/class-wc-heidelpay-gateway-idl.php @@ -27,11 +27,6 @@ public function setPayMethod() $this->id = 'hp_idl'; $this->name = __('iDeal', 'woocommerce-heidelpay'); $this->has_fields = true; - - $this->bookingModes = array( - 'PA' => 'authorize', - 'DB' => 'debit' - ); } /** @@ -45,8 +40,6 @@ public function init_form_fields() $this->form_fields['user_login']['default'] = '31ha07bc8142c5a171744e5aef11ffd3'; $this->form_fields['user_password']['default'] = '93167DE7'; $this->form_fields['transaction_channel']['default'] = '31HA07BC8142C5A171744B56E61281E5'; - - $this->form_fields['bookingmode'] = $this->getBookingSelection(); } /** @@ -61,6 +54,7 @@ public function payment_fields() // declare text $accountHolderLabel = __('Account Holder', 'woocommerce-heidelpay'); $bankNameLabel = __('Bank', 'woocommerce-heidelpay'); + // Performe Authorize request to get paymethod config $this->setAuthentification(); $this->setAsync(); @@ -122,7 +116,4 @@ public function setAvailability($available_gateways) return $available_gateways; } - public function getBookingAction() { - return $this->bookingModes[$this->get_option('bookingmode')]; - } } From 79943d7cd0856037e75ef5e49b427ecd4a0813eb Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Thu, 31 May 2018 17:45:49 +0200 Subject: [PATCH 08/41] (WOO-5) Feature iDeal: Adjust css file to fit the look of the default woocommerce plugin. --- assets/css/creditCardFrame.css | 48 ++++++++++++------- .../abstract-wc-heidelpay-iframe-gateway.php | 8 ++-- .../abstract-wc-heidelpay-payment-gateway.php | 2 +- .../class-wc-heidelpay-gateway-va.php | 3 ++ 4 files changed, 39 insertions(+), 22 deletions(-) diff --git a/assets/css/creditCardFrame.css b/assets/css/creditCardFrame.css index 4d584bc..9db644f 100644 --- a/assets/css/creditCardFrame.css +++ b/assets/css/creditCardFrame.css @@ -1,43 +1,59 @@ #paymentFrameForm { - background-color: pink; + background: #fff; } .form-row { - + margin: 0 0 1.5em; + padding: 0; + display: block; } .form-label { + color: #333; + margin-bottom: 0.5em; + position: relative; + word-wrap: break-word; + line-height: 1.66; + font: 800 15px Arial; } -.verificationInlineHintWrapper { - +.form-input, .form-select{ + border: 1px solid #bbb; + border-radius: 3px; + display: block; + width: 90%; + box-sizing: content-box; + padding: 0.7em; + font: 400 15px Arial; + color: #666; } -.form-input fullWidth { - +.form-select { + width: 75%; } -.form-select fullWidth { - +.verificationInlineHintWrapper { + width: 62%; } -.creditCardSymbols { +.form-input fullWidth {} -} +.form-select fullWidth {} -.creditCardImage { +.creditCardSymbols {} -} +.creditCardImage {} -.fillWidth { +.fillWidth {} -} - -.halfWidth { +.halfWidth{} +#verificationInlineHint { + right: -15px; } + diff --git a/includes/abstracts/abstract-wc-heidelpay-iframe-gateway.php b/includes/abstracts/abstract-wc-heidelpay-iframe-gateway.php index 213f124..f52fa7b 100644 --- a/includes/abstracts/abstract-wc-heidelpay-iframe-gateway.php +++ b/includes/abstracts/abstract-wc-heidelpay-iframe-gateway.php @@ -48,6 +48,7 @@ public function init_form_fields() $this->form_fields['user_password']['default'] = '93167DE7'; $this->form_fields['transaction_channel']['default'] = '31HA07BC8142C5A171744F3D6D155865'; + $this->form_fields['description']['default'] = ''; $this->form_fields['bookingmode'] = $this->getBookingSelection(); } @@ -75,10 +76,7 @@ protected function getIFrame( WC_Order $order) { wp_enqueue_script('heidelpay-iFrame'); - $this->setAuthentification(); - $this->setAsync(); - $this->setCustomer($order); - $this->setBasket($order->get_id()); + $this->prepareRequest($order); $protocol = $_SERVER['HTTPS'] ? 'https' : 'http'; $host = $protocol . '://' . $_SERVER['SERVER_NAME']; @@ -96,7 +94,7 @@ protected function getIFrame( WC_Order $order) if ($this->payMethod->getResponse()->isSuccess()) { echo '
'; + . '" frameborder="0" scrolling="no" style="height:360px;">
'; } else { echo get_home_url() . '/wp-content/plugins/woocommerce-heidelpay/vendor/'; echo '
' . print_r($this->payMethod->getResponse()->getError(), 1) . '
'; diff --git a/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php b/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php index de01acf..1f3bd44 100644 --- a/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php +++ b/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php @@ -49,7 +49,7 @@ public function init_form_fields() 'title' => __('Enable/Disable', 'woocommerce-heidelpay'), 'type' => 'checkbox', 'label' => sprintf(__('Enable %s', 'woocommerce-heidelpay'), $this->name), - 'default' => 'yes', + 'default' => 'no', ), 'title' => array( 'title' => __('Title', 'woocommerce-heidelpay'), diff --git a/includes/gateways/class-wc-heidelpay-gateway-va.php b/includes/gateways/class-wc-heidelpay-gateway-va.php index 6e69eae..bae20a6 100644 --- a/includes/gateways/class-wc-heidelpay-gateway-va.php +++ b/includes/gateways/class-wc-heidelpay-gateway-va.php @@ -70,6 +70,9 @@ protected function performRequest($order_id) return null; } + /** + * @return String get the transaction type to use for payment + */ public function getBookingAction() { return $this->bookingModes[$this->get_option('bookingmode')]; } From a934f2071b2c426b36e7f4c5fc702c242a02c3d2 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Mon, 4 Jun 2018 15:45:02 +0200 Subject: [PATCH 09/41] (WOO-5) Feature va-ot-cc-db: Add Criterions for shop-version module-version and push-url. tidy up code. --- .../abstract-wc-heidelpay-iframe-gateway.php | 39 ++++++++++++++----- .../abstract-wc-heidelpay-payment-gateway.php | 30 ++++++++++---- .../class-wc-heidelpay-gateway-so.php | 4 -- .../class-wc-heidelpay-gateway-va.php | 2 +- 4 files changed, 54 insertions(+), 21 deletions(-) diff --git a/includes/abstracts/abstract-wc-heidelpay-iframe-gateway.php b/includes/abstracts/abstract-wc-heidelpay-iframe-gateway.php index f52fa7b..0270344 100644 --- a/includes/abstracts/abstract-wc-heidelpay-iframe-gateway.php +++ b/includes/abstracts/abstract-wc-heidelpay-iframe-gateway.php @@ -5,6 +5,10 @@ require_once(WC_HEIDELPAY_PLUGIN_PATH . '/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php'); +/** + * Class WC_Heidelpay_IFrame_Gateway + * Provide payment using an iFrame. + */ abstract class WC_Heidelpay_IFrame_Gateway extends WC_Heidelpay_Payment_Gateway { protected $bookingModes; @@ -52,6 +56,19 @@ public function init_form_fields() $this->form_fields['bookingmode'] = $this->getBookingSelection(); } + /** + * register scripts and stylesheets for your payment gateway + */ + public function enqueue_assets() + { + wp_register_script('heidelpay-iFrame', + WC_HEIDELPAY_PLUGIN_URL . '/assets/js/creditCardFrame.js', + [], + false, + true + ); + } + /** * @throws \Heidelpay\PhpPaymentApi\Exceptions\PaymentFormUrlException * @throws \Heidelpay\PhpPaymentApi\Exceptions\UndefinedTransactionModeException @@ -62,15 +79,16 @@ public function after_pay() $order = wc_get_order($order_id); if ($order->get_payment_method() === $this->id) { - $this->getIFrame($order); + echo $this->getIFrame($order); } } /** - * @param $order_id + * Build the Iframe and return the String * @param $order * @throws \Heidelpay\PhpPaymentApi\Exceptions\PaymentFormUrlException * @throws \Heidelpay\PhpPaymentApi\Exceptions\UndefinedTransactionModeException + * @return String */ protected function getIFrame( WC_Order $order) { @@ -90,20 +108,23 @@ protected function getIFrame( WC_Order $order) $cssPath ); - echo '
'; + $iFrame = ''; if ($this->payMethod->getResponse()->isSuccess()) { - echo '
'; } else { - echo get_home_url() . '/wp-content/plugins/woocommerce-heidelpay/vendor/'; - echo '
' . print_r($this->payMethod->getResponse()->getError(), 1) . '
'; + $iFrame .= get_home_url() . '/wp-content/plugins/woocommerce-heidelpay/vendor/'; + $iFrame .= '
' . print_r($this->payMethod->getResponse()->getError(), 1) . '
'; } - echo ''; - echo '
'; + $iFrame .= ''; + $iFrame .= ''; + + return $iFrame; } - public function getBookingAction() { + public function getBookingAction() + { return $this->bookingModes[$this->get_option('bookingmode')]; } } diff --git a/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php b/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php index 1f3bd44..601bb7e 100644 --- a/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php +++ b/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php @@ -38,7 +38,7 @@ public function __construct() } /** - * Set the id and PaymenMethod + * Set the id and PaymentMethod */ abstract protected function setPayMethod(); @@ -125,16 +125,15 @@ public function init_form_fields() ); } + /** + * register scripts and stylesheets for your payment gateway + */ public function enqueue_assets() { - wp_register_script('heidelpay-iFrame', - WC_HEIDELPAY_PLUGIN_URL . '/assets/js/creditCardFrame.js', - [], - false, - true - ); + } + public function process_payment($order_id) { $order = wc_get_order($order_id); @@ -152,6 +151,7 @@ public function prepareRequest(WC_Order $order) $this->setAsync(); $this->setCustomer($order); $this->setBasket($order->get_id()); + $this->setCriterions(); } /** @@ -218,6 +218,22 @@ protected function setBasket($order_id) ); } + /** + * @global string $wp_version + */ + protected function setCriterions() + { + global $wp_version; + + $shopType = 'WordPress: '. $wp_version . ' - ' .'WooCommerce: '. wc()->version ; + $this->payMethod->getRequest()->getCriterion()->set('PUSH_URL', 'push-url for testing'); //TODO insert URL + $this->payMethod->getRequest()->getCriterion()->set('SHOP.TYPE', $shopType); + $this->payMethod->getRequest()->getCriterion()->set( + 'SHOPMODULE.VERSION', + 'heidelpay gateway '. WC_HEIDELPAY_VERSION + ); + } + /** * Send payment request * @return mixed diff --git a/includes/gateways/class-wc-heidelpay-gateway-so.php b/includes/gateways/class-wc-heidelpay-gateway-so.php index f19f868..ae0f060 100644 --- a/includes/gateways/class-wc-heidelpay-gateway-so.php +++ b/includes/gateways/class-wc-heidelpay-gateway-so.php @@ -37,10 +37,6 @@ public function init_form_fields() $this->form_fields['transaction_channel']['default'] = '31HA07BC8142C5A171749CDAA43365D2'; } - public function payment_fields() - { - } - protected function performRequest($order_id) { try { diff --git a/includes/gateways/class-wc-heidelpay-gateway-va.php b/includes/gateways/class-wc-heidelpay-gateway-va.php index bae20a6..8c06384 100644 --- a/includes/gateways/class-wc-heidelpay-gateway-va.php +++ b/includes/gateways/class-wc-heidelpay-gateway-va.php @@ -52,7 +52,7 @@ protected function performRequest($order_id) try { $this->payMethod->$bookingAction(); } catch (\Exception $exception) { - wc_get_logger()->logger->log(WC_Log_Levels::DEBUG, print_r('Paymethod not found', 1)); + wc_get_logger()->logger->log(WC_Log_Levels::DEBUG, print_r('Paymentmethod not found', 1)); } if ($this->payMethod->getResponse()->isSuccess()) { From bb1603c6404009d7690069b74124f99611700079 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Mon, 4 Jun 2018 15:55:21 +0200 Subject: [PATCH 10/41] (WOO-5) Feature va-ot-cc-db: Reworked response handling a little bit. In Success case status will be set to "on-hold" as long as no money transfer has happened. In Error case status will be set to "failed" In Pending case status will not be set and therefore it will stay on pending. --- includes/class-wc-heidelpay-response.php | 58 +++++++++++++----------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/includes/class-wc-heidelpay-response.php b/includes/class-wc-heidelpay-response.php index 518764f..08c24b8 100644 --- a/includes/class-wc-heidelpay-response.php +++ b/includes/class-wc-heidelpay-response.php @@ -30,58 +30,64 @@ public function init(array $post_data, $secret) } catch (\Exception $exception) { $callers = debug_backtrace(); wc_get_logger()->log(WC_Log_Levels::NOTICE, print_r("Heidelpay - " . - $callers [0] ['function'] . ": Invalid response hash from ". + $callers [0] ['function'] . ": Invalid response hash from " . $_SERVER ['REMOTE_ADDR'] . ", suspecting manipulation", 1)); exit(); //error } $orderId = self::$response->getIdentification()->getTransactionId(); + $order = wc_get_order($orderId); + - $this->handleResult($post_data, $orderId); + $this->handleResult($post_data, $order); //TODO: if case for distinction between result and push } - /* + /** * handle result post */ - public function handleResult($post_data, $orderId) + public function handleResult($post_data, WC_Order $order) { - - $uid = self::$response->getIdentification()->getUniqueId();; - - $order = wc_get_order($orderId); + $uid = self::$response->getIdentification()->getUniqueId(); if (self::$response->isSuccess()) { $payCode = explode('.', $post_data ['PAYMENT_CODE']); - - if (strtoupper($payCode [0]) != 'PP' AND strtoupper($payCode [0]) != 'IV') { - - //let wc take care of it + $note = ''; + + // If no money has been payed yet. + if (strtoupper($payCode[1]) === 'PA' or strtoupper($payCode[1]) === 'RG') { + // In not Prepayment and Invoice payment can be captured manually + if (strtoupper($payCode [0]) !== 'PP' and strtoupper($payCode [0]) !== 'IV') { + $note = __( + 'Payment reservation successful. Please use the hiP to check the payment.', + 'woocommerce-heidelpay.' + ); + $order->add_order_note($note, false); + } + + $order->update_status('on-hold', __('Awaiting payment.', 'woocommerce-heidelpay') + . ' ' . $note) . ' '; + } else { $order->payment_complete(); + } - //show thank you page - echo $order->get_checkout_order_received_url(); + echo $order->get_checkout_order_received_url(); - } else { - echo $order->get_checkout_order_received_url(); - } /* redirect customer to success page */ } elseif (self::$response->isError()) { $error = self::$response->getError(); + $order->update_status('failed'); - echo apply_filters( 'woocommerce_get_cancel_order_url_raw', add_query_arg( array( + echo apply_filters('woocommerce_get_cancel_order_url_raw', add_query_arg(array( 'cancel_order' => 'true', - 'order' => $order->get_order_key(), - 'order_id' => $order->get_id(), - '_wpnonce' => wp_create_nonce( 'woocommerce-cancel_order' ), - 'errorCode' => $error['code'], - ), $order->get_cancel_endpoint() ) ); + 'order' => $order->get_order_key(), + 'order_id' => $order->get_id(), + '_wpnonce' => wp_create_nonce('woocommerce-cancel_order'), + 'errorCode' => $error['code'], + ), $order->get_cancel_endpoint())); } elseif (self::$response->isPending()) { - //update status to on hold - $order->update_status('on-hold', __('Awaiting payment', 'woocommerce-heidelpay')); - //empty cart wc()->cart->empty_cart(); From 02ba7599e37e97157548f8d5c3e124e86b2a87a5 Mon Sep 17 00:00:00 2001 From: "David.Owusu" Date: Mon, 4 Jun 2018 16:48:22 +0200 Subject: [PATCH 11/41] (WOO-5) Feature va-ot-cc-db: Remove a log in iFrame-script --- assets/js/creditCardFrame.js | 34 ++++++++-------------------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/assets/js/creditCardFrame.js b/assets/js/creditCardFrame.js index cff5658..353dc49 100644 --- a/assets/js/creditCardFrame.js +++ b/assets/js/creditCardFrame.js @@ -1,30 +1,27 @@ /** - * SUMMARY + * Script to handle the communication with the iFrame in order to submit the form from outside the iFrame * * DESC * * @license Use of this software requires acceptance of the License Agreement. See LICENSE file. * @copyright Copyright © 2016-present heidelpay GmbH. All rights reserved. - * @link https://dev.heidelpay.de/JTL + * @link https://dev.heidelpay.de/woocommerce * @author David Owusu * @category WOOCOMMERCE */ -/*var paymentFrameForm; -var targetOrigin;*/ - - -/** - * Get hostname and protocol from paymentIframe - */ jQuery(function () { + /** + * Get the form element + */ paymentFrameForm = document.getElementById('paymentFrameForm'); if(paymentFrameForm != null) { - console.log(paymentFrameForm); - var paymentFrameIframe = document.getElementById('paymentFrameIframe'); + /** + * Add an event listener to from submit, which will execute the sendMessage function + */ if (paymentFrameForm.addEventListener) {// W3C DOM paymentFrameForm.addEventListener('submit', sendMessage); } @@ -35,21 +32,6 @@ jQuery(function () { } ) - - - -/** - * Get the form element - */ - - - - -/** - * Add an event listener to from submit, which will execute the sendMessage function - */ - - /** * Define send Message function * This function will collect each inpunt inside the form and then submit From 82dac3a0274c80c2a46c71db5e03eee373f2f5bd Mon Sep 17 00:00:00 2001 From: Florian Evertz Date: Tue, 5 Jun 2018 16:08:46 +0200 Subject: [PATCH 12/41] restrictions and validation and backend settings - add min/max amount settings + validation - add available country settings + validation - add JS to validate Age <- Not working --- .../abstract-wc-heidelpay-payment-gateway.php | 8 + .../class-wc-heidelpay-gateway-ivpg.php | 153 ++++++++++++++---- includes/js/securedInvoice.js | 16 +- 3 files changed, 146 insertions(+), 31 deletions(-) diff --git a/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php b/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php index 6987baa..a06fcad 100644 --- a/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php +++ b/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php @@ -135,7 +135,15 @@ public function enqueue_scripts() true ); + wp_register_script('heidelpay-secured', + WC_HEIDELPAY_PLUGIN_URL . '/includes/js/securedInvoice.js', + [], + false, + true + ); + wp_enqueue_script('heidelpay-iFrame'); + wp_enqueue_script('heidelpay-secured'); } public function process_payment($order_id) diff --git a/includes/gateways/class-wc-heidelpay-gateway-ivpg.php b/includes/gateways/class-wc-heidelpay-gateway-ivpg.php index e1dc3cc..2ceeccc 100644 --- a/includes/gateways/class-wc-heidelpay-gateway-ivpg.php +++ b/includes/gateways/class-wc-heidelpay-gateway-ivpg.php @@ -21,8 +21,8 @@ public function __construct() parent::__construct(); add_action('woocommerce_email_before_order_table', array($this, 'email_instructions'), 10, 3); - add_filter('woocommerce_available_payment_gateways', array($this, 'unsetIVPG')); + } /** @@ -41,30 +41,69 @@ public function init_form_fields() $this->form_fields['user_password']['default'] = '93167DE7'; $this->form_fields['transaction_channel']['default'] = '31HA07BC81856CAD6D8E05CDDE7E2AC8'; + $this->form_fields['advanced'] = array( + 'title' => __('Advanced options', 'woocommerce-heidelpay'), + 'type' => 'title', + 'description' => '' + ); + $this->form_fields['min'] = array( - 'title' => __('Minimum Value', 'woocommerce-heidelpay'), + 'title' => __('Minimum Amount', 'woocommerce-heidelpay'), 'type' => 'text', 'default' => 100, 'desc_tip' => true, - ); $this->form_fields['max'] = array( - 'title' => __('Maxmimum Value', 'woocommerce-heidelpay'), + 'title' => __('Maxmimum Amount', 'woocommerce-heidelpay'), 'type' => 'text', 'default' => 1000, 'desc_tip' => true, ); + + $this->form_fields['availableCountries'] = array( + 'title' => __('Available Countries for secured invoice', 'woocommerce-heidelpay'), + 'type' => 'title', + 'description' => 'Here you can enable secured Invoice for specific countries. + Be aware that this will not enable the country in your WooCommerce settings + and you have to enable them seperately.' + ); + + $this->form_fields['availableDE'] = array( + 'title' => __('Enable Germany', 'woocommerce-heidelpay'), + 'type' => 'checkbox', + 'default' => 'yes', + ); + + $this->form_fields['availableAT'] = array( + 'title' => __('Enable Austria', 'woocommerce-heidelpay'), + 'type' => 'checkbox', + 'default' => 'no', + ); + + //Switzerland not working yet + /* + $this->form_fields['availableCH'] = array( + 'title' => __('Enable Switzerland', 'woocommerce-heidelpay'), + 'type' => 'checkbox', + 'default' => 'no', + ); + */ } + /** + * @param $available_gateways + * @return mixed + */ public function unsetIVPG($available_gateways) { $security = true; + if (!empty(wc()->customer->get_billing_company())) { $security = false; } - if (wc()->customer->get_billing_country() !== 'DE') { + if (!in_array(wc()->customer->get_billing_country(), $this->getEnabledCountries(), true)) { $security = false; } @@ -76,8 +115,8 @@ public function unsetIVPG($available_gateways) $security = false; } - if (wc()->cart->get_totals()['total'] > $this->settings['max'] || - wc()->cart->get_totals()['total'] < $this->settings['min']) { + if (wc()->cart->get_totals()['total'] > $this->get_option('max') || + wc()->cart->get_totals()['total'] < $this->get_option('min')) { $security = false; } @@ -87,8 +126,32 @@ public function unsetIVPG($available_gateways) return $available_gateways; } + /** + * This function checks which countries are enabled for secured invoice + * and returns an array containing these country short codes + * + * @return array + */ + private function getEnabledCountries() + { + $availableCountries = array(); + + if ($this->get_option('availableDE') === 'yes') { + $availableCountries[] = 'DE'; + } + if ($this->get_option('availableAT') === 'yes') { + $availableCountries[] = 'AT'; + } + if ($this->get_option('availableCH') === 'yes') { + $availableCountries[] = 'CH'; + } + + return $availableCountries; + } + public function payment_fields() { + $apiLink = get_permalink(wc_get_page_id('shop')) . 'wc-api/validation_IV'; $salutationText = __('Salutation', 'woocommerce-heidelpay'); $salutationMText = __('Mr', 'woocommerce-heidelpay'); $salutationWText = __('Mrs', 'woocommerce-heidelpay'); @@ -97,18 +160,42 @@ public function payment_fields() echo '
'; echo - '' . - '' . '' . '' . '' . '' . '
' . - '' . - '' . + '' . + '' . '
'; echo '
'; + echo ''; } public function email_instructions($order, $sent_to_admin, $plain_text = false) @@ -131,35 +218,45 @@ protected function setPayMethod() /** * Send payment request + * @param $order_id * @return mixed */ protected function performRequest($order_id) { + $order = wc_get_order($order_id); $this->payMethod->getRequest()->b2cSecured($_POST['salutation'], $_POST['birthdate']); - /** - * Set necessary parameters for Heidelpay payment Frame and send a registration request - */ - try { - $this->payMethod->authorize(); - } catch (Exception $e) { - wc_get_logger()->log(WC_Log_Levels::DEBUG, print_r($e->getMessage(), 1)); - // TODO: redirect to errorpage + if ($order->get_billing_company() === '') { + /** + * Set necessary parameters for Heidelpay payment Frame and send a registration request + */ + try { + $this->payMethod->authorize(); + } catch (Exception $e) { + wc_get_logger()->log(WC_Log_Levels::DEBUG, print_r($e->getMessage(), 1)); + // TODO: redirect to errorpage + wc_add_notice( + __('Payment error: ', 'woocommerce-heidelpay') . + $this->payMethod->getResponse()->getError()['message'], + 'error' + ); + return null; + } + + if ($this->payMethod->getResponse()->isSuccess()) { + return [ + 'result' => 'success', + 'redirect' => $this->payMethod->getResponse()->getPaymentFormUrl(), + ]; + } wc_add_notice( - __('Payment error: ', 'woocommerce-heidelpay') . $this->payMethod->getResponse()->getError()['message'], + __('Payment error: ' . $this->payMethod->getResponse()->getError()['message'], 'woocommerce-heidelpay'), 'error' ); return null; } - - if ($this->payMethod->getResponse()->isSuccess()) { - return [ - 'result' => 'success', - 'redirect' => $this->payMethod->getResponse()->getPaymentFormUrl(), - ]; - } wc_add_notice( - __('Payment error: ' . $this->payMethod->getResponse()->getError()['message'], 'woocommerce-heidelpay'), + __('You are not allowed to use secured invoice with a company name', 'woocommerce-heidelpay'), 'error' ); return null; diff --git a/includes/js/securedInvoice.js b/includes/js/securedInvoice.js index d82cd48..f0a744e 100644 --- a/includes/js/securedInvoice.js +++ b/includes/js/securedInvoice.js @@ -9,6 +9,16 @@ * @category WOOCOMMERCE */ -function( - -); \ No newline at end of file +/** + * This function checks if the billing_company is empty + */ +jQuery(function () { + jQuery('#billing_company').change(function () { + if (jQuery('#billing_company').val() !== '') { + jQuery('li.payment_method_hp_ivpg').hide(); + } else { + jQuery('li.payment_method_hp_ivpg').show(); + } + ; + }); +}); \ No newline at end of file From 7f5002262b5a8e7217a63de5deffe6a59180d40a Mon Sep 17 00:00:00 2001 From: Florian Evertz Date: Wed, 6 Jun 2018 16:13:28 +0200 Subject: [PATCH 13/41] use JS to show error Notice --- .../class-wc-heidelpay-gateway-ivpg.php | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/includes/gateways/class-wc-heidelpay-gateway-ivpg.php b/includes/gateways/class-wc-heidelpay-gateway-ivpg.php index 2ceeccc..74b4660 100644 --- a/includes/gateways/class-wc-heidelpay-gateway-ivpg.php +++ b/includes/gateways/class-wc-heidelpay-gateway-ivpg.php @@ -151,7 +151,6 @@ private function getEnabledCountries() public function payment_fields() { - $apiLink = get_permalink(wc_get_page_id('shop')) . 'wc-api/validation_IV'; $salutationText = __('Salutation', 'woocommerce-heidelpay'); $salutationMText = __('Mr', 'woocommerce-heidelpay'); $salutationWText = __('Mrs', 'woocommerce-heidelpay'); @@ -161,14 +160,14 @@ public function payment_fields() echo '' . - '' . '' . '' . '' . '' . '
' . '' . - '' . + '' . '
'; echo '
'; @@ -179,25 +178,32 @@ public function payment_fields() var inputDate = this.valueAsDate; var currentDate = new Date(); if(new Date(currentDate-inputDate).getFullYear() - new Date(0).getFullYear() < 18){ - console.log("i dun know what to do D:"); return false; } return true; }; date_input.onchange = function () { - //Dieser Block wird zwar nicht ignoriert - //aber sämtliche Validity Bubbles werden von Wordpress/woocommerce verschluckt - if(!this.reportValidity()){ - this.validationError = "blögh"; - this.validationMessage ="noch mehr blögh" ; - this.setCustomValidity("tot"); - this.valid = false; + if(!this.reportValidity() && jQuery("ul[class=woocommerce-error]")[0] == undefined){ + jQuery("form[name=checkout]").prepend(\''. $this->ErrorHtml().'\'); + jQuery("ul[class=woocommerce-error]")[0].scrollIntoView({behavior : "smooth"}) + }else{ + if(this.reportValidity() && jQuery("ul[class=woocommerce-error]")[0] !== undefined){ + jQuery("ul[class=woocommerce-error]").remove(); + } } }; '; } + public function ErrorHtml() + { + $errorText = __('You have to be at least 18 years old in order to use secured invoice', 'woocommerce-heidelpay'); + return ''; + } + public function email_instructions($order, $sent_to_admin, $plain_text = false) { if ($this->instructions) { From 0a610184f9942857d2f17ad853b898de9b538c35 Mon Sep 17 00:00:00 2001 From: Florian Evertz Date: Thu, 7 Jun 2018 14:40:01 +0200 Subject: [PATCH 14/41] add validation on paymentfields --- .../class-wc-heidelpay-gateway-ivpg.php | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/includes/gateways/class-wc-heidelpay-gateway-ivpg.php b/includes/gateways/class-wc-heidelpay-gateway-ivpg.php index 74b4660..a1cce77 100644 --- a/includes/gateways/class-wc-heidelpay-gateway-ivpg.php +++ b/includes/gateways/class-wc-heidelpay-gateway-ivpg.php @@ -22,7 +22,33 @@ public function __construct() add_action('woocommerce_email_before_order_table', array($this, 'email_instructions'), 10, 3); add_filter('woocommerce_available_payment_gateways', array($this, 'unsetIVPG')); + add_action('woocommerce_after_checkout_validation', array($this, 'validateInvoice')); + } + + public function validateInvoice() + { + if (!$this->is18($_POST['birthdate']) || empty($_POST['birthdate'])) { + wc_add_notice( + __('You have to be at least 18 years old in order to use secured invoice', 'woocommerce-heidelpay'), + 'error' + ); + } + if(empty($_POST['salutation'])){ + wc_add_notice( + __('You have to enter your salutation', 'woocommerce-heidelpay'), + 'error' + ); + } + } + private function is18($given) + { + $given = strtotime($given); + $min = strtotime('+18 years', $given); + if (time() < $min) { + return false; + } + return true; } /** @@ -185,7 +211,7 @@ public function payment_fields() date_input.onchange = function () { if(!this.reportValidity() && jQuery("ul[class=woocommerce-error]")[0] == undefined){ - jQuery("form[name=checkout]").prepend(\''. $this->ErrorHtml().'\'); + jQuery("form[name=checkout]").prepend(\'' . $this->ErrorHtml() . '\'); jQuery("ul[class=woocommerce-error]")[0].scrollIntoView({behavior : "smooth"}) }else{ if(this.reportValidity() && jQuery("ul[class=woocommerce-error]")[0] !== undefined){ @@ -199,8 +225,8 @@ public function payment_fields() public function ErrorHtml() { $errorText = __('You have to be at least 18 years old in order to use secured invoice', 'woocommerce-heidelpay'); - return '