Skip to content

Commit

Permalink
New Settings UI: Add modules feature state to merchant data
Browse files Browse the repository at this point in the history
  • Loading branch information
hmouhtar committed Dec 16, 2024
1 parent e5159ec commit 828a8e0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
20 changes: 20 additions & 0 deletions modules/ppcp-applepay/src/ApplepayModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,26 @@ function( array $locations, string $setting_name ): array {
2
);

add_filter(
'woocommerce_paypal_payments_rest_common_merchant_data',
function( array $merchant_data ) use ( $c ): array {
if ( ! isset( $merchant_data['features'] ) ) {
$merchant_data['features'] = array();
}

$product_status = $c->get( 'applepay.apple-product-status' );
assert( $product_status instanceof AppleProductStatus );

$apple_pay_enabled = $product_status->is_active();

$merchant_data['features']['apple_pay'] = array(
'enabled' => $apple_pay_enabled,
);

return $merchant_data;
}
);

return true;
}

Expand Down
28 changes: 28 additions & 0 deletions modules/ppcp-wc-gateway/src/WCGatewayModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Psr\Log\LoggerInterface;
use Throwable;
use WooCommerce\PayPalCommerce\AdminNotices\Entity\Message;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\BillingAgreementsEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\Orders;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Authorization;
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
Expand Down Expand Up @@ -547,6 +548,33 @@ function( string $installed_plugin_version ) use ( $c ) {
}
);

add_filter(
'woocommerce_paypal_payments_rest_common_merchant_data',
function( array $merchant_data ) use ( $c ): array {
if ( ! isset( $merchant_data['features'] ) ) {
$merchant_data['features'] = array();
}

$billing_agreements_endpoint = $c->get( 'api.endpoint.billing-agreements' );
assert( $billing_agreements_endpoint instanceof BillingAgreementsEndpoint );

$reference_transactions_enabled = $billing_agreements_endpoint->reference_transaction_enabled();
$merchant_data['features']['save_paypal_and_venmo'] = array(
'enabled' => $reference_transactions_enabled,
);

$dcc_product_status = $c->get( 'wcgateway.helper.dcc-product-status' );
assert( $dcc_product_status instanceof DCCProductStatus );

$dcc_enabled = $dcc_product_status->dcc_is_active();
$merchant_data['features']['advanced_credit_and_debit_cards'] = array(
'enabled' => $dcc_enabled,
);

return $merchant_data;
}
);

return true;
}

Expand Down

0 comments on commit 828a8e0

Please sign in to comment.