Commit 8c1ae17e authored by Daniel's avatar Daniel
Browse files

Merge branch 'develop'

parents eaf824f2 a34da955
{
"name": "crefopay/woocommerce",
"description": "CrefoPay Payment Solution for WooCommerce",
"version": "3.2.0",
"readme": "docs/de/admin_index.md",
"type": "project",
"keywords": ["payment", "crefopay", "creditreform", "riskmanagement", "psp"],
"homepage": "https://repo.crefopay.de/crefopay/woocommerce",
"license": "GPL-3.0-or-later",
"require": {
"wp-user-manager/wp-optionskit": "1.0.15",
"crefopay/php-clientlibrary": "1.2.4",
......
......@@ -3,7 +3,7 @@
* Plugin Name: CrefoPay Payment Solution
* Plugin URI: https://repo.crefopay.de/crefopay/woocommerce
* Description: The complete solution for your eCommerce payments.
* Version: 3.1.5
* Version: 3.2.0
* Requires at least: 5.1
* Requires PHP: 7.2
* Author: Shakuras GbR
......@@ -15,7 +15,7 @@
*
* Woo: 12345:342928dfsfhsf8429842374wdf4234sfd
* WC requires at least: 4.2
* WC tested up to: 5.7
* WC tested up to: 5.3.0
*
* Copyright: © 2019, Shakuras GbR - kontakt@shakuras.de.
* License: GNU General Public License v3.0
......@@ -47,6 +47,11 @@ require_once plugin_dir_path(WP_PLUGIN_DIR . '/woocommerce/woocommerce.php') . '
*/
require_once plugin_dir_path(__FILE__) . 'includes/controllers/class-wc-crefopay.php';
/**
* require CrefoPay Models
*/
require_once plugin_dir_path(__FILE__) . 'includes/models/class-wc-crefopay-order.php';
/**
* require payment gateways
*/
......@@ -85,7 +90,8 @@ define('ORDER_STATE_INDUNNING', 'wc-payment-dunning');
define('ORDER_STATE_RESERVED', 'wc-payment-reserved');
define('ORDER_STATE_CANCELLED', 'wc-cancelled');
define('ORDER_STATE_PENDING', 'wc-pending');
define('ORDER_STATE_CIA_PENDING', 'on-hold');
define('ORDER_STATE_BILL_PENDING', 'wc-pending');
define('ORDER_STATE_DONE', 'wc-completed');
define('ORDER_STATE_DELIVERED', 'wc-delivered');
define('ORDER_STATE_FAILED', 'wc-failed');
......@@ -122,7 +128,7 @@ define('PHONE_REGEX', '/^(((((((00|\+)[0-9]{2}[ \\\\\-\/]?)|0)[1-9][0-9]{1,4})[
* Main Class of the CrefoPay payment plugin
*
* @class CrefoPay_Payment_Solution
* @version 3.1.5
* @version 3.2.0
* @package CrefoPay-Payment-Solution
*/
class Crefopay_Payment_Solution
......@@ -323,13 +329,13 @@ class Crefopay_Payment_Solution
$orderID = $_POST['order_id'];
$logger = wc_get_logger('crefopay-payment-solution');
$payment = CrefoPay::getInstance();
$order = wc_get_order($orderID);
$order = WC_Crefo_Order::get_order_by_number($orderID);
// If we could not load the order we cannot proceed
if (!$order) {
$logger->error("unable to load order for reservation");
$logger->error("orderID = " . $orderID);
$logger->error("order_id = " . $order_id);
$logger->error("order_id = " . $_POST['order_id']);
wp_send_json_error(array(
'message' => 'order not found',
'redirectUrl' => ''
......@@ -341,7 +347,7 @@ class Crefopay_Payment_Solution
$logger->debug("Now trying to reserve order" . $orderID . " with paymentInstrumentID " . $_POST['paymentInstrumentId']);
$payment
->setPaymentInstrumentID($_POST['paymentInstrumentId'])
->setOrderID($orderID)
->setOrderID($order->get_order_number())
->reserve($_POST['paymentMethod'], $payment->getOrderAmount($order));
switch ($payment->getResultCode()) {
......
......@@ -8,15 +8,12 @@ defined('ABSPATH') or die('No script kiddies please!');
require_once plugin_dir_path(__FILE__) . '../controllers/class-wc-api-callback-processor.php';
use Upg\Library\Callback\Handler;
use Upg\Library\Request\Objects\Amount;
/**
* Provide success- and failrure- callback function
*
* @class WC_API_CrefoPay_Api_Callback
* @extends WC_API
* @version 3.1.5
* @version 3.2.0
* @package CrefoPay-Payment-Solution\Callbacks
*/
class WC_API_CrefoPay_Api_Callback extends WC_API
......@@ -76,7 +73,7 @@ class WC_API_CrefoPay_Api_Callback extends WC_API
exit;
}
if (!$order = wc_get_order($orderID)) {
if (!$order = WC_Crefo_Order::get_order_by_number($orderID)) {
$this->logger->error('crefoApiCallback Exception: order not found');
exit;
} else {
......
......@@ -16,7 +16,7 @@ use Upg\Library\Mns\Handler;
*
* @class WC_API_Crefo_Notification_Callback
* @extends WC_API
* @version 3.1.5
* @version 3.2.0
* @package CrefoPay-Payment-Solution\Callbacks
*/
class WC_API_Crefo_Notification_Callback extends WC_API
......@@ -57,7 +57,7 @@ class WC_API_Crefo_Notification_Callback extends WC_API
public function notification_callback_handler()
{
try {
$handler = new Handler(CrefoPay::getInstance()->getConfig(), $_POST, new CrefoPay_Notification_Callback_Processor());
$handler = new Handler(CrefoPay::getInstance()->getConfig(), $_POST, $this->callbackProcessor);
$handler->run();
} catch (\Upg\Library\Callback\Exception\MacValidation $macInvalid) {
$this->logger->critical('notification callback MacValidation.Exception: ' . $macInvalid->getMessage());
......
......@@ -12,7 +12,7 @@ require_once plugin_dir_path(__FILE__) . '../controllers/class-wc-crefopay.php';
* Process redirect payments
*
* @class WC_API_CrefoPay_Api_Callback
* @version 3.1.5
* @version 3.2.0
* @package CrefoPay-Payment-Solution\Controllers
*/
class CrefoPay_API_Callback_Processor
......@@ -51,8 +51,7 @@ class CrefoPay_API_Callback_Processor
{
global $woocommerce;
try {
if ($order = wc_get_order($this->orderId)) {
// Updating the order
if ($order = WC_Crefo_Order::get_order_by_number($this->orderId)) {
// Empty cart before redirect to "thank you" page
$woocommerce->cart->empty_cart();
......
......@@ -52,7 +52,7 @@ use Upg\Library\Validation\Validation;
*
* @class CrefoPay
* @autoloads Upg\Library
* @version 3.1.5
* @version 3.2.0
* @package CrefoPay-Payment-Solution\Controllers
*/
class CrefoPay
......@@ -545,13 +545,15 @@ class CrefoPay
*/
public function cancel(string $order_id)
{
if (empty($order_id)) {
throw new Exception('No order id provided');
}
try {
$order = wc_get_order($order_id);
if (empty($order)) {
throw new Exception('order not found');
}
// create the request
$this->request = new CancelRequest($this->config);
$this->request->setOrderID($order_id);
$this->request->setOrderID($order->get_order_number());
// perform api call
$api = new CancelApi($this->config, $this->request);
......@@ -604,11 +606,16 @@ class CrefoPay
}
try {
// getting the order number
$order = wc_get_order($order_id);
if (empty($order)) {
throw new Exception('order not found');
}
// create the request
$this->request = new CaptureRequest($this->config);
$this->request
->setOrderID($order_id)
->setOrderID($order->get_order_number())
->setAmount(new Amount($amount))
->setCaptureID($capture_id);
......@@ -641,13 +648,16 @@ class CrefoPay
*/
public function finish(string $order_id)
{
if (empty($order_id)) {
throw new Exception('No order id provided');
}
try {
// getting the order number
$order = wc_get_order($order_id);
if (empty($order)) {
throw new Exception('order not found');
}
// create the request
$this->request = new FinishRequest($this->config);
$this->request->setOrderID($order_id);
$this->request->setOrderID($order->get_order_number());
// perform api call
$api = new FinishApi($this->config, $this->request);
......@@ -854,17 +864,20 @@ class CrefoPay
*/
public function refund(int $amount, string $capture_id, string $order_id, string $desc = 'unknown description')
{
if (empty($amount)) {
throw new Exception('Amount must be greater then zero');
}
if (empty($capture_id)) {
throw new Exception('No capture id provided');
}
if (empty($order_id)) {
throw new Exception('No order id provided');
}
try {
if (empty($amount)) {
throw new Exception('Amount must be greater then zero');
}
if (empty($capture_id)) {
throw new Exception('No capture id provided');
}
// getting the order number
$order = wc_get_order($order_id);
if (empty($order)) {
throw new Exception('order not found');
}
$this->request = new RefundRequest($this->config);
if ($desc != '') {
$this->request->setRefundDescription($desc);
......@@ -872,7 +885,7 @@ class CrefoPay
$this->request
->setAmount(new Amount($amount))
->setCaptureID($capture_id)
->setOrderID($order_id);
->setOrderID($order->get_order_number());
$api = new RefundApi($this->config, $this->request);
$this->response = $api->sendRequest();
......
......@@ -14,7 +14,7 @@ if ( class_exists( 'WC_GZD_Email_Customer_Paid_For_Order' ) ) :
* from the WooCommerce Germanized extension.
*
* @class CrefoPay_GZD_Email_Customer_Paid_For_Order
* @version 3.1.5
* @version 3.2.0
* @package CrefoPay-Payment-Solution\Controllers
*/
class CrefoPay_GZD_Email_Customer_Paid_For_Order extends WC_GZD_Email_Customer_Paid_For_Order
......
<?php
/**
* CrefoPay Notification Callback Processor
*
*
* prevent unauthorized access
*/
defined('ABSPATH') or die('No script kiddies please!');
......@@ -10,12 +10,13 @@ require_once plugin_dir_path(__FILE__) . '../controllers/class-wc-crefopay.php';
use Upg\Library\Mns\ProcessorInterface;
/**
* Process CrefoPay notifications callbacks.
*
* @class CrefoPay_Notification_Callback_Processor
* @implements Upg\Library\Mns\ProcessorInterface
* @version 3.1.5
* @version 3.2.0
* @package CrefoPay-Payment-Solution\Controllers
*/
class CrefoPay_Notification_Callback_Processor implements ProcessorInterface
......@@ -136,7 +137,6 @@ class CrefoPay_Notification_Callback_Processor implements ProcessorInterface
*/
private $version;
/**
* Processor contructor
*/
......@@ -205,8 +205,30 @@ class CrefoPay_Notification_Callback_Processor implements ProcessorInterface
*/
public function run()
{
$options = get_option('igp_settings');
// check if notifications shall be handled synchronous
if ($options['crefopay_orderstate_processing'] == 'sync') {
$processor = new CrefoPay_Notification_Processor();
$order = WC_Crefo_Order::get_order_by_number($this->orderID);
// if it's still empty we were unable to find the order
if (!$order) {
throw new Exception("unable to load order with CrefoPay orderID {$this->orderID}");
}
$mnsQueue[] = $this->getMnsArray();
try {
$processor->process_mns($order, $mnsQueue);
} catch (Exception $e) {
$this->logger->error('undable to process notification for order ' . $order->get_order_number() . ': ' . $e->getMessage());
throw $e;
}
}
try {
if ($order = wc_get_order($this->orderID)) {
$order = WC_Crefo_Order::get_order_by_number($this->orderID);
if ($order) {
if ($order->meta_exists(META_TAG_MNS)) {
$mnsQueue = $order->get_meta(META_TAG_MNS);
$this->logger->debug("loaded existing mns queue: " . print_r($mnsQueue, true));
......@@ -232,7 +254,7 @@ class CrefoPay_Notification_Callback_Processor implements ProcessorInterface
* Returns CrefoPay mns as array.
* Adds the processed key to the mns array and set its value to false.
*
* @return void
* @return array
*/
private function getMnsArray()
{
......@@ -252,7 +274,7 @@ class CrefoPay_Notification_Callback_Processor implements ProcessorInterface
'transactionBalance' => $this->transactionBalance,
'timestamp' => $this->timestamp,
'version' => $this->version,
'processed' => false
'processed' => false,
);
}
}
......@@ -10,7 +10,7 @@ defined('ABSPATH') or die('No script kiddies please!');
* Process CrefoPay notifications.
*
* @class CrefoPay_Notification_Processor
* @version 3.1.5
* @version 3.2.0
* @package CrefoPay-Payment-Solution\Controllers
*/
class CrefoPay_Notification_Processor
......@@ -87,7 +87,7 @@ class CrefoPay_Notification_Processor
case self::STATE_CIAPENDING:
if ($this->options['crefopay_orderstate_cia_pending'] != 'disabled') {
$newState = empty($this->options['crefopay_orderstate_cia_pending']) ? ORDER_STATE_PENDING : $this->options['crefopay_orderstate_cia_pending'];
$newState = empty($this->options['crefopay_orderstate_cia_pending']) ? ORDER_STATE_CIA_PENDING : $this->options['crefopay_orderstate_cia_pending'];
$this->logger->debug("set new order status: " . $newState);
if ($order->set_status($newState, __('TRANSACTION_CIAPENDING', 'crefopay-payment-solution'))) {
$this->logger->debug("successfully set new order state " . $newState);
......
......@@ -19,7 +19,7 @@ require_once plugin_dir_path(__FILE__) . '../models/class-wc-crefopay-error.php'
*
* @class WC_Crefo_Exception
* @extends WC_Data_Exception
* @version 3.1.5
* @version 3.2.0
* @package CrefoPay Payment Solution
*/
class WC_Crefo_Exception extends WC_Data_Exception
......
......@@ -14,7 +14,7 @@ require_once plugin_dir_path(__FILE__) . '../controllers/class-wc-crefopay.php';
*
* @class WC_Crefo_Credit Card
* @extends WC_Crefo_Gateway
* @version 3.1.5
* @version 3.2.0
* @package CrefoPay Payment Solution
*/
class WC_Crefo_CreditCard extends WC_Crefo_Gateway
......@@ -118,7 +118,7 @@ class WC_Crefo_CreditCard extends WC_Crefo_Gateway
$payment = CrefoPay::getInstance();
// Create the transaction
$payment->setIntegrationType(self::CREFO_INTEGRATION_TYPE_PCI)->setOrderID($order_id)->createTransaction();
$payment->setIntegrationType(self::CREFO_INTEGRATION_TYPE_PCI)->setOrderID($order->get_order_number())->createTransaction();
// check if CC is allowed or CC3D is required
if ($payment->isAllowedPaymentMethod($this->getPaymentMethod())) {
......@@ -178,6 +178,7 @@ class WC_Crefo_CreditCard extends WC_Crefo_Gateway
$logging = $options['crefopay_js_log_enabled'] ? 'enabled' : 'disabled';
$order = wc_get_order($order_id);
$order_number = $order->get_order_number();
$payment = CrefoPay::getInstance();
// load the payment template style sheet
......@@ -236,7 +237,7 @@ class WC_Crefo_CreditCard extends WC_Crefo_Gateway
url: '<?=admin_url('admin-ajax.php')?>',
data: {
action: 'credit_card_payment',
order_id: '<?=$order_id?>',
order_id: '<?=$order_number?>',
paymentInstrumentId: response.paymentInstrumentId,
paymentMethod: response.paymentMethod
},
......@@ -363,7 +364,7 @@ class WC_Crefo_CreditCard extends WC_Crefo_Gateway
} else {
var secureFieldsClientInstance = new SecureFieldsClient(
"<?=$payment->getPublicKey()?>",
"<?=$order_id?>",
"<?=$order_number?>",
paymentRegisteredCallback,
initializationCompleteCallback,
configuration
......
......@@ -15,7 +15,7 @@ require_once plugin_dir_path(__FILE__) . 'class-wc-payment-gateway.php';
*
* @class WC_Crefo_Debit
* @extends WC_Crefo_Gateway
* @version 3.1.5
* @version 3.2.0
* @package CrefoPay-Payment-Solution\Gateways
*/
class WC_Crefo_Debit extends WC_Crefo_Gateway
......
<?php
if ( ! defined( 'ABSPATH' ) ) {
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly.
}
......@@ -13,21 +13,21 @@ require_once plugin_dir_path(__FILE__) . 'class-wc-payment-gateway.php';
*
* @class WC_Crefo_Invoice
* @extends WC_Crefo_Gateway
* @version 3.1.5
* @version 3.2.0
* @package CrefoPay-Payment-Solution\Gateways
*/
class WC_Crefo_Invoice extends WC_Crefo_Gateway
{
/**
* Formated date of birth: YYYY-MM-DD
*
*
* @var string
*/
protected $dateOfBirth;
/**
* Salutation
*
*
* @var string
*/
protected $salutation;
......@@ -41,31 +41,37 @@ class WC_Crefo_Invoice extends WC_Crefo_Gateway
// payment gateway description
$this->_setCrefoLabel(PAYMENT_METHOD_BILL);
$this->id = 'crefopay_invoice';
$this->has_fields = true;
$this->has_fields = true;
if (array_key_exists('disable_payment_logos', $pluginOptions) && !$pluginOptions['disable_payment_logos']) {
$this->icon = plugin_dir_url(false) . 'crefopay-payment-solution' . '/img/BILL.png';
$this->icon = plugin_dir_url(false) . 'crefopay-payment-solution' . '/img/BILL.png';
}
return parent::__construct();
}
/**
* Form field initialisation
*
*
* @return void
*/
public function init_form_fields()
{
public function init_form_fields()
{
$parent_fields = parent::init_form_fields();
$this->form_fields = array_merge($parent_fields,
array(
'label_birthdate' => array (
'title' => __( 'Label Birthdate', 'crefopay-payment-solution' ),
'crefopay_set_complete_invoice' => array(
'title' => __('Set Payment Complete for invoice', 'crefopay-payment-solution'),
'type' => 'checkbox',
'description' => __('Set Payment Complete for invoice Description', 'crefopay-payment-solution'),
'default' => 'no',
'desc_tip' => true,
),
'label_birthdate' => array(
'title' => __('Label Birthdate', 'crefopay-payment-solution'),
'type' => 'text',
'description' => __( 'Label Birthdate Description', 'crefopay-payment-solution' ),
'default' => __( 'Birthdate', 'crefopay-payment-solution' ),
'desc_tip' => true,
'description' => __('Label Birthdate Description', 'crefopay-payment-solution'),
'default' => __('Birthdate', 'crefopay-payment-solution'),
'desc_tip' => true,
),
'label_invoice_birthdate_day' => array(
'title' => __('Label Birthdate Day', 'crefopay-payment-solution'),
......@@ -87,12 +93,11 @@ class WC_Crefo_Invoice extends WC_Crefo_Gateway
'description' => __('Label Birthdate Year Description', 'crefopay-payment-solution'),
'default' => '',
'desc_tip' => true,
)
),
)
);
}
/**
* Renders the frontend input form.
*
......@@ -102,48 +107,48 @@ class WC_Crefo_Invoice extends WC_Crefo_Gateway
{
// Datepicker and salutation is just required for B2C transactions
if (!CrefoPay::getInstance()->isBusinessTransaction()) {
wp_enqueue_style('crefopay_css', plugin_dir_url(false) . 'crefopay-payment-solution/css/crefopay.css');
?>
wp_enqueue_style('crefopay_css', plugin_dir_url(false) . 'crefopay-payment-solution/css/crefopay.css');
?>
<fieldset id="wc-crefopay_invoice-form" class="wc-crefo-invoice-form wc-payment-form" style="background:transparent;">
<!-- Request for salutation -->
<div class="form-row form-row-first">
<label for="cp-salutation-invoice"><?= __('Salutation', 'crefopay-payment-solution'); ?>&nbsp;<abbr class="required" title="<?= __('required', 'woocommerce') ?>">*</abbr></label>
<label for="cp-salutation-invoice"><?=__('Salutation', 'crefopay-payment-solution');?>&nbsp;<abbr class="required" title="<?=__('required', 'woocommerce')?>">*</abbr></label>
<select name="cp-salutation-invoice" id="cp-salutation-invoice">
<?php $this->printSalutation() ?>
<?php $this->printSalutation()?>
</select>
</div>
<div class="clear"></div>
<!-- STRAT: html datepicker -->
<?php
if (!empty($this->get_option('label_birthdate'))) {
?>
<label for="cp-date-of-birth-invoice"><?= $this->get_option('label_birthdate') ?>&nbsp;<abbr class="required" title="<?= __('required', 'woocommerce') ?>">*</abbr></label>
<?php
}
?>
if (!empty($this->get_option('label_birthdate'))) {
?>
<label for="cp-date-of-birth-invoice"><?=$this->get_option('label_birthdate')?>&nbsp;<abbr class="required" title="<?=__('required', 'woocommerce')?>">*</abbr></label>
<?php
}
?>
<div class="cp-input-group" id ="cp-date-of-birth-invoice">
<!-- Label Day -->
<?php if (!empty($this->get_option('label_invoice_birthdate_day'))) { ?>
<label class="cp-input-group-text" for="cp-date-of-birth-invoice-day"><?= $this->get_option('label_invoice_birthdate_day') ?></label>
<?php } ?>
<?php if (!empty($this->get_option('label_invoice_birthdate_day'))) {?>
<label class="cp-input-group-text" for="cp-date-of-birth-invoice-day"><?=$this->get_option('label_invoice_birthdate_day')?></label>
<?php }?>
<select name="cp-date-of-birth-invoice-day" id="cp-date-of-birth-invoice-day" class="cp-custom-select">
<?php $this->printOptionDays() ?>
</select>
<?php $this->printOptionDays()?>
</select>
<!-- Label Month -->
<?php if (!empty($this->get_option('label_invoice_birthdate_mon'))) { ?>
<label class="cp-input-group-text" for="cp-date-of-birth-invoice-mon"><?= $this->get_option('label_invoice_birthdate_mon') ?></label>
<?php } ?>
<?php if (!empty($this->get_option('label_invoice_birthdate_mon'))) {?>
<label class="cp-input-group-text" for="cp-date-of-birth-invoice-mon"><?=$this->get_option('label_invoice_birthdate_mon')?></label>
<?php }?>
<select name="cp-date-of-birth-invoice-mon" id="cp-date-of-birth-invoice-mon" class="cp-custom-select">
<?php $this->printOptionMonths() ?>
<?php $this->printOptionMonths()?>
</select>
<!-- Label Year -->