You are here

public function WorldpayRedirect::createPayment in Commerce Worldpay 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Commerce/PaymentGateway/WorldpayRedirect.php \Drupal\commerce_worldpay\Plugin\Commerce\PaymentGateway\WorldpayRedirect::createPayment()

Create a Commerce Payment from a WorldPay form request successful result.

Return value

PaymentInterface $payment The commerce payment record.

Throws

\Drupal\Core\Entity\EntityStorageException

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

1 call to WorldpayRedirect::createPayment()
WorldpayRedirect::onNotify in src/Plugin/Commerce/PaymentGateway/WorldpayRedirect.php

File

src/Plugin/Commerce/PaymentGateway/WorldpayRedirect.php, line 513

Class

WorldpayRedirect
Provides the Worldpay Redirect payment gateway.

Namespace

Drupal\commerce_worldpay\Plugin\Commerce\PaymentGateway

Code

public function createPayment(array $responseData, OrderInterface $order) {

  /** @var \Drupal\commerce_payment\PaymentStorageInterface $paymentStorage */
  $paymentStorage = $this->entityTypeManager
    ->getStorage('commerce_payment');

  /** @var PaymentInterface $payment */
  $payment = $paymentStorage
    ->create([
    'state' => 'authorization',
    'amount' => $order
      ->getTotalPrice(),
    'payment_gateway' => $this->parentEntity
      ->id(),
    'order_id' => $order
      ->id(),
    'test' => $this
      ->getMode() == 'test',
    'remote_id' => $responseData['transId'],
    'remote_state' => $responseData['transStatus'],
    'authorized' => $this->time
      ->getRequestTime(),
  ]);
  $payment
    ->save();
  return $payment;
}