Skip to content

Commit

Permalink
Merge pull request #27 from donmo-roundup/feat/multicurrency-support
Browse files Browse the repository at this point in the history
Feat/multicurrency support
  • Loading branch information
DavidVin357 authored Sep 11, 2023
2 parents 33356f4 + 47955b3 commit 92c39fa
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 15 deletions.
16 changes: 16 additions & 0 deletions Api/Data/DonationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface DonationInterface
*/
const DONATION_ID = 'donation_id';
const DONATION_AMOUNT = 'donation_amount';
const DONATION_CURRENCY = 'currency';
const STATUS = 'status';
const MODE = 'mode';
const MASKED_QUOTE_ID = 'masked_quote_id';
Expand Down Expand Up @@ -50,6 +51,21 @@ public function getDonationAmount(): float;
*/
public function setDonationAmount(float $donationAmount);

/**
* Get Donation Currency
*
* @return string
*/
public function getCurrency(): string;

/**
* Set Donation Currency
*
* @param string $currency
* @return $this
*/
public function setCurrency($currency);

/**
* Get Status
*
Expand Down
1 change: 1 addition & 0 deletions Block/Checkout/LayoutProcessor/DonmoConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function process($jsLayout)
['children']['donmo-block']['donmoConfig'] = [
'publicKey' => $this->donmoConfig->getPublicKey($this->mode),
'language' => $this->donmoConfig->getLanguageCode(),
'currency' => $this->donmoConfig->getCurrencyCode(),
'integrationTitle' => $this->donmoConfig->getIntegrationTitle(),
'roundupMessage' => $this->donmoConfig->getRoundupMessage(),
'thankMessage' => $this->donmoConfig->getThankMessage(),
Expand Down
15 changes: 13 additions & 2 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Locale\Resolver as LocaleResolver;
use Magento\Store\Model\StoreManagerInterface;

class Config
{
Expand All @@ -17,16 +18,21 @@ class Config

private ScopeConfigInterface $scopeConfig;
private LocaleResolver $localeResolver;
private StoreManagerInterface $storeManager;

/**
* Config constructor.
*
* @param ScopeConfigInterface $scopeConfig
*/
public function __construct(ScopeConfigInterface $scopeConfig, LocaleResolver $localeResolver)
{
public function __construct(
ScopeConfigInterface $scopeConfig,
LocaleResolver $localeResolver,
StoreManagerInterface $storeManager
) {
$this->scopeConfig = $scopeConfig;
$this->localeResolver = $localeResolver;
$this->storeManager = $storeManager;
}

public function getCurrentMode(): string
Expand Down Expand Up @@ -79,4 +85,9 @@ public function getLanguageCode() : string
$languageCode = strstr($currentLocaleCode, '_', true);
return $languageCode;
}

public function getCurrencyCode() : string
{
return $this->storeManager->getStore()->getCurrentCurrencyCode();
}
}
21 changes: 21 additions & 0 deletions Model/Donation.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,27 @@ public function setDonationAmount($donationAmount)
return $this->setData(self::DONATION_AMOUNT, $donationAmount);
}

/**
* Get Currency
*
* @return string
*/
public function getCurrency(): string
{
return $this->getData(self::DONATION_CURRENCY);
}

/**
* Set Status
*
* @param string $currency
* @return $this
*/
public function setCurrency($currency)
{
return $this->setData(self::DONATION_CURRENCY, $currency);
}

/**
* Get Status
*
Expand Down
2 changes: 2 additions & 0 deletions Model/DonationManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,15 @@ public function createDonation(Order $order): void
$quoteId = $order->getQuoteId();
$maskedId = $this->quoteIdToMaskedQuoteId->execute($quoteId);
$currentMode = $this->donmoConfig->getCurrentMode();
$currency = $order->getOrderCurrency()->getCurrencyCode();

if ($donationAmount) {
$donation = $this->donationFactory->create();
$donation
->setOrderId($orderId)
->setMaskedQuoteId($maskedId)
->setDonationAmount($donationAmount)
->setCurrency($currency)
->setMode($currentMode)
->setStatus(self::STATUS_PENDING);

Expand Down
1 change: 0 additions & 1 deletion Model/GuestCartDonationManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public function __construct(
*/
public function addDonationToCart(string $cartId, float $donationAmount): string
{
$this->logger->info('addDonationToCart guest');
return $this->cartDonationManagement->addDonationToCart($this->maskedQuoteIdToQuoteId->execute($cartId), $donationAmount);
}

Expand Down
1 change: 1 addition & 0 deletions ViewModel/Cart/Donmo.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function getDonmoConfig(): string
$this->json->serialize([
'publicKey' => $this->donmoConfig->getPublicKey($this->mode),
'language' => $this->donmoConfig->getLanguageCode(),
'currency' => $this->donmoConfig->getCurrencyCode(),
'integrationTitle' => $this->donmoConfig->getIntegrationTitle(),
'roundupMessage' => $this->donmoConfig->getRoundupMessage(),
'thankMessage' => $this->donmoConfig->getThankMessage(),
Expand Down
2 changes: 2 additions & 0 deletions etc/db_schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<column xsi:type="decimal" name="donation_amount" scale="2" precision="20" unsigned="false"
comment="Donation Amount"/>

<column xsi:type="varchar" name="currency" length="3" comment="Donation Currency"/>

<column xsi:type="varchar" name="status" length="32" default="PENDING" comment="Status"/>

<column xsi:type="varchar" name="mode" length="32" comment="Mode"/>
Expand Down
13 changes: 7 additions & 6 deletions lib/ApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ private function generatePayload(array $donations): array
$payload[] = [
'donationAmount' => $donation->getDonationAmount(),
'createdAt' => $donation->getCreatedAt(),
'orderId' => $donation->getMaskedQuoteId()
'orderId' => $donation->getMaskedQuoteId(),
'currency' => $donation->getCurrency()
];
}
return $payload;
Expand All @@ -46,13 +47,13 @@ public function createAndConfirmDonations($mode, array $donations): int
{
$sk = $this->donmoConfig->getSecretKey($mode);

$url = Donmo::$apiBase . '/donations/confirm';
$url = Donmo::$apiBase . '/donations';

$ch = curl_init();
$headers = array(
$headers = [
'Content-Type: application/json',
"sk: $sk"
);
];

$payload = $this->generatePayload($donations);
$body = json_encode(['donations' => $payload]);
Expand Down Expand Up @@ -84,10 +85,10 @@ public function deleteDonation($donationMode, $id): int
$url = Donmo::$apiBase . "/donations/{$id}";

$ch = curl_init();
$headers = array(
$headers = [
'Content-Type: application/json',
"sk: $sk"
);
];

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
Expand Down
2 changes: 1 addition & 1 deletion lib/Donmo.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

class Donmo
{
public static string $apiBase = 'https://api.donmo.org/v1/ua';
public static string $apiBase = 'https://api.donmo.org/v1';
}
18 changes: 13 additions & 5 deletions view/adminhtml/ui_component/donmo_report.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@
</column>

<column name="donation_amount"
class="Magento\Sales\Ui\Component\Listing\Column\Price"
sortOrder="24">
<settings>
<filter>text</filter>
Expand All @@ -112,10 +111,19 @@
</settings>
</column>

<column name="currency"
sortOrder="25">
<settings>
<filter>text</filter>
<dataType>text</dataType>
<label>Donation Currency</label>
</settings>
</column>

<column name="created_at"
class="Magento\Ui\Component\Listing\Columns\Date"
component="Magento_Ui/js/grid/columns/date"
sortOrder="25">
sortOrder="26">
<settings>
<filter>text</filter>
<dataType>text</dataType>
Expand All @@ -126,7 +134,7 @@
<column name="updated_at"
class="Magento\Ui\Component\Listing\Columns\Date"
component="Magento_Ui/js/grid/columns/date"
sortOrder="26"
sortOrder="27"
>
<settings>
<filter>text</filter>
Expand All @@ -137,7 +145,7 @@

<column name="mode"
component="Magento_Ui/js/grid/columns/select"
sortOrder="27">
sortOrder="28">
<settings>
<options class="Donmo\Roundup\Ui\Component\Listing\Column\Mode"/>
<filter>select</filter>
Expand All @@ -149,7 +157,7 @@
<column
name="status"
component="Magento_Ui/js/grid/columns/select"
sortOrder="28"
sortOrder="29"
>
<settings>
<options class="Donmo\Roundup\Ui\Component\Listing\Column\Status"/>
Expand Down
1 change: 1 addition & 0 deletions view/frontend/web/js/view/cart/donmo-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ define([
isBackendBased: true,
elementId: 'donmo-roundup',
language: this.donmoConfig.language,
currency: this.donmoConfig.currency,
orderId: quote.getQuoteId(),
integrationTitle: this.donmoConfig.integrationTitle,
roundupMessage: this.donmoConfig.roundupMessage,
Expand Down
1 change: 1 addition & 0 deletions view/frontend/web/js/view/checkout/summary/donmo-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ define([
isBackendBased: true,
elementId: 'donmo-roundup',
language: this.donmoConfig.language,
currency: this.donmoConfig.currency,
orderId: quote.getQuoteId(),
integrationTitle: this.donmoConfig.integrationTitle,
roundupMessage: this.donmoConfig.roundupMessage,
Expand Down

0 comments on commit 92c39fa

Please sign in to comment.