Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions woocommerce-gateway-billmate/class-billmate-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,18 +503,28 @@ function billmate_update_address(){
$order->set_address($shipping_address, 'shipping');
}
}

WC()->customer->set_billing_country( $billing_address['country'] );
WC()->customer->set_shipping_country( $shipping_address['country'] );
WC()->customer->set_billing_postcode( $billing_address['postcode'] );
WC()->customer->set_shipping_postcode( $shipping_address['postcode'] );
WC()->customer->set_billing_city( $billing_address['city'] );
WC()->customer->set_shipping_city( $shipping_address['city'] );
WC()->customer->set_billing_address_1( $billing_address['address_1'] );
WC()->customer->set_shipping_address_1( $shipping_address['address_1'] );
WC()->customer->set_billing_address( $billing_address['address_1'] );
WC()->customer->set_shipping_address( $shipping_address['address_1'] );
WC()->customer->save();

$chosen_shipping = WC()->session->get('billmate_checkout_saved_shipping_method');
WC()->shipping->reset_shipping();
WC()->session->set('chosen_shipping_methods', array( $chosen_shipping ) );
WC()->session->set('billmate_checkout_billing_country', $billing_address['country']);
WC()->session->set('billmate_checkout_billing_postcode', $billing_address['postcode']);
WC()->session->set('billmate_checkout_shipping_country', $shipping_address['country']);
WC()->session->set('billmate_checkout_billing_postcode', $billing_address['postcode']);
WC()->session->set('billmate_checkout_shipping_postcode', $shipping_address['postcode']);

WC()->session->set('billmate_checkout_billing_city', $billing_address['city']);
WC()->session->set('billmate_checkout_shipping_city', $shipping_address['city']);
WC()->session->set('billmate_checkout_billing_address_1', $billing_address['address_1']);
WC()->session->set('billmate_checkout_shipping_address_1', $shipping_address['address_1']);

WC()->cart->calculate_shipping();
WC()->cart->calculate_fees();
Expand All @@ -537,11 +547,13 @@ function billmate_update_address(){
}

} else {
$cart = do_shortcode('[woocommerce_cart]');
$current_order_total = (int)WC_Payment_Gateway::get_order_total();
wp_send_json_success(array('update_checkout' => false, "order_total" => $current_order_total));
wp_send_json_success(array('update_checkout' => false, "order_total" => $current_order_total, 'cart' => $cart));
}
$cart = do_shortcode('[woocommerce_cart]');
$current_order_total = (int)WC_Payment_Gateway::get_order_total();
wp_send_json_success(array('update_checkout' => false, "order_total" => $current_order_total));
wp_send_json_success(array('update_checkout' => false, "order_total" => $current_order_total, 'cart' => $cart));
}

}
Expand Down Expand Up @@ -888,6 +900,7 @@ function get_url(){
$current_order_total = (int)WC_Payment_Gateway::get_order_total();
if ($previous_order_total != $current_order_total) {
$this->updateCheckoutFromOrderId( $orderId );

}

$checkout = $billmate->getCheckout(array('PaymentData' => array('hash' => WC()->session->get( 'billmate_checkout_hash' ))));
Expand Down Expand Up @@ -1020,6 +1033,12 @@ public function updateCheckoutFromOrderId( $orderId = null )
'number' => $checkoutOrderNumber
);
WC()->session->set('billmate_previous_calculated_order_total', WC_Payment_Gateway::get_order_total());
if (count(debug_backtrace()) < 25) {
do_action('billmate_checkout_save_shipping_method');
}
else {
WC()->session->set('billmate_update_cart_timestamp', time());
}
return $billmate->updateCheckout($orderValues);
}
return array();
Expand All @@ -1030,7 +1049,7 @@ function initCheckout($orderId = null){

$billmate = $this->getBillmateConnection();
$result = $billmate->initCheckout($orderValues);

do_action('billmate_checkout_save_shipping_method');
// Save checkout hash
if(!isset($result['code']) AND isset($result['url']) AND $result['url'] != "") {
$url = $result['url'];
Expand Down Expand Up @@ -1131,7 +1150,7 @@ public function updateCheckout($result, $order)

WC()->session->set('billmate_previous_calculated_order_total', WC_Payment_Gateway::get_order_total());
$data = $billmate->updateCheckout($orderValues);

do_action('billmate_checkout_save_shipping_method');
if(!isset($data['code'])){
$current_order_total = (int)WC_Payment_Gateway::get_order_total();
if($previousTotal != $orderValues['Cart']['Total']['withtax']){
Expand Down
18 changes: 18 additions & 0 deletions woocommerce-gateway-billmate/commonfunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@
if (!function_exists('is_plugin_active')) {
require_once(ABSPATH.'wp-admin/includes/plugin.php');
}
add_action('billmate_checkout_save_shipping_method', 'updateshipping');
add_action('woocommerce_proceed_to_checkout', 'updatecartshipping');

function updatecartshipping() {
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping = $chosen_methods[0];
if ($chosen_shipping !== null && is_cart() && (time() - WC()->session->get( 'billmate_update_cart_timestamp') > 5)) {
WC()->session->set('billmate_checkout_saved_shipping_method', $chosen_shipping);
}
}

function updateshipping() {
$chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
$chosen_shipping = $chosen_methods[0];
if ($chosen_shipping !== null) {
WC()->session->set('billmate_checkout_saved_shipping_method', $chosen_shipping);
}
}

function convertToUTF8($str) {
$enc = mb_detect_encoding($str);
Expand Down
3 changes: 3 additions & 0 deletions woocommerce-gateway-billmate/js/billmatecheckout.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ var BillmateIframe = new function(){
} else {
self.hideCheckoutLoading();
}
if (response.data.hasOwnProperty('cart')){
document.getElementsByClassName("woocommerce")[0].innerHTML = response.data.cart;
}
}
});

Expand Down