Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(docs): Adds dredd tests for calculate-amount API #7263

Merged
merged 1 commit into from
Sep 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions docs/api/blueprint/order/orders.apib
Original file line number Diff line number Diff line change
Expand Up @@ -735,3 +735,90 @@ Create paypal payment
"payment_id": "example",
"error": null
}

## Calculate Order Amount [/v1/orders/calculate-amount]

### Calculate Order Amount [POST]
Calculates the order amount

+ Request (application/json)

+ Headers

Accept: application/json

Authorization: JWT <Auth Key>

+ Body

{
"tickets": [
{"id": 1, "quantity": 2},
{"id": 2, "quantity": 4},
{"id": 3, "quantity": 3, "price": 789.7},
{"id": 4, "quantity": 3}
],
"discount_code": "1"
}

+ Response 200 (application/json)

{
"discount": 419.43,
"sub_total": 4021.87,
"tax": {
"amount": 723.94,
"included": false,
"name": "GST",
"percent": 18
},
"tickets": [
{
"discount": null,
"id": 1,
"name": "example",
"price": 123.5,
"quantity": 2,
"sub_total": 247,
"ticket_fee": 0
},
{
"discount": {
"amount": 45.63,
"code": "example",
"percent": 10,
"total": 182.52
},
"id": 2,
"name": "example",
"price": 456.3,
"quantity": 4,
"sub_total": 1642.68,
"ticket_fee": 0
},
{
"discount": {
"amount": 78.97,
"code": "example",
"percent": 10,
"total": 236.91
},
"id": 3,
"name": "example",
"price": 789.7,
"quantity": 3,
"sub_total": 2132.19,
"ticket_fee": 0
},
{
"discount": null,
"id": 4,
"name": "example",
"price": 0,
"quantity": 3,
"sub_total": 0,
"ticket_fee": 0
}
],
"total": 4745.81
}
17 changes: 15 additions & 2 deletions tests/hook_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4226,9 +4226,22 @@ def create_order(transaction):
discount_code = DiscountCodeTicketSubFactory(
type='percent', value=10.0, tickets=[]
)
tickets_dict = _create_taxed_tickets(
db, tax_included=False, discount_code=discount_code
_create_taxed_tickets(db, tax_included=False, discount_code=discount_code)
db.session.commit()


@hooks.before("Orders > Calculate Order Amount > Calculate Order Amount")
def calculate_amount(transaction):
"""
POST /orders/calculate-amount
:param transaction:
:return:
"""
with stash['app'].app_context():
discount_code = DiscountCodeTicketSubFactory(
blossom2017 marked this conversation as resolved.
Show resolved Hide resolved
type='percent', value=10.0, tickets=[]
)
_create_taxed_tickets(db, tax_included=False, discount_code=discount_code)
db.session.commit()


Expand Down