diff --git a/CHANGELOG.md b/CHANGELOG.md index d3905ae..dbd42ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Release Notes - heidelpay Payment Gateway for WooCommerce +## 1.3.0 + +### Fixed: +- Credit Card iFrame not working in Safari Browsers + +### Added: +#### Features: +- Add GiroPay Payment Method + ## 1.2.0 ### Fixed: diff --git a/README.md b/README.md index a532500..253a972 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ To use this extension please paste the contents of the folder "woocommerce"" int * credit card * debit card * direct debit +* GiroPay * iDEAL * Paypal * Sofort diff --git a/assets/js/creditCardFrame.js b/assets/js/creditCardFrame.js index dd3798c..5311922 100644 --- a/assets/js/creditCardFrame.js +++ b/assets/js/creditCardFrame.js @@ -10,28 +10,28 @@ * @category WOOCOMMERCE */ +jQuery(document).ready(function(){ + /** + * Add an event listener to form submit, which will execute the sendMessage function + */ + if (paymentFrameForm.addEventListener) {// W3C DOM + paymentFrameForm.addEventListener('submit', sendMessage); + } else if (paymentFrameForm.attachEvent) { // IE DOM + paymentFrameForm.attachEvent('onsubmit', sendMessage); + } -jQuery(function () { - /** - * Get the form element - */ - paymentFrameForm = document.getElementById('paymentFrameForm'); - if(paymentFrameForm != null) { - 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); - } - else if (paymentFrameForm.attachEvent) { // IE DOM - paymentFrameForm.attachEvent('onsubmit', sendMessage); - } - } + /** + * Add an event listener to your webpage, which will receive the response message from payment server. + */ + if (window.addEventListener) { // W3C DOM + window.addEventListener('message', receiveMessage); + } else if (window.attachEvent) { // IE DOM + window.attachEvent('onmessage', receiveMessage); + } } ) + /** * Define send Message function * This function will collect each inpunt inside the form and then submit @@ -40,60 +40,54 @@ jQuery(function () { */ function sendMessage(e) { - - if(e.preventDefault) { e.preventDefault(); } - else { e.returnValue = false; } - - var data = {}; - - /** - * Collection form input fields - */ - - /** - * Send html postmessage to payment frame - */ - targetOrigin = getDomainFromUrl(jQuery('#paymentFrameIframe').attr('src')); - paymentFrameIframe.contentWindow.postMessage(JSON.stringify(data), targetOrigin); -} + if(e.preventDefault) { e.preventDefault(); } + else { e.returnValue = false; } + var data = {}; + /** + * Get the iFrame element + */ + var paymentFrameIframe = document.getElementById('paymentFrameIframe'); + /** + * Get hostname and protocol from paymentIframe + */ + var targetOrigin = getDomainFromUrl(paymentFrameIframe.src); -/** - * Function to get the domain from a given url - */ -function getDomainFromUrl(url) { - var arr = url.split("/"); - return arr[0] + "//" + arr[2]; - } + /** + * Send html postmessage to payment frame + */ + paymentFrameIframe.contentWindow.postMessage(JSON.stringify(data), targetOrigin); +} /** - * Add an listener to your webpage, which will recieve the response message - * from payment server. + * Function to get the domain from a given url */ -if (window.addEventListener) { // W3C DOM - window.addEventListener('message', receiveMessage); - - } -else if (window.attachEvent) { // IE DOM - window.attachEvent('onmessage', receiveMessage); - } +function getDomainFromUrl(url) { + var arr = url.split("/"); + return arr[0] + "//" + arr[2]; +} /** * Define receiveMessage function * - * This function will recieve the response message form the payment server. + * This function will receive the response message form the payment server. */ -function receiveMessage(e) { - - if (e.origin !== targetOrigin) { - return; - } - - var antwort = JSON.parse(e.data); - console.log(antwort); -} - +function receiveMessage(e) { + /** + * Get the iFrame element + */ + var paymentFrameIframe = document.getElementById('paymentFrameIframe'); + /** + * Get hostname and protocol from paymentIframe + */ + var targetOrigin = getDomainFromUrl(paymentFrameIframe.src); + if (e.origin !== targetOrigin) { + return; + } + var antwort = JSON.parse(e.data); + //console.log(antwort); +} \ No newline at end of file diff --git a/includes/abstracts/abstract-wc-heidelpay-iframe-gateway.php b/includes/abstracts/abstract-wc-heidelpay-iframe-gateway.php index 36ea146..172f6ce 100644 --- a/includes/abstracts/abstract-wc-heidelpay-iframe-gateway.php +++ b/includes/abstracts/abstract-wc-heidelpay-iframe-gateway.php @@ -14,12 +14,13 @@ * @package woocommerce-heidelpay * @category WooCommerce */ + if (!defined('ABSPATH')) { exit; } -require_once(WC_HEIDELPAY_PLUGIN_PATH . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'abstracts' . - DIRECTORY_SEPARATOR . 'abstract-wc-heidelpay-payment-gateway.php'); +require_once WC_HEIDELPAY_PLUGIN_PATH . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'abstracts' . + DIRECTORY_SEPARATOR . 'abstract-wc-heidelpay-payment-gateway.php'; /** * Class WC_Heidelpay_IFrame_Gateway @@ -61,12 +62,6 @@ public function toCheckoutPayment($order_id) ]; } - protected function performRequest($order_id) - { - $order = wc_get_order($order_id); - echo $this->getIFrame($order); - } - /** * Initialise Gateway Settings Form Fields. */ @@ -88,7 +83,8 @@ public function init_form_fields() */ public function enqueue_assets() { - wp_register_script('heidelpay-iFrame', + wp_register_script( + 'heidelpay-iFrame', WC_HEIDELPAY_PLUGIN_URL . '/assets/js/creditCardFrame.js', [], false, @@ -109,6 +105,12 @@ public function after_pay() } } + protected function performRequest($order_id) + { + $order = wc_get_order($order_id); + echo $this->getIFrame($order); + } + /** * Build the Iframe and return the String * @param $order @@ -116,7 +118,7 @@ public function after_pay() * @throws \Heidelpay\PhpPaymentApi\Exceptions\UndefinedTransactionModeException * @return String */ - protected function getIFrame( WC_Order $order) + protected function getIFrame(WC_Order $order) { // Load script for payment cards wp_enqueue_script('heidelpay-iFrame'); @@ -139,7 +141,7 @@ protected function getIFrame( WC_Order $order) $iFrame = '
'; + $iFrame .= ''; return $iFrame; } @@ -160,7 +162,8 @@ protected function getIFrame( WC_Order $order) htmlspecialchars( print_r( $this->plugin_id . ' - ' . $this->id . __( - ' Error: Paymentmethod was not found: ', 'woocommerce-heidelpay' + ' Error: Paymentmethod was not found: ', + 'woocommerce-heidelpay' ) . $bookingAction, 1 ) @@ -171,7 +174,7 @@ protected function getIFrame( WC_Order $order) public function getBookingAction() { - if(!empty($this->bookingModes[$this->get_option('bookingmode')])) { + if (!empty($this->bookingModes[$this->get_option('bookingmode')])) { return $this->bookingModes[$this->get_option('bookingmode')]; } return $this->bookingAction; diff --git a/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php b/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php index a7c4cd4..9bce4a6 100644 --- a/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php +++ b/includes/abstracts/abstract-wc-heidelpay-payment-gateway.php @@ -27,7 +27,6 @@ abstract class WC_Heidelpay_Payment_Gateway extends WC_Payment_Gateway { - public $payMethod; protected $name; protected $bookingAction; @@ -70,16 +69,9 @@ public function __construct() */ abstract protected function setPayMethod(); - - public function pushHandler() - { - if (array_key_exists('init(file_get_contents('php://input'), $this->get_option('secret')); - } - exit; - } - + /** + * Initiates the form fields + */ public function init_form_fields() { $this->form_fields = array( @@ -163,9 +155,23 @@ public function init_form_fields() ); } + /** + * Handles an incoming Push Notification + * + * @throws \Heidelpay\PhpPaymentApi\Exceptions\XmlResponseParserException + */ + public function pushHandler() + { + if (array_key_exists('init(file_get_contents('php://input'), $this->get_option('secret')); + } + exit; + } + /** * Validate the customer input coming from checkout. - * @return boolean + * @return void */ public function checkoutValidation() { @@ -178,12 +184,7 @@ public function checkoutValidation() */ public function isGatewayActive() { - if (!empty($_POST['payment_method'])) { - if ($_POST['payment_method'] === $this->id) - return true; - } - - return false; + return !empty($_POST['payment_method']) && $_POST['payment_method'] === $this->id; } /** @@ -191,7 +192,8 @@ public function isGatewayActive() */ public function enqueue_assets() { - wp_register_script('heidelpay-secured', + wp_register_script( + 'heidelpay-secured', WC_HEIDELPAY_PLUGIN_URL . '/assets/js/securedInvoice.js', [], false, @@ -201,6 +203,13 @@ public function enqueue_assets() wp_enqueue_script('heidelpay-secured'); } + /** + * Process the payment + * + * @param int $order_id + * @return array|mixed + * @throws \Heidelpay\PhpPaymentApi\Exceptions\PaymentFormUrlException + */ public function process_payment($order_id) { $order = wc_get_order($order_id); @@ -250,6 +259,11 @@ protected function setAsync() ); } + /** + * Get the Language set in WordPress Settings + * + * @return string + */ public function getLanguage() { if (strpos(get_locale(), 'de_') !== false) { @@ -258,6 +272,9 @@ public function getLanguage() return 'en'; } + /** + * @param WC_Order $order + */ protected function setCustomer(WC_Order $order) { $this->payMethod->getRequest()->customerAddress( @@ -274,6 +291,9 @@ protected function setCustomer(WC_Order $order) ); } + /** + * @param $order_id + */ protected function setBasket($order_id) { $order = wc_get_order($order_id); @@ -304,7 +324,9 @@ protected function setCriterions() /** * Send payment request. * Validation happens before this in the checkoutValidation() function. + * * @return mixed + * @throws \Heidelpay\PhpPaymentApi\Exceptions\PaymentFormUrlException */ protected function performRequest($order_id) { @@ -312,8 +334,8 @@ protected function performRequest($order_id) $this->handleFormPost($_POST); } - if (!empty($this->bookingAction) AND method_exists($this->payMethod, $this->bookingAction)) { - $action = $this->getbookingAction(); + if (!empty($this->bookingAction) && method_exists($this->payMethod, $this->bookingAction)) { + $action = $this->getBookingAction(); try { $this->payMethod->$action(); } catch (Exception $e) { @@ -354,7 +376,7 @@ protected function performRequest($order_id) } /** - * process the Form input from customer comimg from checkout. + * process the Form input from customer coming from checkout. */ protected function handleFormPost() { @@ -371,7 +393,7 @@ public function getBookingAction() /** * @param String $message */ - public function addPaymentError(String $message) + public function addPaymentError($message) { wc_add_notice( __('Payment error: ', 'woocommerce-heidelpay') . htmlspecialchars($message), @@ -402,6 +424,21 @@ protected function getErrorMessage(Response $response = null) return $this->messageMapper->getDefaultMessage(); } + /** + * Funktion to log Events as a notice. It has a prefix to identify that the log entry is from heidelpay and which + * function has created it. + * @param string|array $logData + */ + protected function paymentLog($logData) + { + $callers = debug_backtrace(); + wc_get_logger()->log(WC_Log_Levels::NOTICE, print_r('heidelpay - ' . + $callers [1] ['function'] . ': ' . print_r($logData, 1), 1)); + } + + /** + * echoes the admin options + */ public function admin_options() { echo '' . $paymentInfo . '
'; } return $orderReceivedText; } + /** + * Get the order using the Get parameter 'key' + * @return bool|WC_Order|WC_Refund + */ + public function getOrderFromKey() + { + if (isset($_GET['key'])) { + $order_id = wc_get_order_id_by_order_key($_GET['key']); + return wc_get_order($order_id); + } + + return null; + } + /** * Hook - "woocommerce_email_before_order_table". Add heidelpay-paymentInfo text to "completed order" email. * @param WC_Order $order - * @param $sent_to_admin - * @param bool $plain_text * @return null */ - public function emailInstructions(WC_Order $order, $sent_to_admin, $plain_text = false) + public function emailInstructions(WC_Order $order) { if ($order->get_payment_method() !== $this->id) { return null; @@ -534,4 +539,22 @@ public function emailInstructions(WC_Order $order, $sent_to_admin, $plain_text = } } } + + /** + * @return array Containing the option field to select booking mode in the admin menu. + */ + protected function getBookingSelection() + { + return array( + 'title' => __('Bookingmode', 'woocommerce-heidelpay'), + 'type' => 'select', + 'options' => array( + 'DB' => __('Debit', 'woocommerce-heidelpay'), + 'PA' => __('Authorization', 'woocommerce-heidelpay') + ), + 'id' => $this->id . '_bookingmode', + 'label' => __('Choose a bookingmode', 'woocommerce-heidelpay'), + 'default' => 'DB' + ); + } } diff --git a/includes/class-wc-heidelpay-push.php b/includes/class-wc-heidelpay-push.php index fe8701e..9629d16 100644 --- a/includes/class-wc-heidelpay-push.php +++ b/includes/class-wc-heidelpay-push.php @@ -19,7 +19,7 @@ exit; // Exit if accessed directly } -require_once(dirname(__DIR__) . '/vendor/autoload.php'); +require_once dirname(__DIR__) . '/vendor/autoload.php'; use Heidelpay\PhpPaymentApi\Push; @@ -35,7 +35,7 @@ class WC_Heidelpay_Push */ public function init($rawPayload, $secret) { - if (empty(self::$push)) { + if (null === self::$push) { self::$push = new Push($rawPayload); } /** @var Heidelpay\PhpPaymentApi\Response $response */ @@ -45,9 +45,9 @@ public function init($rawPayload, $secret) $response->verifySecurityHash($secret, $response->getIdentification()->getTransactionId()); } catch (\Exception $e) { $callers = debug_backtrace(); - wc_get_logger()->log(WC_Log_Levels::NOTICE, print_r("Heidelpay - " . - $callers [0] ['function'] . ": Invalid push hash from " . - $_SERVER ['REMOTE_ADDR'] . ", suspecting manipulation", 1)); + wc_get_logger()->log(WC_Log_Levels::NOTICE, print_r('Heidelpay - ' . + $callers [0] ['function'] . ': Invalid push hash from ' . + $_SERVER ['REMOTE_ADDR'] . ', suspecting manipulation', 1)); exit(); //error } $this->handlePush($response); diff --git a/includes/gateways/class-wc-heidelpay-gateway-cc.php b/includes/gateways/class-wc-heidelpay-gateway-cc.php index dd91884..d856760 100644 --- a/includes/gateways/class-wc-heidelpay-gateway-cc.php +++ b/includes/gateways/class-wc-heidelpay-gateway-cc.php @@ -19,8 +19,8 @@ exit; // Exit if accessed directly } -require_once(WC_HEIDELPAY_PLUGIN_PATH . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'abstracts' . - DIRECTORY_SEPARATOR . 'abstract-wc-heidelpay-iframe-gateway.php'); +require_once WC_HEIDELPAY_PLUGIN_PATH . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'abstracts' . + DIRECTORY_SEPARATOR . 'abstract-wc-heidelpay-iframe-gateway.php'; use Heidelpay\PhpPaymentApi\PaymentMethods\CreditCardPaymentMethod; diff --git a/includes/gateways/class-wc-heidelpay-gateway-dc.php b/includes/gateways/class-wc-heidelpay-gateway-dc.php index dc8dec9..38165d3 100644 --- a/includes/gateways/class-wc-heidelpay-gateway-dc.php +++ b/includes/gateways/class-wc-heidelpay-gateway-dc.php @@ -15,17 +15,17 @@ * @category WooCommerce */ -if ( ! defined( 'ABSPATH' ) ) { - exit; // Exit if accessed directly +if (!defined('ABSPATH')) { + exit; // Exit if accessed directly } -require_once(WC_HEIDELPAY_PLUGIN_PATH . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'abstracts' . - DIRECTORY_SEPARATOR . 'abstract-wc-heidelpay-iframe-gateway.php'); +require_once WC_HEIDELPAY_PLUGIN_PATH . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'abstracts' . + DIRECTORY_SEPARATOR . 'abstract-wc-heidelpay-iframe-gateway.php'; use Heidelpay\PhpPaymentApi\PaymentMethods\DebitCardPaymentMethod; -class WC_Gateway_HP_DC extends WC_Heidelpay_IFrame_Gateway { - +class WC_Gateway_HP_DC extends WC_Heidelpay_IFrame_Gateway +{ public function setPayMethod() { $this->payMethod = new DebitCardPaymentMethod(); diff --git a/includes/gateways/class-wc-heidelpay-gateway-dd.php b/includes/gateways/class-wc-heidelpay-gateway-dd.php index 2085d9e..2e4f4bd 100644 --- a/includes/gateways/class-wc-heidelpay-gateway-dd.php +++ b/includes/gateways/class-wc-heidelpay-gateway-dd.php @@ -19,9 +19,8 @@ exit; // Exit if accessed directly } -require_once(WC_HEIDELPAY_PLUGIN_PATH . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'abstracts' . - DIRECTORY_SEPARATOR . 'abstract-wc-heidelpay-payment-gateway.php'); - +require_once WC_HEIDELPAY_PLUGIN_PATH . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'abstracts' . + DIRECTORY_SEPARATOR . 'abstract-wc-heidelpay-payment-gateway.php'; use Heidelpay\PhpPaymentApi\PaymentMethods\DirectDebitPaymentMethod; @@ -33,7 +32,7 @@ class WC_Gateway_HP_DD extends WC_Heidelpay_Payment_Gateway public function checkoutValidation() { // If gateway is not active no validation is necessary. - if($this->isGatewayActive() === false) { + if ($this->isGatewayActive() === false) { return true; } @@ -83,12 +82,12 @@ public function payment_fields() $accountHolderLabel = __('Account Holder', 'woocommerce-heidelpay'); $accountIbanLabel = __('IBAN', 'woocommerce-heidelpay'); - $accountHolder = wc()->customer->get_billing_first_name(). ' ' . wc()->customer->get_last_name(); + $accountHolder = wc()->customer->get_billing_first_name() . ' ' . wc()->customer->get_last_name(); echo '