Skip to content

add JSDoc links to REST APIs #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions advanced-integration/paypal-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import fetch from "node-fetch";
const { CLIENT_ID, APP_SECRET } = process.env;
const base = "https://api-m.sandbox.paypal.com";

// call the create order method
/**
* Create an order
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_create
*/
export async function createOrder() {
const purchaseAmount = "100.00"; // TODO: pull prices from a database
const accessToken = await generateAccessToken();
Expand All @@ -31,7 +34,10 @@ export async function createOrder() {
return handleResponse(response);
}

// capture payment for an order
/**
* Capture payment for an order
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_capture
*/
export async function capturePayment(orderId) {
const accessToken = await generateAccessToken();
const url = `${base}/v2/checkout/orders/${orderId}/capture`;
Expand All @@ -46,7 +52,10 @@ export async function capturePayment(orderId) {
return handleResponse(response);
}

// generate access token
/**
* Generate an OAuth 2.0 access token
* @see https://developer.paypal.com/api/rest/authentication/
*/
export async function generateAccessToken() {
const auth = Buffer.from(CLIENT_ID + ":" + APP_SECRET).toString("base64");
const response = await fetch(`${base}/v1/oauth2/token`, {
Expand All @@ -60,7 +69,10 @@ export async function generateAccessToken() {
return jsonData.access_token;
}

// generate client token
/**
* Generate a client token
* @see https://developer.paypal.com/docs/checkout/advanced/integrate/#link-sampleclienttokenrequest
*/
export async function generateClientToken() {
const accessToken = await generateAccessToken();
const response = await fetch(`${base}/v1/identity/generate-token`, {
Expand Down
12 changes: 12 additions & 0 deletions standard-integration/paypal-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import fetch from "node-fetch";
const { CLIENT_ID, APP_SECRET } = process.env;
const base = "https://api-m.sandbox.paypal.com";

/**
* Create an order
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_create
*/
export async function createOrder() {
const accessToken = await generateAccessToken();
const url = `${base}/v2/checkout/orders`;
Expand All @@ -28,6 +32,10 @@ export async function createOrder() {
return handleResponse(response);
}

/**
* Capture payment for an order
* @see https://developer.paypal.com/docs/api/orders/v2/#orders_capture
*/
export async function capturePayment(orderId) {
const accessToken = await generateAccessToken();
const url = `${base}/v2/checkout/orders/${orderId}/capture`;
Expand All @@ -42,6 +50,10 @@ export async function capturePayment(orderId) {
return handleResponse(response);
}

/**
* Generate an OAuth 2.0 access token
* @see https://developer.paypal.com/api/rest/authentication/
*/
export async function generateAccessToken() {
const auth = Buffer.from(CLIENT_ID + ":" + APP_SECRET).toString("base64");
const response = await fetch(`${base}/v1/oauth2/token`, {
Expand Down