Skip to content
Snippets Groups Projects

Rerolled patch. #2998065 @MrDaleSmith

Open arne michiels requested to merge issue/commerce-2998065:2998065-ensure-all-calls-3 into 3.x
Files
3
@@ -137,7 +137,7 @@ class PaymentInformation extends PaymentCheckoutPaneBase {
/** @var \Drupal\commerce_payment\Entity\PaymentGatewayInterface $payment_gateway */
$payment_gateway = $this->order->get('payment_gateway')->entity;
$summary = [];
if ($this->collectBillingProfileOnly() || !$payment_gateway) {
if (!$this->needsPayment()) {
if ($billing_profile) {
// Only the billing information was collected.
$view_builder = $this->entityTypeManager->getViewBuilder('profile');
@@ -175,10 +175,9 @@ class PaymentInformation extends PaymentCheckoutPaneBase {
* {@inheritdoc}
*/
public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &$complete_form) {
if ($this->collectBillingProfileOnly()) {
// No payment is needed if we don't require payment method collection,
// and the order balance is zero. In that case, collect just the billing
// information.
if (!$this->order->getTotalPrice() || !$this->needsPayment() ) {
// No payment is needed if the order is free or has already been paid.
// In that case, collect just the billing information.
$pane_form['#title'] = $this->t('Billing information');
$pane_form = $this->buildBillingProfileForm($pane_form, $form_state);
return $pane_form;
@@ -386,7 +385,7 @@ class PaymentInformation extends PaymentCheckoutPaneBase {
* {@inheritdoc}
*/
public function validatePaneForm(array &$pane_form, FormStateInterface $form_state, array &$complete_form) {
if ($this->collectBillingProfileOnly()) {
if (!$this->order->getTotalPrice() || !$this->needsPayment()) {
return;
}
@@ -409,7 +408,7 @@ class PaymentInformation extends PaymentCheckoutPaneBase {
// The billing profile is provided either because the order is free,
// or the selected gateway does not support stored payment methods.
// If it's the former, stop here.
if ($this->collectBillingProfileOnly()) {
if (!$this->needsPayment()) {
return;
}
}
@@ -514,4 +513,26 @@ class PaymentInformation extends PaymentCheckoutPaneBase {
return $message;
}
/**
* Checks whether or not the order still needs payment.
*
* The order doesn't needs payment if:
* - The order is already paid;
* - The order has no total price;
* - The order has a total price of zero.
*
* @return bool
* TRUE if the order still need to be paid, FALSE otherwise.
*/
protected function needsPayment() {
if ($this->order->isPaid()) {
return FALSE;
}
if (!$this->order->getTotalPrice() || $this->order->getTotalPrice()->isZero()) {
// No total price or a total price of zero.
return FALSE;
}
return TRUE;
}
}
Loading