Skip to content

Commit

Permalink
add JSDoc links to REST APIs (#28)
Browse files Browse the repository at this point in the history
* add JSDoc links to REST APIs

Co-authored-by: Greg Jopa <[email protected]>
  • Loading branch information
jshawl and gregjopa authored Jul 28, 2023
1 parent 0806635 commit 3d333d5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
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

0 comments on commit 3d333d5

Please sign in to comment.