Progetto finanziato con fondi POR FESR 2014/2020 - ASSE PRIORITARIO I
“RICERCA SCIENTIFICA, SVILUPPO TECNOLOGICO E INNOVAZIONE”.
R.2.6 - ALLEGATO RELAZIONE TECNICO SCIENTIFICA FINALE
Un documento che descrive le API per accedere al marketplace
Progetto cluster SardCoin - Resp. Scient.: Prof. Michele Marchesi
In questo documento sono descritte le API REST utilizzate dagli attori del sistema per interagire con il motore del progetto cluster top-down “ SardCoin: tecnologie blockchain a supporto del turismo in Sardegna”, finanziato da Sardegna Ricerche con fondi POR-FESR Sardegna 2014-2020 e soggetto attuatore Università degli Studi di Cagliari, responsabile scientifico Prof.
Michele Marchesi.
1. Chiamate di gestione degli utenti della piattaforma
Di seguito verranno descritte le chiamate riservate alla gestione degli utenti nella piattaforma.
Creazione utente
● Indirizzo: /users/create
● Tipo: POST
● Body:
○ Username: nome utente
○ Email: email dell’utente
○ Azienda: nome dell’azienda dell’utente
○ Partita iva: partita iva del cliente
○ Nome: nome dell’utente
○ Cognome: cognome dell’utente
○ Data di nascita: data di nascita dell’utente
○ Luogo di nascita: luogo di nascita dell’utente
○ Codice avviamento postale: CAP dell’utente
○ Email Paypal: email Paypal dell’utente per le transazioni di denaro
○ Password: password dell’user per accedere alla piattaforma
● Risposte:
○ 400 (BAD REQUEST):
{
created: false.
error: 'Username or email already exists' }
○ 200 ok {
first_name: “Alessio”, Last_name: “Delrio”
}
Ottieni utente dal Token di accesso utente
● Indirizzo: /users/getFromToken
● Tipo: GET
● Header: Authorization: Bearer token
● Risposte:
○ 200 OK {
"id":2,
"username":"admin",
"email":"email@email.com",
"company_name":"company_name", "vat_number":"100",
"first_name":"Alessio", "last_name":"Delrio", "birth_place":"Gesturi", "birth_date":"2000-01-01",
"fiscal_code":"psveindoven79c4412dsfdf", "address":"address",
"province":"CA", "city":"city", "zip":"09100",
"password":"$2a$10$uVPr7u7bhuiWLWg8pbUx6.rLbPz6wTMjlC1au3V.6P2bedu Rrr3ma",
"user_type":"0",
"checksum":"0",
"email_paypal":"email_paypal@libero.it"
}
○ 401 Unauthorized Unauthorized
Ottieni l’ utente dal suo id
● Indirizzo: /users/getProducerFromId/:producer_id
● Tipo: GET
● Header: Authorization: Bearer token
● Paramentri: id dell’ utente
● Risposte:
○ 200 OK {
"id":2,
"username":"admin",
"email":"email@email.com",
"company_name":"company_name", "vat_number":"100",
"first_name":"Alessio", "last_name":"Delrio", "birth_place":"Gesturi", "birth_date":"2000-01-01",
"fiscal_code":"psveindoven79c4412dsfdf", "address":"address",
"province":"CA", "city":"city", "zip":"09100",
"password":"$2a$10$uVPr7u7bhuiWLWg8pbUx6.rLbPz6wTMjlC1au3V.6P2bedu Rrr3ma",
"user_type":"0", "checksum":"0",
"email_paypal":"email_paypal@libero.it"
}
○ 401 Unauthorized Unauthorized
○ 200 OK
{
"error":"No user found with the given id and the given coupon","producer_id":"100"
}
Modifica dati utente
● Indirizzo: /users/editUser
● Tipo: PUT
● Header: Authorization: Bearer token
● Parametri:
○ Username: nome utente
○ Email: email dell’utente
○ Azienda: nome dell’azienda dell’utente
○ Partita iva: partita iva del cliente
○ Nome: nome dell’utente
○ Cognome: cognome dell’utente
○ Data di nascita: data di nascita dell’utente
○ Luogo di nascita: luogo di nascita dell’utente
○ Codice avviamento postale: CAP dell’utente
○ Email Paypal: email Paypal dell’utente per le transazioni di denaro
○ Password: password dell’user per accedere alla piattaforma
● Risposte:
○ 200 OK {
updated: true, user_id: 12 }
○ 401 Unauthorized Unauthorized
Elimina utente
● Indirizzo: /users/deleteUser
● Tipo: DELETE
● Header: Authorization: Bearer token
● Parametri:
○ Username: nome utente
● Risposte:
○ 200 OK {
deleted: false, username: “lele”
“Message”: “User don’t exist!”
}
○ 500 Internal Server Error {
"deleted": false,
"error": "Cannot delete the user"
}
○ 200 OK {
deleted: true, username: “lele”
}
○ 401 Unauthorized Unauthorized {
"error": "You are not authorized to view this content"
}
Login utente
● Indirizzo: /login
● Tipo: POST
● Header: Authorization: Bearer token
● Parametri:
○ Username: nome utente
○ Password: password dell’user per accedere alla piattaforma
● Risposte:
○ 200 OK {
"user": { "id": 3,
"username": "consumer", "email": "serusi@gmail.com", "first_name": "Sergio",
"last_name": "Serusi", "user_type": "1"
},
"token": "vSE1L8ng-dVJaDlmnmi2JlbMvudkaIeDqvJ-zBjk0Uk"
}
○ 401 Unauthorized {
"logged": false,
"error": "unauthorized"
}
Ottieni utenti di tipo broker
● Indirizzo: /users/getBroker
● Tipo: GET
● Header: Authorization: Bearer token
● Risposte:
○ 200 OK [
{
"id":2,
"username":"admin",
"email":"email@email.com",
"company_name":"company_name", "vat_number":"100",
"first_name":"Alessio", "last_name":"Delrio", "birth_place":"Gesturi", "birth_date":"2000-01-01",
"fiscal_code":"psveindoven79c4412dsfdf", "address":"address",
"province":"CA", "city":"city", "zip":"09100", },
{
"id":5,
"username":"Broker",
"email":"emailBroker@email.com", "company_name":"company_name", "vat_number":"102",
"first_name":"Alessandro", "last_name":"Delrionale", "birth_place":”Villanovatulo", "birth_date":"2000-01-02",
"fiscal_code":"psveindoven78c4412dsfdf", "address":"address",
"province":"CA", "city":"city", "zip":"09100", },
]
○ 401 Unauthorized Unauthorized
2. Chiamate di gestione dei coupon della piattaforma
Di seguito verranno descritte le chiamate riservate alla gestione dei coupon
Ottieni coupon dato il suo id
● Indirizzo: /coupons/getById
● Tipo: GET
● Header: Authorization: Bearer token
● Parametro: id: id del coupon
● Risposte:
○ 200 OK
{
"id": 914,
"title": "Restaurant Schick",
"description": "Pizza for everyone", "image": "pizzeria-maccheroni.jpg",
"timestamp": "2018-08-04T07:04:27.000Z",
"price": 19.95,
"valid_from": "2018-09-04T10:22:00.000Z", "valid_until": null,
"state": 0,
"constraints": "Ocala, CA, USA", "owner": 150,
"consumer": null, "token": "sdaklfjòslfjd", “type”: 0 ,
“ }
○ 401 Unauthorized Unauthorized
○ 400 Bad request {
"error": "No coupon found with the given id and the given user.", "coupon_id": 1,
"user_id": 1 }
Ottieni tutti i coupons relativi ad un producer
● Indirizzo: /coupons/getProducerCoupons
● Tipo: GET
● Header: Authorization: Bearer token
● Risposte:
○ 200 OK
[ {
"id": 914,
"title": "Restaurant Schick",
"description": "Pizza for everyone", "image": "pizzeria-maccheroni.jpg",
"timestamp": "2018-08-04T07:04:27.000Z", "price": 19.95,
"valid_from": "2018-09-04T10:22:00.000Z", "valid_until": null,
"state": 0,
"constraints": "Ocala, CA, USA", "owner": 150,
"consumer": null, "token": "sdaklfjòslfjd", “type”: 0
}, {
"id": 915,
"title": "Restaurant",
"description": "Pizza pazza", "image": "pizzeria.jpg",
"timestamp": "2018-08-04T07:04:27.000Z", "price": 22.30,
"valid_from": "2018-09-04T10:22:00.000Z", "valid_until": null,
"state": 0,
"constraints": "Ocala, CA, USA", "owner": 150,
"consumer": null, "token": "sdaklefwgeg", “type”: 0
} ]
○ 401 Unauthorized Unauthorized
○ 401 Unauthorized {
"error": "You are not authorized to view this content"
}
Ottieni i coupons venduti relativi ad un producer
● Indirizzo: /coupons/getPurchasedCoupons
● Tipo: GET
● Header: Authorization: Bearer token
● Risposte:
○ 200 OK [
{
"id": 914,
"title": "Restaurant Schick",
"description": "Pizza for everyone", "image": "pizzeria-maccheroni.jpg",
"timestamp": "2018-08-04T07:04:27.000Z", "price": 19.95,
"valid_from": "2018-09-04T10:22:00.000Z", "valid_until": null,
"state": 0,
"constraints": "Ocala, CA, USA", "owner": 150,
"consumer": 21, "token": "sdaklfjòslfjd", “type”: 0 ,
“quantity”: 2 }, {
"id": 915,
"title": "Restaurant",
"description": "Pizza pazza", "image": "pizzeria.jpg",
"timestamp": "2018-08-04T07:04:27.000Z", "price": 22.30,
"valid_from": "2018-09-04T10:22:00.000Z", "valid_until": null,
"state": 0,
"constraints": "Ocala, CA, USA", "owner": 150,
"consumer": 23,
"token": "sdaklefwgeg", “type”: 0,
“quantity”: 2 }
]
○ 401 Unauthorized Unauthorized
○ 401 Unauthorized {
"error": "You are not authorized to view this content"
}
Ottieni i coupons non venduti e non privati
● Indirizzo: /coupons/getAvailableCoupons
● Tipo: GET
● Risposte:
○ 200 OK
[ {
"id": 914,
"title": "Restaurant Schick",
"description": "Pizza for everyone", "image": "pizzeria-maccheroni.jpg",
"timestamp": "2018-08-04T07:04:27.000Z", "price": 19.95,
"valid_from": "2018-09-04T10:22:00.000Z", "valid_until": null,
"state": 0,
"constraints": "Ocala, CA, USA", "owner": 150,
"consumer": null, "token": "sdaklfjòslfjd", “type”: 0 ,
“quantity”: 2 }, {
"id": 915,
"title": "Restaurant",
"description": "Pizza pazza", "image": "pizzeria.jpg",
"timestamp": "2018-08-04T07:04:27.000Z", "price": 22.30,
"valid_from": "2018-09-04T10:22:00.000Z", "valid_until": null,
"state": 0,
"constraints": "Ocala, CA, USA", "owner": 150,
"consumer": null, "token": "sdaklefwgeg", “type”: 0,
“quantity”: 2 }
]
○ 400 Bad request {
"error": "No coupon found ", }
Acquista un coupon
● Indirizzo: /coupons/buyCoupon
● Tipo: GET
● Header: Authorization: Bearer token
● Parametro: id: id del coupon
● Risposte:
○ 200 OK
{
updated: true, coupon_id: 12
message: "Coupon bought!!!"
}
○ 200 OK
{
updated: false, coupon_id: 12
message: "Coupon don’t exist!!!"
}
○ 401 Unauthorized Unauthorized
○ 401 Unauthorized {
"error": "You are not authorized to view this content"
}
Crea un coupon
● Indirizzo: /coupons/create
● Tipo: POST
● Header: Authorization: Bearer token
● Parametri:
○ title: titolo del coupon
○ description: descrizione del coupon
○ image: nome dell’immagine con estensione
○ price: prezzo del coupon
○ visible_from: data di inizio visibilità del coupon (se null il coupon è privato)
○ valid_from: data di inizio validità del coupon
○ valid_until: data scadenza del coupon
○ constrains: limitazioni del coupon
○ owner: id del proprietario del coupon
○ consumer: eventuale id del cliente che ha acquistato il coupon
○ Password: password dell’user per accedere alla piattaforma
○ Category: lista delle categorie relative al coupon
○ Brokers: lista dei brokers abilitati all’utilizzo del coupon
○ Quantity: quantità del coupon
● Risposte:
○ 200 OK
{
"created": true, "coupon_id": 12, }
○ 401 Unauthorized Unauthorized
○ 400 Bad request {
"Status code": 400,
"Type error": “Bad Request”,
"message": “the title must be between 5 and 40 characters long, is required”
}
Modifica un coupon
● Indirizzo: /coupons/editCoupon
● Tipo: PUT
● Header: Authorization: Bearer token
● Parametri:
○ id: id del coupon
○ title: titolo del coupon
○ description: descrizione del coupon
○ image: nome dell’immagine con estensione
○ price: prezzo del coupon
○ visible_from: data di inizio visibilità del coupon (se null il coupon è privato)
○ valid_from: data di inizio validità del coupon
○ valid_until: data scadenza del coupon
○ constrains: limitazioni del coupon
○ owner: id del proprietario del coupon
○ consumer: eventuale id del cliente che ha acquistato il coupon
○ Password: password dell’user per accedere alla piattaforma
○ Category: lista delle categorie relative al coupon
○ Brokers: lista dei brokers abilitati all’utilizzo del coupon
● Risposte:
○ 200 OK
{
"updated": true, "coupon_id": 12, }
○ 200 OK
{
updated: false, coupon_id: 12
message: "Coupon don’t exist!!!"
}
○ 401 Unauthorized Unauthorized
○ 400 Bad request {
"Status code": 400,
"Type error": “Bad Request”,
"message": “the title must be between 5 and 40 characters long, is required”
}
Elimina un coupon
● Indirizzo: /coupons/deleteCoupon
● Tipo: DELETE
● Header: Authorization: Bearer token
● Parametri:
○ id: id del coupon
● Risposte:
○ 200 OK
{
"deleted": true, "coupon_id": 12,
“Message” : "Coupon deleted!!!"
}
○ 200 OK
{
updated: false, coupon_id: 12
message: "Coupon don’t exist!!!"
}
○ 401 Unauthorized Unauthorized
Importa un coupon
● Indirizzo: /coupons/importOfflineCoupon
● Tipo: PUT
● Header: Authorization: Bearer token
● Parametri:
○ token: token del coupon
● Risposte:
○ 200 OK
{
"validate": true, "token": grthhrhth, }
○ 200 OK
{
validate: false, "token": grthhrhth,
error: "Cannot import the coupon"
}
○ 401 Unauthorized Unauthorized
Riscatta un coupon
● Indirizzo: /coupons/redeemCoupon
● Tipo: PUT
● Header: Authorization: Bearer token
● Parametri:
○ token: token del coupon
● Risposte:
○ 200 OK
{
"validate": true, "token": grthhrhth, }
○ 200 OK
{
validate: false, "token": grthhrhth,
error: "Cannot verifier the coupon"
}
○ 401 Unauthorized Unauthorized
Ottieni coupon dato il suo token e il suo tipo
● Indirizzo: /coupons/getByToken
● Tipo: GET
● Header: Authorization: Bearer token
● Parametri:
○ token: token del coupon
○ type: tipo (0 se semplice coupon, 1 se è un pacchetto)
● Risposte:
○ 200 OK
{
"id": 914,
"title": "Restaurant Schick",
"description": "Pizza for everyone", "image": "pizzeria-maccheroni.jpg",
"timestamp": "2018-08-04T07:04:27.000Z", "price": 19.95,
"valid_from": "2018-09-04T10:22:00.000Z", "valid_until": null,
"state": 0,
"constraints": "Ocala, CA, USA", "owner": 150,
"consumer": null, "token": "sdaklfjòslfjd", “type”: 0 ,
“
}
○ 401 Unauthorized Unauthorized
○ 400 Bad request {
"error": true,
message: 'Cannot retrieve the coupon: either the token or the type are not correct.'
}
○ 500 Internal Server Error {
"error": true,
message: 'An error occurred while retrieving the coupon.' }
Ottieni i coupons non venduti, non privati e di una determinata categoria
● Indirizzo: /coupons/getAvailableByCatId
● Tipo: GET
● Header: Authorization: Bearer token
● Parametri:
○ category: categoria in esame
● Risposte:
○ 200 OK
[ {
"id": 914,
"title": "Restaurant Schick",
"description": "Pizza for everyone", "image": "pizzeria-maccheroni.jpg",
"timestamp": "2018-08-04T07:04:27.000Z", "price": 19.95,
"valid_from": "2018-09-04T10:22:00.000Z", "valid_until": null,
"state": 0,
"constraints": "Ocala, CA, USA", "owner": 150,
"consumer": null, "token": "sdaklfjòslfjd", “type”: 0 ,
“quantity”: 2 }, {
"id": 915,
"title": "Restaurant",
"description": "Pizza pazza", "image": "pizzeria.jpg",
"timestamp": "2018-08-04T07:04:27.000Z", "price": 22.30,
"valid_from": "2018-09-04T10:22:00.000Z", "valid_until": null,
"state": 0,
"constraints": "Ocala, CA, USA", "owner": 150,
"consumer": null, "token": "sdaklefwgeg", “type”: 0,
“quantity”: 2 }
]
○ 204 No content { }
○ 500 Internal server error {
"error": "Cannot GET available coupons by category ID", }
Ottieni i coupons non venduti, non privati e di una determinata categoria con filtro su un determinato testo
● Indirizzo: /coupons/getAvailableByTextAndCatId
● Tipo: GET
● Header: Authorization: Bearer token
● Parametri:
○ category: categoria in esame
○ text: testo in esame
● Risposte:
○ 200 OK
[ {
"id": 914,
"title": "Restaurant Schick",
"description": "Pizza for everyone", "image": "pizzeria-maccheroni.jpg",
"timestamp": "2018-08-04T07:04:27.000Z", "price": 19.95,
"valid_from": "2018-09-04T10:22:00.000Z", "valid_until": null,
"state": 0,
"constraints": "Ocala, CA, USA", "owner": 150,
"consumer": null, "token": "sdaklfjòslfjd", “type”: 0 ,
“quantity”: 2 }, {
"id": 915,
"title": "Restaurant",
"description": "Pizza pazza", "image": "pizzeria.jpg",
"timestamp": "2018-08-04T07:04:27.000Z", "price": 22.30,
"valid_from": "2018-09-04T10:22:00.000Z", "valid_until": null,
"state": 0,
"constraints": "Ocala, CA, USA", "owner": 150,
"consumer": null, "token": "sdaklefwgeg", “type”: 0,
“quantity”: 2 }
]
○ 204 No content { }
○ 500 Internal server error {
"error": "Cannot GET available coupons by category ID and text inserted", }
Ottieni la quantità venduta di un determinato coupon
● Indirizzo: /coupons/getPurchasedCouponsById
● Tipo: GET
● Header: Authorization: Bearer token
● Parametri:
○ coupon_id: id del coupon in esame
● Risposte:
○ 200 OK {
coupon_id: 12, bought: 10 }
○ 204 No content { }
○ 500 Internal server error {
"error: true,
message: 'Error retrieving purchased coupons'
}
Ottieni i coupons disponibili per un determinato broker
● Indirizzo: /coupons/getBrokerCoupons
● Tipo: GET
● Header: Authorization: Bearer token
● Risposte:
○ 200 OK
[ {
"id": 914,
"title": "Restaurant Schick",
"description": "Pizza for everyone", "image": "pizzeria-maccheroni.jpg",
"timestamp": "2018-08-04T07:04:27.000Z", "price": 19.95,
"valid_from": "2018-09-04T10:22:00.000Z", "valid_until": null,
"state": 0,
"constraints": "Ocala, CA, USA", "owner": 150,
"consumer": null, "token": "sdaklfjòslfjd", “type”: 0 ,
“quantity”: 2 }, {
"id": 915,
"title": "Restaurant",
"description": "Pizza pazza", "image": "pizzeria.jpg",
"timestamp": "2018-08-04T07:04:27.000Z", "price": 22.30,
"valid_from": "2018-09-04T10:22:00.000Z", "valid_until": null,
"state": 0,
"constraints": "Ocala, CA, USA", "owner": 150,
"consumer": null, "token": "sdaklefwgeg", “type”: 0,
“quantity”: 2 }
]
○ 204 No content { }
○ 500 Internal server error {
"error": "Cannot get the broker coupons”, }
Upload di un’immagine
● Indirizzo: /coupons/addImage
● Tipo: POST
● Header: Authorization: Bearer token
● Body:
○ file: path del file
● Risposte:
○ 200 OK
{
inserted: true, image: pizzeria.jpg,
path: c://image/pizzeria.jpg }
○ 500 Internal server error {
"name: ‘Upload image error’,
message: 'A problem occurred during upload of the image’
}
Estrapola i broker associati a un coupon fornendo l’id del coupon
● Indirizzo: /coupons/getBrokerFromCouponId
● Tipo: GET
● Header: Authorization: Bearer token
● Parametri:
○ id: id del coupon
● Risposte:
○ 200 OK
[
● {
"id":12,
"username":"broker",
"email":"broker@email.com",
"company_name":"broker_company", "vat_number":"100",
"first_name":"Alessio", "last_name":"Delrione", "birth_place":"Gesturi", "birth_date":"2000-01-01",
"fiscal_code":"psveindoven79c4412dsfdf", "address":"address",
"province":"CA", "city":"city", "zip":"09100",
"password":"$2a$10$uVPr7u7bhuiWLWg8pbUx6.rLbPz6wTMjlC1au3V.6P2bedu Rrr3ma",
"user_type":"4", "checksum":"0",
"email_paypal":"email_paypal_broker@libero.it"
},
○ {
"id":13,
"username":"broker2",
"email":"broker2@email.com",
"company_name":"broker2company", "vat_number":"100",
"first_name":"Alessandro", "last_name":"Delrio", "birth_place":"Gesturi", "birth_date":"2000-01-01",
"fiscal_code":"psveindoven79c4412dsfdf", "address":"address",
"province":"CA", "city":"city", "zip":"09100",
"password":"$2a$10$uVPr7u7bhuiWLWg8pbUx6.rLbPz6wTMjlC1au3V.6P2bedu Rrr3ma",
"user_type":"4", "checksum":"0",
"email_paypal":"email_paypal_broker@libero.it"
}
]
○ 500 Internal server error {
error: true,
message: 'Cannot GET the brokers authorized to the given coupon.'
}
○ 204 No Content {
error: true,
message: `Cannot retrieve a broker with id 12`
}
3. Chiamate di gestione dei pacchetti della piattaforma
Qui di seguito verranno descritte le chiamate per poter gestire i pacchetti della piattaforma
Ottieni i pacchetti di un determinato broker
● Indirizzo: /packages/getBrokerPackages
● Tipo: GET
● Header: Authorization: Bearer token
● Risposte:
○ 200 OK
[ {
"id": 914,
"title": "Restaurant Schick",
"description": "Pizza for everyone", "image": "pizzeria-maccheroni.jpg",
"timestamp": "2018-08-04T07:04:27.000Z", "price": 19.95,
"valid_from": "2018-09-04T10:22:00.000Z", "valid_until": null,
"state": 0,
"constraints": "Ocala, CA, USA", "owner": 150,
"consumer": null, "token": "sdaklfjòslfjd", “type”: 1 ,
“quantity”: 2, “bought”: 0 }, {
"id": 915,
"title": "Restaurant",
"description": "Pizza pazza", "image": "pizzeria.jpg",
"timestamp": "2018-08-04T07:04:27.000Z", "price": 22.30,
"valid_from": "2018-09-04T10:22:00.000Z", "valid_until": null,
"state": 0,
"constraints": "Ocala, CA, USA", "owner": 150,
"consumer": null, "token": "sdaklefwgeg", “type”: 1,
“quantity”: 2, “bought”: 1 } ]
○ 204 No content { }
○ 500 Internal server error {
"error": "Cannot get the distinct packages created”, }
Ottieni i coupons di un determinato pacchetto
● Indirizzo: /packages/getCouponsPackage
● Tipo: GET
● Parametri: id: id del pacchetto
● Header: Authorization: Bearer token
● Risposte:
○ 200 OK {
Coupons_count: 2, coupons_array:
[ {
"id": 914,
"title": "Restaurant Schick",
"description": "Pizza for everyone", "image": "pizzeria-maccheroni.jpg",
"timestamp": "2018-08-04T07:04:27.000Z", "price": 19.95,
"valid_from": "2018-09-04T10:22:00.000Z", "valid_until": null,
"state": 0,
"constraints": "Ocala, CA, USA", "owner": 150,
"consumer": null, "token": "sdaklfjòslfjd", “type”: 0 ,
“quantity”: 2, “bought”: 0 }, {
"id": 915,
"title": "Restaurant",
"description": "Pizza pazza", "image": "pizzeria.jpg",
"timestamp": "2018-08-04T07:04:27.000Z", "price": 22.30,
"valid_from": "2018-09-04T10:22:00.000Z", "valid_until": null,
"state": 0,
"constraints": "Ocala, CA, USA", "owner": 150,
"consumer": null, "token": "sdaklefwgeg", “type”: 1,
“quantity”: 2,
“bought”: 1 } ]
○ 204 No content { }
4. Chiamate di gestione degli ordini della piattaforma
Qui di seguito verranno descritte le chiamate per poter gestire gli ordini della piattaforma
Ottieni ordine dato l’id
● Indirizzo: /orders/getOrderById
● Tipo: GET
● Parametri: id: id dell’ordine
● Header: Authorization: Bearer token
● Risposte:
○ 200 OK
{
id: 14,
coupon_token: afdsfsdfsfg, package_token: null, price: 12.99,
verifier: 2, coupon_id: 123 }
○ 204 No content { }
○ 500 Internal Server Error {
message: 'Error on querying the orders made by the user.' }
Ottieni ordini
● Indirizzo: /orders/getOrdersByConsumer
● Tipo: GET
● Header: Authorization: Bearer token
● Risposte:
○ 200 OK [
{
"id": 14, "consumer": 3,
"purchase_time": "2018-08-04T07:04:27.000Z", },
{
"id": 15, "consumer": 3,
"purchase_time": "2018-09-04T07:04:27.000Z", },
]
○ 204 No content { }
○ 500 Internal Server Error {
message: 'Error on querying the orders made by the user.' }
Ottieni l’id dell’ultimo ordine
● Indirizzo: /orders/getOrdersByConsumer
● Tipo: GET
● Header: Authorization: Bearer token
● Risposte:
○ 200 OK
{
"id": 14, },
○ 204 No content { }
○ 500 Internal Server Error {
message: 'Cannot get the last order.'
}
5. Chiamate di gestione dei pagamenti sulla piattaforma
Qui di seguito verranno descritte le chiamate per poter gestire i pagamenti sulla piattaforma
Configurazione checkout Paypal
● Indirizzo: /paypal/setCheckout
● Tipo: POST
● Parametri:
○ config: configurazione di Paypal
●
● Header: Authorization: Bearer token
● Risposte:
○ 200 OK
{
"link":
‘https://www.sandbox.paypal.com/checkoutnow?token=EC-8GP96771H6819743 R’,
},
○ 400 Bad request {
status: 401,
Message: ‘You can’t buy more than 10 products ad time’
}
○ 500 Internal Server Error {
message: 'Error doing something' }
Ottieni conferma Paypal
● Indirizzo: /paypal/confirm
● Tipo: GET
● Parametri:
○ config: configurazione di Paypal
Pagamento Paypal
● Indirizzo: /paypal/pay
● Tipo: POST
● Parametri:
○ config: configurazione di Paypal
● Risposte:
○ 200 OK {
paid: true, result:
{
TOKEN: 'EC-8GP96771H6819743R',
SUCCESSPAGEREDIRECTREQUESTED: 'false', TIMESTAMP: '2019-09-02T14:09:43Z',
CORRELATIONID: 'a74dff4eef034', ACK: 'Success',
VERSION: '204', BUILD: '53481737',
INSURANCEOPTIONSELECTED: 'false', SHIPPINGOPTIONISDEFAULT: 'false',
PAYMENTINFO_0_TRANSACTIONID: '6J471604GS160651A', PAYMENTINFO_0_TRANSACTIONTYPE: 'expresscheckout', PAYMENTINFO_0_PAYMENTTYPE: 'instant',
PAYMENTINFO_0_ORDERTIME: '2019-09-02T14:09:39Z', PAYMENTINFO_0_AMT: '100.00',
PAYMENTINFO_0_FEEAMT: '3.75', PAYMENTINFO_0_TAXAMT: '0.00',
PAYMENTINFO_0_CURRENCYCODE: 'EUR', PAYMENTINFO_0_PAYMENTSTATUS: 'Completed', PAYMENTINFO_0_PENDINGREASON: 'None', PAYMENTINFO_0_REASONCODE: 'None',
PAYMENTINFO_0_PROTECTIONELIGIBILITY: 'Eligible', PAYMENTINFO_0_PROTECTIONELIGIBILITYTYPE:
'ItemNotReceivedEligible,UnauthorizedPaymentEligible',
PAYMENTINFO_0_SELLERPAYPALACCOUNTID:
'sardcoin2018-facilitator@gmail.com',
PAYMENTINFO_0_SECUREMERCHANTACCOUNTID: 'EUB3DZPPCWEJ8', PAYMENTINFO_0_PAYMENTREQUESTID:
'AWzgaTnUc31Hs2n67Q-98rXkdgzCnbePdlaWYXnYSOBw1w7NkAOYaNhZ0qD maX2XiK9jCxuJEn2yEd6e',
PAYMENTINFO_0_ERRORCODE: '0', PAYMENTINFO_0_ACK: 'Success',
PAYMENTINFO_1_TRANSACTIONID: '8YL47108V40569819', PAYMENTINFO_1_TRANSACTIONTYPE: 'expresscheckout', PAYMENTINFO_1_PAYMENTTYPE: 'instant',
PAYMENTINFO_1_ORDERTIME: '2019-09-02T14:09:42Z', PAYMENTINFO_1_AMT: '20.00',
PAYMENTINFO_1_FEEAMT: '1.03', PAYMENTINFO_1_TAXAMT: '0.00',
PAYMENTINFO_1_CURRENCYCODE: 'EUR', PAYMENTINFO_1_PAYMENTSTATUS: 'Completed', PAYMENTINFO_1_PENDINGREASON: 'None', PAYMENTINFO_1_REASONCODE: 'None',
PAYMENTINFO_1_PROTECTIONELIGIBILITY: 'Eligible', PAYMENTINFO_1_PROTECTIONELIGIBILITYTYPE:
'ItemNotReceivedEligible,UnauthorizedPaymentEligible', PAYMENTINFO_1_SELLERPAYPALACCOUNTID:
'sardcoin2018-facilitator-2@gmail.com',
PAYMENTINFO_1_SECUREMERCHANTACCOUNTID: 'VXAFNDNJ6UV8L', PAYMENTINFO_1_PAYMENTREQUESTID:
'AaaBa9u6r4HziBzFyMwzvogOqRCGMaEsnNGbVgbbHBnRk41DnBQtBQD8PJL OAkpFZBZfojQeoxy0hZIr',
PAYMENTINFO_1_ERRORCODE: '0', PAYMENTINFO_1_ACK: 'Success'
} }
○ 500 Internal server error {
call: ‘pay’,
Message: ‘Error doing the payment’
}
6. Chiamate di gestione delle categorie della piattaforma
Qui di seguito verranno descritte le chiamate per poter gestire le categorie dei pacchetti/coupons della piattaforma
Ottieni tutte le categorie
● Indirizzo: /categories/getAll
● Tipo: GET
● Risposte:
○ 200 OK
[ {
"id": 1,
“name”: “Ristorazione”, },
{
"id": 2,
“name”: “Albergazione”, },
{
"id": 3,
“name”: “Servizio turistico”, },
{
"id": 4,
“name”: “Visite e musei”, },
]
○ 204 No content { }
○ 500 Internal Server Error {
Error: true,
message: 'An error occured while retrieving the categories.' }
Ottieni tutte le categorie di un relativo coupon
● Indirizzo: /categories/getCategoryCoupon
● Tipo: GET
● Parametri:
○ id: id del coupon
● Risposte:
○ 200 OK
[ {
"coupon_id": 1, “category_id”: 1, },
{
"coupon_id": 1, “category_id”: 2, }
]
○ 500 Internal Server Error {
error: true,
message: 'An error occured while finding the category associated to the coupon.'
}
Aggiorna la categoria
● Indirizzo: /categories/update
● Tipo: PUT
● Header: Authorization: Bearer token
● Parametri:
○ id: id della categoria
● Risposte:
○ 200 OK
{
"updated": true,
“name”: “Alpinismo estremo”, }
○ 400 Bad request {
error: true,
message: 'The requested category to updated does not exist' }
○ 500 Internal server error {
error: true,
message: 'An error occured while finding updating the category' }
Aggiungi una categoria
● Indirizzo: /categories/insert
● Tipo: POST
● Header: Authorization: Bearer token
● Body:
○ name: nome della categoria
● Risposte:
○ 201 CREATED
[ {
"created": true,
“name”: “Alpinismo estremo”, }
○ 500 Internal server error {
error: true,
message: 'An error occurred while creating a new category' }
Elimina una categoria
● Indirizzo: /categories/delete
● Tipo: DELETE
● Header: Authorization: Bearer token
● Parametri:
○ id: id della categoria
● Risposte:
○ 200 OK
{
"deleted": true, “id”: 2,
“name”: “Albergazione”, }
○ 500 Internal server error {
error: true,
message: 'An error occurred while deleting the category' }
Assegna una categoria a un coupon
● Indirizzo: /categories/assignCategoryCoupon
● Tipo: POST
● Header: Authorization: Bearer token
● Body:
○ coupon_id: id del coupon
○ category_id: id della categoria
Elimina una categoria a un coupon
● Indirizzo: /categories/removeCouponCategory
● Tipo: DELETE
● Header: Authorization: Bearer token
● Body:
○ coupon_id: id del coupon
○ category_id: id della categoria
● Risposte:
○ 200 OK
{
"deleted": true, “coupon_id”: 2, “category_id”: 2, }
○ 400 Bad request {
error: true,
message: 'The tuple category-coupon to delete does not exist.’
}
○ 500 Internal server error {
error: true,
message: 'An error occurred while deleting the category associated to the coupon'
}
7. Chiamate di gestione dei reports della piattaforma
Qui di seguito verranno descritte le chiamate per poter gestire i reports dei pacchetti/coupons della piattaforma
Ottieni tutti i coupons di un determinato producer suddivisi in generati, attivi, acquistati, verificati.
● Indirizzo: /reports/getReportProducerCoupons
● Tipo: GET
● Header: Authorization: Bearer token
● Risposte:
○ 200 OK
[ {
id: 14,
title: 'Pizzeria Baccu Mandara',
description: 'Pizza all-you-can-eat per 2 persone da Pizzeria ' + 'Baccu Mandara (sconto fino a 70%). Prenota&Vai!',
year: 2018, month: 8, day: 4,
timestamp: 2018-08-04T05:04:27.000Z, bougth: 1,
active: 0, expired: 0, verify: 1, generated: 2 },
{ id: 15,
title: 'Ghetto Quarantasette',
description: 'Menu hamburger con birra artigianale o calice di vino e ' + 'dolce per 2 al Ghetto Quarantasei (sconto fino a 62%).',
year: 2018, month: 9, day: 2,
timestamp: 2018-09-02T08:59:59.000Z, bougth: 1,
active: 0, expired: 0, verify: 0, generated: 1 }
]
○ 500 Internal Server Error {
error: true,
message: 'Cannot get the distinct coupons report’
}
○ 204 No content null
Ottieni tutti i coupons con prezzo di un producer
● Indirizzo: /reports/getReportBoughtProducerCoupons
● Tipo: GET
● Header: Authorization: Bearer token
● Risposte:
○ 200 OK
[ {
bought: 2, coupon_id: 14, package: null,
timestamp: 2018-08-04T05:04:27.000Z, price: 19.95,
year: 2018, month: 8, day: 4 }, {
bought: 1, coupon_id: 15, package: null,
timestamp: 2018-09-02T08:59:59.000Z, price: 21.95,
year: 2018, month: 9, day: 2 }, {
bought: 1, coupon_id: 21,
package: '1111AAAA',
timestamp: 2018-09-04T10:52:23.000Z, price: 369,
year: 2018, month: 9, day: 4 } ]
○ 500 Internal Server Error {
error: true,
message: 'Cannot get the distinct coupons report ’ }
Ottieni il broker relativo al coupon selezionato
● Indirizzo: /reports/getBrokerFromCouponId
● Tipo: GET
● Parametri: id: id del coupon
● Header: Authorization: Bearer token
● Risposte:
○ 200 OK
{
username: 'broker 1producer', coupon_id: 22
}
○ 500 Internal Server Error {
error: true,
message: 'Cannot get the coupon report with broker’
}
○ 204 No content null