mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +08:00
Add my account save payment (WIP)
This commit is contained in:
parent
b07ac130dc
commit
1d74d08b4f
6 changed files with 77 additions and 3 deletions
|
@ -0,0 +1,29 @@
|
|||
import {
|
||||
getCurrentPaymentMethod,
|
||||
ORDER_BUTTON_SELECTOR,
|
||||
PaymentMethods
|
||||
} from "../../../ppcp-button/resources/js/modules/Helper/CheckoutMethodState";
|
||||
|
||||
import {setVisible} from "../../../ppcp-button/resources/js/modules/Helper/Hiding";
|
||||
import {loadPaypalJsScript} from "../../../ppcp-button/resources/js/modules/Helper/ScriptLoading";
|
||||
|
||||
const init = () => {
|
||||
setVisible(ORDER_BUTTON_SELECTOR, getCurrentPaymentMethod() !== PaymentMethods.PAYPAL);
|
||||
setVisible(`#ppc-button-${PaymentMethods.PAYPAL}-save-payment-method`, getCurrentPaymentMethod() === PaymentMethods.PAYPAL);
|
||||
}
|
||||
|
||||
document.addEventListener(
|
||||
'DOMContentLoaded',
|
||||
() => {
|
||||
jQuery(document.body).on('click init_add_payment_method', '.payment_methods input.input-radio', function () {
|
||||
init()
|
||||
});
|
||||
|
||||
loadPaypalJsScript(
|
||||
{},
|
||||
{},
|
||||
`#ppc-button-${PaymentMethods.PAYPAL}-save-payment-method`
|
||||
);
|
||||
}
|
||||
);
|
||||
|
|
@ -13,7 +13,7 @@ use WooCommerce\PayPalCommerce\SavePaymentMethods\Helper\SavePaymentMethodsAppli
|
|||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
|
||||
return array(
|
||||
'save-payment-methods.eligible' => static function ( ContainerInterface $container ): bool {
|
||||
'save-payment-methods.eligible' => static function ( ContainerInterface $container ): bool {
|
||||
$save_payment_methods_applies = $container->get( 'save-payment-methods.helpers.save-payment-methods-applies' );
|
||||
assert( $save_payment_methods_applies instanceof SavePaymentMethodsApplies );
|
||||
|
||||
|
@ -41,4 +41,15 @@ return array(
|
|||
)
|
||||
);
|
||||
},
|
||||
'save-payment-methods.module.url' => static function ( ContainerInterface $container ): string {
|
||||
/**
|
||||
* The path cannot be false.
|
||||
*
|
||||
* @psalm-suppress PossiblyFalseArgument
|
||||
*/
|
||||
return plugins_url(
|
||||
'/modules/ppcp-save-payment-methods/',
|
||||
dirname( realpath( __FILE__ ), 3 ) . '/woocommerce-paypal-payments.php'
|
||||
);
|
||||
},
|
||||
);
|
||||
|
|
|
@ -149,5 +149,36 @@ class SavePaymentMethodsModule implements ModuleInterface {
|
|||
10,
|
||||
2
|
||||
);
|
||||
|
||||
add_filter( 'woocommerce_paypal_payments_disable_add_payment_method', '__return_false' );
|
||||
|
||||
add_action(
|
||||
'wp_enqueue_scripts',
|
||||
function() use ( $c ) {
|
||||
if ( ! is_user_logged_in() || ! is_add_payment_method_page() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$module_url = $c->get( 'save-payment-methods.module.url' );
|
||||
wp_enqueue_script(
|
||||
'ppcp-add-payment-method',
|
||||
untrailingslashit( $module_url ) . '/assets/js/add-payment-method.js',
|
||||
array( 'jquery' ),
|
||||
$c->get( 'ppcp.asset-version' ),
|
||||
true
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
add_action(
|
||||
'woocommerce_add_payment_method_form_bottom',
|
||||
function () {
|
||||
if ( ! is_user_logged_in() || ! is_add_payment_method_page() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
echo '<div id="ppc-button-' . PayPalGateway::ID . '-save-payment-method"></div>';
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ module.exports = {
|
|||
target: 'web',
|
||||
plugins: [ new DependencyExtractionWebpackPlugin() ],
|
||||
entry: {
|
||||
'boot': path.resolve('./resources/js/boot.js')
|
||||
'add-payment-method': path.resolve('./resources/js/add-payment-method.js')
|
||||
},
|
||||
output: {
|
||||
path: path.resolve(__dirname, 'assets/'),
|
||||
|
|
|
@ -191,7 +191,10 @@ class VaultingModule implements ModuleInterface {
|
|||
'woocommerce_available_payment_gateways',
|
||||
function( array $methods ): array {
|
||||
global $wp;
|
||||
if ( isset( $wp->query_vars['add-payment-method'] ) ) {
|
||||
if (
|
||||
isset( $wp->query_vars['add-payment-method'] )
|
||||
&& apply_filters( 'woocommerce_paypal_payments_disable_add_payment_method', true )
|
||||
) {
|
||||
unset( $methods[ PayPalGateway::ID ] );
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue