Skip to content

Commit

Permalink
Minor fixes on the credit note creation/listing (#80)
Browse files Browse the repository at this point in the history
* Improvements on the credit note

* Minor fixes

* Fix and uUpdate translations

* Version bump
  • Loading branch information
arthurmmoreira authored May 24, 2023
1 parent 12b24d5 commit 7007d8c
Show file tree
Hide file tree
Showing 15 changed files with 113 additions and 73 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM wordpress:6.2.0
ENV WOOCOMMERCE_VERSION 7.6.0
ENV WOOCOMMERCE_PDF_INVOICES_VERSION 3.5.2
FROM wordpress:6.2.2
ENV WOOCOMMERCE_VERSION 7.6.1
ENV WOOCOMMERCE_PDF_INVOICES_VERSION 3.5.4

RUN apt update
RUN apt -y install wget
Expand Down
7 changes: 6 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: mondu-ai, arthurmmoreira, tikohov20
Tags: mondu, woocommerce, e-commerce, ecommerce, store, sales, sell, woo, shop, cart, checkout, payment, payments, bnpl, b2b
Requires at least: 5.9.0
Tested up to: 6.1.0
Stable tag: 1.3.1
Stable tag: 1.3.2
Requires PHP: 7.4.0

Increase your revenue with Mondu’s solution, without the operational burden.
Expand All @@ -23,6 +23,11 @@ Increase your revenue with Mondu’s solution, without the operational burden.

== Changelog ==

=== 1.3.2 ===

* Add early return on credit note creation
* Minor fixes on the credit note creation/listing

=== 1.3.1 ===

* Add payment method name to the enabled label
Expand Down
Binary file modified languages/mondu-de_AT.mo
Binary file not shown.
15 changes: 9 additions & 6 deletions languages/mondu-de_AT.po
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ msgid "Create Invoice"
msgstr "Rechnung erstellen"

#: src/Mondu/Mondu/Presenters/PaymentInfo.php:94
#: src/Mondu/Mondu/Presenters/PaymentInfo.php:275
#: src/Mondu/Mondu/Presenters/PaymentInfo.php:272
msgid "Corrupt Mondu order!"
msgstr "Fehlerhafte Mondu Bestellung!"

Expand Down Expand Up @@ -223,21 +223,24 @@ msgid "Invoice state"
msgstr "Rechnungsstatus"

#: src/Mondu/Mondu/Presenters/PaymentInfo.php:205
#: src/Mondu/Mondu/Presenters/PaymentInfo.php:245
msgid "Total"
msgstr "Gesamt"

#: src/Mondu/Mondu/Presenters/PaymentInfo.php:209
msgid "Paid out"
msgstr "Ausgezahlt"

#: src/Mondu/Mondu/Presenters/PaymentInfo.php:224
#: src/Mondu/Mondu/Presenters/PaymentInfo.php:222
msgid "Cancel Invoice"
msgstr "Rechnung stornieren"

#: src/Mondu/Mondu/Presenters/PaymentInfo.php:241
msgid "Credit Note number"
msgstr "Gutschriftsnummer"
#: src/Mondu/Mondu/Presenters/PaymentInfo.php:237
msgid "Credit Notes"
msgstr "Gutschriften"

#: src/Mondu/Mondu/Presenters/PaymentInfo.php:243
msgid "Tax"
msgstr "Steuer"

#: src/Mondu/Plugin.php:183
msgid "Since this order will be paid via Mondu you will not be able to change the addresses."
Expand Down
Binary file modified languages/mondu-de_DE.mo
Binary file not shown.
15 changes: 9 additions & 6 deletions languages/mondu-de_DE.po
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ msgid "Create Invoice"
msgstr "Rechnung erstellen"

#: src/Mondu/Mondu/Presenters/PaymentInfo.php:94
#: src/Mondu/Mondu/Presenters/PaymentInfo.php:275
#: src/Mondu/Mondu/Presenters/PaymentInfo.php:272
msgid "Corrupt Mondu order!"
msgstr "Fehlerhafte Mondu Bestellung!"

Expand Down Expand Up @@ -223,21 +223,24 @@ msgid "Invoice state"
msgstr "Rechnungsstatus"

#: src/Mondu/Mondu/Presenters/PaymentInfo.php:205
#: src/Mondu/Mondu/Presenters/PaymentInfo.php:245
msgid "Total"
msgstr "Gesamt"

#: src/Mondu/Mondu/Presenters/PaymentInfo.php:209
msgid "Paid out"
msgstr "Ausgezahlt"

#: src/Mondu/Mondu/Presenters/PaymentInfo.php:224
#: src/Mondu/Mondu/Presenters/PaymentInfo.php:222
msgid "Cancel Invoice"
msgstr "Rechnung stornieren"

#: src/Mondu/Mondu/Presenters/PaymentInfo.php:241
msgid "Credit Note number"
msgstr "Gutschriftsnummer"
#: src/Mondu/Mondu/Presenters/PaymentInfo.php:237
msgid "Credit Notes"
msgstr "Gutschriften"

#: src/Mondu/Mondu/Presenters/PaymentInfo.php:243
msgid "Tax"
msgstr "Steuer"

#: src/Mondu/Plugin.php:183
msgid "Since this order will be paid via Mondu you will not be able to change the addresses."
Expand Down
Binary file modified languages/mondu-fr_FR.mo
Binary file not shown.
15 changes: 9 additions & 6 deletions languages/mondu-fr_FR.po
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ msgid "Create Invoice"
msgstr "Créer une facture"

#: src/Mondu/Mondu/Presenters/PaymentInfo.php:94
#: src/Mondu/Mondu/Presenters/PaymentInfo.php:275
#: src/Mondu/Mondu/Presenters/PaymentInfo.php:272
msgid "Corrupt Mondu order!"
msgstr "Commande Mondu corrompue!"

Expand Down Expand Up @@ -223,21 +223,24 @@ msgid "Invoice state"
msgstr "État de la facture"

#: src/Mondu/Mondu/Presenters/PaymentInfo.php:205
#: src/Mondu/Mondu/Presenters/PaymentInfo.php:245
msgid "Total"
msgstr "Total"

#: src/Mondu/Mondu/Presenters/PaymentInfo.php:209
msgid "Paid out"
msgstr "Payé"

#: src/Mondu/Mondu/Presenters/PaymentInfo.php:224
#: src/Mondu/Mondu/Presenters/PaymentInfo.php:222
msgid "Cancel Invoice"
msgstr "Annuler la facture"

#: src/Mondu/Mondu/Presenters/PaymentInfo.php:241
msgid "Credit Note number"
msgstr "Numéro de la note de crédit"
#: src/Mondu/Mondu/Presenters/PaymentInfo.php:237
msgid "Credit Notes"
msgstr "Notes de crédit"

#: src/Mondu/Mondu/Presenters/PaymentInfo.php:243
msgid "Tax"
msgstr "Taxe"

#: src/Mondu/Plugin.php:183
msgid "Since this order will be paid via Mondu you will not be able to change the addresses."
Expand Down
Binary file modified languages/mondu-nl_NL.mo
Binary file not shown.
15 changes: 9 additions & 6 deletions languages/mondu-nl_NL.po
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ msgid "Create Invoice"
msgstr "Factuur aanmaken"

#: src/Mondu/Mondu/Presenters/PaymentInfo.php:94
#: src/Mondu/Mondu/Presenters/PaymentInfo.php:275
#: src/Mondu/Mondu/Presenters/PaymentInfo.php:272
msgid "Corrupt Mondu order!"
msgstr "Corrupte Mondu order!"

Expand Down Expand Up @@ -223,21 +223,24 @@ msgid "Invoice state"
msgstr "Factuurstatus"

#: src/Mondu/Mondu/Presenters/PaymentInfo.php:205
#: src/Mondu/Mondu/Presenters/PaymentInfo.php:245
msgid "Total"
msgstr "Totaal"

#: src/Mondu/Mondu/Presenters/PaymentInfo.php:209
msgid "Paid out"
msgstr "Uitbetaald"

#: src/Mondu/Mondu/Presenters/PaymentInfo.php:224
#: src/Mondu/Mondu/Presenters/PaymentInfo.php:222
msgid "Cancel Invoice"
msgstr "Factuur annuleren"

#: src/Mondu/Mondu/Presenters/PaymentInfo.php:241
msgid "Credit Note number"
msgstr "Creditnota Nummer"
#: src/Mondu/Mondu/Presenters/PaymentInfo.php:237
msgid "Credit Notes"
msgstr "Creditnota's"

#: src/Mondu/Mondu/Presenters/PaymentInfo.php:243
msgid "Tax"
msgstr "Belasting"

#: src/Mondu/Plugin.php:183
msgid "Since this order will be paid via Mondu you will not be able to change the addresses."
Expand Down
17 changes: 10 additions & 7 deletions languages/mondu.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# This file is distributed under the MIT.
msgid ""
msgstr ""
"Project-Id-Version: WooCommerce-Mondu 1.3.1\n"
"Project-Id-Version: WooCommerce-Mondu 1.3.2\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/Woocommerce-Mondu\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2023-05-17T13:06:27+00:00\n"
"POT-Creation-Date: 2023-05-24T15:04:20+00:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.7.1\n"
"X-Domain: mondu\n"
Expand Down Expand Up @@ -183,7 +183,7 @@ msgid "Create Invoice"
msgstr ""

#: src/Mondu/Mondu/Presenters/PaymentInfo.php:94
#: src/Mondu/Mondu/Presenters/PaymentInfo.php:275
#: src/Mondu/Mondu/Presenters/PaymentInfo.php:272
msgid "Corrupt Mondu order!"
msgstr ""

Expand Down Expand Up @@ -226,20 +226,23 @@ msgid "Invoice state"
msgstr ""

#: src/Mondu/Mondu/Presenters/PaymentInfo.php:205
#: src/Mondu/Mondu/Presenters/PaymentInfo.php:245
msgid "Total"
msgstr ""

#: src/Mondu/Mondu/Presenters/PaymentInfo.php:209
msgid "Paid out"
msgstr ""

#: src/Mondu/Mondu/Presenters/PaymentInfo.php:224
#: src/Mondu/Mondu/Presenters/PaymentInfo.php:222
msgid "Cancel Invoice"
msgstr ""

#: src/Mondu/Mondu/Presenters/PaymentInfo.php:241
msgid "Credit Note number"
#: src/Mondu/Mondu/Presenters/PaymentInfo.php:237
msgid "Credit Notes"
msgstr ""

#: src/Mondu/Mondu/Presenters/PaymentInfo.php:243
msgid "Tax"
msgstr ""

#: src/Mondu/Plugin.php:183
Expand Down
6 changes: 1 addition & 5 deletions src/Mondu/Mondu/MonduRequestWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,7 @@ public function order_refunded($order_id, $refund_id) {
}

$refund = new WC_Order_Refund($refund_id);
$refund_total = $refund->get_total();
$credit_note = [
'gross_amount_cents' => abs(round((float) $refund_total * 100)),
'external_reference_id' => (string) $refund->get_id()
];
$credit_note = OrderData::create_credit_note($refund);

$this->wrap_with_mondu_log_event('create_credit_note', array($mondu_invoice_id, $credit_note));
}
Expand Down
47 changes: 22 additions & 25 deletions src/Mondu/Mondu/Presenters/PaymentInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,23 +209,21 @@ public function get_mondu_invoices_html() {
<span><strong><?php _e('Paid out', 'mondu'); ?>:</strong></span>
<?php printf($invoice['paid_out'] ? __('Yes', 'mondu') : __('No', 'mondu')) ?>
</p>
<div>
<?php printf($this->get_mondu_credit_note_html($invoice)) ?>
</div>
<?php
if ($invoice['state'] !== 'canceled') {
?>
<?php $mondu_data = [
'order_id' => $this->order->get_id(),
'invoice_id' => $invoice['uuid'],
'mondu_order_id' => $this->order_data['uuid'],
]; ?>
<button data-mondu='<?php echo(json_encode($mondu_data)) ?>' id="mondu-cancel-invoice-button" type="submit" class="button grant_access">
<?php _e('Cancel Invoice', 'mondu'); ?>
</button>
<?php
}
?>
<?php
printf($this->get_mondu_credit_note_html($invoice));
if ($invoice['state'] !== 'canceled') {
?>
<?php $mondu_data = [
'order_id' => $this->order->get_id(),
'invoice_id' => $invoice['uuid'],
'mondu_order_id' => $this->order_data['uuid'],
]; ?>
<button data-mondu='<?php echo(json_encode($mondu_data)) ?>' id="mondu-cancel-invoice-button" type="submit" class="button grant_access">
<?php _e('Cancel Invoice', 'mondu'); ?>
</button>
<?php
}
?>
<?php
}

Expand All @@ -235,16 +233,15 @@ public function get_mondu_invoices_html() {
public function get_mondu_credit_note_html($invoice) {
ob_start();

?>
<p><strong><?php if (!empty($invoice['credit_notes'])) _e('Credit Notes', 'mondu') ?>:</strong></p>
<?php

foreach ($invoice['credit_notes'] as $note) {
?>
<p>
<span><strong><?php _e('Credit Note number', 'mondu'); ?>:</strong></span>
<?php printf($note['external_reference_id']) ?>
</p>
<p>
<span><strong><?php _e('Total', 'mondu'); ?>:</strong></span>
<?php printf('%s %s', ($note['gross_amount_cents'] / 100), $invoice['order']['currency']) ?>
</p>
<li>
<?php printf('%s: %s %s (%s: %s %s)', '<strong>#' . $note['external_reference_id'] . '</strong>', ($note['gross_amount_cents'] / 100), $invoice['order']['currency'], __('Tax', 'mondu'), ($note['tax_cents'] / 100), $invoice['order']['currency']) ?>
</li>
<?php
}

Expand Down
39 changes: 33 additions & 6 deletions src/Mondu/Mondu/Support/OrderData.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Mondu\Mondu\Support\Helper;
use Mondu\Plugin;
use WC_Order;
use WC_Order_Refund;

class OrderData {
/**
Expand Down Expand Up @@ -281,12 +282,6 @@ public static function invoice_data_from_wc_order(WC_Order $order) {
$invoice_data['shipping_info']['shipping_method'] = $order->get_shipping_method();
}

if ($order->get_shipping_method()) {
$invoice_data['shipping_info'] = [
'shipping_method' => $order->get_shipping_method()
];
}

foreach ($order->get_items() as $item_id => $item) {
$product = $item->get_product();

Expand All @@ -300,6 +295,38 @@ public static function invoice_data_from_wc_order(WC_Order $order) {
return Helper::remove_keys($invoice_data, $except_keys);
}

/**
* @param $order
* @param $refund
*
* @return array[]
*/
public static function create_credit_note(WC_Order_Refund $refund) {
$credit_note = [
'gross_amount_cents' => abs(round((float) $refund->get_total() * 100)),
'tax_cents' => abs(round((float) $refund->get_total_tax() * 100)),
'external_reference_id' => (string) $refund->get_id(),
'line_items' => []
];

if ($refund->get_reason()) {
$credit_note['notes'] = $refund->get_reason();
}

foreach ($refund->get_items() as $item_id => $item) {
$product = $item->get_product();

$line_item = [
'external_reference_id' => Helper::not_null_or_empty($product->get_id()) ? (string) $product->get_id() : null,
'quantity' => abs($item->get_quantity()), # The quantity will be negative
];

$credit_note['line_items'][] = $line_item;
}

return $credit_note;
}

private static function add_lines_to_except_keys($keys, $itemType = 'order') {
$global_settings = get_option(Plugin::OPTION_NAME);
$sendLineSetting = $global_settings['field_send_line_items'] ?? 'yes';
Expand Down
4 changes: 2 additions & 2 deletions woocommerce-mondu.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: WooCommerce-Mondu
* Plugin URI: https://github.com/mondu-ai/bnpl-checkout-woocommerce/releases
* Description: Increase your revenue with Mondu’s solution, without the operational burden.
* Version: 1.3.1
* Version: 1.3.2
* Author: Mondu
* Author URI: https://mondu.ai
* License: MIT
Expand All @@ -21,7 +21,7 @@

defined('ABSPATH') or die('Direct access not allowed');

define('MONDU_PLUGIN_VERSION', '1.3.1');
define('MONDU_PLUGIN_VERSION', '1.3.2');
define('MONDU_PLUGIN_FILE', __FILE__);
define('MONDU_PLUGIN_PATH', __DIR__);
define('MONDU_PLUGIN_BASENAME', plugin_basename(MONDU_PLUGIN_FILE));
Expand Down

0 comments on commit 7007d8c

Please sign in to comment.