@vendure/payments-plugin 1.4.7 → 1.5.2
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/README.md +3 -0
- package/package/braintree/types.d.ts +2 -1
- package/package/braintree/types.js +1 -0
- package/package/braintree/types.js.map +1 -1
- package/package/mollie/graphql/generated-shop-types.d.ts +2894 -0
- package/package/mollie/graphql/generated-shop-types.js +952 -0
- package/package/mollie/graphql/generated-shop-types.js.map +1 -0
- package/package/mollie/mollie-shop-schema.d.ts +1 -0
- package/package/mollie/mollie-shop-schema.js +21 -0
- package/package/mollie/mollie-shop-schema.js.map +1 -0
- package/package/mollie/mollie.controller.d.ts +3 -7
- package/package/mollie/mollie.controller.js +11 -61
- package/package/mollie/mollie.controller.js.map +1 -1
- package/package/mollie/mollie.handler.d.ts +4 -0
- package/package/mollie/mollie.handler.js +18 -51
- package/package/mollie/mollie.handler.js.map +1 -1
- package/package/mollie/mollie.plugin.d.ts +13 -19
- package/package/mollie/mollie.plugin.js +24 -20
- package/package/mollie/mollie.plugin.js.map +1 -1
- package/package/mollie/mollie.resolver.d.ts +11 -0
- package/package/mollie/mollie.resolver.js +56 -0
- package/package/mollie/mollie.resolver.js.map +1 -0
- package/package/mollie/mollie.service.d.ts +27 -0
- package/package/mollie/mollie.service.js +189 -0
- package/package/mollie/mollie.service.js.map +1 -0
- package/package/stripe/constants.d.ts +2 -0
- package/package/stripe/constants.js +6 -0
- package/package/stripe/constants.js.map +1 -0
- package/package/stripe/index.d.ts +2 -0
- package/package/stripe/index.js +15 -0
- package/package/stripe/index.js.map +1 -0
- package/package/stripe/raw-body.middleware.d.ts +6 -0
- package/package/stripe/raw-body.middleware.js +17 -0
- package/package/stripe/raw-body.middleware.js.map +1 -0
- package/package/stripe/stripe.controller.d.ts +14 -0
- package/package/stripe/stripe.controller.js +127 -0
- package/package/stripe/stripe.controller.js.map +1 -0
- package/package/stripe/stripe.handler.d.ts +5 -0
- package/package/stripe/stripe.handler.js +72 -0
- package/package/stripe/stripe.handler.js.map +1 -0
- package/package/stripe/stripe.plugin.d.ts +80 -0
- package/package/stripe/stripe.plugin.js +140 -0
- package/package/stripe/stripe.plugin.js.map +1 -0
- package/package/stripe/stripe.resolver.d.ts +8 -0
- package/package/stripe/stripe.resolver.js +46 -0
- package/package/stripe/stripe.resolver.js.map +1 -0
- package/package/stripe/stripe.service.d.ts +19 -0
- package/package/stripe/stripe.service.js +114 -0
- package/package/stripe/stripe.service.js.map +1 -0
- package/package/stripe/types.d.ts +40 -0
- package/package/stripe/types.js +4 -0
- package/package/stripe/types.js.map +1 -0
- package/package.json +9 -7
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var StripePlugin_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.StripePlugin = void 0;
|
|
11
|
+
const core_1 = require("@vendure/core");
|
|
12
|
+
const graphql_tag_1 = require("graphql-tag");
|
|
13
|
+
const constants_1 = require("./constants");
|
|
14
|
+
const raw_body_middleware_1 = require("./raw-body.middleware");
|
|
15
|
+
const stripe_controller_1 = require("./stripe.controller");
|
|
16
|
+
const stripe_handler_1 = require("./stripe.handler");
|
|
17
|
+
const stripe_resolver_1 = require("./stripe.resolver");
|
|
18
|
+
const stripe_service_1 = require("./stripe.service");
|
|
19
|
+
/**
|
|
20
|
+
* @description
|
|
21
|
+
* Plugin to enable payments through [Stripe](https://stripe.com/docs) via the Payment Intents API.
|
|
22
|
+
*
|
|
23
|
+
* ## Requirements
|
|
24
|
+
*
|
|
25
|
+
* 1. You will need to create a Stripe account and get your secret key in the dashboard.
|
|
26
|
+
* 2. Create a webhook endpoint in the Stripe dashboard which listens to the `payment_intent.succeeded` and
|
|
27
|
+
* `payment_intent.payment_failed` events. The URL should be `https://my-shop.com/payments/stripe`, where
|
|
28
|
+
* `my-shop.com` is the host of your storefront application.
|
|
29
|
+
* 3. Get the signing secret for the newly created webhook.
|
|
30
|
+
* 4. Install the Payments plugin and the Stripe Node library:
|
|
31
|
+
*
|
|
32
|
+
* `yarn add \@vendure/payments-plugin stripe`
|
|
33
|
+
*
|
|
34
|
+
* or
|
|
35
|
+
*
|
|
36
|
+
* `npm install \@vendure/payments-plugin stripe`
|
|
37
|
+
*
|
|
38
|
+
* ## Setup
|
|
39
|
+
*
|
|
40
|
+
* 1. Add the plugin to your VendureConfig `plugins` array:
|
|
41
|
+
* ```TypeScript
|
|
42
|
+
* import { StripePlugin } from '\@vendure/payments-plugin/package/stripe';
|
|
43
|
+
*
|
|
44
|
+
* // ...
|
|
45
|
+
*
|
|
46
|
+
* plugins: [
|
|
47
|
+
* StripePlugin.init({
|
|
48
|
+
* apiKey: process.env.YOUR_STRIPE_SECRET_KEY,
|
|
49
|
+
* webhookSigningSecret: process.env.YOUR_STRIPE_WEBHOOK_SIGNING_SECRET,
|
|
50
|
+
* // This prevents different customers from using the same PaymentIntent
|
|
51
|
+
* storeCustomersInStripe: true,
|
|
52
|
+
* }),
|
|
53
|
+
* ]
|
|
54
|
+
* ````
|
|
55
|
+
* 2. Create a new PaymentMethod in the Admin UI, and select "Stripe payments" as the handler.
|
|
56
|
+
*
|
|
57
|
+
* ## Storefront usage
|
|
58
|
+
*
|
|
59
|
+
* The plugin is designed to work with the [Custom payment flow](https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=elements).
|
|
60
|
+
* In this flow, Stripe provides libraries which handle the payment UI and confirmation for you. You can install it in your storefront project
|
|
61
|
+
* with:
|
|
62
|
+
*
|
|
63
|
+
* ```shell
|
|
64
|
+
* yarn add \@stripe/stripe-js
|
|
65
|
+
* # or
|
|
66
|
+
* npm install \@stripe/stripe-js
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* If you are using React, you should also consider installing `@stripe/react-stripe-js`, which is a wrapper around Stripe Elements.
|
|
70
|
+
*
|
|
71
|
+
* The high-level workflow is:
|
|
72
|
+
* 1. Create a "payment intent" on the server by executing the `createStripePaymentIntent` mutation which is exposed by this plugin.
|
|
73
|
+
* 2. Use the returned client secret to instantiate the Stripe Payment Element.
|
|
74
|
+
* 3. Once the form is submitted and Stripe processes the payment, the webhook takes care of updating the order without additional action
|
|
75
|
+
* in the storefront.
|
|
76
|
+
*
|
|
77
|
+
* ## Local development
|
|
78
|
+
*
|
|
79
|
+
* Use something like [localtunnel](https://github.com/localtunnel/localtunnel) to test on localhost.
|
|
80
|
+
*
|
|
81
|
+
* ```bash
|
|
82
|
+
* npx localtunnel --port 3000 --subdomain my-shop-local-dev
|
|
83
|
+
* > your url is: https://my-shop-local-dev.loca.lt
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @docsCategory payments-plugin
|
|
87
|
+
* @docsPage StripePlugin
|
|
88
|
+
*/
|
|
89
|
+
let StripePlugin = StripePlugin_1 = class StripePlugin {
|
|
90
|
+
/**
|
|
91
|
+
* @description
|
|
92
|
+
* Initialize the Stripe payment plugin
|
|
93
|
+
*/
|
|
94
|
+
static init(options) {
|
|
95
|
+
this.options = options;
|
|
96
|
+
return StripePlugin_1;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
StripePlugin = StripePlugin_1 = __decorate([
|
|
100
|
+
core_1.VendurePlugin({
|
|
101
|
+
imports: [core_1.PluginCommonModule],
|
|
102
|
+
controllers: [stripe_controller_1.StripeController],
|
|
103
|
+
providers: [
|
|
104
|
+
{
|
|
105
|
+
provide: constants_1.STRIPE_PLUGIN_OPTIONS,
|
|
106
|
+
useFactory: () => StripePlugin_1.options,
|
|
107
|
+
},
|
|
108
|
+
stripe_service_1.StripeService,
|
|
109
|
+
],
|
|
110
|
+
configuration: config => {
|
|
111
|
+
config.paymentOptions.paymentMethodHandlers.push(stripe_handler_1.stripePaymentMethodHandler);
|
|
112
|
+
config.apiOptions.middleware.push({
|
|
113
|
+
route: '/payments/stripe',
|
|
114
|
+
handler: raw_body_middleware_1.rawBodyMiddleware,
|
|
115
|
+
beforeListen: true,
|
|
116
|
+
});
|
|
117
|
+
if (StripePlugin_1.options.storeCustomersInStripe) {
|
|
118
|
+
config.customFields.Customer.push({
|
|
119
|
+
name: 'stripeCustomerId',
|
|
120
|
+
type: 'string',
|
|
121
|
+
label: [{ languageCode: core_1.LanguageCode.en, value: 'Stripe Customer ID' }],
|
|
122
|
+
nullable: true,
|
|
123
|
+
public: false,
|
|
124
|
+
readonly: true,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return config;
|
|
128
|
+
},
|
|
129
|
+
shopApiExtensions: {
|
|
130
|
+
schema: graphql_tag_1.gql `
|
|
131
|
+
extend type Mutation {
|
|
132
|
+
createStripePaymentIntent: String
|
|
133
|
+
}
|
|
134
|
+
`,
|
|
135
|
+
resolvers: [stripe_resolver_1.StripeResolver],
|
|
136
|
+
},
|
|
137
|
+
})
|
|
138
|
+
], StripePlugin);
|
|
139
|
+
exports.StripePlugin = StripePlugin;
|
|
140
|
+
//# sourceMappingURL=stripe.plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripe.plugin.js","sourceRoot":"","sources":["../../src/stripe/stripe.plugin.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,wCAAsF;AACtF,6CAAkC;AAElC,2CAAoD;AACpD,+DAA0D;AAC1D,2DAAuD;AACvD,qDAA8D;AAC9D,uDAAmD;AACnD,qDAAiD;AAGjD;;;;;;;;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YACD,SAAS,EAAE,CAAC,gCAAc,CAAC;SAC9B;KACJ,CAAC;GACW,YAAY,CAWxB;AAXY,oCAAY"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ActiveOrderService, RequestContext } from '@vendure/core';
|
|
2
|
+
import { StripeService } from './stripe.service';
|
|
3
|
+
export declare class StripeResolver {
|
|
4
|
+
private stripeService;
|
|
5
|
+
private activeOrderService;
|
|
6
|
+
constructor(stripeService: StripeService, activeOrderService: ActiveOrderService);
|
|
7
|
+
createStripePaymentIntent(ctx: RequestContext): Promise<string | undefined>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.StripeResolver = void 0;
|
|
16
|
+
const graphql_1 = require("@nestjs/graphql");
|
|
17
|
+
const core_1 = require("@vendure/core");
|
|
18
|
+
const stripe_service_1 = require("./stripe.service");
|
|
19
|
+
let StripeResolver = class StripeResolver {
|
|
20
|
+
constructor(stripeService, activeOrderService) {
|
|
21
|
+
this.stripeService = stripeService;
|
|
22
|
+
this.activeOrderService = activeOrderService;
|
|
23
|
+
}
|
|
24
|
+
async createStripePaymentIntent(ctx) {
|
|
25
|
+
if (ctx.authorizedAsOwnerOnly) {
|
|
26
|
+
const sessionOrder = await this.activeOrderService.getOrderFromContext(ctx);
|
|
27
|
+
if (sessionOrder) {
|
|
28
|
+
return this.stripeService.createPaymentIntent(ctx, sessionOrder);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
__decorate([
|
|
34
|
+
graphql_1.Mutation(),
|
|
35
|
+
core_1.Allow(core_1.Permission.Owner),
|
|
36
|
+
__param(0, core_1.Ctx()),
|
|
37
|
+
__metadata("design:type", Function),
|
|
38
|
+
__metadata("design:paramtypes", [core_1.RequestContext]),
|
|
39
|
+
__metadata("design:returntype", Promise)
|
|
40
|
+
], StripeResolver.prototype, "createStripePaymentIntent", null);
|
|
41
|
+
StripeResolver = __decorate([
|
|
42
|
+
graphql_1.Resolver(),
|
|
43
|
+
__metadata("design:paramtypes", [stripe_service_1.StripeService, core_1.ActiveOrderService])
|
|
44
|
+
], StripeResolver);
|
|
45
|
+
exports.StripeResolver = StripeResolver;
|
|
46
|
+
//# sourceMappingURL=stripe.resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripe.resolver.js","sourceRoot":"","sources":["../../src/stripe/stripe.resolver.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6CAAqD;AACrD,wCAA2F;AAE3F,qDAAiD;AAGjD,IAAa,cAAc,GAA3B,MAAa,cAAc;IACvB,YAAoB,aAA4B,EAAU,kBAAsC;QAA5E,kBAAa,GAAb,aAAa,CAAe;QAAU,uBAAkB,GAAlB,kBAAkB,CAAoB;IAAG,CAAC;IAIpG,KAAK,CAAC,yBAAyB,CAAQ,GAAmB;QACtD,IAAI,GAAG,CAAC,qBAAqB,EAAE;YAC3B,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;YAC5E,IAAI,YAAY,EAAE;gBACd,OAAO,IAAI,CAAC,aAAa,CAAC,mBAAmB,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;aACpE;SACJ;IACL,CAAC;CACJ,CAAA;AARG;IAFC,kBAAQ,EAAE;IACV,YAAK,CAAC,iBAAU,CAAC,KAAK,CAAC;IACS,WAAA,UAAG,EAAE,CAAA;;qCAAM,qBAAc;;+DAOzD;AAZQ,cAAc;IAD1B,kBAAQ,EAAE;qCAE4B,8BAAa,EAA8B,yBAAkB;GADvF,cAAc,CAa1B;AAbY,wCAAc"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Order, RequestContext, TransactionalConnection } from '@vendure/core';
|
|
3
|
+
import Stripe from 'stripe';
|
|
4
|
+
import { StripePluginOptions } from './types';
|
|
5
|
+
export declare class StripeService {
|
|
6
|
+
private connection;
|
|
7
|
+
private options;
|
|
8
|
+
private stripe;
|
|
9
|
+
constructor(connection: TransactionalConnection, options: StripePluginOptions);
|
|
10
|
+
createPaymentIntent(ctx: RequestContext, order: Order): Promise<string | undefined>;
|
|
11
|
+
createRefund(paymentIntentId: string, amount: number): Promise<Stripe.Refund | Stripe.StripeError>;
|
|
12
|
+
constructEventFromPayload(payload: Buffer, signature: string): Stripe.Event;
|
|
13
|
+
/**
|
|
14
|
+
* Returns the stripeCustomerId if the Customer has one. If that's not the case, queries Stripe to check
|
|
15
|
+
* if the customer is already registered, in which case it saves the id as stripeCustomerId and returns it.
|
|
16
|
+
* Otherwise, creates a new Customer record in Stripe and returns the generated id.
|
|
17
|
+
*/
|
|
18
|
+
private getStripeCustomerId;
|
|
19
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.StripeService = void 0;
|
|
19
|
+
const common_1 = require("@nestjs/common");
|
|
20
|
+
const core_1 = require("@vendure/core");
|
|
21
|
+
const stripe_1 = __importDefault(require("stripe"));
|
|
22
|
+
const constants_1 = require("./constants");
|
|
23
|
+
let StripeService = class StripeService {
|
|
24
|
+
constructor(connection, options) {
|
|
25
|
+
this.connection = connection;
|
|
26
|
+
this.options = options;
|
|
27
|
+
this.stripe = new stripe_1.default(this.options.apiKey, {
|
|
28
|
+
apiVersion: '2020-08-27',
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async createPaymentIntent(ctx, order) {
|
|
32
|
+
let customerId;
|
|
33
|
+
if (this.options.storeCustomersInStripe && ctx.activeUserId) {
|
|
34
|
+
customerId = await this.getStripeCustomerId(ctx, order);
|
|
35
|
+
}
|
|
36
|
+
const { client_secret } = await this.stripe.paymentIntents.create({
|
|
37
|
+
amount: order.totalWithTax,
|
|
38
|
+
currency: order.currencyCode.toLowerCase(),
|
|
39
|
+
customer: customerId,
|
|
40
|
+
automatic_payment_methods: {
|
|
41
|
+
enabled: true,
|
|
42
|
+
},
|
|
43
|
+
metadata: {
|
|
44
|
+
channelToken: ctx.channel.token,
|
|
45
|
+
orderId: order.id,
|
|
46
|
+
orderCode: order.code,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
if (!client_secret) {
|
|
50
|
+
// This should never happen
|
|
51
|
+
core_1.Logger.warn(`Payment intent creation for order ${order.code} did not return client secret`, constants_1.loggerCtx);
|
|
52
|
+
}
|
|
53
|
+
return client_secret !== null && client_secret !== void 0 ? client_secret : undefined;
|
|
54
|
+
}
|
|
55
|
+
async createRefund(paymentIntentId, amount) {
|
|
56
|
+
// TODO: Consider passing the "reason" property once this feature request is addressed:
|
|
57
|
+
// https://github.com/vendure-ecommerce/vendure/issues/893
|
|
58
|
+
try {
|
|
59
|
+
const refund = await this.stripe.refunds.create({
|
|
60
|
+
payment_intent: paymentIntentId,
|
|
61
|
+
amount,
|
|
62
|
+
});
|
|
63
|
+
return refund;
|
|
64
|
+
}
|
|
65
|
+
catch (e) {
|
|
66
|
+
return e;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
constructEventFromPayload(payload, signature) {
|
|
70
|
+
return this.stripe.webhooks.constructEvent(payload, signature, this.options.webhookSigningSecret);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Returns the stripeCustomerId if the Customer has one. If that's not the case, queries Stripe to check
|
|
74
|
+
* if the customer is already registered, in which case it saves the id as stripeCustomerId and returns it.
|
|
75
|
+
* Otherwise, creates a new Customer record in Stripe and returns the generated id.
|
|
76
|
+
*/
|
|
77
|
+
async getStripeCustomerId(ctx, activeOrder) {
|
|
78
|
+
// Load relation with customer not available in the response from activeOrderService.getOrderFromContext()
|
|
79
|
+
const order = await this.connection.getRepository(core_1.Order).findOne(activeOrder.id, {
|
|
80
|
+
relations: ['customer'],
|
|
81
|
+
});
|
|
82
|
+
if (!order || !order.customer) {
|
|
83
|
+
// This should never happen
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
const { customer } = order;
|
|
87
|
+
if (customer.customFields.stripeCustomerId) {
|
|
88
|
+
return customer.customFields.stripeCustomerId;
|
|
89
|
+
}
|
|
90
|
+
let stripeCustomerId;
|
|
91
|
+
const stripeCustomers = await this.stripe.customers.list({ email: customer.emailAddress });
|
|
92
|
+
if (stripeCustomers.data.length > 0) {
|
|
93
|
+
stripeCustomerId = stripeCustomers.data[0].id;
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
const newStripeCustomer = await this.stripe.customers.create({
|
|
97
|
+
email: customer.emailAddress,
|
|
98
|
+
name: `${customer.firstName} ${customer.lastName}`,
|
|
99
|
+
});
|
|
100
|
+
stripeCustomerId = newStripeCustomer.id;
|
|
101
|
+
core_1.Logger.info(`Created Stripe Customer record for customerId ${customer.id}`, constants_1.loggerCtx);
|
|
102
|
+
}
|
|
103
|
+
customer.customFields.stripeCustomerId = stripeCustomerId;
|
|
104
|
+
await this.connection.getRepository(ctx, core_1.Customer).save(customer, { reload: false });
|
|
105
|
+
return stripeCustomerId;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
StripeService = __decorate([
|
|
109
|
+
common_1.Injectable(),
|
|
110
|
+
__param(1, common_1.Inject(constants_1.STRIPE_PLUGIN_OPTIONS)),
|
|
111
|
+
__metadata("design:paramtypes", [core_1.TransactionalConnection, Object])
|
|
112
|
+
], StripeService);
|
|
113
|
+
exports.StripeService = StripeService;
|
|
114
|
+
//# sourceMappingURL=stripe.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripe.service.js","sourceRoot":"","sources":["../../src/stripe/stripe.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,wCAAiG;AACjG,oDAA4B;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AC,CAAC,CAAC,EAAE,CAAC;SACjD;aAAM;YACH,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC;gBACzD,KAAK,EAAE,QAAQ,CAAC,YAAY;gBAC5B,IAAI,EAAE,GAAG,QAAQ,CAAC,SAAS,IAAI,QAAQ,CAAC,QAAQ,EAAE;aACrD,CAAC,CAAC;YAEH,gBAAgB,GAAG,iBAAiB,CAAC,EAAE,CAAC;YAExC,aAAM,CAAC,IAAI,CAAC,iDAAiD,QAAQ,CAAC,EAAE,EAAE,EAAE,qBAAS,CAAC,CAAC;SAC1F;QAED,QAAQ,CAAC,YAAY,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QAC1D,MAAM,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,GAAG,EAAE,eAAQ,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;QAErF,OAAO,gBAAgB,CAAC;IAC5B,CAAC;CACJ,CAAA;AA1GY,aAAa;IADzB,mBAAU,EAAE;IAMJ,WAAA,eAAM,CAAC,iCAAqB,CAAC,CAAA;qCADV,8BAAuB;GAJtC,aAAa,CA0GzB;AA1GY,sCAAa"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import '@vendure/core/dist/entity/custom-entity-fields';
|
|
3
|
+
import { IncomingMessage } from 'http';
|
|
4
|
+
declare module '@vendure/core/dist/entity/custom-entity-fields' {
|
|
5
|
+
interface CustomCustomerFields {
|
|
6
|
+
stripeCustomerId?: string;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* @description
|
|
11
|
+
* Configuration options for the Stripe payments plugin.
|
|
12
|
+
*
|
|
13
|
+
* @docsCategory payments-plugin
|
|
14
|
+
* @docsPage StripePlugin
|
|
15
|
+
*/
|
|
16
|
+
export interface StripePluginOptions {
|
|
17
|
+
/**
|
|
18
|
+
* @description
|
|
19
|
+
* Secret key of your Stripe account.
|
|
20
|
+
*/
|
|
21
|
+
apiKey: string;
|
|
22
|
+
/**
|
|
23
|
+
* @description
|
|
24
|
+
* Signing secret of your configured Stripe webhook.
|
|
25
|
+
*/
|
|
26
|
+
webhookSigningSecret: string;
|
|
27
|
+
/**
|
|
28
|
+
* @description
|
|
29
|
+
* If set to `true`, a [Customer](https://stripe.com/docs/api/customers) object will be created in Stripe - if
|
|
30
|
+
* it doesn't already exist - for authenticated users, which prevents payment methods attached to other Customers
|
|
31
|
+
* to be used with the same PaymentIntent. This is done by adding a custom field to the Customer entity to store
|
|
32
|
+
* the Stripe customer ID, so switching this on will require a database migration / synchronization.
|
|
33
|
+
*
|
|
34
|
+
* @default false
|
|
35
|
+
*/
|
|
36
|
+
storeCustomersInStripe?: boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface IncomingMessageWithRawBody extends IncomingMessage {
|
|
39
|
+
rawBody: Buffer;
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/stripe/types.ts"],"names":[],"mappings":";;AAAA,0DAAwD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vendure/payments-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "package/index.js",
|
|
6
6
|
"types": "package/index.d.ts",
|
|
@@ -22,18 +22,20 @@
|
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"@mollie/api-client": "3.x",
|
|
25
|
-
"braintree": "3.x"
|
|
25
|
+
"braintree": "3.x",
|
|
26
|
+
"stripe": "8.x"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
|
-
"@mollie/api-client": "^3.
|
|
29
|
+
"@mollie/api-client": "^3.6.0",
|
|
29
30
|
"@types/braintree": "^2.22.15",
|
|
30
|
-
"@vendure/common": "^1.
|
|
31
|
-
"@vendure/core": "^1.
|
|
32
|
-
"@vendure/testing": "^1.
|
|
31
|
+
"@vendure/common": "^1.5.2",
|
|
32
|
+
"@vendure/core": "^1.5.2",
|
|
33
|
+
"@vendure/testing": "^1.5.2",
|
|
33
34
|
"braintree": "^3.0.0",
|
|
34
35
|
"nock": "^13.1.4",
|
|
35
36
|
"rimraf": "^3.0.2",
|
|
37
|
+
"stripe": "^8.197.0",
|
|
36
38
|
"typescript": "4.3.5"
|
|
37
39
|
},
|
|
38
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "8b72fb60f2c190d42c727eb522941259d8e1a92f"
|
|
39
41
|
}
|