Skip to content

Commit

Permalink
Merge branch 'dev-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
mason authored and mason committed Apr 12, 2022
2 parents cb32c1c + 5a30e2b commit fcdefef
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
3 changes: 3 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ View our full installation guide: <https://docs.paymentwall.com/modules/woocomme

== Changelog ==

= v1.9.0 [04/12/2022] =
* Support Woocommerce Shipment Tracking for Delivery Confirmation API

= v1.8.1 [04/07/2022] =
* Fix duplicated charge for Brick 1.6

Expand Down
4 changes: 2 additions & 2 deletions src/includes/class-paymentwall-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ function prepare_delivery_confirmation_data($orderId, $deliveryStatus = '', $tra
'shipping_address[lastname]' => !empty($shippingAddress['last_name']) ? $shippingAddress['last_name'] : $billingAddress['last_name'],
'shipping_address[country]' => !empty($shippingAddress['country']) ? $shippingAddress['country'] : $billingAddress['country'],
'shipping_address[street]' => !empty($shippingAddress['address_1']) ? $shippingAddress['address_1'] : $billingAddress['address_1'],
'shipping_address[state]' => !empty($shippingAddress['state']) ? $shippingAddress['state'] : !empty($billingAddress['state'])? $billingAddress['state'] : 'N/A',
'shipping_address[zip]' => !empty($shippingAddress['postcode']) ? $shippingAddress['postcode'] : !empty($billingAddress['postcode']) ? $billingAddress['postcode'] : 'N/A' ,
'shipping_address[state]' => !empty($shippingAddress['state']) ? $shippingAddress['state'] : (!empty($billingAddress['state']) ? $billingAddress['state'] : 'N/A'),
'shipping_address[zip]' => !empty($shippingAddress['postcode']) ? $shippingAddress['postcode'] : (!empty($billingAddress['postcode']) ? $billingAddress['postcode'] : 'N/A'),
'shipping_address[city]' => !empty($shippingAddress['city']) ? $shippingAddress['city'] : $billingAddress['city'],
'shipping_address[phone]' => !empty($shippingAddress['phone']) ? $shippingAddress['phone'] : $billingAddress['phone'],
'reason' => 'none',
Expand Down
53 changes: 52 additions & 1 deletion src/paymentwall-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Plugin Name: Paymentwall for WooCommerce
* Plugin URI: https://docs.paymentwall.com/modules/woocommerce
* Description: Official Paymentwall module for WordPress WooCommerce.
* Version: 1.8.1
* Version: 1.9.0
* Author: The Paymentwall Team
* Author URI: http://www.paymentwall.com/
* Text Domain: paymentwall-for-woocommerce
Expand Down Expand Up @@ -150,6 +150,57 @@ function start_session() {
}
}

add_action('updated_postmeta', 'pw_on_order_tracking_change', 10, 4);

add_action('added_post_meta', 'pw_on_order_tracking_change', 10, 4);

function pw_on_order_tracking_change($meta_id, $post_id, $meta_key, $meta_value) {
if ($meta_key != '_wc_shipment_tracking_items' || empty($meta_value)) {
return;
}

$tracking_data = $meta_value;

if (!is_array($meta_value)) {
$tracking_data = unserialize($meta_value);
}

if (empty($tracking_data[0])) {
return;
}

$tracking_data_to_send = $tracking_data[0];

$order = wc_get_order($post_id);
if (!$order) {
return;
}

$gateway = wc_get_payment_gateway_by_order($order);
if (is_gateway_valid($gateway)) {
return;
}

pw_update_delivery_status($order, Paymentwall_Api::DELIVERY_STATUS_ORDER_SHIPPED, $tracking_data_to_send);
}

function is_gateway_valid($gateway = null) {
if (empty($gateway) || empty($gateway->id) || $gateway->id != Paymentwall_Gateway::PAYMENTWALL_METHOD) {
return false;
}

return true;
}

function pw_update_delivery_status(WC_Order $order, $status, $tracking_data = null) {
try {
$paymentwallApi = new Paymentwall_Api();
$paymentwallApi->sendDeliveryApi($order->get_id(), $status, $tracking_data);
} catch (\Exception $e) {
return $e->getMessage();
}
}

add_filter('woocommerce_available_payment_gateways', 'addPaymentwallGateway', 99, 2);
function addPaymentwallGateway($availableGateways){

Expand Down

0 comments on commit fcdefef

Please sign in to comment.