three equal parts, %s EUR per month. First payment on %s %s', 'wc_makecommerce_domain' ), $amount, $this->month_to_text( strtotime( $first_payment ) ), $this->day_to_ordinal( strtotime( $first_payment ) ) );
case 'indivy-go':
return __( 'Buy now, pay on the 15th of the next month', 'wc_makecommerce_domain' );
case 'liisi_ee':
$interest = 11.9;
$downpayment = 0;
$months = 12;
$amount = ( ( $price - $downpayment ) * ( 1 + ( $interest / 100 ) * $months / 12 ) ) / ( $months );
return sprintf( __( 'Pay %s EUR per month for 12 months. Interest %s', 'wc_makecommerce_domain' ), ceil( $amount ), $interest ) . '%';
case 'bigbank':
$months = 12;
$downpayment = 0;
$interest = 12.9;
$contractfee = 3;
$managementfee = 0;
$contractconclusion = $price / 100 * $contractfee;
$creditamount = ( $price - $downpayment ) + $contractconclusion;
$monthlypayment = $this->pmt( $interest, $months, $creditamount );
$totalamount = $months * $monthlypayment;
$interestpayment = $totalamount - $creditamount - ( $months * $managementfee );
$annualinterest = $this->effect( $this->rate( $months, $monthlypayment, -( $creditamount - $contractconclusion ) ) * 12, 12 ) * 100;
return sprintf(
__( 'Pay %s EUR per month for 12 months
Borrowing rate %s%, credit amount %s€, contract conclusion fee %s€, total amount payable %s€, annual interest rate %s%
Calculation is only informative.' , 'wc_makecommerce_domain'
),
number_format( $monthlypayment, 2 ),
number_format( $interest, 2 ),
number_format( $creditamount, 2 ),
number_format( $contractconclusion, 2 ),
number_format( $totalamount, 2 ),
number_format( $annualinterest, 2 )
);
default:
return 'Pay with ' . $method;
}
}
/**
* Calculate rate
*
* @since 3.0.10
*/
public function rate( $numberOfPeriods, $payment, $presentValue ) {
$rate = 0.1;
$close = false;
$iter = 0;
while ( !$close && $iter < 128 ) {
$nextdiff = $this->rateNextGuess( $rate, $numberOfPeriods, $payment, $presentValue );
if ( !is_numeric( $nextdiff ) ) {
break;
}
$rate1 = $rate - $nextdiff;
$close = abs( $rate1 - $rate ) < 1.0e-08;
$iter++;
$rate = $rate1;
}
return $rate;
}
/**
* Returns next rate guess
*
* @since 3.0.10
*/
private function rateNextGuess( $rate, $numberOfPeriods, $payment, $presentValue, $futureValue = 0, $type = 0 )
{
$tt1 = ( $rate + 1 ) ** $numberOfPeriods;
$tt2 = ( $rate + 1 ) ** ( $numberOfPeriods - 1 );
$numerator = $futureValue + $tt1 * $presentValue + $payment * ( $tt1 - 1 ) * ( $rate * $type + 1 ) / $rate;
$denominator = $numberOfPeriods * $tt2 * $presentValue - $payment * ( $tt1 - 1 )
* ( $rate * $type + 1 ) / ( $rate * $rate ) + $numberOfPeriods
* $payment * $tt2 * ( $rate * $type + 1 ) / $rate + $payment * ( $tt1 - 1 ) * $type / $rate;
return $numerator / $denominator;
}
/**
* Calculate monthly payment
*
* @since 3.0.10
*/
public function pmt( $interest, $months, $loan )
{
$interest = $interest / 1200;
$amount = $interest * -$loan * pow( ( 1 + $interest ), $months ) / ( 1 - pow( ( 1 + $interest ), $months ) );
return $amount;
}
/**
* Calculate effect
*
* @since 3.0.10
*/
public function effect($nominalRate, $periodsPerYear)
{
return ( ( 1 + $nominalRate / $periodsPerYear ) ** $periodsPerYear ) - 1;
}
/**
* Adds pay later block to product view
*
* @since 3.0.9
*/
public function add_pay_later_block_to_product() {
if ( !in_array( wc_get_base_location()['country'], $this->allowed_pl_countries ) ) {
return;
}
//don't show more than once
if ( self::$pay_later_shown ) {
return;
}
global $product;
//ignore for subscription and grouped products
if ( class_exists( '\WC_Subscriptions_Product' ) && \WC_Subscriptions_Product::is_subscription( $product ) ) {
return;
}
//get product using variation id
if ( isset( $_GET['paylater_variation_id'] ) ) {
$product = wc_get_product( $_GET['paylater_variation_id'] );
}
//dont use for grouped products. Too confusing to implement. Something for v2 perhaps
if ( $product->get_type() == 'grouped' ) {
return;
}
//get product price
$price = wc_get_price_including_tax( $product );
//get allowed methods
$methods = $this->get_allowed_pl_methods();
//add paylater css and js
wp_enqueue_style( 'mc_paylater', plugins_url( '/css/paylater.css', __FILE__ ), array(), $this->version );
\MakeCommerce::mc_enqueue_script(
'MC_PAYLATER',
dirname( __FILE__ ) . '/js/mc_paylater.js',
[ 'type' => $product->get_type() ],
[ 'jquery' ]
);
$logo = plugins_url( '/images/paylater-en.png', __FILE__ );
if ( file_exists( dirname( __FILE__ ) . '/images/paylater-' . \MakeCommerce\i18n::get_two_char_locale() .'.png' ) ) {
$logo = plugins_url( '/images/paylater-' . \MakeCommerce\i18n::get_two_char_locale() . '.png', __FILE__ );
}
$displaycss = '';
if ( $product->get_type() == 'variable' || isset( $_GET['paylater_variation_id'] ) ) {
$displaycss = 'style="display: none;"';
}
echo '
' . $this->get_paylater_method_description( $method->name, $price ) . '
' . __( 'Dismiss', 'wc_makecommerce_domain' ) . ' ' . sprintf( __( 'MakeCommerce module now includes option to display pay later options and payment terms examples in product view. Having pay later options available potentially grows your customer base as well as average shopping cart. We recommend to use this option if considerable number of purchases are above 75 euros.', 'wc_makecommerce_domain' ), '/wp-admin/admin.php?page=wc-settings&tab=checkout§ion=makecommerce&mc_pay_later_notice_dismissed' ). '