commerce_alphabank_redirect-1.0.1/src/Plugin/Commerce/PaymentGateway/AlphabankPaymentRedirect.php

src/Plugin/Commerce/PaymentGateway/AlphabankPaymentRedirect.php
<?php

namespace Drupal\commerce_alphabank_redirect\Plugin\Commerce\PaymentGateway;

use Drupal\commerce_payment\Plugin\Commerce\PaymentGateway\OffsitePaymentGatewayBase;
use Drupal\Core\Form\FormStateInterface;

/**
 * Provides the Off-site Redirect payment gateway.
 *
 * @CommercePaymentGateway(
 *   id = "alphabank_redirect",
 *   label = "Alphabank Payment Redirect",
 *   display_label = "Alphabank Payment Redirect",
 *   forms = {
 *     "offsite-payment" = "Drupal\commerce_alphabank_redirect\PluginForm\OffsiteRedirect\AlphabankPaymentRedirectForm",
 *   },
 *   payment_method_types = {"credit_card"},
 *   credit_card_types = {
 *     "amex", "dinersclub", "discover", "maestro", "mastercard", "visa",
 *   },
 *   requires_billing_information = FALSE,
 * )
 */
class AlphabankPaymentRedirect extends OffsitePaymentGatewayBase {

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return [
      'version' => '2',
      'mid' => '0000000000',
      'currency' => 'EUR',
      'confirmUrl' => 'https://example.com/commerce_alphabank_redirect/callback?action=success',
      'cancelUrl' => 'https://example.com/commerce_alphabank_redirect/callback?action=failure',
      'shared_secret' => 'SECRET',
      'postUrl' => 'https://alphaecommerce-test.cardlink.gr/vpos/shophandlermpi',
      'pay_method' => 'default',
      'beneficiary_code' => '00000'
    ] + parent::defaultConfiguration();
  }

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

    $form['pay_method'] = [
      '#type' => 'radios',
      '#title' => $this->t('Pay method'),
      '#options' => [
        'default' => $this->t('Default'),
        'iris' => $this->t('IRIS'),
      ],
      '#default_value' => $this->configuration['pay_method'],
      '#required' => TRUE,
    ];

    $form['version'] = [
      '#type' => 'textfield',
      '#required' => TRUE,
      '#title' => $this->t('Specification version'),
      '#description' => $this->t('Value 2'),
      '#default_value' => $this->configuration['version'],
    ];

    $form['mid'] = [
      '#type' => 'textfield',
      '#required' => TRUE,
      '#title' => $this->t('Merchant ID'),
      '#description' => $this->t('Merchant id supplied (integer number) will be supplied to merchant, max length 30'),
      '#default_value' => $this->configuration['mid'],
    ];

    $form['beneficiary_code'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Beneficiary code'),
      '#default_value' => $this->configuration['beneficiary_code'],
      '#description' => $this->t('Required only for IRIS payment method.'),
    ];

    $form['currency'] = [
      '#type' => 'textfield',
      '#required' => TRUE,
      '#title' => $this->t('Currency'),
      '#description' => $this->t('Order amount currency (string 3 ISO ISO 4217 alphabetic code (EUR, USD))'),
      '#default_value' => $this->configuration['currency'],
    ];

    $form['confirmUrl'] = [
      '#type' => 'textfield',
      '#required' => TRUE,
      '#title' => $this->t('Confirm url'),
      '#description' => $this->t('Confirmation url where to send payment confirmation in case payment was successful (string..128)'),
      '#default_value' => $this->configuration['confirmUrl'],
    ];

    $form['cancelUrl'] = [
      '#type' => 'textfield',
      '#required' => TRUE,
      '#title' => $this->t('Cancel url'),
      '#description' => $this->t('Cancel url where to send payment feedback in case payment has failed or was canceled by user (string..128)'),
      '#default_value' => $this->configuration['cancelUrl'],
    ];

    $form['shared_secret'] = [
      '#type' => 'textfield',
      '#required' => TRUE,
      '#title' => $this->t('Shared Secret'),
      '#description' => $this->t('Shared Secret'),
      '#default_value' => $this->configuration['shared_secret'],
    ];

    $form['postUrl'] = [
      '#type' => 'textfield',
      '#required' => TRUE,
      '#title' => $this->t('Post url'),
      '#description' => $this->t('Post url'),
      '#default_value' => $this->configuration['postUrl'],
    ];

    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
    parent::submitConfigurationForm($form, $form_state);
    if (!$form_state->getErrors()) {
      $values = $form_state->getValue($form['#parents']);
      $this->configuration['pay_method'] = $values['pay_method'];
      $this->configuration['version'] = $values['version'];
      $this->configuration['mid'] = $values['mid'];
      $this->configuration['beneficiary_code'] = $values['beneficiary_code'];
      $this->configuration['currency'] = $values['currency'];
      $this->configuration['confirmUrl'] = $values['confirmUrl'];
      $this->configuration['cancelUrl'] = $values['cancelUrl'];
      $this->configuration['shared_secret'] = $values['shared_secret'];
      $this->configuration['postUrl'] = $values['postUrl'];
    }
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc