mirror of
https://github.com/therootcompany/paypal-checkout.js.git
synced 2025-05-13 09:36:37 +00:00
refactor!: rename id => request_id as appropriate
This commit is contained in:
parent
fc6eb5371a
commit
38361ffe1e
@ -3,17 +3,17 @@
|
|||||||
let request = require("@root/request");
|
let request = require("@root/request");
|
||||||
|
|
||||||
let PayPal = {};
|
let PayPal = {};
|
||||||
PayPal.init = function (id, secret) {
|
PayPal.init = function (client_id, client_secret) {
|
||||||
PayPal.__sandboxUrl = "https://api-m.sandbox.paypal.com";
|
PayPal.__sandboxUrl = "https://api-m.sandbox.paypal.com";
|
||||||
PayPal.__baseUrl = PayPal.__sandboxUrl;
|
PayPal.__baseUrl = PayPal.__sandboxUrl;
|
||||||
PayPal.__id = id;
|
PayPal.__id = client_id;
|
||||||
PayPal.__secret = secret;
|
PayPal.__secret = client_secret;
|
||||||
};
|
};
|
||||||
PayPal.request = async function _paypalRequest(reqObj) {
|
PayPal.request = async function _paypalRequest(reqObj) {
|
||||||
let headers = {};
|
let headers = {};
|
||||||
if (reqObj.id) {
|
if (reqObj.request_id) {
|
||||||
// Optional and if passed, helps identify idempotent requests
|
// Optional and if passed, helps identify idempotent requests
|
||||||
headers["PayPal-Request-Id"] = reqObj.id;
|
headers["PayPal-Request-Id"] = reqObj.request_id;
|
||||||
}
|
}
|
||||||
// ex: https://api-m.sandbox.paypal.com/v1/billing/subscriptions
|
// ex: https://api-m.sandbox.paypal.com/v1/billing/subscriptions
|
||||||
reqObj.url = `${PayPal.__baseUrl}${reqObj.url}`;
|
reqObj.url = `${PayPal.__baseUrl}${reqObj.url}`;
|
||||||
@ -85,7 +85,7 @@ Product.categories = {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Product.create = async function _createSubscription({
|
Product.create = async function _createSubscription({
|
||||||
id,
|
request_id,
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
type,
|
type,
|
||||||
@ -93,8 +93,8 @@ Product.create = async function _createSubscription({
|
|||||||
image_url,
|
image_url,
|
||||||
home_url,
|
home_url,
|
||||||
}) {
|
}) {
|
||||||
if (id) {
|
if (request_id) {
|
||||||
if (!id.startsWith("PROD-")) {
|
if (!request_id.startsWith("PROD-")) {
|
||||||
console.warn(`Warn: product ID should start with "PROD-"`);
|
console.warn(`Warn: product ID should start with "PROD-"`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -108,7 +108,7 @@ Product.create = async function _createSubscription({
|
|||||||
return await PayPal.request({
|
return await PayPal.request({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: "/v1/catalogs/products",
|
url: "/v1/catalogs/products",
|
||||||
id: id,
|
request_id: request_id,
|
||||||
json: {
|
json: {
|
||||||
// ex: "Video Streaming Service"
|
// ex: "Video Streaming Service"
|
||||||
name: name,
|
name: name,
|
||||||
@ -142,7 +142,7 @@ Plan.tenures = {
|
|||||||
|
|
||||||
// See https://developer.paypal.com/docs/api/subscriptions/v1/
|
// See https://developer.paypal.com/docs/api/subscriptions/v1/
|
||||||
Plan.create = async function _createPlan({
|
Plan.create = async function _createPlan({
|
||||||
id,
|
request_id,
|
||||||
status = "ACTIVE",
|
status = "ACTIVE",
|
||||||
product_id,
|
product_id,
|
||||||
name,
|
name,
|
||||||
@ -152,19 +152,20 @@ Plan.create = async function _createPlan({
|
|||||||
taxes, // optional
|
taxes, // optional
|
||||||
quantity_supported = false,
|
quantity_supported = false,
|
||||||
}) {
|
}) {
|
||||||
let headers = {};
|
if (request_id) {
|
||||||
if (id) {
|
if (!request_id.startsWith("PLAN-")) {
|
||||||
if (!id.startsWith("PLAN-")) {
|
|
||||||
// ex: PLAN-18062020-001
|
// ex: PLAN-18062020-001
|
||||||
console.warn(`Warn: plan ID should start with "PLAN-"`);
|
console.warn(`Warn: plan ID should start with "PLAN-"`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
headers["Prefer"] = "return=representation";
|
|
||||||
return await PayPal.request({
|
return await PayPal.request({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: "/v1/billing/plans",
|
url: "/v1/billing/plans",
|
||||||
id: id,
|
request_id: request_id,
|
||||||
headers: headers,
|
// TODO should we make this the default?
|
||||||
|
headers: {
|
||||||
|
Prefer: "return=representation",
|
||||||
|
},
|
||||||
json: {
|
json: {
|
||||||
// ex: "PROD-6XB24663H4094933M"
|
// ex: "PROD-6XB24663H4094933M"
|
||||||
product_id: product_id,
|
product_id: product_id,
|
||||||
@ -219,7 +220,7 @@ Subscription.payee_preferences = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Subscription.createRequest = async function _createSubscription({
|
Subscription.createRequest = async function _createSubscription({
|
||||||
id,
|
request_id,
|
||||||
plan_id,
|
plan_id,
|
||||||
start_time,
|
start_time,
|
||||||
quantity,
|
quantity,
|
||||||
@ -230,7 +231,7 @@ Subscription.createRequest = async function _createSubscription({
|
|||||||
return await PayPal.request({
|
return await PayPal.request({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: "/v1/billing/subscriptions",
|
url: "/v1/billing/subscriptions",
|
||||||
id: id,
|
request_id: request_id,
|
||||||
json: {
|
json: {
|
||||||
// ex: "P-5ML4271244454362WXNWU5NQ"
|
// ex: "P-5ML4271244454362WXNWU5NQ"
|
||||||
plan_id: plan_id,
|
plan_id: plan_id,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user