You are here

public function OffsiteRedirect::onReturn in Commerce Core 8.2

Processes the "return" request.

This method should only be concerned with creating/completing payments, the parent order does not need to be touched. The order state is updated automatically when the order is paid in full, or manually by the merchant (via the admin UI).

Parameters

\Drupal\commerce_order\Entity\OrderInterface $order: The order.

\Symfony\Component\HttpFoundation\Request $request: The request.

Throws

\Drupal\commerce_payment\Exception\PaymentGatewayException Thrown when the request is invalid or the payment failed.

Overrides OffsitePaymentGatewayBase::onReturn

1 call to OffsiteRedirect::onReturn()
TestOffsite::onReturn in modules/payment/tests/modules/commerce_payment_test/src/Plugin/Commerce/PaymentGateway/TestOffsite.php
Adds data to the order and saves it. Done before or after the payment is saved. Used by OffsiteOrderDataTest.
2 methods override OffsiteRedirect::onReturn()
StoredOffsiteRedirect::onReturn in modules/payment_example/src/Plugin/Commerce/PaymentGateway/StoredOffsiteRedirect.php
Processes the "return" request.
TestOffsite::onReturn in modules/payment/tests/modules/commerce_payment_test/src/Plugin/Commerce/PaymentGateway/TestOffsite.php
Adds data to the order and saves it. Done before or after the payment is saved. Used by OffsiteOrderDataTest.

File

modules/payment_example/src/Plugin/Commerce/PaymentGateway/OffsiteRedirect.php, line 74

Class

OffsiteRedirect
Provides the Off-site Redirect payment gateway.

Namespace

Drupal\commerce_payment_example\Plugin\Commerce\PaymentGateway

Code

public function onReturn(OrderInterface $order, Request $request) {

  // @todo Add examples of request validation.
  // Note: Since requires_billing_information is FALSE, the order is
  // not guaranteed to have a billing profile. Confirm that
  // $order->getBillingProfile() is not NULL before trying to use it.
  $payment_storage = $this->entityTypeManager
    ->getStorage('commerce_payment');
  $payment = $payment_storage
    ->create([
    'state' => 'completed',
    'amount' => $order
      ->getBalance(),
    'payment_gateway' => $this->parentEntity
      ->id(),
    'order_id' => $order
      ->id(),
    'remote_id' => $request->query
      ->get('txn_id'),
    'remote_state' => $request->query
      ->get('payment_status'),
  ]);
  $payment
    ->save();
}