Orders-orderId-account-products-productId-discounts:PUT

(Difference between revisions)
Jump to: navigation, search
m (1 revision: Release 85)
(Status Code)
Line 60: Line 60:
  
 
== Response ==
 
== Response ==
 
 
=== Status Code ===
 
=== Status Code ===
;200 OK
+
{| class='wikitable'
: The discount was successfully set.
+
|-
 +
! Status Code
 +
! Error Message
 +
! Description
 +
|-
 +
| 204 No Content
 +
| align="center" | -
 +
| The discount was successfully set.
 +
|-
 +
| rowspan="6" | 400 Bad Request
 +
| POST data error
 +
| Required fields are missing.
 +
|-
 +
! colspan="4" align="center" | Validation Error:
 +
|-
 +
| Code: invalid_fee_type, {priceName} discount fee type is invalid
 +
| Type of price is not recognized by the system.
 +
|-
 +
| Code: invalid_discount_amount, {value} discount amount is invalid
 +
| Discount amount should be a '''positive''' number.
 +
|-
 +
| Code: unsupported_discount_type, {type} discount type is unsupported
 +
| Type should be set to either '''amount''' or '''percent'''.
 +
|-
 +
| Code: invalid_discount_period, {recurrences} discount period is invalid
 +
| Number of reccurences should be either a '''positive''' integer or '''-1'''. If priceName is '''recurring''', it should be '''-1'''.
 +
|-
 +
| 401 Unauthorized
 +
| align="center" | -
 +
| The request was not properly authorized.
 +
|-
 +
| 403 Forbidden
 +
| Unauthorized: DiscountsView failed permission check
 +
| The client does not have sufficient privileges.
 +
|-
 +
| rowspan="2" | 404 Not Found
 +
| rowspan="2" | Resource not found
 +
| Order does not exist.
 +
|-
 +
| Product could not be found.
 +
|-
 +
| 502 Bad Gateway
 +
| align="center" | -
 +
| Unexpected backend response. Cannot set custom discounts.
 +
|}
 +
 
 +
== Example ==
 +
=== Success ===
 +
'''Request'''
 +
<nowiki>
 +
PUT /orders/{orderId}/account/products/{productId}/discounts
 +
Content-Type : application/json; charset=UTF-8
 +
Authorization: Basic dGVzdC52cGxleEBjb3JwX2xkYXBfc2VydmljZV9jaGk6VHJAcXNQODch
 +
Cookie: OwnerId={owner_id}; Path=/
 +
 
 +
{
 +
  "discounts": [{
 +
    "priceName": "recurring",
 +
    "recurrences": "-1",
 +
    "type": "amount",
 +
    "value": "5.00"
 +
  }]
 +
}</nowiki>
 +
 
 +
'''Response'''
 +
<nowiki>
 +
204 No Content</nowiki>
 +
 
 +
=== Invalid discount amount ===
 +
'''Request'''
 +
<nowiki>
 +
PUT /orders/{orderId}/account/products/{productId}/discounts
 +
Content-Type : application/json; charset=UTF-8
 +
Authorization: Basic dGVzdC52cGxleEBjb3JwX2xkYXBfc2VydmljZV9jaGk6VHJAcXNQODch
 +
Cookie: OwnerId={owner_id}; Path=/
 +
 
 +
{
 +
  "discounts": [{
 +
    "priceName": "recurring",
 +
    "recurrences": "-1",
 +
    "type": "amount",
 +
    "value": "-5.00"
 +
  }]
 +
}</nowiki>
 +
 
 +
'''Response'''
 +
<nowiki>
 +
400 Bad Request
 +
Content-Type : application/json; charset=UTF-8
 +
 
 +
{
 +
  "computeFault": {
 +
    "guid": "c3563e61-a297-4dbe-b072-24aace7b5e44",
 +
    "message": "<class 'order_builder.bl.validation.ValidationError.ValidationError'>: Code: invalid_discount_amount, -5.00 discount amount is invalid",
 +
    "code": 400,
 +
    "details": ""
 +
  }
 +
}</nowiki>
 +
 
 +
=== Invalid discount type ===
 +
'''Request'''
 +
<nowiki>
 +
PUT /orders/{orderId}/account/products/{productId}/discounts
 +
Content-Type : application/json; charset=UTF-8
 +
Authorization: Basic dGVzdC52cGxleEBjb3JwX2xkYXBfc2VydmljZV9jaGk6VHJAcXNQODch
 +
Cookie: OwnerId={owner_id}; Path=/
 +
 
 +
{
 +
  "discounts": [{
 +
    "priceName": "recurring",
 +
    "recurrences": "-1",
 +
    "type": "numbers",
 +
    "value": "5.00"
 +
  }]
 +
}</nowiki>
 +
 
 +
'''Response'''
 +
<nowiki>
 +
400 Bad Request
 +
Content-Type : application/json; charset=UTF-8
 +
 
 +
{
 +
  "computeFault": {
 +
    "guid": "1a94f744-5b33-4d54-ab28-77b875934829",
 +
    "message": "<class 'order_builder.bl.validation.ValidationError.ValidationError'>: Code: unsupported_discount_type, amounts discount type is unsupported",
 +
    "code": 400,
 +
    "details": ""
 +
  }
 +
}</nowiki>
 +
 
 +
=== Invalid price type ===
 +
'''Request'''
 +
<nowiki>
 +
PUT /orders/{orderId}/account/products/{productId}/discounts
 +
Content-Type : application/json; charset=UTF-8
 +
Authorization: Basic dGVzdC52cGxleEBjb3JwX2xkYXBfc2VydmljZV9jaGk6VHJAcXNQODch
 +
Cookie: OwnerId={owner_id}; Path=/
 +
 
 +
{
 +
  "discounts": [{
 +
    "priceName": "nonrecurring",
 +
    "recurrences": "-1",
 +
    "type": "amount",
 +
    "value": "5.00"
 +
  }]
 +
}</nowiki>
 +
 
 +
'''Response'''
 +
<nowiki>
 +
400 Bad Request
 +
Content-Type : application/json; charset=UTF-8
 +
 
 +
{
 +
  "computeFault" : {
 +
    "guid" : "62967417-b2d6-46fa-8a8d-90d9231ce844",
 +
    "message" : "<class 'order_builder.bl.validation.ValidationError.ValidationError'>: Code: invalid_fee_type, nonrecurring discount fee type is invalid",
 +
    "code" : 400,
 +
    "details" : ""
 +
  }
 +
}</nowiki>
 +
 
 +
=== Invalid discount number of recurrences ===
 +
'''Request'''
 +
<nowiki>
 +
PUT /orders/{orderId}/account/products/{productId}/discounts
 +
Content-Type : application/json; charset=UTF-8
 +
Authorization: Basic dGVzdC52cGxleEBjb3JwX2xkYXBfc2VydmljZV9jaGk6VHJAcXNQODch
 +
Cookie: OwnerId={owner_id}; Path=/
 +
 
 +
{
 +
  "discounts": [{
 +
    "priceName": "recurring",
 +
    "recurrences": "-10",
 +
    "type": "amount",
 +
    "value": "5.00"
 +
  }]
 +
}</nowiki>
 +
 
 +
'''Response'''
 +
<nowiki>
 +
400 Bad Request
 +
Content-Type : application/json; charset=UTF-8
 +
 
 +
{
 +
  "computeFault" : {
 +
    "guid" : "bc360508-3392-4185-a07f-8f8cfff6884e",
 +
    "message" : "<class 'order_builder.bl.validation.ValidationError.ValidationError'>: Code: invalid_discount_period, -10 discount period is invalid",
 +
    "code" : 400,
 +
    "details" : ""
 +
  }
 +
}</nowiki>
 +
 
 +
=== Missing price type ===
 +
'''Request'''
 +
<nowiki>
 +
PUT /orders/{orderId}/account/products/{productId}/discounts
 +
Content-Type : application/json; charset=UTF-8
 +
Authorization: Basic dGVzdC52cGxleEBjb3JwX2xkYXBfc2VydmljZV9jaGk6VHJAcXNQODch
 +
Cookie: OwnerId={owner_id}; Path=/
 +
 
 +
{
 +
  "discounts": [{,
 +
    "recurrences": "-10",
 +
    "type": "amount",
 +
    "value": "5.00"
 +
  }]
 +
}</nowiki>
 +
 
 +
'''Response'''
 +
<nowiki>
 +
400 Bad Request
 +
Content-Type : application/json; charset=UTF-8
 +
 
 +
{
 +
  "badRequest" : {
 +
    "guid" : "5f2c19c5-ae18-4fee-b509-476b7ebe4b9c",
 +
    "message" : "POST data error",
 +
    "code" : 400,
 +
    "details" : {
 +
      "discounts.0.priceName" : "Required"
 +
    }
 +
  }
 +
}</nowiki>
 +
 
 +
=== Missing authorization ===
 +
'''Request'''
 +
<nowiki>
 +
PUT /orders/{orderId}/account/products/{productId}/discounts
 +
Content-Type : application/json; charset=UTF-8
 +
Cookie: OwnerId={owner_id}; Path=/
 +
 
 +
{
 +
  "discounts": [{
 +
    "priceName": "recurring",
 +
    "recurrences": "-1",
 +
    "type": "amount",
 +
    "value": "5.00"
 +
  }]
 +
}</nowiki>
 +
 
 +
'''Response'''
 +
<nowiki>
 +
401 Unauthorized
 +
Content-Type : text/plain; charset=UTF-8
 +
 
 +
401 Unauthorized
 +
 
 +
This server could not verify that you are authorized to access the document you requested.
 +
Either you supplied the wrong credentials (e.g., bad password),
 +
or your browser does not understand how to supply the credentials required.</nowiki>
 +
 
 +
=== Insuffucient privileges ===
 +
'''Request'''
 +
<nowiki>
 +
PUT /orders/{orderId}/account/products/{productId}/discounts
 +
Content-Type : application/json; charset=UTF-8
 +
Authorization: Basic ZWdjUlBtZWZiWnJVQHNpdGVjb250cm9sX2hvc3R3YXlfdXNfbWFpbjpTdnVROGlWOUFTVTc0
 +
Cookie: OwnerId={owner_id}; Path=/
 +
 
 +
{
 +
  "discounts": [{
 +
    "priceName": "recurring",
 +
    "recurrences": "-1",
 +
    "type": "amount",
 +
    "value": "5.00"
 +
  }]
 +
}</nowiki>
 +
 
 +
'''Response'''
 +
<nowiki>
 +
403 Forbidden
 +
Content-Type : application/json; charset=UTF-8
 +
 
 +
{
 +
  "forbidden": {
 +
    "guid": "1912d9fa-5fbe-4e16-b0ba-00d50c9c1ec4",
 +
    "message": "Unauthorized: DiscountsView failed permission check",
 +
    "code": 403,
 +
    "details": ""
 +
  }
 +
}</nowiki>
  
;400 Bad Request
+
=== Order does not exist ===
: Returned if discount data is invalid.
+
'''Request'''
 +
<nowiki>
 +
PUT /orders/{non-existent_orderId}/account/products/{productId}/discounts
 +
Content-Type : application/json; charset=UTF-8
 +
Authorization: Basic dGVzdC52cGxleEBjb3JwX2xkYXBfc2VydmljZV9jaGk6VHJAcXNQODch
 +
Cookie: OwnerId={owner_id}; Path=/
  
;401 Unauthorized
+
{
: The request was not properly authorized.
+
  "discounts": [{
 +
    "priceName": "recurring",
 +
    "recurrences": "-1",
 +
    "type": "amount",
 +
    "value": "5.00"
 +
  }]
 +
}</nowiki>
  
;403 Forbidden
+
'''Response'''
: The client does not have sufficient privileges.
+
<nowiki>
 +
404 Not Found
 +
Content-Type : application/json; charset=UTF-8
  
;404 Not Found
+
{
: Returned if the order could not be found.
+
  "itemNotFound": {
 +
    "guid": "cca219c5-3e2b-481d-8e7f-7083064872ff",
 +
    "message": "Resource not found",
 +
    "code": 404,
 +
    "details": ""
 +
  }
 +
}</nowiki>
  
 
== See also ==
 
== See also ==

Revision as of 11:46, 10 September 2014

PUT /orders/{orderId}/account/products/{productId}/discounts

Set discounts for a Product in an Order. Discounts will be applied only to the specified product. Note: This will replace any existing discounts that were configured for the specified product.

Contents


Request

PUT /orders/{orderId}/account/products/{productId}/discounts

Request Parameters

orderId - string
The unique order Id. The URI of the order is returned by the POST /orders call.
productId - string
UUID specifying the product for which actions are to be performed

URI Parameters

None.

Request Headers

Content-Type
Required. Set this header to application/json; charset=UTF-8
Cookie
A cookie named OwnerId to identify the client (for most browser clients, the browser will do this automatically, depending on the browser configuration). The value of the cookie would come from the response to the create order request in the Set-Cookie response header.

Request Body

{
  "discounts": [
    {
      "priceName": "recurring",
      "recurrences": -1,
      "type": "amount",
      "value": "1.00"
    }
  ]
}
 

Parameters

discounts - list
A list of discounts. Each discount contains the following:
priceName - string
The type of price to which the discount will be applied.
Validation: Should match the fee types configured in the back-end (eg. 'recurring').
recurrences - integer
The number of times that the discount will be applied. A value of "-1" means the discount will be applied every time the fee is charged.
Validation: Should be either a positive integer or -1.
Note: Value must be -1 if the priceName is "recurring".
type - string
Specifies the discount type which determines the method used to calculate the amount that is discounted. Possible values are:
amount: Discount will be treated as an exact amount
percent: Discount will be treated as a percentage
Validation: Should be set to either amount or percent.
value - string
The discount amount. The value will be interpreted based on the specified discount type.
Validation: Should be a positive number.

Response

Status Code

Status Code Error Message Description
204 No Content - The discount was successfully set.
400 Bad Request POST data error Required fields are missing.
Validation Error:
Code: invalid_fee_type, {priceName} discount fee type is invalid Type of price is not recognized by the system.
Code: invalid_discount_amount, {value} discount amount is invalid Discount amount should be a positive number.
Code: unsupported_discount_type, {type} discount type is unsupported Type should be set to either amount or percent.
Code: invalid_discount_period, {recurrences} discount period is invalid Number of reccurences should be either a positive integer or -1. If priceName is recurring, it should be -1.
401 Unauthorized - The request was not properly authorized.
403 Forbidden Unauthorized: DiscountsView failed permission check The client does not have sufficient privileges.
404 Not Found Resource not found Order does not exist.
Product could not be found.
502 Bad Gateway - Unexpected backend response. Cannot set custom discounts.

Example

Success

Request

PUT /orders/{orderId}/account/products/{productId}/discounts
Content-Type : application/json; charset=UTF-8
Authorization: Basic dGVzdC52cGxleEBjb3JwX2xkYXBfc2VydmljZV9jaGk6VHJAcXNQODch
Cookie: OwnerId={owner_id}; Path=/

{
  "discounts": [{
    "priceName": "recurring",
    "recurrences": "-1",
    "type": "amount",
    "value": "5.00"
  }]
}

Response

204 No Content

Invalid discount amount

Request

PUT /orders/{orderId}/account/products/{productId}/discounts
Content-Type : application/json; charset=UTF-8
Authorization: Basic dGVzdC52cGxleEBjb3JwX2xkYXBfc2VydmljZV9jaGk6VHJAcXNQODch
Cookie: OwnerId={owner_id}; Path=/

{
  "discounts": [{
    "priceName": "recurring",
    "recurrences": "-1",
    "type": "amount",
    "value": "-5.00"
  }]
}

Response

400 Bad Request
Content-Type : application/json; charset=UTF-8

{
  "computeFault": {
    "guid": "c3563e61-a297-4dbe-b072-24aace7b5e44",
    "message": "<class 'order_builder.bl.validation.ValidationError.ValidationError'>: Code: invalid_discount_amount, -5.00 discount amount is invalid",
    "code": 400,
    "details": ""
  }
}

Invalid discount type

Request

PUT /orders/{orderId}/account/products/{productId}/discounts
Content-Type : application/json; charset=UTF-8
Authorization: Basic dGVzdC52cGxleEBjb3JwX2xkYXBfc2VydmljZV9jaGk6VHJAcXNQODch
Cookie: OwnerId={owner_id}; Path=/

{
  "discounts": [{
    "priceName": "recurring",
    "recurrences": "-1",
    "type": "numbers",
    "value": "5.00"
  }]
}

Response

400 Bad Request
Content-Type : application/json; charset=UTF-8

{
  "computeFault": {
    "guid": "1a94f744-5b33-4d54-ab28-77b875934829",
    "message": "<class 'order_builder.bl.validation.ValidationError.ValidationError'>: Code: unsupported_discount_type, amounts discount type is unsupported",
    "code": 400,
    "details": ""
  }
}

Invalid price type

Request

PUT /orders/{orderId}/account/products/{productId}/discounts
Content-Type : application/json; charset=UTF-8
Authorization: Basic dGVzdC52cGxleEBjb3JwX2xkYXBfc2VydmljZV9jaGk6VHJAcXNQODch
Cookie: OwnerId={owner_id}; Path=/

{
  "discounts": [{
    "priceName": "nonrecurring",
    "recurrences": "-1",
    "type": "amount",
    "value": "5.00"
  }]
}

Response

400 Bad Request
Content-Type : application/json; charset=UTF-8

{
  "computeFault" : {
    "guid" : "62967417-b2d6-46fa-8a8d-90d9231ce844",
    "message" : "<class 'order_builder.bl.validation.ValidationError.ValidationError'>: Code: invalid_fee_type, nonrecurring discount fee type is invalid",
    "code" : 400,
    "details" : ""
  }
}

Invalid discount number of recurrences

Request

PUT /orders/{orderId}/account/products/{productId}/discounts
Content-Type : application/json; charset=UTF-8
Authorization: Basic dGVzdC52cGxleEBjb3JwX2xkYXBfc2VydmljZV9jaGk6VHJAcXNQODch
Cookie: OwnerId={owner_id}; Path=/

{
  "discounts": [{
    "priceName": "recurring",
    "recurrences": "-10",
    "type": "amount",
    "value": "5.00"
  }]
}

Response

400 Bad Request
Content-Type : application/json; charset=UTF-8

{
  "computeFault" : {
    "guid" : "bc360508-3392-4185-a07f-8f8cfff6884e",
    "message" : "<class 'order_builder.bl.validation.ValidationError.ValidationError'>: Code: invalid_discount_period, -10 discount period is invalid",
    "code" : 400,
    "details" : ""
  }
}

Missing price type

Request

PUT /orders/{orderId}/account/products/{productId}/discounts
Content-Type : application/json; charset=UTF-8
Authorization: Basic dGVzdC52cGxleEBjb3JwX2xkYXBfc2VydmljZV9jaGk6VHJAcXNQODch
Cookie: OwnerId={owner_id}; Path=/

{
  "discounts": [{,
    "recurrences": "-10",
    "type": "amount",
    "value": "5.00"
  }]
}

Response

400 Bad Request
Content-Type : application/json; charset=UTF-8

{
  "badRequest" : {
    "guid" : "5f2c19c5-ae18-4fee-b509-476b7ebe4b9c",
    "message" : "POST data error",
    "code" : 400,
    "details" : {
      "discounts.0.priceName" : "Required"
    }
  }
}

Missing authorization

Request

PUT /orders/{orderId}/account/products/{productId}/discounts
Content-Type : application/json; charset=UTF-8
Cookie: OwnerId={owner_id}; Path=/

{
  "discounts": [{
    "priceName": "recurring",
    "recurrences": "-1",
    "type": "amount",
    "value": "5.00"
  }]
}

Response

401 Unauthorized
Content-Type : text/plain; charset=UTF-8

401 Unauthorized

This server could not verify that you are authorized to access the document you requested.
Either you supplied the wrong credentials (e.g., bad password),
or your browser does not understand how to supply the credentials required.

Insuffucient privileges

Request

PUT /orders/{orderId}/account/products/{productId}/discounts
Content-Type : application/json; charset=UTF-8
Authorization: Basic ZWdjUlBtZWZiWnJVQHNpdGVjb250cm9sX2hvc3R3YXlfdXNfbWFpbjpTdnVROGlWOUFTVTc0
Cookie: OwnerId={owner_id}; Path=/

{
  "discounts": [{
    "priceName": "recurring",
    "recurrences": "-1",
    "type": "amount",
    "value": "5.00"
  }]
}

Response

403 Forbidden
Content-Type : application/json; charset=UTF-8

{
  "forbidden": {
    "guid": "1912d9fa-5fbe-4e16-b0ba-00d50c9c1ec4",
    "message": "Unauthorized: DiscountsView failed permission check",
    "code": 403,
    "details": ""
  }
}

Order does not exist

Request

PUT /orders/{non-existent_orderId}/account/products/{productId}/discounts
Content-Type : application/json; charset=UTF-8
Authorization: Basic dGVzdC52cGxleEBjb3JwX2xkYXBfc2VydmljZV9jaGk6VHJAcXNQODch
Cookie: OwnerId={owner_id}; Path=/

{
  "discounts": [{
    "priceName": "recurring",
    "recurrences": "-1",
    "type": "amount",
    "value": "5.00"
  }]
}

Response

404 Not Found
Content-Type : application/json; charset=UTF-8

{
  "itemNotFound": {
    "guid": "cca219c5-3e2b-481d-8e7f-7083064872ff",
    "message": "Resource not found",
    "code": 404,
    "details": ""
  }
}

See also


blog comments powered by Disqus

Personal tools
Namespaces
Variants
Actions
APIs
Navigation
Toolbox