View source
<?php
namespace Drupal\Tests\commerce_authnet\FunctionalJavascript;
use Drupal\commerce_payment\Entity\PaymentGateway;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Url;
use Drupal\Tests\commerce\FunctionalJavascript\CommerceWebDriverTestBase;
class CheckoutTest extends CommerceWebDriverTestBase {
protected $account;
protected $product;
public static $modules = [
'commerce_checkout',
'commerce_authnet',
];
protected function setUp() : void {
parent::setUp();
$variation = $this
->createEntity('commerce_product_variation', [
'type' => 'default',
'sku' => strtolower($this
->randomMachineName()),
'price' => [
'number' => '9.99',
'currency_code' => 'USD',
],
]);
$this->product = $this
->createEntity('commerce_product', [
'type' => 'default',
'title' => 'My product',
'variations' => [
$variation,
],
'stores' => [
$this->store,
],
]);
$gateway = PaymentGateway::create([
'id' => 'authorize_net_us',
'label' => 'Authorize.net US',
'plugin' => 'authorizenet_acceptjs',
]);
$gateway
->getPlugin()
->setConfiguration([
'api_login' => '5KP3u95bQpv',
'transaction_key' => '346HZ32z3fP4hTG2',
'mode' => 'test',
'payment_method_types' => [
'credit_card',
],
'client_key' => 'test-client-key',
]);
$gateway
->save();
$customer_form_display = EntityFormDisplay::load('profile.customer.default');
$address_component = $customer_form_display
->getComponent('address');
$address_component['settings']['default_country'] = 'US';
$customer_form_display
->setComponent('address', $address_component);
$customer_form_display
->save();
}
public function testGuestAuthorizeNetPayment() {
$this
->drupalLogout();
$this
->drupalGet($this->product
->toUrl()
->toString());
$this
->submitForm([], 'Add to cart');
$this
->drupalGet(Url::fromRoute('commerce_cart.page'));
$this
->submitForm([], 'Checkout');
$this
->assertSession()
->pageTextNotContains('Order Summary');
$this
->submitForm([], 'Continue as Guest');
$this
->submitForm([
'contact_information[email]' => 'guest@example.com',
'contact_information[email_confirm]' => 'guest@example.com',
'payment_information[add_payment_method][payment_details][number]' => '4111111111111111',
'payment_information[add_payment_method][payment_details][expiration][month]' => '02',
'payment_information[add_payment_method][payment_details][expiration][year]' => '27',
'payment_information[add_payment_method][payment_details][security_code]' => '123',
'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
->assertSession()
->pageTextContains('A HTTPS connection is required.');
}
public function testRegisteredAuthorizeNetPayment() {
$this
->drupalGet($this->product
->toUrl()
->toString());
$this
->submitForm([], 'Add to cart');
$cart_link = $this
->getSession()
->getPage()
->findLink('your cart');
$cart_link
->click();
$this
->submitForm([], 'Checkout');
$this
->assertSession()
->pageTextContains('Order Summary');
$this
->submitForm([
'payment_information[add_payment_method][payment_details][number]' => '4111111111111111',
'payment_information[add_payment_method][payment_details][expiration][month]' => '02',
'payment_information[add_payment_method][payment_details][expiration][year]' => '27',
'payment_information[add_payment_method][payment_details][security_code]' => '123',
'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
->assertSession()
->pageTextContains('A HTTPS connection is required.');
}
}