Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
fre-sund committed May 10, 2019
2 parents eb86c17 + deb9e04 commit 9c3684c
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 138 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sveaekonomi/webpay",
"version": "3.10.0",
"version": "3.10.1",
"description": "Php integration library for Svea Ekonomis payment methods",
"license": "Apache-2.0",
"authors": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private function calculate($price, $params, $ignoreMaxAndMinFlag)
foreach ($params->campaignCodes as $key => $value) {
if ($ignoreMaxAndMinFlag || ($price >= $value->fromAmount && $price <= $value->toAmount)) {
$pair = array();
$pair['pricePerMonth'] = ($value['initialFee'] + (ceil($price * $value['monthlyAnnuityFactor']) + $value['notificationFee']) * $value['contractLengthInMonths']) / $value['contractLengthInMonths'];
$pair['pricePerMonth'] = ($value->initialFee + (ceil($price * $value->monthlyAnnuityFactor) + $value->notificationFee) * $value->contractLengthInMonths) / $value->contractLengthInMonths;
foreach ($value as $key => $val) {
if ($key == "campaignCode") {
$pair[$key] = $val;
Expand Down
283 changes: 147 additions & 136 deletions test/UnitTest/Helper/HelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Svea\WebPay\Test\TestUtil;
use Svea\WebPay\Config\ConfigurationService;
use Svea\WebPay\WebService\GetPaymentPlanParams\GetPaymentPlanParams;
use Svea\WebPay\WebService\WebServiceResponse\CampaignCode\CampaignCode;
use Svea\WebPay\WebService\WebServiceResponse\PaymentPlanParamsResponse;

class HelperTest extends \PHPUnit\Framework\TestCase
Expand Down Expand Up @@ -442,143 +443,153 @@ function test_calculateCorrectPricePerMonth()
{
$price = 10000;

$params = new GetPaymentPlanParams(ConfigurationService::getDefaultConfig());
$params->campaignCodes = array (
0 =>
array(
'campaignCode' => 213060,
'description' => 'Dela upp betalningen på 60 månader',
'paymentPlanType' => 'Standard',
'contractLengthInMonths' => 60,
'monthlyAnnuityFactor' => '0.02555',
'initialFee' => '100',
'notificationFee' => '29',
'interestRatePercent' => '16.75',
'numberOfInterestFreeMonths' => 3,
'numberOfPaymentFreeMonths' => 3,
'fromAmount' => '1000',
'toAmount' => '50000',
$response = (object) array(
"GetPaymentPlanParamsEuResult" => (object)array (
"Accepted" => true,
"ResultCode" => 0,
"CampaignCodes" => (object)array(
"CampaignCodeInfo" => array(
0 =>
(object)array(
"CampaignCode" => 213060,
"Description" => "Dela upp betalningen på 60 månader",
"PaymentPlanType" => "Standard",
"ContractLengthInMonths" => 60,
"MonthlyAnnuityFactor" => '0.02555',
"InitialFee" => '100',
"NotificationFee" => '29',
"InterestRatePercent" => '16.75',
"NumberOfInterestFreeMonths" => 3,
"NumberOfPaymentFreeMonths" => 3,
"FromAmount" => '1000',
"ToAmount" => '50000',
),
1 =>
array(
'campaignCode' => 222065,
'description' => 'Vårkampanj',
'paymentPlanType' => 'InterestAndAmortizationFree',
'contractLengthInMonths' => 3,
'monthlyAnnuityFactor' => '1',
'initialFee' => '0',
'notificationFee' => '0',
'interestRatePercent' => '0',
'numberOfInterestFreeMonths' => 3,
'numberOfPaymentFreeMonths' => 3,
'fromAmount' => '120',
'toAmount' => '30000',
),
2 =>
array(
'campaignCode' => 222066,
'description' => 'Sommarkampanj',
'paymentPlanType' => 'InterestAndAmortizationFree',
'contractLengthInMonths' => 3,
'monthlyAnnuityFactor' => '1',
'initialFee' => '0',
'notificationFee' => '0',
'interestRatePercent' => '0',
'numberOfInterestFreeMonths' => 3,
'numberOfPaymentFreeMonths' => 3,
'fromAmount' => '120',
'toAmount' => '30000',
),
3 =>
array(
'campaignCode' => 223060,
'description' => 'Köp nu betala om 3 månader (räntefritt)',
'paymentPlanType' => 'InterestAndAmortizationFree',
'contractLengthInMonths' => 3,
'monthlyAnnuityFactor' => '1',
'initialFee' => '0',
'notificationFee' => '29',
'interestRatePercent' => '0',
'numberOfInterestFreeMonths' => 3,
'numberOfPaymentFreeMonths' => 3,
'fromAmount' => '1000',
'toAmount' => '50000',
),
4 =>
array(
'campaignCode' => 223065,
'description' => 'Black Friday - Cyber Monday',
'paymentPlanType' => 'InterestAndAmortizationFree',
'contractLengthInMonths' => 3,
'monthlyAnnuityFactor' => '1',
'initialFee' => '0',
'notificationFee' => '0',
'interestRatePercent' => '0',
'numberOfInterestFreeMonths' => 3,
'numberOfPaymentFreeMonths' => 3,
'fromAmount' => '120',
'toAmount' => '30000',
),
5 =>
array(
'campaignCode' => 223066,
'description' => 'Julkampanj',
'paymentPlanType' => 'InterestAndAmortizationFree',
'contractLengthInMonths' => 3,
'monthlyAnnuityFactor' => '1',
'initialFee' => '0',
'notificationFee' => '0',
'interestRatePercent' => '0',
'numberOfInterestFreeMonths' => 3,
'numberOfPaymentFreeMonths' => 3,
'fromAmount' => '120',
'toAmount' => '30000',
),
6 =>
array(
'campaignCode' => 310012,
'description' => 'Dela upp betalningen på 12 månader (räntefritt)',
'paymentPlanType' => 'InterestFree',
'contractLengthInMonths' => 12,
'monthlyAnnuityFactor' => '0.08333',
'initialFee' => '295',
'notificationFee' => '35',
'interestRatePercent' => '0',
'numberOfInterestFreeMonths' => 12,
'numberOfPaymentFreeMonths' => 0,
'fromAmount' => '1000',
'toAmount' => '30000',
),
7 =>
array(
'campaignCode' => 410012,
'description' => 'Dela upp betalningen på 12 månader',
'paymentPlanType' => 'Standard',
'contractLengthInMonths' => 12,
'monthlyAnnuityFactor' => '0.09259',
'initialFee' => '0',
'notificationFee' => '29',
'interestRatePercent' => '19.9',
'numberOfInterestFreeMonths' => 0,
'numberOfPaymentFreeMonths' => 0,
'fromAmount' => '100',
'toAmount' => '30000',
),
8 =>
array(
'campaignCode' => 410024,
'description' => 'Dela upp betalningen på 24 månader',
'paymentPlanType' => 'Standard',
'contractLengthInMonths' => 24,
'monthlyAnnuityFactor' => '0.04684',
'initialFee' => '350',
'notificationFee' => '35',
'interestRatePercent' => '11.5',
'numberOfInterestFreeMonths' => 0,
'numberOfPaymentFreeMonths' => 0,
'fromAmount' => '1000',
'toAmount' => '150000',
));
1 =>
(object)array(
'CampaignCode' => 222065,
'Description' => 'Vårkampanj',
'PaymentPlanType' => 'InterestAndAmortizationFree',
'ContractLengthInMonths' => 3,
'MonthlyAnnuityFactor' => '1',
'InitialFee' => '0',
'NotificationFee' => '0',
'InterestRatePercent' => '0',
'NumberOfInterestFreeMonths' => 3,
'NumberOfPaymentFreeMonths' => 3,
'FromAmount' => '120',
'ToAmount' => '30000',
),
2 =>
(object)array(
'CampaignCode' => 222066,
'Description' => 'Sommarkampanj',
'PaymentPlanType' => 'InterestAndAmortizationFree',
'ContractLengthInMonths' => 3,
'MonthlyAnnuityFactor' => '1',
'InitialFee' => '0',
'NotificationFee' => '0',
'InterestRatePercent' => '0',
'NumberOfInterestFreeMonths' => 3,
'NumberOfPaymentFreeMonths' => 3,
'FromAmount' => '120',
'ToAmount' => '30000',
),
3 =>
(object)array(
'CampaignCode' => 223060,
'Description' => 'Köp nu betala om 3 månader (räntefritt)',
'PaymentPlanType' => 'InterestAndAmortizationFree',
'ContractLengthInMonths' => 3,
'MonthlyAnnuityFactor' => '1',
'InitialFee' => '0',
'NotificationFee' => '29',
'InterestRatePercent' => '0',
'NumberOfInterestFreeMonths' => 3,
'NumberOfPaymentFreeMonths' => 3,
'FromAmount' => '1000',
'ToAmount' => '50000',
),
4 =>
(object)array(
'CampaignCode' => 223065,
'Description' => 'Black Friday - Cyber Monday',
'PaymentPlanType' => 'InterestAndAmortizationFree',
'ContractLengthInMonths' => 3,
'MonthlyAnnuityFactor' => '1',
'InitialFee' => '0',
'NotificationFee' => '0',
'InterestRatePercent' => '0',
'NumberOfInterestFreeMonths' => 3,
'NumberOfPaymentFreeMonths' => 3,
'FromAmount' => '120',
'ToAmount' => '30000',
),
5 =>
(object)array(
'CampaignCode' => 223066,
'Description' => 'Julkampanj',
'PaymentPlanType' => 'InterestAndAmortizationFree',
'ContractLengthInMonths' => 3,
'MonthlyAnnuityFactor' => '1',
'InitialFee' => '0',
'NotificationFee' => '0',
'InterestRatePercent' => '0',
'NumberOfInterestFreeMonths' => 3,
'NumberOfPaymentFreeMonths' => 3,
'FromAmount' => '120',
'ToAmount' => '30000',
),
6 =>
(object)array(
'CampaignCode' => 310012,
'Description' => 'Dela upp betalningen på 12 månader (räntefritt)',
'PaymentPlanType' => 'InterestFree',
'ContractLengthInMonths' => 12,
'MonthlyAnnuityFactor' => '0.08333',
'InitialFee' => '295',
'NotificationFee' => '35',
'InterestRatePercent' => '0',
'NumberOfInterestFreeMonths' => 12,
'NumberOfPaymentFreeMonths' => 0,
'FromAmount' => '1000',
'ToAmount' => '30000',
),
7 =>
(object)array(
'CampaignCode' => 410012,
'Description' => 'Dela upp betalningen på 12 månader',
'PaymentPlanType' => 'Standard',
'ContractLengthInMonths' => 12,
'MonthlyAnnuityFactor' => '0.09259',
'InitialFee' => '0',
'NotificationFee' => '29',
'InterestRatePercent' => '19.9',
'NumberOfInterestFreeMonths' => 0,
'NumberOfPaymentFreeMonths' => 0,
'FromAmount' => '100',
'ToAmount' => '30000',
),
8 =>
(object)array(
'CampaignCode' => 410024,
'Description' => 'Dela upp betalningen på 24 månader',
'PaymentPlanType' => 'Standard',
'ContractLengthInMonths' => 24,
'MonthlyAnnuityFactor' => '0.04684',
'InitialFee' => '350',
'NotificationFee' => '35',
'InterestRatePercent' => '11.5',
'NumberOfInterestFreeMonths' => 0,
'NumberOfPaymentFreeMonths' => 0,
'FromAmount' => '1000',
'ToAmount' => '150000',
)
)
)
)
);

$params = new PaymentPlanParamsResponse($response, false);

$arr = Helper::paymentPlanPricePerMonth($price, $params, true);

Expand Down

0 comments on commit 9c3684c

Please sign in to comment.