You are here

public function PaymentTest::testPayment in Commerce Core 8.2

@covers ::getType @covers ::getPaymentGatewayId @covers ::getPaymentGatewayMode @covers ::getOrder @covers ::getOrderId @covers ::getRemoteId @covers ::setRemoteId @covers ::getRemoteState @covers ::setRemoteState @covers ::getBalance @covers ::getAmount @covers ::setAmount @covers ::getRefundedAmount @covers ::setRefundedAmount @covers ::getState @covers ::setState @covers ::getAuthorizedTime @covers ::setAuthorizedTime @covers ::isExpired @covers ::getExpiresTime @covers ::setExpiresTime @covers ::isCompleted @covers ::getCompletedTime @covers ::setCompletedTime

File

modules/payment/tests/src/Kernel/Entity/PaymentTest.php, line 112

Class

PaymentTest
Tests the payment entity.

Namespace

Drupal\Tests\commerce_payment\Kernel\Entity

Code

public function testPayment() {

  /** @var \Drupal\commerce_payment\Entity\PaymentInterface $payment */
  $payment = Payment::create([
    'type' => 'payment_default',
    'payment_gateway' => 'example',
    'order_id' => $this->order
      ->id(),
    'amount' => new Price('30', 'USD'),
    'refunded_amount' => new Price('10', 'USD'),
    'state' => 'refunded',
    'avs_response_code' => 'X',
    'avs_response_code_label' => 'Meaning of X',
  ]);
  $payment
    ->save();
  $this
    ->assertInstanceOf(PaymentDefault::class, $payment
    ->getType());
  $this
    ->assertEquals('example', $payment
    ->getPaymentGatewayId());
  $this
    ->assertEquals('test', $payment
    ->getPaymentGatewayMode());
  $this
    ->assertEquals('X', $payment
    ->getAvsResponseCode());
  $this
    ->assertEquals('Meaning of X', $payment
    ->getAvsResponseCodeLabel());
  $this
    ->assertEquals($this->order, $payment
    ->getOrder());
  $this
    ->assertEquals($this->order
    ->id(), $payment
    ->getOrderId());
  $payment
    ->setRemoteId('123456');
  $this
    ->assertEquals('123456', $payment
    ->getRemoteId());
  $payment
    ->setRemoteState('pending');
  $this
    ->assertEquals('pending', $payment
    ->getRemoteState());
  $payment
    ->setAvsResponseCode('Z');
  $this
    ->assertEquals('Z', $payment
    ->getAvsResponseCode());
  $payment
    ->setAvsResponseCodeLabel('Meaning of Z');
  $this
    ->assertEquals('Meaning of Z', $payment
    ->getAvsResponseCodeLabel());
  $this
    ->assertEquals(new Price('30', 'USD'), $payment
    ->getAmount());
  $this
    ->assertEquals(new Price('10', 'USD'), $payment
    ->getRefundedAmount());
  $this
    ->assertEquals(new Price('20', 'USD'), $payment
    ->getBalance());
  $payment
    ->setAmount(new Price('40', 'USD'));
  $this
    ->assertEquals(new Price('40', 'USD'), $payment
    ->getAmount());
  $payment
    ->setRefundedAmount(new Price('15', 'USD'));
  $this
    ->assertEquals(new Price('15', 'USD'), $payment
    ->getRefundedAmount());
  $this
    ->assertEquals('refunded', $payment
    ->getState()
    ->getId());
  $payment
    ->setState('completed');
  $this
    ->assertEquals('completed', $payment
    ->getState()
    ->getId());
  $this
    ->assertEmpty($payment
    ->getAuthorizedTime());
  $payment
    ->setAuthorizedTime(635879600);
  $this
    ->assertEquals(635879600, $payment
    ->getAuthorizedTime());
  $this
    ->assertEmpty($payment
    ->isExpired());
  $payment
    ->setExpiresTime(635879700);
  $this
    ->assertTrue($payment
    ->isExpired());
  $this
    ->assertEquals(635879700, $payment
    ->getExpiresTime());
  $this
    ->assertEmpty($payment
    ->isCompleted());
  $payment
    ->setCompletedTime(635879700);
  $this
    ->assertEquals(635879700, $payment
    ->getCompletedTime());
  $this
    ->assertTrue($payment
    ->isCompleted());
}