Skip to content

API Docs

Tom Hudson edited this page Dec 14, 2022 · 1 revision

Nest Payments v1.0

Scroll down for code samples, example requests and responses. Select a language for code samples from the tabs above or the mobile navigation menu.

An API for customers and payments with Stripe.

Base URLs:

Authentication

  • HTTP Authentication, scheme: bearer An http bearer auth token is required for all secured routes. An auth grant can be obtained from /user/login and /user/register

User

UserController_create

Code samples

const inputBody = '{
  "userName": "Alan Turing",
  "email": "aturing@gmail.com",
  "password": "password"
}';
const headers = {
  'Content-Type':'application/json',
  'Accept':'application/json',
  'Authorization':'Bearer {access-token}'
};

fetch('/user',
{
  method: 'POST',
  body: inputBody,
  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});

POST /user

Body parameter

{
  "userName": "Alan Turing",
  "email": "aturing@gmail.com",
  "password": "password"
}

Parameters

Name In Type Required Description
body body CreateUserDto true none

Example responses

201 Response

{
  "userId": "5f9f1c9b9c9c9c9c9c9c9c9c",
  "userName": "Alan Turing",
  "email": "aturing@gmail.com",
  "customerId": "cus_1234567890"
}

Responses

Status Meaning Description Schema
201 Created none ReturnUserDto
To perform this operation, you must be authenticated by means of one of the following methods: bearer

UserController_findAll

Code samples

const headers = {
  'Accept':'application/json',
  'Authorization':'Bearer {access-token}'
};

fetch('/user',
{
  method: 'GET',

  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});

GET /user

Example responses

200 Response

[
  {
    "userId": "5f9f1c9b9c9c9c9c9c9c9c9c",
    "userName": "Alan Turing",
    "email": "aturing@gmail.com",
    "customerId": "cus_1234567890"
  }
]

Responses

Status Meaning Description Schema
200 OK none Inline

Response Schema

Status Code 200

Name Type Required Restrictions Description
anonymous [ReturnUserDto] false none none
» userId string true none The user's id in Mongodb.
» userName string true none The user's name.
» email string true none The user's email address.
» customerId string false none The user's Stripe customer id. Users without transactions do not have a customer id.
To perform this operation, you must be authenticated by means of one of the following methods: bearer

UserController_findOne

Code samples

const headers = {
  'Accept':'application/json',
  'Authorization':'Bearer {access-token}'
};

fetch('/user/{id}',
{
  method: 'GET',

  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});

GET /user/{id}

Parameters

Name In Type Required Description
id path string true none

Example responses

200 Response

{
  "userId": "5f9f1c9b9c9c9c9c9c9c9c9c",
  "userName": "Alan Turing",
  "email": "aturing@gmail.com",
  "customerId": "cus_1234567890"
}

Responses

Status Meaning Description Schema
200 OK none ReturnUserDto
To perform this operation, you must be authenticated by means of one of the following methods: bearer

UserController_update

Code samples

const inputBody = '{
  "userName": "Alan Turing",
  "email": "aturing@gmail.com",
  "customerId": "cus_1234567890"
}';
const headers = {
  'Content-Type':'application/json',
  'Accept':'application/json',
  'Authorization':'Bearer {access-token}'
};

fetch('/user/{id}',
{
  method: 'PATCH',
  body: inputBody,
  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});

PATCH /user/{id}

Body parameter

{
  "userName": "Alan Turing",
  "email": "aturing@gmail.com",
  "customerId": "cus_1234567890"
}

Parameters

Name In Type Required Description
id path string true none
body body UpdateUserDto true none

Example responses

200 Response

{
  "userId": "5f9f1c9b9c9c9c9c9c9c9c9c",
  "userName": "Alan Turing",
  "email": "aturing@gmail.com",
  "customerId": "cus_1234567890"
}

Responses

Status Meaning Description Schema
200 OK none ReturnUserDto
To perform this operation, you must be authenticated by means of one of the following methods: bearer

UserController_remove

Code samples

const headers = {
  'Accept':'application/json',
  'Authorization':'Bearer {access-token}'
};

fetch('/user/{id}',
{
  method: 'DELETE',

  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});

DELETE /user/{id}

Parameters

Name In Type Required Description
id path string true none

Example responses

200 Response

{
  "userId": "5f9f1c9b9c9c9c9c9c9c9c9c",
  "userName": "Alan Turing",
  "email": "aturing@gmail.com",
  "customerId": "cus_1234567890"
}

Responses

Status Meaning Description Schema
200 OK none ReturnUserDto
To perform this operation, you must be authenticated by means of one of the following methods: bearer

UserController_register

Code samples

const inputBody = '{
  "userName": "Alan Turing",
  "email": "aturing@gmail.com",
  "password": "password"
}';
const headers = {
  'Content-Type':'application/json',
  'Accept':'application/json'
};

fetch('/user/register',
{
  method: 'POST',
  body: inputBody,
  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});

POST /user/register

Body parameter

{
  "userName": "Alan Turing",
  "email": "aturing@gmail.com",
  "password": "password"
}

Parameters

Name In Type Required Description
body body CreateUserDto true none

Example responses

201 Response

{
  "access_token": "string"
}

Responses

Status Meaning Description Schema
201 Created none AuthGrantDto
This operation does not require authentication

UserController_login

Code samples

const inputBody = '{
  "email": "aturing@gmail.com",
  "password": "password"
}';
const headers = {
  'Content-Type':'application/json',
  'Accept':'application/json'
};

fetch('/user/login',
{
  method: 'POST',
  body: inputBody,
  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});

POST /user/login

Body parameter

{
  "email": "aturing@gmail.com",
  "password": "password"
}

Parameters

Name In Type Required Description
body body LoginUserDto true none

Example responses

201 Response

{
  "access_token": "string"
}

Responses

Status Meaning Description Schema
201 Created none AuthGrantDto
This operation does not require authentication

Payment

PaymentController_getPayments

Code samples

const headers = {
  'Accept':'application/json',
  'Authorization':'Bearer {access-token}'
};

fetch('/payment',
{
  method: 'GET',

  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});

GET /payment

Example responses

200 Response

[
  {
    "id": "pi_1H7jg1CZ6F7J6I8jW2Q2c2jG",
    "amount": 2000,
    "currency": "usd",
    "status": "pending",
    "paymentMethod": "pm_1H7jg1CZ6F7J6I8jW2Q2c2jG"
  }
]

Responses

Status Meaning Description Schema
200 OK none Inline

Response Schema

Status Code 200

Name Type Required Restrictions Description
anonymous [ReturnPaymentDto] false none none
» id string true none Payment Intent ID.
» amount number true none Amount in cents.
» currency string true none Currency code. See https://stripe.com/docs/currencies.
» status string true none Payment Intent status. See https://stripe.com/docs/payments/payment-intents#intent-statuses.
» paymentMethod string true none Stripe payment method
To perform this operation, you must be authenticated by means of one of the following methods: bearer

PaymentController_createPayment

Code samples

const inputBody = '{
  "cuid": "cjld2cjxh0000qzrmn831i7rn"
}';
const headers = {
  'Content-Type':'application/json',
  'Accept':'application/json',
  'Authorization':'Bearer {access-token}'
};

fetch('/payment',
{
  method: 'POST',
  body: inputBody,
  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});

POST /payment

Body parameter

{
  "cuid": "cjld2cjxh0000qzrmn831i7rn"
}

Parameters

Name In Type Required Description
body body CreatePaymentDto true none

Example responses

201 Response

{
  "id": "pi_1H7jg1CZ6F7J6I8jW2Q2c2jG",
  "amount": 2000,
  "currency": "usd",
  "status": "pending",
  "paymentMethod": "pm_1H7jg1CZ6F7J6I8jW2Q2c2jG",
  "clientSecret": "Jreaw828oaooi3j3r"
}

Responses

Status Meaning Description Schema
201 Created none PaymentCreatedDto
To perform this operation, you must be authenticated by means of one of the following methods: bearer

PaymentController_getPayment

Code samples

const headers = {
  'Accept':'application/json',
  'Authorization':'Bearer {access-token}'
};

fetch('/payment/{id}',
{
  method: 'GET',

  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});

GET /payment/{id}

Parameters

Name In Type Required Description
id path string true none

Example responses

200 Response

{
  "id": "pi_1H7jg1CZ6F7J6I8jW2Q2c2jG",
  "amount": 2000,
  "currency": "usd",
  "status": "pending",
  "paymentMethod": "pm_1H7jg1CZ6F7J6I8jW2Q2c2jG"
}

Responses

Status Meaning Description Schema
200 OK none ReturnPaymentDto
To perform this operation, you must be authenticated by means of one of the following methods: bearer

PaymentController_confirmPayment

Code samples

const inputBody = '{
  "cuid": "cjld2cjxh0000qzrmn831i7rn",
  "paymentId": "pi_1H4Q2cKZ4Z4Z4Z4Z4Z4Z4Z4Z",
  "paymentMethodId": "pm_1H7jg1CZ6F7J6I8jW2Q2c2jG"
}';
const headers = {
  'Content-Type':'application/json',
  'Accept':'application/json',
  'Authorization':'Bearer {access-token}'
};

fetch('/payment/confirm',
{
  method: 'POST',
  body: inputBody,
  headers: headers
})
.then(function(res) {
    return res.json();
}).then(function(body) {
    console.log(body);
});

POST /payment/confirm

Body parameter

{
  "cuid": "cjld2cjxh0000qzrmn831i7rn",
  "paymentId": "pi_1H4Q2cKZ4Z4Z4Z4Z4Z4Z4Z4Z",
  "paymentMethodId": "pm_1H7jg1CZ6F7J6I8jW2Q2c2jG"
}

Parameters

Name In Type Required Description
body body ConfirmPaymentDto true none

Example responses

201 Response

{
  "id": "pi_1H7jg1CZ6F7J6I8jW2Q2c2jG",
  "amount": 2000,
  "currency": "usd",
  "status": "pending",
  "paymentMethod": "pm_1H7jg1CZ6F7J6I8jW2Q2c2jG"
}

Responses

Status Meaning Description Schema
201 Created none ReturnPaymentDto
To perform this operation, you must be authenticated by means of one of the following methods: bearer

Schemas

CreateUserDto

{
  "userName": "Alan Turing",
  "email": "aturing@gmail.com",
  "password": "password"
}

Properties

Name Type Required Restrictions Description
userName string true none The user's name.
email string true none The user's email address.
password string true none The user's password.

ReturnUserDto

{
  "userId": "5f9f1c9b9c9c9c9c9c9c9c9c",
  "userName": "Alan Turing",
  "email": "aturing@gmail.com",
  "customerId": "cus_1234567890"
}

Properties

Name Type Required Restrictions Description
userId string true none The user's id in Mongodb.
userName string true none The user's name.
email string true none The user's email address.
customerId string false none The user's Stripe customer id. Users without transactions do not have a customer id.

UpdateUserDto

{
  "userName": "Alan Turing",
  "email": "aturing@gmail.com",
  "customerId": "cus_1234567890"
}

Properties

Name Type Required Restrictions Description
userName string false none The user's name.
email string false none The user's email address.
customerId string false none The user's Stripe customer id.

AuthGrantDto

{
  "access_token": "string"
}

Properties

Name Type Required Restrictions Description
access_token string true none The access token.

LoginUserDto

{
  "email": "aturing@gmail.com",
  "password": "password"
}

Properties

Name Type Required Restrictions Description
email string true none The user's email address.
password string true none The user's password.

ReturnPaymentDto

{
  "id": "pi_1H7jg1CZ6F7J6I8jW2Q2c2jG",
  "amount": 2000,
  "currency": "usd",
  "status": "pending",
  "paymentMethod": "pm_1H7jg1CZ6F7J6I8jW2Q2c2jG"
}

Properties

Name Type Required Restrictions Description
id string true none Payment Intent ID.
amount number true none Amount in cents.
currency string true none Currency code. See https://stripe.com/docs/currencies.
status string true none Payment Intent status. See https://stripe.com/docs/payments/payment-intents#intent-statuses.
paymentMethod string true none Stripe payment method

CreatePaymentDto

{
  "cuid": "cjld2cjxh0000qzrmn831i7rn"
}

Properties

Name Type Required Restrictions Description
cuid string true none CUID (collision resistant id) that identifies the user session. Use https://github.com/paralleldrive/cuid to generate them. This is used as an idempotency key for the payment intent creation. Thus, they should be unique foreach payment intent creation but remain constant between retries.

PaymentCreatedDto

{
  "id": "pi_1H7jg1CZ6F7J6I8jW2Q2c2jG",
  "amount": 2000,
  "currency": "usd",
  "status": "pending",
  "paymentMethod": "pm_1H7jg1CZ6F7J6I8jW2Q2c2jG",
  "clientSecret": "Jreaw828oaooi3j3r"
}

Properties

Name Type Required Restrictions Description
id string true none Payment Intent ID.
amount number true none Amount in cents.
currency string true none Currency code. See https://stripe.com/docs/currencies.
status string true none Payment Intent status. See https://stripe.com/docs/payments/payment-intents#intent-statuses.
paymentMethod string true none Stripe payment method
clientSecret string true none Client secret for the payment intent.

ConfirmPaymentDto

{
  "cuid": "cjld2cjxh0000qzrmn831i7rn",
  "paymentId": "pi_1H4Q2cKZ4Z4Z4Z4Z4Z4Z4Z4Z",
  "paymentMethodId": "pm_1H7jg1CZ6F7J6I8jW2Q2c2jG"
}

Properties

Name Type Required Restrictions Description
cuid string true none CUID (collision resistant id) that identifies the user session. Use https://github.com/paralleldrive/cuid to generate them. This is used as an idempotency key for the payment intent creation. Thus, they should be unique foreach payment intent creation but remain constant between retries.
paymentId string true none Payment intent id.
paymentMethodId string true none Payment method id.