Use PHP 7.4 featers and PHP 8 polyfills

This commit is contained in:
David Stone
2025-02-08 13:57:32 -07:00
parent 8bea6067cd
commit b41dc2b2eb
550 changed files with 15270 additions and 14627 deletions

View File

@ -61,7 +61,7 @@ abstract class Base_Gateway {
* @since 2.0.7
* @var array
*/
protected $other_ids = array();
protected $other_ids = [];
/**
* The order cart object.
@ -165,7 +165,7 @@ abstract class Base_Gateway {
* @param \WP_Ultimo\Checkout\Cart $order The order.
* @return void
*/
public function set_order($order) {
public function set_order($order): void {
if ($order === null) {
return;
@ -643,16 +643,16 @@ abstract class Base_Gateway {
$return_url = is_admin() ? admin_url('admin.php') : $this->return_url;
$return_url = remove_query_arg(
array(
[
'wu-confirm',
'token',
'PayerID',
),
],
$return_url
);
if (is_admin()) {
$args = array('page' => 'account');
$args = ['page' => 'account'];
if ($this->order) {
$args['updated'] = $this->order->get_cart_type();
@ -661,10 +661,10 @@ abstract class Base_Gateway {
$return_url = add_query_arg($args, $return_url);
} else {
$return_url = add_query_arg(
array(
[
'payment' => $this->payment->get_hash(),
'status' => 'done',
),
],
$return_url
);
}
@ -696,9 +696,9 @@ abstract class Base_Gateway {
}
return add_query_arg(
array(
[
'payment' => $this->payment->get_hash(),
),
],
$this->cancel_url
);
}
@ -716,10 +716,10 @@ abstract class Base_Gateway {
}
return add_query_arg(
array(
[
'payment' => $this->payment->get_hash(),
'wu-confirm' => $this->get_id(),
),
],
$this->confirm_url
);
}
@ -744,7 +744,7 @@ abstract class Base_Gateway {
* @param \WP_Ultimo\Models\Payment $payment The payment.
* @return void
*/
public function set_payment($payment) {
public function set_payment($payment): void {
$this->payment = $payment;
}
@ -756,7 +756,7 @@ abstract class Base_Gateway {
* @param \WP_Ultimo\Models\Membership $membership The membership.
* @return void
*/
public function set_membership($membership) {
public function set_membership($membership): void {
$this->membership = $membership;
}
@ -768,7 +768,7 @@ abstract class Base_Gateway {
* @param \WP_Ultimo\Models\Payment $customer The customer.
* @return void
*/
public function set_customer($customer) {
public function set_customer($customer): void {
$this->customer = $customer;
}
@ -782,7 +782,7 @@ abstract class Base_Gateway {
* @param \WP_Ultimo\Models\Membership $membership The membership object.
* @return void
*/
public function trigger_payment_processed($payment, $membership = null) {
public function trigger_payment_processed($payment, $membership = null): void {
if ($membership === null) {
$membership = $payment->get_membership();
@ -829,7 +829,7 @@ abstract class Base_Gateway {
*/
public function get_all_ids() {
$all_ids = array_merge(array($this->get_id()), (array) $this->other_ids);
$all_ids = array_merge([$this->get_id()], (array) $this->other_ids);
return array_unique($all_ids);
}

File diff suppressed because it is too large Load Diff

View File

@ -56,7 +56,7 @@ class Free_Gateway extends Base_Gateway {
* @param string $type The checkout type. Can be 'new', 'retry', 'upgrade', 'downgrade', 'addon'.
* @return void
*/
public function process_checkout($payment, $membership, $customer, $cart, $type) {
public function process_checkout($payment, $membership, $customer, $cart, $type): void {
$membership_status = $membership->get_status();

View File

@ -43,11 +43,11 @@ class Manual_Gateway extends Base_Gateway {
* @since 2.0.0
* @return void
*/
public function hooks() {
public function hooks(): void {
/*
* Adds payment instructions to the thank you page.
*/
add_action('wu_thank_you_before_info_blocks', array($this, 'add_payment_instructions_block'), 10, 3);
add_action('wu_thank_you_before_info_blocks', [$this, 'add_payment_instructions_block'], 10, 3);
}
/**
@ -81,35 +81,35 @@ class Manual_Gateway extends Base_Gateway {
* @since 2.0.0
* @return void
*/
public function settings() {
public function settings(): void {
wu_register_settings_field(
'payment-gateways',
'manual_header',
array(
[
'title' => __('Manual', 'wp-ultimo'),
'desc' => __('Use the settings section below to configure the manual payment method. This method allows your customers to manually pay for their memberships, but those payments require manual confirmation on your part.', 'wp-ultimo'),
'type' => 'header',
'show_as_submenu' => true,
'require' => array(
'require' => [
'active_gateways' => 'manual',
),
)
],
]
);
wu_register_settings_field(
'payment-gateways',
'manual_payment_instructions',
array(
[
'title' => __('Payment Instructions', 'wp-ultimo'),
'desc' => __('This instructions will be shown to the customer on the thank you page, as well as be sent via email.', 'wp-ultimo'),
'type' => 'wp_editor',
'allow_html' => true,
'default' => __('Payment instructions here.', 'wp-ultimo'),
'require' => array(
'require' => [
'active_gateways' => 'manual',
),
)
],
]
);
}
@ -332,7 +332,7 @@ class Manual_Gateway extends Base_Gateway {
* @param \WP_Ultimo\Models\Customer $customer The customer checking out.
* @return void|bool
*/
public function process_refund($amount, $payment, $membership, $customer) {
public function process_refund($amount, $payment, $membership, $customer): void {
$status = $payment->refund($amount);
@ -367,7 +367,7 @@ class Manual_Gateway extends Base_Gateway {
* @param \WP_Ultimo\Models\Customer $customer the current customer.
* @return void
*/
public function add_payment_instructions_block($payment, $membership, $customer) {
public function add_payment_instructions_block($payment, $membership, $customer): void {
if ($payment->get_gateway() !== $this->id) {
return;

View File

@ -138,7 +138,7 @@ class PayPal_Gateway extends Base_Gateway {
* @since 2.0.0
* @return void
*/
public function init() {
public function init(): void {
/*
* Checks if we are in test mode or not,
* based on the PayPal Setting.
@ -180,43 +180,43 @@ class PayPal_Gateway extends Base_Gateway {
* @since 2.0.0
* @return void
*/
public function settings() {
public function settings(): void {
wu_register_settings_field(
'payment-gateways',
'paypal_header',
array(
[
'title' => __('PayPal', 'wp-ultimo'),
'desc' => __('Use the settings section below to configure PayPal Express as a payment method.', 'wp-ultimo'),
'type' => 'header',
'show_as_submenu' => true,
'require' => array(
'require' => [
'active_gateways' => 'paypal',
),
)
],
]
);
wu_register_settings_field(
'payment-gateways',
'paypal_sandbox_mode',
array(
[
'title' => __('PayPal Sandbox Mode', 'wp-ultimo'),
'desc' => __('Toggle this to put PayPal on sandbox mode. This is useful for testing and making sure PayPal is correctly setup to handle your payments.', 'wp-ultimo'),
'type' => 'toggle',
'default' => 0,
'html_attr' => array(
'html_attr' => [
'v-model' => 'paypal_sandbox_mode',
),
'require' => array(
],
'require' => [
'active_gateways' => 'paypal',
),
)
],
]
);
wu_register_settings_field(
'payment-gateways',
'paypal_test_username',
array(
[
'title' => __('PayPal Test Username', 'wp-ultimo'),
'desc' => '',
'tooltip' => __('Make sure you are placing the TEST username, not the live one.', 'wp-ultimo'),
@ -224,17 +224,17 @@ class PayPal_Gateway extends Base_Gateway {
'type' => 'text',
'default' => '',
'capability' => 'manage_api_keys',
'require' => array(
'require' => [
'active_gateways' => 'paypal',
'paypal_sandbox_mode' => 1,
),
)
],
]
);
wu_register_settings_field(
'payment-gateways',
'paypal_test_password',
array(
[
'title' => __('PayPal Test Password', 'wp-ultimo'),
'desc' => '',
'tooltip' => __('Make sure you are placing the TEST password, not the live one.', 'wp-ultimo'),
@ -242,17 +242,17 @@ class PayPal_Gateway extends Base_Gateway {
'type' => 'text',
'default' => '',
'capability' => 'manage_api_keys',
'require' => array(
'require' => [
'active_gateways' => 'paypal',
'paypal_sandbox_mode' => 1,
),
)
],
]
);
wu_register_settings_field(
'payment-gateways',
'paypal_test_signature',
array(
[
'title' => __('PayPal Test Signature', 'wp-ultimo'),
'desc' => '',
'tooltip' => __('Make sure you are placing the TEST signature, not the live one.', 'wp-ultimo'),
@ -260,17 +260,17 @@ class PayPal_Gateway extends Base_Gateway {
'type' => 'text',
'default' => '',
'capability' => 'manage_api_keys',
'require' => array(
'require' => [
'active_gateways' => 'paypal',
'paypal_sandbox_mode' => 1,
),
)
],
]
);
wu_register_settings_field(
'payment-gateways',
'paypal_live_username',
array(
[
'title' => __('PayPal Live Username', 'wp-ultimo'),
'desc' => '',
'tooltip' => __('Make sure you are placing the LIVE username, not the test one.', 'wp-ultimo'),
@ -278,17 +278,17 @@ class PayPal_Gateway extends Base_Gateway {
'type' => 'text',
'default' => '',
'capability' => 'manage_api_keys',
'require' => array(
'require' => [
'active_gateways' => 'paypal',
'paypal_sandbox_mode' => 0,
),
)
],
]
);
wu_register_settings_field(
'payment-gateways',
'paypal_live_password',
array(
[
'title' => __('PayPal Live Password', 'wp-ultimo'),
'desc' => '',
'tooltip' => __('Make sure you are placing the LIVE password, not the test one.', 'wp-ultimo'),
@ -296,17 +296,17 @@ class PayPal_Gateway extends Base_Gateway {
'type' => 'text',
'default' => '',
'capability' => 'manage_api_keys',
'require' => array(
'require' => [
'active_gateways' => 'paypal',
'paypal_sandbox_mode' => 0,
),
)
],
]
);
wu_register_settings_field(
'payment-gateways',
'paypal_live_signature',
array(
[
'title' => __('PayPal Live Signature', 'wp-ultimo'),
'desc' => '',
'tooltip' => __('Make sure you are placing the LIVE signature, not the test one.', 'wp-ultimo'),
@ -314,11 +314,11 @@ class PayPal_Gateway extends Base_Gateway {
'type' => 'text',
'default' => '',
'capability' => 'manage_api_keys',
'require' => array(
'require' => [
'active_gateways' => 'paypal',
'paypal_sandbox_mode' => 0,
),
)
],
]
);
}
@ -357,7 +357,7 @@ class PayPal_Gateway extends Base_Gateway {
$description = wu_get_setting('company_name', __('Subscription', 'wp-ultimo')) . ': ' . implode(', ', array_map(fn($item) => 'x' . $item->get_quantity() . ' ' . $item->get_title(), $temp_payment->get_line_items()));
$args = array(
$args = [
'USER' => $this->username,
'PWD' => $this->password,
'SIGNATURE' => $this->signature,
@ -368,15 +368,15 @@ class PayPal_Gateway extends Base_Gateway {
'DESC' => $description,
'AMT' => $temp_payment->get_total() - $temp_payment->get_tax_total(),
'TAXAMT' => $temp_payment->get_tax_total(),
);
];
$request = wp_remote_post(
$this->api_endpoint,
array(
[
'timeout' => 45,
'httpversion' => '1.1',
'body' => $args,
)
]
);
/*
@ -417,7 +417,7 @@ class PayPal_Gateway extends Base_Gateway {
* @param string $type The checkout type. Can be 'new', 'retry', 'upgrade', 'downgrade', 'addon'.
* @return void
*/
public function process_checkout($payment, $membership, $customer, $cart, $type) {
public function process_checkout($payment, $membership, $customer, $cart, $type): void {
/*
* To make our lives easier, let's
* set a couple of variables based on the order.
@ -466,7 +466,7 @@ class PayPal_Gateway extends Base_Gateway {
* request object, and append the products
* later.
*/
$args = array(
$args = [
'USER' => $this->username,
'PWD' => $this->password,
'SIGNATURE' => $this->signature,
@ -492,9 +492,9 @@ class PayPal_Gateway extends Base_Gateway {
'LANDINGPAGE' => 'Billing',
'RETURNURL' => $return_url,
'LOGOIMG' => wu_get_network_logo(),
);
];
$notes = array();
$notes = [];
if ($is_trial_setup) {
$desc = $membership->get_recurring_description();
@ -553,13 +553,13 @@ class PayPal_Gateway extends Base_Gateway {
$sub_total = $line_item->get_subtotal();
$tax_amount = $line_item->get_tax_total();
$product_args = array(
$product_args = [
"L_PAYMENTREQUEST_0_NAME{$product_index}" => $line_item->get_title(),
"L_PAYMENTREQUEST_0_DESC{$product_index}" => $line_item->get_description(),
"L_PAYMENTREQUEST_0_AMT{$product_index}" => $sub_total,
"L_PAYMENTREQUEST_0_QTY{$product_index}" => $line_item->get_quantity(),
"L_PAYMENTREQUEST_0_TAXAMT{$product_index}" => $tax_amount,
);
];
$args['PAYMENTREQUEST_0_ITEMAMT'] = $args['PAYMENTREQUEST_0_ITEMAMT'] + $sub_total;
$args['PAYMENTREQUEST_0_TAXAMT'] = $args['PAYMENTREQUEST_0_TAXAMT'] + $tax_amount;
@ -577,11 +577,11 @@ class PayPal_Gateway extends Base_Gateway {
$args = array_merge(
$args,
array(
[
"L_PAYMENTREQUEST_0_NAME{$product_index}" => __('Account credit and other discounts', 'wp-ultimo'),
"L_PAYMENTREQUEST_0_AMT{$product_index}" => $discounts_total,
"L_PAYMENTREQUEST_0_QTY{$product_index}" => 1,
)
]
);
$args['PAYMENTREQUEST_0_ITEMAMT'] = $args['PAYMENTREQUEST_0_ITEMAMT'] + $discounts_total;
@ -592,11 +592,11 @@ class PayPal_Gateway extends Base_Gateway {
$request = wp_remote_post(
$this->api_endpoint,
array(
[
'timeout' => 45,
'httpversion' => '1.1',
'body' => $args,
)
]
);
$body = wp_remote_retrieve_body($request);
@ -664,11 +664,11 @@ class PayPal_Gateway extends Base_Gateway {
* @param \WP_Ultimo\Models\Customer $customer The customer checking out.
* @return void|bool
*/
public function process_cancellation($membership, $customer) {
public function process_cancellation($membership, $customer): void {
$profile_id = $membership->get_gateway_subscription_id();
$args = array(
$args = [
'USER' => $this->username,
'PWD' => $this->password,
'SIGNATURE' => $this->signature,
@ -676,15 +676,15 @@ class PayPal_Gateway extends Base_Gateway {
'METHOD' => 'ManageRecurringPaymentsProfileStatus',
'PROFILEID' => $profile_id,
'ACTION' => 'Cancel',
);
];
$request = wp_remote_post(
$this->api_endpoint,
array(
[
'timeout' => 45,
'httpversion' => '1.1',
'body' => $args,
)
]
);
}
@ -720,7 +720,7 @@ class PayPal_Gateway extends Base_Gateway {
$amount_formatted = number_format($amount, 2);
$args = array(
$args = [
'USER' => $this->username,
'PWD' => $this->password,
'SIGNATURE' => $this->signature,
@ -729,7 +729,7 @@ class PayPal_Gateway extends Base_Gateway {
'REFUND_TYPE' => $refund_type,
'TRANSACTIONID' => $gateway_payment_id,
'INVOICEID' => $payment->get_hash(),
);
];
if ($refund_type === 'Partial') {
$args['AMT'] = $amount_formatted;
@ -737,11 +737,11 @@ class PayPal_Gateway extends Base_Gateway {
$request = wp_remote_post(
$this->api_endpoint,
array(
[
'timeout' => 45,
'httpversion' => '1.1',
'body' => $args,
)
]
);
$body = wp_remote_retrieve_body($request);
@ -802,7 +802,7 @@ class PayPal_Gateway extends Base_Gateway {
* @access public
* @return void
*/
public function process_confirmation() {
public function process_confirmation(): void {
/*
* Tries to retrieve the nonce, this part is necessary due EU SCA Compliancy.
*/
@ -905,7 +905,7 @@ class PayPal_Gateway extends Base_Gateway {
$customer = false;
$membership = false;
$custom = ! empty($posted['custom']) ? explode('|', (string) $posted['custom']) : array();
$custom = ! empty($posted['custom']) ? explode('|', (string) $posted['custom']) : [];
if (is_array($custom) && ! empty($custom)) {
$payment = wu_get_payment(absint($custom[0]));
@ -927,12 +927,12 @@ class PayPal_Gateway extends Base_Gateway {
* Base payment data for update
* or insertion.
*/
$payment_data = array(
$payment_data = [
'status' => Payment_Status::COMPLETED,
'customer_id' => $membership->get_customer_id(),
'membership_id' => $membership->get_id(),
'gateway' => $this->id,
);
];
$amount = isset($posted['mc_gross']) ? wu_to_float($posted['mc_gross']) : false;
@ -1112,7 +1112,7 @@ class PayPal_Gateway extends Base_Gateway {
case 'recurring_payment_suspended_due_to_max_failed_payment': // Same case as before
wu_log_add('paypal', 'Processing PayPal Express recurring_payment_failed or recurring_payment_suspended_due_to_max_failed_payment IPN.');
if ( ! in_array($membership->get_status(), array('cancelled', 'expired'), true)) {
if ( ! in_array($membership->get_status(), ['cancelled', 'expired'], true)) {
$membership->set_status('expired');
}
@ -1195,7 +1195,7 @@ class PayPal_Gateway extends Base_Gateway {
*/
protected function create_recurring_profile($details, $cart, $payment, $membership, $customer) {
$args = array(
$args = [
'USER' => $this->username,
'PWD' => $this->password,
'SIGNATURE' => $this->signature,
@ -1212,7 +1212,7 @@ class PayPal_Gateway extends Base_Gateway {
'L_BILLINGTYPE0' => 'RecurringPayments',
'DESC' => $this->get_subscription_description($cart),
'BUTTONSOURCE' => 'WP_Ultimo',
);
];
if ($args['INITAMT'] < 0) {
unset($args['INITAMT']);
@ -1236,11 +1236,11 @@ class PayPal_Gateway extends Base_Gateway {
$request = wp_remote_post(
$this->api_endpoint,
array(
[
'timeout' => 45,
'httpversion' => '1.1',
'body' => $args,
)
]
);
$body = wp_remote_retrieve_body($request);
@ -1272,8 +1272,8 @@ class PayPal_Gateway extends Base_Gateway {
* First, set the value
* and the transaction ID.
*/
$transaction_id = isset($body['TRANSACTIONID']) ? $body['TRANSACTIONID'] : '';
$profile_status = isset($body['PROFILESTATUS']) ? $body['PROFILESTATUS'] : '';
$transaction_id = $body['TRANSACTIONID'] ?? '';
$profile_status = $body['PROFILESTATUS'] ?? '';
// If TRANSACTIONID is not passed we need to wait for webhook
$payment_status = Payment_Status::PENDING;
@ -1287,10 +1287,10 @@ class PayPal_Gateway extends Base_Gateway {
*/
$transaction_id = empty($transaction_id) && ! empty($body['PROFILEID']) ? $body['PROFILEID'] : $transaction_id;
$payment_data = array(
$payment_data = [
'gateway_payment_id' => $transaction_id,
'status' => $payment_status,
);
];
/*
* Update local payment.
@ -1350,10 +1350,10 @@ class PayPal_Gateway extends Base_Gateway {
wp_die(
__('Something has gone wrong, please try again', 'wp-ultimo'),
__('Error', 'wp-ultimo'),
array(
[
'back_link' => true,
'response' => '401',
)
]
);
}
}
@ -1390,7 +1390,7 @@ class PayPal_Gateway extends Base_Gateway {
protected function complete_single_payment($details, $cart, $payment, $membership, $customer) {
// One time payment
$args = array(
$args = [
'USER' => $this->username,
'PWD' => $this->password,
'SIGNATURE' => $this->signature,
@ -1405,15 +1405,15 @@ class PayPal_Gateway extends Base_Gateway {
'PAYMENTREQUEST_0_TAXAMT' => 0,
'PAYMENTREQUEST_0_CURRENCYCODE' => $details['CURRENCYCODE'],
'BUTTONSOURCE' => 'WP_Ultimo',
);
];
$request = wp_remote_post(
$this->api_endpoint,
array(
[
'timeout' => 45,
'httpversion' => '1.1',
'body' => $args,
)
]
);
/*
@ -1447,10 +1447,10 @@ class PayPal_Gateway extends Base_Gateway {
*/
$transaction_id = $body['PAYMENTINFO_0_TRANSACTIONID'];
$payment_data = array(
$payment_data = [
'gateway_payment_id' => $transaction_id,
'status' => Payment_Status::COMPLETED,
);
];
/*
* Update local payment.
@ -1505,10 +1505,10 @@ class PayPal_Gateway extends Base_Gateway {
wp_die(
__('Something has gone wrong, please try again', 'wp-ultimo'),
__('Error', 'wp-ultimo'),
array(
[
'back_link' => true,
'response' => '401',
)
]
);
}
}
@ -1539,12 +1539,12 @@ class PayPal_Gateway extends Base_Gateway {
wu_get_template(
'checkout/paypal/confirm',
array(
[
'checkout_details' => $checkout_details,
'customer' => $customer,
'payment' => $checkout_details['pending_payment'],
'membership' => $checkout_details['pending_payment']->get_membership(),
)
]
);
}
/**
@ -1555,22 +1555,22 @@ class PayPal_Gateway extends Base_Gateway {
*/
public function get_checkout_details($token = '') {
$args = array(
$args = [
'TOKEN' => $token,
'USER' => $this->username,
'PWD' => $this->password,
'SIGNATURE' => $this->signature,
'VERSION' => '124',
'METHOD' => 'GetExpressCheckoutDetails',
);
];
$request = wp_remote_post(
$this->api_endpoint,
array(
[
'timeout' => 45,
'httpversion' => '1.1',
'body' => $args,
)
]
);
$body = wp_remote_retrieve_body($request);

View File

@ -39,53 +39,53 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
* @since 2.0.0
* @return void
*/
public function settings() {
public function settings(): void {
$error_message_wrap = '<span class="wu-p-2 wu-bg-red-100 wu-text-red-600 wu-rounded wu-mt-3 wu-mb-0 wu-block wu-text-xs">%s</span>';
wu_register_settings_field(
'payment-gateways',
'stripe_checkout_header',
array(
[
'title' => __('Stripe Checkout', 'wp-ultimo'),
'desc' => __('Use the settings section below to configure Stripe Checkout as a payment method.', 'wp-ultimo'),
'type' => 'header',
'show_as_submenu' => true,
'require' => array(
'require' => [
'active_gateways' => 'stripe-checkout',
),
)
],
]
);
wu_register_settings_field(
'payment-gateways',
'stripe_checkout_public_title',
array(
[
'title' => __('Stripe Public Name', 'wp-ultimo'),
'tooltip' => __('The name to display on the payment method selection field. By default, "Credit Card" is used.', 'wp-ultimo'),
'type' => 'text',
'default' => __('Credit Card', 'wp-ultimo'),
'require' => array(
'require' => [
'active_gateways' => 'stripe-checkout',
),
)
],
]
);
wu_register_settings_field(
'payment-gateways',
'stripe_checkout_sandbox_mode',
array(
[
'title' => __('Stripe Checkout Sandbox Mode', 'wp-ultimo'),
'desc' => __('Toggle this to put Stripe on sandbox mode. This is useful for testing and making sure Stripe is correctly setup to handle your payments.', 'wp-ultimo'),
'type' => 'toggle',
'default' => 1,
'html_attr' => array(
'html_attr' => [
'v-model' => 'stripe_checkout_sandbox_mode',
),
'require' => array(
],
'require' => [
'active_gateways' => 'stripe-checkout',
),
)
],
]
);
$pk_test_status = wu_get_setting('stripe_checkout_test_pk_key_status', '');
@ -93,7 +93,7 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
wu_register_settings_field(
'payment-gateways',
'stripe_checkout_test_pk_key',
array(
[
'title' => __('Stripe Test Publishable Key', 'wp-ultimo'),
'desc' => ! empty($pk_test_status) ? sprintf($error_message_wrap, $pk_test_status) : '',
'tooltip' => __('Make sure you are placing the TEST keys, not the live ones.', 'wp-ultimo'),
@ -101,11 +101,11 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
'type' => 'text',
'default' => '',
'capability' => 'manage_api_keys',
'require' => array(
'require' => [
'active_gateways' => 'stripe-checkout',
'stripe_checkout_sandbox_mode' => 1,
),
)
],
]
);
$sk_test_status = wu_get_setting('stripe_checkout_test_sk_key_status', '');
@ -113,7 +113,7 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
wu_register_settings_field(
'payment-gateways',
'stripe_checkout_test_sk_key',
array(
[
'title' => __('Stripe Test Secret Key', 'wp-ultimo'),
'desc' => ! empty($sk_test_status) ? sprintf($error_message_wrap, $sk_test_status) : '',
'tooltip' => __('Make sure you are placing the TEST keys, not the live ones.', 'wp-ultimo'),
@ -121,11 +121,11 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
'type' => 'text',
'default' => '',
'capability' => 'manage_api_keys',
'require' => array(
'require' => [
'active_gateways' => 'stripe-checkout',
'stripe_checkout_sandbox_mode' => 1,
),
)
],
]
);
$pk_status = wu_get_setting('stripe_checkout_live_pk_key_status', '');
@ -133,7 +133,7 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
wu_register_settings_field(
'payment-gateways',
'stripe_checkout_live_pk_key',
array(
[
'title' => __('Stripe Live Publishable Key', 'wp-ultimo'),
'desc' => ! empty($pk_status) ? sprintf($error_message_wrap, $pk_status) : '',
'tooltip' => __('Make sure you are placing the LIVE keys, not the test ones.', 'wp-ultimo'),
@ -141,11 +141,11 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
'type' => 'text',
'default' => '',
'capability' => 'manage_api_keys',
'require' => array(
'require' => [
'active_gateways' => 'stripe-checkout',
'stripe_checkout_sandbox_mode' => 0,
),
)
],
]
);
$sk_status = wu_get_setting('stripe_checkout_live_sk_key_status', '');
@ -153,7 +153,7 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
wu_register_settings_field(
'payment-gateways',
'stripe_checkout_live_sk_key',
array(
[
'title' => __('Stripe Live Secret Key', 'wp-ultimo'),
'desc' => ! empty($sk_status) ? sprintf($error_message_wrap, $sk_status) : '',
'tooltip' => __('Make sure you are placing the LIVE keys, not the test ones.', 'wp-ultimo'),
@ -161,11 +161,11 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
'type' => 'text',
'default' => '',
'capability' => 'manage_api_keys',
'require' => array(
'require' => [
'active_gateways' => 'stripe-checkout',
'stripe_checkout_sandbox_mode' => 0,
),
)
],
]
);
$webhook_message = sprintf('<span class="wu-p-2 wu-bg-blue-100 wu-text-blue-600 wu-rounded wu-mt-3 wu-mb-0 wu-block wu-text-xs">%s</span>', __('Whenever you change your Stripe settings, WP Multisite WaaS will automatically check the webhook URLs on your Stripe account to make sure we get notified about changes in subscriptions and payments.', 'wp-ultimo'));
@ -173,7 +173,7 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
wu_register_settings_field(
'payment-gateways',
'stripe_checkout_webhook_listener_explanation',
array(
[
'title' => __('Webhook Listener URL', 'wp-ultimo'),
'desc' => $webhook_message,
'tooltip' => __('This is the URL Stripe should send webhook calls to.', 'wp-ultimo'),
@ -181,10 +181,10 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
'copy' => true,
'default' => $this->get_webhook_listener_url(),
'wrapper_classes' => '',
'require' => array(
'require' => [
'active_gateways' => 'stripe-checkout',
),
)
],
]
);
parent::settings();
@ -244,17 +244,17 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
*/
$allowed_payment_method_types = apply_filters(
'wu_stripe_checkout_allowed_payment_method_types',
array(
[
'card',
),
],
$this
);
$metadata = array(
$metadata = [
'payment_id' => $this->payment->get_id(),
'membership_id' => $this->membership->get_id(),
'customer_id' => $this->customer->get_id(),
);
];
$this->membership->set_gateway_customer_id($s_customer->id);
$this->membership->set_gateway($this->get_id());
@ -277,7 +277,7 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
$metadata['swap_id'] = $swap_id;
}
$subscription_data = array(
$subscription_data = [
'payment_method_types' => $allowed_payment_method_types,
'success_url' => $redirect_url,
'cancel_url' => $this->get_cancel_url(),
@ -285,7 +285,7 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
'client_reference_id' => $this->customer->get_id(),
'customer' => $s_customer->id,
'metadata' => $metadata,
);
];
if ($this->order->should_auto_renew()) {
$stripe_cart = $this->build_stripe_cart($this->order);
@ -294,9 +294,9 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
/*
* Adds recurring stuff.
*/
$subscription_data['subscription_data'] = array(
$subscription_data['subscription_data'] = [
'items' => array_values($stripe_cart),
);
];
} else {
/*
* Create non-recurring only cart.
@ -316,9 +316,9 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
$s_coupon = $this->get_credit_coupon($this->order);
if ($s_coupon) {
$subscription_data['discounts'] = array(
array('coupon' => $s_coupon),
);
$subscription_data['discounts'] = [
['coupon' => $s_coupon],
];
}
/**
@ -350,9 +350,9 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
$session = Stripe\Checkout\Session::create($subscription_data);
// Add the client secret to the JSON success data.
return array(
return [
'stripe_session_id' => sanitize_text_field($session->id),
);
];
}
/**
@ -367,7 +367,7 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
* @since 2.0.0
* @return void
*/
public function process_confirmation() {
public function process_confirmation(): void {
$saved_swap = $this->get_saved_swap(wu_request('swap'));
@ -409,19 +409,19 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
*/
public function payment_methods() {
$fields = array();
$fields = [];
$card_options = $this->get_saved_card_options();
if ($card_options) {
foreach ($card_options as $payment_method => $card) {
$fields = array(
"payment_method_{$payment_method}" => array(
$fields = [
"payment_method_{$payment_method}" => [
'type' => 'text-display',
'title' => __('Saved Cards', 'wp-ultimo'),
'display_value' => $card,
),
);
],
];
}
}
@ -442,7 +442,7 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
$customer = wu_get_current_customer();
if ( ! $customer) {
return array();
return [];
}
$customer_id = $customer->get_id();
@ -457,14 +457,14 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
return $existing_payment_methods[ $customer_id ];
}
$customer_payment_methods = array();
$customer_payment_methods = [];
$stripe_customer_id = \WP_Ultimo\Models\Membership::query(
array(
[
'customer_id' => $customer_id,
'search' => 'cus_*',
'fields' => array('gateway_customer_id'),
)
'fields' => ['gateway_customer_id'],
]
);
$stripe_customer_id = current(array_column($stripe_customer_id, 'gateway_customer_id'));
@ -475,10 +475,10 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
$this->setup_api_keys();
$payment_methods = Stripe\PaymentMethod::all(
array(
[
'customer' => $stripe_customer_id,
'type' => 'card',
)
]
);
foreach ($payment_methods->data as $payment_method) {
@ -489,7 +489,7 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
return $existing_payment_methods[ $customer_id ];
} catch (\Throwable $exception) {
return array();
return [];
}
}
}

View File

@ -40,7 +40,7 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
* @since 2.0.0
* @return void
*/
public function hooks() {
public function hooks(): void {
parent::hooks();
@ -65,53 +65,53 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
* @since 2.0.0
* @return void
*/
public function settings() {
public function settings(): void {
$error_message_wrap = '<span class="wu-p-2 wu-bg-red-100 wu-text-red-600 wu-rounded wu-mt-3 wu-mb-0 wu-block wu-text-xs">%s</span>';
wu_register_settings_field(
'payment-gateways',
'stripe_header',
array(
[
'title' => __('Stripe', 'wp-ultimo'),
'desc' => __('Use the settings section below to configure Stripe as a payment method.', 'wp-ultimo'),
'type' => 'header',
'show_as_submenu' => true,
'require' => array(
'require' => [
'active_gateways' => 'stripe',
),
)
],
]
);
wu_register_settings_field(
'payment-gateways',
'stripe_public_title',
array(
[
'title' => __('Stripe Public Name', 'wp-ultimo'),
'tooltip' => __('The name to display on the payment method selection field. By default, "Credit Card" is used.', 'wp-ultimo'),
'type' => 'text',
'default' => __('Credit Card', 'wp-ultimo'),
'require' => array(
'require' => [
'active_gateways' => 'stripe',
),
)
],
]
);
wu_register_settings_field(
'payment-gateways',
'stripe_sandbox_mode',
array(
[
'title' => __('Stripe Sandbox Mode', 'wp-ultimo'),
'desc' => __('Toggle this to put Stripe on sandbox mode. This is useful for testing and making sure Stripe is correctly setup to handle your payments.', 'wp-ultimo'),
'type' => 'toggle',
'default' => 1,
'html_attr' => array(
'html_attr' => [
'v-model' => 'stripe_sandbox_mode',
),
'require' => array(
],
'require' => [
'active_gateways' => 'stripe',
),
)
],
]
);
$pk_test_status = wu_get_setting('stripe_test_pk_key_status', '');
@ -119,7 +119,7 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
wu_register_settings_field(
'payment-gateways',
'stripe_test_pk_key',
array(
[
'title' => __('Stripe Test Publishable Key', 'wp-ultimo'),
'desc' => ! empty($pk_test_status) ? sprintf($error_message_wrap, $pk_test_status) : '',
'tooltip' => __('Make sure you are placing the TEST keys, not the live ones.', 'wp-ultimo'),
@ -127,11 +127,11 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
'type' => 'text',
'default' => '',
'capability' => 'manage_api_keys',
'require' => array(
'require' => [
'active_gateways' => 'stripe',
'stripe_sandbox_mode' => 1,
),
)
],
]
);
$sk_test_status = wu_get_setting('stripe_test_sk_key_status', '');
@ -139,7 +139,7 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
wu_register_settings_field(
'payment-gateways',
'stripe_test_sk_key',
array(
[
'title' => __('Stripe Test Secret Key', 'wp-ultimo'),
'desc' => ! empty($sk_test_status) ? sprintf($error_message_wrap, $sk_test_status) : '',
'tooltip' => __('Make sure you are placing the TEST keys, not the live ones.', 'wp-ultimo'),
@ -147,11 +147,11 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
'type' => 'text',
'default' => '',
'capability' => 'manage_api_keys',
'require' => array(
'require' => [
'active_gateways' => 'stripe',
'stripe_sandbox_mode' => 1,
),
)
],
]
);
$pk_status = wu_get_setting('stripe_live_pk_key_status', '');
@ -159,7 +159,7 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
wu_register_settings_field(
'payment-gateways',
'stripe_live_pk_key',
array(
[
'title' => __('Stripe Live Publishable Key', 'wp-ultimo'),
'desc' => ! empty($pk_status) ? sprintf($error_message_wrap, $pk_status) : '',
'tooltip' => __('Make sure you are placing the LIVE keys, not the test ones.', 'wp-ultimo'),
@ -167,11 +167,11 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
'type' => 'text',
'default' => '',
'capability' => 'manage_api_keys',
'require' => array(
'require' => [
'active_gateways' => 'stripe',
'stripe_sandbox_mode' => 0,
),
)
],
]
);
$sk_status = wu_get_setting('stripe_live_sk_key_status', '');
@ -179,7 +179,7 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
wu_register_settings_field(
'payment-gateways',
'stripe_live_sk_key',
array(
[
'title' => __('Stripe Live Secret Key', 'wp-ultimo'),
'desc' => ! empty($sk_status) ? sprintf($error_message_wrap, $sk_status) : '',
'tooltip' => __('Make sure you are placing the LIVE keys, not the test ones.', 'wp-ultimo'),
@ -187,11 +187,11 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
'type' => 'text',
'default' => '',
'capability' => 'manage_api_keys',
'require' => array(
'require' => [
'active_gateways' => 'stripe',
'stripe_sandbox_mode' => 0,
),
)
],
]
);
$webhook_message = sprintf('<span class="wu-p-2 wu-bg-blue-100 wu-text-blue-600 wu-rounded wu-mt-3 wu-mb-0 wu-block wu-text-xs">%s</span>', __('Whenever you change your Stripe settings, WP Multisite WaaS will automatically check the webhook URLs on your Stripe account to make sure we get notified about changes in subscriptions and payments.', 'wp-ultimo'));
@ -199,7 +199,7 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
wu_register_settings_field(
'payment-gateways',
'stripe_webhook_listener_explanation',
array(
[
'title' => __('Webhook Listener URL', 'wp-ultimo'),
'desc' => $webhook_message,
'tooltip' => __('This is the URL Stripe should send webhook calls to.', 'wp-ultimo'),
@ -207,10 +207,10 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
'copy' => true,
'default' => $this->get_webhook_listener_url(),
'wrapper_classes' => '',
'require' => array(
'require' => [
'active_gateways' => 'stripe',
),
)
],
]
);
parent::settings();
@ -279,11 +279,11 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
$this->membership->save();
$intent_args = array(
$intent_args = [
'customer' => $s_customer->id,
'metadata' => $this->get_customer_metadata(),
'description' => $this->order->get_cart_descriptor(),
);
];
/*
* Maybe use an existing payment method.
@ -299,7 +299,7 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
* This should also be filterable, to allow support
* for Stripe Connect in the future.
*/
$intent_options = array();
$intent_options = [];
/*
* Tries to retrieve an existing intent id,
@ -325,7 +325,7 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
* payment attached to the membership. Those start with a pi_
* id.
*/
if ( ! empty($payment_intent_id) && strncmp((string) $payment_intent_id, 'pi_', strlen('pi_')) === 0) {
if ( ! empty($payment_intent_id) && str_starts_with((string) $payment_intent_id, 'pi_')) {
$existing_intent = Stripe\PaymentIntent::retrieve($payment_intent_id);
/*
@ -334,7 +334,7 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
* when we set up a subscription without a
* initial amount.
*/
} elseif ( ! empty($payment_intent_id) && strncmp((string) $payment_intent_id, 'seti_', strlen('seti_')) === 0) {
} elseif ( ! empty($payment_intent_id) && str_starts_with((string) $payment_intent_id, 'seti_')) {
$existing_intent = Stripe\SetupIntent::retrieve($payment_intent_id);
}
@ -355,13 +355,13 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
if ($this->order->get_total() && $this->order->has_trial() === false) {
$intent_args = wp_parse_args(
$intent_args,
array(
[
'amount' => $this->order->get_total() * wu_stripe_get_currency_multiplier(),
'confirmation_method' => 'automatic',
'setup_future_usage' => 'off_session',
'currency' => strtolower((string) wu_get_setting('currency_symbol', 'USD')),
'confirm' => false,
)
]
);
/**
@ -390,7 +390,7 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
$intent_options['idempotency_key'] = wu_stripe_generate_idempotency_key($idempotency_args);
// Unset some options we can't update.
$unset_args = array('confirmation_method', 'confirm');
$unset_args = ['confirmation_method', 'confirm'];
foreach ($unset_args as $unset_arg) {
if (isset($intent_args[ $unset_arg ])) {
@ -413,9 +413,9 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
*/
$intent_args = wp_parse_args(
$intent_args,
array(
[
'usage' => 'off_session',
)
]
);
if (empty($existing_intent) || 'setup_intent' !== $existing_intent->object) {
@ -463,10 +463,10 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
* Using this info, we'll be able to process
* the Stripe payment on the next step: process_checkout
*/
return array(
return [
'stripe_client_secret' => sanitize_text_field($intent->client_secret),
'stripe_intent_type' => sanitize_text_field($intent->object),
);
];
}
/**
@ -487,7 +487,7 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
*
* @return void
*/
public function process_checkout($payment, $membership, $customer, $cart, $type) {
public function process_checkout($payment, $membership, $customer, $cart, $type): void {
/*
* Here's the general idea
* of how the Stripe integration works.
@ -529,7 +529,7 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
* Get the correct intent
* type depending on the intent ID
*/
if (strncmp((string) $payment_intent_id, 'seti_', strlen('seti_')) === 0) {
if (str_starts_with((string) $payment_intent_id, 'seti_')) {
$is_setup_intent = true;
$payment_intent = Stripe\SetupIntent::retrieve($payment_intent_id);
@ -557,15 +557,15 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
*/
Stripe\Customer::update(
$s_customer->id,
array(
[
'address' => $this->convert_to_stripe_address($customer->get_billing_address()),
'description' => sanitize_text_field($description),
'metadata' => array(
'metadata' => [
'email' => $customer->get_email_address(),
'user_id' => $customer->get_user_id(),
'customer_id' => $customer->get_id(),
),
)
],
]
);
/*
@ -609,7 +609,7 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
$membership->set_gateway_customer_id($s_customer->id);
$membership->set_gateway_subscription_id($subscription->id);
$membership->add_to_times_billed(1);
$membership->should_auto_renew(true);
$membership->should_auto_renew();
if ($type !== 'downgrade') {
$membership_status = $cart->has_trial() ? Membership_Status::TRIALING : Membership_Status::ACTIVE;
@ -641,37 +641,37 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
*/
public function fields(): string {
$fields = array();
$fields = [];
$card_options = $this->get_saved_card_options();
if ($card_options) {
$card_options['add-new'] = __('Add new card', 'wp-ultimo');
$fields = array(
'payment_method' => array(
$fields = [
'payment_method' => [
'type' => 'radio',
'title' => __('Saved Payment Methods', 'wp-ultimo'),
'value' => wu_request('payment_method'),
'options' => $card_options,
'html_attr' => array(
'html_attr' => [
'v-model' => 'payment_method',
),
),
);
],
],
];
}
$stripe_form = new \WP_Ultimo\UI\Form(
'billing-address-fields',
$fields,
array(
[
'views' => 'checkout/fields',
'variables' => array(
'step' => (object) array(
'variables' => [
'step' => (object) [
'classes' => '',
),
),
)
],
],
]
);
ob_start();
@ -712,19 +712,19 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
*/
public function payment_methods() {
$fields = array();
$fields = [];
$card_options = $this->get_saved_card_options();
if ($card_options) {
foreach ($card_options as $payment_method => $card) {
$fields = array(
"payment_method_{$payment_method}" => array(
$fields = [
"payment_method_{$payment_method}" => [
'type' => 'text-display',
'title' => __('Saved Cards', 'wp-ultimo'),
'display_value' => $card,
),
);
],
];
}
}
@ -745,7 +745,7 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
$customer = wu_get_current_customer();
if ( ! $customer) {
return array();
return [];
}
$customer_id = $customer->get_id();
@ -760,14 +760,14 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
return $existing_payment_methods[ $customer_id ];
}
$customer_payment_methods = array();
$customer_payment_methods = [];
$stripe_customer_id = \WP_Ultimo\Models\Membership::query(
array(
[
'customer_id' => $customer_id,
'search' => 'cus_*',
'fields' => array('gateway_customer_id'),
)
'fields' => ['gateway_customer_id'],
]
);
$stripe_customer_id = current(array_column($stripe_customer_id, 'gateway_customer_id'));
@ -778,10 +778,10 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
$this->setup_api_keys();
$payment_methods = Stripe\PaymentMethod::all(
array(
[
'customer' => $stripe_customer_id,
'type' => 'card',
)
]
);
foreach ($payment_methods->data as $payment_method) {
@ -792,7 +792,7 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
return $existing_payment_methods[ $customer_id ];
} catch (\Throwable $exception) {
return array();
return [];
}
}
}