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 #12 from heidelpay/develop
Browse files Browse the repository at this point in the history
Release 1.2.0
  • Loading branch information
bnoobbnoob authored Aug 1, 2018
2 parents a669dca + 50608a6 commit efe63a9
Show file tree
Hide file tree
Showing 14 changed files with 512 additions and 121 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Release Notes - heidelpay Payment Gateway for WooCommerce

## 1.2.0

### Fixed:
- Missing payment information for secured invoice and direct debit on success page and notification mail.
- Invoice instruction was shown in other mails where other payment methods were used.
- Exception that can occur in combination with other plugins.

### Added
#### Features:
- Support for push notifications
- A checkbox to decide whether payment information should be added to the notification mail or not.

## 1.1.1

### Fixed:
Expand Down
8 changes: 4 additions & 4 deletions includes/abstracts/abstract-wc-heidelpay-iframe-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,10 @@ public function enqueue_assets()
*/
public function after_pay()
{
$order_id = wc_get_order_id_by_order_key($_GET['key']);
$order = wc_get_order($order_id);
$order = $this->getOrderFromKey();

if ($order->get_payment_method() === $this->id) {
$this->performRequest($order_id);
if ($order !== null && $order->get_payment_method() === $this->id) {
$this->performRequest($order->get_id());
}
}

Expand Down Expand Up @@ -145,6 +144,7 @@ protected function getIFrame( WC_Order $order)
. '" 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>';
Expand Down
158 changes: 128 additions & 30 deletions includes/abstracts/abstract-wc-heidelpay-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,43 +51,33 @@ public function __construct()
$this->title = $this->get_option('title');
$this->description = $this->get_option('description');
$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('woocommerce_api_push', array($this, 'pushHandler'));
add_action('wp_enqueue_scripts', array($this, 'enqueue_assets'));
add_action('woocommerce_after_checkout_validation', array($this, 'checkoutValidation'));
add_action('woocommerce_email_before_order_table', array($this, 'emailInstructions'), 10, 3);

// Filter
add_filter('woocommerce_available_payment_gateways', array($this, 'setAvailability'));
add_filter('woocommerce_thankyou_order_received_text', array($this, 'addPayInfo'));
}

/**
* Set the id and PaymentMethod
*/
abstract protected function setPayMethod();

/**
* Validate the customer input coming from checkout.
* @return boolean
*/
public function checkoutValidation()
{
//return true;
}

/**
* Check whether this paymethod was selected based on
* @return bool
*/
public function isGatewayActive()
public function pushHandler()
{
if(!empty($_POST['payment_method'])) {
if($_POST['payment_method'] === $this->id)
return true;
if (array_key_exists('<?xml_version', $_POST)) {
$push = new WC_Heidelpay_Push();
$push->init(file_get_contents('php://input'), $this->get_option('secret'));
}

return false;
exit;
}

public function init_form_fields()
Expand Down Expand Up @@ -124,7 +114,7 @@ public function init_form_fields()
'Instructions that will be added to the thank you page and emails.',
'woocommerce-heidelpay'
),
'default' => __('The following account will be billed:', 'woocommerce-heidelpay'),
'default' => '',
'desc_tip' => true,
),
'security_sender' => array(
Expand Down Expand Up @@ -173,6 +163,29 @@ public function init_form_fields()
);
}

/**
* Validate the customer input coming from checkout.
* @return boolean
*/
public function checkoutValidation()
{
//return true;
}

/**
* Check whether this paymethod was selected based on
* @return bool
*/
public function isGatewayActive()
{
if (!empty($_POST['payment_method'])) {
if ($_POST['payment_method'] === $this->id)
return true;
}

return false;
}

/**
* register scripts and stylesheets for your payment gateway
*/
Expand Down Expand Up @@ -280,7 +293,7 @@ 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('PUSH_URL', get_home_url() . '/wc-api/push');
$this->payMethod->getRequest()->getCriterion()->set('SHOP.TYPE', $shopType);
$this->payMethod->getRequest()->getCriterion()->set(
'SHOPMODULE.VERSION',
Expand Down Expand Up @@ -318,6 +331,7 @@ protected function performRequest($order_id)
];
}

$this->paymentLog($this->payMethod->getResponse()->getError());
$this->addPaymentError($this->getErrorMessage());
} else {
$this->addPaymentError($this->getErrorMessage());
Expand All @@ -326,7 +340,10 @@ protected function performRequest($order_id)
WC_Log_Levels::ERROR,
htmlspecialchars(
print_r(
$this->plugin_id . ' - ' . $this->id . __(' Error: Paymentmethod was not found: ', 'woocommerce-heidelpay') . $this->bookingAction,
$this->plugin_id . ' - ' . $this->id . __(
' Error: Paymentmethod was not found: ',
'woocommerce-heidelpay'
) . $this->bookingAction,
1
)
)
Expand All @@ -336,6 +353,13 @@ protected function performRequest($order_id)
}
}

/**
* process the Form input from customer comimg from checkout.
*/
protected function handleFormPost()
{
}

/**
* @return string
*/
Expand All @@ -355,13 +379,6 @@ public function addPaymentError(String $message)
);
}

/**
* process the Form input from customer comimg from checkout.
*/
protected function handleFormPost()
{
}

/**
* Get the mapped Errormessage from Respone wich is html escaped.
* If a response is given as a parameter that will determine the message. Otherwise the Response from the payMethod
Expand Down Expand Up @@ -401,8 +418,8 @@ public function admin_options()
*/
public function callback_handler()
{
$response = new WC_Heidelpay_Response();
if (!empty($_POST)) {
$response = new WC_Heidelpay_Response();
$response->init($_POST, $this->get_option('secret'));
}
exit();
Expand Down Expand Up @@ -436,4 +453,85 @@ protected function getBookingSelection()
'default' => 'DB'
);
}

/**
* 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));
}

/**
* 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;
}

/**
* "woocommerce_thankyou_order_received_text" hook to display heidelpay-paymentInfo text on the successpage after
* payment.
* @param $orderReceivedText
* @return string
*/
public function addPayInfo($orderReceivedText)
{
$order = $this->getOrderFromKey();

if ($order === null || $order->get_payment_method() !== $this->id) {
return $orderReceivedText;
}

$paymentInfo = $order->get_meta('heidelpay-paymentInfo');

if(!empty($paymentInfo)) {
$orderReceivedText .= '<p>' . $paymentInfo . '</p>';
}

return $orderReceivedText;
}

/**
* 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)
{
if ($order->get_payment_method() !== $this->id) {
return null;
}

if ($this->instructions) {
echo wpautop(wptexturize($this->instructions)) . PHP_EOL;
}

$status = $order->get_status();
// defines the statuses when the mail should be send
$mailingArray = array(
'pending',
'on-hold',
'processing'
);

if ($this->get_option('send_payment_info') === 'yes') {
if (in_array($status, $mailingArray)) {
echo $order->get_meta('heidelpay-paymentInfo');
}
}
}
}
Loading

0 comments on commit efe63a9

Please sign in to comment.