This commit is contained in:
carmenmaymo 2023-09-08 16:58:32 +02:00
parent 9139c54cec
commit c05041eee1
No known key found for this signature in database
GPG key ID: 6023F686B0F3102E
9 changed files with 503 additions and 401 deletions

View file

@ -63,7 +63,7 @@ return array(
$container->get( 'applepay.url' ), $container->get( 'applepay.url' ),
$container->get( 'ppcp.asset-version' ), $container->get( 'ppcp.asset-version' ),
$container->get( 'applepay.data_to_scripts' ), $container->get( 'applepay.data_to_scripts' ),
$container->get( 'wcgateway.settings.status' ), $container->get( 'wcgateway.settings.status' )
); );
}, },
'applepay.blocks-payment-method' => static function ( ContainerInterface $container ): PaymentMethodTypeInterface { 'applepay.blocks-payment-method' => static function ( ContainerInterface $container ): PaymentMethodTypeInterface {

View file

@ -11,6 +11,7 @@ namespace WooCommerce\PayPalCommerce\Applepay;
use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry; use Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry;
use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache; use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache;
use WooCommerce\PayPalCommerce\Applepay\Assets\ApplePayButton;
use WooCommerce\PayPalCommerce\Applepay\Assets\AppleProductStatus; use WooCommerce\PayPalCommerce\Applepay\Assets\AppleProductStatus;
use WooCommerce\PayPalCommerce\Button\Assets\ButtonInterface; use WooCommerce\PayPalCommerce\Button\Assets\ButtonInterface;
use WooCommerce\PayPalCommerce\Onboarding\Environment; use WooCommerce\PayPalCommerce\Onboarding\Environment;
@ -18,6 +19,7 @@ use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface; use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;
use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface; use WooCommerce\PayPalCommerce\Vendor\Interop\Container\ServiceProviderInterface;
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface; use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
/** /**
* Class ApplepayModule * Class ApplepayModule
@ -86,7 +88,7 @@ class ApplepayModule implements ModuleInterface {
$this->load_assets( $c ); $this->load_assets( $c );
$this->handle_validation_file( $c ); $this->handle_validation_file( $c );
$this->render_buttons( $c ); $this->render_buttons( $c );
assert( $apple_payment_method instanceof ButtonInterface ); assert( $apple_payment_method instanceof ApplepayButton );
$apple_payment_method->bootstrap_ajax_request(); $apple_payment_method->bootstrap_ajax_request();
add_action( add_action(
'woocommerce_blocks_payment_method_type_registration', 'woocommerce_blocks_payment_method_type_registration',
@ -110,8 +112,9 @@ class ApplepayModule implements ModuleInterface {
* Loads the validation string. * Loads the validation string.
* *
* @param boolean $is_sandbox The environment for this merchant. * @param boolean $is_sandbox The environment for this merchant.
* @param Settings $settings The settings.
*/ */
protected function load_domain_association_file(bool $is_sandbox, $settings ): void { protected function load_domain_association_file( bool $is_sandbox, Settings $settings ): void {
if ( ! isset( $_SERVER['REQUEST_URI'] ) ) { if ( ! isset( $_SERVER['REQUEST_URI'] ) ) {
return; return;
} }
@ -139,8 +142,7 @@ class ApplepayModule implements ModuleInterface {
'wp_enqueue_scripts', 'wp_enqueue_scripts',
function () use ( $c ) { function () use ( $c ) {
$button = $c->get( 'applepay.button' ); $button = $c->get( 'applepay.button' );
assert( $button instanceof ButtonInterface ); assert( $button instanceof ApplePayButton );
if ( $button->should_load_script() ) { if ( $button->should_load_script() ) {
$button->enqueue(); $button->enqueue();
} }
@ -174,11 +176,13 @@ class ApplepayModule implements ModuleInterface {
} }
/** /**
* @param ContainerInterface $c * Removes the status cache.
*
* @param ContainerInterface $c The container.
*
* @return void * @return void
*/ */
public function remove_status_cache(ContainerInterface $c): void public function remove_status_cache( ContainerInterface $c ): void {
{
add_action( add_action(
'woocommerce_paypal_payments_gateway_migrate_on_update', 'woocommerce_paypal_payments_gateway_migrate_on_update',
static function () use ( $c ) { static function () use ( $c ) {
@ -210,11 +214,12 @@ class ApplepayModule implements ModuleInterface {
} }
/** /**
* @param ContainerInterface $c * Handles the validation file.
*
* @param ContainerInterface $c The container.
* @return void * @return void
*/ */
public function handle_validation_file(ContainerInterface $c): void public function handle_validation_file( ContainerInterface $c ): void {
{
$env = $c->get( 'onboarding.environment' ); $env = $c->get( 'onboarding.environment' );
assert( $env instanceof Environment ); assert( $env instanceof Environment );
$is_sandobx = $env->current_environment_is( Environment::SANDBOX ); $is_sandobx = $env->current_environment_is( Environment::SANDBOX );

View file

@ -45,12 +45,16 @@ class ApplePayButton implements ButtonInterface {
*/ */
private $logger; private $logger;
/** /**
* The response templates.
*
* @var ResponsesToApple * @var ResponsesToApple
*/ */
private $response_templates; private $response_templates;
/** /**
* @var array The old cart contents. * The old cart contents.
*
* @var array
*/ */
private $old_cart_contents; private $old_cart_contents;
@ -72,16 +76,29 @@ class ApplePayButton implements ButtonInterface {
* @var OrderProcessor * @var OrderProcessor
*/ */
protected $order_processor; protected $order_processor;
/** /**
* @var bool Whether to reload the cart after the order is processed. * Whether to reload the cart after the order is processed.
*
* @var bool
*/ */
protected $reload_cart = false; protected $reload_cart = false;
/**
* The module version.
*
* @var string
*/
private $version; private $version;
/** /**
* The module URL.
*
* @var string * @var string
*/ */
private $module_url; private $module_url;
/** /**
* The data to send to the ApplePay button script.
*
* @var DataToAppleButtonScripts * @var DataToAppleButtonScripts
*/ */
private $script_data; private $script_data;
@ -98,6 +115,10 @@ class ApplePayButton implements ButtonInterface {
* @param Settings $settings The settings. * @param Settings $settings The settings.
* @param LoggerInterface $logger The logger. * @param LoggerInterface $logger The logger.
* @param OrderProcessor $order_processor The Order processor. * @param OrderProcessor $order_processor The Order processor.
* @param string $module_url The module URL.
* @param string $version The module version.
* @param DataToAppleButtonScripts $data The data to send to the ApplePay button script.
* @param SettingsStatus $settings_status The settings status helper.
*/ */
public function __construct( public function __construct(
Settings $settings, Settings $settings,
@ -241,8 +262,7 @@ class ApplePayButton implements ButtonInterface {
* On fail triggers and option that shows an admin notice showing the error * On fail triggers and option that shows an admin notice showing the error
* On success removes such flag * On success removes such flag
*/ */
public function validate() public function validate() {
{
$applepay_request_data_object = $this->applepay_data_object_http(); $applepay_request_data_object = $this->applepay_data_object_http();
if ( ! $this->is_nonce_valid() ) { if ( ! $this->is_nonce_valid() ) {
return; return;
@ -258,7 +278,6 @@ class ApplePayButton implements ButtonInterface {
* It updates the amount paying information if needed * It updates the amount paying information if needed
* On error returns an array of errors to be handled by the script * On error returns an array of errors to be handled by the script
* On success returns the new contact data * On success returns the new contact data
* @throws \Exception
*/ */
public function update_shipping_contact(): void { public function update_shipping_contact(): void {
$applepay_request_data_object = $this->applepay_data_object_http(); $applepay_request_data_object = $this->applepay_data_object_http();
@ -312,7 +331,6 @@ class ApplePayButton implements ButtonInterface {
* It updates the amount paying information if needed * It updates the amount paying information if needed
* On error returns an array of errors to be handled by the script * On error returns an array of errors to be handled by the script
* On success returns the new contact data * On success returns the new contact data
* @throws \Exception
*/ */
public function update_shipping_method(): void { public function update_shipping_method(): void {
$applepay_request_data_object = $this->applepay_data_object_http(); $applepay_request_data_object = $this->applepay_data_object_http();
@ -332,7 +350,8 @@ class ApplePayButton implements ButtonInterface {
* Method to create a WC order from the data received from the ApplePay JS * Method to create a WC order from the data received from the ApplePay JS
* On error returns an array of errors to be handled by the script * On error returns an array of errors to be handled by the script
* On success returns the new order data * On success returns the new order data
* @throws \Exception *
* @throws \Exception When validation fails.
*/ */
public function create_wc_order() { public function create_wc_order() {
// $this->response_after_successful_result(); // $this->response_after_successful_result();
@ -359,12 +378,15 @@ class ApplePayButton implements ButtonInterface {
return; return;
} }
$this->add_addresses_to_order( $applepay_request_data_object ); $this->add_addresses_to_order( $applepay_request_data_object );
//add_action('woocommerce_checkout_order_processed', array($this, 'process_order_as_paid'), 10, 3); // add_action('woocommerce_checkout_order_processed', array($this, 'process_order_as_paid'), 10, 3).
add_filter('woocommerce_payment_successful_result', function (array $result) use ($cart, $cart_item_key) : array { add_filter(
'woocommerce_payment_successful_result',
function ( array $result ) use ( $cart, $cart_item_key ) : array {
$this->clear_current_cart( $cart, $cart_item_key ); $this->clear_current_cart( $cart, $cart_item_key );
$this->reload_cart( $cart ); $this->reload_cart( $cart );
return $result; return $result;
}); }
);
WC()->checkout()->process_checkout(); WC()->checkout()->process_checkout();
} }
@ -413,7 +435,7 @@ class ApplePayButton implements ButtonInterface {
/** /**
* Selector between product detail and cart page calculations * Selector between product detail and cart page calculations
* *
* @param $applepay_request_data_object * @param ApplePayDataObjectHttp $applepay_request_data_object The data object.
* *
* @return array|bool * @return array|bool
*/ */
@ -421,7 +443,7 @@ class ApplePayButton implements ButtonInterface {
$applepay_request_data_object $applepay_request_data_object
) { ) {
$address = empty( $applepay_request_data_object->shipping_address() ) ? $applepay_request_data_object->simplified_contact() : $applepay_request_data_object->shipping_address(); $address = empty( $applepay_request_data_object->shipping_address() ) ? $applepay_request_data_object->simplified_contact() : $applepay_request_data_object->shipping_address();
if ( $applepay_request_data_object->caller_page === 'productDetail' ) { if ( $applepay_request_data_object->caller_page() === 'productDetail' ) {
$cart_item_key = $this->prepare_cart( $applepay_request_data_object ); $cart_item_key = $this->prepare_cart( $applepay_request_data_object );
$cart = WC()->cart; $cart = WC()->cart;
if ( ! assert( $cart instanceof WC_Cart ) ) { if ( ! assert( $cart instanceof WC_Cart ) ) {
@ -436,7 +458,7 @@ class ApplePayButton implements ButtonInterface {
$this->reload_cart( $cart ); $this->reload_cart( $cart );
return $totals; return $totals;
} }
if ( $applepay_request_data_object->caller_page === 'cart' ) { if ( $applepay_request_data_object->caller_page() === 'cart' ) {
return $this->calculate_totals_cart_page( return $this->calculate_totals_cart_page(
$address, $address,
$applepay_request_data_object->shipping_method() $applepay_request_data_object->shipping_method()
@ -451,10 +473,9 @@ class ApplePayButton implements ButtonInterface {
* If no shippingMethodId provided will return the first available shipping * If no shippingMethodId provided will return the first available shipping
* method * method
* *
* @param $product_id * @param WC_Cart $cart The cart.
* @param $product_quantity * @param array $customer_address customer address to use.
* @param $customer_address * @param array|null $shipping_method shipping method to use.
* @param null $shipping_method
*/ */
protected function calculate_totals_single_product( protected function calculate_totals_single_product(
$cart, $cart,
@ -463,7 +484,7 @@ class ApplePayButton implements ButtonInterface {
): array { ): array {
$results = array(); $results = array();
try { try {
// I just care about apple address details // I just care about apple address details.
$shipping_method_id = ''; $shipping_method_id = '';
$shipping_methods_array = array(); $shipping_methods_array = array();
$selected_shipping_method = array(); $selected_shipping_method = array();
@ -476,6 +497,9 @@ class ApplePayButton implements ButtonInterface {
); );
} }
if ( $cart->needs_shipping() ) { if ( $cart->needs_shipping() ) {
if ( ! $shipping_method ) {
return array();
}
list( list(
$shipping_methods_array, $selected_shipping_method $shipping_methods_array, $selected_shipping_method
) = $this->cart_shipping_methods( ) = $this->cart_shipping_methods(
@ -495,6 +519,7 @@ class ApplePayButton implements ButtonInterface {
$shipping_methods_array $shipping_methods_array
); );
} catch ( Exception $exception ) { } catch ( Exception $exception ) {
return array();
} }
return $results; return $results;
} }
@ -503,6 +528,8 @@ class ApplePayButton implements ButtonInterface {
* Sets the customer address with ApplePay details to perform correct * Sets the customer address with ApplePay details to perform correct
* calculations * calculations
* If no parameter passed then it resets the customer to shop details * If no parameter passed then it resets the customer to shop details
*
* @param array $address customer address.
*/ */
protected function customer_address( array $address = array() ) { protected function customer_address( array $address = array() ) {
$base_location = wc_get_base_location(); $base_location = wc_get_base_location();
@ -524,10 +551,10 @@ class ApplePayButton implements ButtonInterface {
/** /**
* Add shipping methods to cart to perform correct calculations * Add shipping methods to cart to perform correct calculations
* *
* @param $cart * @param WC_Cart $cart WC Cart instance.
* @param $customer_address * @param array $customer_address Customer address.
* @param $shipping_method * @param array $shipping_method Shipping method.
* @param $shipping_method_id * @param array $shipping_method_id Shipping method id.
*/ */
protected function cart_shipping_methods( protected function cart_shipping_methods(
$cart, $cart,
@ -573,13 +600,13 @@ class ApplePayButton implements ButtonInterface {
/** /**
* Sets shipping packages for correct calculations * Sets shipping packages for correct calculations
* *
* @param $customer_address * @param array $customer_address ApplePay address details.
* @param $total * @param float $total Total amount of the cart.
* *
* @return mixed|void|null * @return mixed|void|null
*/ */
protected function getShippingPackages( $customer_address, $total ) { protected function getShippingPackages( $customer_address, $total ) {
// Packages array for storing 'carts' // Packages array for storing 'carts'.
$packages = array(); $packages = array();
$packages[0]['contents'] = WC()->cart->cart_contents; $packages[0]['contents'] = WC()->cart->cart_contents;
$packages[0]['contents_cost'] = $total; $packages[0]['contents_cost'] = $total;
@ -597,9 +624,9 @@ class ApplePayButton implements ButtonInterface {
/** /**
* Returns the formatted results of the cart calculations * Returns the formatted results of the cart calculations
* *
* @param $cart * @param WC_Cart $cart WC Cart object.
* @param $selected_shipping_method * @param array $selected_shipping_method Selected shipping method.
* @param $shipping_methods_array * @param array $shipping_methods_array Shipping methods array.
*/ */
protected function cart_calculation_results( protected function cart_calculation_results(
$cart, $cart,
@ -629,11 +656,11 @@ class ApplePayButton implements ButtonInterface {
* If no shippingMethodId provided will return the first available shipping * If no shippingMethodId provided will return the first available shipping
* method * method
* *
* @param $customer_address * @param array $customer_address The customer address.
* @param null $shipping_method * @param array|null $shipping_method The shipping method.
*/ */
protected function calculate_totals_cart_page( protected function calculate_totals_cart_page(
$customer_address = null, array $customer_address,
$shipping_method = null $shipping_method = null
): array { ): array {
@ -644,7 +671,7 @@ class ApplePayButton implements ButtonInterface {
try { try {
$shipping_methods_array = array(); $shipping_methods_array = array();
$selected_shipping_method = array(); $selected_shipping_method = array();
// I just care about apple address details // I just care about apple address details.
$this->customer_address( $customer_address ); $this->customer_address( $customer_address );
$cart = WC()->cart; $cart = WC()->cart;
if ( $shipping_method ) { if ( $shipping_method ) {
@ -655,6 +682,9 @@ class ApplePayButton implements ButtonInterface {
} }
if ( $cart->needs_shipping() ) { if ( $cart->needs_shipping() ) {
if ( ! $shipping_method ) {
return [];
}
list( list(
$shipping_methods_array, $selected_shipping_method $shipping_methods_array, $selected_shipping_method
) = $this->cart_shipping_methods( ) = $this->cart_shipping_methods(
@ -676,6 +706,7 @@ class ApplePayButton implements ButtonInterface {
$this->customer_address(); $this->customer_address();
} catch ( Exception $e ) { } catch ( Exception $e ) {
return array();
} }
return $results; return $results;
@ -684,19 +715,18 @@ class ApplePayButton implements ButtonInterface {
/** /**
* Add address billing and shipping data to order * Add address billing and shipping data to order
* *
* @param ApplePayDataObjectHttp $applepay_request_data_object * @param ApplePayDataObjectHttp $applepay_request_data_object ApplePayDataObjectHttp.
* @param $order
*/ */
protected function add_addresses_to_order( protected function add_addresses_to_order(
ApplePayDataObjectHttp $applepay_request_data_object ApplePayDataObjectHttp $applepay_request_data_object
) { ): void {
add_action( add_action(
'woocommerce_checkout_create_order', 'woocommerce_checkout_create_order',
static function ( $order, $data ) use ( $applepay_request_data_object ) { static function (WC_Order $order, array $data ) use ( $applepay_request_data_object ) {
if ( $applepay_request_data_object->shipping_method() !== null ) { if ( !empty($applepay_request_data_object->shipping_method()) ) {
$billing_address = $applepay_request_data_object->billing_address(); $billing_address = $applepay_request_data_object->billing_address();
$shipping_address = $applepay_request_data_object->shipping_address(); $shipping_address = $applepay_request_data_object->shipping_address();
// apple puts email in shipping_address while we get it from WC's billing_address // apple puts email in shipping_address while we get it from WC's billing_address.
$billing_address['email'] = $shipping_address['email']; $billing_address['email'] = $shipping_address['email'];
$billing_address['phone'] = $shipping_address['phone']; $billing_address['phone'] = $shipping_address['phone'];
@ -712,9 +742,9 @@ class ApplePayButton implements ButtonInterface {
* Empty the cart to use for calculations * Empty the cart to use for calculations
* while saving its contents in a field * while saving its contents in a field
*/ */
protected function save_old_cart() { protected function save_old_cart(): void {
$cart = WC()->cart; $cart = WC()->cart;
if ( $cart->is_empty() || ! assert($cart instanceof WC_Cart)) { if ( $cart->is_empty() ) {
return; return;
} }
$this->old_cart_contents = $cart->get_cart_contents(); $this->old_cart_contents = $cart->get_cart_contents();
@ -725,7 +755,9 @@ class ApplePayButton implements ButtonInterface {
} }
/** /**
* @param WC_Cart $cart * Reloads the previous cart contents
*
* @param WC_Cart $cart The cart to reload.
*/ */
protected function reload_cart( WC_Cart $cart ): void { protected function reload_cart( WC_Cart $cart ): void {
if ( ! $this->reload_cart ) { if ( ! $this->reload_cart ) {
@ -736,64 +768,40 @@ class ApplePayButton implements ButtonInterface {
} }
} }
protected function response_after_successful_result(): void {
add_filter(
'woocommerce_payment_successful_result',
function ( $result, $order_id ) {
if (
isset( $result['result'] )
&& 'success' === $result['result']
) {
$this->response_templates->response_success(
$this->response_templates->authorization_result_response(
'STATUS_SUCCESS',
$order_id
)
);
} else {
wp_send_json_error(
$this->response_templates->authorization_result_response(
'STATUS_FAILURE',
0,
array( array( 'errorCode' => 'unknown' ) )
)
);
}
return $result;
},
10,
2
);
}
/** /**
* @param WC_Cart|null $cart * Clear the current cart
* @param $cart_item_key *
* @param WC_Cart|null $cart The cart object.
* @param string $cart_item_key The cart item key.
* @return void * @return void
*/ */
public function clear_current_cart(?WC_Cart $cart, $cart_item_key): void public function clear_current_cart(?WC_Cart $cart, string $cart_item_key ): void {
{ if ( ! $cart ) {
return;
}
$cart->remove_cart_item( $cart_item_key ); $cart->remove_cart_item( $cart_item_key );
$this->customer_address(); $this->customer_address();
} }
/** /**
* Removes the old cart, saves it, and creates a new one * Removes the old cart, saves it, and creates a new one
* @param ApplePayDataObjectHttp $applepay_request_data_object *
* @return bool | string The cart item key after adding to the new cart * @param ApplePayDataObjectHttp $applepay_request_data_object The request data object.
* @throws \Exception * @return bool | string The cart item key after adding to the new cart.
* @throws \Exception If cannot be added to cart.
*/ */
public function prepare_cart(ApplePayDataObjectHttp $applepay_request_data_object): string public function prepare_cart( ApplePayDataObjectHttp $applepay_request_data_object ): string {
{
$this->save_old_cart(); $this->save_old_cart();
$cart = WC()->cart; $cart = WC()->cart;
return $cart->add_to_cart( return $cart->add_to_cart(
(int) $applepay_request_data_object->product_id(), (int) $applepay_request_data_object->product_id(),
(int) $applepay_request_data_object->product_quantity()); (int) $applepay_request_data_object->product_quantity()
);
} }
public function process_order_as_paid($order_id): void /*
{ TODO
public function process_order_as_paid( $order_id ): void {
$order = wc_get_order( $order_id ); $order = wc_get_order( $order_id );
if ( ! assert( $order instanceof WC_Order ) ) { if ( ! assert( $order instanceof WC_Order ) ) {
return; return;
@ -802,14 +810,19 @@ class ApplePayButton implements ButtonInterface {
wc_reduce_stock_levels( $order_id ); wc_reduce_stock_levels( $order_id );
$order->save(); $order->save();
} }
*/
protected function update_posted_data( $applepay_request_data_object ) /**
{ * Update the posted data to match the Apple Pay request data
*
* @param ApplePayDataObjectHttp $applepay_request_data_object The Apple Pay request data.
*/
protected function update_posted_data( $applepay_request_data_object ): void {
add_filter( add_filter(
'woocommerce_checkout_posted_data', 'woocommerce_checkout_posted_data',
function ($data) use ($applepay_request_data_object) { function (array $data ) use ( $applepay_request_data_object ): array {
$data['payment_method'] = "ppcp-gateway"; $data['payment_method'] = 'ppcp-gateway';
$data['shipping_method'] = $applepay_request_data_object->shipping_method(); $data['shipping_method'] = $applepay_request_data_object->shipping_method();
$data['billing_first_name'] = $applepay_request_data_object->billing_address()['first_name'] ?? ''; $data['billing_first_name'] = $applepay_request_data_object->billing_address()['first_name'] ?? '';
$data['billing_last_name'] = $applepay_request_data_object->billing_address()['last_name'] ?? ''; $data['billing_last_name'] = $applepay_request_data_object->billing_address()['last_name'] ?? '';
@ -821,8 +834,7 @@ class ApplePayButton implements ButtonInterface {
$data['billing_state'] = $applepay_request_data_object->billing_address()['state'] ?? ''; $data['billing_state'] = $applepay_request_data_object->billing_address()['state'] ?? '';
$data['billing_postcode'] = $applepay_request_data_object->billing_address()['postcode'] ?? ''; $data['billing_postcode'] = $applepay_request_data_object->billing_address()['postcode'] ?? '';
if ( !empty($applepay_request_data_object->shipping_method()) ) {
if ( $applepay_request_data_object->shipping_method() !== null ) {
$data['billing_email'] = $applepay_request_data_object->shipping_address()['email'] ?? ''; $data['billing_email'] = $applepay_request_data_object->shipping_address()['email'] ?? '';
$data['billing_phone'] = $applepay_request_data_object->shipping_address()['phone'] ?? ''; $data['billing_phone'] = $applepay_request_data_object->shipping_address()['phone'] ?? '';
$data['shipping_first_name'] = $applepay_request_data_object->shipping_address()['first_name'] ?? ''; $data['shipping_first_name'] = $applepay_request_data_object->shipping_address()['first_name'] ?? '';
@ -843,8 +855,12 @@ class ApplePayButton implements ButtonInterface {
); );
} }
public function render(): bool /**
{ * Renders the Apple Pay button on the page
*
* @return bool
*/
public function render(): bool {
$is_applepay_button_enabled = $this->settings->has( 'applepay_button_enabled' ) ? $this->settings->get( 'applepay_button_enabled' ) : false; $is_applepay_button_enabled = $this->settings->has( 'applepay_button_enabled' ) ? $this->settings->get( 'applepay_button_enabled' ) : false;
$button_enabled_product = $is_applepay_button_enabled && $this->settings_status->is_smart_button_enabled_for_location( 'product' ); $button_enabled_product = $is_applepay_button_enabled && $this->settings_status->is_smart_button_enabled_for_location( 'product' );
@ -855,7 +871,7 @@ class ApplePayButton implements ButtonInterface {
add_filter( add_filter(
'woocommerce_paypal_payments_sdk_components_hook', 'woocommerce_paypal_payments_sdk_components_hook',
function( $components ) { function( array $components ) {
$components[] = 'applepay'; $components[] = 'applepay';
return $components; return $components;
} }
@ -908,7 +924,9 @@ class ApplePayButton implements ButtonInterface {
); );
} }
/*if ( $button_enabled_minicart ) { /*
TODO
if ( $button_enabled_minicart ) {
$default_hook_name = 'woocommerce_paypal_payments_minicart_button_render'; $default_hook_name = 'woocommerce_paypal_payments_minicart_button_render';
$render_placeholder = apply_filters( 'woocommerce_paypal_payments_googlepay_minicart_button_render_hook', $default_hook_name ); $render_placeholder = apply_filters( 'woocommerce_paypal_payments_googlepay_minicart_button_render_hook', $default_hook_name );
$render_placeholder = is_string( $render_placeholder ) ? $render_placeholder : $default_hook_name; $render_placeholder = is_string( $render_placeholder ) ? $render_placeholder : $default_hook_name;
@ -919,7 +937,9 @@ class ApplePayButton implements ButtonInterface {
}, },
21 21
); );
}*/ }
*/
return true; return true;
} }
/** /**
@ -935,13 +955,21 @@ class ApplePayButton implements ButtonInterface {
<?php <?php
} }
public function should_load_script(): bool /**
{ * Checks if the module should load the script.
*
* @return bool
*/
public function should_load_script(): bool {
return true; return true;
} }
public function enqueue(): void /**
{ * Enqueues the scripts.
*
* @return void
*/
public function enqueue(): void {
wp_register_script( wp_register_script(
'wc-ppcp-applepay', 'wc-ppcp-applepay',
untrailingslashit( $this->module_url ) . '/assets/js/boot.js', untrailingslashit( $this->module_url ) . '/assets/js/boot.js',
@ -966,13 +994,22 @@ class ApplePayButton implements ButtonInterface {
); );
} }
public function script_data(): array /**
{ * Returns the script data.
*
* @return array
*/
public function script_data(): array {
return $this->script_data->apple_pay_script_data(); return $this->script_data->apple_pay_script_data();
} }
public function is_enabled(): bool /**
{ * Returns true if the module is enabled.
*
* @return bool
*/
public function is_enabled(): bool {
// TODO: Implement is_enabled() method. // TODO: Implement is_enabled() method.
return true;
} }
} }

View file

@ -20,6 +20,7 @@ class ApplePayDataObjectHttp {
* The nonce of the request. * The nonce of the request.
* *
* @var string * @var string
* @psalm-suppress PropertyNotSetInConstructor
*/ */
protected $nonce; protected $nonce;
@ -44,6 +45,13 @@ class ApplePayDataObjectHttp {
*/ */
protected $product_id; protected $product_id;
/**
* The caller page.
*
* @var mixed
*/
protected $caller_page;
/** /**
* The product quantity. * The product quantity.
* *
@ -104,7 +112,7 @@ class ApplePayDataObjectHttp {
/** /**
* Resets the errors array * Resets the errors array
*/ */
protected function reset_errors() { protected function reset_errors(): void {
$this->errors = array(); $this->errors = array();
} }
@ -113,7 +121,8 @@ class ApplePayDataObjectHttp {
* *
* @return bool * @return bool
*/ */
public function has_errors() { public function has_errors(): bool
{
return ! empty( $this->errors ); return ! empty( $this->errors );
} }
/** /**
@ -125,7 +134,12 @@ class ApplePayDataObjectHttp {
return $this->errors; return $this->errors;
} }
public function validation_data() { /**
* Assigns the validation flag
*
* @return void
*/
public function validation_data(): void {
$data = filter_input( INPUT_POST, 'validation', FILTER_VALIDATE_BOOL ); $data = filter_input( INPUT_POST, 'validation', FILTER_VALIDATE_BOOL );
if ( ! $data ) { if ( ! $data ) {
return; return;
@ -137,8 +151,11 @@ class ApplePayDataObjectHttp {
* Set the object with the data relevant to ApplePay on update shipping contact * Set the object with the data relevant to ApplePay on update shipping contact
* Required data depends on callerPage * Required data depends on callerPage
*/ */
public function update_contact_data() { public function update_contact_data(): void {
$nonce = filter_input( INPUT_POST, 'woocommerce-process-checkout-nonce', FILTER_SANITIZE_SPECIAL_CHARS ); $nonce = filter_input( INPUT_POST, 'woocommerce-process-checkout-nonce', FILTER_SANITIZE_SPECIAL_CHARS );
if ( ! $nonce ) {
return;
}
$is_nonce_valid = wp_verify_nonce( $is_nonce_valid = wp_verify_nonce(
$nonce, $nonce,
'woocommerce-process_checkout' 'woocommerce-process_checkout'
@ -147,7 +164,9 @@ class ApplePayDataObjectHttp {
return; return;
} }
$data = $this->get_filtered_request_data(); $data = $this->get_filtered_request_data();
if ( ! $data ) {
return;
}
$result = $this->update_required_data( $result = $this->update_required_data(
$data, $data,
PropertiesDictionary::UPDATE_CONTACT_SINGLE_PROD_REQUIRED_FIELDS, PropertiesDictionary::UPDATE_CONTACT_SINGLE_PROD_REQUIRED_FIELDS,
@ -163,8 +182,11 @@ class ApplePayDataObjectHttp {
* Set the object with the data relevant to ApplePay on update shipping method * Set the object with the data relevant to ApplePay on update shipping method
* Required data depends on callerPage * Required data depends on callerPage
*/ */
public function update_method_data() { public function update_method_data(): void {
$nonce = filter_input( INPUT_POST, 'woocommerce-process-checkout-nonce', FILTER_SANITIZE_SPECIAL_CHARS ); $nonce = filter_input( INPUT_POST, 'woocommerce-process-checkout-nonce', FILTER_SANITIZE_SPECIAL_CHARS );
if ( ! $nonce ) {
return;
}
$is_nonce_valid = wp_verify_nonce( $is_nonce_valid = wp_verify_nonce(
$nonce, $nonce,
'woocommerce-process_checkout' 'woocommerce-process_checkout'
@ -174,6 +196,9 @@ class ApplePayDataObjectHttp {
} }
$data = $this->get_filtered_request_data(); $data = $this->get_filtered_request_data();
if ( ! $data ) {
return;
}
$result = $this->update_required_data( $result = $this->update_required_data(
$data, $data,
PropertiesDictionary::UPDATE_METHOD_SINGLE_PROD_REQUIRED_FIELDS, PropertiesDictionary::UPDATE_METHOD_SINGLE_PROD_REQUIRED_FIELDS,
@ -192,8 +217,11 @@ class ApplePayDataObjectHttp {
* *
* @param string $caller_page The caller page. * @param string $caller_page The caller page.
*/ */
public function order_data( string $caller_page ) { public function order_data( string $caller_page ): void {
$nonce = filter_input( INPUT_POST, 'woocommerce-process-checkout-nonce', FILTER_SANITIZE_SPECIAL_CHARS ); $nonce = filter_input( INPUT_POST, 'woocommerce-process-checkout-nonce', FILTER_SANITIZE_SPECIAL_CHARS );
if ( ! $nonce ) {
return;
}
$is_nonce_valid = wp_verify_nonce( $is_nonce_valid = wp_verify_nonce(
$nonce, $nonce,
'woocommerce-process_checkout' 'woocommerce-process_checkout'
@ -202,6 +230,9 @@ class ApplePayDataObjectHttp {
return; return;
} }
$data = filter_var_array( $_POST, FILTER_SANITIZE_SPECIAL_CHARS ); $data = filter_var_array( $_POST, FILTER_SANITIZE_SPECIAL_CHARS );
if ( ! $data ) {
return;
}
$data[ PropertiesDictionary::CALLER_PAGE ] = $caller_page; $data[ PropertiesDictionary::CALLER_PAGE ] = $caller_page;
$result = $this->update_required_data( $result = $this->update_required_data(
$data, $data,
@ -273,7 +304,7 @@ class ApplePayDataObjectHttp {
* *
* @param array $data The data. * @param array $data The data.
*/ */
protected function assign_data_object_values( array $data ) { protected function assign_data_object_values( array $data ): void {
foreach ( $data as $key => $value ) { foreach ( $data as $key => $value ) {
if ( $key === 'woocommerce-process-checkout-nonce' ) { if ( $key === 'woocommerce-process-checkout-nonce' ) {
$key = 'nonce'; $key = 'nonce';
@ -285,7 +316,7 @@ class ApplePayDataObjectHttp {
/** /**
* Returns the address details used in pre-authorization steps. * Returns the address details used in pre-authorization steps.
* *
* @param array $contact_info * @param array $contact_info The contact info.
* *
* @return string[] * @return string[]
*/ */
@ -316,9 +347,9 @@ class ApplePayDataObjectHttp {
* are not empty. * are not empty.
* If not it adds a contacField error to the object's error list. * If not it adds a contacField error to the object's error list.
* *
* @param array $post The address to check * @param array $post The address to check.
* @param array $required The required fields for the given address * @param array $required The required fields for the given address.
* @param string $error_code Either shipping or billing kind * @param string $error_code Either shipping or billing kind.
* *
* @return bool * @return bool
*/ */
@ -356,7 +387,7 @@ class ApplePayDataObjectHttp {
* Returns the address details for after authorization steps. * Returns the address details for after authorization steps.
* *
* @param array $data The data. * @param array $data The data.
* @param string $error_code differentiates between billing and shipping information * @param string $error_code differentiates between billing and shipping information.
* *
* @return string[] * @return string[]
*/ */
@ -397,8 +428,8 @@ class ApplePayDataObjectHttp {
* Updates the object with the required data. * Updates the object with the required data.
* *
* @param array $data The data. * @param array $data The data.
* @param array $required_product_fields * @param array $required_product_fields The required product fields.
* @param array $required_cart_fields * @param array $required_cart_fields The required cart fields.
* @return bool * @return bool
*/ */
protected function update_required_data( array $data, array $required_product_fields, array $required_cart_fields ) { protected function update_required_data( array $data, array $required_product_fields, array $required_cart_fields ) {
@ -499,6 +530,15 @@ class ApplePayDataObjectHttp {
return $this->product_id; return $this->product_id;
} }
/**
* Returns the product id.
*
* @return string
*/
public function caller_page(): string {
return $this->caller_page;
}
/** /**
* Returns the product quantity. * Returns the product quantity.
* *
@ -511,9 +551,10 @@ class ApplePayDataObjectHttp {
/** /**
* Returns the nonce. * Returns the nonce.
* *
* @return mixed * @return string
*/ */
public function nonce() { public function nonce(): string
{
return $this->nonce; return $this->nonce;
} }
@ -531,8 +572,7 @@ class ApplePayDataObjectHttp {
* *
* @return bool * @return bool
*/ */
public function validated_flag() public function validated_flag() {
{
return $this->validation_flag; return $this->validation_flag;
} }

View file

@ -9,6 +9,9 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Applepay\Assets; namespace WooCommerce\PayPalCommerce\Applepay\Assets;
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
/** /**
* Class DataToAppleButtonScripts * Class DataToAppleButtonScripts
*/ */
@ -23,11 +26,17 @@ class DataToAppleButtonScripts {
/** /**
* The settings. * The settings.
* *
* @var array * @var Settings
*/ */
private $settings; private $settings;
public function __construct($sdk_url, $settings) { /**
* DataToAppleButtonScripts constructor.
*
* @param string $sdk_url The URL to the SDK.
* @param Settings $settings The settings.
*/
public function __construct(string $sdk_url, Settings $settings ) {
$this->sdk_url = $sdk_url; $this->sdk_url = $sdk_url;
$this->settings = $settings; $this->settings = $settings;
} }
@ -36,8 +45,9 @@ class DataToAppleButtonScripts {
* Sets the appropriate data to send to ApplePay script * Sets the appropriate data to send to ApplePay script
* Data differs between product page and cart page * Data differs between product page and cart page
* *
* @param bool $is_block * @param bool $is_block Whether the button is in a block or not.
* @return array * @return array
* @throws NotFoundException When the setting is not found.
*/ */
public function apple_pay_script_data( bool $is_block = false ): array { public function apple_pay_script_data( bool $is_block = false ): array {
$base_location = wc_get_base_location(); $base_location = wc_get_base_location();
@ -62,7 +72,7 @@ class DataToAppleButtonScripts {
/** /**
* Check if the product needs shipping * Check if the product needs shipping
* *
* @param $product * @param \WC_Product $product The product.
* *
* @return bool * @return bool
*/ */
@ -85,11 +95,14 @@ class DataToAppleButtonScripts {
} }
/** /**
* @param $shop_country_code * Prepares the data for the product page.
* @param $currency_code *
* @param $tota_label * @param string $shop_country_code The shop country code.
* @param string $currency_code The currency code.
* @param string $total_label The label for the total amount.
* *
* @return array * @return array
* @throws NotFoundException When the setting is not found.
*/ */
protected function data_for_product_page( protected function data_for_product_page(
$shop_country_code, $shop_country_code,
@ -138,9 +151,11 @@ class DataToAppleButtonScripts {
} }
/** /**
* @param $shop_country_code * Prepares the data for the cart page.
* @param $currency_code *
* @param $total_label * @param string $shop_country_code The shop country code.
* @param string $currency_code The currency code.
* @param string $total_label The label for the total amount.
* *
* @return array * @return array
*/ */

View file

@ -12,8 +12,8 @@ namespace WooCommerce\PayPalCommerce\Applepay\Assets;
/** /**
* Class PropertiesDictionary * Class PropertiesDictionary
*/ */
class PropertiesDictionary class PropertiesDictionary {
{
public const BILLING_CONTACT_INVALID = 'billing Contact Invalid'; public const BILLING_CONTACT_INVALID = 'billing Contact Invalid';
@ -108,8 +108,7 @@ class PropertiesDictionary
* *
* @return array * @return array
*/ */
public static function button_colors(): array public static function button_colors(): array {
{
return array( return array(
'white' => __( 'White', 'woocommerce-paypal-payments' ), 'white' => __( 'White', 'woocommerce-paypal-payments' ),
'black' => __( 'Black', 'woocommerce-paypal-payments' ), 'black' => __( 'Black', 'woocommerce-paypal-payments' ),
@ -122,8 +121,7 @@ class PropertiesDictionary
* *
* @return array * @return array
*/ */
public static function button_types(): array public static function button_types(): array {
{
return array( return array(
'book' => __( 'Book', 'woocommerce-paypal-payments' ), 'book' => __( 'Book', 'woocommerce-paypal-payments' ),
'buy' => __( 'Buy', 'woocommerce-paypal-payments' ), 'buy' => __( 'Buy', 'woocommerce-paypal-payments' ),
@ -141,48 +139,47 @@ class PropertiesDictionary
* *
* @return array * @return array
*/ */
public static function button_languages(): array public static function button_languages(): array {
{
return array( return array(
"ar-AB" => __('Arabic', 'woocommerce-paypal-payments'), 'ar-AB' => __( 'Arabic', 'woocommerce-paypal-payments' ),
"ca-ES" => __('Catalan', 'woocommerce-paypal-payments'), 'ca-ES' => __( 'Catalan', 'woocommerce-paypal-payments' ),
"cs-CZ" => __('Czech', 'woocommerce-paypal-payments'), 'cs-CZ' => __( 'Czech', 'woocommerce-paypal-payments' ),
"da-DK" => __('Danish', 'woocommerce-paypal-payments'), 'da-DK' => __( 'Danish', 'woocommerce-paypal-payments' ),
"de-DE" => __('German', 'woocommerce-paypal-payments'), 'de-DE' => __( 'German', 'woocommerce-paypal-payments' ),
"el-GR" => __('Greek', 'woocommerce-paypal-payments'), 'el-GR' => __( 'Greek', 'woocommerce-paypal-payments' ),
"en-AU" => __('English (Australia)', 'woocommerce-paypal-payments'), 'en-AU' => __( 'English (Australia)', 'woocommerce-paypal-payments' ),
"en-GB" => __('English (United Kingdom)', 'woocommerce-paypal-payments'), 'en-GB' => __( 'English (United Kingdom)', 'woocommerce-paypal-payments' ),
"en-US" => __('English (United States)', 'woocommerce-paypal-payments'), 'en-US' => __( 'English (United States)', 'woocommerce-paypal-payments' ),
"es-ES" => __('Spanish (Spain)', 'woocommerce-paypal-payments'), 'es-ES' => __( 'Spanish (Spain)', 'woocommerce-paypal-payments' ),
"es-MX" => __('Spanish (Mexico)', 'woocommerce-paypal-payments'), 'es-MX' => __( 'Spanish (Mexico)', 'woocommerce-paypal-payments' ),
"fi-FI" => __('Finnish', 'woocommerce-paypal-payments'), 'fi-FI' => __( 'Finnish', 'woocommerce-paypal-payments' ),
"fr-CA" => __('French (Canada)', 'woocommerce-paypal-payments'), 'fr-CA' => __( 'French (Canada)', 'woocommerce-paypal-payments' ),
"fr-FR" => __('French (France)', 'woocommerce-paypal-payments'), 'fr-FR' => __( 'French (France)', 'woocommerce-paypal-payments' ),
"he-IL" => __('Hebrew', 'woocommerce-paypal-payments'), 'he-IL' => __( 'Hebrew', 'woocommerce-paypal-payments' ),
"hi-IN" => __('Hindi', 'woocommerce-paypal-payments'), 'hi-IN' => __( 'Hindi', 'woocommerce-paypal-payments' ),
"hr-HR" => __('Croatian', 'woocommerce-paypal-payments'), 'hr-HR' => __( 'Croatian', 'woocommerce-paypal-payments' ),
"hu-HU" => __('Hungarian', 'woocommerce-paypal-payments'), 'hu-HU' => __( 'Hungarian', 'woocommerce-paypal-payments' ),
"id-ID" => __('Indonesian', 'woocommerce-paypal-payments'), 'id-ID' => __( 'Indonesian', 'woocommerce-paypal-payments' ),
"it-IT" => __('Italian', 'woocommerce-paypal-payments'), 'it-IT' => __( 'Italian', 'woocommerce-paypal-payments' ),
"ja-JP" => __('Japanese', 'woocommerce-paypal-payments'), 'ja-JP' => __( 'Japanese', 'woocommerce-paypal-payments' ),
"ko-KR" => __('Korean', 'woocommerce-paypal-payments'), 'ko-KR' => __( 'Korean', 'woocommerce-paypal-payments' ),
"ms-MY" => __('Malay', 'woocommerce-paypal-payments'), 'ms-MY' => __( 'Malay', 'woocommerce-paypal-payments' ),
"nb-NO" => __('Norwegian', 'woocommerce-paypal-payments'), 'nb-NO' => __( 'Norwegian', 'woocommerce-paypal-payments' ),
"nl-NL" => __('Dutch', 'woocommerce-paypal-payments'), 'nl-NL' => __( 'Dutch', 'woocommerce-paypal-payments' ),
"pl-PL" => __('Polish', 'woocommerce-paypal-payments'), 'pl-PL' => __( 'Polish', 'woocommerce-paypal-payments' ),
"pt-BR" => __('Portuguese (Brazil)', 'woocommerce-paypal-payments'), 'pt-BR' => __( 'Portuguese (Brazil)', 'woocommerce-paypal-payments' ),
"pt-PT" => __('Portuguese (Portugal)', 'woocommerce-paypal-payments'), 'pt-PT' => __( 'Portuguese (Portugal)', 'woocommerce-paypal-payments' ),
"ro-RO" => __('Romanian', 'woocommerce-paypal-payments'), 'ro-RO' => __( 'Romanian', 'woocommerce-paypal-payments' ),
"ru-RU" => __('Russian', 'woocommerce-paypal-payments'), 'ru-RU' => __( 'Russian', 'woocommerce-paypal-payments' ),
"sk-SK" => __('Slovak', 'woocommerce-paypal-payments'), 'sk-SK' => __( 'Slovak', 'woocommerce-paypal-payments' ),
"sv-SE" => __('Swedish', 'woocommerce-paypal-payments'), 'sv-SE' => __( 'Swedish', 'woocommerce-paypal-payments' ),
"th-TH" => __('Thai', 'woocommerce-paypal-payments'), 'th-TH' => __( 'Thai', 'woocommerce-paypal-payments' ),
"tr-TR" => __('Turkish', 'woocommerce-paypal-payments'), 'tr-TR' => __( 'Turkish', 'woocommerce-paypal-payments' ),
"uk-UA" => __('Ukrainian', 'woocommerce-paypal-payments'), 'uk-UA' => __( 'Ukrainian', 'woocommerce-paypal-payments' ),
"vi-VN" => __('Vietnamese', 'woocommerce-paypal-payments'), 'vi-VN' => __( 'Vietnamese', 'woocommerce-paypal-payments' ),
"zh-CN" => __('Chinese (Simplified)', 'woocommerce-paypal-payments'), 'zh-CN' => __( 'Chinese (Simplified)', 'woocommerce-paypal-payments' ),
"zh-HK" => __('Chinese (Hong Kong)', 'woocommerce-paypal-payments'), 'zh-HK' => __( 'Chinese (Hong Kong)', 'woocommerce-paypal-payments' ),
"zh-TW" => __('Chinese (Traditional)', 'woocommerce-paypal-payments'), 'zh-TW' => __( 'Chinese (Traditional)', 'woocommerce-paypal-payments' ),
); );
} }
} }

View file

@ -1,12 +1,17 @@
<?php <?php
/**
* Prepares the data for the response to Apple.
*
* @package WooCommerce\PayPalCommerce\Applepay
*/
declare(strict_types=1); declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Applepay\Assets; namespace WooCommerce\PayPalCommerce\Applepay\Assets;
use Psr\Log\LoggerInterface; /**
use WC_Payment_Gateway; * Class ResponsesToApple
*/
class ResponsesToApple { class ResponsesToApple {
/** /**
@ -14,9 +19,10 @@ class ResponsesToApple {
* Adds the error list if provided to be handled by the script * Adds the error list if provided to be handled by the script
* On success it adds the redirection url * On success it adds the redirection url
* *
* @param $status 0 => success, 1 => error * @param int $status 0 => success, 1 => error.
* @param string $order_id * @param string $order_id The order ID.
* @param array $error_list * @param array $error_list [['errorCode'=>required, 'contactField'=>'']].
* @param string $return_url The URL to redirect to.
* *
* @return array * @return array
*/ */
@ -44,13 +50,12 @@ class ResponsesToApple {
/** /**
* Returns an error response to be handled by the script * Returns an error response to be handled by the script
* *
* @param array $errorList [['errorCode'=>required, 'contactField'=>'']] * @param array $error_list [['errorCode'=>required, 'contactField'=>'']].
*
* @return void * @return void
*/ */
public function response_with_data_errors( $errorList ) { public function response_with_data_errors( $error_list ) {
$response = array(); $response = array();
$response['errors'] = $this->apple_pay_error( $errorList ); $response['errors'] = $this->apple_pay_error( $error_list );
$response['newTotal'] = $this->apple_new_total_response( $response['newTotal'] = $this->apple_new_total_response(
0, 0,
'pending' 'pending'
@ -61,6 +66,7 @@ class ResponsesToApple {
/** /**
* Creates a response formatted for ApplePay * Creates a response formatted for ApplePay
* *
* @param array $payment_details Payment details.
* @return array * @return array
*/ */
public function apple_formatted_response( array $payment_details ) { public function apple_formatted_response( array $payment_details ) {
@ -81,16 +87,18 @@ class ResponsesToApple {
/** /**
* Returns a success response to be handled by the script * Returns a success response to be handled by the script
*
* @param array $response Response to send.
*/ */
public function response_success( array $response ) { public function response_success( array $response ): void {
wp_send_json_success( $response ); wp_send_json_success( $response );
} }
/** /**
* Creates an array of errors formatted * Creates an array of errors formatted
* *
* @param array $error_list * @param array $error_list List of errors.
* @param array $errors * @param array $errors (optional).
* *
* @return array * @return array
*/ */
@ -110,9 +118,8 @@ class ResponsesToApple {
/** /**
* Creates NewTotals line * Creates NewTotals line
* *
* @param $total * @param float $total Total amount.
* * @param string $type final or pending.
* @param string $type
* *
* @return array * @return array
*/ */
@ -127,9 +134,9 @@ class ResponsesToApple {
/** /**
* Creates item line * Creates item line
* *
* @param $subtotal_label * @param string $subtotal_label Subtotal label.
* @param $subtotal * @param float $subtotal Subtotal amount.
* @param $type * @param string $type final or pending.
* *
* @return array * @return array
*/ */
@ -144,6 +151,7 @@ class ResponsesToApple {
/** /**
* Creates NewLineItems line * Creates NewLineItems line
* *
* @param array $payment_details Payment details.
* @return array[] * @return array[]
*/ */
protected function apple_new_line_items_response( array $payment_details ): array { protected function apple_new_line_items_response( array $payment_details ): array {