-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hook up payment methods configuration #4091
base: add/settings-synchronization
Are you sure you want to change the base?
Changes from all commits
8d1cfbb
0287e85
1d9f970
158eddb
af8c2ad
b54619a
9ff8be1
08b5e29
5929aa0
af190ae
4a120e0
74cc799
9829c73
3489d66
5e52f8c
77efc8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
if ( ! defined( 'ABSPATH' ) ) { | ||
exit; | ||
} | ||
|
||
/** | ||
* Class WC_Stripe_Payment_Method_Configurations | ||
*/ | ||
class WC_Stripe_Payment_Method_Configurations { | ||
/** | ||
* Get the merchant payment method configuration in Stripe. | ||
* | ||
* @return object|null | ||
*/ | ||
private static function get_primary_configuration() { | ||
$result = WC_Stripe_API::get_instance()->get_payment_method_configurations(); | ||
$payment_method_configurations = $result->data ?? null; | ||
|
||
if ( ! $payment_method_configurations ) { | ||
return null; | ||
} | ||
|
||
foreach ( $payment_method_configurations as $payment_method_configuration ) { | ||
if ( $payment_method_configuration->active && $payment_method_configuration->parent ) { | ||
return $payment_method_configuration; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* Get the UPE enabled payment method IDs. | ||
* | ||
* @return array | ||
*/ | ||
public static function get_upe_enabled_payment_method_ids() { | ||
$enabled_payment_method_ids = []; | ||
$merchant_payment_method_configuration = self::get_primary_configuration(); | ||
|
||
if ( $merchant_payment_method_configuration ) { | ||
foreach ( $merchant_payment_method_configuration as $payment_method_id => $payment_method ) { | ||
if ( is_object( $payment_method ) && | ||
property_exists( $payment_method, 'display_preference' ) && | ||
property_exists( $payment_method->display_preference, 'value' ) ) { | ||
|
||
$payment_method_status = 'on' === $payment_method->display_preference->value; | ||
|
||
if ( $payment_method_status ) { | ||
$enabled_payment_method_ids[] = $payment_method_id; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return $enabled_payment_method_ids; | ||
} | ||
|
||
/** | ||
* Update the payment method configuration. | ||
* | ||
* @param array $enabled_payment_method_ids | ||
* @param array $available_payment_method_ids | ||
*/ | ||
public static function update_payment_method_configuration( $enabled_payment_method_ids, $available_payment_method_ids ) { | ||
$payment_method_configuration = self::get_primary_configuration(); | ||
$updated_payment_method_configuration = []; | ||
|
||
foreach ( $available_payment_method_ids as $stripe_id ) { | ||
$updated_payment_method_configuration[ $stripe_id ] = [ | ||
'display_preference' => [ | ||
'preference' => in_array( $stripe_id, $enabled_payment_method_ids, true ) ? 'on' : 'off', | ||
], | ||
]; | ||
} | ||
|
||
if ( ! $payment_method_configuration ) { | ||
WC_Stripe_Logger::log( 'No primary payment method configuration found while updating payment method configuration' ); | ||
return; | ||
} | ||
|
||
WC_Stripe_API::get_instance()->update_payment_method_configurations( | ||
$payment_method_configuration->id, | ||
$updated_payment_method_configuration | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,8 @@ public static function is_amazon_pay_enabled() { | |
return false; | ||
} | ||
|
||
$upe_enabled_method_ids = WC_Stripe_Helper::get_settings( null, 'upe_checkout_experience_accepted_payments' ); | ||
$wc_stripe_upe_payment_method_amazon_pay = new self(); | ||
$upe_enabled_method_ids = $wc_stripe_upe_payment_method_amazon_pay->get_upe_enabled_payment_method_ids(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about calling the parent method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since |
||
|
||
return is_array( $upe_enabled_method_ids ) && in_array( self::STRIPE_ID, $upe_enabled_method_ids, true ); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this tracking part accidentally removed? Or is it intentionally removed in favor of #3920?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's removed in favor of #3920.