You are here

class PaymentOffsiteForm in Commerce robokassa 8.2

Hierarchy

Expanded class hierarchy of PaymentOffsiteForm

File

src/PluginForm/OffsiteRedirect/PaymentOffsiteForm.php, line 12

Namespace

Drupal\commerce_robokassa\PluginForm\OffsiteRedirect
View source
class PaymentOffsiteForm extends BasePaymentOffsiteForm {

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $form = parent::buildConfigurationForm($form, $form_state);

    /** @var \Drupal\commerce_payment\Entity\PaymentInterface $payment */
    $payment = $this->entity;
    $payment
      ->save();

    /** @var \Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\OffsitePaymentGatewayInterface $payment_gateway_plugin */
    $payment_gateway_plugin = $payment
      ->getPaymentGateway()
      ->getPlugin();
    $data = [];
    $payment_gateway_configuration = $payment_gateway_plugin
      ->getConfiguration();
    $user_name = $payment_gateway_configuration["MrchLogin"];
    $password = $payment_gateway_configuration['pass1'];
    $double_staged = !$form['#capture'];
    $mode = $payment
      ->getPaymentGatewayMode() == 'live' ? false : true;
    $logging = $payment_gateway_configuration['logging'] == 0 ? false : true;
    $timeout = empty($payment_gateway_configuration['timeout']) ? null : $payment_gateway_configuration['timeout'];
    $redirect_url = $payment_gateway_configuration['server_url_' . $payment
      ->getPaymentGatewayMode()];
    $form['#action'] = $redirect_url;
    $data["MerchantLogin"] = $payment_gateway_configuration['MrchLogin'];
    $amount = $payment
      ->getOrder()
      ->getTotalPrice();
    $data["OutSum"] = number_format($amount
      ->getNumber(), 2, '.', '');
    $data["InvId"] = $payment
      ->getOrderId();
    $data["shp_trx_id"] = $payment
      ->id();

    // For test transactions.
    if ($payment
      ->getPaymentGatewayMode() == 'test') {
      $data['IsTest'] = '1';
    }
    $signature_data = array(
      $data["MerchantLogin"],
      $data["OutSum"],
      $data["InvId"],
      $payment_gateway_configuration['pass1'],
      'shp_trx_id=' . $data["shp_trx_id"],
    );

    // Calculate signature.
    $data['SignatureValue'] = hash($payment_gateway_configuration['hash_type'], implode(':', $signature_data));
    $inv_desc_params = array(
      '@order_id' => $payment
        ->getOrderId(),
      '@mail' => $payment
        ->getOrder()
        ->getEmail(),
    );
    $inv_desc = t('Order ID: @order_id, User mail: @mail', $inv_desc_params);
    $data['InvDesc'] = Unicode::truncate($inv_desc, 100);
    if (isset($payment
      ->getOrder()
      ->getData('commerce_robokassa')['IncCurrLabel'])) {
      $data['IncCurrLabel'] = $payment
        ->getOrder()
        ->getData('commerce_robokassa')['IncCurrLabel'];
    }
    $payment
      ->save();
    return $this
      ->buildRedirectForm($form, $form_state, $redirect_url, $data, self::REDIRECT_POST);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
PaymentGatewayFormBase::$entity protected property The form entity.
PaymentGatewayFormBase::getEntity public function Gets the form entity. Overrides PaymentGatewayFormInterface::getEntity
PaymentGatewayFormBase::getErrorElement public function Gets the form element to which errors should be assigned. Overrides PaymentGatewayFormInterface::getErrorElement 1
PaymentGatewayFormBase::setEntity public function Sets the form entity. Overrides PaymentGatewayFormInterface::setEntity
PaymentOffsiteForm::buildConfigurationForm public function Form constructor. Overrides PaymentOffsiteForm::buildConfigurationForm
PaymentOffsiteForm::buildRedirectForm protected function Builds the redirect form.
PaymentOffsiteForm::processRedirectForm public static function Prepares the complete form for a POST redirect.
PaymentOffsiteForm::REDIRECT_GET constant
PaymentOffsiteForm::REDIRECT_POST constant
PaymentOffsiteForm::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm
PluginFormBase::$plugin protected property The plugin this form is for. 3
PluginFormBase::setPlugin public function Sets the plugin for this object. Overrides PluginAwareInterface::setPlugin 1
PluginFormBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm 2
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.