Skip to content

Commit

Permalink
RWC-320
Browse files Browse the repository at this point in the history
Close #97.
  • Loading branch information
Tornevall committed Apr 21, 2022
1 parent f17221f commit 38ad587
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
35 changes: 22 additions & 13 deletions src/Module/Data.php
Expand Up @@ -557,6 +557,24 @@ public static function getAnnuityFactors($productPrice = null, $display = true)
}
}

/**
* @param $customerCountry
* @return float
* @since 0.0.1.6
*/
private static function getDefaultPartPaymentThreshold($customerCountry): float
{
$threshold = (float)Data::getResursOption('part_payment_threshold');

if ($threshold === 150.00 && $customerCountry === 'FI') {
$threshold = 15.00;
} elseif ((int)$threshold === 0) {
$threshold = 150.00;
}

return (float)WordPress::applyFilters('getMinimumAnnuityPrice', $threshold, $customerCountry);
}

/**
* @param $wcDisplayPrice
* @param $annuityMethod
Expand All @@ -567,24 +585,15 @@ public static function getAnnuityFactors($productPrice = null, $display = true)
private static function getAnnuityHtml($wcDisplayPrice, $annuityMethod, $annuityDuration)
{
$customerCountry = self::getCustomerCountry();
switch ($customerCountry) {
case 'US':
// Resides here as an example.
$minimumPaymentLimit = (float)WordPress::applyFilters('getMinimumAnnuityPrice', 15, $customerCountry);
break;
case 'FI':
$minimumPaymentLimit = (float)WordPress::applyFilters('getMinimumAnnuityPrice', 15, $customerCountry);
break;
default:
$minimumPaymentLimit = (float)WordPress::applyFilters('getMinimumAnnuityPrice', 150, $customerCountry);
}

$monthlyPrice = ResursBankAPI::getResurs()->getAnnuityPriceByDuration(
$wcDisplayPrice,
$annuityMethod,
$annuityDuration
);
if ($monthlyPrice >= $minimumPaymentLimit || self::getTestMode()) {
$defaultThreshold = self::getDefaultPartPaymentThreshold($customerCountry);

if ($monthlyPrice >= $defaultThreshold || self::getTestMode()) {
$annuityPaymentMethod = (array)self::getPaymentMethodById($annuityMethod);

// Customized string.
Expand All @@ -604,7 +613,7 @@ private static function getAnnuityHtml($wcDisplayPrice, $annuityMethod, $annuity
'currency' => get_woocommerce_currency_symbol(),
'monthlyPrice' => (float)$monthlyPrice,
'monthlyDuration' => (int)$annuityDuration,
'paymentLimit' => (int)$minimumPaymentLimit,
'paymentLimit' => $defaultThreshold,
'paymentMethod' => $annuityPaymentMethod,
'isTest' => self::getTestMode(),
'readmore' => self::getReadMoreString($annuityPaymentMethod, $monthlyPrice),
Expand Down
13 changes: 13 additions & 0 deletions src/Module/FormFields.php
Expand Up @@ -435,6 +435,19 @@ public static function getFormFields($section = 'basic', $id = null): array
'tornevalls-resurs-bank-payment-gateway-for-woocommerce'
),
],
'part_payment_threshold' => [
'id' => 'part_payment_threshold',
'title' => __('Part payment threshold', 'tornevalls-resurs-bank-payment-gateway-for-woocommerce'),
'type' => 'text',
'desc' => __(
'Minimum installment amount per month for when part payment information should be displayed. ' .
'Default is 150. When set to 150, this value will be automatically adjusted to ' .
'15 if country is set to FI, since EUR is used there. If any other sum is set here, that ' .
'value will always be used instead of the defaults. ',
'tornevalls-resurs-bank-payment-gateway-for-woocommerce'
),
'default' => '150',
],
'payment_methods_settings_end' => [
'id' => 'payment_methods_settings_end',
'type' => 'sectionend',
Expand Down

0 comments on commit 38ad587

Please sign in to comment.