Commit 5d5c7c81 authored by Vincent Mrose's avatar Vincent Mrose 💬
Browse files

Merge branch 'release/2.4.1'

parents 68ae99fa 12c5db81
......@@ -54,18 +54,19 @@ class WC_Gateway_Hosted_Payments extends WC_Payment_Gateway
/**
* Update Daniel Klöttschen - 16.11.2018:
*
*
* Added an if condition to check if 'Anrede' already exists as billing information from Germanized context.
* Yes: The additional gender field will not be required
* No: The additional gender field will be added to checkout page
*/
if (!array_key_exists('billing_title', $fields['billing']) && !in_array('Anrede', $fields['billing']['billing_title'])) {
if (!array_key_exists('billing_title', $fields['billing']) && !in_array('Anrede',
$fields['billing']['billing_title'])) {
$newBillingFields['billing_payco_gender'] = array(
'label' => __('Gender', 'upg'),
'type' => 'select',
'label' => __('Gender', 'upg'),
'type' => 'select',
'required' => 1,
'clear' => false,
'options' => array(
'clear' => false,
'options' => array(
\Upg\Library\Request\Objects\Person::SALUTATIONMALE => __('Male', $this->id),
\Upg\Library\Request\Objects\Person::SALUTATIONFEMALE => __('Female', $this->id),
),
......@@ -77,7 +78,7 @@ class WC_Gateway_Hosted_Payments extends WC_Payment_Gateway
$newCheckoutFields = array();
$pos = (int) array_search('billing_company', array_keys($checkoutFields));
$pos = (int)array_search('billing_company', array_keys($checkoutFields));
if (array_key_exists('b2b_enable', $this->settings) && strtolower($this->settings['b2b_enable']) == 'yes') {
$newCheckoutFields = array_merge(
......@@ -187,25 +188,31 @@ class WC_Gateway_Hosted_Payments extends WC_Payment_Gateway
}
if (!empty($_POST['billing_upg_company_registration_id'])) {
update_post_meta($order_id, '_billing_upg_company_registration_id', sanitize_text_field($_POST['billing_upg_company_registration_id']));
update_post_meta($order_id, '_billing_upg_company_registration_id',
sanitize_text_field($_POST['billing_upg_company_registration_id']));
}
if (!empty($_POST['billing_upg_company_vat_id'])) {
update_post_meta($order_id, '_billing_upg_company_vat_id', sanitize_text_field($_POST['billing_upg_company_vat_id']));
update_post_meta($order_id, '_billing_upg_company_vat_id',
sanitize_text_field($_POST['billing_upg_company_vat_id']));
}
if (!empty($_POST['billing_upg_company_tax_id'])) {
update_post_meta($order_id, '_billing_upg_company_tax_id', sanitize_text_field($_POST['billing_upg_company_tax_id']));
update_post_meta($order_id, '_billing_upg_company_tax_id',
sanitize_text_field($_POST['billing_upg_company_tax_id']));
}
if (!empty($_POST['billing_upg_company_register_type'])) {
update_post_meta($order_id, '_billing_upg_company_register_type', sanitize_text_field($_POST['billing_upg_company_register_type']));
update_post_meta($order_id, '_billing_upg_company_register_type',
sanitize_text_field($_POST['billing_upg_company_register_type']));
}
}
/**
* Get the payco setting object
*
* @param array $wcSettings
*
* @return \Upg\Library\Config
*/
public function getUpgConfig(array $wcSettings)
......@@ -272,11 +279,13 @@ class WC_Gateway_Hosted_Payments extends WC_Payment_Gateway
$api = new \Upg\Library\Api\CreateTransaction($this->getUpgConfig($this->settings), $request);
$result = $api->sendRequest();
if (!empty($this->iframeErrorMessage)) {
echo '<h1 class="paycoMessage">'.$this->iframeErrorMessage.'</h1>';
echo '<h1 class="paycoMessage">' . $this->iframeErrorMessage . '</h1>';
}
echo '<iframe id="payco_iframe" src="' . $result->getData('redirectUrl') . '" style="width:100%; border:none" width="100%" height="1500px" />';
$hostedPageUrl = $result->getData('redirectUrl');
update_post_meta($order_id, '_payco_recover_url', $hostedPageUrl);
echo '<iframe id="payco_iframe" src="' . $hostedPageUrl . '" style="width:100%; border:none" width="100%" height="1500px" />';
} catch (Exception $e) {
WC_Gateway_Upg_Payment_Log::logError($order_id.' - '.$e->getMessage());
WC_Gateway_Upg_Payment_Log::logError($order_id . ' - ' . $e->getMessage());
$order->update_status('failed', __('Invalid request.', 'upg'));
$order->update_status('cancelled', 'Invalid API Request');
echo '<p>' . __('There was an issue with your payment please contact the merchant', $this->id) . '</p>';
......@@ -286,7 +295,9 @@ class WC_Gateway_Hosted_Payments extends WC_Payment_Gateway
/**
* Get the Create Transaction Amount
*
* @param WC_Order $order
*
* @return \Upg\Library\Request\CreateTransaction
*/
private function getCreateTransactionRequest(WC_Order $order)
......@@ -297,8 +308,8 @@ class WC_Gateway_Hosted_Payments extends WC_Payment_Gateway
$request = $this->populateCreateTransactionBasketItems($order, $request);
$orderAmount = WC_Gateway_Upg_Helper::convertPriceToInt($order->get_total());
$autoCapture = ($this->settings['autocapture'] == 'no'?false:true);
update_post_meta($order->get_id(), '_payco_transaction_setting_autocapture', ($autoCapture?1:0));
$autoCapture = ($this->settings['autocapture'] == 'no' ? false : true);
update_post_meta($order->get_id(), '_payco_transaction_setting_autocapture', ($autoCapture ? 1 : 0));
update_post_meta($order->get_id(), '_payco_transaction_sent_request', 1);
$request->setIntegrationType(\Upg\Library\Request\CreateTransaction::INTEGRATION_TYPE_HOSTED_AFTER)
->setOrderID($order->get_order_number())
......@@ -317,7 +328,9 @@ class WC_Gateway_Hosted_Payments extends WC_Payment_Gateway
/**
* Get risk class to be used by transaction
*
* @param WC_Order $order
*
* @return int
*/
private function getRiskClass(WC_Order $order)
......@@ -384,15 +397,17 @@ class WC_Gateway_Hosted_Payments extends WC_Payment_Gateway
/**
* Populate the customer object
* @param WC_Order $order
*
* @param WC_Order $order
* @param \Upg\Library\Request\CreateTransaction $request
*
* @return \Upg\Library\Request\CreateTransaction
*/
private function populateCreateTransactionCustomer(WC_Order $order, \Upg\Library\Request\CreateTransaction $request)
{
$userId = $order->get_user_id();
if ($userId == 0) {
$userId = 'GUEST:ORDER:'.$order->get_order_number();
$userId = 'GUEST:ORDER:' . $order->get_order_number();
}
$user = new \Upg\Library\Request\Objects\Person();
......@@ -419,7 +434,7 @@ class WC_Gateway_Hosted_Payments extends WC_Payment_Gateway
}
}
if(!empty($salutation)) {
if (!empty($salutation)) {
$user->setSalutation($salutation);
}
$user->setName($order->get_billing_first_name())
......@@ -439,16 +454,20 @@ class WC_Gateway_Hosted_Payments extends WC_Payment_Gateway
/**
* Populate the address objects
* @param WC_Order $order
*
* @param WC_Order $order
* @param \Upg\Library\Request\CreateTransaction $request
*
* @return \Upg\Library\Request\CreateTransaction
*/
private function populateCreateTransactionAddresses(WC_Order $order, \Upg\Library\Request\CreateTransaction $request)
{
private function populateCreateTransactionAddresses(
WC_Order $order,
\Upg\Library\Request\CreateTransaction $request
) {
$billingAddress = new \Upg\Library\Request\Objects\Address();
$shippingAddress = new \Upg\Library\Request\Objects\Address();
$billingStreet = $order->get_billing_address_1().' '.$order->get_billing_address_2();
$shippingStreet = $order->get_shipping_address_1().' '.$order->get_shipping_address_2();
$billingStreet = $order->get_billing_address_1() . ' ' . $order->get_billing_address_2();
$shippingStreet = $order->get_shipping_address_1() . ' ' . $order->get_shipping_address_2();
$billingAddress->setStreet($billingStreet)
->setZip($order->get_billing_postcode())
......@@ -470,16 +489,20 @@ class WC_Gateway_Hosted_Payments extends WC_Payment_Gateway
/**
* Populate th basket
* @param WC_Order $order
*
* @param WC_Order $order
* @param \Upg\Library\Request\CreateTransaction $request
*
* @return \Upg\Library\Request\CreateTransaction
*/
private function populateCreateTransactionBasketItems(WC_Order $order, \Upg\Library\Request\CreateTransaction $request)
{
private function populateCreateTransactionBasketItems(
WC_Order $order,
\Upg\Library\Request\CreateTransaction $request
) {
$calculated = 0;
foreach ($order->get_items() as $itemId => $item) {
$product = $order->get_product_from_item($item);
$product = $order->get_product_from_item($item);
$upgItem = new \Upg\Library\Request\Objects\BasketItem();
$itemAmountWc = $order->get_line_subtotal($item, false, true);
$itemAmount = WC_Gateway_Upg_Helper::convertPriceToInt($itemAmountWc);
......@@ -538,7 +561,7 @@ class WC_Gateway_Hosted_Payments extends WC_Payment_Gateway
$discount = $calculated - $orderAmount;
if ($discount > 0) {
//get discount inc tax
$discount = intval('0'.$discount);
$discount = intval('0' . $discount);
$discountItem = new \Upg\Library\Request\Objects\BasketItem();
$discountItem->setBasketItemText(__('Discount', $this->id))
->setBasketItemCount(1)
......
......@@ -10,12 +10,12 @@ class WC_Gateway_Upg_Mns_Process
}
public static function processMessage($mns, wpdb $db)
{
{
global $wpdb;
$id = $wpdb->get_results($wpdb->prepare("SELECT post_id FROM {$wpdb->prefix}postmeta WHERE
meta_key = '_order_number' and meta_value = %d",$mns->order_id));
meta_key = '_order_number' and meta_value = %d", $mns->order_id));
if(count($id) === 1) {
if (count($id) === 1) {
$order = new WC_Order($id[0]->post_id);
} else {
$order = new WC_Order($mns->order_id);
......@@ -23,7 +23,7 @@ class WC_Gateway_Upg_Mns_Process
$paymentMethod = get_post_meta($order->get_id(), '_payment_method', true);
if($paymentMethod != WC_Gateway_Hosted_Payments::MODULE_ID) {
if ($paymentMethod != WC_Gateway_Hosted_Payments::MODULE_ID) {
return false;
}
......@@ -33,8 +33,8 @@ class WC_Gateway_Upg_Mns_Process
$processed = false;
$orderStatusProcess = false;
if(!empty($mnsTransactionStatus)) {
switch($mnsTransactionStatus) {
if (!empty($mnsTransactionStatus)) {
switch ($mnsTransactionStatus) {
case 'FRAUDCANCELLED':
self::mnsTransactionStatusFraudCancel($order);
$processed = true;
......@@ -78,7 +78,7 @@ class WC_Gateway_Upg_Mns_Process
}
}
if(!empty($mnsOrderStatus) && ($orderStatusProcess || !$processed)) {
if (!empty($mnsOrderStatus) && ($orderStatusProcess || !$processed)) {
switch ($mnsOrderStatus) {
case 'PAID':
self::mnsOrderStatusPaid($order, $db);
......@@ -110,7 +110,7 @@ class WC_Gateway_Upg_Mns_Process
}
}
if($processed) {
if ($processed) {
return true;
}
......@@ -129,7 +129,7 @@ class WC_Gateway_Upg_Mns_Process
public static function mnsTransactionStatusAcknowledgePending(WC_Order $order, $paymentReference)
{
update_post_meta( $order->get_id(), '_payco_payment_reference', $paymentReference);
update_post_meta($order->get_id(), '_payco_payment_reference', $paymentReference);
self::updateStatus($order, self::$setting['payco_mns_acknowledge_pending']);
}
......@@ -145,7 +145,7 @@ class WC_Gateway_Upg_Mns_Process
public static function mnsTransactionStatusMerchantPending(WC_Order $order)
{
self::updateStatus($order->get_id(), self::$setting['payco_mns_merchant_pending']);
self::updateStatus($order, self::$setting['payco_mns_merchant_pending']);
}
public static function mnsTransactionStatusInProgress(WC_Order $order)
......@@ -162,13 +162,14 @@ class WC_Gateway_Upg_Mns_Process
{
$autocapture = get_post_meta($order->get_id(), '_payco_transaction_setting_autocapture', true);
//ok now check if any autocaptures have been done
$autoCaptured = $db->get_var($db->prepare("SELECT autocapture FROM {$db->prefix}woocommerce_payco_captures WHERE order_id = %d;", $order->get_id()));
$autoCaptured = $db->get_var($db->prepare("SELECT autocapture FROM {$db->prefix}woocommerce_payco_captures WHERE order_id = %d;",
$order->get_id()));
if($autocapture && !$autoCaptured) {
if ($autocapture && !$autoCaptured) {
//ok go record an autocapture as happening
//correct the captures
$db->update(
$db->prefix.'woocommerce_payco_captures',
$db->prefix . 'woocommerce_payco_captures',
array(
'capture_amount' => 0,
),
......@@ -178,7 +179,7 @@ class WC_Gateway_Upg_Mns_Process
);
$db->insert(
$db->prefix.'woocommerce_payco_captures',
$db->prefix . 'woocommerce_payco_captures',
array(
'order_id' => $order->get_id(),
'capture_amount' => $order->get_total(),
......@@ -223,8 +224,8 @@ class WC_Gateway_Upg_Mns_Process
}
private static function updateStatus(WC_Order $order, $status)
{
if($order->post_status != $status && $status != 'crefo_none'){
{
if ($order->post_status != $status && $status != 'crefo_none') {
$order->update_status($status);
}
}
......@@ -232,7 +233,7 @@ class WC_Gateway_Upg_Mns_Process
public static function markMnsProcessed(wpdb $db, $id_mns)
{
$db->update(
$db->prefix.'woocommerce_payco_mns_messages',
$db->prefix . 'woocommerce_payco_mns_messages',
array(
'mns_processed' => 1,
'mns_error_processing' => 0,
......@@ -246,9 +247,9 @@ class WC_Gateway_Upg_Mns_Process
public static function markMnsError(wpdb $db, $id_mns, $processed = false)
{
$db->update(
$db->prefix.'woocommerce_payco_mns_messages',
$db->prefix . 'woocommerce_payco_mns_messages',
array(
'mns_processed' => ($processed?1:0),
'mns_processed' => ($processed ? 1 : 0),
'mns_error_processing' => 1,
),
array('id_mns' => $id_mns),
......
......@@ -2,7 +2,7 @@
/**
* Plugin Name: CrefoPay für WooCommerce
* Description: Die Komplettlösung für Ihre Zahlungsabwicklung.
* Version: 2.4.0
* Version: 2.4.1
* Author: CrefoPayment GmbH & Co. KG
* Text Domain: upg
*/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment