Skip to content

Commit

Permalink
Merge pull request #61 from Adyen/develop
Browse files Browse the repository at this point in the history
Release 1.2.0
  • Loading branch information
khushboo-singhvi authored Oct 3, 2024
2 parents 8230f3e + 0ad4c40 commit eec79f2
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 3 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Main CI workflow

on:
pull_request:
workflow_dispatch:

jobs:
build:
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')
environment: ${{ (github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository) && 'external' || 'internal' }}
runs-on: ubuntu-latest

strategy:
matrix:
php-version: [8.2,8.3]

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Use PHP ${{ matrix.php-version }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
tools: composer:v1

- name: SonarCloud Scan
if: ${{ env.SONAR_TOKEN }}
uses: SonarSource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
32 changes: 32 additions & 0 deletions Magewire/Payment/Method/AdyenPaymentComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ abstract class AdyenPaymentComponent extends Component implements EvaluationInte
public ?string $paymentDetails = null;
public ?string $billingAddress = null;
public ?string $shippingAddress = null;
public ?string $quoteData = null;
public ?string $customerData = null;

protected CheckoutStateDataValidator $checkoutStateDataValidator;
protected Configuration $configuration;
Expand Down Expand Up @@ -138,6 +140,8 @@ public function refreshProperties(): void
$this->processRequiresShipping();
$this->processPaymentResponse();
$this->processQuoteAddresses();
$this->processQuoteData();
$this->processCustomerData();
}

/**
Expand Down Expand Up @@ -253,4 +257,32 @@ private function filterAddressFields(array $address): array

return $filteredAddress;
}

private function processQuoteData(): void
{
try {
$quote = $this->session->getQuote();
$quoteData = [
'shopper_email' => $quote->getCustomerEmail(),
];
$this->quoteData = json_encode($quoteData);
} catch (\Exception $e) {
$this->logger->error('Could not process quote data: ' . $e->getMessage());
}
}

private function processCustomerData(): void
{
try {
$customer = $this->session->getQuote()->getCustomer();
if ($customer && $customer->getId()) {
$customerData = [
'shopper_date_of_birth' => $customer->getDob()
];
$this->customerData = json_encode($customerData);
}
} catch (\Exception $e) {
$this->logger->error('Could not process customer data: ' . $e->getMessage());
}
}
}
8 changes: 6 additions & 2 deletions Magewire/Payment/Method/CreditCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Adyen\Hyva\Model\CreditCard\InstallmentsManager;
use Hyva\Checkout\Model\Magewire\Component\Evaluation\EvaluationResult;
use Hyva\Checkout\Model\Magewire\Component\EvaluationResultFactory;

use Magento\Checkout\Model\Session as SessionCheckout;
class CreditCard extends AdyenPaymentComponent
{
const METHOD_CC = 'adyen_cc';
Expand All @@ -19,6 +19,7 @@ public function __construct(
private readonly Context $context,
private readonly BrandsManager $brandsManager,
private readonly InstallmentsManager $installmentsManager,
private readonly SessionCheckout $sessionCheckout

) {
parent::__construct($this->context);
Expand All @@ -37,7 +38,10 @@ public function getMethodCode(): string
*/
public function evaluateCompletion(EvaluationResultFactory $resultFactory): EvaluationResult
{
return $resultFactory->createSuccess();
$payment = $this->sessionCheckout->getQuote()->getPayment();
return $payment->getMethod() === 'adyen_cc' && !$payment->getAdditionalData()
? $resultFactory->createBlocking()
: $resultFactory->createSuccess();
}

public function refreshProperties(): void
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "adyen/module-hyva-checkout",
"description": "Adyen Integration with Hyva Checkout",
"type": "magento2-module",
"version": "1.1.0",
"version": "1.2.0",
"license": "MIT",
"require": {
"adyen/module-payment": "^9.6.1",
Expand Down
1 change: 1 addition & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<item name="adyen_cashapp" xsi:type="string">adyen-cashapp-method.phtml</item>
<item name="adyen_affirm" xsi:type="string">adyen-affirm-method.phtml</item>
<item name="adyen_amazonpay" xsi:type="string">adyen-amazonpay-method.phtml</item>
<item name="adyen_facilypay_3x" xsi:type="string">adyen-facilypay-3x-method.phtml</item>
</argument>
<argument name="customMagewireClasses" xsi:type="array">
<item name="adyen_cc" xsi:type="object">Adyen\Hyva\Magewire\Payment\Method\CreditCard</item>
Expand Down
3 changes: 3 additions & 0 deletions etc/frontend/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<event name="payment_method_assign_data_adyen_klarna">
<observer name="adyen_hyva_klarna_gateway_data_assign" instance="Adyen\Hyva\Observer\BrandCodeDataAssigner" />
</event>
<event name="payment_method_assign_data_adyen_facilypay_3x">
<observer name="adyen_hyva_facilypay_3x_gateway_data_assign" instance="Adyen\Hyva\Observer\BrandCodeDataAssigner" />
</event>
<!-- End of brand code assigner -->

<!-- Hyva Checkout Related -->
Expand Down
6 changes: 6 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
sonar.organization=adyen
sonar.projectKey=Adyen_adyen-magento2-hyva
sonar.sources=.
sonar.exclusions=vendor/**/*, Test/**/*, view/**/*
sonar.php.coverage.reportPaths=build/clover.xml
sonar.php.tests.reportPath=build/tests-log.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?php
use Adyen\Hyva\Magewire\Payment\Method\AbstractPaymentMethodWire;
use Magento\Framework\Escaper;
use Magento\Framework\View\Element\Template;

/** @var AbstractPaymentMethodWire $magewire */
/** @var Template $block */
/** @var Escaper $escaper */

?>

<div>

<div id="<?= $magewire->getContainerName() ?>ActionContainer" wire:ignore></div>

<script>
class facilypay3xComponentHandler extends componentHandler {
constructor(paymentMethodCode, wire, elementLabel) {
super(paymentMethodCode, wire, elementLabel);
}

buildConfiguration(paymentMethod, paymentMethodsExtraInfo) {
let baseComponentConfiguration = super.buildConfiguration(paymentMethod, paymentMethodsExtraInfo);

let formattedShippingAddress = {};
let formattedBillingAddress = {};
let shopperDateOfBirth = '';
let email = '';

const shippingAddress = this.wire.get('shippingAddress');
const billingAddress = this.wire.get('billingAddress');
const quoteData = this.wire.get('quoteData');
const customerData = this.wire.get('customerData');


if (customerData) {
const parsedCustomerData = JSON.parse(customerData);
shopperDateOfBirth = parsedCustomerData.shopper_date_of_birth || '';
email = parsedCustomerData.email || '';
}

if (!email && quoteData) {
const parsedQuoteData = JSON.parse(quoteData);
email = parsedQuoteData.shopper_email || '';
}

if (shippingAddress) {
formattedShippingAddress = this.getFormattedAddress(JSON.parse(shippingAddress));
}

if (billingAddress) {
formattedBillingAddress = this.getFormattedAddress(JSON.parse(billingAddress));
}

baseComponentConfiguration.data = {};

if (formattedShippingAddress) {
baseComponentConfiguration.data.deliveryAddress = {
city: formattedShippingAddress.city,
country: formattedShippingAddress.country,
houseNumberOrName: formattedShippingAddress.houseNumber,
postalCode: formattedShippingAddress.postalCode,
street: formattedShippingAddress.street
};
}

if (formattedBillingAddress) {
baseComponentConfiguration.data.personalDetails = {
firstName: formattedBillingAddress.firstName,
lastName: formattedBillingAddress.lastName,
telephoneNumber: formattedBillingAddress.telephone,
shopperEmail: email,
dateOfBirth: shopperDateOfBirth,
};
baseComponentConfiguration.data.billingAddress = {
city: formattedBillingAddress.city,
country: formattedBillingAddress.country,
houseNumberOrName: formattedBillingAddress.houseNumber,
postalCode: formattedBillingAddress.postalCode,
street: formattedBillingAddress.street,
};
}

return baseComponentConfiguration;
}
}

window.addEventListener('checkout:payment:method-list-boot', async (event) => {
unmountAdyenComponent();
await init(event.detail.method);
});

window.addEventListener('checkout:payment:method-activate', async (event) => {
await init(event.detail.method);
});

window.addEventListener('checkout:init:evaluation', event => {
hyvaCheckout.evaluation.registerValidator('validate-adyen-component-state', (element, component) => {
let isValid;
if (!window.AdyenPaymentHandler.actionComponent.isValid) {
window.AdyenPaymentHandler.actionComponent.showValidation();
isValid = false;
} else {
isValid = true;
}
return isValid;
});
});

async function init(methodCode) {
try {
let wire = Magewire.find('checkout.payment.methods.' + methodCode);

wire.refreshProperties()
.then(() => {
let methodHandler = new facilypay3xComponentHandler(
methodCode,
wire,
'<?= $magewire->getContainerName() ?>ActionContainer'
);
window.AdyenPaymentHandler = methodHandler;
if (methodCode !== '<?= $magewire->getMethodCode() ?>') {
methodHandler.renderMethodUnavailableMessage();
return;
}
if (wire.get('requiresShipping')) {
methodHandler.renderMessage('Please select shipping method.');
} else {
let rawResponse = wire.get('paymentResponse');
let paymentMethods = JSON.parse(rawResponse);
methodHandler.activatePaymentMethod(methodCode, paymentMethods, '<?= $magewire->getContainerName() ?>ActionContainer');
showPrimaryButton();
}
}).catch(() => {
console.error(`Error occurred during ${methodCode} component load`);
});
} catch (e) {
console.error('Error in init function:', e);
}
}
</script>
</div>

0 comments on commit eec79f2

Please sign in to comment.