Add change subscription payment for vault v3

This commit is contained in:
Emili Castells Guasch 2024-01-08 11:38:00 +01:00
parent 09d6ccc92d
commit 16eebecc5a
2 changed files with 14 additions and 11 deletions

View file

@ -400,18 +400,25 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
* If customer is changing subscription payment.
*/
if (
// phpcs:ignore WordPress.Security.NonceVerification.Missing
// phpcs:disable WordPress.Security.NonceVerification.Missing
isset( $_POST['woocommerce_change_payment'] )
&& $this->subscription_helper->has_subscription( $wc_order->get_id() )
&& $this->subscription_helper->is_subscription_change_payment()
&& $saved_credit_card
) {
$payment_token = WC_Payment_Tokens::get($saved_credit_card);
if($payment_token) {
$wc_order->add_payment_token($payment_token);
$wc_order->save();
$saved_credit_card = wc_clean( wp_unslash( $_POST['wc-ppcp-credit-card-gateway-payment-token'] ?? '' ) );
if ( ! $saved_credit_card ) {
$saved_credit_card = wc_clean( wp_unslash( $_POST['saved_credit_card'] ?? '' ) );
// phpcs:enable WordPress.Security.NonceVerification.Missing
}
return $this->handle_payment_success( $wc_order );
if ( $saved_credit_card ) {
$payment_token = WC_Payment_Tokens::get( $saved_credit_card );
if ( $payment_token ) {
$wc_order->add_payment_token( $payment_token );
$wc_order->save();
return $this->handle_payment_success( $wc_order );
}
}
wc_add_notice( __( 'Could not change payment.', 'woocommerce-paypal-payments' ), 'error' );

View file

@ -117,10 +117,6 @@ class WcSubscriptionsModule implements ModuleInterface {
* @psalm-suppress MissingClosureParamType
*/
function ( $description, $id ) use ( $c ) {
if ( $c->has( 'save-payment-methods.eligible' ) && $c->get( 'save-payment-methods.eligible' ) ) {
return $description;
}
$payment_token_repository = $c->get( 'vaulting.repository.payment-token' );
$settings = $c->get( 'wcgateway.settings' );
$subscription_helper = $c->get( 'wc-subscriptions.helper' );