@vendure/payments-plugin 1.3.4 → 1.4.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/package/braintree/braintree-common.d.ts +2 -2
- package/package/braintree/braintree-common.js +2 -2
- package/package/braintree/braintree-common.js.map +1 -1
- package/package/braintree/braintree.handler.d.ts +28 -0
- package/package/braintree/braintree.handler.js +129 -0
- package/package/braintree/braintree.handler.js.map +1 -0
- package/package/braintree/braintree.plugin.d.ts +190 -0
- package/package/braintree/braintree.plugin.js +241 -0
- package/package/braintree/braintree.plugin.js.map +1 -0
- package/package/braintree/braintree.resolver.d.ts +4 -2
- package/package/braintree/braintree.resolver.js +14 -10
- package/package/braintree/braintree.resolver.js.map +1 -1
- package/package/braintree/constants.d.ts +1 -0
- package/package/braintree/constants.js +2 -1
- package/package/braintree/constants.js.map +1 -1
- package/package/braintree/index.d.ts +3 -2
- package/package/braintree/index.js +3 -2
- package/package/braintree/index.js.map +1 -1
- package/package/braintree/types.d.ts +33 -1
- package/package/index.d.ts +1 -1
- package/package/index.js +1 -1
- package/package/mollie/constants.d.ts +2 -0
- package/package/mollie/constants.js +6 -0
- package/package/mollie/constants.js.map +1 -0
- package/package/mollie/index.d.ts +2 -0
- package/package/mollie/index.js +15 -0
- package/package/mollie/index.js.map +1 -0
- package/package/mollie/mollie.controller.d.ts +10 -0
- package/package/mollie/mollie.controller.js +101 -0
- package/package/mollie/mollie.controller.js.map +1 -0
- package/package/mollie/mollie.handler.d.ts +18 -0
- package/package/mollie/mollie.handler.js +127 -0
- package/package/mollie/mollie.handler.js.map +1 -0
- package/package/mollie/mollie.plugin.d.ts +101 -0
- package/package/mollie/mollie.plugin.js +116 -0
- package/package/mollie/mollie.plugin.js.map +1 -0
- package/package.json +37 -29
- package/package/braintree/braintree-payment-method.d.ts +0 -15
- package/package/braintree/braintree-payment-method.js +0 -79
- package/package/braintree/braintree-payment-method.js.map +0 -1
- package/package/braintree/braintree-plugin.d.ts +0 -5
- package/package/braintree/braintree-plugin.js +0 -38
- package/package/braintree/braintree-plugin.js.map +0 -1
|
@@ -13,30 +13,32 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.BraintreeResolver = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
16
17
|
const graphql_1 = require("@nestjs/graphql");
|
|
17
18
|
const core_1 = require("@vendure/core");
|
|
18
19
|
const braintree_common_1 = require("./braintree-common");
|
|
19
|
-
const
|
|
20
|
+
const braintree_handler_1 = require("./braintree.handler");
|
|
20
21
|
const constants_1 = require("./constants");
|
|
21
22
|
let BraintreeResolver = class BraintreeResolver {
|
|
22
|
-
constructor(connection, orderService) {
|
|
23
|
+
constructor(connection, orderService, options) {
|
|
23
24
|
this.connection = connection;
|
|
24
25
|
this.orderService = orderService;
|
|
26
|
+
this.options = options;
|
|
25
27
|
}
|
|
26
28
|
async generateBraintreeClientToken(ctx, { orderId }) {
|
|
29
|
+
var _a;
|
|
27
30
|
const order = await this.orderService.findOne(ctx, orderId);
|
|
28
31
|
if (order && order.customer) {
|
|
29
|
-
const customerId = order.customer.
|
|
32
|
+
const customerId = (_a = order.customer.customFields.braintreeCustomerId) !== null && _a !== void 0 ? _a : undefined;
|
|
30
33
|
const args = await this.getPaymentMethodArgs(ctx);
|
|
31
|
-
const gateway = braintree_common_1.getGateway(args);
|
|
34
|
+
const gateway = braintree_common_1.getGateway(args, this.options);
|
|
32
35
|
try {
|
|
33
|
-
const result = await gateway.clientToken.generate({
|
|
34
|
-
customerId,
|
|
35
|
-
});
|
|
36
|
+
const result = await gateway.clientToken.generate({ customerId });
|
|
36
37
|
return result.clientToken;
|
|
37
38
|
}
|
|
38
39
|
catch (e) {
|
|
39
|
-
core_1.Logger.error(
|
|
40
|
+
core_1.Logger.error(`Could not generate Braintree clientToken. Check the configured credentials.`, constants_1.loggerCtx);
|
|
41
|
+
throw e;
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
44
|
else {
|
|
@@ -46,7 +48,7 @@ let BraintreeResolver = class BraintreeResolver {
|
|
|
46
48
|
async getPaymentMethodArgs(ctx) {
|
|
47
49
|
const method = await this.connection.getRepository(ctx, core_1.PaymentMethod).findOne({
|
|
48
50
|
where: {
|
|
49
|
-
code:
|
|
51
|
+
code: braintree_handler_1.braintreePaymentMethodHandler.code,
|
|
50
52
|
},
|
|
51
53
|
});
|
|
52
54
|
if (!method) {
|
|
@@ -67,7 +69,9 @@ __decorate([
|
|
|
67
69
|
], BraintreeResolver.prototype, "generateBraintreeClientToken", null);
|
|
68
70
|
BraintreeResolver = __decorate([
|
|
69
71
|
graphql_1.Resolver(),
|
|
70
|
-
|
|
72
|
+
__param(2, common_1.Inject(constants_1.BRAINTREE_PLUGIN_OPTIONS)),
|
|
73
|
+
__metadata("design:paramtypes", [core_1.TransactionalConnection,
|
|
74
|
+
core_1.OrderService, Object])
|
|
71
75
|
], BraintreeResolver);
|
|
72
76
|
exports.BraintreeResolver = BraintreeResolver;
|
|
73
77
|
//# sourceMappingURL=braintree.resolver.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"braintree.resolver.js","sourceRoot":"","sources":["../../src/braintree/braintree.resolver.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6CAAwD;AACxD,wCASuB;AAEvB,yDAAgD;AAChD,
|
|
1
|
+
{"version":3,"file":"braintree.resolver.js","sourceRoot":"","sources":["../../src/braintree/braintree.resolver.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAwC;AACxC,6CAAwD;AACxD,wCASuB;AAEvB,yDAAgD;AAChD,2DAAoE;AACpE,2CAAkE;AAIlE,IAAa,iBAAiB,GAA9B,MAAa,iBAAiB;IAC1B,YACY,UAAmC,EACnC,YAA0B,EACQ,OAA+B;QAFjE,eAAU,GAAV,UAAU,CAAyB;QACnC,iBAAY,GAAZ,YAA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M,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;YAC5C,uCACO,IAAI,KACP,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,GAAG,CAAC,KAAK,IACvB;QACN,CAAC,EAAE,EAA2B,CAAC,CAAC;IACpC,CAAC;CACJ,CAAA;AArCG;IADC,eAAK,EAAE;IAC4B,WAAA,UAAG,EAAE,CAAA;IAAuB,WAAA,cAAI,EAAE,CAAA;;qCAAvB,qBAAc;;qEAmB5D;AA3BQ,iBAAiB;IAD7B,kBAAQ,EAAE;IAKF,WAAA,eAAM,CAAC,oCAAwB,CAAC,CAAA;qCAFb,8BAAuB;QACrB,mBAAY;GAH7B,iBAAiB,CA6C7B;AA7CY,8CAAiB"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.loggerCtx = void 0;
|
|
3
|
+
exports.BRAINTREE_PLUGIN_OPTIONS = exports.loggerCtx = void 0;
|
|
4
4
|
exports.loggerCtx = 'BraintreePlugin';
|
|
5
|
+
exports.BRAINTREE_PLUGIN_OPTIONS = Symbol('BRAINTREE_PLUGIN_OPTIONS');
|
|
5
6
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/braintree/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,SAAS,GAAG,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/braintree/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,SAAS,GAAG,iBAAiB,CAAC;AAC9B,QAAA,wBAAwB,GAAG,MAAM,CAAC,0BAA0B,CAAC,CAAC"}
|
|
@@ -10,8 +10,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
__exportStar(require("./braintree
|
|
14
|
-
__exportStar(require("./braintree
|
|
13
|
+
__exportStar(require("./braintree.plugin"), exports);
|
|
14
|
+
__exportStar(require("./braintree.handler"), exports);
|
|
15
15
|
__exportStar(require("./braintree.resolver"), exports);
|
|
16
16
|
__exportStar(require("./braintree-common"), exports);
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
17
18
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/braintree/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAmC;AACnC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/braintree/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAmC;AACnC,sDAAoC;AACpC,uDAAqC;AACrC,qDAAmC;AACnC,0CAAwB"}
|
|
@@ -1,3 +1,35 @@
|
|
|
1
1
|
import { ConfigArgValues } from '@vendure/core/dist/common/configurable-operation';
|
|
2
|
-
import {
|
|
2
|
+
import { Environment } from 'braintree';
|
|
3
|
+
import { braintreePaymentMethodHandler } from './braintree.handler';
|
|
3
4
|
export declare type PaymentMethodArgsHash = ConfigArgValues<typeof braintreePaymentMethodHandler['args']>;
|
|
5
|
+
declare module '@vendure/core' {
|
|
6
|
+
interface CustomCustomerFields {
|
|
7
|
+
braintreeCustomerId?: string;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* @description
|
|
12
|
+
* Options for the Braintree plugin.
|
|
13
|
+
*
|
|
14
|
+
* @docsCategory payments-plugin
|
|
15
|
+
* @docsPage BraintreePlugin
|
|
16
|
+
*/
|
|
17
|
+
export interface BraintreePluginOptions {
|
|
18
|
+
/**
|
|
19
|
+
* @description
|
|
20
|
+
* The Braintree environment being targeted, e.g. sandbox or production.
|
|
21
|
+
*
|
|
22
|
+
* @default Environment.Sandbox
|
|
23
|
+
*/
|
|
24
|
+
environment?: Environment;
|
|
25
|
+
/**
|
|
26
|
+
* @description
|
|
27
|
+
* If set to `true`, a [Customer](https://developer.paypal.com/braintree/docs/guides/customers) object
|
|
28
|
+
* will be created in Braintree, which allows the secure storage of previously-used payment methods.
|
|
29
|
+
* This is done by adding a custom field to the Customer entity to store the Braintree customer ID,
|
|
30
|
+
* so switching this on will require a database migration / synchronization.
|
|
31
|
+
*
|
|
32
|
+
* @default false
|
|
33
|
+
*/
|
|
34
|
+
storeCustomersInBraintree?: boolean;
|
|
35
|
+
}
|
package/package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* This is a placeholder. Please import from one of the sub-packages, e.g `@vendure/payments-plugin/package/
|
|
2
|
+
* This is a placeholder. Please import from one of the sub-packages, e.g `@vendure/payments-plugin/package/braintree`
|
|
3
3
|
*/
|
|
4
4
|
export declare const placeholder = "Vendure Payments Plugin";
|
package/package/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.placeholder = void 0;
|
|
4
4
|
/**
|
|
5
|
-
* This is a placeholder. Please import from one of the sub-packages, e.g `@vendure/payments-plugin/package/
|
|
5
|
+
* This is a placeholder. Please import from one of the sub-packages, e.g `@vendure/payments-plugin/package/braintree`
|
|
6
6
|
*/
|
|
7
7
|
exports.placeholder = 'Vendure Payments Plugin';
|
|
8
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PLUGIN_INIT_OPTIONS = exports.loggerCtx = void 0;
|
|
4
|
+
exports.loggerCtx = 'MolliePlugin';
|
|
5
|
+
exports.PLUGIN_INIT_OPTIONS = Symbol('PLUGIN_INIT_OPTIONS');
|
|
6
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/mollie/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,SAAS,GAAG,cAAc,CAAC;AAC3B,QAAA,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./mollie.plugin"), exports);
|
|
14
|
+
__exportStar(require("./"), exports);
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mollie/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAAgC;AAChC,qCAAmB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ChannelService, OrderService, PaymentMethodService, TransactionalConnection } from '@vendure/core';
|
|
2
|
+
export declare class MollieController {
|
|
3
|
+
private orderService;
|
|
4
|
+
private connection;
|
|
5
|
+
private paymentMethodService;
|
|
6
|
+
private channelService;
|
|
7
|
+
constructor(orderService: OrderService, connection: TransactionalConnection, paymentMethodService: PaymentMethodService, channelService: ChannelService);
|
|
8
|
+
webhook(channelToken: string, paymentMethodId: string, body: any): Promise<void>;
|
|
9
|
+
private createContext;
|
|
10
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
15
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
16
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
17
|
+
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;
|
|
18
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
19
|
+
};
|
|
20
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
21
|
+
if (mod && mod.__esModule) return mod;
|
|
22
|
+
var result = {};
|
|
23
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
24
|
+
__setModuleDefault(result, mod);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
28
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
29
|
+
};
|
|
30
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
31
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
32
|
+
};
|
|
33
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
exports.MollieController = void 0;
|
|
35
|
+
const api_client_1 = __importStar(require("@mollie/api-client"));
|
|
36
|
+
const common_1 = require("@nestjs/common");
|
|
37
|
+
const core_1 = require("@vendure/core");
|
|
38
|
+
const constants_1 = require("./constants");
|
|
39
|
+
let MollieController = class MollieController {
|
|
40
|
+
constructor(orderService, connection, paymentMethodService, channelService) {
|
|
41
|
+
this.orderService = orderService;
|
|
42
|
+
this.connection = connection;
|
|
43
|
+
this.paymentMethodService = paymentMethodService;
|
|
44
|
+
this.channelService = channelService;
|
|
45
|
+
}
|
|
46
|
+
async webhook(channelToken, paymentMethodId, body) {
|
|
47
|
+
var _a;
|
|
48
|
+
const ctx = await this.createContext(channelToken);
|
|
49
|
+
core_1.Logger.info(`Received payment for ${channelToken}`, constants_1.loggerCtx);
|
|
50
|
+
const paymentMethod = await this.paymentMethodService.findOne(ctx, paymentMethodId);
|
|
51
|
+
if (!paymentMethod) {
|
|
52
|
+
// Fail silently, as we don't want to expose if a paymentMethodId exists or not
|
|
53
|
+
return core_1.Logger.error(`No paymentMethod found with id ${paymentMethod}`, constants_1.loggerCtx);
|
|
54
|
+
}
|
|
55
|
+
const apiKey = (_a = paymentMethod.handler.args.find(a => a.name === 'apiKey')) === null || _a === void 0 ? void 0 : _a.value;
|
|
56
|
+
if (!apiKey) {
|
|
57
|
+
throw Error(`No apiKey found for payment ${paymentMethod.id} for channel ${channelToken}`);
|
|
58
|
+
}
|
|
59
|
+
const client = api_client_1.default({ apiKey });
|
|
60
|
+
const molliePayment = await client.payments.get(body.id);
|
|
61
|
+
core_1.Logger.info(`Received payment ${molliePayment.id} for order ${molliePayment.metadata.orderCode} with status ${molliePayment.status}`, constants_1.loggerCtx);
|
|
62
|
+
const dbPayment = await this.connection
|
|
63
|
+
.getRepository(core_1.Payment)
|
|
64
|
+
.findOneOrFail({ where: { transactionId: molliePayment.id } });
|
|
65
|
+
if (molliePayment.status === api_client_1.PaymentStatus.paid) {
|
|
66
|
+
await this.orderService.settlePayment(ctx, dbPayment.id);
|
|
67
|
+
core_1.Logger.info(`Payment for order ${molliePayment.metadata.orderCode} settled`, constants_1.loggerCtx);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
core_1.Logger.warn(`Received payment for order ${molliePayment.metadata.orderCode} with status ${molliePayment.status}`, constants_1.loggerCtx);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async createContext(channelToken) {
|
|
74
|
+
const channel = await this.channelService.getChannelFromToken(channelToken);
|
|
75
|
+
return new core_1.RequestContext({
|
|
76
|
+
apiType: 'admin',
|
|
77
|
+
isAuthorized: true,
|
|
78
|
+
authorizedAsOwnerOnly: false,
|
|
79
|
+
channel,
|
|
80
|
+
languageCode: core_1.LanguageCode.en,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
__decorate([
|
|
85
|
+
common_1.Post('mollie/:channelToken/:paymentMethodId'),
|
|
86
|
+
__param(0, common_1.Param('channelToken')),
|
|
87
|
+
__param(1, common_1.Param('paymentMethodId')),
|
|
88
|
+
__param(2, common_1.Body()),
|
|
89
|
+
__metadata("design:type", Function),
|
|
90
|
+
__metadata("design:paramtypes", [String, String, Object]),
|
|
91
|
+
__metadata("design:returntype", Promise)
|
|
92
|
+
], MollieController.prototype, "webhook", null);
|
|
93
|
+
MollieController = __decorate([
|
|
94
|
+
common_1.Controller('payments'),
|
|
95
|
+
__metadata("design:paramtypes", [core_1.OrderService,
|
|
96
|
+
core_1.TransactionalConnection,
|
|
97
|
+
core_1.PaymentMethodService,
|
|
98
|
+
core_1.ChannelService])
|
|
99
|
+
], MollieController);
|
|
100
|
+
exports.MollieController = MollieController;
|
|
101
|
+
//# sourceMappingURL=mollie.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mollie.controller.js","sourceRoot":"","sources":["../../src/mollie/mollie.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iEAAuE;AACvE,2CAA+D;AAC/D,wCASuB;AAEvB,2CAAwC;AAGxC,IAAa,gBAAgB,GAA7B,MAAa,gBAAgB;IACzB,YACY,YAA0B,EAC1B,UAAmC,EACnC,oBAA0C,EAC1C,cAA8B;QAH9B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,eAAU,GAAV,UAAU,CAAyB;QACnC,yBAAoB,GAApB,oBAAoB,CAAsB;QAC1C,mBAAc,GAAd,cAAc,CAAgB;IACvC,CAAC;IAGJ,KAAK,CAAC,OAAO,CACc,YAAoB,EACjB,eAAuB,EACzC,IAAS;;QAEjB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;QACnD,aAAM,CAAC,IAAI,CAAC,wBAAwB,YAAY,EAAE,EAAE,qBAAS,CAAC,CAAC;QAC/D,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;QACpF,IAAI,CAAC,aAAa,EAAE;YAChB,+EAA+E;YAC/E,OAAO,aAAM,CAAC,KAAK,CAAC,kCAAkC,aAAa,EAAE,EAAE,qBAAS,CAAC,CAAC;SACrF;QACD,MAAM,MAAM,GAAG,MAAA,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,QAAQ,CAAC,0CAAE,KAAK,CAAC;QAChF,IAAI,CAAC,MAAM,EAAE;YACT,MAAM,KAAK,CAAC,+BAA+B,aAAa,CAAC,EAAE,gBAAgB,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,CAAC;CACJ,CAAA;AA9CG;IADC,aAAI,CAAC,uCAAuC,CAAC;IAEzC,WAAA,cAAK,CAAC,cAAc,CAAC,CAAA;IACrB,WAAA,cAAK,CAAC,iBAAiB,CAAC,CAAA;IACxB,WAAA,aAAI,EAAE,CAAA;;;;+CA+BV;AA3CQ,gBAAgB;IAD5B,mBAAU,CAAC,UAAU,CAAC;qCAGO,mBAAY;QACd,8BAAuB;QACb,2BAAoB;QAC1B,qBAAc;GALjC,gBAAgB,CAuD5B;AAvDY,4CAAgB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { LanguageCode } from '@vendure/common/lib/generated-types';
|
|
2
|
+
import { PaymentMethodHandler } from '@vendure/core';
|
|
3
|
+
export declare const molliePaymentHandler: PaymentMethodHandler<{
|
|
4
|
+
apiKey: {
|
|
5
|
+
type: "string";
|
|
6
|
+
label: {
|
|
7
|
+
languageCode: LanguageCode.en;
|
|
8
|
+
value: string;
|
|
9
|
+
}[];
|
|
10
|
+
};
|
|
11
|
+
redirectUrl: {
|
|
12
|
+
type: "string";
|
|
13
|
+
label: {
|
|
14
|
+
languageCode: LanguageCode.en;
|
|
15
|
+
value: string;
|
|
16
|
+
}[];
|
|
17
|
+
};
|
|
18
|
+
}>;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.molliePaymentHandler = void 0;
|
|
23
|
+
const api_client_1 = __importStar(require("@mollie/api-client"));
|
|
24
|
+
const generated_types_1 = require("@vendure/common/lib/generated-types");
|
|
25
|
+
const core_1 = require("@vendure/core");
|
|
26
|
+
const constants_1 = require("./constants");
|
|
27
|
+
let paymentMethodService;
|
|
28
|
+
let options;
|
|
29
|
+
exports.molliePaymentHandler = new core_1.PaymentMethodHandler({
|
|
30
|
+
code: 'mollie-payment-handler',
|
|
31
|
+
description: [
|
|
32
|
+
{
|
|
33
|
+
languageCode: generated_types_1.LanguageCode.en,
|
|
34
|
+
value: 'Mollie payment',
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
args: {
|
|
38
|
+
apiKey: {
|
|
39
|
+
type: 'string',
|
|
40
|
+
label: [{ languageCode: generated_types_1.LanguageCode.en, value: 'API Key' }],
|
|
41
|
+
},
|
|
42
|
+
redirectUrl: {
|
|
43
|
+
type: 'string',
|
|
44
|
+
label: [{ languageCode: generated_types_1.LanguageCode.en, value: 'Redirect URL' }],
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
init(injector) {
|
|
48
|
+
paymentMethodService = injector.get(core_1.PaymentMethodService);
|
|
49
|
+
options = injector.get(constants_1.PLUGIN_INIT_OPTIONS);
|
|
50
|
+
},
|
|
51
|
+
createPayment: async (ctx, order, amount, args, _metadata) => {
|
|
52
|
+
try {
|
|
53
|
+
const { apiKey } = args;
|
|
54
|
+
let { redirectUrl } = args;
|
|
55
|
+
const paymentMethods = await paymentMethodService.findAll(ctx);
|
|
56
|
+
const paymentMethod = paymentMethods.items.find(pm => pm.handler.args.find(arg => arg.value === apiKey) &&
|
|
57
|
+
pm.handler.args.find(arg => arg.value === redirectUrl));
|
|
58
|
+
if (!paymentMethod) {
|
|
59
|
+
throw Error(`No paymentMethod found for given apiKey`); // This should never happen
|
|
60
|
+
}
|
|
61
|
+
const mollieClient = api_client_1.default({ apiKey });
|
|
62
|
+
redirectUrl = redirectUrl.endsWith('/') ? redirectUrl.slice(0, -1) : redirectUrl; // remove appending slash
|
|
63
|
+
const vendureHost = options.vendureHost.endsWith('/')
|
|
64
|
+
? options.vendureHost.slice(0, -1)
|
|
65
|
+
: options.vendureHost; // remove appending slash
|
|
66
|
+
const payment = await mollieClient.payments.create({
|
|
67
|
+
amount: {
|
|
68
|
+
value: `${(order.totalWithTax / 100).toFixed(2)}`,
|
|
69
|
+
currency: order.currencyCode,
|
|
70
|
+
},
|
|
71
|
+
metadata: {
|
|
72
|
+
orderCode: order.code,
|
|
73
|
+
},
|
|
74
|
+
description: `Order ${order.code}`,
|
|
75
|
+
redirectUrl: `${redirectUrl}/${order.code}`,
|
|
76
|
+
webhookUrl: `${vendureHost}/payments/mollie/${ctx.channel.token}/${paymentMethod.id}`,
|
|
77
|
+
});
|
|
78
|
+
return {
|
|
79
|
+
amount: order.totalWithTax,
|
|
80
|
+
transactionId: payment.id,
|
|
81
|
+
state: 'Authorized',
|
|
82
|
+
metadata: {
|
|
83
|
+
public: {
|
|
84
|
+
redirectLink: payment.getPaymentUrl(),
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
core_1.Logger.error(err, constants_1.loggerCtx);
|
|
91
|
+
return {
|
|
92
|
+
amount: order.totalWithTax,
|
|
93
|
+
state: 'Error',
|
|
94
|
+
errorMessage: err.message,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
settlePayment: async (order, payment, args) => {
|
|
99
|
+
// Settlement is handled by incoming webhook in mollie.controller.ts
|
|
100
|
+
return { success: true };
|
|
101
|
+
},
|
|
102
|
+
createRefund: async (ctx, input, amount, order, payment, args) => {
|
|
103
|
+
const { apiKey } = args;
|
|
104
|
+
const mollieClient = api_client_1.default({ apiKey });
|
|
105
|
+
const refund = await mollieClient.payments_refunds.create({
|
|
106
|
+
paymentId: payment.transactionId,
|
|
107
|
+
description: input.reason,
|
|
108
|
+
amount: {
|
|
109
|
+
value: (amount / 100).toFixed(2),
|
|
110
|
+
currency: order.currencyCode,
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
if (refund.status === api_client_1.RefundStatus.failed) {
|
|
114
|
+
core_1.Logger.error(`Failed to create refund of ${amount.toFixed()} for order ${order.code} for transaction ${payment.transactionId}`, constants_1.loggerCtx);
|
|
115
|
+
return {
|
|
116
|
+
state: 'Failed',
|
|
117
|
+
transactionId: payment.transactionId,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
core_1.Logger.info(`Created refund of ${amount.toFixed()} for order ${order.code} for transaction ${payment.transactionId}`, constants_1.loggerCtx);
|
|
121
|
+
return {
|
|
122
|
+
state: 'Settled',
|
|
123
|
+
transactionId: payment.transactionId,
|
|
124
|
+
};
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
//# sourceMappingURL=mollie.handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mollie.handler.js","sourceRoot":"","sources":["../../src/mollie/mollie.handler.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,iEAAsE;AACtE,yEAAmE;AACnE,wCAQuB;AAEvB,2CAA6D;AAG7D,IAAI,oBAA0C,CAAC;AAC/C,IAAI,OAA4B,CAAC;AACpB,QAAA,oBAAoB,GAAG,IAAI,2BAAoB,CAAC;IACzD,IAAI,EAAE,wBAAwB;IAC9B,WAAW,EAAE;QACT;YACI,YAA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,EAAE,cAAc,KAAK,CAAC,IAAI,oBACzD,OAAO,CAAC,aACZ,EAAE,EACF,qBAAS,CACZ,CAAC;QACF,OAAO;YACH,KAAK,EAAE,SAAS;YAChB,aAAa,EAAE,OAAO,CAAC,aAAa;SACvC,CAAC;IACN,CAAC;CACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description
|
|
3
|
+
* Configuration options for the Mollie payments plugin.
|
|
4
|
+
*
|
|
5
|
+
* @docsCategory payments-plugin
|
|
6
|
+
* @docsPage MolliePlugin
|
|
7
|
+
*/
|
|
8
|
+
export interface MolliePluginOptions {
|
|
9
|
+
/**
|
|
10
|
+
* @description
|
|
11
|
+
* The host of your storefront application, e.g. `'https://my-shop.com'`
|
|
12
|
+
*/
|
|
13
|
+
vendureHost: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* @description
|
|
17
|
+
* Plugin to enable payments through the [Mollie platform](https://docs.mollie.com/).
|
|
18
|
+
* This plugin uses the Payments API from Mollie, not the Orders API.
|
|
19
|
+
*
|
|
20
|
+
* ## Requirements
|
|
21
|
+
*
|
|
22
|
+
* 1. You will need to create a Mollie account and get your apiKey in the dashboard.
|
|
23
|
+
* 2. Install the Payments plugin and the Mollie client:
|
|
24
|
+
*
|
|
25
|
+
* `yarn add \@vendure/payments-plugin \@mollie/api-client`
|
|
26
|
+
*
|
|
27
|
+
* or
|
|
28
|
+
*
|
|
29
|
+
* `npm install \@vendure/payments-plugin \@mollie/api-client`
|
|
30
|
+
*
|
|
31
|
+
* ## Setup
|
|
32
|
+
*
|
|
33
|
+
* 1. Add the plugin to your VendureConfig `plugins` array:
|
|
34
|
+
* ```TypeScript
|
|
35
|
+
* import { MolliePlugin } from '\@vendure/payments-plugin/package/mollie';
|
|
36
|
+
*
|
|
37
|
+
* // ...
|
|
38
|
+
*
|
|
39
|
+
* plugins: [
|
|
40
|
+
* MolliePlugin.init({ vendureHost: 'https://yourhost.io/' }),
|
|
41
|
+
* ]
|
|
42
|
+
* ```
|
|
43
|
+
* 2. Create a new PaymentMethod in the Admin UI, and select "Mollie payments" as the handler.
|
|
44
|
+
* 3. Set the Redirect URL. This is the url that is used to redirect the end-user, e.g. `https://storefront/order`
|
|
45
|
+
* 4. Set your Mollie apiKey in the `API Key` field.
|
|
46
|
+
*
|
|
47
|
+
* ## Storefront usage
|
|
48
|
+
*
|
|
49
|
+
* In your storefront you add a payment to an order using the `addPaymentToOrder` mutation. In this example, our Mollie
|
|
50
|
+
* PaymentMethod was given the code "mollie-payment-method".
|
|
51
|
+
*
|
|
52
|
+
* ```GraphQL
|
|
53
|
+
* mutation AddPaymentToOrder {
|
|
54
|
+
* addPaymentToOrder(input: {
|
|
55
|
+
* method: "mollie-payment-method"
|
|
56
|
+
* metadata: {}
|
|
57
|
+
* }) {
|
|
58
|
+
* ...on Order {
|
|
59
|
+
* id
|
|
60
|
+
* state
|
|
61
|
+
* payments {
|
|
62
|
+
* id
|
|
63
|
+
* metadata
|
|
64
|
+
* }
|
|
65
|
+
* }
|
|
66
|
+
* ...on ErrorResult {
|
|
67
|
+
* errorCode
|
|
68
|
+
* message
|
|
69
|
+
* }
|
|
70
|
+
* }
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
* The response will have
|
|
74
|
+
* a `order.payments.metadata.public.redirectLink` in it, which can be used to redirect your customer to the Mollie
|
|
75
|
+
* platform.
|
|
76
|
+
*
|
|
77
|
+
* After completing payment on the Mollie platform,
|
|
78
|
+
* the user is redirected to the configured redirect url + orderCode: `https://storefront/order/CH234X5`
|
|
79
|
+
*
|
|
80
|
+
* ## Local development
|
|
81
|
+
*
|
|
82
|
+
* Use something like [localtunnel](https://github.com/localtunnel/localtunnel) to test on localhost.
|
|
83
|
+
*
|
|
84
|
+
* ```bash
|
|
85
|
+
* npx localtunnel --port 3000 --subdomain my-shop-local-dev
|
|
86
|
+
* > your url is: https://my-shop-local-dev.loca.lt <- use this as the vendureHost for local dev.
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* @docsCategory payments-plugin
|
|
90
|
+
* @docsPage MolliePlugin
|
|
91
|
+
* @docsWeight 0
|
|
92
|
+
*/
|
|
93
|
+
export declare class MolliePlugin {
|
|
94
|
+
static options: MolliePluginOptions;
|
|
95
|
+
/**
|
|
96
|
+
* @description
|
|
97
|
+
* Initialize the mollie payment plugin
|
|
98
|
+
* @param vendureHost is needed to pass to mollie for callback
|
|
99
|
+
*/
|
|
100
|
+
static init(options: MolliePluginOptions): typeof MolliePlugin;
|
|
101
|
+
}
|