Skip to content

Commit eec79f2

Browse files
Merge pull request #61 from Adyen/develop
Release 1.2.0
2 parents 8230f3e + 0ad4c40 commit eec79f2

File tree

8 files changed

+224
-3
lines changed

8 files changed

+224
-3
lines changed

.github/workflows/main.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Main CI workflow
2+
3+
on:
4+
pull_request:
5+
workflow_dispatch:
6+
7+
jobs:
8+
build:
9+
if: (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) || (github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository) || (github.event_name == 'workflow_dispatch')
10+
environment: ${{ (github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository) && 'external' || 'internal' }}
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
php-version: [8.2,8.3]
16+
17+
steps:
18+
- uses: actions/checkout@v3
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Use PHP ${{ matrix.php-version }}
23+
uses: shivammathur/setup-php@v2
24+
with:
25+
php-version: ${{ matrix.php-version }}
26+
tools: composer:v1
27+
28+
- name: SonarCloud Scan
29+
if: ${{ env.SONAR_TOKEN }}
30+
uses: SonarSource/sonarcloud-github-action@master
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

Magewire/Payment/Method/AdyenPaymentComponent.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ abstract class AdyenPaymentComponent extends Component implements EvaluationInte
4040
public ?string $paymentDetails = null;
4141
public ?string $billingAddress = null;
4242
public ?string $shippingAddress = null;
43+
public ?string $quoteData = null;
44+
public ?string $customerData = null;
4345

4446
protected CheckoutStateDataValidator $checkoutStateDataValidator;
4547
protected Configuration $configuration;
@@ -138,6 +140,8 @@ public function refreshProperties(): void
138140
$this->processRequiresShipping();
139141
$this->processPaymentResponse();
140142
$this->processQuoteAddresses();
143+
$this->processQuoteData();
144+
$this->processCustomerData();
141145
}
142146

143147
/**
@@ -253,4 +257,32 @@ private function filterAddressFields(array $address): array
253257

254258
return $filteredAddress;
255259
}
260+
261+
private function processQuoteData(): void
262+
{
263+
try {
264+
$quote = $this->session->getQuote();
265+
$quoteData = [
266+
'shopper_email' => $quote->getCustomerEmail(),
267+
];
268+
$this->quoteData = json_encode($quoteData);
269+
} catch (\Exception $e) {
270+
$this->logger->error('Could not process quote data: ' . $e->getMessage());
271+
}
272+
}
273+
274+
private function processCustomerData(): void
275+
{
276+
try {
277+
$customer = $this->session->getQuote()->getCustomer();
278+
if ($customer && $customer->getId()) {
279+
$customerData = [
280+
'shopper_date_of_birth' => $customer->getDob()
281+
];
282+
$this->customerData = json_encode($customerData);
283+
}
284+
} catch (\Exception $e) {
285+
$this->logger->error('Could not process customer data: ' . $e->getMessage());
286+
}
287+
}
256288
}

Magewire/Payment/Method/CreditCard.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Adyen\Hyva\Model\CreditCard\InstallmentsManager;
1010
use Hyva\Checkout\Model\Magewire\Component\Evaluation\EvaluationResult;
1111
use Hyva\Checkout\Model\Magewire\Component\EvaluationResultFactory;
12-
12+
use Magento\Checkout\Model\Session as SessionCheckout;
1313
class CreditCard extends AdyenPaymentComponent
1414
{
1515
const METHOD_CC = 'adyen_cc';
@@ -19,6 +19,7 @@ public function __construct(
1919
private readonly Context $context,
2020
private readonly BrandsManager $brandsManager,
2121
private readonly InstallmentsManager $installmentsManager,
22+
private readonly SessionCheckout $sessionCheckout
2223

2324
) {
2425
parent::__construct($this->context);
@@ -37,7 +38,10 @@ public function getMethodCode(): string
3738
*/
3839
public function evaluateCompletion(EvaluationResultFactory $resultFactory): EvaluationResult
3940
{
40-
return $resultFactory->createSuccess();
41+
$payment = $this->sessionCheckout->getQuote()->getPayment();
42+
return $payment->getMethod() === 'adyen_cc' && !$payment->getAdditionalData()
43+
? $resultFactory->createBlocking()
44+
: $resultFactory->createSuccess();
4145
}
4246

4347
public function refreshProperties(): void

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "adyen/module-hyva-checkout",
33
"description": "Adyen Integration with Hyva Checkout",
44
"type": "magento2-module",
5-
"version": "1.1.0",
5+
"version": "1.2.0",
66
"license": "MIT",
77
"require": {
88
"adyen/module-payment": "^9.6.1",

etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<item name="adyen_cashapp" xsi:type="string">adyen-cashapp-method.phtml</item>
2525
<item name="adyen_affirm" xsi:type="string">adyen-affirm-method.phtml</item>
2626
<item name="adyen_amazonpay" xsi:type="string">adyen-amazonpay-method.phtml</item>
27+
<item name="adyen_facilypay_3x" xsi:type="string">adyen-facilypay-3x-method.phtml</item>
2728
</argument>
2829
<argument name="customMagewireClasses" xsi:type="array">
2930
<item name="adyen_cc" xsi:type="object">Adyen\Hyva\Magewire\Payment\Method\CreditCard</item>

etc/frontend/events.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
<event name="payment_method_assign_data_adyen_klarna">
1515
<observer name="adyen_hyva_klarna_gateway_data_assign" instance="Adyen\Hyva\Observer\BrandCodeDataAssigner" />
1616
</event>
17+
<event name="payment_method_assign_data_adyen_facilypay_3x">
18+
<observer name="adyen_hyva_facilypay_3x_gateway_data_assign" instance="Adyen\Hyva\Observer\BrandCodeDataAssigner" />
19+
</event>
1720
<!-- End of brand code assigner -->
1821

1922
<!-- Hyva Checkout Related -->

sonar-project.properties

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
sonar.organization=adyen
2+
sonar.projectKey=Adyen_adyen-magento2-hyva
3+
sonar.sources=.
4+
sonar.exclusions=vendor/**/*, Test/**/*, view/**/*
5+
sonar.php.coverage.reportPaths=build/clover.xml
6+
sonar.php.tests.reportPath=build/tests-log.xml
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
<?php
2+
use Adyen\Hyva\Magewire\Payment\Method\AbstractPaymentMethodWire;
3+
use Magento\Framework\Escaper;
4+
use Magento\Framework\View\Element\Template;
5+
6+
/** @var AbstractPaymentMethodWire $magewire */
7+
/** @var Template $block */
8+
/** @var Escaper $escaper */
9+
10+
?>
11+
12+
<div>
13+
14+
<div id="<?= $magewire->getContainerName() ?>ActionContainer" wire:ignore></div>
15+
16+
<script>
17+
class facilypay3xComponentHandler extends componentHandler {
18+
constructor(paymentMethodCode, wire, elementLabel) {
19+
super(paymentMethodCode, wire, elementLabel);
20+
}
21+
22+
buildConfiguration(paymentMethod, paymentMethodsExtraInfo) {
23+
let baseComponentConfiguration = super.buildConfiguration(paymentMethod, paymentMethodsExtraInfo);
24+
25+
let formattedShippingAddress = {};
26+
let formattedBillingAddress = {};
27+
let shopperDateOfBirth = '';
28+
let email = '';
29+
30+
const shippingAddress = this.wire.get('shippingAddress');
31+
const billingAddress = this.wire.get('billingAddress');
32+
const quoteData = this.wire.get('quoteData');
33+
const customerData = this.wire.get('customerData');
34+
35+
36+
if (customerData) {
37+
const parsedCustomerData = JSON.parse(customerData);
38+
shopperDateOfBirth = parsedCustomerData.shopper_date_of_birth || '';
39+
email = parsedCustomerData.email || '';
40+
}
41+
42+
if (!email && quoteData) {
43+
const parsedQuoteData = JSON.parse(quoteData);
44+
email = parsedQuoteData.shopper_email || '';
45+
}
46+
47+
if (shippingAddress) {
48+
formattedShippingAddress = this.getFormattedAddress(JSON.parse(shippingAddress));
49+
}
50+
51+
if (billingAddress) {
52+
formattedBillingAddress = this.getFormattedAddress(JSON.parse(billingAddress));
53+
}
54+
55+
baseComponentConfiguration.data = {};
56+
57+
if (formattedShippingAddress) {
58+
baseComponentConfiguration.data.deliveryAddress = {
59+
city: formattedShippingAddress.city,
60+
country: formattedShippingAddress.country,
61+
houseNumberOrName: formattedShippingAddress.houseNumber,
62+
postalCode: formattedShippingAddress.postalCode,
63+
street: formattedShippingAddress.street
64+
};
65+
}
66+
67+
if (formattedBillingAddress) {
68+
baseComponentConfiguration.data.personalDetails = {
69+
firstName: formattedBillingAddress.firstName,
70+
lastName: formattedBillingAddress.lastName,
71+
telephoneNumber: formattedBillingAddress.telephone,
72+
shopperEmail: email,
73+
dateOfBirth: shopperDateOfBirth,
74+
};
75+
baseComponentConfiguration.data.billingAddress = {
76+
city: formattedBillingAddress.city,
77+
country: formattedBillingAddress.country,
78+
houseNumberOrName: formattedBillingAddress.houseNumber,
79+
postalCode: formattedBillingAddress.postalCode,
80+
street: formattedBillingAddress.street,
81+
};
82+
}
83+
84+
return baseComponentConfiguration;
85+
}
86+
}
87+
88+
window.addEventListener('checkout:payment:method-list-boot', async (event) => {
89+
unmountAdyenComponent();
90+
await init(event.detail.method);
91+
});
92+
93+
window.addEventListener('checkout:payment:method-activate', async (event) => {
94+
await init(event.detail.method);
95+
});
96+
97+
window.addEventListener('checkout:init:evaluation', event => {
98+
hyvaCheckout.evaluation.registerValidator('validate-adyen-component-state', (element, component) => {
99+
let isValid;
100+
if (!window.AdyenPaymentHandler.actionComponent.isValid) {
101+
window.AdyenPaymentHandler.actionComponent.showValidation();
102+
isValid = false;
103+
} else {
104+
isValid = true;
105+
}
106+
return isValid;
107+
});
108+
});
109+
110+
async function init(methodCode) {
111+
try {
112+
let wire = Magewire.find('checkout.payment.methods.' + methodCode);
113+
114+
wire.refreshProperties()
115+
.then(() => {
116+
let methodHandler = new facilypay3xComponentHandler(
117+
methodCode,
118+
wire,
119+
'<?= $magewire->getContainerName() ?>ActionContainer'
120+
);
121+
window.AdyenPaymentHandler = methodHandler;
122+
if (methodCode !== '<?= $magewire->getMethodCode() ?>') {
123+
methodHandler.renderMethodUnavailableMessage();
124+
return;
125+
}
126+
if (wire.get('requiresShipping')) {
127+
methodHandler.renderMessage('Please select shipping method.');
128+
} else {
129+
let rawResponse = wire.get('paymentResponse');
130+
let paymentMethods = JSON.parse(rawResponse);
131+
methodHandler.activatePaymentMethod(methodCode, paymentMethods, '<?= $magewire->getContainerName() ?>ActionContainer');
132+
showPrimaryButton();
133+
}
134+
}).catch(() => {
135+
console.error(`Error occurred during ${methodCode} component load`);
136+
});
137+
} catch (e) {
138+
console.error('Error in init function:', e);
139+
}
140+
}
141+
</script>
142+
</div>

0 commit comments

Comments
 (0)