Skip to content

Commit

Permalink
Do only exclude certain gateways from supporting pickup location deli…
Browse files Browse the repository at this point in the history
…very from frontend requests. API request improvements.
  • Loading branch information
dennisnissle committed Dec 27, 2024
1 parent c52ec6f commit 1d707f5
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 6 deletions.
4 changes: 4 additions & 0 deletions src/API/Auth/Basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public function auth() {
return true;
}

public function get_url() {
return '';
}

abstract protected function get_username();

abstract protected function get_password();
Expand Down
2 changes: 2 additions & 0 deletions src/API/Auth/OAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public function get_type() {

abstract protected function get_access_token();

abstract public function get_url();

public function get_headers() {
$headers = array();

Expand Down
15 changes: 13 additions & 2 deletions src/API/REST.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ protected function get_auth() {
* @return bool
*/
protected function is_auth_request( $url ) {
return strstr( $url, $this->get_auth()->get_url() );
$auth_url = $this->get_auth()->get_url();

if ( empty( $auth_url ) ) {
return false;
}

return strstr( $url, $auth_url );
}

protected function get_timeout( $request_type = 'GET' ) {
Expand Down Expand Up @@ -68,7 +74,6 @@ protected function maybe_encode_body( $body_args, $content_type = '' ) {
* @return Response
*/
protected function get_response( $url, $type = 'GET', $body_args = array(), $headers = array() ) {
$headers = $this->get_headers( $headers );
$response = false;
$is_auth_request = false;

Expand All @@ -78,6 +83,12 @@ protected function get_response( $url, $type = 'GET', $body_args = array(), $hea
$auth_response = $this->get_auth()->auth();
}

/**
* Need to build-up headers after (potentially) performing the auth request
* to make sure new auth headers are set.
*/
$headers = $this->get_headers( $headers );

if ( 'GET' === $type ) {
$response = wp_remote_get(
esc_url_raw( $url ),
Expand Down
1 change: 0 additions & 1 deletion src/DataStores/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ public function update( &$shipment ) {

// Shipping provider has changed - lets remove existing label
if ( in_array( 'shipping_provider', $changed_props, true ) ) {

if ( $shipment->supports_label() && $shipment->has_label() ) {
$shipment->get_label()->delete();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ private static function get_schema() {
shipment_date_sent_gmt datetime default NULL,
shipment_est_delivery_date datetime default NULL,
shipment_est_delivery_date_gmt datetime default NULL,
shipment_status varchar(20) NOT NULL default 'gzd-draft',
shipment_status varchar(150) NOT NULL default 'gzd-draft',
shipment_order_id bigint(20) unsigned NOT NULL DEFAULT 0,
shipment_packaging_id bigint(20) unsigned NOT NULL DEFAULT 0,
shipment_parent_id bigint(20) unsigned NOT NULL DEFAULT 0,
Expand Down
10 changes: 8 additions & 2 deletions src/PickupDelivery.php
Original file line number Diff line number Diff line change
Expand Up @@ -716,14 +716,20 @@ public static function register_assets() {
}

public static function get_excluded_gateways() {
$excluded_gateways = array( 'cod' );

if ( ! is_admin() ) {
$excluded_gateways[] = 'amazon_payments_advanced';
}

/**
* Filter to disable pickup delivery for certain gateways.
*
* @param array $gateways Array of gateway IDs to exclude.
*/
$codes = apply_filters( 'woocommerce_gzd_shipments_pickup_delivery_excluded_gateways', array( 'cod', 'amazon_payments_advanced' ) );
$excluded_gateways = apply_filters( 'woocommerce_gzd_shipments_pickup_delivery_excluded_gateways', $excluded_gateways );

return $codes;
return $excluded_gateways;
}

public static function get_pickup_delivery_cart_args() {
Expand Down

0 comments on commit 1d707f5

Please sign in to comment.