Add card payment token for free trial subscriptions (WIP)

This commit is contained in:
Emili Castells Guasch 2024-07-24 16:00:55 +02:00
parent 112b98875b
commit efbd36025d
5 changed files with 134 additions and 6 deletions

View file

@ -426,12 +426,26 @@ class CreditCardGateway extends \WC_Payment_Gateway_CC {
public function process_payment( $order_id ) {
$wc_order = wc_get_order( $order_id );
if ( ! is_a( $wc_order, WC_Order::class ) ) {
WC()->session->set( 'ppcp_card_payment_token_for_free_trial', null );
return $this->handle_payment_failure(
null,
new GatewayGenericException( new Exception( 'WC order was not found.' ) )
);
}
$card_payment_token_for_free_trial = WC()->session->get( 'ppcp_card_payment_token_for_free_trial') ?? null;
WC()->session->set( 'ppcp_card_payment_token_for_free_trial', null );
if($card_payment_token_for_free_trial) {
$tokens = WC_Payment_Tokens::get_customer_tokens( get_current_user_id() );
foreach ( $tokens as $token ) {
if ( $token->get_id() === (int) $card_payment_token_for_free_trial ) {
$wc_order->payment_complete();
return $this->handle_payment_success( $wc_order );
}
}
}
// phpcs:ignore WordPress.Security.NonceVerification.Missing
$card_payment_token_id = wc_clean( wp_unslash( $_POST['wc-ppcp-credit-card-gateway-payment-token'] ?? '' ) );