> For the complete documentation index, see [llms.txt](https://docs.microservice-stack.com/introduction/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.microservice-stack.com/introduction/demo-project/order-payment-reservation.md).

# Order payment reservation

{% embed url="<https://github.com/FurlanLuka/microservice-stack-shop-demo/pull/6>" %}

In this step order payment functionality is added to the customer service. Customer entity has a property which defines how many spendable credits the customer has available. In this step we add a simple endpoint with which customer can top up their credits.

The order payment is done by Customer service listening to the Order created event, which is broadcasted by the Order service once the order is created.

To listen to the event, a Customer queue controller is created. The RabbitMQ service works in a way so that Subscription decorators have to be defined in a service separate from the Rest controllers. In case both are defined in the same service, Rest controllers will no longer work. You can see the queue controller implementation in the link bellow

{% embed url="<https://github.com/FurlanLuka/microservice-stack-shop-demo/pull/6/files#diff-a8e5e068b604a30904cc902ddba816ef96097885f4b665971db2c8c84c6f6f23>" %}
CustomerQueueController
{% endembed %}

Once the order created event is received, the customer service will either&#x20;

* Decrement customers available credits balance, create reserved credits entity tied to the order id and broadcast Order payment reserved event
* Broadcast Order payment failed event, in case the customer doesn't have high enough balance.

{% embed url="<https://github.com/FurlanLuka/microservice-stack-shop-demo/pull/6/files#diff-e221cffd3d4993205b72dbbd2a284a8abf172d91e7a99eb607d482c48108630aR134>" %}
Reserve order payment logic
{% endembed %}

With these events broadcasted, Order service can now listen to these events and update the order status accordingly

{% embed url="<https://github.com/FurlanLuka/microservice-stack-shop-demo/pull/6/files#diff-d0556d3901b84079b48cb1623411d25e8fb7ae6091176cf34091345c66d4adecR50>" %}
OrderQueueController
{% endembed %}

### Testing order payment reservation

To test the new updates, we should first update both customer and order service in the local cluster.

To test the new payment reservation functionality lets create new order

![](/files/rG6aamprWvdqv49tbGJT)

Once the order is created, the get details endpoint should return that the order has failed. This happened because customer had no credits.

![](/files/8xAN01TGMH9B90Pnjjlw)

For the next step, lets add some credits to customer account

![](/files/CfNTX7sOKDBye6fod6Jv)

After this is done, we should create a new order. This time, the order details endpoint should return  status order reserved.

With the order payments done, its time to handle the shipping


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.microservice-stack.com/introduction/demo-project/order-payment-reservation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
