You are here

public function CheckoutTest::testCheckoutAndPayment in Commerce Stripe 8

Tests an anonymous customer can checkout.

This uses a card which does not trigger SCA or 3DS authentication.

@dataProvider dataProviderUserAuthenticated

File

tests/src/FunctionalJavascript/CheckoutTest.php, line 96

Class

CheckoutTest
Tests checkout with Stripe.

Namespace

Drupal\Tests\commerce_stripe\FunctionalJavascript

Code

public function testCheckoutAndPayment($authenticated) {
  if ($authenticated) {
    $customer = $this
      ->createUser();
    $this
      ->drupalLogin($customer);
  }
  $this
    ->drupalGet($this->product
    ->toUrl()
    ->toString());
  $this
    ->submitForm([], 'Add to cart');
  $this
    ->drupalGet('checkout/1');
  if (!$authenticated) {
    $this
      ->submitForm([], 'Continue as Guest');
    $this
      ->getSession()
      ->getPage()
      ->fillField('contact_information[email]', 'guest@example.com');
    $this
      ->getSession()
      ->getPage()
      ->fillField('contact_information[email_confirm]', 'guest@example.com');
  }
  $this
    ->fillCreditCardData('4242424242424242', '0322', '123');
  $this
    ->submitForm([
    'payment_information[add_payment_method][billing_information][address][0][address][given_name]' => 'Johnny',
    'payment_information[add_payment_method][billing_information][address][0][address][family_name]' => 'Appleseed',
    'payment_information[add_payment_method][billing_information][address][0][address][address_line1]' => '123 New York Drive',
    'payment_information[add_payment_method][billing_information][address][0][address][locality]' => 'New York City',
    'payment_information[add_payment_method][billing_information][address][0][address][administrative_area]' => 'NY',
    'payment_information[add_payment_method][billing_information][address][0][address][postal_code]' => '10001',
  ], 'Continue to review');
  $this
    ->assertWaitForText('Visa ending in 4242');
  $this
    ->assertWaitForText('Expires 3/2022');
  $this
    ->submitForm([], 'Pay and complete purchase');
  $this
    ->assertWaitForText('Your order number is 1. You can view your order on your account page when logged in.');
}