Everywhere yoda conditions are
This commit is contained in:
@ -167,7 +167,7 @@ abstract class Base_Gateway {
|
||||
*/
|
||||
public function set_order($order): void {
|
||||
|
||||
if ($order === null) {
|
||||
if (null === $order) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -784,7 +784,7 @@ abstract class Base_Gateway {
|
||||
*/
|
||||
public function trigger_payment_processed($payment, $membership = null): void {
|
||||
|
||||
if ($membership === null) {
|
||||
if (null === $membership) {
|
||||
$membership = $payment->get_membership();
|
||||
}
|
||||
|
||||
|
@ -1313,7 +1313,7 @@ class Base_Stripe_Gateway extends Base_Gateway {
|
||||
/*
|
||||
* Skip recurring items
|
||||
*/
|
||||
if ($line_item->is_recurring() && $include_recurring_products === false) {
|
||||
if ($line_item->is_recurring() && false === $include_recurring_products) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -1626,21 +1626,21 @@ class Base_Stripe_Gateway extends Base_Gateway {
|
||||
// Legacy WP Multisite WaaS uses user_id
|
||||
$user_id = (int) $subscription->metadata['user_id'];
|
||||
|
||||
if ($customer_id === 0 && $user_id === 0) {
|
||||
if (0 === $customer_id && 0 === $user_id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($customer_id !== $this->customer->get_id() && $user_id !== $this->customer->get_user_id()) {
|
||||
if ($this->customer->get_id() !== $customer_id && $this->customer->get_user_id() !== $user_id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$membership_id = (int) $subscription->metadata['membership_id'];
|
||||
|
||||
if ($allow_multiple_membership && $membership_id !== $this->membership->get_id()) {
|
||||
if ($allow_multiple_membership && $this->membership->get_id() !== $membership_id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($membership_id === 0 && $customer_id === 0) {
|
||||
if (0 === $membership_id && 0 === $customer_id) {
|
||||
/**
|
||||
* If we do not have a $membership_id it can be a legacy subscription.
|
||||
* The best way to check this is checking if the plan in Stripe haves
|
||||
@ -1666,7 +1666,7 @@ class Base_Stripe_Gateway extends Base_Gateway {
|
||||
}
|
||||
|
||||
// Check if membership exist and is from this customer before delete subscription
|
||||
if ($membership_id !== 0 && $membership_id !== $this->membership->get_id()) {
|
||||
if (0 !== $membership_id && $this->membership->get_id() !== $membership_id) {
|
||||
$membership_from_s = wu_get_membership($membership_id);
|
||||
|
||||
if ( ! $membership_from_s || $membership_from_s->get_customer_id() !== $customer_id) {
|
||||
@ -2214,14 +2214,14 @@ class Base_Stripe_Gateway extends Base_Gateway {
|
||||
|
||||
$old_subtotal = $payment_data['subtotal'];
|
||||
|
||||
if ($type === 'percentage') {
|
||||
if ('percentage' === $type) {
|
||||
$payment_data['subtotal'] = $old_subtotal / (1 - ($discount_code->get_value() / 100));
|
||||
|
||||
$discount_total = $payment_data['subtotal'] - $old_subtotal;
|
||||
} elseif ($type === 'absolute') {
|
||||
} elseif ('absolute' === $type) {
|
||||
$discount_total = $discount_code->get_value();
|
||||
|
||||
$payment_data['subtotal'] = $payment_data['subtotal'] - $discount_total;
|
||||
$payment_data['subtotal'] -= $discount_total;
|
||||
}
|
||||
|
||||
// Now we apply this discount to the line items.
|
||||
@ -2773,7 +2773,7 @@ class Base_Stripe_Gateway extends Base_Gateway {
|
||||
*/
|
||||
function maybe_create_price($title, $amount, $currency, $quantity = 1, $duration = false, $duration_unit = false, $tax_behavior = '') {
|
||||
|
||||
$name = $quantity === 1 ? $title : "x$quantity $title";
|
||||
$name = 1 === $quantity ? $title : "x$quantity $title";
|
||||
|
||||
$currency = strtolower($currency);
|
||||
$s_amount = round($amount * wu_stripe_get_currency_multiplier());
|
||||
|
@ -66,7 +66,7 @@ class Free_Gateway extends Base_Gateway {
|
||||
$membership->set_gateway($this->get_id());
|
||||
$membership->set_auto_renew(false);
|
||||
|
||||
if ($type === 'downgrade' && ($membership_status === Membership_Status::ACTIVE || $membership_status === Membership_Status::TRIALING)) {
|
||||
if ('downgrade' === $type && (Membership_Status::ACTIVE === $membership_status || Membership_Status::TRIALING === $membership_status)) {
|
||||
/*
|
||||
* When downgrading, we need to schedule a swap for the end of the
|
||||
* current expiration date.
|
||||
@ -79,7 +79,7 @@ class Free_Gateway extends Base_Gateway {
|
||||
$status = $membership->save();
|
||||
|
||||
return;
|
||||
} elseif ($type === 'upgrade' || $type === 'downgrade' || $type === 'addon') {
|
||||
} elseif ('upgrade' === $type || 'downgrade' === $type || 'addon' === $type) {
|
||||
/*
|
||||
* A change to another free membership
|
||||
* is a upgrade and if membership is not
|
||||
|
@ -215,13 +215,13 @@ class Manual_Gateway extends Base_Gateway {
|
||||
* simply throw a exception and WP Multisite WaaS will
|
||||
* catch it and rollback any changes.
|
||||
*/
|
||||
if ($type === 'new') {
|
||||
if ('new' === $type) {
|
||||
|
||||
// Your logic here.
|
||||
} elseif ($type === 'renewal') {
|
||||
} elseif ('renewal' === $type) {
|
||||
|
||||
// Your logic here.
|
||||
} elseif ($type === 'downgrade') {
|
||||
} elseif ('downgrade' === $type) {
|
||||
/*
|
||||
* When downgrading, we need to schedule a swap for the end of the
|
||||
* current expiration date.
|
||||
@ -238,7 +238,7 @@ class Manual_Gateway extends Base_Gateway {
|
||||
* Saves the membership with the changes.
|
||||
*/
|
||||
$status = $membership->save();
|
||||
} elseif ($type === 'upgrade' || $type === 'addon') {
|
||||
} elseif ('upgrade' === $type || 'addon' === $type) {
|
||||
/*
|
||||
* After everything is said and done,
|
||||
* we need to swap the membership to the new products
|
||||
|
@ -27,14 +27,17 @@ class PayPal_Gateway extends Base_Gateway {
|
||||
* @var string
|
||||
*/
|
||||
public $error_message;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $webhook_event_id;
|
||||
|
||||
/**
|
||||
* @var \WP_Ultimo\Models\Payment
|
||||
*/
|
||||
public $payment;
|
||||
|
||||
/**
|
||||
* Holds the ID of a given gateway.
|
||||
*
|
||||
@ -517,7 +520,7 @@ class PayPal_Gateway extends Base_Gateway {
|
||||
$recurring_total_format = wu_format_currency($recurring_total, $cart->get_currency());
|
||||
|
||||
if ($recurring_total !== $cart_total) {
|
||||
if ($type === 'downgrade') {
|
||||
if ('downgrade' === $type) {
|
||||
if ($is_trial_setup) {
|
||||
$notes[] = sprintf(__('Your updated membership will start on $1$s, from that date you will be billed %2$s every month.', 'wp-ultimo'), $date, $recurring_total_format);
|
||||
} else {
|
||||
@ -561,8 +564,8 @@ class PayPal_Gateway extends Base_Gateway {
|
||||
"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;
|
||||
$args['PAYMENTREQUEST_0_ITEMAMT'] += $sub_total;
|
||||
$args['PAYMENTREQUEST_0_TAXAMT'] += $tax_amount;
|
||||
$args['PAYMENTREQUEST_0_AMT'] = $args['PAYMENTREQUEST_0_AMT'] + $sub_total + $tax_amount;
|
||||
|
||||
$args = array_merge($args, $product_args);
|
||||
@ -584,8 +587,8 @@ class PayPal_Gateway extends Base_Gateway {
|
||||
]
|
||||
);
|
||||
|
||||
$args['PAYMENTREQUEST_0_ITEMAMT'] = $args['PAYMENTREQUEST_0_ITEMAMT'] + $discounts_total;
|
||||
$args['PAYMENTREQUEST_0_AMT'] = $args['PAYMENTREQUEST_0_AMT'] + $discounts_total;
|
||||
$args['PAYMENTREQUEST_0_ITEMAMT'] += $discounts_total;
|
||||
$args['PAYMENTREQUEST_0_AMT'] += $discounts_total;
|
||||
|
||||
++$product_index;
|
||||
}
|
||||
@ -731,7 +734,7 @@ class PayPal_Gateway extends Base_Gateway {
|
||||
'INVOICEID' => $payment->get_hash(),
|
||||
];
|
||||
|
||||
if ($refund_type === 'Partial') {
|
||||
if ('Partial' === $refund_type) {
|
||||
$args['AMT'] = $amount_formatted;
|
||||
}
|
||||
|
||||
@ -773,6 +776,7 @@ class PayPal_Gateway extends Base_Gateway {
|
||||
|
||||
throw new \Exception(__('Something went wrong.', 'wp-ultimo'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds additional fields to the checkout form for a particular gateway.
|
||||
*
|
||||
@ -890,6 +894,7 @@ class PayPal_Gateway extends Base_Gateway {
|
||||
$this->confirmation_form();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process webhooks
|
||||
*
|
||||
@ -936,7 +941,7 @@ class PayPal_Gateway extends Base_Gateway {
|
||||
|
||||
$amount = isset($posted['mc_gross']) ? wu_to_float($posted['mc_gross']) : false;
|
||||
|
||||
if ($amount !== false) {
|
||||
if (false !== $amount) {
|
||||
$payment_data['amount'] = $amount;
|
||||
}
|
||||
|
||||
@ -1278,7 +1283,7 @@ class PayPal_Gateway extends Base_Gateway {
|
||||
// If TRANSACTIONID is not passed we need to wait for webhook
|
||||
$payment_status = Payment_Status::PENDING;
|
||||
|
||||
if ( ! empty($transaction_id) || $profile_status === 'ActiveProfile' || $is_trial_setup) {
|
||||
if ( ! empty($transaction_id) || 'ActiveProfile' === $profile_status || $is_trial_setup) {
|
||||
$payment_status = Payment_Status::COMPLETED;
|
||||
}
|
||||
|
||||
@ -1311,7 +1316,7 @@ class PayPal_Gateway extends Base_Gateway {
|
||||
$membership->set_gateway_customer_id($details['PAYERID']);
|
||||
$membership->set_gateway('paypal');
|
||||
|
||||
if ($payment_status === Payment_Status::COMPLETED) {
|
||||
if (Payment_Status::COMPLETED === $payment_status) {
|
||||
$membership->add_to_times_billed(1);
|
||||
|
||||
/*
|
||||
@ -1547,6 +1552,7 @@ class PayPal_Gateway extends Base_Gateway {
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get checkout details.
|
||||
*
|
||||
|
@ -389,6 +389,7 @@ class Stripe_Checkout_Gateway extends Base_Stripe_Gateway {
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add credit card fields.
|
||||
*
|
||||
|
@ -271,9 +271,9 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
|
||||
* Here, we just need to make sure we process
|
||||
* a membership swap.
|
||||
*/
|
||||
if ($type === 'upgrade' || $type === 'addon') {
|
||||
if ('upgrade' === $type || 'addon' === $type) {
|
||||
$this->membership->swap($this->order);
|
||||
} elseif ($type === 'downgrade') {
|
||||
} elseif ('downgrade' === $type) {
|
||||
$this->membership->schedule_swap($this->order);
|
||||
}
|
||||
|
||||
@ -611,7 +611,7 @@ class Stripe_Gateway extends Base_Stripe_Gateway {
|
||||
$membership->add_to_times_billed(1);
|
||||
$membership->should_auto_renew();
|
||||
|
||||
if ($type !== 'downgrade') {
|
||||
if ('downgrade' !== $type) {
|
||||
$membership_status = $cart->has_trial() ? Membership_Status::TRIALING : Membership_Status::ACTIVE;
|
||||
|
||||
$renewal_date = new \DateTime();
|
||||
|
Reference in New Issue
Block a user