Skip to content
Snippets Groups Projects
Commit 1176a7ba authored by Wayne Eaker's avatar Wayne Eaker
Browse files

Issue #3437950 by zengenuity: Drupal 10 Compatibility

parent 62e952f7
No related branches found
No related tags found
No related merge requests found
name: Commerce Multiple Payments
type: module
description: Allows multiple payments at checkout for supported payment gateways.
core_version_requirement: ^8.8 || ^9
core_version_requirement: ^9 || ^10
package: Commerce
dependencies:
......
name: 'Commerce Multiple Payments: Example Payment Gateways'
type: module
description: Example payment gateways that support Drupal Commerce multiple payments.
core_version_requirement: ^8.8 || ^9
core_version_requirement: ^9 || ^10
package: Commerce
dependencies:
......
......@@ -114,7 +114,7 @@ class GiftCardForm extends InlineFormBase {
'#title' => t('@label @number: @balance available', [
'@label' => $payment_gateway_plugin->multiPaymentDisplayLabel(),
'@number' => $staged_payment->getData('remote_id'),
'@balance' => render($formatted_balance),
'@balance' => \Drupal::service('renderer')->render($formatted_balance),
]),
];
......
......@@ -136,7 +136,7 @@ class StoreCreditForm extends InlineFormBase {
'#open' => !empty($staged_payment),
'#title' => t('@label: @balance available', [
'@label' => $payment_gateway_plugin->multiPaymentDisplayLabel(),
'@balance' => render($formatted_balance),
'@balance' => \Drupal::service('renderer')->render($formatted_balance),
]),
];
......
......@@ -2,6 +2,7 @@
namespace Drupal\commerce_multi_payment;
use CommerceGuys\Intl\Formatter\NumberFormatterInterface;
use Drupal\commerce_price\Entity\Currency;
use Drupal\commerce_price\NumberFormatterFactoryInterface;
use Drupal\Core\Entity\EntityInterface;
......@@ -43,11 +44,11 @@ class StagedPaymentListBuilder extends EntityListBuilder {
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The current route match.
*/
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, RouteMatchInterface $route_match, NumberFormatterFactoryInterface $number_formatter_factory) {
public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, RouteMatchInterface $route_match, NumberFormatterInterface $number_formatter) {
parent::__construct($entity_type, $storage);
$this->routeMatch = $route_match;
$this->numberFormatter = $number_formatter_factory->createInstance();
$this->numberFormatter = $number_formatter;
}
/**
......@@ -58,7 +59,7 @@ class StagedPaymentListBuilder extends EntityListBuilder {
$entity_type,
$container->get('entity_type.manager')->getStorage($entity_type->id()),
$container->get('current_route_match'),
$container->get('commerce_price.number_formatter_factory')
$container->get('commerce_price.number_formatter')
);
}
......
......@@ -44,7 +44,7 @@ class MultiplePaymentsCheckoutTest extends CommerceWebDriverTestBase {
*
* @var array
*/
public static $modules = [
protected static $modules = [
'commerce_product',
'commerce_cart',
'commerce_checkout',
......@@ -213,26 +213,26 @@ class MultiplePaymentsCheckoutTest extends CommerceWebDriverTestBase {
// Add gift card
$this->getSession()->getPage()->fillField('multi_payment_apply[form][gift_card][new][gift_card_number]', '3111');
$this->getSession()->getPage()->pressButton('add_gift_card_gift_card');
$this->waitForAjaxToFinish();
$this->waitForAjaxToFinishLocal();
$this->assertTrue($this->orderAdjustmentExists('Gift card: 3111', '-$500.00'));
$this->assertEquals('$250.00', $this->getOrderTotalFromSummary());
// Try to apply same gift card again. Should only be one.
$this->getSession()->getPage()->fillField('multi_payment_apply[form][gift_card][new][gift_card_number]', '3111');
$this->getSession()->getPage()->pressButton('add_gift_card_gift_card');
$this->waitForAjaxToFinish();
$this->waitForAjaxToFinishLocal();
$this->assertSession()->pageTextContains('This gift card has already been added to the order.');
// Try to apply an invalid gift card.
$this->getSession()->getPage()->fillField('multi_payment_apply[form][gift_card][new][gift_card_number]', '3222');
$this->getSession()->getPage()->pressButton('add_gift_card_gift_card');
$this->waitForAjaxToFinish();
$this->waitForAjaxToFinishLocal();
$this->assertSession()->pageTextContains('Gift card 3222 has been declined.');
// Add a second gift card to the order
$this->getSession()->getPage()->fillField('multi_payment_apply[form][gift_card][new][gift_card_number]', '5111');
$this->getSession()->getPage()->pressButton('add_gift_card_gift_card');
$this->waitForAjaxToFinish();
$this->waitForAjaxToFinishLocal();
$this->assertSession()->pageTextNotContains('This gift card has already been added to the order.');
$this->assertSession()->pageTextNotContains('Gift card 3222 has been declined.');
$this->assertTrue($this->orderAdjustmentExists('Gift card: 5111', '-$250.00'));
......@@ -251,14 +251,14 @@ class MultiplePaymentsCheckoutTest extends CommerceWebDriverTestBase {
$apply_button_field_name = 'apply_gift_card_payment_' . $stored_payment_id;
$this->getSession()->getPage()->fillField($amount_field_name, '400');
$this->getSession()->getPage()->pressButton($apply_button_field_name);
$this->waitForAjaxToFinish();
$this->waitForAjaxToFinishLocal();
$this->assertTrue($this->orderAdjustmentExists('Gift card: 5111', '-$250.00'));
$this->assertEquals('250.00', $gift_card_details[1]->find('xpath', $css_selector_converter->toXPath('input[type=text]'))->getAttribute('value'));
// Remove the second gift card
$remove_button_field_name = 'remove_gift_card_payment_' . $stored_payment_id;
$this->getSession()->getPage()->pressButton($remove_button_field_name);
$this->waitForAjaxToFinish();
$this->waitForAjaxToFinishLocal();
$this->assertFalse($this->orderAdjustmentExists('Gift card: 5111'));
$this->assertTrue($this->orderAdjustmentExists('Gift card: 3111', '-$500.00'));
......@@ -275,7 +275,7 @@ class MultiplePaymentsCheckoutTest extends CommerceWebDriverTestBase {
$this->getSession()->getPage()->find('xpath', $xpath)->click();
$this->getSession()->getPage()->fillField('multi_payment_apply[form][store_credit][store_credit][amount][number]', '250');
$this->getSession()->getPage()->pressButton('store_credit_apply_store_credit_payment');
$this->waitForAjaxToFinish();
$this->waitForAjaxToFinishLocal();
$this->assertTrue($this->orderAdjustmentExists('Store credit', '-$250.00'));
$this->assertEquals('$0.00', $this->getOrderTotalFromSummary());
......@@ -302,7 +302,7 @@ class MultiplePaymentsCheckoutTest extends CommerceWebDriverTestBase {
// Add gift card
$this->getSession()->getPage()->fillField('multi_payment_apply[form][gift_card][new][gift_card_number]', '3111');
$this->getSession()->getPage()->pressButton('add_gift_card_gift_card');
$this->waitForAjaxToFinish();
$this->waitForAjaxToFinishLocal();
$this->assertTrue($this->orderAdjustmentExists('Gift card: 3111', '-$500.00'));
$this->assertEquals('$250.00', $this->getOrderTotalFromSummary());
......@@ -316,7 +316,7 @@ class MultiplePaymentsCheckoutTest extends CommerceWebDriverTestBase {
// Add a second gift card for a small amount.
$this->getSession()->getPage()->fillField('multi_payment_apply[form][gift_card][new][gift_card_number]', '5111');
$this->getSession()->getPage()->pressButton('add_gift_card_gift_card');
$this->waitForAjaxToFinish();
$this->waitForAjaxToFinishLocal();
$this->assertTrue($this->orderAdjustmentExists('Gift card: 5111', '-$250.00'));
$xpath = $css_selector_converter->toXPath('#edit-multi-payment-apply #edit-multi-payment-apply-form-gift-card details');
......@@ -328,7 +328,7 @@ class MultiplePaymentsCheckoutTest extends CommerceWebDriverTestBase {
$apply_button_field_name = 'apply_gift_card_payment_' . $stored_payment_id;
$this->getSession()->getPage()->fillField($amount_field_name, '50');
$this->getSession()->getPage()->pressButton($apply_button_field_name);
$this->waitForAjaxToFinish();
$this->waitForAjaxToFinishLocal();
$this->assertTrue($this->orderAdjustmentExists('Gift card: 5111', '-$50.00'));
// Go to review page, check for both cards listed.
......@@ -342,7 +342,7 @@ class MultiplePaymentsCheckoutTest extends CommerceWebDriverTestBase {
$this->getSession()->getPage()->find('xpath', $xpath)->click();
$this->getSession()->getPage()->fillField('multi_payment_apply[form][store_credit][store_credit][amount][number]', '200');
$this->getSession()->getPage()->pressButton('store_credit_apply_store_credit_payment');
$this->waitForAjaxToFinish();
$this->waitForAjaxToFinishLocal();
$this->assertTrue($this->orderAdjustmentExists('Store credit', '-$200.00'));
// Go to review page, check that all payments are shown.
......@@ -369,7 +369,7 @@ class MultiplePaymentsCheckoutTest extends CommerceWebDriverTestBase {
// Add gift card
$this->getSession()->getPage()->fillField('multi_payment_apply[form][gift_card][new][gift_card_number]', '3111');
$this->getSession()->getPage()->pressButton('add_gift_card_gift_card');
$this->waitForAjaxToFinish();
$this->waitForAjaxToFinishLocal();
$this->assertTrue($this->orderAdjustmentExists('Gift card: 3111', '-$500.00'));
$this->assertEquals('$250.00', $this->getOrderTotalFromSummary());
......@@ -378,7 +378,7 @@ class MultiplePaymentsCheckoutTest extends CommerceWebDriverTestBase {
$this->getSession()->getPage()->find('xpath', $xpath)->click();
$this->getSession()->getPage()->fillField('multi_payment_apply[form][store_credit][store_credit][amount][number]', '200');
$this->getSession()->getPage()->pressButton('store_credit_apply_store_credit_payment');
$this->waitForAjaxToFinish();
$this->waitForAjaxToFinishLocal();
$this->assertTrue($this->orderAdjustmentExists('Store credit', '-$200.00'));
$this->assertEquals('$50.00', $this->getOrderTotalFromSummary());
......@@ -436,7 +436,7 @@ class MultiplePaymentsCheckoutTest extends CommerceWebDriverTestBase {
// Add gift card
$this->getSession()->getPage()->fillField('multi_payment_apply[form][gift_card][new][gift_card_number]', '3111');
$this->getSession()->getPage()->pressButton('add_gift_card_gift_card');
$this->waitForAjaxToFinish();
$this->waitForAjaxToFinishLocal();
$this->assertTrue($this->orderAdjustmentExists('Gift card: 3111', '-$500.00'));
$this->assertEquals('$250.00', $this->getOrderTotalFromSummary());
......@@ -445,7 +445,7 @@ class MultiplePaymentsCheckoutTest extends CommerceWebDriverTestBase {
$this->getSession()->getPage()->find('xpath', $xpath)->click();
$this->getSession()->getPage()->fillField('multi_payment_apply[form][store_credit][store_credit][amount][number]', '250');
$this->getSession()->getPage()->pressButton('store_credit_apply_store_credit_payment');
$this->waitForAjaxToFinish();
$this->waitForAjaxToFinishLocal();
$this->assertTrue($this->orderAdjustmentExists('Store credit', '-$250.00'));
$this->assertEquals('$0.00', $this->getOrderTotalFromSummary());
......@@ -512,7 +512,7 @@ class MultiplePaymentsCheckoutTest extends CommerceWebDriverTestBase {
// Add gift card
$this->getSession()->getPage()->fillField('multi_payment_apply[form][gift_card][new][gift_card_number]', '3111');
$this->getSession()->getPage()->pressButton('add_gift_card_gift_card');
$this->waitForAjaxToFinish();
$this->waitForAjaxToFinishLocal();
$this->assertTrue($this->orderAdjustmentExists('Gift card: 3111', '-$500.00'));
$this->assertEquals('$250.00', $this->getOrderTotalFromSummary());
......@@ -521,7 +521,7 @@ class MultiplePaymentsCheckoutTest extends CommerceWebDriverTestBase {
$this->getSession()->getPage()->find('xpath', $xpath)->click();
$this->getSession()->getPage()->fillField('multi_payment_apply[form][store_credit][store_credit][amount][number]', '200');
$this->getSession()->getPage()->pressButton('store_credit_apply_store_credit_payment');
$this->waitForAjaxToFinish();
$this->waitForAjaxToFinishLocal();
$this->assertTrue($this->orderAdjustmentExists('Store credit', '-$200.00'));
$this->assertEquals('$50.00', $this->getOrderTotalFromSummary());
......@@ -685,4 +685,9 @@ class MultiplePaymentsCheckoutTest extends CommerceWebDriverTestBase {
return $cart;
}
protected function waitForAjaxToFinishLocal() {
$condition = "(0 === jQuery.active && 0 === jQuery(':animated').length)";
$this->assertJsCondition($condition, 10000);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment