M
M
Maxim Demidov2017-02-18 23:34:24
PHP
Maxim Demidov, 2017-02-18 23:34:24

How to set up delivery calculation for API 2.0 from Nova Poshta?

Can you please tell me how to set up the delivery calculation for API 2.0 from Nova Poshta? (the site itself is in php and mysql).
1) I registered in the account of New Mail itself, I received the Api key.
2) I found a ready-made class on Github ( https://github.com/lis-dev/nova-poshta-api-2).
3) How can I display on the page, for example, a form with the point of departure, the point of receipt and the price for delivery? Give, please, at least a direction where to dig...
UPd 02/19/17
On the advice of the respected sim3x, I dug into the documentation of "Novaya Poshta", tried to create json for a request to their API.

<!DOCTYPE html>
<html>
 
<head>
  <meta charset='UTF-8'>
  <title>Пример отправки (Новая почта)</title>
</head>
 
<body>
<div class='citySender'></div>
<div class='cityRecipient'></div>
<div class='weight'></div>
<div class='cost'></div>
 
</body>
 
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js'></script>
<script>
  $(function () {
      var params = {
          'apiKey': 'Ключ АПИ, который я вставил',
          'modelName': 'InternetDocument',
          'calledMethod': 'getDocumentPrice',
          'methodProperties': {
      'CitySender': '8d5a980d-391c-11dd-90d9-001a92567626',
      'CityRecipient': 'db5c88e0-391c-11dd-90d9-001a92567626',
      'Weight': '1',
    'ServiceType': 'DoorsDoors',
      'Cost': '400',
    'CargoType': 'Documents',
      'SeatsAmount': '1',
     'PackCalculate': {
            'PackCount': '1',
            'PackRef': '1499fa4a-d26e-11e1-95e4-0026b97ed48a'
        },
      'RedeliveryCalculate': {
         'CargoType': 'Money',
         'Amount': '100'
      }
          
      }
      };
      $.ajax({
          url: 'https://api.novaposhta.ua/v2.0/json/?' + $.param(params),
          beforeSend: function (xhrObj) {
              xhrObj.setRequestHeader('Content-Type', 'application/json');
          },
          type: 'POST',
          dataType: 'jsonp',
          data: '{body}'
      }).done(function (jsondb) {
            
            $('.citySender').html('Город отправитель: ' + jsondb.data[0].CitySender) // город отправитель
            $('.cityRecipient').html('Город получатель: ' + jsondb.data[0].CityRecipient) // город получатель
            $('.weight').html('Вес: ' + jsondb.data[0].Weight + ' кг.') // вес
      $('.cost').html('Стоимость: ' + jsondb.data[0].Cost + ' грн.') // стоимость
      
      
      
      
      }).fail(function () {
          alert('error');
      });
  });
</script>
 
</html>

[]}) There are two questions -
1) Why doesn't it display the names of the sender's and recipient's cities?
2) How to change the values ​​of variables in the request (for example, so that the user selects the sender's city, the recipient's city, etc. from the list in the form and the values ​​of the variables change).
Sorry for such questions, I’m just very inexperienced, and Google doesn’t always save ((((

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2017-02-18
@sim3x

The class has not been updated for a long time - I would not advise using it
Start from here
https://devcenter.novaposhta.ua/docs/services/556e...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question