Skip to content

Commit cbb9440

Browse files
authored
Merge pull request #182 from paynl/feature/PLUG-5011
Feature/plug 5011
2 parents d09e95d + 6a044d5 commit cbb9440

12 files changed

Lines changed: 114 additions & 42 deletions

File tree

includes/classes/PPMFWC/Gateway/Abstract.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,8 +623,8 @@ public function process_payment($order_id)
623623
$message = $e->getMessage();
624624
wc_add_notice($message, 'error');
625625

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');
626+
} catch (Exception $e) {
627+
PPMFWC_Helper_Data::ppmfwc_payLogger('Could not initiate payment. Error ' . $e->getMessage(), null, array('wc_order_id' => $order_id, 'methodid' => $paymentOption), 'critical');
628628
$message = 'Could not initiate payment. Please try again or use another payment method.';
629629
wc_add_notice(esc_html(__($message, PPMFWC_WOOCOMMERCE_TEXTDOMAIN)), 'error');
630630
}

includes/classes/PPMFWC/Gateways.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,12 +1056,9 @@ public static function ppmfwc_onExchange()
10561056
throw new PPMFWC_Exception_Notice('Ignoring: ' . $action);
10571057
}
10581058

1059-
1060-
10611059
$newStatus = PPMFWC_Helper_Transaction::processTransaction($payOrder, $status, $methodId);
10621060
$responseMessage = 'Status updated to ' . $newStatus;
10631061

1064-
10651062
} catch (PPMFWC_Exception_Notice $e) {
10661063
$responseMessage = $e->getMessage();
10671064

includes/classes/PPMFWC/Helper/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static function getPayConfig(): PayConfig
2121
$failOver = get_option('paynl_custom_failover_gateway');
2222
}
2323

24-
if (!empty($failOver) && strlen($failOver) > 12) {
24+
if (!empty($failOver) && in_array($failOver, ['https://connect.pay.nl', 'https://connect.achterelkebetaling.nl', 'https://connect.payments.nl'])) {
2525
$config->setCore($failOver);
2626
}
2727

includes/classes/PPMFWC/Helper/Data.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ private static function parseDefaultLanguage($http_accept, $deflang = "en")
298298
*/
299299
public static function getVersion()
300300
{
301-
return '4.0.0';
301+
return '4.0.1';
302302
}
303303

304304
/**
@@ -347,11 +347,11 @@ public static function ppmfwc_getAvailableLanguages()
347347
}
348348

349349
/**
350-
* @return string[]
350+
* @return array
351351
*/
352-
public static function ppmfwc_getCores()
352+
public static function ppmfwc_getCores(): array
353353
{
354-
$cores = get_site_option('paynl_cores') ?? [];
354+
$cores = (array)(get_site_option('paynl_cores') ?? []);
355355

356356
$options = array_column($cores, 'label', 'domain');
357357
$options['custom'] = esc_html(__('Custom', PPMFWC_WOOCOMMERCE_TEXTDOMAIN));

includes/classes/PPMFWC/Helper/Transaction.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,17 +200,20 @@ public static function processTransaction(\PayNL\Sdk\Model\Pay\PayOrder $payOrde
200200
if (in_array($wcOrderStatus, array('complete', 'processing'))) {
201201
if ($payApiStatus == PPMFWC_Gateways::STATUS_REFUND) {
202202
PPMFWC_Helper_Data::ppmfwc_payLogger('processTransaction - Continue to process refund', $transactionId);
203+
203204
} elseif ($payApiStatus == PPMFWC_Gateways::STATUS_CHARGEBACK) {
204205
PPMFWC_Helper_Data::ppmfwc_payLogger('processTransaction - Continue to process chargeback', $transactionId);
206+
205207
} elseif ($status == PPMFWC_Gateways::STATUS_PINREFUND && $payApiStatus == PPMFWC_Gateways::STATUS_SUCCESS) {
206208
$pinRefundAmount = ($transactionLocalDB['amount'] / 100);
207209
PPMFWC_Helper_Data::ppmfwc_payLogger('processTransaction - Continue to process pin refund', $transactionId);
208210
$order->add_order_note(sprintf(esc_html(__('Pay.: Refunded: EUR %s via Retourpinnen', PPMFWC_WOOCOMMERCE_TEXTDOMAIN)), $pinRefundAmount));
209211
self::processRefund($order, $pinRefundAmount);
210212
return PPMFWC_Gateways::STATUS_REFUND;
213+
211214
} else {
212215
PPMFWC_Helper_Data::ppmfwc_payLogger('processTransaction - Done', $transactionId);
213-
throw new PPMFWC_Exception_Notice('Order is already completed or processed');
216+
throw new PPMFWC_Exception_Notice('Order is already completed or processed: ' . $wcOrderStatus . '/' . $status . '/' . $payApiStatus);
214217
}
215218
}
216219

includes/classes/PPMFWC/Hooks/FastCheckout/Start.php

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -155,29 +155,32 @@ public static function addProducts()
155155
*/
156156
public static function getProducts($shippingMethodArr)
157157
{
158-
$tax = new WC_Tax();
159158
$products = [];
160159
$orderDiscount = 0;
161160

162-
foreach (WC()->cart->get_cart() as $cart_item) {
161+
foreach (WC()->cart->get_cart() as $itemNumber => $cart_item) {
163162
$product = $cart_item['data'];
164163
$product_id = $cart_item['product_id'];
165164
$variation_id = $cart_item['variation_id'];
166-
$name = $product->get_title();
167-
$quantity = $cart_item['quantity'];
168-
$price = $product->get_price();
169-
$tax_percentage = 0;
170-
$taxes = $tax->get_rates($product->get_tax_class());
171-
if (!empty($taxes)) {
172-
$rates = array_shift($taxes);
173-
$tax_percentage = round(array_shift($rates));
174-
}
165+
166+
$line_total = $cart_item['line_total']; // excl tax
167+
$line_tax = $cart_item['line_tax']; // tax amount
168+
$qty = $cart_item['quantity'];
169+
170+
$price_ex_tax = $line_total / $qty;
171+
$tax_per_unit = $line_tax / $qty;
172+
$price_inc_tax = $price_ex_tax + $tax_per_unit;
173+
174+
$tax_percentage = $price_ex_tax > 0
175+
? round(($tax_per_unit / $price_ex_tax) * 100, 2)
176+
: 0;
177+
175178
$products[] = [
176-
'id' => $product_id,
179+
'id' => empty($product_id) ? 'p' . $itemNumber : $product_id,
177180
'variation_id' => $variation_id,
178-
'name' => $name,
179-
'qty' => $quantity,
180-
'amount' => $price,
181+
'name' => $product->get_title(),
182+
'qty' => $cart_item['quantity'],
183+
'amount' => round($price_inc_tax, 2),
181184
'taxPercentage' => $tax_percentage,
182185
'type' => 'ARTICLE',
183186
'currency' => get_woocommerce_currency()
@@ -215,15 +218,20 @@ public static function getProducts($shippingMethodArr)
215218

216219
if (!empty($shippingMethodArr['shippingMethod'])) {
217220
$shippingMethod = $shippingMethodArr['shippingMethod'];
218-
$shippingAmount = WC()->cart->get_shipping_total() + (float) array_shift($shippingMethod->get_taxes());
221+
$shippingAmount = WC()->cart->get_shipping_total() + (float)array_shift($shippingMethod->get_taxes());
222+
219223
if ($shippingAmount > 0) {
224+
$shipTotal = WC()->cart->get_shipping_total();
225+
$shipTax = WC()->cart->get_shipping_tax();
226+
$vatPerc = round((100 * $shipTax) / $shipTotal);
227+
220228
$products[] = [
221-
'id' => $shippingMethodArr['shippingMethodId'] ?? 0,
229+
'id' => 'shipping',
222230
'name' => $shippingMethod->label,
223231
'qty' => 1,
224232
'amount' => $shippingAmount,
225233
'amountExclTax' => WC()->cart->get_shipping_total(),
226-
'taxPercentage' => round(\Paynl\Helper::calculateTaxPercentage($shippingAmount, array_shift($shippingMethod->get_taxes()))), // phpcs:ignore
234+
'taxPercentage' => $vatPerc,
227235
'type' => 'SHIPPING',
228236
'currency' => get_woocommerce_currency()
229237
];

readme.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Donate link: https://www.pay.nl/webshops/plugin-woocommerce
44
Link: https://www.pay.nl
55
Tags: paynl, paymentmethods, iDEAL, betaalmethoden, pay
66
Requires at least: 6.1.0
7-
Stable tag: 4.0.0
7+
Stable tag: 4.0.1
88
Tested up to: 6.8.3
99
WC tested up to: 10.3.3
1010
WC requires at least: 3.0
@@ -188,6 +188,8 @@ Paid accounts have better tariffs! see: [tariffs](https://pay.nl/tarieven)
188188
8. One platform for all payments.
189189

190190
== Changelog ==
191+
= 4.0.1 =
192+
Fixed processing issues
191193
= 4.0.0 =
192194
Updated SDK
193195
= 3.22.2 =

vendor/paynl/php-sdk/config/config.global.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
'password' => '', # Use API token or secret. Use Secret in combination with SL-Code.
99
],
1010
'debug' => false,
11-
'useFileCaching' => true
11+
'useFileCaching' => false
1212
];

vendor/paynl/php-sdk/src/Hydrator/Entity.php

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Entity extends AbstractHydrator implements OptionsAwareInterface
5454
*
5555
* @return array
5656
*/
57-
protected function load(ModelInterface $model): array
57+
protected function loadStandard(ModelInterface $model): array
5858
{
5959
$ref = new ReflectionClass($model);
6060

@@ -86,6 +86,68 @@ protected function load(ModelInterface $model): array
8686
return $propertyInfo;
8787
}
8888

89+
/**
90+
* @param ModelInterface $model
91+
* @return array
92+
* @throws ReflectionException
93+
*/
94+
protected function load(ModelInterface $model): array
95+
{
96+
$saveComments = (string)ini_get('opcache.save_comments');
97+
$useOpcacheFallback = ($saveComments !== '1');
98+
99+
if ($useOpcacheFallback === true) {
100+
return $this->loadWithFallback($model);
101+
}
102+
103+
return $this->loadStandard($model);
104+
}
105+
106+
107+
/**
108+
* @param ModelInterface $model
109+
* @return array
110+
*/
111+
protected function loadWithFallback(ModelInterface $model): array
112+
{
113+
$ref = new ReflectionClass($model);
114+
$properties = $ref->getProperties();
115+
116+
$propertyInfo = [];
117+
118+
foreach ($properties as $property) {
119+
$docComment = $property->getDocComment();
120+
121+
// If docblock exists, try to parse @var
122+
if ($docComment !== false &&
123+
preg_match("/@var(?:\n|\s(?P<type>.*))\n/s", $docComment, $annotations)
124+
) {
125+
$propertyInfo[$property->getName()] = $annotations['type'];
126+
continue;
127+
}
128+
129+
// Try to determine type via setter reflection
130+
$setter = 'set' . ucfirst($property->getName());
131+
if ($ref->hasMethod($setter)) {
132+
$method = $ref->getMethod($setter);
133+
$params = $method->getParameters();
134+
135+
if (!empty($params)) {
136+
$param = $params[0];
137+
$paramType = $param->getType();
138+
139+
if ($paramType && !$paramType->isBuiltin()) {
140+
// Example: PayOrder::setAmount(Amount $amount)
141+
$propertyInfo[$property->getName()] = $paramType->getName();
142+
}
143+
}
144+
}
145+
}
146+
147+
return $propertyInfo;
148+
}
149+
150+
89151
/**
90152
* @param array $data
91153
* @param object $object

vendor/paynl/php-sdk/src/Response/Response.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@
44

55
namespace PayNL\Sdk\Response;
66

7-
use PayNL\Sdk\{
8-
Common\DebugAwareInterface,
7+
use PayNL\Sdk\{Common\DebugAwareInterface,
98
Common\DebugAwareTrait,
109
Common\FormatAwareTrait,
1110
Exception\InvalidArgumentException,
11+
Exception\PayException,
1212
Model\Error,
1313
Model\Errors,
1414
Transformer\TransformerAwareInterface,
15-
Transformer\TransformerAwareTrait
16-
};
15+
Transformer\TransformerAwareTrait};
1716

1817
/**
1918
* Class Response
@@ -103,9 +102,9 @@ public function getBody()
103102
}
104103

105104
/**
106-
* @param mixed $body
107-
*
108-
* @return Response
105+
* @param $body
106+
* @return Response|$this
107+
* @throws \Exception
109108
*/
110109
public function setBody($body): Response
111110
{
@@ -114,11 +113,12 @@ public function setBody($body): Response
114113
return $this->setBody(self::HTTP_STATUS_CODES[$this->getStatusCode()]);
115114
}
116115

117-
// initiate transformer (... more than meets the eye ;-) )
116+
# initiate transformer (... more than meets the eye ;-) )
118117
if (true === $this->isFormat(static::FORMAT_OBJECTS) && null !== $this->getTransformer()) {
119118
try {
120119
$body = $this->getTransformer()->transform($body);
121120
} catch (\Exception $e) {
121+
throw new \Exception('Could not parse response: ' . $e->getMessage() . ', Response: ' . print_r($body, true));
122122
}
123123
}
124124

0 commit comments

Comments
 (0)