@efaj/pulumi-dynamic-stripe 0.0.1-4dd8c79

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Emmanuel Jimenez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/Makefile ADDED
@@ -0,0 +1,15 @@
1
+ .PHONY: all install build test clean
2
+
3
+ all: install build test
4
+
5
+ install:
6
+ npm install
7
+
8
+ build:
9
+ npm run build
10
+
11
+ test:
12
+ npm test
13
+
14
+ clean:
15
+ rm -rf dist node_modules package-lock.json
package/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # pulumi-dynamic-stripe
2
+
3
+ ![NPM Version](https://img.shields.io/npm/v/pulumi-dynamic-stripe)
4
+ ![License](https://img.shields.io/npm/l/pulumi-dynamic-stripe)
5
+ [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fefaj%2Fpulumi-dynamic-stripe.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fefaj%2Fpulumi-dynamic-stripe?ref=badge_shield)
6
+
7
+ A native Pulumi Dynamic Provider for Stripe.
8
+
9
+ ## Why this package?
10
+
11
+ The official `pulumi-stripe` package is a bridged Terraform provider that relies on an older version of the Stripe API. It lacks support for modern features, including Stripe Payment Links.
12
+
13
+ `pulumi-dynamic-stripe` solves this by natively wrapping the official Node.js `stripe` SDK using Pulumi's Dynamic Providers. Because it directly interfaces with the SDK, it can support any modern Stripe endpoint natively in TypeScript.
14
+
15
+ ## Features
16
+
17
+ This package provides native Pulumi resources for the following Stripe objects:
18
+ * **[Product](file:///media/efaj/data/workspace/pulumi-dynamic-stripe/src/index.ts#L57):** Represents a product you sell in Stripe.
19
+ * **[Price](file:///media/efaj/data/workspace/pulumi-dynamic-stripe/src/index.ts#L106):** Represents a price attached to a Product.
20
+ * **[PaymentLink](file:///media/efaj/data/workspace/pulumi-dynamic-stripe/src/index.ts#L48):** Represents a shareable URL that allows customers to purchase a Price.
21
+
22
+ ## Known Gaps
23
+
24
+ Currently, this library is focused on the core billing and checkout flow and only implements the three resources listed above (`Product`, `Price`, `PaymentLink`). Other Stripe objects (like `Customer`, `Subscription`, `Invoice`, etc.) are not yet supported.
25
+
26
+ Contributions to add more dynamic providers for other Stripe resources are highly welcome!
27
+
28
+ ## Installation
29
+
30
+ ```bash
31
+ npm install pulumi-dynamic-stripe
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ Here is a full example of provisioning a Product, attaching a Price to it, and generating a Payment Link for it—all managed as Pulumi infrastructure.
37
+
38
+ ```typescript
39
+ import * as pulumi from "@pulumi/pulumi";
40
+ import { Product, Price, PaymentLink } from "pulumi-dynamic-stripe";
41
+
42
+ const config = new pulumi.Config();
43
+ const stripeApiKey = config.requireSecret("stripeApiKey");
44
+
45
+ // 1. Create a Product
46
+ const premiumProduct = new Product("premium-product", {
47
+ apiKey: stripeApiKey,
48
+ name: "Premium Subscription",
49
+ description: "Access to all premium features",
50
+ });
51
+
52
+ // 2. Create a Price for the Product
53
+ const premiumPrice = new Price("premium-price", {
54
+ apiKey: stripeApiKey,
55
+ productId: premiumProduct.productId,
56
+ unitAmount: 2000, // $20.00
57
+ currency: "usd",
58
+ });
59
+
60
+ // 3. Generate a Payment Link for the Price
61
+ const premiumPaymentLink = new PaymentLink("premium-link", {
62
+ apiKey: stripeApiKey,
63
+ priceId: premiumPrice.priceId,
64
+ sparksAmount: "1000",
65
+ });
66
+
67
+ // Export the generated URL so it can be used in your application
68
+ export const paymentUrl = premiumPaymentLink.url;
69
+ ```
70
+
71
+ ## How it works
72
+
73
+ Behind the scenes, this library defines custom Pulumi Dynamic Resource Providers that implement the CRUD operations for Stripe entities via the `@pulumi/pulumi` and `stripe` Node packages.
@@ -0,0 +1,27 @@
1
+ import * as pulumi from "@pulumi/pulumi";
2
+ export interface StripePaymentLinkArgs {
3
+ apiKey: pulumi.Input<string>;
4
+ priceId: pulumi.Input<string>;
5
+ sparksAmount: pulumi.Input<string>;
6
+ redirectUrl: pulumi.Input<string>;
7
+ allowPromotionCodes?: pulumi.Input<boolean>;
8
+ managedPayments?: pulumi.Input<boolean>;
9
+ }
10
+ export interface StripePaymentLinkProviderArgs {
11
+ apiKey: string;
12
+ priceId: string;
13
+ sparksAmount: string;
14
+ redirectUrl: string;
15
+ allowPromotionCodes?: boolean;
16
+ managedPayments?: boolean;
17
+ }
18
+ export declare class StripePaymentLinkProvider implements pulumi.dynamic.ResourceProvider {
19
+ create(inputs: StripePaymentLinkProviderArgs): Promise<pulumi.dynamic.CreateResult>;
20
+ diff(id: string, olds: StripePaymentLinkProviderArgs, news: StripePaymentLinkProviderArgs): Promise<pulumi.dynamic.DiffResult>;
21
+ delete(id: string, props: StripePaymentLinkProviderArgs): Promise<void>;
22
+ }
23
+ export declare class PaymentLink extends pulumi.dynamic.Resource {
24
+ readonly url: pulumi.Output<string>;
25
+ readonly paymentLinkId: pulumi.Output<string>;
26
+ constructor(name: string, args: StripePaymentLinkArgs, opts?: pulumi.CustomResourceOptions);
27
+ }
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.PaymentLink = exports.StripePaymentLinkProvider = void 0;
40
+ const pulumi = __importStar(require("@pulumi/pulumi"));
41
+ const stripe_1 = __importDefault(require("stripe"));
42
+ class StripePaymentLinkProvider {
43
+ async create(inputs) {
44
+ const stripe = new stripe_1.default(inputs.apiKey, { apiVersion: '2022-11-15' });
45
+ const paymentLink = await stripe.paymentLinks.create({
46
+ line_items: [{
47
+ price: inputs.priceId,
48
+ quantity: 1,
49
+ adjustable_quantity: {
50
+ enabled: true,
51
+ minimum: 1,
52
+ maximum: 100,
53
+ },
54
+ }],
55
+ after_completion: {
56
+ type: 'redirect',
57
+ redirect: {
58
+ url: inputs.redirectUrl,
59
+ }
60
+ },
61
+ allow_promotion_codes: inputs.allowPromotionCodes,
62
+ ...(inputs.managedPayments ? { managed_payments: { enabled: true } } : {}),
63
+ metadata: {
64
+ sparks: inputs.sparksAmount
65
+ }
66
+ });
67
+ return {
68
+ id: paymentLink.id,
69
+ outs: {
70
+ ...inputs,
71
+ paymentLinkId: paymentLink.id,
72
+ url: paymentLink.url,
73
+ }
74
+ };
75
+ }
76
+ async diff(id, olds, news) {
77
+ const replaces = [];
78
+ if (olds.priceId !== news.priceId)
79
+ replaces.push("priceId");
80
+ if (olds.sparksAmount !== news.sparksAmount)
81
+ replaces.push("sparksAmount");
82
+ if (olds.redirectUrl !== news.redirectUrl)
83
+ replaces.push("redirectUrl");
84
+ if (olds.allowPromotionCodes !== news.allowPromotionCodes)
85
+ replaces.push("allowPromotionCodes");
86
+ if (olds.managedPayments !== news.managedPayments)
87
+ replaces.push("managedPayments");
88
+ if (olds.apiKey !== news.apiKey)
89
+ replaces.push("apiKey");
90
+ return {
91
+ changes: replaces.length > 0,
92
+ replaces,
93
+ };
94
+ }
95
+ async delete(id, props) {
96
+ const stripe = new stripe_1.default(props.apiKey, { apiVersion: '2022-11-15' });
97
+ await stripe.paymentLinks.update(id, { active: false });
98
+ }
99
+ }
100
+ exports.StripePaymentLinkProvider = StripePaymentLinkProvider;
101
+ const stripePaymentLinkProvider = new StripePaymentLinkProvider();
102
+ class PaymentLink extends pulumi.dynamic.Resource {
103
+ constructor(name, args, opts) {
104
+ super(stripePaymentLinkProvider, name, {
105
+ apiKey: args.apiKey,
106
+ priceId: args.priceId,
107
+ sparksAmount: args.sparksAmount,
108
+ redirectUrl: args.redirectUrl,
109
+ allowPromotionCodes: args.allowPromotionCodes,
110
+ managedPayments: args.managedPayments,
111
+ paymentLinkId: undefined,
112
+ url: undefined,
113
+ }, opts);
114
+ }
115
+ }
116
+ exports.PaymentLink = PaymentLink;
@@ -0,0 +1,22 @@
1
+ import * as pulumi from "@pulumi/pulumi";
2
+ export interface StripePriceArgs {
3
+ apiKey: pulumi.Input<string>;
4
+ productId: pulumi.Input<string>;
5
+ unitAmount: pulumi.Input<number>;
6
+ currency: pulumi.Input<string>;
7
+ }
8
+ export interface StripePriceProviderArgs {
9
+ apiKey: string;
10
+ productId: string;
11
+ unitAmount: number;
12
+ currency: string;
13
+ }
14
+ export declare class StripePriceProvider implements pulumi.dynamic.ResourceProvider {
15
+ create(inputs: StripePriceProviderArgs): Promise<pulumi.dynamic.CreateResult>;
16
+ diff(id: string, olds: StripePriceProviderArgs, news: StripePriceProviderArgs): Promise<pulumi.dynamic.DiffResult>;
17
+ delete(id: string, props: StripePriceProviderArgs): Promise<void>;
18
+ }
19
+ export declare class Price extends pulumi.dynamic.Resource {
20
+ readonly priceId: pulumi.Output<string>;
21
+ constructor(name: string, args: StripePriceArgs, opts?: pulumi.CustomResourceOptions);
22
+ }
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.Price = exports.StripePriceProvider = void 0;
40
+ const pulumi = __importStar(require("@pulumi/pulumi"));
41
+ const stripe_1 = __importDefault(require("stripe"));
42
+ class StripePriceProvider {
43
+ async create(inputs) {
44
+ const stripe = new stripe_1.default(inputs.apiKey, { apiVersion: '2022-11-15' });
45
+ const price = await stripe.prices.create({
46
+ product: inputs.productId,
47
+ unit_amount: inputs.unitAmount,
48
+ currency: inputs.currency,
49
+ });
50
+ return {
51
+ id: price.id,
52
+ outs: {
53
+ ...inputs,
54
+ priceId: price.id,
55
+ }
56
+ };
57
+ }
58
+ async diff(id, olds, news) {
59
+ const replaces = [];
60
+ if (olds.productId !== news.productId)
61
+ replaces.push("productId");
62
+ if (olds.unitAmount !== news.unitAmount)
63
+ replaces.push("unitAmount");
64
+ if (olds.currency !== news.currency)
65
+ replaces.push("currency");
66
+ if (olds.apiKey !== news.apiKey)
67
+ replaces.push("apiKey");
68
+ return {
69
+ changes: replaces.length > 0,
70
+ replaces,
71
+ };
72
+ }
73
+ async delete(id, props) {
74
+ const stripe = new stripe_1.default(props.apiKey, { apiVersion: '2022-11-15' });
75
+ await stripe.prices.update(id, { active: false });
76
+ }
77
+ }
78
+ exports.StripePriceProvider = StripePriceProvider;
79
+ const stripePriceProvider = new StripePriceProvider();
80
+ class Price extends pulumi.dynamic.Resource {
81
+ constructor(name, args, opts) {
82
+ super(stripePriceProvider, name, { ...args, priceId: undefined }, opts);
83
+ }
84
+ }
85
+ exports.Price = Price;
@@ -0,0 +1,23 @@
1
+ import * as pulumi from "@pulumi/pulumi";
2
+ export interface StripeProductArgs {
3
+ apiKey: pulumi.Input<string>;
4
+ name: pulumi.Input<string>;
5
+ description?: pulumi.Input<string>;
6
+ taxCode?: pulumi.Input<string>;
7
+ }
8
+ export interface StripeProductProviderArgs {
9
+ apiKey: string;
10
+ name: string;
11
+ description?: string;
12
+ taxCode?: string;
13
+ }
14
+ export declare class StripeProductProvider implements pulumi.dynamic.ResourceProvider {
15
+ create(inputs: StripeProductProviderArgs): Promise<pulumi.dynamic.CreateResult>;
16
+ diff(id: string, olds: StripeProductProviderArgs, news: StripeProductProviderArgs): Promise<pulumi.dynamic.DiffResult>;
17
+ update(id: string, olds: StripeProductProviderArgs, news: StripeProductProviderArgs): Promise<pulumi.dynamic.UpdateResult>;
18
+ delete(id: string, props: StripeProductProviderArgs): Promise<void>;
19
+ }
20
+ export declare class Product extends pulumi.dynamic.Resource {
21
+ readonly productId: pulumi.Output<string>;
22
+ constructor(name: string, args: StripeProductArgs, opts?: pulumi.CustomResourceOptions);
23
+ }
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.Product = exports.StripeProductProvider = void 0;
40
+ const pulumi = __importStar(require("@pulumi/pulumi"));
41
+ const stripe_1 = __importDefault(require("stripe"));
42
+ class StripeProductProvider {
43
+ async create(inputs) {
44
+ const stripe = new stripe_1.default(inputs.apiKey, { apiVersion: '2022-11-15' });
45
+ const product = await stripe.products.create({
46
+ name: inputs.name,
47
+ description: inputs.description,
48
+ tax_code: inputs.taxCode,
49
+ });
50
+ return {
51
+ id: product.id,
52
+ outs: {
53
+ ...inputs,
54
+ productId: product.id,
55
+ }
56
+ };
57
+ }
58
+ async diff(id, olds, news) {
59
+ const changes = [];
60
+ if (olds.name !== news.name)
61
+ changes.push("name");
62
+ if (olds.description !== news.description)
63
+ changes.push("description");
64
+ if (olds.taxCode !== news.taxCode)
65
+ changes.push("taxCode");
66
+ if (olds.apiKey !== news.apiKey)
67
+ changes.push("apiKey");
68
+ return {
69
+ changes: changes.length > 0,
70
+ replaces: [], // None require replacement, all can be updated
71
+ };
72
+ }
73
+ async update(id, olds, news) {
74
+ const stripe = new stripe_1.default(news.apiKey, { apiVersion: '2022-11-15' });
75
+ await stripe.products.update(id, {
76
+ name: news.name,
77
+ description: news.description,
78
+ tax_code: news.taxCode,
79
+ });
80
+ return {
81
+ outs: {
82
+ ...news,
83
+ productId: id,
84
+ }
85
+ };
86
+ }
87
+ async delete(id, props) {
88
+ const stripe = new stripe_1.default(props.apiKey, { apiVersion: '2022-11-15' });
89
+ await stripe.products.update(id, { active: false });
90
+ }
91
+ }
92
+ exports.StripeProductProvider = StripeProductProvider;
93
+ const stripeProductProvider = new StripeProductProvider();
94
+ class Product extends pulumi.dynamic.Resource {
95
+ constructor(name, args, opts) {
96
+ super(stripeProductProvider, name, { ...args, productId: undefined }, opts);
97
+ }
98
+ }
99
+ exports.Product = Product;
@@ -0,0 +1,3 @@
1
+ export * from "./StripePaymentLink";
2
+ export * from "./StripeProduct";
3
+ export * from "./StripePrice";
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./StripePaymentLink"), exports);
18
+ __exportStar(require("./StripeProduct"), exports);
19
+ __exportStar(require("./StripePrice"), exports);
package/jest.config.js ADDED
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ preset: 'ts-jest',
3
+ testEnvironment: 'node',
4
+ testMatch: ['**/tests/**/*.test.ts'],
5
+ };
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@efaj/pulumi-dynamic-stripe",
3
+ "version": "0.0.1-4dd8c79",
4
+ "description": "A Pulumi Dynamic Provider for Stripe, supporting modern features like Payment Links.",
5
+ "keywords": [
6
+ "pulumi",
7
+ "stripe"
8
+ ],
9
+ "homepage": "https://github.com/efaj/pulumi-dynamic-stripe#readme",
10
+ "bugs": {
11
+ "url": "https://github.com/efaj/pulumi-dynamic-stripe/issues"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/efaj/pulumi-dynamic-stripe.git"
16
+ },
17
+ "license": "MIT",
18
+ "author": "Emmanuel Abarca Jimenez <efaj@crenet.games> (https://crenet.games/emmanuel)",
19
+ "type": "commonjs",
20
+ "main": "dist/index.js",
21
+ "types": "dist/index.d.ts",
22
+ "scripts": {
23
+ "build": "tsc",
24
+ "prepare": "tsc",
25
+ "test": "jest"
26
+ },
27
+ "dependencies": {
28
+ "@pulumi/pulumi": "^3.259.0",
29
+ "stripe": "^22.6.0"
30
+ },
31
+ "devDependencies": {
32
+ "@types/jest": "^30.0.0",
33
+ "@types/node": "^26.4.0",
34
+ "jest": "^30.4.2",
35
+ "ts-jest": "^29.4.12",
36
+ "typescript": "^6.0.3"
37
+ }
38
+ }
@@ -0,0 +1,322 @@
1
+ import { StripePaymentLinkProvider, StripeProductProvider, StripePriceProvider } from "../src/index";
2
+ import Stripe from "stripe";
3
+ import { describe, it, expect, jest, beforeEach } from '@jest/globals';
4
+
5
+ // Mock the Stripe SDK
6
+ jest.mock("stripe");
7
+
8
+ const MockedStripe = Stripe as jest.MockedClass<typeof Stripe>;
9
+
10
+ describe("Stripe Providers", () => {
11
+ let mockPaymentLinksCreate: jest.Mock<any>;
12
+ let mockPaymentLinksUpdate: jest.Mock<any>;
13
+ let mockProductsCreate: jest.Mock<any>;
14
+ let mockProductsUpdate: jest.Mock<any>;
15
+ let mockPricesCreate: jest.Mock<any>;
16
+ let mockPricesUpdate: jest.Mock<any>;
17
+
18
+ beforeEach(() => {
19
+ // Reset mocks before each test
20
+ jest.clearAllMocks();
21
+
22
+ mockPaymentLinksCreate = jest.fn<any>().mockResolvedValue({ id: "plink_123", url: "https://stripe.com/plink_123" } as any);
23
+ mockPaymentLinksUpdate = jest.fn<any>().mockResolvedValue({ id: "plink_123" } as any);
24
+
25
+ mockProductsCreate = jest.fn<any>().mockResolvedValue({ id: "prod_123" } as any);
26
+ mockProductsUpdate = jest.fn<any>().mockResolvedValue({ id: "prod_123" } as any);
27
+
28
+ mockPricesCreate = jest.fn<any>().mockResolvedValue({ id: "price_123" } as any);
29
+ mockPricesUpdate = jest.fn<any>().mockResolvedValue({ id: "price_123" } as any);
30
+
31
+ // Setup the mocked Stripe instance's internal resource objects
32
+ MockedStripe.mockImplementation(() => {
33
+ return {
34
+ paymentLinks: {
35
+ create: mockPaymentLinksCreate,
36
+ update: mockPaymentLinksUpdate,
37
+ },
38
+ products: {
39
+ create: mockProductsCreate,
40
+ update: mockProductsUpdate,
41
+ },
42
+ prices: {
43
+ create: mockPricesCreate,
44
+ update: mockPricesUpdate,
45
+ },
46
+ } as any;
47
+ });
48
+ });
49
+
50
+ describe("StripePaymentLinkProvider", () => {
51
+ const provider = new StripePaymentLinkProvider();
52
+
53
+ describe("create", () => {
54
+ const createCases = [
55
+ {
56
+ name: "all properties provided",
57
+ inputs: {
58
+ apiKey: "sk_test_123",
59
+ priceId: "price_abc",
60
+ sparksAmount: "100",
61
+ redirectUrl: "https://example.com/success",
62
+ allowPromotionCodes: true,
63
+ managedPayments: true,
64
+ },
65
+ expectedPayload: {
66
+ line_items: [{
67
+ price: "price_abc",
68
+ quantity: 1,
69
+ adjustable_quantity: { enabled: true, minimum: 1, maximum: 100 },
70
+ }],
71
+ after_completion: { type: 'redirect', redirect: { url: "https://example.com/success" } },
72
+ allow_promotion_codes: true,
73
+ managed_payments: { enabled: true },
74
+ metadata: { sparks: "100" }
75
+ }
76
+ },
77
+ {
78
+ name: "only required properties provided",
79
+ inputs: {
80
+ apiKey: "sk_test_123",
81
+ priceId: "price_abc",
82
+ sparksAmount: "50",
83
+ redirectUrl: "https://example.com/success",
84
+ },
85
+ expectedPayload: {
86
+ line_items: [{
87
+ price: "price_abc",
88
+ quantity: 1,
89
+ adjustable_quantity: { enabled: true, minimum: 1, maximum: 100 },
90
+ }],
91
+ after_completion: { type: 'redirect', redirect: { url: "https://example.com/success" } },
92
+ allow_promotion_codes: undefined,
93
+ metadata: { sparks: "50" }
94
+ }
95
+ }
96
+ ];
97
+
98
+ it.each(createCases)("should correctly map Pulumi inputs to Stripe API payload when $name", async ({ inputs, expectedPayload }) => {
99
+ const result = await provider.create(inputs as any);
100
+
101
+ expect(result.id).toBe("plink_123");
102
+ expect(result.outs?.paymentLinkId).toBe("plink_123");
103
+ expect(result.outs?.url).toBe("https://stripe.com/plink_123");
104
+
105
+ expect(MockedStripe).toHaveBeenCalledWith(inputs.apiKey, { apiVersion: '2022-11-15' as any });
106
+ expect(mockPaymentLinksCreate).toHaveBeenCalledWith(expectedPayload);
107
+ });
108
+ });
109
+
110
+ describe("diff", () => {
111
+ const diffCases = [
112
+ {
113
+ name: "all properties change",
114
+ olds: { priceId: "old", sparksAmount: "10", redirectUrl: "url1", allowPromotionCodes: false, managedPayments: false, apiKey: "old_key" },
115
+ news: { priceId: "new", sparksAmount: "20", redirectUrl: "url2", allowPromotionCodes: true, managedPayments: true, apiKey: "new_key" },
116
+ expectedChanges: true,
117
+ expectedReplaces: ["priceId", "sparksAmount", "redirectUrl", "allowPromotionCodes", "managedPayments", "apiKey"]
118
+ },
119
+ {
120
+ name: "some properties change",
121
+ olds: { priceId: "old", sparksAmount: "10", redirectUrl: "url1" },
122
+ news: { priceId: "old", sparksAmount: "20", redirectUrl: "url1" },
123
+ expectedChanges: true,
124
+ expectedReplaces: ["sparksAmount"]
125
+ },
126
+ {
127
+ name: "no properties change",
128
+ olds: { priceId: "same", sparksAmount: "10" },
129
+ news: { priceId: "same", sparksAmount: "10" },
130
+ expectedChanges: false,
131
+ expectedReplaces: []
132
+ }
133
+ ];
134
+
135
+ it.each(diffCases)("should correctly detect diff when $name", async ({ olds, news, expectedChanges, expectedReplaces }) => {
136
+ const diffResult = await provider.diff("plink_123", olds as any, news as any);
137
+ expect(diffResult.changes).toBe(expectedChanges);
138
+ expect(diffResult.replaces).toEqual(expect.arrayContaining(expectedReplaces));
139
+ expect(diffResult.replaces?.length).toBe(expectedReplaces.length);
140
+ });
141
+ });
142
+
143
+ describe("delete", () => {
144
+ it("should deactivate the payment link", async () => {
145
+ await provider.delete("plink_123", { apiKey: "sk_test_123" } as any);
146
+ expect(mockPaymentLinksUpdate).toHaveBeenCalledWith("plink_123", { active: false });
147
+ });
148
+ });
149
+ });
150
+
151
+ describe("StripeProductProvider", () => {
152
+ const provider = new StripeProductProvider();
153
+
154
+ describe("create", () => {
155
+ const createCases = [
156
+ {
157
+ name: "all properties provided",
158
+ inputs: {
159
+ apiKey: "sk_test_123",
160
+ name: "Full Product",
161
+ description: "A complete product",
162
+ taxCode: "txcd_123",
163
+ },
164
+ expectedPayload: {
165
+ name: "Full Product",
166
+ description: "A complete product",
167
+ tax_code: "txcd_123",
168
+ }
169
+ },
170
+ {
171
+ name: "only required properties provided",
172
+ inputs: {
173
+ apiKey: "sk_test_123",
174
+ name: "Minimal Product",
175
+ },
176
+ expectedPayload: {
177
+ name: "Minimal Product",
178
+ description: undefined,
179
+ tax_code: undefined,
180
+ }
181
+ }
182
+ ];
183
+
184
+ it.each(createCases)("should correctly create a product when $name", async ({ inputs, expectedPayload }) => {
185
+ const result = await provider.create(inputs as any);
186
+
187
+ expect(result.id).toBe("prod_123");
188
+ expect(result.outs?.productId).toBe("prod_123");
189
+
190
+ expect(MockedStripe).toHaveBeenCalledWith(inputs.apiKey, { apiVersion: '2022-11-15' as any });
191
+ expect(mockProductsCreate).toHaveBeenCalledWith(expectedPayload);
192
+ });
193
+ });
194
+
195
+ describe("diff", () => {
196
+ const diffCases = [
197
+ {
198
+ name: "all properties change",
199
+ olds: { name: "old name", description: "old desc", taxCode: "tx_1", apiKey: "old_key" },
200
+ news: { name: "new name", description: "new desc", taxCode: "tx_2", apiKey: "new_key" },
201
+ expectedChanges: true,
202
+ },
203
+ {
204
+ name: "some properties change",
205
+ olds: { name: "old name", description: "old desc" },
206
+ news: { name: "old name", description: "new desc" },
207
+ expectedChanges: true,
208
+ },
209
+ {
210
+ name: "no properties change",
211
+ olds: { name: "same name", description: "same desc" },
212
+ news: { name: "same name", description: "same desc" },
213
+ expectedChanges: false,
214
+ }
215
+ ];
216
+
217
+ it.each(diffCases)("should correctly detect diff when $name", async ({ olds, news, expectedChanges }) => {
218
+ const diffResult = await provider.diff("prod_123", olds as any, news as any);
219
+ expect(diffResult.changes).toBe(expectedChanges);
220
+ expect(diffResult.replaces).toHaveLength(0);
221
+ });
222
+ });
223
+
224
+ describe("update", () => {
225
+ it("should correctly update a product", async () => {
226
+ const result = await provider.update("prod_123",
227
+ { apiKey: "sk_test_123", name: "Old Name" } as any,
228
+ { apiKey: "sk_test_123", name: "New Name", description: "New Desc", taxCode: "txcd_999" } as any
229
+ );
230
+
231
+ expect(result.outs?.productId).toBe("prod_123");
232
+ expect(result.outs?.name).toBe("New Name");
233
+
234
+ expect(mockProductsUpdate).toHaveBeenCalledWith("prod_123", {
235
+ name: "New Name",
236
+ description: "New Desc",
237
+ tax_code: "txcd_999",
238
+ });
239
+ });
240
+ });
241
+
242
+ describe("delete", () => {
243
+ it("should deactivate the product on delete", async () => {
244
+ await provider.delete("prod_123", { apiKey: "sk_test_123" } as any);
245
+ expect(mockProductsUpdate).toHaveBeenCalledWith("prod_123", { active: false });
246
+ });
247
+ });
248
+ });
249
+
250
+ describe("StripePriceProvider", () => {
251
+ const provider = new StripePriceProvider();
252
+
253
+ describe("create", () => {
254
+ const createCases = [
255
+ {
256
+ name: "required properties provided",
257
+ inputs: {
258
+ apiKey: "sk_test_123",
259
+ productId: "prod_123",
260
+ unitAmount: 1000,
261
+ currency: "usd",
262
+ },
263
+ expectedPayload: {
264
+ product: "prod_123",
265
+ unit_amount: 1000,
266
+ currency: "usd",
267
+ }
268
+ }
269
+ ];
270
+
271
+ it.each(createCases)("should correctly create a price when $name", async ({ inputs, expectedPayload }) => {
272
+ const result = await provider.create(inputs as any);
273
+
274
+ expect(result.id).toBe("price_123");
275
+ expect(result.outs?.priceId).toBe("price_123");
276
+
277
+ expect(MockedStripe).toHaveBeenCalledWith(inputs.apiKey, { apiVersion: '2022-11-15' as any });
278
+ expect(mockPricesCreate).toHaveBeenCalledWith(expectedPayload);
279
+ });
280
+ });
281
+
282
+ describe("diff", () => {
283
+ const diffCases = [
284
+ {
285
+ name: "all properties change",
286
+ olds: { productId: "prod_1", unitAmount: 100, currency: "usd", apiKey: "old_key" },
287
+ news: { productId: "prod_2", unitAmount: 200, currency: "eur", apiKey: "new_key" },
288
+ expectedChanges: true,
289
+ expectedReplaces: ["productId", "unitAmount", "currency", "apiKey"]
290
+ },
291
+ {
292
+ name: "some properties change",
293
+ olds: { productId: "prod_1", unitAmount: 100, currency: "usd" },
294
+ news: { productId: "prod_1", unitAmount: 200, currency: "usd" },
295
+ expectedChanges: true,
296
+ expectedReplaces: ["unitAmount"]
297
+ },
298
+ {
299
+ name: "no properties change",
300
+ olds: { productId: "prod_1", unitAmount: 100, currency: "usd" },
301
+ news: { productId: "prod_1", unitAmount: 100, currency: "usd" },
302
+ expectedChanges: false,
303
+ expectedReplaces: []
304
+ }
305
+ ];
306
+
307
+ it.each(diffCases)("should correctly detect diff when $name", async ({ olds, news, expectedChanges, expectedReplaces }) => {
308
+ const diffResult = await provider.diff("price_123", olds as any, news as any);
309
+ expect(diffResult.changes).toBe(expectedChanges);
310
+ expect(diffResult.replaces).toEqual(expect.arrayContaining(expectedReplaces));
311
+ expect(diffResult.replaces?.length).toBe(expectedReplaces.length);
312
+ });
313
+ });
314
+
315
+ describe("delete", () => {
316
+ it("should deactivate the price on delete", async () => {
317
+ await provider.delete("price_123", { apiKey: "sk_test_123" } as any);
318
+ expect(mockPricesUpdate).toHaveBeenCalledWith("price_123", { active: false });
319
+ });
320
+ });
321
+ });
322
+ });