Skip to content

Commit

Permalink
aurum app
Browse files Browse the repository at this point in the history
  • Loading branch information
JulioMCruz committed Nov 7, 2024
0 parents commit 33890b6
Show file tree
Hide file tree
Showing 243 changed files with 59,798 additions and 0 deletions.
153 changes: 153 additions & 0 deletions API/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@

<h1 align="center">API Integration</h1>

<h4 align="center">
<a href="https://ethglobal.com/">ETHGlobal</a> | <a href="https://ethglobal.com/">Website</a>
<br><br>
<span style="font-weight: 300; font-style: italic;">Note: Everything in blue is a clickable link.</span>
<br>
<span style="font-weight: 300; font-style: italic;">Please use Node.js's Latest Version</span>
<br><br>
<img src="assets/logo.jpeg" alt="logo">
</h4>

---

## Project Overview

This project demonstrates the integration of the GateFi API to manage customer data, fiat accounts, and deposits using Express.js, Axios, and environment variables for secure API key management.

### Key Features:
- **Create Customer**: Register a new customer with their email and phone number.
- **Create Fiat Account**: Set up a new fiat account tied to a specific customer.
- **Create Deposit**: Execute deposit operations and receive relevant quotes for a transaction.

---

## Environment Configuration (.env)

Make sure to create a `.env` file at the root of your project and define the following variables:

- `SECRET_KEY`: The secret key used to generate signatures for API requests.
- `API_KEY`: The API key used for authenticating with GateFi's external services.

```bash
SECRET_KEY=your_secret_key_here
API_KEY=your_api_key_here
```

DIAGRAM OF APP

<img src="assets/diagram.jpg" alt="logo">

<br>
We use User's Customer Id and POS's Account number to simplify process for merchant, meaning merchant wont have to complete KYC in order to receive funds!
<br><br>


---

## API Endpoints


### 1. Create New Customer
**POST** `/newCustomer`

Creates a new customer in GateFi.

#### Request Body:
```json
{
"email": "[email protected]",
"phoneNumber": "+123456789"
}
```

#### Response:
```json
{
"customerId": "12345",
"createdAt": "2024-10-01T12:00:00Z"
}
```

### 2. Create New Fiat Account
**POST** `/newFiatAccount`

Creates a new fiat account for the specified customer.

#### Request Body:
```json
{
"customerId": "12345",
"accountNumber": "DE1234567890",
"recipientFullAddress": "123 Main St, City, Country",
"recipientAddressCountry": "Germany"
}
```

#### Response:
```json
{
"fiatAccountId": "abc123",
"createdAt": "2024-10-01T12:00:00Z",
"bankName": "Example Bank"
}
```

### 3. Create New Deposit
**POST** `/newDeposit`

Executes a deposit operation for a customer.

#### Request Body:
```json
{
"customerId": "12345",
"chain": "TRX",
"fromAmount": "1000",
"fromCurrency": "USD",
"toCurrency": "EUR",
"fiatAccountId": "abc123",
"amount": "950"
}
```

#### Response:
```json
{
"depositId": "deposit123",
"createdAt": "2024-10-01T12:00:00Z"
}
```

---

## Running the Project

To install the required dependencies and run the server, follow these steps:

### 1. Install Dependencies:
```bash
npm install
```

### 2. Start the Server:
```bash
node app.js
```

The server will be running on `http://localhost:3001`.

---

## Technologies Used

- **Express.js**: Web framework for building the API.
- **Axios**: To handle HTTP requests to the GateFi API.
- **crypto**: For generating secure HMAC signatures.
- **dotenv**: For environment variable management.

---

Built for ETHGlobal 2024 🎉
240 changes: 240 additions & 0 deletions API/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
// import
const express = require('express');
const axios = require('axios');
const dotenv = require('dotenv');
const crypto = require('crypto');

dotenv.config();

const app = express();
const port = 3002;

const baseUrl = 'https://api-sandbox.gatefi.com'

let secretKey = process.env.SECRET_KEY; // secret key, used for generating signature
let apiKey = process.env.API_KEY // api key, used for authentication

app.get('/', (req, res) => {
res.send('Hello, World!');
});

app.use(express.json());

// Method To Generate Signature
function generateSignature(method, path) {
const data = method.toUpperCase() + path;
const hmac = crypto.createHmac('sha256', secretKey);
hmac.update(data);
return hmac.digest('hex');
}


// POST endpoint to create a new customer
// Request body should contain the following parameters:
// - email: The email address of the customer
// - phoneNumber: The phone number of the customer
app.post('/newCustomer', async (req, res) => {
console.log(req.body);
const { email, phoneNumber } = req.body;

let method = '/v1/external/customers';

const signature = generateSignature('POST', method);

const response = await axios.post(
`${baseUrl}${method}`,
{
email,
phoneNumber,
type : "INDIVIDUAL"
},
{
headers: {
'Content-Type': 'application/json',
'api-key': apiKey,
'signature': signature
}
}
);

res.json({response: response.data});
});
// returns [customerId,createdAt]

// _______________________________________________________

// POST endpoint to create a new fiat account
// Request body should contain the following parameters:
// - customerId: The unique ID of the customer
// - accountNumber: The customer's account number
// - recipientFullAddress: The full address of the recipient
// - recipientAddressCountry: The country of the recipient's address
app.post('/newFiatAccount', async (req, res) => {
const { customerId, accountNumber, recipientFullAddress, recipientAddressCountry } = req.body;

let method = '/v1/external/fiatAccounts';

const signature = generateSignature('POST', method);

const response = await axios.post(
`${baseUrl}${method}`,
{
customerId,
type : "SEPA",
fiatAccountFields : {
accountNumber,
recipientFullAddress,
recipientAddressCountry
}
},
{
headers: {
'Content-Type': 'application/json',
'api-key': apiKey,
'signature': signature
}
}
);

if (response.status !== 200) {
res.status(400).send('Error creating new fiat account');
}

res.json({response: response.data});
});
// returns [fiatAccountId,createdAt,bankName]


// _______________________________________________________

// POST endpoint to create a new deposit
// Request body should contain the following parameters:
// - customerId: The unique ID of the customer
// - accountNumber: The customer's account number
// - recipientFullAddress: The full address of the recipient
// - recipientAddressCountry: The country of the recipient's address
app.post('/newDeposit', async (req, res) => {
const { customerId, chain,fromAmount, fromCurrency, toCurrency, fiatAccountId, amount } = req.body;

let method = '/v1/external/quotes';

const signature1 = generateSignature('POST', method);
console.log(signature1);
const response1 = await axios.post(
`${baseUrl}${method}`,
{
chain,

fromCurrency,
paymentMethodType : "SEPA",
toCurrency,
fromAmount,
amount
},
{
headers: {
'Content-Type': 'application/json',
'api-key': apiKey,
'signature': signature1
}
}
);
let method2 = '/v1/external/offramp';

const signature2 = generateSignature('POST', method2);

console.log('quoteId', response1.data.quoteId);

const response2 = await axios.post(
`${baseUrl}${method2}`,
{
customerId,
quoteId : response1.data.quoteId,
fromCurrency,
toCurrency,
amount,
toCurrency,
fiatAccountId,
chain
},
{
headers: {
'Content-Type': 'application/json',
'api-key': apiKey,
'signature': signature2
}
}
);

return res.json({response: response2.data});


});
// returns [depositAddress]


// _______________________________________________________


// POST endpoint to create a KYC Metadata Request
// Request body should contain the following parameters:
// - firstName: The first name of the customer
// - lastName: The last name of the customer
// - nationality: The nationality of the customer
// - dateOfBirth: The date of birth of the customer
// - countryOfResidence: The country where the customer resides
// POST endpoint to create a KYC Metadata Request
app.post('/newKYCMetadata', async (req, res) => {
const { customerId, firstName, lastName, nationality, dateOfBirth, countryOfResidence } = req.body;

// Verify that required fields are present
if (!customerId || !firstName || !lastName || !nationality || !dateOfBirth || !countryOfResidence) {
return res.status(400).json({ error: 'Missing required KYC fields' });
}

let method = `/v1/external/customers/${customerId}/kyc`;

console.log('method', method);

try {
const signature = generateSignature('POST', method);

const response = await axios.post(
`${baseUrl}${method}`,
{
kycSubmission: {
firstName,
lastName,
nationality,
dateOfBirth,
countryOfResidence
}
},
{
headers: {
'Content-Type': 'application/json',
'api-key': apiKey,
'signature': signature
}
}
);

if (response.status === 200) {
// Successfully created KYC metadata
res.json({ response: response.data });
} else {
// Handle non-200 responses
res.status(response.status).json({ error: response.data });
}
} catch (error) {
// Capture and log the error for debugging
console.error('Error creating KYC Metadata:', error.response ? error.response.data : error.message);
res.status(500).json({ error: 'Internal server error, please try again later.' });
}
});

// returns [fiatAccountId,createdAt,bankName]

app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
Binary file added API/assets/diagram.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added API/assets/logo.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 33890b6

Please sign in to comment.