You are here

public function OrderPaidSubscriberTest::testOffsiteGateway in Commerce Core 8.2

Confirms that off-site payments result in the order getting placed.

File

modules/payment/tests/src/Kernel/OrderPaidSubscriberTest.php, line 101

Class

OrderPaidSubscriberTest
Tests the OrderPaidSubscriber.

Namespace

Drupal\Tests\commerce_payment\Kernel

Code

public function testOffsiteGateway() {

  /** @var \Drupal\commerce_payment\Entity\PaymentGatewayInterface $offsite_gateway */
  $offsite_gateway = PaymentGateway::create([
    'id' => 'offsite',
    'label' => 'Off-site',
    'plugin' => 'example_offsite_redirect',
    'configuration' => [
      'redirect_method' => 'post',
      'payment_method_types' => [
        'credit_card',
      ],
    ],
  ]);
  $offsite_gateway
    ->save();
  $this->order
    ->set('payment_gateway', $offsite_gateway);
  $this->order
    ->lock();
  $this->order
    ->save();
  $payment = Payment::create([
    'type' => 'payment_default',
    'payment_gateway' => $offsite_gateway
      ->id(),
    'order_id' => $this->order
      ->id(),
    'amount' => $this->order
      ->getTotalPrice(),
    'state' => 'completed',
  ]);
  $payment
    ->save();
  $this->order
    ->save();
  $this
    ->assertEquals('completed', $this->order
    ->getState()
    ->getId());
  $this
    ->assertFalse($this->order
    ->isLocked());
  $this
    ->assertNotEmpty($this->order
    ->getOrderNumber());
  $this
    ->assertNotEmpty($this->order
    ->getPlacedTime());
  $this
    ->assertNotEmpty($this->order
    ->getCompletedTime());
}