paypal-rest
Advanced tools
Comparing version 1.3.0-ALPHA to 1.3.1-ALPHA
@@ -15,2 +15,3 @@ import UnitBuilder from "./UnitBuilder"; | ||
setPlanId(id: string): this; | ||
setPlan(plan: SubscriptionInlinePlanBuilder | SubscriptionsInlinePlanBuilderProps): this; | ||
setQuantity(quantity: number): this; | ||
@@ -21,3 +22,2 @@ setCustomId(id: string): this; | ||
setApplicationContext(context: ApplicationContext): this; | ||
setPlan(plan: SubscriptionInlinePlanBuilder | SubscriptionsInlinePlanBuilderProps): this; | ||
toJSON(): Readonly<SubscriptionsBuilderProps<'JSON'>>; | ||
@@ -24,0 +24,0 @@ private validate; |
@@ -17,5 +17,5 @@ "use strict"; | ||
this.shipping_amount = data.shipping_amount instanceof UnitBuilder_1.default ? data.shipping_amount : new UnitBuilder_1.default(data === null || data === void 0 ? void 0 : data.shipping_amount); | ||
if (data === null || data === void 0 ? void 0 : data.plan) | ||
this.plan = data.plan instanceof SubscriptionInlinePlanBuilder_1.default ? data.plan : new SubscriptionInlinePlanBuilder_1.default(data === null || data === void 0 ? void 0 : data.plan); | ||
this.application_context = data === null || data === void 0 ? void 0 : data.application_context; | ||
if (data === null || data === void 0 ? void 0 : data.plan) | ||
this.plan = data.plan instanceof SubscriptionInlinePlanBuilder_1.default ? data.plan : new SubscriptionInlinePlanBuilder_1.default(data.plan); | ||
} | ||
@@ -28,2 +28,6 @@ setPlanId(id) { | ||
} | ||
setPlan(plan) { | ||
this.plan = plan instanceof SubscriptionInlinePlanBuilder_1.default ? plan : new SubscriptionInlinePlanBuilder_1.default(plan); | ||
return this; | ||
} | ||
setQuantity(quantity) { | ||
@@ -56,6 +60,2 @@ if (isNaN(quantity)) | ||
} | ||
setPlan(plan) { | ||
this.plan = plan instanceof SubscriptionInlinePlanBuilder_1.default ? plan : new SubscriptionInlinePlanBuilder_1.default(plan); | ||
return this; | ||
} | ||
toJSON() { | ||
@@ -75,3 +75,3 @@ var _a, _b, _c; | ||
validate() { | ||
var _a; | ||
var _a, _b; | ||
if (!this.plan_id || this.plan_id.length < 3 || this.plan_id.length > 50) | ||
@@ -87,5 +87,4 @@ throw new Errors_1.default("Invalid plan ID provided. The plan ID must be between 3 and 50 characters long."); | ||
this.verifyApplicationContextValues(this.application_context); | ||
if (this.plan) | ||
this.plan.toJSON(); | ||
(_a = this.shipping_amount) === null || _a === void 0 ? void 0 : _a.toJSON(); | ||
(_b = this.plan) === null || _b === void 0 ? void 0 : _b.toJSON(); | ||
} | ||
@@ -92,0 +91,0 @@ verifyApplicationContextValues(context) { |
import { SubscriptionsInlinePlanBuilderProps, Taxes } from "../types/Subscriptions"; | ||
import BillingCycleBuilder from "./BillingCycleBuilder"; | ||
import PaymentPreferencesBuilder from "./PaymentPreferencesBuilder"; | ||
import { BillingCycleProps } from "../types/BillingCycle"; | ||
import { InlineBillingCycleProps } from "../types/BillingCycle"; | ||
import { PaymentPreferencesProps } from "../types/PaymentPreferences"; | ||
export default class SubscriptionInlinePlanBuilder { | ||
protected billing_cycles: BillingCycleBuilder[]; | ||
protected billing_cycles: InlineBillingCycleProps[]; | ||
protected payment_preferences?: PaymentPreferencesBuilder; | ||
protected taxes?: Taxes; | ||
constructor(data?: Partial<SubscriptionsInlinePlanBuilderProps>); | ||
addBillingCycle(...billing_cycle: (BillingCycleBuilder | BillingCycleProps)[]): SubscriptionInlinePlanBuilder; | ||
setBillingCycles(...billing_cycles: (BillingCycleBuilder | BillingCycleProps)[]): SubscriptionInlinePlanBuilder; | ||
addBillingCycle(...billing_cycle: (InlineBillingCycleProps)[]): SubscriptionInlinePlanBuilder; | ||
setBillingCycles(...billing_cycles: (InlineBillingCycleProps)[]): SubscriptionInlinePlanBuilder; | ||
setPaymentPreferences(payment_preferences: PaymentPreferencesBuilder | PaymentPreferencesProps): SubscriptionInlinePlanBuilder; | ||
@@ -14,0 +13,0 @@ setTaxes(taxes: Taxes): SubscriptionInlinePlanBuilder; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const BillingCycleBuilder_1 = require("./BillingCycleBuilder"); | ||
const PaymentPreferencesBuilder_1 = require("./PaymentPreferencesBuilder"); | ||
const Errors_1 = require("../Manager/Errors"); | ||
const PricingSchemeBuilder_1 = require("./PricingSchemeBuilder"); | ||
class SubscriptionInlinePlanBuilder { | ||
constructor(data) { | ||
var _a; | ||
this.billing_cycles = ((_a = data === null || data === void 0 ? void 0 : data.billing_cycles) === null || _a === void 0 ? void 0 : _a.map(billingCycle => { | ||
return (billingCycle instanceof BillingCycleBuilder_1.default) ? billingCycle : new BillingCycleBuilder_1.default(billingCycle); | ||
})) || []; | ||
this.billing_cycles = (data === null || data === void 0 ? void 0 : data.billing_cycles) || []; | ||
this.payment_preferences = ((data === null || data === void 0 ? void 0 : data.payment_preferences) instanceof PaymentPreferencesBuilder_1.default) ? data.payment_preferences : new PaymentPreferencesBuilder_1.default(data === null || data === void 0 ? void 0 : data.payment_preferences); | ||
@@ -18,5 +15,3 @@ this.taxes = data === null || data === void 0 ? void 0 : data.taxes; | ||
throw new Errors_1.default("Invalid billing_cycle the length must be less than 12."); | ||
this.billing_cycles.push(...billing_cycle.map(billingCycle => { | ||
return (billingCycle instanceof BillingCycleBuilder_1.default) ? billingCycle : new BillingCycleBuilder_1.default(billingCycle); | ||
})); | ||
this.billing_cycles.push(...billing_cycle); | ||
return this; | ||
@@ -27,5 +22,3 @@ } | ||
throw new Errors_1.default("Invalid billing_cycle the length must be less than 12."); | ||
this.billing_cycles = billing_cycles.map(billingCycle => { | ||
return (billingCycle instanceof BillingCycleBuilder_1.default) ? billingCycle : new BillingCycleBuilder_1.default(billingCycle); | ||
}); | ||
this.billing_cycles = billing_cycles; | ||
return this; | ||
@@ -45,4 +38,13 @@ } | ||
return { | ||
billing_cycles: this.billing_cycles.map(billingCycle => { | ||
return billingCycle.toJSON(); | ||
billing_cycles: this.billing_cycles.map(({ sequence, pricing_scheme, total_cycles }) => { | ||
const data = { | ||
sequence, | ||
total_cycles | ||
}; | ||
if (pricing_scheme) { | ||
data.pricing_scheme = (pricing_scheme instanceof PricingSchemeBuilder_1.default) ? | ||
pricing_scheme.toJSON() : | ||
new PricingSchemeBuilder_1.default(pricing_scheme).toJSON(); | ||
} | ||
return data; | ||
}), | ||
@@ -58,4 +60,15 @@ payment_preferences: (_a = this.payment_preferences) === null || _a === void 0 ? void 0 : _a.toJSON(), | ||
(_a = this.payment_preferences) === null || _a === void 0 ? void 0 : _a.toJSON(); | ||
this.billing_cycles.forEach(billingCycle => { | ||
billingCycle.toJSON(); | ||
this.billing_cycles.forEach(({ sequence, pricing_scheme, total_cycles }) => { | ||
if (typeof sequence !== 'number' || isNaN(sequence) || sequence < 1 || sequence > 99 || sequence % 1 !== 0) | ||
throw new Errors_1.default("Invalid billing_cycle.sequence the billing_cycle.sequence must be a valid integer between 1 and 99."); | ||
if (total_cycles && (isNaN(total_cycles) || total_cycles < 0 || total_cycles > 999 || total_cycles % 1 !== 0)) | ||
throw new Errors_1.default("Invalid billing_cycle.total_cycles the billing_cycle.total_cycles must be a valid integer between 0 and 999."); | ||
if (pricing_scheme) { | ||
if (pricing_scheme instanceof PricingSchemeBuilder_1.default) { | ||
pricing_scheme.toJSON(); | ||
} | ||
else { | ||
new PricingSchemeBuilder_1.default(pricing_scheme).toJSON(); | ||
} | ||
} | ||
}); | ||
@@ -62,0 +75,0 @@ if (this.taxes) { |
@@ -1,11 +0,17 @@ | ||
import { SubscriptionsPlanBuilderProps, SubscriptionsPlanJSON, SubscriptionsStatus } from "../types/Subscriptions"; | ||
import { SubscriptionsPlanBuilderProps, SubscriptionsPlanJSON, SubscriptionsStatus, Taxes } from "../types/Subscriptions"; | ||
import ProductBuilder from "./ProductBuilder"; | ||
import BillingCycleBuilder from "./BillingCycleBuilder"; | ||
import PaymentPreferencesBuilder from "./PaymentPreferencesBuilder"; | ||
import { BillingCycleProps } from "../types/BillingCycle"; | ||
import { PaymentPreferencesProps } from "../types/PaymentPreferences"; | ||
import { ProductUpdateBuilder } from "./ProductUpdateBuilder"; | ||
import SubscriptionInlinePlanBuilder from "./SubscriptionInlinePlanBuilder"; | ||
export default class SubscriptionPlanBuilder extends SubscriptionInlinePlanBuilder { | ||
export default class SubscriptionPlanBuilder { | ||
private product_id?; | ||
private name?; | ||
private billing_cycles; | ||
private payment_preferences?; | ||
private status?; | ||
private description?; | ||
private quantity_supported?; | ||
private taxes?; | ||
constructor(data?: Partial<SubscriptionsPlanBuilderProps>); | ||
@@ -17,5 +23,9 @@ setProductId(product_id: string | ProductBuilder | ProductUpdateBuilder): SubscriptionPlanBuilder; | ||
setQuantitySupported(quantity_supported: boolean): SubscriptionPlanBuilder; | ||
setTaxes(taxes: Taxes): SubscriptionPlanBuilder; | ||
addBillingCycle(...billing_cycle: (BillingCycleBuilder | BillingCycleProps)[]): SubscriptionPlanBuilder; | ||
setBillingCycles(...billing_cycles: (BillingCycleBuilder | BillingCycleProps)[]): SubscriptionPlanBuilder; | ||
setPaymentPreferences(payment_preferences: PaymentPreferencesBuilder | PaymentPreferencesProps): SubscriptionPlanBuilder; | ||
create(): Promise<SubscriptionsPlanJSON>; | ||
toJSON(): Readonly<SubscriptionsPlanBuilderProps<'JSON'>>; | ||
protected validate(): void; | ||
private validate; | ||
} |
@@ -13,10 +13,11 @@ "use strict"; | ||
const ProductBuilder_1 = require("./ProductBuilder"); | ||
const BillingCycleBuilder_1 = require("./BillingCycleBuilder"); | ||
const PaymentPreferencesBuilder_1 = require("./PaymentPreferencesBuilder"); | ||
const Errors_1 = require("../Manager/Errors"); | ||
const ProductUpdateBuilder_1 = require("./ProductUpdateBuilder"); | ||
const Subscriptions_1 = require("../Functions/Subscriptions"); | ||
const SubscriptionInlinePlanBuilder_1 = require("./SubscriptionInlinePlanBuilder"); | ||
const ALLOWS_STATUS = ["ACTIVE", "INACTIVE", "CREATED"]; | ||
class SubscriptionPlanBuilder extends SubscriptionInlinePlanBuilder_1.default { | ||
class SubscriptionPlanBuilder { | ||
constructor(data) { | ||
super(data); | ||
var _a; | ||
if (data === null || data === void 0 ? void 0 : data.product_id) { | ||
@@ -26,5 +27,10 @@ this.product_id = (data.product_id instanceof ProductBuilder_1.default) || (data.product_id instanceof ProductUpdateBuilder_1.ProductUpdateBuilder) ? data.product_id.toJSON().id : data.product_id; | ||
this.name = data === null || data === void 0 ? void 0 : data.name; | ||
this.billing_cycles = ((_a = data === null || data === void 0 ? void 0 : data.billing_cycles) === null || _a === void 0 ? void 0 : _a.map(billingCycle => { | ||
return (billingCycle instanceof BillingCycleBuilder_1.default) ? billingCycle : new BillingCycleBuilder_1.default(billingCycle); | ||
})) || []; | ||
this.payment_preferences = ((data === null || data === void 0 ? void 0 : data.payment_preferences) instanceof PaymentPreferencesBuilder_1.default) ? data.payment_preferences : new PaymentPreferencesBuilder_1.default(data === null || data === void 0 ? void 0 : data.payment_preferences); | ||
this.status = data === null || data === void 0 ? void 0 : data.status; | ||
this.description = data === null || data === void 0 ? void 0 : data.description; | ||
this.quantity_supported = data === null || data === void 0 ? void 0 : data.quantity_supported; | ||
this.taxes = data === null || data === void 0 ? void 0 : data.taxes; | ||
} | ||
@@ -60,2 +66,26 @@ setProductId(product_id) { | ||
} | ||
setTaxes(taxes) { | ||
this.taxes = taxes; | ||
return this; | ||
} | ||
addBillingCycle(...billing_cycle) { | ||
if (billing_cycle.length + this.billing_cycles.length > 12) | ||
throw new Errors_1.default("Invalid billing_cycle the length must be less than 12."); | ||
this.billing_cycles.push(...billing_cycle.map(billingCycle => { | ||
return (billingCycle instanceof BillingCycleBuilder_1.default) ? billingCycle : new BillingCycleBuilder_1.default(billingCycle); | ||
})); | ||
return this; | ||
} | ||
setBillingCycles(...billing_cycles) { | ||
if (billing_cycles.length > 12) | ||
throw new Errors_1.default("Invalid billing_cycle the length must be less than 12."); | ||
this.billing_cycles = billing_cycles.map(billingCycle => { | ||
return (billingCycle instanceof BillingCycleBuilder_1.default) ? billingCycle : new BillingCycleBuilder_1.default(billingCycle); | ||
}); | ||
return this; | ||
} | ||
setPaymentPreferences(payment_preferences) { | ||
this.payment_preferences = (payment_preferences instanceof PaymentPreferencesBuilder_1.default) ? payment_preferences : new PaymentPreferencesBuilder_1.default(payment_preferences); | ||
return this; | ||
} | ||
create() { | ||
@@ -72,9 +102,9 @@ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () { | ||
status: this.status, | ||
billing_cycles: super.billing_cycles.map(billingCycle => { | ||
billing_cycles: this.billing_cycles.map(billingCycle => { | ||
return billingCycle.toJSON(); | ||
}), | ||
payment_preferences: super.payment_preferences.toJSON(), | ||
payment_preferences: this.payment_preferences.toJSON(), | ||
description: this.description, | ||
quantity_supported: this.quantity_supported, | ||
taxes: super.taxes | ||
taxes: this.taxes | ||
}; | ||
@@ -88,7 +118,12 @@ } | ||
throw new Errors_1.default("Invalid name the length must be between 1 and 127 characters."); | ||
super.validate(); | ||
if (!super.billing_cycles.length) | ||
if (!this.billing_cycles.length) | ||
throw new Errors_1.default("billing_cycle are required."); | ||
if (!super.payment_preferences) | ||
if (this.billing_cycles.length > 12) | ||
throw new Errors_1.default("Invalid billing_cycle the length must be less than 12."); | ||
if (!this.payment_preferences) | ||
throw new Errors_1.default("payment_preferences are required."); | ||
this.payment_preferences.toJSON(); | ||
this.billing_cycles.forEach(billingCycle => { | ||
billingCycle.toJSON(); | ||
}); | ||
if (this.status && !ALLOWS_STATUS.includes(this.status)) | ||
@@ -100,4 +135,8 @@ throw new Errors_1.default(`Invalid status the status must be one of the following: ${ALLOWS_STATUS.join(", ")}`); | ||
throw new Errors_1.default("Invalid quantity_supported the quantity_supported must be a boolean."); | ||
if (this.taxes) { | ||
if (!this.taxes.percentage || !/^((-?[0-9]+)|(-?([0-9]+)?[.][0-9]+))$/.test(this.taxes.percentage.toString())) | ||
throw new Errors_1.default("Invalid taxes.percentage the taxes.percentage must be a number."); | ||
} | ||
} | ||
} | ||
exports.default = SubscriptionPlanBuilder; |
@@ -17,3 +17,3 @@ import auth from './Functions/Auth'; | ||
import SubscriptionInlinePlanBuilder from './Builders/SubscriptionInlinePlanBuilder'; | ||
export { config, auth, PurchaseUnitBuilder, UnitBuilder, ItemsBuilder, ProductBuilder, CurrencyCodes, SubscriptionPlanBuilder, SubscriptionInlinePlanBuilder, BillingCycleBuilder, PaymentPreferencesBuilder, PricingSchemeBuilder, SubscriptionBuilder }; | ||
export { config, auth, PurchaseUnitBuilder, UnitBuilder, ItemsBuilder, ProductBuilder, CurrencyCodes, SubscriptionPlanBuilder, BillingCycleBuilder, PaymentPreferencesBuilder, PricingSchemeBuilder, SubscriptionBuilder, SubscriptionInlinePlanBuilder }; | ||
export declare const order: { | ||
@@ -20,0 +20,0 @@ create: typeof createOrder; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.subscriptions = exports.plan = exports.product = exports.order = exports.SubscriptionBuilder = exports.PricingSchemeBuilder = exports.PaymentPreferencesBuilder = exports.BillingCycleBuilder = exports.SubscriptionInlinePlanBuilder = exports.SubscriptionPlanBuilder = exports.CurrencyCodes = exports.ProductBuilder = exports.ItemsBuilder = exports.UnitBuilder = exports.PurchaseUnitBuilder = exports.auth = exports.config = void 0; | ||
exports.subscriptions = exports.plan = exports.product = exports.order = exports.SubscriptionInlinePlanBuilder = exports.SubscriptionBuilder = exports.PricingSchemeBuilder = exports.PaymentPreferencesBuilder = exports.BillingCycleBuilder = exports.SubscriptionPlanBuilder = exports.CurrencyCodes = exports.ProductBuilder = exports.ItemsBuilder = exports.UnitBuilder = exports.PurchaseUnitBuilder = exports.auth = exports.config = void 0; | ||
const Auth_1 = require("./Functions/Auth"); | ||
@@ -5,0 +5,0 @@ exports.auth = Auth_1.default; |
@@ -6,5 +6,7 @@ import PricingSchemeBuilder from "../Builders/PricingSchemeBuilder"; | ||
export type BillingCycleTenureType = 'REGULAR' | 'TRIAL'; | ||
export interface BillingCycleProps<T extends 'Props' | 'JSON' = 'Props'> { | ||
export interface BillingCycleProps<T extends 'Props' | 'JSON' = 'Props'> extends InlineBillingCycleProps<T> { | ||
tenure_type: BillingCycleTenureType; | ||
frequency: T extends 'Props' ? (FrequencyBuilder | FrequencyBuilderProps) : FrequencyBuilderJSON; | ||
} | ||
export interface InlineBillingCycleProps<T extends 'Props' | 'JSON' = 'Props'> { | ||
sequence: number; | ||
@@ -11,0 +13,0 @@ total_cycles?: number; |
import BillingCycleBuilder from "../Builders/BillingCycleBuilder"; | ||
import PaymentPreferencesBuilder from "../Builders/PaymentPreferencesBuilder"; | ||
import { PaymentPreferencesProps } from "./PaymentPreferences"; | ||
import { BillingCycleProps } from "./BillingCycle"; | ||
import { BillingCycleProps, InlineBillingCycleProps } from "./BillingCycle"; | ||
import ProductBuilder from "../Builders/ProductBuilder"; | ||
@@ -21,9 +21,10 @@ import { ProductUpdateBuilder } from "../Builders/ProductUpdateBuilder"; | ||
export interface SubscriptionsInlinePlanBuilderProps<T extends 'Props' | 'JSON' = 'Props'> { | ||
billing_cycles: T extends 'Props' ? (BillingCycleBuilder | BillingCycleProps)[] : (BillingCycleProps<T>)[]; | ||
payment_preferences: T extends 'Props' ? (PaymentPreferencesBuilder | PaymentPreferencesProps) : PaymentPreferencesProps<T>; | ||
payment_preferences?: T extends 'Props' ? (PaymentPreferencesBuilder | PaymentPreferencesProps) : PaymentPreferencesProps<T>; | ||
taxes?: T extends 'Props' ? Taxes : JSONTaxes; | ||
billing_cycles?: InlineBillingCycleProps<T>[]; | ||
} | ||
export interface SubscriptionsPlanBuilderProps<T extends 'Props' | 'JSON' = 'Props'> extends SubscriptionsInlinePlanBuilderProps<T> { | ||
export interface SubscriptionsPlanBuilderProps<T extends 'Props' | 'JSON' = 'Props'> extends Omit<SubscriptionsInlinePlanBuilderProps<T>, 'billing_cycles'> { | ||
product_id: T extends 'Props' ? string | ProductBuilder | ProductUpdateBuilder : string; | ||
name: string; | ||
billing_cycles: T extends 'Props' ? (BillingCycleBuilder | BillingCycleProps)[] : (BillingCycleProps<T>)[]; | ||
status?: SubscriptionsStatus; | ||
@@ -76,3 +77,3 @@ description?: string; | ||
application_context?: ApplicationContext; | ||
plan?: T extends 'Props' ? SubscriptionInlinePlanBuilder | SubscriptionsInlinePlanBuilderProps : Partial<SubscriptionsInlinePlanBuilderProps<'JSON'>>; | ||
plan?: T extends 'Props' ? (SubscriptionInlinePlanBuilder | SubscriptionsInlinePlanBuilderProps<T>) : SubscriptionsInlinePlanBuilderProps<T>; | ||
} |
{ | ||
"name": "paypal-rest", | ||
"version": "1.3.0-ALPHA", | ||
"version": "1.3.1-ALPHA", | ||
"description": "SDK for REST PayPal API", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
116705
2172