The Flexigift service allows users to pay for their Amazon purchases with third-party gift cards. This tutorial will teach you how to add a new gift card to Flexigift and fetch your new card’s details.
Allow 30 minutes to complete this lesson.
Note: This tutorial assumes that the Flexigift service is running at http://localhost:3000. Remember to point to your own host when you adapt the code samples to your own environment.
The following procedures will teach you how to Create a new gift card and to Fetch your new card’s details. When you’ve completed the procedures you will have a new gift card ready to spend.
You create new cards in the system with the POST method of the Create a Gift Card API.
Submit a Create a Gift Card request with the following details:
card_id
: Unique identifier provided by the issuer of the card.user_id
: The user associated with the payment card.issuer
: The merchant that issued the payment card.balance
: How much money is left on the card.expiry_date
: Date the gift card expires.Example request:
curl -POST -H "Content-type: application/json" -d ' {
"card_id": "hanes-gc-003",
"user_id": "user001",
"issuer": "Hanes",
"balance": 200,
"expiry_date": "2026-12-31"
}' 'http://localhost:3000/gift_cards'
The service responds with the gift card details that you submitted plus a unique ID that the system generates automatically.
Example response:
{
"card_id": "hanes-gc-003",
"user_id": "user001",
"issuer": "Hanes",
"balance": 200,
"expiry_date": "2026-12-31",
"id": 6
}
Verify that the response data matches the card details that you submitted.
If the data matches, congratulations! Your new gift card is in the system and ready to be spent.
Note the unique id
; you will need to know it if you want to fetch your card’s details later.
You can fetch your gift card’s details any time with the GET method of the Gift Card Resource and the
instance’s unique id
.
Example Get a Gift Card request:
curl "http://localhost:3000/gift_cards/6"
Response:
{
"card_id": "hanes-gc-003",
"user_id": "user001",
"issuer": "Hanes",
"balance": 200,
"expiry_date": "2026-12-31",
"id": 6
}
Now that you have a gift card in the system, link it to a user as described in the Add a User tutorial.