Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Commit

Permalink
Merge pull request #15 from heidelpay/develop
Browse files Browse the repository at this point in the history
release
  • Loading branch information
xBlack-Shadow authored Aug 29, 2018
2 parents efe63a9 + 1412399 commit 135d77c
Show file tree
Hide file tree
Showing 15 changed files with 329 additions and 218 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
116 changes: 55 additions & 61 deletions assets/js/creditCardFrame.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
31 changes: 17 additions & 14 deletions includes/abstracts/abstract-wc-heidelpay-iframe-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
*/
Expand All @@ -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,
Expand All @@ -109,14 +105,20 @@ 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
* @throws \Heidelpay\PhpPaymentApi\Exceptions\PaymentFormUrlException
* @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');
Expand All @@ -139,15 +141,15 @@ protected function getIFrame( WC_Order $order)

$iFrame = '<form method="post" class="formular" id="paymentFrameForm">';
if ($this->payMethod->getResponse()->isSuccess()) {
$iFrame .= '<iframe id="paymentFrameIframe" src="'
$iFrame .= '<iframe id="paymentFrameIframe" src="'
. $this->payMethod->getResponse()->getPaymentFormUrl()
. '" frameborder="0" scrolling="no" style="height:360px;"></iframe><br />';
} else {
$iFrame .= '<pre>' . print_r($this->getErrorMessage(), 1) . '</pre>';
$this->paymentLog($this->payMethod->getResponse()->getError());
}
$iFrame .= '<button type="submit">' . __('Pay Now', 'woocommerce-heidelpay') . '</button>';
$iFrame .= '</form>';
$iFrame .= '</form>';

return $iFrame;
}
Expand All @@ -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
)
Expand All @@ -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;
Expand Down
Loading

0 comments on commit 135d77c

Please sign in to comment.