Skip to content

Commit

Permalink
Merge pull request #152 from Dintero/develop
Browse files Browse the repository at this point in the history
Version 1.7.1
  • Loading branch information
mntzrr authored Sep 26, 2023
2 parents fdc8250 + b26a58c commit 0f50e28
Show file tree
Hide file tree
Showing 14 changed files with 1,893 additions and 15,875 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"no-unused-vars":"off"
},
"extends": [
"plugin:@wordpress/eslint-plugin/esnext"
"plugin:@wordpress/eslint-plugin/recommended"
],
"globals": {
"dintero": false,
Expand Down
2 changes: 1 addition & 1 deletion assets/js/dintero-checkout-express.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/dintero-checkout-express.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/dintero-checkout-web-sdk.umd.min.js

Large diffs are not rendered by default.

40 changes: 38 additions & 2 deletions classes/class-dintero-checkout-embedded.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,42 @@ public function __construct() {
add_filter( 'woocommerce_checkout_fields', array( $this, 'add_shipping_data_input' ) );
add_action( 'woocommerce_before_calculate_totals', array( $this, 'update_shipping_method' ), 1 );
add_action( 'woocommerce_after_calculate_totals', array( $this, 'update_dintero_checkout_session' ), 9999 );
add_action( 'woocommerce_checkout_update_order_review', array( $this, 'update_wc_customer' ) );
}
}

/**
* Update the WC_Customer with the entered billing and shipping data.
*
* By default, only the fields required for calculating shipping are updated.
*
* @param string $raw_post_data The checkout form data.
* @return void
*/
public function update_wc_customer( $raw_post_data ) {
parse_str( $raw_post_data, $post_data );
$post_data = array_filter(
wc_clean( wp_unslash( $post_data ) ),
function ( $value ) {
return ! empty( $value );
}
);

isset( $post_data['billing_first_name'] ) && WC()->customer->set_billing_first_name( $post_data['billing_first_name'] );
isset( $post_data['billing_last_name'] ) && WC()->customer->set_billing_last_name( $post_data['billing_last_name'] );
isset( $post_data['billing_company'] ) && WC()->customer->set_billing_company( $post_data['billing_company'] );
isset( $post_data['billing_phone'] ) && WC()->customer->set_billing_phone( $post_data['billing_phone'] );
isset( $post_data['billing_email'] ) && WC()->customer->set_billing_email( $post_data['billing_email'] );

if ( isset( $post_data['ship_to_different_address'] ) ) {
isset( $post_data['shipping_first_name'] ) && WC()->customer->set_shipping_first_name( $post_data['shipping_first_name'] );
isset( $post_data['shipping_last_name'] ) && WC()->customer->set_shipping_last_name( $post_data['shipping_last_name'] );
isset( $post_data['shipping_company'] ) && WC()->customer->set_shipping_company( $post_data['shipping_company'] );

// Since WC 5.6.0.
if ( method_exists( WC()->customer, 'set_shipping_phone' ) && isset( $post_data['shipping_phone'] ) ) {
WC()->customer->set_shipping_phone( $post_data['shipping_phone'] );
}
}
}

Expand Down Expand Up @@ -126,5 +162,5 @@ public function update_dintero_checkout_session() {

Dintero()->api->update_checkout_session( $session_id );
}

} new Dintero_Checkout_Embedded();
}
new Dintero_Checkout_Embedded();
9 changes: 4 additions & 5 deletions classes/requests/helpers/class-dintero-checkout-cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ public function process_coupons() {
* @return array An associative array representing the billing address.
*/
public function get_billing_address() {

$billing_address = array(
'first_name' => WC()->customer->get_billing_first_name(),
'last_name' => WC()->customer->get_billing_last_name(),
Expand All @@ -374,8 +373,8 @@ public function get_billing_address() {
/* Sanitize all values. Remove all empty elements (required by Dintero). */
return array_filter(
$billing_address,
function( $value ) {
return ! empty( sanitize_text_field( $value ) );
function ( $value ) {
return ! empty( wc_clean( $value ) );
}
);
}
Expand Down Expand Up @@ -405,8 +404,8 @@ public function get_shipping_address() {
/* Sanitize all values. Remove all empty elements (required by Dintero). */
return array_filter(
$shipping_address,
function( $value ) {
return ! empty( sanitize_text_field( $value ) );
function ( $value ) {
return ! empty( wc_clean( $value ) );
}
);
}
Expand Down
4 changes: 2 additions & 2 deletions classes/requests/helpers/class-dintero-checkout-order.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ public function get_billing_address( $order ) {
return array_filter(
$billing_address,
function ( $value ) {
return ! empty( sanitize_text_field( $value ) );
return ! empty( wc_clean( $value ) );
}
);
}
Expand Down Expand Up @@ -458,7 +458,7 @@ public function get_shipping_address( $order ) {
return array_filter(
$shipping_address,
function ( $value ) {
return ! empty( sanitize_text_field( $value ) );
return ! empty( wc_clean( $value ) );
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ public function get_body() {
'remove_lock' => true,
);

// Only non-express checkout must be updated through API since the fields are entered in WC.
if ( 'checkout' === $this->settings['checkout_type'] ) {
$billing_address = $helper->get_billing_address();
if ( ! empty( $billing_address ) ) {
$body['order']['billing_address'] = $billing_address;
}

$shipping_address = $helper->get_shipping_address();
if ( ! empty( $shipping_address ) ) {
$body['order']['shipping_address'] = $shipping_address;
}
}

// Set if express or not.
if ( $this->is_express() && $this->is_embedded() ) {
$this->add_express_object( $body );
Expand Down
4 changes: 2 additions & 2 deletions dintero-checkout-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: Dintero offers a complete payment solution. Simplifying the payment process for you and the customer.
* Author: Dintero, Krokedil
* Author URI: https://krokedil.com/
* Version: 1.7.0
* Version: 1.7.1
* Text Domain: dintero-checkout-for-woocommerce
* Domain Path: /languages
*
Expand All @@ -22,7 +22,7 @@
exit;
}

define( 'DINTERO_CHECKOUT_VERSION', '1.7.0' );
define( 'DINTERO_CHECKOUT_VERSION', '1.7.1' );
define( 'DINTERO_CHECKOUT_URL', untrailingslashit( plugins_url( '/', __FILE__ ) ) );
define( 'DINTERO_CHECKOUT_PATH', untrailingslashit( plugin_dir_path( __FILE__ ) ) );
define( 'DINTERO_CHECKOUT_MAIN_FILE', __FILE__ );
Expand Down
2 changes: 1 addition & 1 deletion languages/dintero-checkout-for-woocommerce.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: "
"https://wordpress.org/support/plugin/Dintero.Checkout.WooCommerce.V2\n"
"POT-Creation-Date: 2023-09-20 13:14:32+00:00\n"
"POT-Creation-Date: 2023-09-26 08:10:41+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
Expand Down
Loading

0 comments on commit 0f50e28

Please sign in to comment.