Skip to content

Commit

Permalink
[Order] Add total_price
Browse files Browse the repository at this point in the history
  • Loading branch information
MNThomson committed Jun 15, 2022
1 parent 1265b3b commit cd1d927
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 23 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# Terraform
example.tf
.terraform/*
*tfstate*
crash.log

# Binary
terraform-provider-dominos

# VSCode
.vscode
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
main: *.go
build: *.go
go get && go build -o terraform-provider-dominos ./

localinstall:
make clean
make build
mkdir -p ~/.terraform.d/plugins/terraform.local/mnthomson/dominos/0.1.0/linux_amd64/
cp terraform-provider-dominos ~/.terraform.d/plugins/terraform.local/mnthomson/dominos/0.1.0/linux_amd64/terraform-provider-dominos_v0.1.0

clean:
rm -rf .terraform .terraform.lock.hcl
rm -rf terraform-provider-dominos
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ Then write your config. Here's a sample config - a variation on this worked for

```hcl
terraform {
required_providers {
dominos = {
source = "mnthomson/dominos"
}
required_providers {
dominos = {
source = "MNThomson/dominos"
}
}
}
provider "dominos" {
Expand All @@ -35,18 +35,18 @@ data "dominos_address" "addr" {
}
data "dominos_store" "store" {
address_url_object = "${data.dominos_address.addr.url_object}"
address_url_object = data.dominos_address.addr.url_object
}
data "dominos_menu_item" "item" {
store_id = "${data.dominos_store.store.store_id}"
store_id = data.dominos_store.store.store_id
query_string = ["philly", "medium"]
}
resource "dominos_order" "order" {
address_api_object = "${data.dominos_address.addr.api_object}"
address_api_object = data.dominos_address.addr.api_object
item_codes = ["${data.dominos_menu_item.item.matches.0.code}"]
store_id = "${data.dominos_store.store.store_id}"
store_id = data.dominos_store.store.store_id
}
```

Expand Down
37 changes: 23 additions & 14 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,50 @@ chmod +x ~/.terraform.d/plugins/terraform-provider-dominos
## Sample Configuration

```hcl
terraform {
required_providers {
dominos = {
source = "MNThomson/dominos"
}
}
}
provider "dominos" {
first_name = "My"
last_name = "Name"
email_address = "my@name.com"
phone_number = "15555555555"
credit_card {
number = 123456789101112
cvv = 1314
date = "15/16"
zip = 18192
number = 123456789101112
cvv = 1314
date = "15/16"
postalcode = 18192
}
}
data "dominos_address" "addr" {
street = "123 Main St"
city = "Anytown"
state = "WA"
zip = "02122"
street = "123 Main St"
city = "Anytown"
state = "WA"
postalcode = "02122"
}
data "dominos_store" "store" {
address_url_object = "${data.dominos_address.addr.url_object}"
address_url_object = data.dominos_address.addr.url_object
}
data "dominos_menu_item" "item" {
store_id = "${data.dominos_store.store.store_id}"
store_id = data.dominos_store.store.store_id
query_string = ["philly", "medium"]
}
resource "dominos_order" "order" {
address_api_object = "${data.dominos_address.addr.api_object}"
address_api_object = data.dominos_address.addr.api_object
item_codes = ["${data.dominos_menu_item.item.matches.0.code}"]
store_id = "${data.dominos_store.store.store_id}"
store_id = data.dominos_store.store.store_id
}
```

Now I don't know what you're going to get since I don't know what a medium philly is in your area, but in my area it gets you a 12" hand-tossed philly cheesesteak pizza, and it's pretty good. It's all right. Regular dominos.
Expand All @@ -77,15 +86,15 @@ The credit card fields are optional - if you do not configure a credit card, you
The `credit_card` block requires the following fields:
* `number`: just an integer, the whole credit card number. The API accepts Visa, Amex, and Mastercard.
* `cvv`: also an integer
* `zip`: integer!
* `postalcode`: integer!
* `date`: The expiration date, as a string, with a slash between the month and year, e.g. `03/19`.

If you don't plan to place an order, you don't need to fill this out.

## Data Sources
### `dominos_address`

This data source takes in your address and writes it back out in the two different JSON formats that the API expects. Configure it with `street`, `city`, `state`, and `zip`, and use `url_object` and `api_object` in other data sources where required.
This data source takes in your address and writes it back out in the two different JSON formats that the API expects. Configure it with `street`, `city`, `state`, and `postalcode`, and use `url_object` and `api_object` in other data sources where required.

### `dominos_store`

Expand Down
16 changes: 16 additions & 0 deletions internal/provider/resource_order.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ func resourceOrder() *schema.Resource {
Required: true,
ForceNew: true,
},
"price_only": &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Default: false,
ForceNew: true,
},
"total_price": &schema.Schema{
Type: schema.TypeFloat,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -134,6 +144,12 @@ func resourceOrderCreate(d *schema.ResourceData, m interface{}) error {
}
}

price := order_data["Amounts"].(map[string]interface{})["Customer"]
d.Set("total_price", price.(float64))
if d.Get("price_only").(bool) {
return nil
}

if config.CreditCardNumber != 0 {
order_data["Payments"] = []map[string]interface{}{map[string]interface{}{
"Type": "CreditCard",
Expand Down

0 comments on commit cd1d927

Please sign in to comment.