Handle card smart button for free trial (1$ auth + void)

Disabling this funding source also disables DCC
This commit is contained in:
Alex P 2022-04-25 15:24:37 +03:00
parent a5191b04ff
commit 4a4f131325
13 changed files with 74 additions and 5 deletions

View file

@ -37,6 +37,7 @@ class PayPalGateway extends \WC_Payment_Gateway {
const INTENT_META_KEY = '_ppcp_paypal_intent';
const ORDER_ID_META_KEY = '_ppcp_paypal_order_id';
const ORDER_PAYMENT_MODE_META_KEY = '_ppcp_paypal_payment_mode';
const ORDER_PAYMENT_SOURCE = '_ppcp_paypal_payment_source';
const FEES_META_KEY = '_ppcp_paypal_fees';
/**

View file

@ -55,6 +55,7 @@ trait ProcessPaymentTrait {
}
$payment_method = filter_input( INPUT_POST, 'payment_method', FILTER_SANITIZE_STRING );
$funding_source = filter_input( INPUT_POST, 'ppcp-funding-source', FILTER_SANITIZE_STRING );
/**
* If customer has chosen a saved credit card payment.
@ -135,7 +136,7 @@ trait ProcessPaymentTrait {
}
}
if ( PayPalGateway::ID === $payment_method && $this->is_free_trial_order( $wc_order ) ) {
if ( PayPalGateway::ID === $payment_method && 'card' !== $funding_source && $this->is_free_trial_order( $wc_order ) ) {
$user_id = (int) $wc_order->get_customer_id();
$tokens = $this->payment_token_repository->all_for_user_id( $user_id );
if ( ! array_filter(

View file

@ -37,5 +37,29 @@ trait OrderMetaTrait {
PayPalGateway::ORDER_PAYMENT_MODE_META_KEY,
$environment->current_environment_is( Environment::SANDBOX ) ? 'sandbox' : 'live'
);
$payment_source = $this->get_payment_source( $order );
if ( $payment_source ) {
$wc_order->update_meta_data( PayPalGateway::ORDER_PAYMENT_SOURCE, $payment_source );
}
}
/**
* Returns the payment source type or null,
*
* @param Order $order The PayPal order.
* @return string|null
*/
private function get_payment_source( Order $order ): ?string {
$source = $order->payment_source();
if ( $source ) {
if ( $source->card() ) {
return 'card';
}
if ( $source->wallet() ) {
return 'wallet';
}
}
return null;
}
}