JFIF $ d d 7 * Z qn )ZP 0 !1 A "#a$2Qr D8 a Ri [f \m I ykI w0 c u F c Rı?lO7 к _f˓ [C $殷WF< _W ԣ s Kc ëI zyQy /_LK ℂ ;C",p F A : /] =H ~ , l s / 9 ć: [=/#f ; ) x { ٛE Q )~ = 𘙲r*2~ a _V = ' ku m F D } KYYC )( { * g& f `툪 r y ` = ^ c J. I ]( * `wq 1dđ #̩ ͑ 0 ; H ] u 搂 @:~ ו K L N s h } O I R* 8 :2 ! lD JV o ( 3 = M ( z Ȱ+i *N A r6K n S l ) ! J J Ӂ* % ݉?|D } d5: eP0 R; {$X' x F @ .ÊB {,WJ uQ ɲRI ;9 Q E琯 6 2fT .DU J ;*c P A\IL Nj! J ۱+ O\ ͔ ] ޒ S J ȧ c%A N ol ՎprU L Zԛe r E2= X D Xg VQeӓ k y P7 U* o m Q I s ,K `) 6\G3t?pgjr m ۛجw luGt f h 9uyP 0D;Uڽ"OXl i f $ ) &|ML 0 Z rm1 [ H XP l P R0 'G=i 2N +0 e 2 ]] 9 VT P O 7 h(F * 癈 ' = Q VZD F,d ߬ ~ T X G[ `le 69C R(!S2! P < 0 x < !1AQ "Raq 02Br #S CTb ? Ζ "]mH5WR 7 k.ۛ ! } Q~ + yԏ z |@ T20 S~ K e k *zF f^2X *( @ 8 r ? C I uI|֓>^Ex LgNU Y+{.R Ѫ τV YT D I 6 2 '8Y2 7'\T P.6 d &˦ @V q i |8 -O Ε ] ʔ U= T L 8= ;6c | !qfF3 a ů& ~$ l} 'NW U s$U k^S V : U#6w + +s &r+n ڐ { @ 29gL u " T Ù M=6 (^ "7 r}=6Yݾ lC u hquymp Ǧ G jhs ǜNl ɻ} o 7 #S6 a w 4 ! OS r D 5 7 % | ?x> L | / nD 6?/8 w # [ ) L 7 +6〼T A T g ! %5 Mm Z /c -{1_Je "| ^$ 'O & ޱմ < H vNqϡQ$ < 6 &Nݛ ֨tǻN (9 n ru~'όN sMG& ,uH Kw *Ī 5@ u6 BԒ i YN * f 0 _ GhKW u lT <nj- 0{ M L~ | /a v\ E = ?1 \ɟuq Ђ Y O a K ޡP q $ H8o Q˼EV ~ k 0 h' L Pp M -M" m^ !6l nմ 쮝C U T . ! :vMǨb h ډ Vc r @~p # !1QAa q ? AL0L x LU 4 d ; x " 16ad0 7.\ߋ 0 = P l v/ " c A Ay A|2pO8"d MV #1] = \ " ˡ ] k v I9 d ۓ & q ) ǐq E ꞅ v "P )q X &Q З non]я u ג./ ; gZ$ M QР 2M ]h ni 0 P $ێ 3CɏGjώy : m c # S_ l@ '_ \m|C 2`K _ 1 cIvGc $? PCQ S+D ? K aײ k Fr b 8 ύ NEدg ĝ U 3 6 #Ik+ v { v i ( ވ ? a e) X xy/*@Q Ǽ Ծ ) $ IWO l c G; !i k{ gOŀ L ('x T rb $ w) R $ & N1E td U3Uȉ1p M"N* (DNy d96.(jQ) X 5 c QɎMy W ? Q *!R > 6=7)Xj 5`J ] e 8%t ! + ' ! 1Q 5 !1 AQaq ё #2 "0BRb ? G t^ ## .l lQ T $ v , ,m 㵜5u bV =sY+ @d { N ! dn O < .- B; _w J t 6;Q Jd. Q c%p{ 1 ,sND dF H I0 Гo X ш e黅X ۢ F :)[ F G X ƹ / w _c MeD ,ʡc c . W D tA $ j@ : ) - #u c1< @ۗ9F ) KJ- hpP] _ x [ q B lb p ʖ w q " LFGd ƶ * s +ډ_Zc " ? % t[I P 6 J ]# =ɺ V v v CGs Gh1 > )6 |e y ? L ӣ m,4 G W Ui ` ] uJVo VDG< SB 6ϏQ @ TiU l y O U 0 kfV ~ ~}S Z @ *WU Ui ## ; s /[ = ! 7}" W N ] ' (L ! ~ y5 g9T̅J kbM' +s :S +B) v @ M j e C f j E 0 Y\Qn z G 1 д~ W o{T 9?` Rm yhsy3 !HAD ] m c1 ~ 2 L S u7x T ;j$ `} 4-> L# vzŏ I L S ֭ T { r jGK C ; b pU= - ` Bs K. S F w4 M q] Z dH S 0 ) tLg
<?php
namespace WPForms\Integrations\PayPalCommerce\PaymentMethods\ApplePay;
use WPForms\Integrations\PayPalCommerce\Frontend\PaymentMethodAssetsInterface;
use WPForms\Integrations\PayPalCommerce\Frontend\PaymentMethodInterface;
use WPForms\Integrations\PayPalCommerce\PaymentMethods\ColorMapInterface;
/**
* Handles the frontend functionalities of the PayPal Commerce integration.
*
* @since 1.10.0
*/
class PaymentMethod implements PaymentMethodInterface, PaymentMethodAssetsInterface {
/**
* Represents the SDK handle for PayPal Commerce Apple Pay integration.
* This constant is used to identify the SDK within the system.
*
* @since 1.10.0
*/
private const SDK_HANDLE = 'wpforms-paypal-commerce-apple-pay-sdk';
/**
* List of disallowed user agents for Apple Pay.
*
* @since 1.10.0
*/
private const DISALLOWED_USER_AGENTS = [
'Chrome/',
'CriOS/',
'Firefox/',
'OPR/',
'Edg/',
];
/**
* List of allowed browsers for Apple Pay.
*
* @since 1.10.0
*/
private const ALLOWED_USER_BROWSERS = [ 'Safari' ];
/**
* List of allowed devices for Apple Pay.
*
* @since 1.10.0
*/
private const ALLOWED_USER_DEVICES = [ 'Macintosh', 'iPhone', 'iPad', 'iPod' ];
/**
* Color mapper instance for handling button and logo color mappings.
*
* @since 1.10.0
*
* @var ColorMapInterface
*/
private $color_map;
/**
* Constructor.
*
* @since 1.10.0
*
* @param ColorMapInterface $color_map An instance of ColorMapInterface to be set.
*/
public function __construct( ColorMapInterface $color_map ) {
$this->color_map = $color_map;
}
/**
* Checks if the given payment method is supported.
*
* @since 1.10.0
*
* @param array $field The field to be checked for support.
*
* @return bool True if the payment method is supported, false otherwise.
*/
public function is_supported( array $field ): bool {
return ! empty( $field['paypal_checkout'] );
}
/**
* Retrieves the list of components for the integration.
*
* @since 1.10.0
*
* @param bool $is_single Whether to consider One-Time Payment or Recurring. Defaults to One-Time.
*
* @return array List of components.
*/
public function get_components( bool $is_single = true ): array {
return $is_single ? [ 'applepay' ] : [];
}
/**
* Retrieves a list of script handles to be loaded asynchronously.
*
* @since 1.10.0
*
* @return array List of asynchronous script handles.
*/
public function get_async_scripts(): array {
return [
self::SDK_HANDLE,
];
}
/**
* Enqueues the necessary assets for the Apple Pay integration
* within the PayPal Commerce functionality.
*
* @since 1.10.0
*
* @param array $payment_types Array of payment type flags (e.g., ['single' => bool, 'recurring' => bool]).
*/
public function enqueue( array $payment_types ): void {
$has_single = ! empty( $payment_types['single'] );
if ( ! $has_single ) {
return;
}
$min = wpforms_get_min_suffix();
// Load Apple Pay (extends PaymentHandler).
wp_enqueue_script(
'wpforms-paypal-commerce-applepay',
WPFORMS_PLUGIN_URL . "assets/js/integrations/paypal-commerce/payment-methods/applepay{$min}.js",
[ 'wpforms-paypal-commerce', 'wpforms-paypal-commerce-payment-method' ],
WPFORMS_VERSION,
true
);
// Load Apple Pay SDK for Apple Pay button integration.
// phpcs:disable WordPress.WP.EnqueuedResourceParameters.MissingVersion
wp_enqueue_script(
self::SDK_HANDLE,
'https://applepay.cdn-apple.com/jsapi/1.latest/apple-pay-sdk.js',
[],
null,
false
);
// phpcs:enable WordPress.WP.EnqueuedResourceParameters.MissingVersion
}
/**
* Retrieves localized settings for a given field.
*
* @since 1.10.0
*
* @param array $field Field configuration array.
* @param array $form Form configuration array.
*
* @return array Localized settings.
*/
public function get_localized_settings( array $field, array $form ): array {
$color = $this->color_map->get_button_color( $field['color'] );
return [
'applepay' => [
'buttonColor' => $color === 'white' ? 'white-outline' : $color,
],
];
}
/**
* Checks if the current user agent is supported for Apple Pay.
*
* Apple Pay is only supported on Safari browser running on Apple devices.
*
* @since 1.10.0
*
* @return bool True if a user agent is supported, false otherwise.
*/
public static function is_user_agent_supported(): bool {
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
$user_agent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) : '';
if ( empty( $user_agent ) || self::is_disallowed_user_agent( $user_agent ) ) {
return false;
}
return self::is_browser_allowed( $user_agent ) && self::is_device_allowed( $user_agent );
}
/**
* Checks if the user agent is in the disallowed list.
*
* @since 1.10.0
*
* @param string $user_agent The user agent string to check.
*
* @return bool True if a user agent is disallowed, false otherwise.
*/
private static function is_disallowed_user_agent( string $user_agent ): bool {
foreach ( self::DISALLOWED_USER_AGENTS as $disallowed_agent ) {
if ( strpos( $user_agent, $disallowed_agent ) !== false ) {
return true;
}
}
return false;
}
/**
* Checks if the browser is allowed for Apple Pay.
*
* @since 1.10.0
*
* @param string $user_agent The user agent string to check.
*
* @return bool True if a browser is allowed, false otherwise.
*/
private static function is_browser_allowed( string $user_agent ): bool {
foreach ( self::ALLOWED_USER_BROWSERS as $allowed_browser ) {
if ( strpos( $user_agent, $allowed_browser ) !== false ) {
return true;
}
}
return false;
}
/**
* Checks if the device is allowed for Apple Pay.
*
* @since 1.10.0
*
* @param string $user_agent The user agent string to check.
*
* @return bool True if a device is allowed, false otherwise.
*/
private static function is_device_allowed( string $user_agent ): bool {
foreach ( self::ALLOWED_USER_DEVICES as $allowed_device ) {
if ( strpos( $user_agent, $allowed_device ) !== false ) {
return true;
}
}
return false;
}
}