1/**
2 * Copyright 2016 IBM Corp.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *    http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package main
18
19import (
20	"fmt"
21
22	"github.com/softlayer/softlayer-go/datatypes"
23	"github.com/softlayer/softlayer-go/helpers/location"
24	"github.com/softlayer/softlayer-go/helpers/order"
25	"github.com/softlayer/softlayer-go/services"
26	"github.com/softlayer/softlayer-go/session"
27)
28
29func testHelpers() {
30	sess := session.New() // default endpoint
31
32	sess.Debug = true
33
34	// Demonstrate order status helpers using a simulated product order receipt
35
36	// First, get any valid order item ID
37	items, err := services.GetAccountService(sess).
38		Mask("orderItemId").
39		GetNextInvoiceTopLevelBillingItems()
40
41	// Create a receipt object to pass to the method
42	receipt := datatypes.Container_Product_Order_Receipt{
43		PlacedOrder: &datatypes.Billing_Order{
44			Items: []datatypes.Billing_Order_Item{
45				datatypes.Billing_Order_Item{
46					Id: items[0].OrderItemId,
47				},
48			},
49		},
50	}
51
52	complete, _, err := order.CheckBillingOrderStatus(sess, &receipt, []string{"COMPLETE", "PENDING"})
53	if err != nil {
54		fmt.Println(err)
55	} else {
56		fmt.Printf("Order in COMPLETE or PENDING status: %t\n", complete)
57	}
58
59	complete, _, err = order.CheckBillingOrderStatus(sess, &receipt, []string{"PENDING", "CANCELLED"})
60	if err != nil {
61		fmt.Println(err)
62	} else {
63		fmt.Printf("Order in CANCELLED or PENDING status: %t\n", complete)
64	}
65
66	complete, _, err = order.CheckBillingOrderComplete(sess, &receipt)
67	if err != nil {
68		fmt.Println(err)
69	} else {
70		fmt.Printf("Order is Complete: %t\n", complete)
71	}
72
73	// Demonstrate GetDataCenterByName
74
75	l, err := location.GetDatacenterByName(sess, "ams01")
76	fmt.Printf("Found Datacenter: %d\n", *l.Id)
77}
78