COMP 3011 Coursework 2
About this Project
This is a payment provider API for Group 3 (AIRggregator) created by Alex Cheong (sc20a2c) The service is hosted on pythonanywhere.com, and can be accessed from this URL: http://sc20a2c.pythonanywhere.com/
Superuser details
Username: admin Email: admin@gmail.com Password: admin
API Endpoints
The API has 4 endpoints that each represent a specific table in the database. These endpoints are:
- http://sc20a2c.pythonanywhere.com/payment_API/card_provider/
- http://sc20a2c.pythonanywhere.com/payment_API/wallet_provider/
- http://sc20a2c.pythonanywhere.com/payment_API/card_transaction/
- http://sc20a2c.pythonanywhere.com/payment_API/wallet_transaction/
Each is used to manipulate a specific type of resource.
Using the Card Endpoint
This endpoint accepts 4 HTTP methods:
- GET
- POST
- PUT
- DELETE
GET
GET is used to retrieve information about a specific Card resource. It requires these as URL input parameters (not as JSON): { 'id': int }
It will return a JSON body that looks like this: { "id": 16, "card_no": "123456789", "name_on_card": "example name", "cvc": "123", "expiry": "2023-05-10", "card_balance": 199.2 }
An example of a GET request on the Card endpoint can be seen in client.py lines 141 - 147
POST
POST is used to create a new Card resource. It requires a JSON body of this form: post_card = { 'card_no': string, 'name_on_card': string, 'cvc': string, 'expiry': str(DateTime), 'card_balance': float }
Required: card_no, name_on_card, cvc, expiry Optional: card_balance (defaults to 0.0)
It will return a JSON body that looks like this: { "id": 16, "card_no": "123456789", "name_on_card": "example name", "cvc": "123", "expiry": "2023-05-10", "card_balance": 199.2 }
An example of a POST request for a Card can be seen in client.py lines 126 - 132
PUT
PUT is used to update an existing Card resource. Keep in mind that if the Card is already being used for transactions, PUT will not allow changes to the card_no! It requires a JSON body of this form: { 'id': int, 'card_no': string, 'name_on_card': string, 'cvc': string, 'expiry': str(DateTime), 'card_balance': float }
Required: id Optional: Everything else! If not provided, no changes to that field will be done in the database
An example of PUT for Card in client.py is lines 183 - 190
DELETE
DELETE is used to remove a Card AND it's transactions from the database. Take note that the database will not reset back to id 1, and will continue to increment even if wiped. It requires a JSON body like so: { 'id': int }
Required: id
It will return an HttpResponse like this: "Card id 16 with Card no. 123456789 and associated transactions deleted!"
An example of DELETE can be seen in client.py lines 195 - 198
Using the Card Transaction Endpoint
This endpoint accepts 2 HTTP methods:
- GET
- POST
GET
GET is used to retrieve a specific Card Transaction. It requires these as URL parameters (not JSON): { 'id': int }
It will return a JSON body like this: { "id": int, "card_no": string, "amount": float, "datetime": str(DateTime), "merchant": string }
An example of a GET request on the Card Transaction can be seen in client.py lines 165 - 169
POST
POST is used to create a new Card Transaction. It requires a JSON body like this: { "card_no": string, "amount": float, "merchant": string }
Required: All of them! It will return a JSON body like this: { "id": int, "card_no": string, "amount": float, "datetime": str(DateTime), "merchant": string }
An example of a POST request on the Card Transaction can be seen in client.py lines 152 - 159
Using the Wallet Endpoint
This endpoint accepts 4 HTTP methods:
- GET
- POST
- PUT
- DELETE
GET
GET is used to retrieve information about a specific Wallet resource. It requires these as URL input parameters (not as JSON): { 'id': int }
It will return a JSON body that looks like this: { "id": 11, "email": "example@gmail.com", "password": "example password", "account_balance": 199.2 }
An example of a GET request on the Wallet endpoint can be seen in client.py lines 221 - 225
POST
POST is used to create a new Wallet resource. It requires a JSON body of this form: post_wallet = { "email": string, "password": string, "account_balance": float }
Required: email and password Optional: account_balance (defaults to 0)
It will return a JSON body that looks like this: { "id": 11, "email": "example@gmail.com", "password": "example password", "account_balance": 199.2 }
An example of a POST request for a Wallet can be seen in client.py lines 207 - 214
PUT
PUT is used to update an existing Wallet resource. Keep in mind that if the Wallet is already being used for transactions, PUT will not allow changes to the email! It requires a JSON body of this form: { 'id': int, "email": string, "password": string, "account_balance": float }
Required: id Optional: Everything else! If not provided, no changes to that field will be done in the database
It will return a JSON body like this: { "id": 11, "email": "example@gmail.com", "passsword": "new password", "account_balance": 8989.2 }
An example of PUT for Wallet in client.py is lines 262 - 269
DELETE
DELETE is used to remove a Wallet AND it's transactions from the database. Take note that the database will not reset back to id 1, and will continue to increment even if wiped. It requires a JSON body like so: { 'id': int }
Required: id
It will return an HttpResponse like this: "Wallet id 11 with email example@gmail.com and associated transactions deleted!"
An example of DELETE can be seen in client.py lines 273 - 277
Using the Wallet Transaction Endpoint
This endpoint accepts 2 HTTP methods:
- GET
- POST
GET
GET is used to retrieve a specific Wallet Transaction. It requires these as URL parameters (not JSON): { 'id': int }
It will return a JSON body like this: { "id": 4, "email": "example@gmail.com", "amount": -20.0, "datetime": "2023-05-10 15:55:25.954753+00:00", "merchant": "example wallet merchant" }
An example of a GET request on the Wallet Transaction can be seen in client.py lines 244 - 248
POST
POST is used to create a new Wallet Transaction. It requires a JSON body like this: { 'email': string, 'amount': float, 'datetime': str(DateTime), 'merchant': string }
Required: All of them! It will return a JSON body like this: { "id": int, 'email': string, 'amount': float, 'datetime': str(DateTime), 'merchant': string }
An example of a POST request on the Card Transaction can be seen in client.py lines 231 - 238