You are here

function RobokassaPayment::paymentMethodsList in Commerce robokassa 8.2

1 call to RobokassaPayment::paymentMethodsList()
RobokassaPayment::buildConfigurationForm in src/Plugin/Commerce/PaymentGateway/RobokassaPayment.php
Form constructor.

File

src/Plugin/Commerce/PaymentGateway/RobokassaPayment.php, line 217

Class

RobokassaPayment
Provides the Off-site Robokassa payment gateway.

Namespace

Drupal\commerce_robokassa\Plugin\Commerce\PaymentGateway

Code

function paymentMethodsList() {
  $url = 'https://auth.robokassa.ru/Merchant/WebService/Service.asmx/GetCurrencies';
  $data = [
    'MerchantLogin' => $this->configuration['MrchLogin'],
    'Language' => $this->languageManager
      ->getCurrentLanguage()
      ->getId() == 'ru' ? 'ru' : 'en',
  ];
  $response = $this->httpClient
    ->get($url, [
    'query' => $data,
  ]);
  $xmlstring = $response
    ->getBody()
    ->getContents();
  $xml = simplexml_load_string($xmlstring, "SimpleXMLElement", LIBXML_NOCDATA);
  $json = json_encode($xml);
  $array = json_decode($json, TRUE);
  $ret = [];
  if (!isset($array['Groups'])) {
    return $ret;
  }
  foreach ($array['Groups'] as $groups) {
    foreach ($groups as $group) {
      foreach ($group['Items'] as $item) {
        if (isset($item['@attributes'])) {
          $item = array(
            $item,
          );
        }
        foreach ($item as $currency) {
          $ret[$currency['@attributes']['Label']] = $currency['@attributes']['Name'];
        }
      }
    }
  }
  return $ret;
}