Skip to content

Commit

Permalink
multicurrency support (admin side)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidVin357 committed Sep 11, 2023
1 parent 98216be commit 47955b3
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 8 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
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
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
5 changes: 3 additions & 2 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,7 +47,7 @@ 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 = [
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

0 comments on commit 47955b3

Please sign in to comment.