@appweaver/stripe 0.0.0-stage → 3.1.0
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 +21 -0
- package/README.md +104 -2
- package/index.d.ts +1 -0
- package/index.js +17 -0
- package/module.d.ts +3 -0
- package/module.js +50 -0
- package/package.json +57 -3
- package/stripe-gateway.d.ts +42 -0
- package/stripe-gateway.js +710 -0
- package/tsconfig.build.tsbuildinfo +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Luka Matosevic
|
|
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/README.md
CHANGED
|
@@ -1,3 +1,105 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://appweaver.co" target="_blank"><img src="https://raw.githubusercontent.com/lmatosevic/appweaver/refs/heads/main/resources/appweaver-logo.svg" width="460" alt="Appweaver Logo" /></a>
|
|
3
|
+
</p>
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
<p align="center">
|
|
6
|
+
The Stripe payment gateway of Appweaver, the AI-first <a href="https://nodejs.org" target="_blank">Node.js</a> framework for backends built with agents.
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://www.npmjs.com/package/@appweaver/stripe" target="_blank"><img src="https://img.shields.io/npm/v/@appweaver/stripe.svg" alt="NPM Version" /></a>
|
|
11
|
+
<a href="https://github.com/lmatosevic/appweaver/blob/main/LICENSE" target="_blank"><img src="https://img.shields.io/npm/l/@appweaver/stripe.svg" alt="Package License" /></a>
|
|
12
|
+
<a href="https://www.npmjs.com/package/@appweaver/stripe" target="_blank"><img src="https://img.shields.io/npm/dw/@appweaver/stripe.svg" alt="NPM Downloads" /></a>
|
|
13
|
+
<a href="https://github.com/lmatosevic/appweaver/actions/workflows/ci.yml?query=branch%3Amain" target="_blank"><img src="https://img.shields.io/github/actions/workflow/status/lmatosevic/appweaver/ci.yml?branch=main&label=CI" alt="CI Status" /></a>
|
|
14
|
+
<a href="https://codecov.io/gh/lmatosevic/appweaver" target="_blank"><img src="https://codecov.io/gh/lmatosevic/appweaver/graph/badge.svg" alt="Test Coverage" /></a>
|
|
15
|
+
<a href="https://nodejs.org" target="_blank"><img src="https://img.shields.io/node/v/@appweaver/stripe.svg" alt="Node Version" /></a>
|
|
16
|
+
</p>
|
|
17
|
+
|
|
18
|
+
## Description
|
|
19
|
+
|
|
20
|
+
`@appweaver/stripe` is the Stripe driver of the payments of [Appweaver](https://github.com/lmatosevic/appweaver), a
|
|
21
|
+
module enabled by installing it (it requires `@appweaver/payments`), which provides the `stripe` `PaymentGateway`
|
|
22
|
+
provider on the official [Stripe SDK](https://www.npmjs.com/package/stripe):
|
|
23
|
+
|
|
24
|
+
- PaymentIntents confirmed by Stripe.js (cards, wallets, 3D Secure) or charged to a saved payment method, with manual
|
|
25
|
+
captures, cancellations and refunds
|
|
26
|
+
- Checkout Sessions for one-time payments and subscriptions, expired when their payment is canceled
|
|
27
|
+
- SetupIntents saving a payment method, and the default payment method of a customer
|
|
28
|
+
- Billing subscriptions, their invoices, the recurring prices read into the plans, and the customer portal
|
|
29
|
+
- the signed webhooks, verified with the signing secret of their endpoint
|
|
30
|
+
|
|
31
|
+
Every write carries the idempotency key of its record, and the errors of Stripe are thrown as the `PaymentError` of
|
|
32
|
+
the payments: `PAYMENT_DECLINED` for a refused card, `PAYMENT_REQUEST_INVALID` for a rejected request,
|
|
33
|
+
`PAYMENT_GATEWAY_UNAVAILABLE` for a rate limit, a broken connection or a server error.
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
npm install @appweaver/payments @appweaver/stripe
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
or `weaver module add payments` in a project created with `@appweaver/create`.
|
|
42
|
+
|
|
43
|
+
A Stripe account is a gateway of the `payments.gateways` config whose driver is `stripe`, the default driver of a
|
|
44
|
+
gateway named `stripe`:
|
|
45
|
+
|
|
46
|
+
```json
|
|
47
|
+
{
|
|
48
|
+
"payments": {
|
|
49
|
+
"gateways": {
|
|
50
|
+
"stripe": {
|
|
51
|
+
"secretKey": "sk_live_...",
|
|
52
|
+
"publicKey": "pk_live_...",
|
|
53
|
+
"webhookSecret": "whsec_..."
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
or `PAYMENTS_GATEWAYS_STRIPE_SECRET_KEY`, `PAYMENTS_GATEWAYS_STRIPE_PUBLIC_KEY` and
|
|
61
|
+
`PAYMENTS_GATEWAYS_STRIPE_WEBHOOK_SECRET`. Several accounts are several gateways, each with `"driver": "stripe"` and
|
|
62
|
+
the `countries` or `currencies` whose payments it takes. `apiVersion` pins the version of the Stripe API (the one of
|
|
63
|
+
the SDK by default) and `apiUrl` calls another host, i.e. `stripe-mock`.
|
|
64
|
+
|
|
65
|
+
In the Stripe dashboard, add a webhook endpoint at `https://<host>/payments/webhooks/<gateway>`
|
|
66
|
+
(`/payments/webhooks/stripe` above) with the `payment_intent.*`, `refund.*`, `charge.dispute.*`, `payment_method.*`,
|
|
67
|
+
`customer.subscription.*`, `invoice.*`, `checkout.session.*` and `customer.deleted` events, and set its signing secret
|
|
68
|
+
as the `webhookSecret` of the gateway. Locally, `stripe listen --forward-to localhost:5000/payments/webhooks/stripe`
|
|
69
|
+
prints the secret to use.
|
|
70
|
+
|
|
71
|
+
## Usage
|
|
72
|
+
|
|
73
|
+
The payments are taken with `PaymentsService` and `SubscriptionsService` of `@appweaver/payments`; the client confirms
|
|
74
|
+
a payment with Stripe.js, the `clientSecret` and the `publicKey` of its `nextAction`:
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
const { payment, nextAction } = await inject(PaymentsService).createPayment({
|
|
78
|
+
amount: 1999,
|
|
79
|
+
currency: 'EUR',
|
|
80
|
+
userId: user.id,
|
|
81
|
+
email: user.email
|
|
82
|
+
});
|
|
83
|
+
// Client: stripe.confirmPayment({ elements, clientSecret: nextAction.clientSecret, ... })
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
The plans are the recurring prices of the account, their `lookup_key` the key of the plan
|
|
87
|
+
(`weaver run payments-sync-plans`). For a call the gateway does not wrap, its `client` is the client of the SDK:
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
import { StripeGateway } from '@appweaver/stripe';
|
|
91
|
+
|
|
92
|
+
const gateway = (await inject(PaymentsService).gateway(
|
|
93
|
+
'stripe'
|
|
94
|
+
)) as StripeGateway;
|
|
95
|
+
const balance = await gateway.client.balance.retrieve();
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Documentation
|
|
99
|
+
|
|
100
|
+
- [Appweaver README](https://github.com/lmatosevic/appweaver#readme) – getting started, configuration, and the overview of every package
|
|
101
|
+
- [Agent skill](https://github.com/lmatosevic/appweaver/blob/main/skill/SKILL.md) – the complete framework reference shipped to every scaffolded project
|
|
102
|
+
|
|
103
|
+
## License
|
|
104
|
+
|
|
105
|
+
Appweaver is [MIT licensed](LICENSE).
|
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './stripe-gateway';
|
package/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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("./stripe-gateway"), exports);
|
package/module.d.ts
ADDED
package/module.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const common_1 = require("@appweaver/common");
|
|
37
|
+
const payments_1 = require("@appweaver/payments");
|
|
38
|
+
/** The `stripe` driver of the payment gateways, on the official Stripe SDK. */
|
|
39
|
+
exports.default = (0, common_1.defineModule)({
|
|
40
|
+
name: '@appweaver/stripe',
|
|
41
|
+
requires: ['@appweaver/payments'],
|
|
42
|
+
loggers: ['payments'],
|
|
43
|
+
providers: [
|
|
44
|
+
{
|
|
45
|
+
contract: payments_1.PaymentGateway,
|
|
46
|
+
name: 'stripe',
|
|
47
|
+
load: () => Promise.resolve().then(() => __importStar(require('./stripe-gateway')))
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,60 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appweaver/stripe",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "3.1.0",
|
|
4
|
+
"description": "Appweaver - the backend framework for AI-first development (@stripe)",
|
|
5
|
+
"author": "Luka Matosevic",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "./index.js",
|
|
8
|
+
"types": "./index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./index.d.ts",
|
|
12
|
+
"default": "./index.js"
|
|
13
|
+
},
|
|
14
|
+
"./package.json": "./package.json"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"appweaver",
|
|
18
|
+
"appweaver-module",
|
|
19
|
+
"payments",
|
|
20
|
+
"stripe",
|
|
21
|
+
"payment-gateway",
|
|
22
|
+
"subscriptions",
|
|
23
|
+
"checkout",
|
|
24
|
+
"webhooks"
|
|
25
|
+
],
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "https://github.com/lmatosevic/appweaver.git",
|
|
29
|
+
"directory": "packages/stripe"
|
|
30
|
+
},
|
|
31
|
+
"maintainers": [
|
|
32
|
+
{
|
|
33
|
+
"name": "Luka Matosevic",
|
|
34
|
+
"email": "lukamatosevic5@gmail.com",
|
|
35
|
+
"web": "https://lukamatosevic.com"
|
|
36
|
+
}
|
|
37
|
+
],
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">= 24.7"
|
|
43
|
+
},
|
|
44
|
+
"appweaver": {
|
|
45
|
+
"module": "./module.js"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"stripe": "23.2.0"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"@appweaver/common": "^3.1.0",
|
|
52
|
+
"@appweaver/core": "^3.1.0",
|
|
53
|
+
"@appweaver/payments": "^3.1.0"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@appweaver/common": "^2.8.0",
|
|
57
|
+
"@appweaver/core": "^2.8.0",
|
|
58
|
+
"@appweaver/payments": "^2.8.0"
|
|
59
|
+
}
|
|
6
60
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import Stripe from 'stripe';
|
|
2
|
+
import { HealthCheckResult } from '@appweaver/common';
|
|
3
|
+
import { GatewayCheckout, GatewayCheckoutInput, GatewayConfig, GatewayCustomer, GatewayCustomerInput, GatewayEvent, GatewayInvoice, GatewayPayment, GatewayPaymentInput, GatewayPaymentMethod, GatewayPrice, GatewayRefund, GatewayRefundInput, GatewaySetup, GatewaySubscription, GatewaySubscriptionInput, GatewaySubscriptionUpdate, PaymentCapability, PaymentGateway, WebhookHeaders } from '@appweaver/payments';
|
|
4
|
+
/**
|
|
5
|
+
* The gateway of a Stripe account, on the official Stripe SDK: PaymentIntents confirmed by Stripe.js or charged to a
|
|
6
|
+
* saved payment method, Checkout Sessions, SetupIntents, refunds, Billing subscriptions and invoices, the customer
|
|
7
|
+
* portal, and the signed webhooks. A gateway of the `payments.gateways` config with the `stripe` driver, i.e.
|
|
8
|
+
* `{ "stripe": { "secretKey": "sk_...", "webhookSecret": "whsec_...", "publicKey": "pk_..." } }`; several accounts
|
|
9
|
+
* are several gateways, each with its `driver: 'stripe'`.
|
|
10
|
+
*/
|
|
11
|
+
export declare class StripeGateway extends PaymentGateway {
|
|
12
|
+
readonly capabilities: readonly PaymentCapability[];
|
|
13
|
+
/** The client of the Stripe SDK, for the calls the gateway does not wrap. */
|
|
14
|
+
readonly client: Stripe;
|
|
15
|
+
constructor(config: GatewayConfig);
|
|
16
|
+
createCustomer(input: GatewayCustomerInput): Promise<GatewayCustomer>;
|
|
17
|
+
updateCustomer(customerId: string, input: GatewayCustomerInput): Promise<GatewayCustomer>;
|
|
18
|
+
deleteCustomer(customerId: string): Promise<void>;
|
|
19
|
+
createPayment(input: GatewayPaymentInput): Promise<GatewayPayment>;
|
|
20
|
+
getPayment(paymentId: string): Promise<GatewayPayment>;
|
|
21
|
+
capturePayment(paymentId: string, amount?: number, idempotencyKey?: string): Promise<GatewayPayment>;
|
|
22
|
+
cancelPayment(paymentId: string): Promise<GatewayPayment>;
|
|
23
|
+
refundPayment(input: GatewayRefundInput): Promise<GatewayRefund>;
|
|
24
|
+
createCheckout(input: GatewayCheckoutInput): Promise<GatewayCheckout>;
|
|
25
|
+
getCheckout(checkoutId: string): Promise<GatewayCheckout>;
|
|
26
|
+
expireCheckout(checkoutId: string): Promise<GatewayCheckout>;
|
|
27
|
+
createSetup(customerId: string, idempotencyKey?: string): Promise<GatewaySetup>;
|
|
28
|
+
listPaymentMethods(customerId: string): Promise<GatewayPaymentMethod[]>;
|
|
29
|
+
detachPaymentMethod(paymentMethodId: string): Promise<void>;
|
|
30
|
+
setDefaultPaymentMethod(customerId: string, paymentMethodId: string): Promise<void>;
|
|
31
|
+
createSubscription(input: GatewaySubscriptionInput): Promise<GatewaySubscription>;
|
|
32
|
+
getSubscription(subscriptionId: string): Promise<GatewaySubscription>;
|
|
33
|
+
updateSubscription(subscriptionId: string, update: GatewaySubscriptionUpdate): Promise<GatewaySubscription>;
|
|
34
|
+
cancelSubscription(subscriptionId: string): Promise<GatewaySubscription>;
|
|
35
|
+
getInvoice(invoiceId: string): Promise<GatewayInvoice>;
|
|
36
|
+
listPrices(): Promise<GatewayPrice[]>;
|
|
37
|
+
createPortalSession(customerId: string, returnUrl: string): Promise<{
|
|
38
|
+
url: string;
|
|
39
|
+
}>;
|
|
40
|
+
verifyWebhook(body: Buffer, headers: WebhookHeaders, tolerance: number): Promise<GatewayEvent>;
|
|
41
|
+
checkHealth(): Promise<HealthCheckResult>;
|
|
42
|
+
}
|