You are here

public function WorldPayHelper::createData in Commerce Worldpay 8

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

Return value

array

File

src/Plugin/Commerce/PaymentGateway/WorldPayHelper.php, line 86

Class

WorldPayHelper
Class WorldPayHelper Helper class for collecting form data.

Namespace

Drupal\commerce_worldpay\Plugin\Commerce\PaymentGateway

Code

public function createData() {
  if ($this->config['payment_parameters']['test_mode']) {
    $this->data += [
      'testMode' => '100',
    ];
  }
  $this->data += [
    'instId' => $this->config['installation_id'],
    'amount' => $this->order
      ->getTotalPrice()
      ->getNumber(),
    'cartId' => $this->order
      ->uuid(),
    //This is need to clarify.
    'currency' => $this->order
      ->getTotalPrice()
      ->getCurrencyCode(),
    'MC_orderId' => $this->order
      ->id(),
    'M_http_host' => \Drupal::request()
      ->getSchemeAndHttpHost(),
    'signatureFields' => implode(':', WorldpayRedirect::md5signatureFields()),
    'signature' => $this
      ->buildMd5Hash([
      $this->config['installation_id'],
      $this->order
        ->getTotalPrice()
        ->getNumber(),
      $this->order
        ->getTotalPrice()
        ->getCurrencyCode(),
      $this->order
        ->uuid(),
      $this->order
        ->id(),
      $this->order
        ->getData('worldpay_form')['return_url'],
    ]),
    // The path WorldPay should send its Payment Response to
    'MC_callback' => $this->order
      ->getData('worldpay_form')['return_url'],
    // Used in WorldPay custom pages
    'C_siteTitle' => \Drupal::config('system.site')
      ->get('name'),
  ];
  return $this->data;
}