InSales API - Способы доставки — различия между версиями
(→Добавление) |
(api способов оплаты) |
||
Строка 126: | Строка 126: | ||
HTTP/1.1 200 OK | HTTP/1.1 200 OK | ||
</pre> | </pre> | ||
+ | |||
+ | =Привязка способов оплаты= | ||
+ | Для добавления и удаления способов оплаты, доступных для данного способа доставки, используется поле <code>payment_delivery_variants_attributes</code>. | ||
+ | Расмотрим пример. Имеется способ доставки (RESTful адрес <code>http://some.domain/admin/delivery_variants/134212.json</code> или <code>.xml</code>): | ||
+ | <code> | ||
+ | { | ||
+ | "id": 134212, | ||
+ | "title": "Оплата", | ||
+ | "type": "DeliveryVariant::PriceDepend", | ||
+ | "position": 9, | ||
+ | "created_at": "2013-06-06T15:10:25+04:00", | ||
+ | "updated_at": "2013-06-13T11:43:47+04:00", | ||
+ | "description": "test", | ||
+ | "delivery_locations": [], | ||
+ | "payment_delivery_variants": [ | ||
+ | { | ||
+ | "created_at": "2013-06-13T11:43:47+04:00", | ||
+ | "delivery_variant_id": 134212, | ||
+ | "id": 257434, | ||
+ | "payment_gateway_id": 32541 | ||
+ | }, | ||
+ | { | ||
+ | "created_at": "2013-06-13T11:43:47+04:00", | ||
+ | "delivery_variant_id": 134212, | ||
+ | "id": 257433, | ||
+ | "payment_gateway_id": 2958 | ||
+ | } | ||
+ | ] | ||
+ | } | ||
+ | </code> | ||
+ | или в xml: | ||
+ | <code> | ||
+ | <?xml version="1.0" encoding="UTF-8"?> | ||
+ | <price-depend> | ||
+ | <created-at type="timestamp">2013-06-06 15:10:25 +0400</created-at> | ||
+ | <id type="integer">134212</id> | ||
+ | <position type="integer">9</position> | ||
+ | <updated-at type="timestamp">2013-06-13 11:43:47 +0400</updated-at> | ||
+ | <title>титл</title> | ||
+ | <description>test desc</description> | ||
+ | <payment-delivery-variants type="array"> | ||
+ | <payment-delivery-variant> | ||
+ | <created-at type="timestamp">2013-06-13 11:43:47 +0400</created-at> | ||
+ | <delivery-variant-id type="integer">134212</delivery-variant-id> | ||
+ | <id type="integer">257434</id> | ||
+ | <payment-gateway-id type="integer">32541</payment-gateway-id> | ||
+ | </payment-delivery-variant> | ||
+ | <payment-delivery-variant> | ||
+ | <created-at type="timestamp">2013-06-13 11:43:47 +0400</created-at> | ||
+ | <delivery-variant-id type="integer">134212</delivery-variant-id> | ||
+ | <id type="integer">257433</id> | ||
+ | <payment-gateway-id type="integer">2958</payment-gateway-id> | ||
+ | </payment-delivery-variant> | ||
+ | </payment-delivery-variants> | ||
+ | <delivery-locations type="array"/> | ||
+ | <type>DeliveryVariant::PriceDepend</type> | ||
+ | </price-depend> | ||
+ | </code> | ||
+ | Для удаления способа оплаты с <code>id = 32541</code> нужно выполнить запрос PUT по адресу <code>http://some.domain/admin/delivery_variants/134212.json</code> c данными: | ||
+ | <code> | ||
+ | { | ||
+ | delivery_variant: { | ||
+ | payment_delivery_variants_attributes: [ | ||
+ | { | ||
+ | _destroy: true, | ||
+ | id: 257434 | ||
+ | } | ||
+ | ] | ||
+ | } | ||
+ | } | ||
+ | </code> | ||
+ | или xml: | ||
+ | <code> | ||
+ | <?xml version="1.0"?> | ||
+ | <delivery-variant> | ||
+ | <payment-delivery-variants-attributes type="array"> | ||
+ | <payment-delivery-variant> | ||
+ | <_destroy type="boolean">true</_destroy> | ||
+ | <id type="integer">257434</id> | ||
+ | </payment-delivery-variant> | ||
+ | </payment-delivery-variants-attributes> | ||
+ | </delivery-variant> | ||
+ | </code> | ||
+ | Чтобы вновь добавить это способ доставки, и ещё один с <code>id = 53</code> выполните запрос PUT по адресу <code>http://some.domain/admin/delivery_variants/134212.json</code>: | ||
+ | <code> | ||
+ | { | ||
+ | delivery_variant: { | ||
+ | payment_delivery_variants_attributes: [ | ||
+ | { | ||
+ | payment_gateway_id: 32541 | ||
+ | }, | ||
+ | { | ||
+ | payment_gateway_id: 53 | ||
+ | } | ||
+ | ] | ||
+ | } | ||
+ | } | ||
+ | </code> | ||
+ | или xml: | ||
+ | <code> | ||
+ | <?xml version="1.0"?> | ||
+ | <delivery-variant> | ||
+ | <payment-delivery-variants-attributes type="array"> | ||
+ | <payment-delivery-variant> | ||
+ | <payment-gateway-id type="integer">32541</payment-gateway-id> | ||
+ | </payment-delivery-variant> | ||
+ | <payment-delivery-variant> | ||
+ | <payment-gateway-id type="integer">53</payment-gateway-id> | ||
+ | </payment-delivery-variant> | ||
+ | </payment-delivery-variants-attributes> | ||
+ | </delivery-variant> | ||
+ | </code> | ||
+ | Обратите внимание, что способы доставки добавляются по значению их <code>id</code> (<code>payment_gateway_id</code>), а удаляются по <code>id</code> записи <code>payment_delivery_variants</code>. |
Текущая версия на 08:52, 13 июня 2013
Содержание
Получение списка
Запрос: GET /admin/delivery_variants.xml
Ответ:
HTTP/1.1 200 OK <?xml version="1.0" encoding="UTF-8"?> <objects type="array"> <object> <id type="integer">57802</id> <title>Курьером</title> <description>Супер быстрая доставка</description> <position type="integer">1</position> <created-at type="timestamp">2012-02-22 12:56:51 +0400</created-at> <updated-at type="timestamp">2012-05-17 11:55:07 +0400</updated-at> <delivery-locations type="array"> <delivery-location> <region>Респ Адыгея</region> <city>Майкоп</city> </delivery-location> <delivery-location> <region>Респ Адыгея</region> <city>Красногвардейский район</city> </delivery-location> </delivery-locations> <type>DeliveryVariant::PriceDepend</type> </object> <object> <id type="integer">57955</id> <title>Курьером</title> <description nil="true"/> <position type="integer">2</position> <created-at type="timestamp">2012-02-24 11:36:46 +0400</created-at> <updated-at type="timestamp">2012-02-24 11:38:26 +0400</updated-at> <delivery-locations type="array"/> <type>DeliveryVariant::Fixed</type> </object> </objects>
Получение информации о способе доставки
Запрос: GET /admin/delivery_variants/#{id}.xml
Ответ:
HTTP/1.1 200 OK <?xml version="1.0" encoding="UTF-8"?> <object> <id type="integer">57955</id> <title>Курьером</title> <description nil="true"/> <position type="integer">2</position> <created-at type="timestamp">2012-02-24 11:36:46 +0400</created-at> <updated-at type="timestamp">2012-02-24 11:38:26 +0400</updated-at> <delivery-locations type="array"/> <type>DeliveryVariant::Fixed</type> </object>
Добавление
Запрос: POST /admin/delivery_variants.xml
<?xml version="1.0" encoding="UTF-8"?> <delivery-variant> <title>Курьером</title> <description>Супер быстрая доставка</description> <delivery-locations-attributes type="array"> <delivery-location> <region>Респ Адыгея</region> <city>Майкоп</city> </delivery-location> <delivery-location> <region>Респ Адыгея</region> <city>Красногвардейский район</city> </delivery-location> </delivery-locations-attributes> <type>DeliveryVariant::PriceDepend</type> </delivery-variant>
- Если вы хотите, чтобы при создании способа доставки к нему автоматически были добавлены все способы оплаты, нужно добавить в запрос следующий тег:
<?xml version="1.0" encoding="UTF-8"?> <delivery-variant> ... <add-payment-gateways>true</add-payment-gateways> </delivery-variant>
Ответ:
HTTP/1.1 200 OK <?xml version="1.0" encoding="UTF-8"?> <object> <id type="integer">57802</id> <title>Курьером</title> <description>Супер быстрая доставка</description> <position type="integer">3</position> <created-at type="timestamp">2012-02-22 12:56:51 +0400</created-at> <updated-at type="timestamp">2012-05-17 11:55:07 +0400</updated-at> <delivery-locations type="array"> <delivery-location> <id type="integer">12136</id> <region>Респ Адыгея</region> <city>Майкоп</city> </delivery-location> <delivery-location> <id type="integer">12137</id> <region>Респ Адыгея</region> <city>Красногвардейский район</city> </delivery-location> </delivery-locations> <type>DeliveryVariant::PriceDepend</type> </object>
Удаление
Запрос: DELETE /admin/delivery_variants/#{id}.xml
Ответ:
HTTP/1.1 200 OK
Привязка способов оплаты
Для добавления и удаления способов оплаты, доступных для данного способа доставки, используется поле payment_delivery_variants_attributes
.
Расмотрим пример. Имеется способ доставки (RESTful адрес http://some.domain/admin/delivery_variants/134212.json
или .xml
):
{ "id": 134212, "title": "Оплата", "type": "DeliveryVariant::PriceDepend", "position": 9, "created_at": "2013-06-06T15:10:25+04:00", "updated_at": "2013-06-13T11:43:47+04:00", "description": "test", "delivery_locations": [], "payment_delivery_variants": [ { "created_at": "2013-06-13T11:43:47+04:00", "delivery_variant_id": 134212, "id": 257434, "payment_gateway_id": 32541 }, { "created_at": "2013-06-13T11:43:47+04:00", "delivery_variant_id": 134212, "id": 257433, "payment_gateway_id": 2958 } ] }
или в xml:
<?xml version="1.0" encoding="UTF-8"?> <price-depend> <created-at type="timestamp">2013-06-06 15:10:25 +0400</created-at> <id type="integer">134212</id> <position type="integer">9</position> <updated-at type="timestamp">2013-06-13 11:43:47 +0400</updated-at> <title>титл</title> <description>test desc</description> <payment-delivery-variants type="array"> <payment-delivery-variant> <created-at type="timestamp">2013-06-13 11:43:47 +0400</created-at> <delivery-variant-id type="integer">134212</delivery-variant-id> <id type="integer">257434</id> <payment-gateway-id type="integer">32541</payment-gateway-id> </payment-delivery-variant> <payment-delivery-variant> <created-at type="timestamp">2013-06-13 11:43:47 +0400</created-at> <delivery-variant-id type="integer">134212</delivery-variant-id> <id type="integer">257433</id> <payment-gateway-id type="integer">2958</payment-gateway-id> </payment-delivery-variant> </payment-delivery-variants> <delivery-locations type="array"/> <type>DeliveryVariant::PriceDepend</type> </price-depend>
Для удаления способа оплаты с id = 32541
нужно выполнить запрос PUT по адресу http://some.domain/admin/delivery_variants/134212.json
c данными:
{ delivery_variant: { payment_delivery_variants_attributes: [ { _destroy: true, id: 257434 } ] } }
или xml:
<?xml version="1.0"?> <delivery-variant> <payment-delivery-variants-attributes type="array"> <payment-delivery-variant> <_destroy type="boolean">true</_destroy> <id type="integer">257434</id> </payment-delivery-variant> </payment-delivery-variants-attributes> </delivery-variant>
Чтобы вновь добавить это способ доставки, и ещё один с id = 53
выполните запрос PUT по адресу http://some.domain/admin/delivery_variants/134212.json
:
{ delivery_variant: { payment_delivery_variants_attributes: [ { payment_gateway_id: 32541 }, { payment_gateway_id: 53 } ] } }
или xml:
<?xml version="1.0"?> <delivery-variant> <payment-delivery-variants-attributes type="array"> <payment-delivery-variant> <payment-gateway-id type="integer">32541</payment-gateway-id> </payment-delivery-variant> <payment-delivery-variant> <payment-gateway-id type="integer">53</payment-gateway-id> </payment-delivery-variant> </payment-delivery-variants-attributes> </delivery-variant>
Обратите внимание, что способы доставки добавляются по значению их id
(payment_gateway_id
), а удаляются по id
записи payment_delivery_variants
.