Merge pull request #1958 from woocommerce/PCP-2522-venmo-vaulting-integration

Venmo Vaulting integration (2522)
This commit is contained in:
Emili Castells 2024-01-17 14:50:47 +01:00 committed by GitHub
commit 2bd7d2bf0d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 64 additions and 8 deletions

View file

@ -1256,6 +1256,16 @@ document.querySelector("#payment").before(document.querySelector("#ppcp-messages
'commit' => in_array( $context, $this->pay_now_contexts, true ) ? 'true' : 'false', 'commit' => in_array( $context, $this->pay_now_contexts, true ) ? 'true' : 'false',
'intent' => $intent, 'intent' => $intent,
); );
if (
$this->settings->has( 'subscriptions_mode' )
&& $this->settings->get( 'subscriptions_mode' ) === 'vaulting_api'
&& apply_filters( 'woocommerce_paypal_payments_save_payment_methods_eligible', false )
) {
// Remove vault parameter to allow for Venmo with Save Payment Methods (Vault V3).
unset( $params['vault'] );
}
if ( if (
$this->environment->current_environment_is( Environment::SANDBOX ) $this->environment->current_environment_is( Environment::SANDBOX )
&& defined( 'WP_DEBUG' ) && \WP_DEBUG && defined( 'WP_DEBUG' ) && \WP_DEBUG

View file

@ -106,16 +106,30 @@ class SavePaymentMethodsModule implements ModuleInterface {
} }
if ( $payment_method === PayPalGateway::ID ) { if ( $payment_method === PayPalGateway::ID ) {
$data['payment_source'] = array(
'paypal' => array( if ( $request_data['funding_source'] === 'venmo' ) {
'attributes' => array( $data['payment_source'] = array(
'vault' => array( 'venmo' => array(
'store_in_vault' => 'ON_SUCCESS', 'attributes' => array(
'usage_type' => 'MERCHANT', 'vault' => array(
'store_in_vault' => 'ON_SUCCESS',
'usage_type' => 'MERCHANT',
),
), ),
), ),
), );
); } else {
$data['payment_source'] = array(
'paypal' => array(
'attributes' => array(
'vault' => array(
'store_in_vault' => 'ON_SUCCESS',
'usage_type' => 'MERCHANT',
),
),
),
);
}
} }
return $data; return $data;
@ -329,6 +343,13 @@ class SavePaymentMethodsModule implements ModuleInterface {
$endpoint->handle_request(); $endpoint->handle_request();
} }
); );
add_filter(
'woocommerce_paypal_payments_save_payment_methods_eligible',
function() {
return true;
}
);
} }
/** /**

View file

@ -181,6 +181,31 @@ class WcSubscriptionsModule implements ModuleInterface {
} }
); );
add_filter(
'woocommerce_subscription_payment_method_to_display',
/**
* Corrects the payment method name for subscriptions.
*
* @param string $payment_method_to_display The payment method string.
* @param \WC_Subscription $subscription The subscription instance.
* @param string $context The context, ex: view.
* @return string
*
* @psalm-suppress MissingClosureParamType
*/
function ( $payment_method_to_display, $subscription, $context ) {
$payment_gateway = wc_get_payment_gateway_by_order( $subscription );
if ( $payment_gateway instanceof \WC_Payment_Gateway && $payment_gateway->id === PayPalGateway::ID ) {
return $subscription->get_payment_method_title( $context );
}
return $payment_method_to_display;
},
10,
3
);
add_action( add_action(
'wc_ajax_' . SubscriptionChangePaymentMethod::ENDPOINT, 'wc_ajax_' . SubscriptionChangePaymentMethod::ENDPOINT,
static function () use ( $c ) { static function () use ( $c ) {