Skip to content

Commit fcd436e

Browse files
authored
Merge pull request #181 from paynl/feature/updates_for_v4
Feature/updates for v4
2 parents ef854cd + 7bc9ba1 commit fcd436e

7 files changed

Lines changed: 46 additions & 122 deletions

File tree

includes/classes/PPMFWC/Gateway/Abstract.php

Lines changed: 17 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
1010
* @phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
1111
* @phpcs:disable PSR1.Methods.CamelCapsMethodName
12-
* @phpcs:disable Squiz.Commenting.FunctionComment.TypeHintMissing
12+
* @phpcs:disable Squiz.Commenting.FunctionComment.TypeHintMissing
1313
* @phpcs:disable PSR12.Properties.ConstantVisibility
1414
*/
1515

@@ -614,15 +614,17 @@ public function process_payment($order_id)
614614

615615
# Return success redirect
616616
return array(
617-
'result' => 'success',
618-
'redirect' => $payOrder->getPaymentUrl()
617+
'result' => 'success',
618+
'redirect' => $payOrder->getPaymentUrl()
619619
);
620+
620621
} catch (PPMFWC_Exception_Notice $e) {
621622
PPMFWC_Helper_Data::ppmfwc_payLogger('Process payment start notice: ' . $e->getMessage());
622623
$message = $e->getMessage();
623624
wc_add_notice($message, 'error');
624-
} catch (Exception $e) {
625-
PPMFWC_Helper_Data::ppmfwc_payLogger('Could not initiate payment. Error: ' . esc_html($e->getMessage()), null, array('wc-order-id' => $order_id, 'paymentOption' => $paymentOption));
625+
626+
} catch (Exception $e) {
627+
PPMFWC_Helper_Data::ppmfwc_payLogger('Could not initiate payment. Error ' . esc_html($e->getMessage()), null, array('wc_order_id' => $order_id, 'methodid' => $paymentOption), 'critical');
626628
$message = 'Could not initiate payment. Please try again or use another payment method.';
627629
wc_add_notice(esc_html(__($message, PPMFWC_WOOCOMMERCE_TEXTDOMAIN)), 'error');
628630
}
@@ -667,10 +669,12 @@ protected function startTransaction(WC_Order $order, $pickupLocation = null)
667669
$request->setExchangeUrl($exchangeUrl);
668670
$request->setDescription(str_replace('__', ' ', $prefix) . $order->get_order_number());
669671
$request->setAmount($order->get_total());
670-
$request->setReference($order->get_order_number());
672+
673+
$raw = (string)($order->get_order_number() ?? '');
674+
$clean = preg_replace('/[^A-Za-z0-9]/u', '', $raw);
675+
$request->setReference($clean);
671676

672677
if ($this->getOptionId() == 1927) {
673-
//paydbg(PPMFWC_Helper_Data::getPostTextField('terminal_id'));
674678
$request->setTerminal(PPMFWC_Helper_Data::getPostTextField('terminal_id'));
675679
}
676680

@@ -690,78 +694,6 @@ protected function startTransaction(WC_Order $order, $pickupLocation = null)
690694
$requestOrderData->setDeliveryAddress(PPMFWC_Helper_Config::getDeliveryAddress($order));
691695
$request->setOrder($requestOrderData);
692696

693-
694-
// # Retrieve order data
695-
// $shippingAddress = $order->get_shipping_address_1() . ' ' . $order->get_shipping_address_2();
696-
//
697-
// $billingAddress = $order->get_billing_address_1() . ' ' . $order->get_billing_address_2();
698-
// $aBillingAddress = \Paynl\Helper::splitAddress($billingAddress);
699-
// $aShippingAddress = \Paynl\Helper::splitAddress($shippingAddress);
700-
//
701-
// # Check order meta for postNL plugin house number
702-
// $_shipping_house_number = $order->get_meta('_shipping_house_number');
703-
// if (empty($aShippingAddress[1]) && !empty($_shipping_house_number)) {
704-
// $shippingAddress = $order->get_shipping_address_1() . ' ' . $_shipping_house_number . $order->get_shipping_address_2();
705-
// }
706-
//
707-
// $_billing_house_number = $order->get_meta('_billing_house_number');
708-
// if (empty($aBillingAddress[1]) && !empty($_billing_house_number)) {
709-
// $billingAddress = $order->get_billing_address_1() . ' ' . $_billing_house_number .
710-
// $order->get_billing_address_2();
711-
// }
712-
//
713-
// $aBillingAddress = \Paynl\Helper::splitAddress($billingAddress);
714-
// $aShippingAddress = \Paynl\Helper::splitAddress($shippingAddress);
715-
// $address = array(
716-
// 'streetName' => $aShippingAddress[0],
717-
// 'houseNumber' => $aShippingAddress[1],
718-
// 'zipCode' => $order->get_shipping_postcode(),
719-
// 'city' => $order->get_shipping_city(),
720-
// 'country' => $order->get_shipping_country()
721-
// );
722-
//
723-
// if ($this->get_option('use_invoice_address') == 'yes')
724-
// {
725-
// PPMFWC_Helper_Data::ppmfwc_payLogger('Use_invoice_address=yes. Updating shipping address');
726-
// $address = array(
727-
// 'streetName' => $aBillingAddress[0],
728-
// 'houseNumber' => $aBillingAddress[1],
729-
// 'zipCode' => $order->get_billing_postcode(),
730-
// 'city' => $order->get_billing_city(),
731-
// 'country' => $billing_country
732-
// );
733-
// }
734-
735-
# $startData['address'] = $address;
736-
//$startData['invoiceAddress'] = array(
737-
// 'initials' => $order->get_billing_first_name(),
738-
// 'lastName' => substr($order->get_billing_last_name(), 0, 32),
739-
// 'streetName' => $aBillingAddress[0],
740-
// 'houseNumber' => $aBillingAddress[1],
741-
// 'zipCode' => $order->get_billing_postcode(),
742-
// 'city' => $order->get_billing_city(),
743-
// 'country' => $billing_country,
744-
//);
745-
746-
//$startData['products'] = $this->getProductLines($order);
747-
748-
// $optionSubId = PPMFWC_Helper_Data::getPostTextField('selectedissuer');
749-
// if (empty($optionSubId)) {
750-
// $optionSubId = PPMFWC_Helper_Data::getPostTextField('option_sub_id');
751-
// }
752-
753-
// if (!empty($optionSubId)) {
754-
// $startData['bank'] = $optionSubId;
755-
// }
756-
757-
$language = get_option('paynl_language');
758-
759-
if ($language == 'browser') {
760-
$language = PPMFWC_Helper_Data::getBrowserLanguage();
761-
}
762-
763-
//$startData['language'] = $language;
764-
765697
if ($pickupLocation === true) {
766698
PPMFWC_Helper_Data::ppmfwc_payLogger('Payment at pickup, order has been made but transaction skipped.');
767699
$order->save();
@@ -821,21 +753,22 @@ public static function getServiceId()
821753
*/
822754
public function process_refund($order_id, $amount = null, $reason = '')
823755
{
824-
PPMFWC_Helper_Data::ppmfwc_payLogger('process_refund', $order_id, array('orderid' => $order_id, 'amount' => $amount));
825-
826756
if ($amount <= 0) {
757+
PPMFWC_Helper_Data::ppmfwc_payLogger('process_refund: fund amount must be greater than 0.0', '', array('orderid' => $order_id, 'amount' => $amount));
827758
return new WP_Error('1', "Refund amount must be greater than €0.00");
828759
}
829760

830761
$order = wc_get_order($order_id);
831762
$transactionLocalDB = PPMFWC_Helper_Transaction::getPaidTransactionIdForOrderId($order_id);
763+
$transactionId = $transactionLocalDB['transaction_id'] ?? '';
764+
765+
PPMFWC_Helper_Data::ppmfwc_payLogger('process_refund', $transactionId, array('orderid' => $order_id, 'amount' => $amount));
832766

833-
if (empty($order) || empty($transactionLocalDB) || empty($transactionLocalDB['transaction_id'])) {
834-
PPMFWC_Helper_Data::ppmfwc_payLogger('Refund canceled, order empty', $order_id, array('orderid' => $order_id, 'amunt' => $amount, 'transactionId' => $transactionLocalDB['transaction_id'])); // phpcs:ignore
767+
if (empty($order) || empty($transactionId)) {
768+
PPMFWC_Helper_Data::ppmfwc_payLogger('Refund canceled, order empty', $order_id, array('orderid' => $order_id, 'amunt' => $amount, 'transactionId' => $transactionId)); // phpcs:ignore
835769
return new WP_Error(1, esc_html(__('This transaction seems to have already been refunded or may not be captured yet. Please check the status on My.pay.', PPMFWC_WOOCOMMERCE_TEXTDOMAIN)));
836770
}
837771

838-
$transactionId = $transactionLocalDB['transaction_id'];
839772

840773
try {
841774
# First set local state to refund so that the exchange will not try to refund aswell.

includes/classes/PPMFWC/Gateways.php

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -850,16 +850,6 @@ public static function ppmfwc_onReturn()
850850

851851
PPMFWC_Helper_Data::ppmfwc_payLogger('FINISH, back from PAY payment', $orderId, array('orderStatusId' => $orderStatusId, 'status' => $status));
852852

853-
///?wc-api=Wc_Pay_Gateway_Return
854-
/// id=44907558081X114c
855-
/// reference=39
856-
/// statusAction=CANCEL
857-
/// statusCode=-64
858-
/// ticket=
859-
/// utm_nooverride=1
860-
861-
#return (new PayStatus())->get($statusCode) === PayStatus::DENIED
862-
863853
try {
864854
# Retrieve URL to continue (and update status if necessary)
865855
if (!empty($orderId)) {
@@ -1028,10 +1018,8 @@ public static function ppmfwc_onExchange()
10281018
$exchange->setResponse(true, 'Ignoring pending');
10291019
}
10301020

1031-
$config = PPMFWC_Helper_Config::getPayConfig();
1032-
$payOrder = $exchange->process($config);
1033-
1034-
PPMFWC_Helper_Data::ppmfwc_payLogger('payOrder: ' . $payOrder->getOrderId());
1021+
$payOrder = $exchange->process(PPMFWC_Helper_Config::getPayConfig());
1022+
$payOrderId = $payOrder->getOrderId();
10351023

10361024
if ($payOrder->isPending()) {
10371025
$exchange->setResponse(true, 'Ignoring pending.');
@@ -1040,12 +1028,14 @@ public static function ppmfwc_onExchange()
10401028
$order_id = $exchange->getReference();
10411029
$methodId = $payOrder->getPaymentMethod();
10421030

1031+
PPMFWC_Helper_Data::ppmfwc_payLogger('Exchange', $payOrderId, array('action' => $action, 'wc_order_id' => $order_id, 'methodid' => $methodId));
1032+
10431033
if ($methodId == PPMFWC_Gateway_Abstract::PAYMENT_METHOD_PINREFUND && $action == self::ACTION_NEWPPT) {
10441034
$action = self::ACTION_PINREFUND;
10451035
}
10461036

10471037
if ($action == self::ACTION_NEWPPT) {
1048-
if (PPMFWC_Helper_Transaction::checkProcessing($order_id)) {
1038+
if (PPMFWC_Helper_Transaction::checkProcessing($payOrderId)) {
10491039
$exchange->setResponse(false, 'Already processing payment.');
10501040
}
10511041
}
@@ -1057,24 +1047,26 @@ public static function ppmfwc_onExchange()
10571047
throw new PPMFWC_Exception_Notice('Ignoring: ' . $action);
10581048
}
10591049

1060-
PPMFWC_Helper_Data::ppmfwc_payLogger('Exchange incoming', $order_id, array('action' => $action, 'wc_order_id' => '', 'methodid' => $methodId));
1050+
10611051

10621052
$newStatus = PPMFWC_Helper_Transaction::processTransaction($payOrder, $status, $methodId);
10631053
$responseMessage = 'Status updated to ' . $newStatus;
10641054

10651055

10661056
} catch (PPMFWC_Exception_Notice $e) {
10671057
$responseMessage = $e->getMessage();
1058+
10681059
} catch (PPMFWC_Exception $e) {
1069-
$responseResult = false;
10701060
$responseMessage = 'Error 1: ' . $e->getMessage();
1061+
PPMFWC_Helper_Data::ppmfwc_payLogger('Exchange error: ' . $e->getMessage(), ($order_id ?? 0), array('action' => ($action ?? ''), 'wc_order_id' => '', 'payOrderId' => ($payOrderId ?? '')), 'critical');
1062+
10711063
} catch (Exception $e) {
1072-
$responseResult = false;
10731064
$responseMessage = 'Error 2: ' . $e->getMessage();
1065+
PPMFWC_Helper_Data::ppmfwc_payLogger('Exchange Error: ' . $e->getMessage(), ($order_id ?? 0), array('action' => ($action ?? ''), 'wc_order_id' => '', 'payOrderId' => ($payOrderId ?? '')), 'critical');
10741066
}
10751067

1076-
if (($action ?? '') == self::ACTION_NEWPPT && isset($order_id)) {
1077-
PPMFWC_Helper_Transaction::removeProcessing($order_id);
1068+
if (($action ?? '') == self::ACTION_NEWPPT && isset($payOrderId)) {
1069+
PPMFWC_Helper_Transaction::removeProcessing($payOrderId);
10781070
}
10791071

10801072
$exchange->setResponse($responseResult, $responseMessage);

includes/classes/PPMFWC/Helper/Config.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ public static function getPayCustomer($order, $methodName)
100100

101101
$company = new \PayNL\Sdk\Model\Company();
102102
$company->setName($order->get_billing_company());
103-
$company->setVat(PPMFWC_Helper_Data::getPostTextField('vat_number', true));
104-
$company->setCoc(PPMFWC_Helper_Data::getPostTextField('coc_number', true));
103+
$company->setVat((string)PPMFWC_Helper_Data::getPostTextField('vat_number', true));
104+
$company->setCoc((string)PPMFWC_Helper_Data::getPostTextField('coc_number', true));
105105
$company->setCountryCode(strtoupper($order->get_billing_country()));
106106
$customer->setCompany($company);
107107
$customer->setIpAddress(self::getIpAddress($order));

includes/classes/PPMFWC/Helper/Data.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@ class PPMFWC_Helper_Data
2323
*/
2424
public static function ppmfwc_payLogger($message, $payTransactionId = null, $infoFields = array(), $type = 'info')
2525
{
26-
if (self::$paylog === true || self::$paylog === null) {
27-
if (empty(self::$paylog)) {
28-
self::$paylog = get_option('paynl_paylogger') == 'yes';
29-
if (!self::$paylog) {
30-
return;
31-
}
32-
}
26+
if (self::$paylog === null) {
27+
self::$paylog = get_option('paynl_paylogger') == 'yes';
28+
}
29+
30+
if (self::$paylog === true || strtolower($type) == 'critical') {
3331
if (!in_array($type, array('emergency', 'alert', 'critical', 'error', 'warning', 'notice', 'info', 'debug'))) {
3432
$type = 'info';
3533
}

includes/classes/PPMFWC/Helper/Transaction.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ public static function processTransaction(\PayNL\Sdk\Model\Pay\PayOrder $payOrde
164164
throw new PPMFWC_Exception_Notice('Woocommerce could not find internal order ' . $orderId);
165165
}
166166

167-
PPMFWC_Helper_Data::ppmfwc_payLogger('processTransaction', $orderId, array($status, $localTransactionStatus));
167+
PPMFWC_Helper_Data::ppmfwc_payLogger('processTransaction', $transactionId, array($status, $localTransactionStatus, $orderId));
168168

169169
if ($status == $localTransactionStatus) {
170-
PPMFWC_Helper_Data::ppmfwc_payLogger('processTransaction - status allready up-to-date', $transactionId, array('status' => $status));
170+
PPMFWC_Helper_Data::ppmfwc_payLogger('processTransaction - status already up-to-date', $transactionId, array('status' => $status));
171171
throw new PPMFWC_Exception_Notice('Already ' . $status);
172172
}
173173

@@ -228,7 +228,7 @@ public static function processTransaction(\PayNL\Sdk\Model\Pay\PayOrder $payOrde
228228

229229
if ($payOrder->isFastCheckout()) {
230230
if ($transactionId == $order->get_meta('transactionId') && $order->get_meta('fc')) {
231-
PPMFWC_Helper_Data::ppmfwc_payLogger('adding AddressToOrder');
231+
PPMFWC_Helper_Data::ppmfwc_payLogger('FC: adding address to successful order', $transactionId);
232232
PPMFWC_Hooks_FastCheckout_Exchange::addAddressToOrder($payOrder->getCheckoutData(), $order);
233233
}
234234
}

readme.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
=== Pay. Payment Methods for WooCommerce ===
2-
Contributors: andypay
2+
Contributors: woutse
33
Donate link: https://www.pay.nl/webshops/plugin-woocommerce
44
Link: https://www.pay.nl
55
Tags: paynl, paymentmethods, iDEAL, betaalmethoden, pay
6-
Requires at least: 3.5.1
6+
Requires at least: 6.1.0
77
Stable tag: 4.0.0
8-
Tested up to: 6.8
9-
WC tested up to: 9.8.1
8+
Tested up to: 6.8.3
9+
WC tested up to: 10.3.3
1010
WC requires at least: 3.0
1111
Requires PHP: 8.1
1212
License: GPLv2

woocommerce-payment-paynl.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
* Version: 4.0.0
88
* Author: Pay.
99
* Author URI: https://www.pay.nl
10-
* Requires at least: 3.5.1
11-
* WC requires at least: 3.0
10+
* Requires at least: 6.1.0
11+
* WC requires at least: 6.5
12+
* WC tested up to: 10.3.3
1213
* Requires PHP: 8.1
1314
* Text Domain: woocommerce-paynl-payment-methods
1415
* Domain Path: /i18n/languages

0 commit comments

Comments
 (0)