diff --git a/modules/payment_reference/src/Element/PaymentReferenceBase.php b/modules/payment_reference/src/Element/PaymentReferenceBase.php index a3a9fc1..2f3cff0 100644 --- a/modules/payment_reference/src/Element/PaymentReferenceBase.php +++ b/modules/payment_reference/src/Element/PaymentReferenceBase.php @@ -245,7 +245,7 @@ abstract class PaymentReferenceBase extends FormElement implements FormElementIn '#type' => 'payment_line_items_display', ); $build['payment_method'] = $payment_method_selector->buildConfigurationForm(array(), $form_state); - if (!$payment_method_selector->getPaymentMethod() || !$payment_method_selector->getPaymentMethod()->getPaymentExecutionResult()->hasCompleted()) { + if ($payment_method_selector->getPaymentMethod() && !$payment_method_selector->getPaymentMethod()->getPaymentExecutionResult()->hasCompleted()) { $this->disableChildren($build['payment_method']); } $this->getEntityFormDisplay($element, $form_state)->buildForm($payment_method_selector->getPayment(), $build, $form_state); @@ -409,7 +409,7 @@ abstract class PaymentReferenceBase extends FormElement implements FormElementIn $payment_method = $payment_method_selector->getPaymentMethod(); $build = array(); - if ($payment_method) { + if ($payment_method && !$payment_method->getPayment()->isNew()) { $build['message'] = array( '#markup' => $this->t('@payment_method_label requires the payment to be completed in a new window.', array( '@payment_method_label' => $payment_method->getPluginLabel(), @@ -458,6 +458,7 @@ abstract class PaymentReferenceBase extends FormElement implements FormElementIn $payment_method = $payment_method_selector->getPaymentMethod(); $payment->setPaymentMethod($payment_method); + $payment->save(); $result = $payment->execute(); if (!$result->hasCompleted() && !$this->requestStack->getCurrentRequest()->isXmlHttpRequest()) { $url = $payment->urlInfo('complete'); diff --git a/modules/payment_reference/src/Tests/Element/PaymentReferenceWebTest.php b/modules/payment_reference/src/Tests/Element/PaymentReferenceWebTest.php index 89fc05c..2d80da6 100644 --- a/modules/payment_reference/src/Tests/Element/PaymentReferenceWebTest.php +++ b/modules/payment_reference/src/Tests/Element/PaymentReferenceWebTest.php @@ -86,7 +86,7 @@ class PaymentReferenceWebTest extends WebTestBase { $value = $state->get('payment_reference_test_payment_reference_element'); $this->assertNull($value); - // Test with a non-interruptive payment method. + // Test with a payment method that returns no execution completion response. $text_field_value = $this->randomMachineName(); $this->drupalPostForm($path, array( 'payment_reference[container][payment_form][payment_method][container][select][container][payment_method_id]' => 'payment_test_no_response', @@ -101,16 +101,14 @@ class PaymentReferenceWebTest extends WebTestBase { $this->assertTrue($payment instanceof PaymentInterface); $this->assertEqual($payment->get('quxfoobar')[0]->get('value')->getValue(), $text_field_value); - // Test with an interruptive payment method. + // Test with a payment method that returns an execution completion response. $text_field_value = $this->randomMachineName(); - // @todo Once Behat is supported, test the behavior of opening a new window - // and going back to the original form. $this->drupalPostForm($path, array( 'payment_reference[container][payment_form][payment_method][container][select][container][payment_method_id]' => 'payment_test_response', 'payment_reference[container][payment_form][quxfoobar][0][value]' => $text_field_value, ), t('Choose payment method')); $this->drupalPostForm(NULL, array(), t('Pay')); - $this->clickLink(t('Complete payment')); + $this->clickLink(t('Complete payment (opens in a new window).')); /** @var \Drupal\payment\Entity\PaymentInterface $payment */ $payment = Payment::loadMultiple()[2]; $this->assertEqual($payment->getPaymentStatus()->getPluginId(), 'payment_success');