Skip to content

Commit

Permalink
fix: adjusted meta box (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
plarsson authored Feb 16, 2023
1 parent 8bcab59 commit 6d95ac6
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 29 deletions.
7 changes: 5 additions & 2 deletions changelog.readme
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
## 1.5.1
* Fix: Adjusted Ledyer order info box

## 1.5.0
Feature: Show order recipient details in order overview
* Feature: Show order recipient details in order overview

## 1.4.0
Feature: Allow custom shipping address contact details in settings
* Feature: Allow custom shipping address contact details in settings

## 1.3.1
* Fix: Testmode patch and separate test token
Expand Down
101 changes: 78 additions & 23 deletions classes/admin/class-ledyer-meta-box.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,55 +51,110 @@ public function meta_box_content() {

// False if automatic settings are enabled, true if not. If true then show the option.
if ( ! empty( get_post_meta( $order_id, '_transaction_id', true ) ) && ! empty( get_post_meta( $order_id, '_wc_ledyer_order_id', true ) ) ) {

// TODO: if ledyer_pending or status on-hold: get info from session
// Then: print_standard_content but with session info
// Below request will fail if no order has been created yet (fetch from get_order_session instead)
$ledyer_order = ledyer()->api->get_order( get_post_meta( $order_id, '_wc_ledyer_order_id', true ) );

if ( is_wp_error( $ledyer_order ) ) {
if ( is_wp_error( $ledyer_order ) && 404 === $ledyer_order->get_error_code ()) {
$ledyer_session = ledyer()->api->get_order_session( get_post_meta( $order_id, '_wc_ledyer_order_id', true ) );
if ( is_wp_error( $ledyer_session ) ) {
$this->print_error_content( __( 'Failed to retrieve the session from Ledyer.', 'ledyer-checkout-for-woocommerce' ) );
return;
}
$this->print_session_content( $ledyer_session );
} else if ( is_wp_error( $ledyer_order ) ) {
$this->print_error_content( __( 'Failed to retrieve the order from Ledyer. The customer may not have been able to complete the checkout flow', 'ledyer-checkout-for-woocommerce' ) );
return;
} else {
$this->print_order_content( $ledyer_order );
}
}
$this->print_standard_content( $ledyer_order );
}

/**
* Prints the standard content for the Metabox
* Prints the standard order content for the Metabox
*
* @param object $ledyer_order The Ledyer order object.
* @return void
*/
public function print_standard_content( $ledyer_order ) {
// Show ledyer order information.
private function print_order_content( $ledyer_order ) {
?>
<div class="lco-meta-box-content">
<div class="lco-meta-box-content">
<?php if ( $ledyer_order ) { ?>
<?php
if ( '' !== ledyer()->get_setting('testmode') ) {
$environment = 'yes' === ledyer()->get_setting('testmode') ? 'Sandbox' : 'Production';
$environment = 'yes' === ledyer()->get_setting('testmode') ? 'Sandbox' : 'Live';
$ledyer_order_url = 'yes' === ledyer()->get_setting('testmode') ?
'https://merchant.sandbox.ledyer.com/orders/' . $ledyer_order['id'] :
'https://merchant.live.ledyer.com/orders/' . $ledyer_order['id'];
?>
<strong><?php esc_html_e( 'Ledyer Environment: ', 'ledyer-checkout-for-woocommerce' ); ?> </strong><?php echo esc_html( $environment ); ?><br/>
<strong><?php esc_html_e( 'Environment: ', 'ledyer-checkout-for-woocommerce' ); ?> </strong><?php echo esc_html( $environment ); ?><br/>
<?php } ?>
<strong><?php esc_html_e( 'Company id: ', 'ledyer-checkout-for-woocommerce' ); ?> </strong> <?php echo esc_html( $ledyer_order['customer']['companyId'] ); ?><br/>
<strong><?php esc_html_e( 'Order id: ', 'ledyer-checkout-for-woocommerce' ); ?> </strong> <?php echo esc_html( $ledyer_order['id'] ); ?><br/>
<strong><?php esc_html_e( 'Ledyer id: ', 'ledyer-checkout-for-woocommerce' ); ?> </strong> <?php echo esc_html( $ledyer_order['orderReference'] ); ?><br/>
<strong><?php esc_html_e( 'Payment method: ', 'ledyer-checkout-for-woocommerce' ); ?> </strong> <?php echo esc_html( $ledyer_order['paymentMethod']['type'] ); ?><br/>
<strong><?php esc_html_e( 'Ledyer status: ', 'ledyer-checkout-for-woocommerce' ); ?> </strong> <?php echo esc_html( implode(', ', $ledyer_order['status']) ); ?><br/>


<strong><?php esc_html_e( 'Company: ', 'ledyer-checkout-for-woocommerce' ); ?> </strong> <?php echo esc_html( $ledyer_order['customer']['companyName'] ); ?><br/>
<strong><?php esc_html_e( 'Company ID: ', 'ledyer-checkout-for-woocommerce' ); ?> </strong> <?php echo esc_html( $ledyer_order['customer']['companyId'] ); ?><br/>
<?php if( ! empty( $ledyer_order['customer']['firstName'] ) || ! empty( $ledyer_order['customer']['lastName'] ) ) : ?>
<strong><?php esc_html_e( 'Order setter: ', 'ledyer-checkout-for-woocommerce' ); ?> </strong> <?php echo esc_html( $ledyer_order['customer']['firstName'] . ' ' . $ledyer_order['customer']['lastName'] ); ?><br/>
<strong><?php esc_html_e( 'Name: ', 'ledyer-checkout-for-woocommerce' ); ?> </strong> <?php echo esc_html( $ledyer_order['customer']['firstName'] . ' ' . $ledyer_order['customer']['lastName'] ); ?><br/>
<?php endif; ?>
<strong><?php esc_html_e( 'Ledyer ID: ', 'ledyer-checkout-for-woocommerce' ); ?></strong> <a href="<?php echo esc_url( $ledyer_order_url ); ?>" target="_blank"><?php echo esc_html( $ledyer_order['orderReference'] ); ?></a><br/>
<strong><?php esc_html_e( 'Payment method: ', 'ledyer-checkout-for-woocommerce' ); ?> </strong> <?php echo esc_html( $ledyer_order['paymentMethod']['type'] ); ?><br/>
<?php if( "email" === $ledyer_order['customer']['invoiceChannel']['type'] && $ledyer_order['customer']['invoiceChannel']['details'] ) : ?>
<strong><?php esc_html_e( 'Invoice copy: ', 'ledyer-checkout-for-woocommerce' ); ?> </strong> <?php echo esc_html( $ledyer_order['customer']['invoiceChannel']['details'] ); ?><br/>
<?php endif; ?>
<?php if( "edi" === $ledyer_order['customer']['invoiceChannel']['type'] && $ledyer_order['customer']['invoiceChannel']['details'] ) : ?>
<strong><?php esc_html_e( 'GLN: ', 'ledyer-checkout-for-woocommerce' ); ?> </strong> <?php echo esc_html( $ledyer_order['customer']['invoiceChannel']['details'] ); ?><br/>
<?php endif; ?>
<strong><?php esc_html_e( 'Status: ', 'ledyer-checkout-for-woocommerce' ); ?> </strong> <?php echo esc_html( implode(', ', $ledyer_order['status']) ); ?><br/>
<?php if( $ledyer_order['customer']['reference1'] ) : ?>
<strong><?php esc_html_e( 'Invoice reference (e.g. order number): ', 'ledyer-checkout-for-woocommerce' ); ?> </strong> <?php echo esc_html( $ledyer_order['customer']['reference1'] ); ?><br/>
<strong><?php esc_html_e( 'Invoice reference (e.g. order number): ', 'ledyer-checkout-for-woocommerce' ); ?> </strong> <?php echo esc_html( $ledyer_order['customer']['reference1'] ); ?><br/>
<?php endif; ?>
<?php if( $ledyer_order['customer']['reference2'] ) : ?>
<strong><?php esc_html_e( 'Optional reference (e.g. cost center): ', 'ledyer-checkout-for-woocommerce' ); ?> </strong> <?php echo esc_html( $ledyer_order['customer']['reference2'] ); ?><br/>
<strong><?php esc_html_e( 'Optional reference (e.g. cost center): ', 'ledyer-checkout-for-woocommerce' ); ?> </strong> <?php echo esc_html( $ledyer_order['customer']['reference2'] ); ?><br/>
<?php endif; ?>
<?php if( "forced" === $ledyer_order['authorizeStatus'] ) : ?>
<strong><?php esc_html_e( 'Manual review: ', 'ledyer-checkout-for-woocommerce' ); ?> </strong> <span style="color:#a00;"> advised</span><br/>
<?php endif; ?>
<?php if( $ledyer_order['riskProfile']['tags'] ) : ?>
<strong><?php esc_html_e( 'Risk profile: ', 'ledyer-checkout-for-woocommerce' ); ?> </strong> <?php echo esc_html( implode(', ', $ledyer_order['riskProfile']['tags']) ); ?><br/>
<?php endif; ?>
<?php } ?>
</div>
</div>
<?php
}

/**
* Prints the standard session content for the Metabox
*
* @param object $ledyer_session The Ledyer session object.
* @return void
*/
private function print_session_content( $ledyer_session ) {
?>
<div class="lco-meta-box-content">
<?php if ( $ledyer_session ) { ?>
<?php
if ( '' !== ledyer()->get_setting('testmode') ) {
$environment = 'yes' === ledyer()->get_setting('testmode') ? 'Sandbox' : 'Live';
?>
<strong><?php esc_html_e( 'Environment: ', 'ledyer-checkout-for-woocommerce' ); ?> </strong><?php echo esc_html( $environment ); ?><br/>
<?php } ?>
<strong><?php esc_html_e( 'Company ID: ', 'ledyer-checkout-for-woocommerce' ); ?> </strong> <?php echo esc_html( $ledyer_session['customer']['companyId'] ); ?><br/>
<?php if( ! empty( $ledyer_session['customer']['firstName'] ) || ! empty( $ledyer_session['customer']['lastName'] ) ) : ?>
<strong><?php esc_html_e( 'Name: ', 'ledyer-checkout-for-woocommerce' ); ?> </strong> <?php echo esc_html( $ledyer_session['customer']['firstName'] . ' ' . $ledyer_session['customer']['lastName'] ); ?><br/>
<?php endif; ?>
<strong><?php esc_html_e( 'Payment method: ', 'ledyer-checkout-for-woocommerce' ); ?> </strong> <?php echo esc_html( $ledyer_session['customer']['paymentMethod']['type'] ); ?><br/>
<?php if( "email" === $ledyer_session['customer']['invoiceChannel']['type'] && $ledyer_session['customer']['invoiceChannel']['details'] ) : ?>
<strong><?php esc_html_e( 'Invoice copy: ', 'ledyer-checkout-for-woocommerce' ); ?> </strong> <?php echo esc_html( $ledyer_session['customer']['invoiceChannel']['details'] ); ?><br/>
<?php endif; ?>
<?php if( "edi" === $ledyer_session['customer']['invoiceChannel']['type'] && $ledyer_session['customer']['invoiceChannel']['details'] ) : ?>
<strong><?php esc_html_e( 'GLN: ', 'ledyer-checkout-for-woocommerce' ); ?> </strong> <?php echo esc_html( $ledyer_session['customer']['invoiceChannel']['details'] ); ?><br/>
<?php endif; ?>
<strong><?php esc_html_e( 'State: ', 'ledyer-checkout-for-woocommerce' ); ?> </strong> <?php echo esc_html( $ledyer_session['state'] ); ?><br/>
<?php if( $ledyer_session['customer']['reference1'] ) : ?>
<strong><?php esc_html_e( 'Invoice reference (e.g. order number): ', 'ledyer-checkout-for-woocommerce' ); ?> </strong> <?php echo esc_html( $ledyer_session['customer']['reference1'] ); ?><br/>
<?php endif; ?>
<?php if( $ledyer_session['customer']['reference2'] ) : ?>
<strong><?php esc_html_e( 'Optional reference (e.g. cost center): ', 'ledyer-checkout-for-woocommerce' ); ?> </strong> <?php echo esc_html( $ledyer_session['customer']['reference2'] ); ?><br/>
<?php endif; ?>
<?php } ?>
</div>
<?php
}

Expand Down
2 changes: 1 addition & 1 deletion classes/class-ledyer-main.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class Ledyer_Checkout_For_WooCommerce {
*/
public $checkout;

const VERSION = '1.5.0';
const VERSION = '1.5.1';
const SLUG = 'ledyer-checkout-for-woocommerce';
const SETTINGS = 'ledyer_checkout_for_woocommerce_settings';

Expand Down
2 changes: 1 addition & 1 deletion languages/ledyer-checkout-for-woocommerce.pot
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This file is distributed under the same license as the Ledyer Checkout for WooCommerce plugin.
msgid ""
msgstr ""
"Project-Id-Version: Ledyer Checkout for WooCommerce 1.5.0\n"
"Project-Id-Version: Ledyer Checkout for WooCommerce 1.5.1\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/ledyer-checkout-for-woocommerce\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down
2 changes: 1 addition & 1 deletion ledyer-checkout-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: Ledyer Checkout payment gateway for WooCommerce.
* Author: Maksimer/Ledyer
* Author URI: https://www.maksimer.com/
* Version: 1.5.0
* Version: 1.5.1
* Text Domain: ledyer-checkout-for-woocommerce
* Domain Path: /languages
*
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ Tested up to: 8.1.11
Requires PHP: 7.0
WC requires at least: 4.0.0
WC tested up to: 6.9.3
Stable tag: 1.5.0
Stable tag: 1.5.1
License: GPLv3 or later
License URI: http://www.gnu.org/licenses/gpl-3.0.html

0 comments on commit 6d95ac6

Please sign in to comment.