feature: add Product.list and Plan.list

This commit is contained in:
AJ ONeal 2021-10-11 18:24:17 -06:00
parent 1c941cb104
commit 0b5e0ab292
2 changed files with 54 additions and 1 deletions

View File

@ -84,7 +84,7 @@ Product.categories = {
};
*/
Product.create = async function _createSubscription({
Product.create = async function _createProduct({
request_id,
name,
description,
@ -127,6 +127,14 @@ Product.create = async function _createSubscription({
.then(must201or200)
.then(justBody);
};
Product.list = async function _listProducts() {
return await PayPal.request({
url: "/v1/catalogs/products",
json: true,
})
.then(must201or200)
.then(justBody);
};
let Plan = {};
Plan.intervals = {
@ -201,6 +209,15 @@ Plan.create = async function _createPlan({
.then(justBody);
};
Plan.list = async function _listPlans() {
return await PayPal.request({
url: "/v1/billing/plans",
json: true,
})
.then(must201or200)
.then(justBody);
};
let Subscription = {};
Subscription.actions = {
CONTINUE: "CONTINUE",

36
tests/list.js Normal file
View File

@ -0,0 +1,36 @@
"use strict";
require("dotenv").config({ path: ".env" });
require("dotenv").config({ path: ".env.secret" });
if (!process.env.PAYPAL_CLIENT_ID) {
console.error(
"Please copy example.env to .env and update the values from the PayPal API Dashboard at https://developer.paypal.com/developer/applications"
);
process.exit(1);
}
let PayPal = require("../");
let { Plan, Product, Subscription } = PayPal;
async function test() {
let products = await Plan.list();
console.info();
console.info("Products:");
console.info(JSON.stringify(products, null, 2));
let plans = await Plan.list();
console.info();
console.info("Plans:");
console.info(JSON.stringify(plans, null, 2));
console.info();
}
if (require.main === module) {
PayPal.init(process.env.PAYPAL_CLIENT_ID, process.env.PAYPAL_CLIENT_SECRET);
test().catch(function (err) {
console.error("Something bad happened:");
console.error(JSON.stringify(err, null, 2));
});
}