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 #17 from heidelpay/develop
Browse files Browse the repository at this point in the history
release 1.4.0
  • Loading branch information
xBlack-Shadow authored Oct 9, 2018
2 parents 135d77c + 28baec2 commit 58e0e8d
Show file tree
Hide file tree
Showing 12 changed files with 377 additions and 32 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Release Notes - heidelpay Payment Gateway for WooCommerce

## 1.4.0

### Added:
#### Features:
- Supports WooCommerce Subscriptions
- Add Prepayment Payment Method

## 1.3.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
* prepayment
* GiroPay
* iDEAL
* Paypal
Expand Down
31 changes: 28 additions & 3 deletions includes/abstracts/abstract-wc-heidelpay-iframe-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public function __construct()
);
}

/**
* @param int $order_id
* @return array|mixed
*/
public function process_payment($order_id)
{
return $this->toCheckoutPayment($order_id);
Expand Down Expand Up @@ -101,13 +105,19 @@ public function after_pay()
$order = $this->getOrderFromKey();

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

protected function performRequest($order_id)
/**
* @param $order
* @param null $uid
* @return mixed|void
* @throws \Heidelpay\PhpPaymentApi\Exceptions\PaymentFormUrlException
* @throws \Heidelpay\PhpPaymentApi\Exceptions\UndefinedTransactionModeException
*/
public function performRequest($order, $uid = null)
{
$order = wc_get_order($order_id);
echo $this->getIFrame($order);
}

Expand All @@ -133,6 +143,9 @@ protected function getIFrame(WC_Order $order)
$bookingAction = $this->getBookingAction();

if (method_exists($this->payMethod, $bookingAction)) {
if (class_exists('WC_Subscriptions_Order') && wcs_order_contains_subscription($order)) {
$bookingAction = 'registration';
}
$this->payMethod->$bookingAction(
$host,
'FALSE',
Expand Down Expand Up @@ -172,6 +185,18 @@ protected function getIFrame(WC_Order $order)
return null;
}

/**
* @param $order
* @param $uid
*/
public function performNoGuiRequest($order, $uid)
{
parent::performAfterRegistrationRequest($order, $uid);
}

/**
* @return mixed|string
*/
public function getBookingAction()
{
if (!empty($this->bookingModes[$this->get_option('bookingmode')])) {
Expand Down
72 changes: 60 additions & 12 deletions includes/abstracts/abstract-wc-heidelpay-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
abstract class WC_Heidelpay_Payment_Gateway extends WC_Payment_Gateway
{
public $payMethod;
public $bookingAction;
protected $name;
protected $bookingAction;
protected $messageMapper;

public function __construct()
Expand Down Expand Up @@ -215,15 +215,15 @@ public function process_payment($order_id)
$order = wc_get_order($order_id);
$this->prepareRequest($order);

return $this->performRequest($order_id);
return $this->performRequest($order);
}

/**
* @param $order WC_Order
*/
public function prepareRequest(WC_Order $order)
{
$this->setAuthentification();
$this->setAuthentification($order);
$this->setAsync();
$this->setCustomer($order);
$this->setBasket($order->get_id());
Expand All @@ -232,18 +232,25 @@ public function prepareRequest(WC_Order $order)

/**
* Set up your authentification data for Heidepay api
* @param WC_order $order
*/
protected function setAuthentification()
protected function setAuthentification(WC_order $order = null)
{
$isSandbox = false;
$channel = $this->get_option('transaction_channel');
if ($this->get_option('sandbox') === 'yes') {
$isSandbox = true;
}
if (class_exists('WC_Subscriptions_Order')) {
if ($order !== null && (wcs_order_contains_renewal($order) || wcs_order_contains_subscription($order))) {
$channel = $this->get_option('transaction_channel_subscription');
}
}
$this->payMethod->getRequest()->authentification(
$this->get_option('security_sender'),
$this->get_option('user_login'),
$this->get_option('user_password'),
$this->get_option('transaction_channel'),
$channel,
$isSandbox
);
}
Expand Down Expand Up @@ -328,16 +335,22 @@ protected function setCriterions()
* @return mixed
* @throws \Heidelpay\PhpPaymentApi\Exceptions\PaymentFormUrlException
*/
protected function performRequest($order_id)
public function performRequest($order, $uid)
{
if (!empty($_POST)) {
$this->handleFormPost($_POST);
}

if (!empty($this->bookingAction) && method_exists($this->payMethod, $this->bookingAction)) {
$action = $this->getBookingAction();
if (class_exists('WC_Subscriptions_Order') &&
wcs_order_contains_subscription($order) &&
empty($order->get_meta('heidelpay-Registration'))) {
$action = 'registration';
} else {
$action = $this->getBookingAction();
}
try {
$this->payMethod->$action();
$this->payMethod->$action($uid);
} catch (Exception $e) {
wc_get_logger()->log(WC_Log_Levels::DEBUG, htmlspecialchars(print_r($e->getMessage(), 1)));

Expand All @@ -347,10 +360,13 @@ protected function performRequest($order_id)
}

if ($this->payMethod->getResponse()->isSuccess()) {
return [
'result' => 'success',
'redirect' => $this->payMethod->getResponse()->getPaymentFormUrl(),
];
if ($this->payMethod->getResponse()->getFrontend()->getRedirectUrl() !== '' ||
!empty($this->payMethod->getResponse()->getFrontend()->getRedirectUrl())) {
return [
'result' => 'success',
'redirect' => $this->payMethod->getResponse()->getPaymentFormUrl(),
];
}
}

$this->paymentLog($this->payMethod->getResponse()->getError());
Expand Down Expand Up @@ -436,6 +452,38 @@ protected function paymentLog($logData)
$callers [1] ['function'] . ': ' . print_r($logData, 1), 1));
}

/**
* @param $order
* @param $uid
*/
public function performNoGuiRequest($order, $uid)
{
$this->performAfterRegistrationRequest($order, $uid);
}

/**
* @param WC_Order $order
* @param $uid
*/
public function performAfterRegistrationRequest($order, $uid)
{
if (!empty($_POST)) {
$this->handleFormPost($_POST);
}
if ($order->get_meta('heidelpay-Registration') !== '') {
try {
$this->payMethod->debitOnRegistration($uid);
} catch (Exception $e) {
wc_get_logger()->log(WC_Log_Levels::DEBUG, htmlspecialchars(print_r($e->getMessage(), 1)));

$this->addPaymentError($this->getErrorMessage());
}
if ($this->payMethod->getResponse()->isError()) {
$order->set_status('on-hold');
}
}
}

/**
* echoes the admin options
*/
Expand Down
14 changes: 12 additions & 2 deletions includes/class-wc-heidelpay-response.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,19 @@ public function handleResult($post_data, WC_Order $order)

$this->setPaymentInfo($order);

// If registration, do a debit on registration afterwards
if ($payCode[1] === 'RG' || $payCode[1] === 'CF') {
$order->add_meta_data('heidelpay-Registration', $uid);
$paymethod = 'WC_Gateway_HP_' . $payCode[0];
$paymethod = new $paymethod;
$paymethod->prepareRequest($order);
$paymethod->payMethod->getRequest()->getFrontend()->setEnabled('FALSE');
$paymethod->payMethod->getRequest()->getIdentification()->setReferenceid($uid);
$paymethod->performNoGuiRequest($order, $uid);
}

// If no money has been payed yet.
if ($payCode[0] !== 'IV' && ($payCode[1] === 'PA' || $payCode[1] === 'RG')) {
if ($payCode[0] !== 'IV' && $payCode[1] === 'PA') {
// If not Prepayment and Invoice payment can be captured manually
if ($payCode [0] !== 'PP') {
$note = __(
Expand All @@ -94,7 +105,6 @@ public function handleResult($post_data, WC_Order $order)
} else {
$order->payment_complete();
}

echo $order->get_checkout_order_received_url();

/* redirect customer to success page */
Expand Down
23 changes: 23 additions & 0 deletions includes/gateways/class-wc-heidelpay-gateway-cc.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,36 @@

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 . 'traits' .
DIRECTORY_SEPARATOR . 'trait-wc-heidelpay-subscription-gateway.php';

use Heidelpay\PhpPaymentApi\PaymentMethods\CreditCardPaymentMethod;

class WC_Gateway_HP_CC extends WC_Heidelpay_IFrame_Gateway
{
use WC_Heidelpay_Subscription_Gateway;

/**
* WC_Gateway_HP_CC constructor.
*/
public function __construct()
{
parent::__construct();
$this->constructorAddon();
}

public function init_form_fields()
{
parent::init_form_fields();
$this->initFormFieldsAddon();
}

/**
* sets the Payment Method.
*/
public function setPayMethod()
{
/** @var \Heidelpay\PhpPaymentApi\PaymentMethods\CreditCardPaymentMethod payMethod */
$this->payMethod = new CreditCardPaymentMethod();
$this->id = 'hp_cc';
$this->name = __('Credit Card', 'woocommerce-heidelpay');
Expand Down
22 changes: 22 additions & 0 deletions includes/gateways/class-wc-heidelpay-gateway-dc.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,33 @@

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 . 'traits' .
DIRECTORY_SEPARATOR . 'trait-wc-heidelpay-subscription-gateway.php';

use Heidelpay\PhpPaymentApi\PaymentMethods\DebitCardPaymentMethod;

class WC_Gateway_HP_DC extends WC_Heidelpay_IFrame_Gateway
{
use WC_Heidelpay_Subscription_Gateway;

/**
* WC_Gateway_HP_DC constructor.
*/
public function __construct()
{
parent::__construct();
$this->constructorAddon();
}

public function init_form_fields()
{
parent::init_form_fields();
$this->initFormFieldsAddon();
}

/**
* sets the Payment Method.
*/
public function setPayMethod()
{
$this->payMethod = new DebitCardPaymentMethod();
Expand Down
23 changes: 22 additions & 1 deletion includes/gateways/class-wc-heidelpay-gateway-dd.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,30 @@

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 . 'traits' .
DIRECTORY_SEPARATOR . 'trait-wc-heidelpay-subscription-gateway.php';

use Heidelpay\PhpPaymentApi\PaymentMethods\DirectDebitPaymentMethod;

class WC_Gateway_HP_DD extends WC_Heidelpay_Payment_Gateway
{
use WC_Heidelpay_Subscription_Gateway;

/** @var array Array of locales */
public $locale;

/**
* WC_Gateway_HP_DD constructor.
*/
public function __construct()
{
parent::__construct();
$this->constructorAddon();
}

/**
* @return bool|void
*/
public function checkoutValidation()
{
// If gateway is not active no validation is necessary.
Expand Down Expand Up @@ -58,6 +74,8 @@ public function init_form_fields()
{
parent::init_form_fields();

$this->initFormFieldsAddon();

$this->form_fields['title']['default'] = sprintf(__('%s', 'woocommerce-heidelpay'), $this->name);
$this->form_fields['description']['default'] = sprintf(__('Insert payment data for %s', 'woocommerce-heidelpay'), $this->name);
$this->form_fields['enabled']['label'] = sprintf(__('Enable %s', 'woocommerce-heidelpay'), $this->name);
Expand All @@ -77,6 +95,9 @@ public function init_form_fields()
);
}

/**
* sets Payment Fields
*/
public function payment_fields()
{
$accountHolderLabel = __('Account Holder', 'woocommerce-heidelpay');
Expand Down Expand Up @@ -116,7 +137,7 @@ protected function handleFormPost()
{
parent::handleFormPost();

if (!empty($_POST['accountholder']) AND !empty($_POST['accountiban'])) {
if (!empty($_POST['accountholder']) && !empty($_POST['accountiban'])) {
$this->payMethod->getRequest()->getAccount()->setHolder(htmlspecialchars($_POST['accountholder']));
$this->payMethod->getRequest()->getAccount()->setIban(htmlspecialchars($_POST['accountiban']));
}
Expand Down
Loading

0 comments on commit 58e0e8d

Please sign in to comment.