Skip to content

Commit

Permalink
Use the shipping company as a fallback when the billing company is nu…
Browse files Browse the repository at this point in the history
…ll (#91)

* Use company shipping address as a fallback when the company billing address is null

* Bump version
  • Loading branch information
arthurmmoreira authored Jul 17, 2023
1 parent 02a25da commit 7d22bd4
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 13 deletions.
6 changes: 5 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, woo commerce, shop, cart, shopping cart, sell online, checkout, payment, payments, bnpl, b2b
Requires at least: 5.9.0
Tested up to: 6.2.2
Stable tag: 2.0.1
Stable tag: 2.0.2
Requires PHP: 7.4
License: GPLv3
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Expand Down Expand Up @@ -57,6 +57,10 @@ Check out [Frequently Asked Questions](https://www.mondu.ai/faq) in the Mondu we

== Changelog ==

= 2.0.2 =

* Use company shipping address as a fallback when company billing address is null

= 2.0.1 =

* Fix sandbox or production setting name
Expand Down
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
== Changelog ==

= 2.0.2 =

* Use company shipping address as a fallback when company billing address is null

= 2.0.1 =

* Fix sandbox or production setting name
Expand Down
4 changes: 2 additions & 2 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 GPLv3.
msgid ""
msgstr ""
"Project-Id-Version: Mondu Buy Now Pay Later 2.0.1\n"
"Project-Id-Version: Mondu Buy Now Pay Later 2.0.2\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/mondu-buy-now-pay-later\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2023-07-10T08:16:30+00:00\n"
"POT-Creation-Date: 2023-07-17T12:18:00+00:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.8.1\n"
"X-Domain: mondu\n"
Expand Down
4 changes: 2 additions & 2 deletions mondu-buy-now-pay-later.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Mondu Buy Now Pay Later
* Plugin URI: https://github.com/mondu-ai/bnpl-checkout-woocommerce/releases
* Description: Mondu provides B2B E-commerce and B2B marketplaces with an online payment solution to buy now and pay later.
* Version: 2.0.1
* Version: 2.0.2
* Author: Mondu
* Author URI: https://mondu.ai
*
Expand All @@ -25,7 +25,7 @@
die( 'Direct access not allowed' );
}

define( 'MONDU_PLUGIN_VERSION', '2.0.1' );
define( 'MONDU_PLUGIN_VERSION', '2.0.2' );
define( 'MONDU_PLUGIN_FILE', __FILE__ );
define( 'MONDU_PLUGIN_PATH', __DIR__ );
define( 'MONDU_PLUGIN_BASENAME', plugin_basename(MONDU_PLUGIN_FILE) );
Expand Down
32 changes: 25 additions & 7 deletions src/Mondu/Mondu/Support/OrderData.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,11 @@ public static function create_credit_note( WC_Order_Refund $refund ) {
* @return array
*/
public static function order_data_from_wc_order( WC_Order $order ) {
$billing_first_name = $order->get_billing_first_name();
$billing_last_name = $order->get_billing_last_name();
$billing_company_name = $order->get_billing_company();
$billing_email = $order->get_billing_email();
$billing_phone = $order->get_billing_phone();
$customer_id = $order->get_customer_id();
$billing_first_name = $order->get_billing_first_name();
$billing_last_name = $order->get_billing_last_name();
$billing_email = $order->get_billing_email();
$billing_phone = $order->get_billing_phone();
$customer_id = $order->get_customer_id();

$billing_address_line1 = $order->get_billing_address_1();
$billing_address_line2 = $order->get_billing_address_2();
Expand All @@ -137,7 +136,7 @@ public static function order_data_from_wc_order( WC_Order $order ) {
'buyer' => [
'first_name' => isset($billing_first_name) && Helper::not_null_or_empty($billing_first_name) ? $billing_first_name : null,
'last_name' => isset($billing_last_name) && Helper::not_null_or_empty($billing_last_name) ? $billing_last_name : null,
'company_name' => isset($billing_company_name) && Helper::not_null_or_empty($billing_company_name) ? $billing_company_name : null,
'company_name' => self::get_company_name_from_wc_order( $order ),
'email' => isset($billing_email) && Helper::not_null_or_empty($billing_email) ? $billing_email : null,
'phone' => isset($billing_phone) && Helper::not_null_or_empty($billing_phone) ? $billing_phone : null,
'external_reference_id' => isset($customer_id) && Helper::not_null_or_empty($customer_id) ? (string) $customer_id : null,
Expand Down Expand Up @@ -274,4 +273,23 @@ public static function get_amount_from_wc_order( WC_Order $order ) {

return $amount;
}

/**
* Get company name from WC_Order
*
* @param WC_Order $order
* @return string|null
*/
public static function get_company_name_from_wc_order( WC_Order $order ) {
$billing_company_name = $order->get_billing_company();
$shipping_company_name = $order->get_shipping_company();

if ( isset( $billing_company_name ) && Helper::not_null_or_empty( $billing_company_name ) ) {
return $billing_company_name;
} else if ( isset( $shipping_company_name ) && Helper::not_null_or_empty( $shipping_company_name ) ) {
return $shipping_company_name;
} else {
return null;
}
}
}
2 changes: 1 addition & 1 deletion src/Mondu/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public function validate_required_fields( array $fields, WP_Error $errors ) {
return;
}

if ( !Helper::not_null_or_empty($fields['billing_company']) ) {
if ( !Helper::not_null_or_empty($fields['billing_company']) && !Helper::not_null_or_empty($fields['shipping_company']) ) {
/* translators: %s: Company */
$errors->add('validation', sprintf(__('%s is a required field for Mondu payments.', 'mondu'), '<strong>' . __('Company', 'mondu') . '</strong>'));
}
Expand Down

0 comments on commit 7d22bd4

Please sign in to comment.