paypal-isomorphic-functions
Advanced tools
Comparing version 1.0.9 to 1.0.10
import { IPayPalAccessToken } from "../oauth/interfaces"; | ||
export declare function createToken(token: IPayPalAccessToken, data?: any): Promise<Response>; | ||
export declare function create(token: IPayPalAccessToken, token_id: string): Promise<Response>; | ||
export declare function createToken(token: IPayPalAccessToken, data?: any, headers?: any): Promise<Response>; | ||
export declare function create(token: IPayPalAccessToken, token_id: string, headers?: any): Promise<Response>; |
@@ -5,6 +5,4 @@ "use strict"; | ||
const config_1 = require("../config"); | ||
async function createToken(token, data = {}) { | ||
const payload = Object.keys(data).length > 0 | ||
? data | ||
: constants_1.DEFAULT_CREATE_BILLING_AGREEMENT_TOKEN_PAYLOAD; | ||
async function createToken(token, data, headers) { | ||
const payload = data || constants_1.DEFAULT_CREATE_BILLING_AGREEMENT_TOKEN_PAYLOAD; | ||
const options = { | ||
@@ -14,3 +12,4 @@ method: "POST", | ||
Authorization: `Bearer ${token.access_token}`, | ||
"Content-Type": "application/json" | ||
"Content-Type": "application/json", | ||
...headers | ||
}, | ||
@@ -22,3 +21,3 @@ body: JSON.stringify(payload) | ||
exports.createToken = createToken; | ||
async function create(token, token_id) { | ||
async function create(token, token_id, headers) { | ||
const options = { | ||
@@ -28,3 +27,4 @@ method: "POST", | ||
Authorization: `Bearer ${token.access_token}`, | ||
"Content-Type": "application/json" | ||
"Content-Type": "application/json", | ||
...headers | ||
}, | ||
@@ -31,0 +31,0 @@ body: JSON.stringify({ token_id }) |
import "./polyfills"; | ||
import * as Orders from './orders'; | ||
import * as BillingAgreements from './billing-agreements'; | ||
import * as Oauth from './oauth'; | ||
import * as Payments from './payments'; | ||
import * as Webhooks from './webhooks'; | ||
import * as Middleware from './middleware'; | ||
export { Orders, Oauth, BillingAgreements, Payments, Webhooks, Middleware, }; | ||
import * as Orders from "./orders"; | ||
import * as BillingAgreements from "./billing-agreements"; | ||
import * as Oauth from "./oauth"; | ||
import * as Payments from "./payments"; | ||
import * as Webhooks from "./webhooks"; | ||
import * as Middleware from "./middleware"; | ||
export { Orders, Oauth, BillingAgreements, Payments, Webhooks, Middleware }; |
@@ -1,2 +0,2 @@ | ||
import { Request, Response, NextFunction } from 'express'; | ||
import { Request, Response, NextFunction } from "express"; | ||
export declare function accessTokenMiddleware(req: Request, res: Response, next: NextFunction): Promise<void>; |
import { IPayPalAccessToken } from "./interfaces"; | ||
export * from './interfaces'; | ||
export * from "./interfaces"; | ||
export declare function createAccessToken(): Promise<IPayPalAccessToken>; |
import { IPayPalAccessToken } from "../oauth/interfaces"; | ||
export declare function create(token: IPayPalAccessToken, data: any): Promise<Response>; | ||
export declare function update(token: IPayPalAccessToken, id: string, data: any): Promise<Response>; | ||
export declare function get(token: IPayPalAccessToken, id: string): Promise<Response>; | ||
export declare function authorize(token: IPayPalAccessToken, id: string, data: any): Promise<Response>; | ||
export declare function create(token: IPayPalAccessToken, data?: any, headers?: any): Promise<Response>; | ||
export declare function update(token: IPayPalAccessToken, id: string, data?: any, headers?: any): Promise<Response>; | ||
export declare function get(token: IPayPalAccessToken, id: string, headers?: any): Promise<Response>; | ||
export declare function authorize(token: IPayPalAccessToken, id: string, data?: any, headers?: any): Promise<Response>; |
@@ -5,3 +5,3 @@ "use strict"; | ||
const constants_1 = require("./constants"); | ||
async function create(token, data) { | ||
async function create(token, data, headers) { | ||
const payload = data || constants_1.DEFAULT_CREATE_ORDER_PAYLOAD; | ||
@@ -12,3 +12,4 @@ const options = { | ||
Authorization: `Bearer ${token.access_token}`, | ||
"Content-Type": "application/json" | ||
"Content-Type": "application/json", | ||
...headers | ||
}, | ||
@@ -20,3 +21,3 @@ body: JSON.stringify(payload) | ||
exports.create = create; | ||
async function update(token, id, data) { | ||
async function update(token, id, data, headers) { | ||
const payload = data || constants_1.DEFAULT_UPDATE_ORDER_PAYLOAD; | ||
@@ -27,3 +28,4 @@ const options = { | ||
Authorization: `Bearer ${token.access_token}`, | ||
"Content-Type": "application/json" | ||
"Content-Type": "application/json", | ||
...headers | ||
}, | ||
@@ -35,3 +37,3 @@ body: JSON.stringify(payload) | ||
exports.update = update; | ||
async function get(token, id) { | ||
async function get(token, id, headers) { | ||
const options = { | ||
@@ -41,4 +43,5 @@ method: "GET", | ||
Authorization: `Bearer ${token.access_token}`, | ||
"Content-Type": "application/json" | ||
}, | ||
"Content-Type": "application/json", | ||
...headers | ||
} | ||
}; | ||
@@ -48,3 +51,3 @@ return await fetch(`${config_1.CONFIG.get("PAYPAL_REST_HOSTNAME")}/v2/checkout/orders/${id}`, options); | ||
exports.get = get; | ||
async function authorize(token, id, data) { | ||
async function authorize(token, id, data, headers) { | ||
const payload = data; | ||
@@ -56,3 +59,3 @@ const options = { | ||
"Content-Type": "application/json" | ||
}, | ||
} | ||
}; | ||
@@ -59,0 +62,0 @@ return await fetch(`${config_1.CONFIG.get("PAYPAL_REST_HOSTNAME")}/v2/checkout/orders/${id}/authorize`, options); |
import { IPayPalAccessToken } from "../oauth/interfaces"; | ||
export declare function create(token: IPayPalAccessToken, data?: any): Promise<Response>; | ||
export declare function create(token: IPayPalAccessToken, data?: any, headers?: any): Promise<Response>; |
@@ -5,3 +5,3 @@ "use strict"; | ||
const constants_1 = require("./constants"); | ||
async function create(token, data) { | ||
async function create(token, data, headers) { | ||
const payload = data || constants_1.DEFAULT_PAYMENT_CREATE_PAYLOAD; | ||
@@ -12,3 +12,4 @@ const options = { | ||
Authorization: `Bearer ${token.access_token}`, | ||
"Content-Type": "application/json" | ||
"Content-Type": "application/json", | ||
...headers | ||
}, | ||
@@ -15,0 +16,0 @@ body: JSON.stringify(payload) |
{ | ||
"name": "paypal-isomorphic-functions", | ||
"version": "1.0.9", | ||
"version": "1.0.10", | ||
"description": "Library of helpful paypal functions that can be run in a browser or server", | ||
@@ -9,3 +9,4 @@ "main": "./dist/index.js", | ||
"build": "rm -rf dist && tsc && webpack", | ||
"format": "prettier --write \"src/**/*.{json,ts,yml,md}\"" | ||
"format": "prettier --write \"src/**/*.{json,ts,yml,md}\"", | ||
"release:quick": "npm run format && npm run build && git add -A && git commit -m 'Quick Release' && git push && npm version patch && npm publish" | ||
}, | ||
@@ -12,0 +13,0 @@ "author": "Andrew Throener", |
## Intro | ||
Package full of typed PayPal functions that can be run in the browser or server. You could call it an SDK. | ||
## Server config | ||
## Server Usage | ||
Required Environment variables. Protip: use dotenv | ||
@@ -11,3 +13,3 @@ ``` | ||
### Usage | ||
### Example | ||
``` | ||
@@ -54,3 +56,4 @@ import { Oauth, Orders } from 'paypal-isomorphic-functions'; | ||
# Client | ||
# Client Usage | ||
The library outputs to `window.paypalFunctions`. Place your client/secret in localStorage. Obviously, you would not want to EVER place your production credentials in local storage. | ||
@@ -61,5 +64,3 @@ ### Include Script | ||
### Usage | ||
The library outputs to `window.paypalFunctions`. Place your client/secret in localStorage | ||
### Example | ||
``` | ||
@@ -66,0 +67,0 @@ localStorage.setItem('PAYPAL_CLIENT_ID', ''); |
@@ -7,8 +7,6 @@ import { DEFAULT_CREATE_BILLING_AGREEMENT_TOKEN_PAYLOAD } from "./constants"; | ||
token: IPayPalAccessToken, | ||
data: any = {} | ||
data?: any, | ||
headers?: any | ||
) { | ||
const payload = | ||
Object.keys(data).length > 0 | ||
? data | ||
: DEFAULT_CREATE_BILLING_AGREEMENT_TOKEN_PAYLOAD; | ||
const payload = data || DEFAULT_CREATE_BILLING_AGREEMENT_TOKEN_PAYLOAD; | ||
@@ -19,3 +17,4 @@ const options = { | ||
Authorization: `Bearer ${token.access_token}`, | ||
"Content-Type": "application/json" | ||
"Content-Type": "application/json", | ||
...headers | ||
}, | ||
@@ -35,3 +34,4 @@ body: JSON.stringify(payload) | ||
token: IPayPalAccessToken, | ||
token_id: string | ||
token_id: string, | ||
headers?: any | ||
) { | ||
@@ -42,3 +42,4 @@ const options = { | ||
Authorization: `Bearer ${token.access_token}`, | ||
"Content-Type": "application/json" | ||
"Content-Type": "application/json", | ||
...headers | ||
}, | ||
@@ -45,0 +46,0 @@ body: JSON.stringify({ token_id }) |
import "./polyfills"; | ||
import * as Orders from './orders'; | ||
import * as BillingAgreements from './billing-agreements'; | ||
import * as Oauth from './oauth'; | ||
import * as Payments from './payments'; | ||
import * as Webhooks from './webhooks'; | ||
import * as Middleware from './middleware'; | ||
import * as Orders from "./orders"; | ||
import * as BillingAgreements from "./billing-agreements"; | ||
import * as Oauth from "./oauth"; | ||
import * as Payments from "./payments"; | ||
import * as Webhooks from "./webhooks"; | ||
import * as Middleware from "./middleware"; | ||
export { | ||
Orders, | ||
Oauth, | ||
BillingAgreements, | ||
Payments, | ||
Webhooks, | ||
Middleware, | ||
} | ||
export { Orders, Oauth, BillingAgreements, Payments, Webhooks, Middleware }; |
import { IPayPalAccessToken } from "../oauth/interfaces"; | ||
import { Request, Response, NextFunction } from 'express'; | ||
import { createAccessToken } from '../oauth'; | ||
import { Request, Response, NextFunction } from "express"; | ||
import { createAccessToken } from "../oauth"; | ||
@@ -8,11 +8,11 @@ let accessToken: IPayPalAccessToken; | ||
export async function accessTokenMiddleware( | ||
req: Request, | ||
res: Response, | ||
next: NextFunction | ||
req: Request, | ||
res: Response, | ||
next: NextFunction | ||
) { | ||
if (!accessToken || accessToken.expires_at > Date.now()) { | ||
accessToken = await createAccessToken(); | ||
} | ||
req.paypalAccessToken = accessToken; | ||
return next(); | ||
if (!accessToken || accessToken.expires_at > Date.now()) { | ||
accessToken = await createAccessToken(); | ||
} | ||
req.paypalAccessToken = accessToken; | ||
return next(); | ||
} |
import { IPayPalAccessToken } from "./interfaces"; | ||
import { CONFIG } from "../config"; | ||
export * from './interfaces'; | ||
export * from "./interfaces"; | ||
@@ -6,0 +6,0 @@ export async function createAccessToken() { |
export const DEFAULT_CREATE_ORDER_PAYLOAD = { | ||
intent: "AUTHORIZE", | ||
purchase_units: [ | ||
{ | ||
description: "This is cool", | ||
amount: { | ||
currency_code: "USD", | ||
value: "100.00" | ||
} | ||
} | ||
] | ||
intent: "AUTHORIZE", | ||
purchase_units: [ | ||
{ | ||
description: "This is cool", | ||
amount: { | ||
currency_code: "USD", | ||
value: "100.00" | ||
} | ||
} | ||
] | ||
}; | ||
export const DEFAULT_UPDATE_ORDER_PAYLOAD = [ | ||
{ | ||
op: "replace", | ||
path: "/purchase_units/@reference_id=='default'/description", | ||
value: "this is fine" | ||
} | ||
{ | ||
op: "replace", | ||
path: "/purchase_units/@reference_id=='default'/description", | ||
value: "this is fine" | ||
} | ||
]; |
import { IPayPalAccessToken } from "../oauth/interfaces"; | ||
import { CONFIG } from "../config"; | ||
import { DEFAULT_CREATE_ORDER_PAYLOAD, DEFAULT_UPDATE_ORDER_PAYLOAD } from './constants' | ||
import { | ||
DEFAULT_CREATE_ORDER_PAYLOAD, | ||
DEFAULT_UPDATE_ORDER_PAYLOAD | ||
} from "./constants"; | ||
export async function create(token: IPayPalAccessToken, data: any) { | ||
export async function create( | ||
token: IPayPalAccessToken, | ||
data?: any, | ||
headers?: any | ||
) { | ||
const payload = data || DEFAULT_CREATE_ORDER_PAYLOAD; | ||
@@ -12,3 +19,4 @@ | ||
Authorization: `Bearer ${token.access_token}`, | ||
"Content-Type": "application/json" | ||
"Content-Type": "application/json", | ||
...headers | ||
}, | ||
@@ -23,3 +31,8 @@ body: JSON.stringify(payload) | ||
export async function update(token: IPayPalAccessToken, id: string, data: any) { | ||
export async function update( | ||
token: IPayPalAccessToken, | ||
id: string, | ||
data?: any, | ||
headers?: any | ||
) { | ||
const payload = data || DEFAULT_UPDATE_ORDER_PAYLOAD; | ||
@@ -31,3 +44,4 @@ | ||
Authorization: `Bearer ${token.access_token}`, | ||
"Content-Type": "application/json" | ||
"Content-Type": "application/json", | ||
...headers | ||
}, | ||
@@ -42,4 +56,7 @@ body: JSON.stringify(payload) | ||
export async function get(token: IPayPalAccessToken, id: string) { | ||
export async function get( | ||
token: IPayPalAccessToken, | ||
id: string, | ||
headers?: any | ||
) { | ||
const options = { | ||
@@ -49,4 +66,5 @@ method: "GET", | ||
Authorization: `Bearer ${token.access_token}`, | ||
"Content-Type": "application/json" | ||
}, | ||
"Content-Type": "application/json", | ||
...headers | ||
} | ||
}; | ||
@@ -59,4 +77,8 @@ return await fetch( | ||
export async function authorize(token: IPayPalAccessToken, id: string, data: any) { | ||
export async function authorize( | ||
token: IPayPalAccessToken, | ||
id: string, | ||
data?: any, | ||
headers?: any | ||
) { | ||
// TODO: add a default | ||
@@ -70,3 +92,3 @@ const payload = data; | ||
"Content-Type": "application/json" | ||
}, | ||
} | ||
// body: JSON.stringify(payload) | ||
@@ -79,2 +101,1 @@ }; | ||
} | ||
@@ -5,3 +5,7 @@ import { IPayPalAccessToken } from "../oauth/interfaces"; | ||
export async function create(token: IPayPalAccessToken, data?: any) { | ||
export async function create( | ||
token: IPayPalAccessToken, | ||
data?: any, | ||
headers?: any | ||
) { | ||
const payload = data || DEFAULT_PAYMENT_CREATE_PAYLOAD; | ||
@@ -13,3 +17,4 @@ | ||
Authorization: `Bearer ${token.access_token}`, | ||
"Content-Type": "application/json" | ||
"Content-Type": "application/json", | ||
...headers | ||
}, | ||
@@ -16,0 +21,0 @@ body: JSON.stringify(payload) |
@@ -5,7 +5,7 @@ import { Request } from "express"; | ||
declare global { | ||
namespace Express { | ||
export interface Request { | ||
paypalAccessToken: IPayPalAccessToken; | ||
} | ||
namespace Express { | ||
export interface Request { | ||
paypalAccessToken: IPayPalAccessToken; | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
363369
1351
76