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-3455 Show cards as individual payment methods #137

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion dev/lang/php_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -427,5 +427,7 @@
"payment_methods.transfer": "Überweisen",
"payment_methods.trustly": "Vertrauenswürdig",
"payment_methods.wechatpay": "WeChatPay",
"verification_methods.idin": "iDIN"
"verification_methods.idin": "iDIN",
"dashboard.pages.payments.displayInCheckout": "Group Credit-debitcards",
"dashboard.pages.payments.displayInCheckoutDesc": "Cards option on how to show the brands in the checkout. <br/> <b>Separate</b>: Card issuers are showed seperately in the checkout.</br><b>Grouped</b>: Card issuers are showed within one group."
}
4 changes: 3 additions & 1 deletion dev/lang/php_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -427,5 +427,7 @@
"payment_methods.transfer": "Transfer",
"payment_methods.trustly": "Trustly",
"payment_methods.wechatpay": "WeChatPay",
"verification_methods.idin": "iDIN"
"verification_methods.idin": "iDIN",
"dashboard.pages.payments.displayInCheckout": "Group Credit-debitcards",
"dashboard.pages.payments.displayInCheckoutDesc": "Cards option on how to show the brands in the checkout. <br/> <b>Separate</b>: Card issuers are showed seperately in the checkout.</br><b>Grouped</b>: Card issuers are showed within one group."
}
4 changes: 3 additions & 1 deletion dev/lang/php_fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -427,5 +427,7 @@
"payment_methods.transfer": "Transfert",
"payment_methods.trustly": "En toute confiance",
"payment_methods.wechatpay": "WeChatPay",
"verification_methods.idin": "IDIN"
"verification_methods.idin": "IDIN",
"dashboard.pages.payments.displayInCheckout": "Group Credit-debitcards",
"dashboard.pages.payments.displayInCheckoutDesc": "Cards option on how to show the brands in the checkout. <br/> <b>Separate</b>: Card issuers are showed seperately in the checkout.</br><b>Grouped</b>: Card issuers are showed within one group."
}
4 changes: 3 additions & 1 deletion dev/lang/php_nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -425,5 +425,7 @@
"payment_methods.transfer": "Transfer",
"payment_methods.trustly": "Trustly",
"payment_methods.wechatpay": "WeChatPay",
"verification_methods.idin": "iDIN"
"verification_methods.idin": "iDIN",
"dashboard.pages.payments.displayInCheckout": "Group Credit-debitcards",
"dashboard.pages.payments.displayInCheckoutDesc": "Cards option on how to show the brands in the checkout. <br/> <b>Separate</b>: Card issuers are showed seperately in the checkout.</br><b>Grouped</b>: Card issuers are showed within one group."
}
43 changes: 40 additions & 3 deletions dev/src/components/payments/CreditCardPaymentConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,30 @@
</div>

<ActiveCreditcards v-model="config.activeCreditcards"/>

<div class="p-5 space-y-5">
<div class="space-y-2">
<h2 class="font-semibold text-sm">{{ $t(`dashboard.pages.payments.displayInCheckout`) }}</h2>
<div class="text-gray-400 text-xs" v-html="$t(`dashboard.pages.payments.displayInCheckoutDesc`)"></div>
</div>

<div class="relative">
<select class="w-full rounded-lg border border-gray-300 p-2.5 peer" v-model="displayInCheckout">
<option v-for="option in displayOptions" :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.displayInCheckout`) }}
</label>
</div>
</div>
</div>
</template>

<script>
import { inject } from "vue";
import { inject, computed } from "vue";
import ToggleField from '../fields/ToggleField.vue'
import { useI18n } from "vue-i18n";
import ActiveCreditcards from '../fields/ActiveCreditcards.vue'

export default {
Expand All @@ -39,10 +57,29 @@ export default {
ActiveCreditcards
},
setup(props) {
const config = inject('config')
const { t } = useI18n();

const displayOptions = [
{ text: t('Grouped'), value: 'grouped' },
{ text: t('Separate'), value: 'separate' }
];

const config = inject('config')

const displayInCheckout = computed({
get() {
return config.value.display_in_checkout || 'grouped'
},
set(value) {
config.value.display_in_checkout = value
}
})


return {
config
config,
displayInCheckout,
displayOptions
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions library/checkout/creditcardcheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ class CreditCardCheckout extends Checkout
final public function setCheckout()
{
parent::setCheckout();

$this->payment_request->issuer = Tools::getValue('BPE_CreditCard');
$this->payment_request->issuer = Tools::getValue('BPE_CreditCard', Tools::getValue('cardCode'));
}

public function startPayment()
Expand Down
2 changes: 1 addition & 1 deletion src/Repository/RawCreditCardsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private function insertCreditCard(array $methodData): void
}
}

private function getCreditCardsData()
public function getCreditCardsData()
{
return [
['name' => 'American Express', 'service_code' => 'amex', 'icon' => 'AMEX.svg'],
Expand Down
81 changes: 80 additions & 1 deletion src/Service/BuckarooPaymentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Doctrine\ORM\EntityManager;
use PrestaShop\PrestaShop\Core\Localization\Exception\LocalizationException;
use PrestaShop\PrestaShop\Core\Payment\PaymentOption;
use Buckaroo\PrestaShop\Src\Repository\RawCreditCardsRepository;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down Expand Up @@ -89,7 +90,11 @@ public function getPaymentOptions($cart)
}

if ($isMethodValid) {
$payment_options[] = $this->createPaymentOption($method, $details);
if ($method === 'creditcard' && $this->areCardsSeparate()) {
$payment_options = array_merge($payment_options, $this->getIndividualCards($method, $details));
} else {
$payment_options[] = $this->createPaymentOption($method, $details);
}
}
}

Expand All @@ -106,6 +111,80 @@ public function getPaymentOptions($cart)
return $payment_options;
}

private function getIndividualCards($method, $details): array
{
$configArray = $this->buckarooConfigService->getConfigArrayForMethod('creditcard');

$methods = [];
if (is_array($configArray['activeCreditcards']) && count($configArray['activeCreditcards']) > 0) {
foreach ($configArray['activeCreditcards'] as $card) {
if (array_key_exists('service_code', $card))
$methods[] = $this->getIndividualCard($method, $details, $card['service_code'], $configArray);
}
}
return $methods;
}

private function getIndividualCard($method, $details, $cardCode, $configArray)
{
$newOption = new PaymentOption();
$cardData = $this->getCardData($cardCode);

$title = $this->getCardTitle($cardData['name'] ?? null, $configArray);

if ($title === null) {
$title = $this->getBuckarooLabel($method, $details->getLabel());
}

$newOption->setCallToActionText($title)
->setAction($this->context->link->getModuleLink('buckaroo3', 'request', ['method' => $method, 'cardCode' => $cardCode]))
->setModuleName($method);


$newOption->setInputs($this->buckarooFeeService->getBuckarooFeeInputs($method));

$logoPath = '/modules/buckaroo3/views/img/buckaroo/' . $this->getCardLogoPath($cardData['icon'] ?? null, $details);

$newOption->setLogo($logoPath);

return $newOption;
}

private function getCardTitle($title, $configArray)
{
if (is_string($title)) {
$feeLabel = $this->getFeeLabel($configArray);

return $this->module->l($title . $feeLabel);
}
}

private function getCardLogoPath($logo, $details)
{
if (!is_string($logo)) {
return "Payment methods/SVG/" . $details->getIcon();
}
return "Creditcard issuers/SVG/" . $logo;
}

private function getCardData(string $cardCode): ?array
{
$repo = new RawCreditCardsRepository();

foreach ($repo->getCreditCardsData() as $cardData) {
if ($cardData['service_code'] === $cardCode) {
return $cardData;
}
}
}


private function areCardsSeparate(): bool
{
$configArray = $this->buckarooConfigService->getConfigArrayForMethod('creditcard');
return ($configArray['display_in_checkout'] ?? "grouped") === "separate";
}

public function isCustomerIdinValid($cart)
{
$id_customer = (int) $cart->id_customer;
Expand Down
2 changes: 1 addition & 1 deletion views/css/buckaroo3.vue.css

Large diffs are not rendered by default.

74 changes: 37 additions & 37 deletions views/js/buckaroo.vue.js

Large diffs are not rendered by default.

Loading