Skip to content

Instantly share code, notes, and snippets.

@dongarchive
Created November 27, 2019 20:21
Show Gist options
  • Save dongarchive/62c404829911fc0c95a3acd2a252c1ef to your computer and use it in GitHub Desktop.
Save dongarchive/62c404829911fc0c95a3acd2a252c1ef to your computer and use it in GitHub Desktop.
Demo instructions for Ecommerce Order Service - Phase 1 - Nov 29 2019

Demo Instructions

Setup Services

1. Ecommerce Order Service Core & Kafka cluster

(1) In ecommerce_order_service repo startup the core and kafka cluster with an empty db volume

$ docker volume prune
$ docker-compose up

2. Payment Adapter Consumer (Payment Requirement)

(1) Grab the the network that the kafka cluster is running on (most likely the ecommerce_order_service), this is indicated when you start the kafka cluster, eg: Creating network "ecommerce_order_service_default" with the default driver

(2) Grab the docker image of this repository (eg: ecommerce_payment_consumer_adapter) by running docker images

(3) With the ecommerce_order_service running, find the IP address of the docker container so the endpoints can be hit by running docker inspect **CONTAINER_ID** | grep -i "IPAddress" (eg. 172.18.0.5). This step has to be done as the local server IP address cannot be accessed utilizing localhost:3000

(4) Docker run with the network and inject all the environment variables as needed

docker run --net=**NETWORK_NAME** -e KAFKA_BROKER_LIST=**BROKER_LIST** -e KAFKA_CONSUMER_TOPIC=**TOPIC** -e KAFKA_CONSUMER_GROUP_ID="ID" -e LOG_LEVEL="DEBUG" -e ECOMMERCE_HOST_AND_PROTOCOL=**HOST_AND_PROTOCOL** -e ECOMMERCE_TOKEN="dummy" -it ecommerce_payment_consumer_adapter:latest sh

eg.

docker run --net=ecommerce_order_service_default -e KAFKA_BROKER_LIST="kafka:9092" -e KAFKA_CONSUMER_TOPIC="payment_requirement" -e KAFKA_CONSUMER_GROUP_ID="ID" -e LOG_LEVEL="DEBUG" -e ECOMMERCE_HOST_AND_PROTOCOL="http://172.18.0.5:3000" -e ECOMMERCE_TOKEN="dummy_token" -it ecommerce_payment_consumer_adapter:latest sh

(5) Initialize the kafka consumer by running bundle exec ruby lib/init.rb

3. Dummy Kafka AB Producer (Payment Requirements) -> produces messages from AB.com to Ecommerce Order Service

(1) In ecommerce_order_service repo where the kafka cluster is instantiated -> create a dummy kafka producer that produces to payment_requirement topic

$ docker-compose exec kafka bash
$ ./opt/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic payment_requirement

4. Dummy Kafka AB Consumer (Order Items) -> consumes messages from Ecommerce Order Service to AB.com

(1) In ecommerce_order_service repo where the kafka cluster is instantiated -> create a dummy kafka consumer that consumes from the order_item topic

$ docker-compose exec kafka bash
$ ./opt/kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic order_item

Order Items

(1) SHOW that no order items are within the database (POSTMAN)

GET localhost:3000/order_items

(2) PRODUCE multiple payment requirements through the dummy kafka AB producer

$ {"event_name": "requirement_created","event_object": {"amount": 200,"application_id": 1,"currency": "CAD","description": "Dummy requirement created request -> application fee","item_type": "application_fee","label": "Application Fee","status": "cart","payment_methods_allowed": ["online","manual"],"requirement_id": 1}}
$ {"event_name": "requirement_created","event_object": {"amount": 100,"application_id": 1,"currency": "CAD","description": "Dummy requirement created request -> application fee","item_type": "application_fee","label": "Application Fee","status": "unready","payment_methods_allowed": ["online","manual"],"requirement_id": 2}}
$ {"event_name": "requirement_created","event_object": {"amount": 300,"application_id": 1,"currency": "CAD","description": "Dummy requirement created request -> application fee","item_type": "application_fee","label": "Application Fee","status": "cart","payment_methods_allowed": ["online","manual"],"requirement_id": 3}}

The appropriate create order item messages should be shown in both consumers:

Payment Requirement Topic -> requirement_created Order Item Topic -> order_item_created

(3) SHOW that all order items have been created through the initial kafka messsage (POSTMAN)

GET localhost:3000/order_items

(4) PRODUCE a delete order item kafka message

$ {"event_name": "requirement_deleted","event_object": {"order_item_id": 3}}

The appropriate delete order item messages should be shown in both consumers:

Payment Requirement Topic -> requirement_deleted Order Item Topic -> order_item_deleted

(5) SHOW that the order item was deleted (POSTMAN)

GET localhost:3000/order_items

(6) CREATE order for application and associated order items (POSTMAN)

POST localhost:3000/orders

{
	"data": {
		"attributes": {
			"applicant_id": 10,
			"application_ids": [1]
		}
	}
}

This will produce an error because one of the order items is an invalid status and has an "unready" status

(7) PRODUCE a order item update to change appropriate order item that was unready to cart status so we can create an order

$ {"event_name": "requirement_updated","event_object": {"order_item_id": 2, "status": "cart", "description": "Change status to cart on order item"}}

The appropriate updated order item messages should be shown in both consumers:

Payment Requirement Topic -> requirement_updated Order Item Topic -> order_item_updated

(8) SHOW that all order items are now in the "cart" status and an order can now be created (POSTMAN)

GET localhost:3000/order_items

Orders

(1) CREATE an order for application (POSTMAN)

POST localhost:3000/orders

{
	"data": {
		"attributes": {
			"applicant_id": 10,
			"application_ids": [1]
		}
	}
}

(2) SHOW the order(s) that were just created (POSTMAN)

GET localhost:3000/orders

(3) PAY for the order utilizing Stripe (POSTMAN)

POST localhost:3000/orders/pay

{
	"data":{
		"attributes": {
			"ids": [1],
			"submitter_id": 50,
			"payer_id": 80,
			"payment_method_id": "pm_card_visa",
			"payment_type": "stripe"
			
		}
	}
}

The appropriate order paid message should be shown in the order item consumer:

Order Item Topic -> order_paid

(4) SHOW that the order(s) now has the status complete along with the paid_by_id and submitted_by_id fields (POSTMAN)

GET localhost:3000/orders

(5) SHOW that all order items associated with that order now have a status "paid" (POSTMAN)

GET localhost:3000/orders

or

GET localhost:3000/orders/:id

(6) Attempt to PAY for the same order again via stripe

  • Failure should occur since order is already complete
POST localhost:3000/orders/pay

{
	"data":{
		"attributes": {
			"ids": [1],
			"submitter_id": 50,
			"payer_id": 80,
			"payment_method_id": "pm_card_visa",
			"payment_type": "stripe"
			
		}
	}
}

Handling of order items with different currencies

(1) PRODUCE three new payment requirements

$ {"event_name": "requirement_created","event_object": {"amount": 100,"application_id": 2,"currency": "CAD","description": "Dummy requirement created request -> application fee","item_type": "application_fee","label": "Application Fee","status": "cart","payment_methods_allowed": ["online","manual"],"requirement_id": 4}}
$ {"event_name": "requirement_created","event_object": {"amount": 200,"application_id": 3,"currency": "USD","description": "Dummy requirement created request -> application fee","item_type": "application_fee","label": "Application Fee","status": "ready","payment_methods_allowed": ["online","manual"],"requirement_id": 5}}
$ {"event_name": "requirement_created","event_object": {"amount": 300,"application_id": 4,"currency": "CAD","description": "Dummy requirement created request -> application fee","item_type": "application_fee","label": "Application Fee","status": "cart","payment_methods_allowed": ["online","manual"],"requirement_id": 6}}

(2) CREATE an order for the applications associated with the order items that were just created

POST localhost:3000/orders

{
	"data": {
		"attributes": {
			"applicant_id": 11,
			"application_ids": [2,3,4]
		}
	}
}

(3) SHOW that individual orders are grouped by currency of the order items associated with the application ids passed in when creating an order

GET localhost:3000/orders
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment