mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
ApplePay Vaulting Integration
This commit is contained in:
parent
827bd2568d
commit
96b83c9d0d
7 changed files with 86 additions and 12 deletions
|
@ -28,7 +28,8 @@ class PaymentTokenPayPal extends WC_Payment_Token {
|
|||
* @var string[]
|
||||
*/
|
||||
protected $extra_data = array(
|
||||
'email' => '',
|
||||
'email' => '',
|
||||
'payment_source' => '',
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -48,4 +49,22 @@ class PaymentTokenPayPal extends WC_Payment_Token {
|
|||
public function set_email( $email ) {
|
||||
$this->add_meta_data( 'email', $email, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the payment source.
|
||||
*
|
||||
* @return string The payment source.
|
||||
*/
|
||||
public function get_payment_source() {
|
||||
return $this->get_meta( 'payment_source' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the payment source.
|
||||
*
|
||||
* @param string $payment_source The payment source.
|
||||
*/
|
||||
public function set_payment_source( string $payment_source ) {
|
||||
$this->add_meta_data( 'payment_source', $payment_source, true );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,6 +86,37 @@ class VaultingModule implements ModuleInterface {
|
|||
}
|
||||
);
|
||||
|
||||
add_filter(
|
||||
'woocommerce_get_customer_payment_tokens',
|
||||
/**
|
||||
* Filter available payment tokens depending on context.
|
||||
*
|
||||
* @psalm-suppress MissingClosureParamType
|
||||
* @psalm-suppress MissingClosureReturnType
|
||||
*/
|
||||
function( $tokens, $customer_id, $gateway_id ) {
|
||||
if ( ! is_array( $tokens ) ) {
|
||||
return $tokens;
|
||||
}
|
||||
|
||||
// Exclude ApplePay tokens from payment pages.
|
||||
if ( is_checkout() || is_cart() || is_product() ) {
|
||||
foreach ( $tokens as $index => $token ) {
|
||||
if (
|
||||
$token instanceof PaymentTokenPayPal
|
||||
&& $token->get_payment_source() === 'apple_pay'
|
||||
) {
|
||||
unset( $tokens[ $index ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $tokens;
|
||||
},
|
||||
10,
|
||||
3
|
||||
);
|
||||
|
||||
add_filter(
|
||||
'woocommerce_payment_methods_list_item',
|
||||
/**
|
||||
|
@ -100,8 +131,22 @@ class VaultingModule implements ModuleInterface {
|
|||
|
||||
if ( strtolower( $payment_token->get_type() ) === 'paypal' ) {
|
||||
assert( $payment_token instanceof PaymentTokenPayPal );
|
||||
$item['method']['brand'] = $payment_token->get_email();
|
||||
|
||||
$email = $payment_token->get_email();
|
||||
$payment_source = $payment_token->get_payment_source();
|
||||
$brand_parts = array();
|
||||
|
||||
if ( $payment_source !== 'paypal' ) {
|
||||
$brand_parts[] = ucwords( $payment_source );
|
||||
}
|
||||
|
||||
if ( $email ) {
|
||||
$brand_parts[] = $email;
|
||||
} else {
|
||||
$brand_parts[] = '#' . ( (string) $payment_token->get_id() );
|
||||
}
|
||||
|
||||
$item['method']['brand'] = implode( ' / ', array_filter( $brand_parts ) );
|
||||
return $item;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue