Skip to content
Kenny Bastani edited this page Jan 3, 2017 · 1 revision

Usage

Create an account.

curl -X POST -H "Content-Type: application/hal+json" -H "accept: application/hal+json" -d '{ 
	"firstName": "Jessica", 
	"lastName": "Jones", 
	"email": "jj@example.com"
}' "http://localhost:56042/v1/accounts"
{
  "createdAt": 1483458386497,
  "lastModified": 1483458386497,
  "firstName": "Jessica",
  "lastName": "Jones",
  "email": "jj@example.com",
  "status": "ACCOUNT_CREATED",
  "_links": {
    "commands": {
      "href": "http://localhost:50446/v1/accounts/1/commands"
    },
    "events": {
      "href": "http://localhost:50446/v1/accounts/1/events"
    },
    "orders": {
      "href": "http://localhost:50446/v1/accounts/1/orders"
    },
    "self": {
      "href": "http://localhost:50446/v1/accounts/1"
    }
  },
  "accountId": 1
}

Next we will post a new order to the account. First, follow the commands link on the account we just created.

curl -X GET "http://localhost:50446/v1/accounts/1/commands"
{
  "_links": {
    "suspend": {
      "href": "http://localhost:50446/v1/accounts/1/commands/suspend"
    },
    "activate": {
      "href": "http://localhost:50446/v1/accounts/1/commands/activate"
    },
    "archive": {
      "href": "http://localhost:50446/v1/accounts/1/commands/archive"
    },
    "confirm": {
      "href": "http://localhost:50446/v1/accounts/1/commands/confirm"
    },
    "postOrder": {
      "href": "http://localhost:50446/v1/accounts/1/commands/postOrder"
    }
  }
}

Now follow the postOrder link. We'll send a POST request to this URL with information about the new order.

curl -X POST -H "Content-Type: application/json" -d '{
	"lineItems": [{
		"name": "Best. Cloud. Ever. (T-Shirt, Men'"'"'s Large)",
		"productId": "SKU-24642",
		"quantity": 1,
		"price": 21.99,
		"tax": 0.06
	}, {
		"name": "Like a BOSH (T-Shirt, Women's Medium)",
		"productId": "SKU-34563",
		"quantity": 3,
		"price": 14.99,
		"tax": 0.06
	}],
	"shippingAddress": {
		"street1": "1600 Pennsylvania Ave NW",
		"state": "DC",
		"city": "Washington",
		"country": "United States",
		"zipCode": 20500,
		"addressType": "SHIPPING"
	}
}' "http://localhost:50446/v1/accounts/1/commands/postOrder"

Now follow the orders link.

{
  "_embedded": {
    "orderList": [
      {
        "status": "ACCOUNT_CONNECTED",
        "lineItems": [
          {
            "name": "Best. Cloud. Ever. (T-Shirt, Men's Large)",
            "productId": "SKU-24642",
            "quantity": 1,
            "price": 21.99,
            "tax": 0.06
          },
          {
            "name": "Like a BOSH (T-Shirt, Women's Medium)",
            "productId": "SKU-34563",
            "quantity": 3,
            "price": 14.99,
            "tax": 0.06
          }
        ],
        "shippingAddress": {
          "street1": "1600 Pennsylvania Ave NW",
          "state": "DC",
          "city": "Washington",
          "country": "United States",
          "zipCode": 20500,
          "addressType": "SHIPPING"
        },
        "accountId": 1,
        "_links": {
          "self": {
            "href": "http://10.0.0.171:50452/v1/orders/1"
          }
        }
      }
    ]
  },
  "_links": {
    "self": {
      "href": "http://localhost:50446/v1/accounts/1/orders"
    },
    "account": {
      "href": "http://localhost:50446/v1/accounts/1"
    }
  }
}

Follow the self link for the first order.

{
  "createdAt": 1483458677903,
  "lastModified": 1483458678321,
  "status": "ACCOUNT_CONNECTED",
  "lineItems": [
    {
      "name": "Best. Cloud. Ever. (T-Shirt, Men's Large)",
      "productId": "SKU-24642",
      "quantity": 1,
      "price": 21.99,
      "tax": 0.06
    },
    {
      "name": "Like a BOSH (T-Shirt, Women's Medium)",
      "productId": "SKU-34563",
      "quantity": 3,
      "price": 14.99,
      "tax": 0.06
    }
  ],
  "shippingAddress": {
    "street1": "1600 Pennsylvania Ave NW",
    "state": "DC",
    "city": "Washington",
    "country": "United States",
    "zipCode": 20500,
    "addressType": "SHIPPING"
  },
  "accountId": 1,
  "_links": {
    "commands": {
      "href": "http://10.0.0.171:50452/v1/orders/1/commands"
    },
    "events": {
      "href": "http://10.0.0.171:50452/v1/orders/1/events"
    },
    "account": {
      "href": "http://10.0.0.171:50446/v1/accounts/1"
    },
    "self": {
      "href": "http://10.0.0.171:50452/v1/orders/1"
    }
  },
  "orderId": 1
}

Now we'll create a payment for this order. Follow the commands link.

{
  "_links": {
    "connectAccount": {
      "href": "http://10.0.0.171:50452/v1/orders/1/commands/connectAccount{?accountId}",
      "templated": true
    },
    "connectPayment": {
      "href": "http://10.0.0.171:50452/v1/orders/1/commands/connectPayment{?paymentId}",
      "templated": true
    },
    "createPayment": {
      "href": "http://10.0.0.171:50452/v1/orders/1/commands/createPayment"
    },
    "processPayment": {
      "href": "http://10.0.0.171:50452/v1/orders/1/commands/processPayment"
    },
    "reserveInventory": {
      "href": "http://10.0.0.171:50452/v1/orders/1/commands/reserveInventory"
    }
  }
}

Now follow the createPayment link.

{
  "createdAt": 1483458677903,
  "lastModified": 1483459047305,
  "status": "PAYMENT_CREATED",
  "lineItems": [
    {
      "name": "Best. Cloud. Ever. (T-Shirt, Men's Large)",
      "productId": "SKU-24642",
      "quantity": 1,
      "price": 21.99,
      "tax": 0.06
    },
    {
      "name": "Like a BOSH (T-Shirt, Women's Medium)",
      "productId": "SKU-34563",
      "quantity": 3,
      "price": 14.99,
      "tax": 0.06
    }
  ],
  "shippingAddress": {
    "street1": "1600 Pennsylvania Ave NW",
    "state": "DC",
    "city": "Washington",
    "country": "United States",
    "zipCode": 20500,
    "addressType": "SHIPPING"
  },
  "accountId": 1,
  "_links": {
    "commands": {
      "href": "http://10.0.0.171:50452/v1/orders/1/commands"
    },
    "events": {
      "href": "http://10.0.0.171:50452/v1/orders/1/events"
    },
    "account": {
      "href": "http://10.0.0.171:50446/v1/accounts/1"
    },
    "self": {
      "href": "http://10.0.0.171:50452/v1/orders/1"
    }
  },
  "orderId": 1
}

Worker processes in the background are executing a workflow that automatically updates the state of domain objects. After we've created a payment, the payment will be connected to the account. Follow the self link to get the updated state of the order, which should now have a connected payment.

{
  "createdAt": 1483458677903,
  "lastModified": 1483459047538,
  "status": "PAYMENT_CONNECTED",
  "lineItems": [
    {
      "name": "Like a BOSH (T-Shirt, Women's Medium)",
      "productId": "SKU-34563",
      "quantity": 3,
      "price": 14.99,
      "tax": 0.06
    },
    {
      "name": "Best. Cloud. Ever. (T-Shirt, Men's Large)",
      "productId": "SKU-24642",
      "quantity": 1,
      "price": 21.99,
      "tax": 0.06
    }
  ],
  "shippingAddress": {
    "street1": "1600 Pennsylvania Ave NW",
    "state": "DC",
    "city": "Washington",
    "country": "United States",
    "zipCode": 20500,
    "addressType": "SHIPPING"
  },
  "accountId": 1,
  "paymentId": 1,
  "_links": {
    "commands": {
      "href": "http://10.0.0.171:50452/v1/orders/1/commands"
    },
    "events": {
      "href": "http://10.0.0.171:50452/v1/orders/1/events"
    },
    "account": {
      "href": "http://10.0.0.171:50446/v1/accounts/1"
    },
    "payment": {
      "href": "http://10.0.0.171:50459/v1/payments/1"
    },
    "self": {
      "href": "http://10.0.0.171:50452/v1/orders/1"
    }
  },
  "orderId": 1
}

Now we can retrieve the payment via the payment link.

{
  "createdAt": 1483459046321,
  "lastModified": 1483459047453,
  "status": "ORDER_CONNECTED",
  "amount": 67.2,
  "orderId": 1,
  "paymentMethod": "CREDIT_CARD",
  "_links": {
    "commands": {
      "href": "http://10.0.0.171:50459/v1/payments/1/commands"
    },
    "events": {
      "href": "http://10.0.0.171:50459/v1/payments/1/events"
    },
    "order    ": {
      "href": "http://10.0.0.171:50452/v1/orders/1"
    },
    "self": {
      "href": "http://10.0.0.171:50459/v1/payments/1"
    }
  },
  "paymentId": 1
}
Clone this wiki locally