Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BP-3478-Payment-fee-is-not-working-for-BNPL-methods-Billink-Riverty-Klarna #148

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions dev/src/components/payments/AfterpayPaymentConfig.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
<template>
<div class="p-5 space-y-5">
<div class="space-y-2">
<h2 class="font-semibold text-sm">{{ $t(`dashboard.pages.payments.vat_type_for_wrap`) }}</h2>
</div>

<div class="relative">
<select class="w-full rounded-lg border border-gray-300 p-2.5 peer" v-model="config.wrapping_vat">
<option v-for="option in vatOptions" :key="option.value" :value="option.value">{{ option.text }}</option>
</select>

<label for="frontend_label" class="absolute text-sm text-gray-500 duration-300 transform -translate-y-4 scale-75 top-2 z-10 origin-[0] bg-white px-2 peer-focus:px-2 peer-focus:text-primary peer-placeholder-shown:scale-100 peer-placeholder-shown:-translate-y-1/2 peer-placeholder-shown:top-1/2 peer-focus:top-2 peer-focus:scale-75 peer-focus:-translate-y-4 left-1">
{{ $t(`dashboard.pages.payments.vat_type_for_wrap_select`) }}
</label>
</div>
</div>

<div class="p-5 space-y-5">
<div class="space-y-2">
<h2 class="font-semibold text-sm">{{ $t(`dashboard.pages.payments.customer.type_label`) }}</h2>
Expand Down Expand Up @@ -69,13 +53,6 @@ export default {
const { t } = useI18n();
const config = inject('config')

const vatOptions = [
{ text: t('1 = High rate'), value: '1' },
{ text: t('2 = Low rate'), value: '2' },
{ text: t('3 = Zero rate'), value: '3' },
{ text: t('4 = Null rate'), value: '4' },
{ text: t('5 = Middle rate'), value: '5' },
];

const customerTypeOptions = [
{ text: t('dashboard.pages.payments.customer.type.both'), value: 'both' },
Expand All @@ -85,7 +62,6 @@ export default {

return {
config,
vatOptions,
customerTypeOptions,
}
}
Expand Down
25 changes: 0 additions & 25 deletions dev/src/components/payments/BillinkPaymentConfig.vue
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
<template>
<div>
<div class="p-5 space-y-5">
<div class="space-y-2">
<h2 class="font-semibold text-sm">{{ $t(`dashboard.pages.payments.vat_type_for_wrap`) }}</h2>
</div>

<div class="relative">
<select class="w-full rounded-lg border border-gray-300 p-2.5 peer" v-model="config.wrapping_vat">
<option v-for="option in vatOptions" :key="option.value" :value="option.value">{{ option.text }}</option>
</select>

<label for="frontend_label" class="absolute text-sm text-gray-500 duration-300 transform -translate-y-4 scale-75 top-2 z-10 origin-[0] bg-white px-2 peer-focus:px-2 peer-focus:text-primary peer-placeholder-shown:scale-100 peer-placeholder-shown:-translate-y-1/2 peer-placeholder-shown:top-1/2 peer-focus:top-2 peer-focus:scale-75 peer-focus:-translate-y-4 left-1">
{{ $t(`dashboard.pages.payments.vat_type_for_wrap_select`) }}
</label>
</div>
</div>

<div class="p-5 space-y-5">
<div class="space-y-2">
<h2 class="font-semibold text-sm">{{ $t(`dashboard.pages.payments.customer.type_label`) }}</h2>
Expand Down Expand Up @@ -72,14 +56,6 @@ export default {

const config = inject('config');

const vatOptions = [
{ text: t('1 = High rate'), value: '1' },
{ text: t('2 = Low rate'), value: '2' },
{ text: t('3 = Zero rate'), value: '3' },
{ text: t('4 = Null rate'), value: '4' },
{ text: t('5 = Middle rate'), value: '5' },
];

const customerTypeOptions = [
{ text: t('dashboard.pages.payments.customer.type.both'), value: 'both' },
{ text: `${t('dashboard.pages.payments.customer.type.b2c')} (${t('dashboard.pages.payments.customer.type.b2c.long')})`, value: 'B2C' },
Expand All @@ -88,7 +64,6 @@ export default {

return {
config,
vatOptions,
customerTypeOptions
}
}
Expand Down
38 changes: 0 additions & 38 deletions library/checkout/afterpaycheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,44 +136,6 @@ public function getBillingAddress()
return $payload;
}

public function getArticles()
{
$products = $this->prepareProductArticles();

$wrappingVat = $this->buckarooConfigService->getConfigValue('afterpay', 'wrapping_vat');

if ($wrappingVat == null) {
$wrappingVat = 2;
}

$products = array_merge($products, $this->prepareWrappingArticle($wrappingVat));
$products = array_merge($products, $this->prepareBuckarooFeeArticle($wrappingVat));
$mergedProducts = $this->mergeProductsBySKU($products);

$shippingCostArticle = $this->prepareShippingCostArticle();
if ($shippingCostArticle) {
$mergedProducts[] = $shippingCostArticle;
}

return $mergedProducts;
}

private function prepareBuckarooFeeArticle($wrappingVat)
{
$buckarooFee = $this->getBuckarooFee();
if ($buckarooFee <= 0) {
return [];
}

return [
'identifier' => '0',
'quantity' => '1',
'price' => round($buckarooFee, 2),
'vatPercentage' => $wrappingVat,
'description' => 'buckaroo_fee',
];
}

public function getShippingAddress()
{
if (!empty($this->shipping_address)) {
Expand Down
79 changes: 1 addition & 78 deletions library/checkout/billinkcheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,25 +108,6 @@ public function getBillingAddress()
return $payload;
}

public function getArticles()
{
$products = $this->prepareProductArticles();
$wrappingVat = $this->buckarooConfigService->getConfigValue('billink', 'wrapping_vat');

if ($wrappingVat == null) {
$wrappingVat = 2;
}
$products = array_merge($products, $this->prepareWrappingArticle($wrappingVat));
$products = array_merge($products, $this->prepareBuckarooFeeArticle($wrappingVat));
$mergedProducts = $this->mergeProductsBySKU($products);

$shippingCostArticle = $this->prepareShippingCostArticle();
if ($shippingCostArticle) {
$mergedProducts[] = $shippingCostArticle;
}

return $mergedProducts;
}

public function getRecipientCategory()
{
Expand All @@ -143,76 +124,18 @@ protected function prepareProductArticles()
$articles = [];
foreach ($this->products as $item) {
$tmp = [];
$tmp['description'] = $item['name'];
$tmp['identifier'] = $item['id_product'];
$tmp['quantity'] = $item['quantity'];
$tmp['price'] = round($item['price_with_reduction'], 2);
$tmp['priceExcl'] = round($item['price_with_reduction_without_tax'], 2);
$tmp['vatPercentage'] = $item['rate'];
$tmp['description'] = $item['name'];
$articles[] = $tmp;
}

return $articles;
}

protected function prepareWrappingArticle($wrappingVat)
{
$wrappingCost = $this->cart->getOrderTotal(true, CartCore::ONLY_WRAPPING);

if ($wrappingCost <= 0) {
return [];
}

return [
'identifier' => '0',
'quantity' => '1',
'price' => $wrappingCost,
'priceExcl' => $wrappingCost,
'vatPercentage' => $wrappingVat,
'description' => 'Wrapping',
];
}

private function prepareBuckarooFeeArticle($wrappingVat)
{
$buckarooFee = $this->getBuckarooFee();
if ($buckarooFee <= 0) {
return [];
}

return [
'identifier' => '0',
'quantity' => '1',
'price' => round($buckarooFee, 2),
'priceExcl' => round($buckarooFee, 2),
'vatPercentage' => $wrappingVat,
'description' => 'buckaroo_fee',
];
}

protected function prepareShippingCostArticle()
{
$shippingCost = round($this->cart->getOrderTotal(true, CartCore::ONLY_SHIPPING), 2);
if ($shippingCost <= 0) {
return null;
}

$carrier = new Carrier((int) $this->cart->id_carrier, Configuration::get('PS_LANG_DEFAULT'));

$shippingCostsTax = (version_compare(_PS_VERSION_, '1.7.6.0', '<='))
? $carrier->getTaxesRate(Address::initialize())
: $carrier->getTaxesRate();

return [
'identifier' => 'shipping',
'description' => 'Shipping Costs',
'vatPercentage' => $shippingCostsTax,
'quantity' => 1,
'price' => $shippingCost,
'priceExcl' => $shippingCost,
];
}

public function getBirthDate()
{
return date(
Expand Down
55 changes: 47 additions & 8 deletions library/checkout/checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,22 +347,61 @@ public function getPhone($address)
return $phone;
}

protected function prepareWrappingArticle($wrappingVat)
public function getArticles()
{
$wrappingCost = $this->cart->getOrderTotal(true, CartCore::ONLY_WRAPPING);
if ($wrappingCost <= 0) {
return [];
$products = $this->prepareProductArticles();

// Get the Tax Rule Group for Wrapping
$wrappingTaxRulesGroupId = (int)Configuration::get('PS_GIFT_WRAPPING_TAX_RULES_GROUP');
// Get the VAT Rate for the Tax Rule Group
$address = new Address($this->cart->id_address_delivery);
$tax_manager = TaxManagerFactory::getManager($address, $wrappingTaxRulesGroupId);
$tax_calculator = $tax_manager->getTaxCalculator();
$wrappingVatRate = $tax_calculator->getTotalRate();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what these lines do, can you explain them to me? PS_GIFT_WRAPPING_TAX_RULES_GROUP by the name seems to be related to gift wrapping not products, not sure if this is correct


$additionalArticles = [
$this->prepareWrappingArticle($wrappingVatRate),
$this->prepareBuckarooFeeArticle($wrappingVatRate),
$this->prepareShippingCostArticle(),
];

foreach ($additionalArticles as $article) {
if (!empty($article)) {
$products[] = $article;
}
}

return [
return $this->mergeProductsBySKU($products);
}

protected function prepareWrappingArticle($wrappingVatRate)
{
$wrappingCostInclTax = $this->cart->getOrderTotal(true, CartCore::ONLY_WRAPPING);

return $wrappingCostInclTax > 0 ? [
'identifier' => '0',
'quantity' => '1',
'price' => $wrappingCost,
'vatPercentage' => $wrappingVat,
'price' => $wrappingCostInclTax,
'vatPercentage' => $wrappingVatRate,
'description' => 'Wrapping',
];
] : [];
}

protected function prepareBuckarooFeeArticle($wrappingVatRate)
{
$buckarooFee = $this->getBuckarooFee();

return $buckarooFee > 0 ? [
'identifier' => '0',
'quantity' => '1',
'price' => round($buckarooFee, 2),
'vatPercentage' => $wrappingVatRate,
'description' => 'buckaroo_fee',
] : [];
}



protected function prepareProductArticles()
{
$articles = [];
Expand Down
36 changes: 0 additions & 36 deletions library/checkout/klarnacheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,42 +84,6 @@ public function getShippingAddress()
return $this->getAddress(array_merge((array) $this->shipping_address, $sendCloudData));
}

public function getArticles()
{
$products = $this->prepareProductArticles();
$wrappingVat = $this->buckarooConfigService->getConfigValue('klarna', 'wrapping_vat');

if ($wrappingVat == null) {
$wrappingVat = 2;
}
$products = array_merge($products, $this->prepareWrappingArticle($wrappingVat));
$products = array_merge($products, $this->prepareBuckarooFeeArticle($wrappingVat));
$mergedProducts = $this->mergeProductsBySKU($products);

$shippingCostArticle = $this->prepareShippingCostArticle();
if ($shippingCostArticle) {
$mergedProducts[] = $shippingCostArticle;
}

return $mergedProducts;
}

private function prepareBuckarooFeeArticle($wrappingVat)
{
$buckarooFee = $this->getBuckarooFee();
if ($buckarooFee <= 0) {
return [];
}

return [
'identifier' => '0',
'quantity' => '1',
'price' => round($buckarooFee, 2),
'vatPercentage' => $wrappingVat,
'description' => 'buckaroo_fee',
];
}

public function isRedirectRequired()
{
return true;
Expand Down
3 changes: 1 addition & 2 deletions src/Repository/RawPaymentMethodRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private function insertConfiguration(string $paymentName, int $paymentMethodId):
case 'creditcard':
case 'ideal':
$configValue['show_issuers'] = true;
// no break

case 'paybybank':
$configValue['display_type'] = 'radio';
break;
Expand All @@ -87,7 +87,6 @@ private function insertConfiguration(string $paymentName, int $paymentMethodId):

case 'afterpay':
case 'billink':
$configValue['wrapping_vat'] = '2';
$configValue['customer_type'] = 'B2C';
$configValue['financial_warning'] = true;
break;
Expand Down
1 change: 1 addition & 0 deletions upgrade/upgrade-4.2.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function upgrade_module_4_2_0($object)
];

$configInsertQuery = 'INSERT INTO ' . _DB_PREFIX_ . 'bk_configuration (configurable_id, value) VALUES (' . (int)$paymentMethodId . ', \'' . pSQL(json_encode($knakenConfig)) . '\')';

Db::getInstance()->execute($configInsertQuery);

$orderingRepository = new RawOrderingRepository();
Expand Down
64 changes: 32 additions & 32 deletions views/js/buckaroo.vue.js

Large diffs are not rendered by default.

Loading