Skip to content

Commit

Permalink
Merge pull request #21 from pjaudiomv/master
Browse files Browse the repository at this point in the history
Add optional order_type input to dominos_order resource
  • Loading branch information
nat-henderson committed Sep 27, 2023
2 parents 5fc1d38 + 5756d7b commit 010f181
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/index.md
Expand Up @@ -111,6 +111,7 @@ This is it! This will order you your pizzas! Configure it with:
* `address_api_object`, from your `dominos_address` data source.
* `item_codes`, a list of strings, from your `dominos_menu_item` or `dominos_menu` data source.
* `store_id`, the ID from your `dominos_store` data source.
* `order_type`, optional. valid options are `Delivery` or `Carryout`, defaults to `Delivery`.

As far as I know there is no way to cancel a dominos order programmatically, so if you made a mistake, you'll have to call the store. You should receive an email confirmation almost instantly, and that email will have the store's phone number in it.

Expand Down
16 changes: 15 additions & 1 deletion resource_order.go
Expand Up @@ -37,13 +37,27 @@ func resourceOrder() *schema.Resource {
Required: true,
ForceNew: true,
},
"order_type": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: "Delivery",
ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) {
value := val.(string)
if value != "Delivery" && value != "Carryout" {
errs = append(errs, fmt.Errorf("order_type must be either 'Delivery' or 'Carryout'"))
}
return
},
},
},
}
}

func resourceOrderCreate(d *schema.ResourceData, m interface{}) error {
var client = &http.Client{Timeout: 10 * time.Second}
store_id := d.Get("store_id").(string)
order_type := d.Get("order_type").(string)
address_obj := make(map[string]interface{})
err := json.NewDecoder(strings.NewReader(d.Get("address_api_object").(string))).Decode(&address_obj)
if err != nil {
Expand All @@ -63,7 +77,7 @@ func resourceOrderCreate(d *schema.ResourceData, m interface{}) error {
"Products": []map[string]interface{}{},
"Market": "",
"Currency": "",
"ServiceMethod": "Delivery",
"ServiceMethod": order_type,
"Tags": map[string]string{},
"Version": "1.0",
"SourceOrganizationURI": "order.dominos.com",
Expand Down

0 comments on commit 010f181

Please sign in to comment.