Overview
  • Namespace
  • Class

Namespaces

  • Klarna
    • XMLRPC
      • Exception

Classes

  • Address
  • Calc
  • CheckoutServiceRequest
  • CheckoutServiceResponse
  • Config
  • Country
  • CurlHandle
  • CurlTransport
  • Currency
  • Encoding
  • Flags
  • Klarna
  • Language

Class Calc

Calc provides methods to calculate part payment functions.

All rates are yearly rates, but they are calculated monthly. So a rate of 9 % is used 0.75% monthly. The first is the one we specify to the customers, and the second one is the one added each month to the account. The IRR uses the same notation.

The APR is however calculated by taking the monthly rate and raising it to the 12 power. This is according to the EU law, and will give very large numbers if the $pval is small compared to the $fee and the amount of months you repay is small as well.

All functions work in discrete mode, and the time interval is the mythical evenly divided month. There is no way to calculate APR in days without using integrals and other hairy math. So don't try. The amount of days between actual purchase and the first bill can of course vary between 28 and 61 days, but all calculations in this class assume this time is exactly and that is ok since this will only overestimate the APR and all examples in EU law uses whole months as well.

Namespace: Klarna\XMLRPC
Located at Klarna/XMLRPC/Calc.php

Methods summary

public static float
# calcApr( float $sum, Klarna\XMLRPC\PClass $pclass, integer $flags, integer $free = 0 )

Calculates APR for the specified values.
Result is rounded with two decimals.
.

Calculates APR for the specified values.
Result is rounded with two decimals.
.

Flags can be either:
Flags::CHECKOUT_PAGE
Flags::PRODUCT_PAGE

Parameters

$sum
The sum for the order/product.
$pclass
PClass used to calculate the APR.
$flags
Checkout or Product page.
$free
Number of free months.

Returns

float
APR in %

Throws

InvalidArgumentException
Klarna\XMLRPC\Exception\KlarnaException
public static float
# totalCreditPurchaseCost( float $sum, Klarna\XMLRPC\PClass $pclass, integer $flags )

Calculates the total credit purchase cost.
The result is rounded up, depending on the pclass country.
.

Calculates the total credit purchase cost.
The result is rounded up, depending on the pclass country.
.

Flags can be either:
Flags::CHECKOUT_PAGE
Flags::PRODUCT_PAGE

Parameters

$sum
The sum for the order/product.
$pclass
PClass used to calculate total credit cost.
$flags
Checkout or Product page.

Returns

float
Total credit purchase cost.

Throws

InvalidArgumentException
public static float
# calcMonthlyCost( integer $sum, Klarna\XMLRPC\PClass $pclass, integer $flags )

Calculates the monthly cost for the specified pclass. The result is rounded up to the correct value depending on the pclass country.
.

Calculates the monthly cost for the specified pclass. The result is rounded up to the correct value depending on the pclass country.
.

Example:

  • In product view, round monthly cost with max 0.5 or 0.1 depending on currency.
    • 10.50 SEK rounds to 11 SEK
    • 10.49 SEK rounds to 10 SEK
    • 8.55 EUR rounds to 8.6 EUR
    • 8.54 EUR rounds to 8.5 EUR
  • In checkout, round the monthly cost to have 2 decimals.
    For example 10.57 SEK/per månad

Flags can be either:
Flags::CHECKOUT_PAGE
Flags::PRODUCT_PAGE

Parameters

$sum
The sum for the order/product.
$pclass
PClass used to calculate monthly cost.
$flags
Checkout or product page.

Returns

float
The monthly cost.

Throws

InvalidArgumentException
public static integer|float
# getLowestPaymentForAccount( integer $country )

Returns the lowest monthly payment for Klarna Account.

Returns the lowest monthly payment for Klarna Account.

Parameters

$country
Country constant.

Returns

integer|float
Lowest monthly payment.

Throws

Klarna\XMLRPC\Exception\KlarnaException
public static float|integer
# pRound( integer|float $value, integer $country )

Rounds a value depending on the specified country.

Rounds a value depending on the specified country.

Parameters

$value
The value to be rounded.
$country
Country constant.

Returns

float|integer

Magic methods summary

Properties summary

protected static float $accuracy

This constant tells the irr function when to stop. If the calculation error is lower than this the calculation is done.

This constant tells the irr function when to stop. If the calculation error is lower than this the calculation is done.

# 0.01
API documentation generated by ApiGen