Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
00cb3bc
[ECP-9387]Implementing Adyen Giving Manager V2
khushboo-singhvi Apr 29, 2025
add23af
[ECP-9387]Completing unit tests
khushboo-singhvi May 1, 2025
9ff1deb
Update webapi.xml
khushboo-singhvi May 1, 2025
9b34b5d
Merge branch 'develop-10' into ECP-9387
khushboo-singhvi May 1, 2025
ec72dce
[ECP-9387]Updating MakeFile
khushboo-singhvi May 1, 2025
5a5ce72
Merge remote-tracking branch 'origin/ECP-9387' into ECP-9387
khushboo-singhvi May 1, 2025
5a8fa67
[ECP-9387]Updating Logic and check for DonationToken for fetching cam…
khushboo-singhvi May 6, 2025
61fa14e
[ECP-9387]Updating Logic and check for DonationToken for fetching cam…
khushboo-singhvi May 7, 2025
ad61095
[ECP-9387]Updating Logic and check for DonationToken for fetching cam…
khushboo-singhvi May 7, 2025
0f85690
[ECP-9387]Removing debuggers
khushboo-singhvi May 7, 2025
040b757
Merge branch 'develop-10' into ECP-9387
khushboo-singhvi May 7, 2025
d14892d
[ECP-9387]Improving code by adding Secure renderers and other suggest…
khushboo-singhvi May 7, 2025
14deafa
Merge remote-tracking branch 'origin/ECP-9387' into ECP-9387
khushboo-singhvi May 7, 2025
d5e9a27
[ECP-9387]Improving code by adding Secure renderers and other suggest…
khushboo-singhvi May 7, 2025
b806531
Fixing the DonationId
khushboo-singhvi May 9, 2025
31e76fb
removing return type
khushboo-singhvi May 9, 2025
6f57f2f
fixing return type
khushboo-singhvi May 9, 2025
8449719
Adding RoundUp Donations
khushboo-singhvi May 9, 2025
aed45e4
Updating exceptions
khushboo-singhvi May 14, 2025
03852d4
Merge branch 'develop-10' into ECP-9387
khushboo-singhvi May 14, 2025
51a27ff
Merge branch 'develop-10' into ECP-9387
khushboo-singhvi May 14, 2025
0297b45
Merge branch 'develop-10' into ECP-9387
khushboo-singhvi May 15, 2025
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
5 changes: 0 additions & 5 deletions .github/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ configure: n98-magerun2.phar
bin/magento config:set payment/adyen_pay_by_link/active 1
bin/magento config:set payment/adyen_pay_by_link/days_to_expire 5
bin/magento config:set payment/adyen_giving/active 1
bin/magento config:set payment/adyen_giving/charity_description 'test'
bin/magento config:set payment/adyen_giving/charity_website 'https://adyen.com'
bin/magento config:set payment/adyen_giving/charity_merchant_account "${DONATION_ACCOUNT}"
bin/magento config:set payment/adyen_giving/donation_amounts '1,5,10'
bin/magento config:set payment/adyen_giving/background_image ''
bin/magento config:set payment/adyen_abstract/merchant_account "${ADYEN_MERCHANT}"
bin/magento config:set payment/adyen_abstract/notifications_ip_check 0
bin/magento config:set payment/adyen_abstract/payment_authorized 'processing'
Expand Down
17 changes: 17 additions & 0 deletions Api/AdyenDonationCampaignsInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Adyen\Payment\Api;

use Magento\Framework\Exception\LocalizedException;

interface AdyenDonationCampaignsInterface
{
/**
* Retrieve donation campaigns for the current customer's cart
*
* @param int $orderId
* @return string
* @throws LocalizedException
*/
public function getCampaigns(int $orderId): string;
}
17 changes: 17 additions & 0 deletions Api/GuestAdyenDonationCampaignsInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Adyen\Payment\Api;

use Magento\Framework\Exception\LocalizedException;

interface GuestAdyenDonationCampaignsInterface
{
/**
* Get donation campaigns for a guest cart
*
* @param string $cartId Masked cart ID
* @return string
* @throws LocalizedException
*/
public function getCampaigns(string $cartId): string;
}
45 changes: 21 additions & 24 deletions Block/Checkout/Success.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Adyen\Payment\Model\Ui\AdyenCheckoutSuccessConfigProvider;
use Magento\Checkout\Model\Session as CheckoutSession;
use Magento\Customer\Model\Session as CustomerSession;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Quote\Model\QuoteIdToMaskedQuoteId;
use Magento\Framework\Serialize\SerializerInterface;
Expand Down Expand Up @@ -76,7 +77,7 @@ public function __construct(
* Received e.g. Bank Transfer IBAN
* @return bool
*/
public function renderAction()
public function renderAction(): bool
{
if (
!empty($this->getOrder()->getPayment()->getAdditionalInformation('resultCode')) &&
Expand All @@ -100,7 +101,7 @@ public function getAction()
return json_encode($this->getOrder()->getPayment()->getAdditionalInformation('action'));
}

public function showAdyenGiving()
public function showAdyenGiving(): bool
{
return $this->adyenGivingEnabled() && $this->hasDonationToken();
}
Expand All @@ -110,7 +111,7 @@ public function adyenGivingEnabled(): bool
return (bool) $this->configHelper->adyenGivingEnabled($this->storeManager->getStore()->getId());
}

public function hasDonationToken()
public function hasDonationToken(): bool
{
return $this->getDonationToken() && 'null' !== $this->getDonationToken();
}
Expand All @@ -120,25 +121,6 @@ public function getDonationToken()
return json_encode($this->getOrder()->getPayment()->getAdditionalInformation('donationToken'));
}

public function getDonationComponentConfiguration(): array
{
$storeId = $this->storeManager->getStore()->getId();
$imageBaseUrl = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA).'adyen/';
$donationAmounts = explode(',', (string) $this->configHelper->getAdyenGivingDonationAmounts($storeId));
$donationAmounts = array_map(function ($amount) {
return $this->adyenHelper->formatAmount($amount, $this->getOrder()->getOrderCurrencyCode());
}, $donationAmounts);

return [
'name' => $this->configHelper->getAdyenGivingCharityName($storeId),
'description' => $this->configHelper->getAdyenGivingCharityDescription($storeId),
'backgroundUrl' => $imageBaseUrl . $this->configHelper->getAdyenGivingBackgroundImage($storeId),
'logoUrl' => $imageBaseUrl . $this->configHelper->getAdyenGivingCharityLogo($storeId),
'website' => $this->configHelper->getAdyenGivingCharityWebsite($storeId),
'donationAmounts' => implode(',', $donationAmounts)
];
}

public function getSerializedCheckoutConfig()
{
return $this->serializerInterface->serialize($this->configProvider->getConfig());
Expand All @@ -157,7 +139,7 @@ public function getClientKey()
return $this->configHelper->getClientKey($environment);
}

public function getEnvironment()
public function getEnvironment(): string
{
return $this->adyenHelper->getCheckoutEnvironment(
$this->storeManager->getStore()->getId()
Expand All @@ -166,15 +148,30 @@ public function getEnvironment()

/**
* @return Order
* @throws LocalizedException
*/
public function getOrder()
public function getOrder(): Order
{
if ($this->order == null) {
$this->order = $this->orderRepository->get($this->checkoutSession->getLastOrderId());
}
return $this->order;
}

/**
* @return int
* @throws LocalizedException
*/
public function getOrderAmount()
{
if ($this->order == null) {
$this->order = $this->orderFactory->create()->load($this->checkoutSession->getLastOrderId());
}
$amount = $this->order->getGrandTotal();
$currency = $this->order->getOrderCurrencyCode();
return $this->adyenHelper->formatAmount($amount, $currency);
}

/**
* @throws NoSuchEntityException
*/
Expand Down
47 changes: 0 additions & 47 deletions Helper/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,53 +351,6 @@ public function adyenGivingEnabled($storeId)
return $this->getConfigData('active', self::XML_ADYEN_GIVING_PREFIX, $storeId);
}

public function getAdyenGivingConfigData($storeId)
{
return [
'name' => $this->getAdyenGivingCharityName($storeId),
'description' => $this->getAdyenGivingCharityDescription($storeId),
'backgroundUrl' => $this->getAdyenGivingBackgroundImage($storeId),
'logoUrl' => $this->getAdyenGivingCharityLogo($storeId),
'website' => $this->getAdyenGivingCharityWebsite($storeId),
'donationAmounts' => $this->getAdyenGivingDonationAmounts($storeId)
];
}

public function getAdyenGivingCharityName($storeId)
{
return $this->getConfigData('charity_name', self::XML_ADYEN_GIVING_PREFIX, $storeId);
}

public function getAdyenGivingCharityDescription($storeId)
{
return $this->getConfigData('charity_description', self::XML_ADYEN_GIVING_PREFIX, $storeId);
}

public function getAdyenGivingBackgroundImage($storeId)
{
return $this->getConfigData('background_image', self::XML_ADYEN_GIVING_PREFIX, $storeId);
}

public function getAdyenGivingCharityLogo($storeId)
{
return $this->getConfigData('charity_logo', self::XML_ADYEN_GIVING_PREFIX, $storeId);
}

public function getAdyenGivingCharityWebsite($storeId)
{
return $this->getConfigData('charity_website', self::XML_ADYEN_GIVING_PREFIX, $storeId);
}

public function getAdyenGivingDonationAmounts($storeId)
{
return $this->getConfigData('donation_amounts', self::XML_ADYEN_GIVING_PREFIX, $storeId);
}

public function getCharityMerchantAccount($storeId)
{
return $this->getConfigData('charity_merchant_account', self::XML_ADYEN_GIVING_PREFIX, $storeId);
}

/**
* Retrieve payment_return_url config
*
Expand Down
6 changes: 6 additions & 0 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Adyen\Service\Checkout\ModificationsApi;
use Adyen\Service\Checkout\OrdersApi;
use Adyen\Service\Checkout\PaymentLinksApi;
use Adyen\Service\Checkout\DonationsApi;
use Adyen\Service\Checkout\PaymentsApi;
use Adyen\Service\Checkout\UtilityApi;
use Adyen\Service\PosPayment;
Expand Down Expand Up @@ -1054,6 +1055,11 @@ public function initializePaymentLinksApi(Client $client):PaymentLinksApi
return new PaymentLinksApi($client);
}

public function initializeDonationsApi(Client $client):DonationsApi
{
return new DonationsApi($client);
}

/**
* @param Client $client
* @return PosPayment
Expand Down
83 changes: 83 additions & 0 deletions Helper/DonationsHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

namespace Adyen\Payment\Helper;

use Adyen\Model\Checkout\DonationCampaignsRequest;
use Adyen\Payment\Logger\AdyenLogger;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Adyen\Payment\Helper\Data;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Sales\Model\Order;

class DonationsHelper extends AbstractHelper
{
private Data $adyenHelper;

/**
* @var AdyenLogger
*/
protected $adyenLogger;

public function __construct(
Context $context,
Data $adyenHelper,
AdyenLogger $adyenLogger
) {
parent::__construct($context);
$this->adyenHelper = $adyenHelper;
$this->adyenLogger = $adyenLogger;
}

/**
* @throws NoSuchEntityException
* @throws LocalizedException
*/
public function fetchDonationCampaigns(array $payloadData, int $storeId): array
{
$request = new DonationCampaignsRequest($payloadData);

try {
$client = $this->adyenHelper->initializeAdyenClient($storeId);
$service = $this->adyenHelper->initializeDonationsApi($client);
return $service->donationCampaigns($request)->toArray();
} catch (\Adyen\AdyenException $e) {
$this->adyenLogger->error('Error fetching donation campaigns', ['exception' => $e]);
throw new LocalizedException(__('Unable to retrieve donation campaigns. Please try again later.'));
}
}

//Return the data of the first campaign only.
public function formatCampaign(array $donationCampaignsResponse): array
{
$campaignList = $donationCampaignsResponse['donationCampaigns'] ?? [];

if (empty($campaignList)) {
return [];
}

$firstCampaign = $campaignList[0];

//Doing this workaround for now, Will be fixed with next API Library version
//RoundUp works with donation.type and not with donation.donationType
$firstCampaign['donation']['type'] = $firstCampaign['donation']['donationType'] ?? '';
return [
'nonprofitName' => $firstCampaign['nonprofitName'] ?? '',
'nonprofitDescription' => $firstCampaign['nonprofitDescription'] ?? '',
'nonprofitUrl' => $firstCampaign['nonprofitUrl'] ?? '',
'logoUrl' => $firstCampaign['logoUrl'] ?? '',
'bannerUrl' => $firstCampaign['bannerUrl'] ?? '',
'termsAndConditionsUrl' => $firstCampaign['termsAndConditionsUrl'] ?? '',
'donation' => $firstCampaign['donation'] ?? [],
'causeName' => $firstCampaign['causeName'] ?? '',
];
}

public function setDonationCampaignId(Order $order, $campaignId): void
{
$order->getPayment()->setAdditionalInformation('donationCampaignId', $campaignId);
$order->save();
}

}
4 changes: 1 addition & 3 deletions Helper/Requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class Requests extends AbstractHelper
'paywithgoogle' => 'scheme',
'applepay' => 'scheme'
];
const SHOPPER_INTERACTION_CONTAUTH = 'ContAuth';

private Data $adyenHelper;
private Config $adyenConfig;
Expand Down Expand Up @@ -411,11 +410,10 @@ public function buildDonationData($buildSubject, $storeId): array
'type' => $paymentMethodCode
],
'donationToken' => $buildSubject['donationToken'],
'donationCampaignId' => $buildSubject['donationCampaignId'],
'donationOriginalPspReference' => $buildSubject['donationOriginalPspReference'],
'donationAccount' => $this->adyenConfig->getCharityMerchantAccount($storeId),
'returnUrl' => $buildSubject['returnUrl'],
'merchantAccount' => $this->adyenHelper->getAdyenMerchantAccount('adyen_giving', $storeId),
'shopperInteraction' => self::SHOPPER_INTERACTION_CONTAUTH
];
}

Expand Down
Loading
Loading