@ambushsoftworks/nestjs-payments-graphql 0.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/dist/constants.d.ts +17 -0
- package/dist/constants.js +21 -0
- package/dist/constants.js.map +1 -0
- package/dist/dto/create-installment.input.d.ts +5 -0
- package/dist/dto/create-installment.input.js +39 -0
- package/dist/dto/create-installment.input.js.map +1 -0
- package/dist/dto/create-invoice.input.d.ts +13 -0
- package/dist/dto/create-invoice.input.js +95 -0
- package/dist/dto/create-invoice.input.js.map +1 -0
- package/dist/dto/create-line-item.input.d.ts +10 -0
- package/dist/dto/create-line-item.input.js +77 -0
- package/dist/dto/create-line-item.input.js.map +1 -0
- package/dist/dto/create-payment-plan.input.d.ts +11 -0
- package/dist/dto/create-payment-plan.input.js +76 -0
- package/dist/dto/create-payment-plan.input.js.map +1 -0
- package/dist/dto/create-recurring-invoice.input.d.ts +18 -0
- package/dist/dto/create-recurring-invoice.input.js +117 -0
- package/dist/dto/create-recurring-invoice.input.js.map +1 -0
- package/dist/dto/create-recurring-line-item.input.d.ts +10 -0
- package/dist/dto/create-recurring-line-item.input.js +77 -0
- package/dist/dto/create-recurring-line-item.input.js.map +1 -0
- package/dist/dto/create-refund.input.d.ts +5 -0
- package/dist/dto/create-refund.input.js +43 -0
- package/dist/dto/create-refund.input.js.map +1 -0
- package/dist/dto/index.d.ts +8 -0
- package/dist/dto/index.js +20 -0
- package/dist/dto/index.js.map +1 -0
- package/dist/dto/invoice-filter.input.d.ts +10 -0
- package/dist/dto/invoice-filter.input.js +64 -0
- package/dist/dto/invoice-filter.input.js.map +1 -0
- package/dist/dto/payment-plan-filter.input.d.ts +7 -0
- package/dist/dto/payment-plan-filter.input.js +46 -0
- package/dist/dto/payment-plan-filter.input.js.map +1 -0
- package/dist/dto/record-manual-payment.input.d.ts +9 -0
- package/dist/dto/record-manual-payment.input.js +58 -0
- package/dist/dto/record-manual-payment.input.js.map +1 -0
- package/dist/dto/recurring-invoice-filter.input.d.ts +7 -0
- package/dist/dto/recurring-invoice-filter.input.js +46 -0
- package/dist/dto/recurring-invoice-filter.input.js.map +1 -0
- package/dist/dto/update-invoice-metadata.input.d.ts +3 -0
- package/dist/dto/update-invoice-metadata.input.js +30 -0
- package/dist/dto/update-invoice-metadata.input.js.map +1 -0
- package/dist/dto/update-payment-config.input.d.ts +8 -0
- package/dist/dto/update-payment-config.input.js +61 -0
- package/dist/dto/update-payment-config.input.js.map +1 -0
- package/dist/dto/update-recurring-template.input.d.ts +12 -0
- package/dist/dto/update-recurring-template.input.js +89 -0
- package/dist/dto/update-recurring-template.input.js.map +1 -0
- package/dist/dto/upsert-payment-provider.input.d.ts +5 -0
- package/dist/dto/upsert-payment-provider.input.js +43 -0
- package/dist/dto/upsert-payment-provider.input.js.map +1 -0
- package/dist/dto/validators/is-metadata.d.ts +1 -0
- package/dist/dto/validators/is-metadata.js +41 -0
- package/dist/dto/validators/is-metadata.js.map +1 -0
- package/dist/exceptions/index.d.ts +34 -0
- package/dist/exceptions/index.js +73 -0
- package/dist/exceptions/index.js.map +1 -0
- package/dist/gateways/gateway-registry.service.d.ts +10 -0
- package/dist/gateways/gateway-registry.service.js +45 -0
- package/dist/gateways/gateway-registry.service.js.map +1 -0
- package/dist/gateways/payment-gateway.interface.d.ts +50 -0
- package/dist/gateways/payment-gateway.interface.js +3 -0
- package/dist/gateways/payment-gateway.interface.js.map +1 -0
- package/dist/gateways/recurring-payment-gateway.interface.d.ts +32 -0
- package/dist/gateways/recurring-payment-gateway.interface.js +3 -0
- package/dist/gateways/recurring-payment-gateway.interface.js.map +1 -0
- package/dist/gateways/stripe/stripe-webhook.controller.d.ts +24 -0
- package/dist/gateways/stripe/stripe-webhook.controller.js +150 -0
- package/dist/gateways/stripe/stripe-webhook.controller.js.map +1 -0
- package/dist/gateways/stripe/stripe.gateway.d.ts +84 -0
- package/dist/gateways/stripe/stripe.gateway.js +424 -0
- package/dist/gateways/stripe/stripe.gateway.js.map +1 -0
- package/dist/index.d.ts +70 -0
- package/dist/index.js +147 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/invoice-repository.interface.d.ts +23 -0
- package/dist/interfaces/invoice-repository.interface.js +3 -0
- package/dist/interfaces/invoice-repository.interface.js.map +1 -0
- package/dist/interfaces/payment-config-repository.interface.d.ts +11 -0
- package/dist/interfaces/payment-config-repository.interface.js +3 -0
- package/dist/interfaces/payment-config-repository.interface.js.map +1 -0
- package/dist/interfaces/payment-customer-repository.interface.d.ts +6 -0
- package/dist/interfaces/payment-customer-repository.interface.js +3 -0
- package/dist/interfaces/payment-customer-repository.interface.js.map +1 -0
- package/dist/interfaces/payment-email.interfaces.d.ts +74 -0
- package/dist/interfaces/payment-email.interfaces.js +3 -0
- package/dist/interfaces/payment-email.interfaces.js.map +1 -0
- package/dist/interfaces/payment-event-listener.interface.d.ts +61 -0
- package/dist/interfaces/payment-event-listener.interface.js +3 -0
- package/dist/interfaces/payment-event-listener.interface.js.map +1 -0
- package/dist/interfaces/payment-plan-repository.interface.d.ts +16 -0
- package/dist/interfaces/payment-plan-repository.interface.js +3 -0
- package/dist/interfaces/payment-plan-repository.interface.js.map +1 -0
- package/dist/interfaces/payment-repository.interface.d.ts +13 -0
- package/dist/interfaces/payment-repository.interface.js +3 -0
- package/dist/interfaces/payment-repository.interface.js.map +1 -0
- package/dist/interfaces/recurring-invoice-repository.interface.d.ts +16 -0
- package/dist/interfaces/recurring-invoice-repository.interface.js +3 -0
- package/dist/interfaces/recurring-invoice-repository.interface.js.map +1 -0
- package/dist/interfaces/refund-repository.interface.d.ts +8 -0
- package/dist/interfaces/refund-repository.interface.js +3 -0
- package/dist/interfaces/refund-repository.interface.js.map +1 -0
- package/dist/interfaces/transaction-manager.interface.d.ts +19 -0
- package/dist/interfaces/transaction-manager.interface.js +3 -0
- package/dist/interfaces/transaction-manager.interface.js.map +1 -0
- package/dist/interfaces/webhook-idempotency-repository.interface.d.ts +5 -0
- package/dist/interfaces/webhook-idempotency-repository.interface.js +3 -0
- package/dist/interfaces/webhook-idempotency-repository.interface.js.map +1 -0
- package/dist/models/e-transfer-instructions.model.d.ts +11 -0
- package/dist/models/e-transfer-instructions.model.js +56 -0
- package/dist/models/e-transfer-instructions.model.js.map +1 -0
- package/dist/models/index.d.ts +13 -0
- package/dist/models/index.js +36 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/invoice-client.model.d.ts +5 -0
- package/dist/models/invoice-client.model.js +32 -0
- package/dist/models/invoice-client.model.js.map +1 -0
- package/dist/models/invoice-line-item.model.d.ts +14 -0
- package/dist/models/invoice-line-item.model.js +72 -0
- package/dist/models/invoice-line-item.model.js.map +1 -0
- package/dist/models/invoice.model.d.ts +86 -0
- package/dist/models/invoice.model.js +210 -0
- package/dist/models/invoice.model.js.map +1 -0
- package/dist/models/online-payment-session.model.d.ts +6 -0
- package/dist/models/online-payment-session.model.js +40 -0
- package/dist/models/online-payment-session.model.js.map +1 -0
- package/dist/models/paginated-invoices.model.d.ts +5 -0
- package/dist/models/paginated-invoices.model.js +19 -0
- package/dist/models/paginated-invoices.model.js.map +1 -0
- package/dist/models/paginated-payment-plans.model.d.ts +5 -0
- package/dist/models/paginated-payment-plans.model.js +19 -0
- package/dist/models/paginated-payment-plans.model.js.map +1 -0
- package/dist/models/paginated-recurring-invoices.model.d.ts +5 -0
- package/dist/models/paginated-recurring-invoices.model.js +19 -0
- package/dist/models/paginated-recurring-invoices.model.js.map +1 -0
- package/dist/models/paginated.model.d.ts +6 -0
- package/dist/models/paginated.model.js +30 -0
- package/dist/models/paginated.model.js.map +1 -0
- package/dist/models/payment-config.model.d.ts +21 -0
- package/dist/models/payment-config.model.js +98 -0
- package/dist/models/payment-config.model.js.map +1 -0
- package/dist/models/payment-method-setup.model.d.ts +4 -0
- package/dist/models/payment-method-setup.model.js +32 -0
- package/dist/models/payment-method-setup.model.js.map +1 -0
- package/dist/models/payment-plan-installment.model.d.ts +12 -0
- package/dist/models/payment-plan-installment.model.js +57 -0
- package/dist/models/payment-plan-installment.model.js.map +1 -0
- package/dist/models/payment-plan.model.d.ts +25 -0
- package/dist/models/payment-plan.model.js +105 -0
- package/dist/models/payment-plan.model.js.map +1 -0
- package/dist/models/payment.model.d.ts +23 -0
- package/dist/models/payment.model.js +102 -0
- package/dist/models/payment.model.js.map +1 -0
- package/dist/models/recurring-invoice-line-item.model.d.ts +14 -0
- package/dist/models/recurring-invoice-line-item.model.js +72 -0
- package/dist/models/recurring-invoice-line-item.model.js.map +1 -0
- package/dist/models/recurring-invoice.model.d.ts +43 -0
- package/dist/models/recurring-invoice.model.js +157 -0
- package/dist/models/recurring-invoice.model.js.map +1 -0
- package/dist/models/refund.model.d.ts +15 -0
- package/dist/models/refund.model.js +73 -0
- package/dist/models/refund.model.js.map +1 -0
- package/dist/payments.module.d.ts +54 -0
- package/dist/payments.module.js +211 -0
- package/dist/payments.module.js.map +1 -0
- package/dist/register-payment-enums.d.ts +1 -0
- package/dist/register-payment-enums.js +18 -0
- package/dist/register-payment-enums.js.map +1 -0
- package/dist/services/customer.service.d.ts +15 -0
- package/dist/services/customer.service.js +63 -0
- package/dist/services/customer.service.js.map +1 -0
- package/dist/services/default-payment-email-templates.d.ts +8 -0
- package/dist/services/default-payment-email-templates.js +249 -0
- package/dist/services/default-payment-email-templates.js.map +1 -0
- package/dist/services/e-transfer.service.d.ts +35 -0
- package/dist/services/e-transfer.service.js +93 -0
- package/dist/services/e-transfer.service.js.map +1 -0
- package/dist/services/invoice-number.service.d.ts +9 -0
- package/dist/services/invoice-number.service.js +56 -0
- package/dist/services/invoice-number.service.js.map +1 -0
- package/dist/services/invoice.service.d.ts +66 -0
- package/dist/services/invoice.service.js +293 -0
- package/dist/services/invoice.service.js.map +1 -0
- package/dist/services/payment-config.service.d.ts +26 -0
- package/dist/services/payment-config.service.js +90 -0
- package/dist/services/payment-config.service.js.map +1 -0
- package/dist/services/payment-email.service.d.ts +20 -0
- package/dist/services/payment-email.service.js +153 -0
- package/dist/services/payment-email.service.js.map +1 -0
- package/dist/services/payment-plan.service.d.ts +47 -0
- package/dist/services/payment-plan.service.js +264 -0
- package/dist/services/payment-plan.service.js.map +1 -0
- package/dist/services/payment.service.d.ts +65 -0
- package/dist/services/payment.service.js +532 -0
- package/dist/services/payment.service.js.map +1 -0
- package/dist/services/recurring-interval.util.d.ts +3 -0
- package/dist/services/recurring-interval.util.js +43 -0
- package/dist/services/recurring-interval.util.js.map +1 -0
- package/dist/services/recurring-invoice.service.d.ts +88 -0
- package/dist/services/recurring-invoice.service.js +450 -0
- package/dist/services/recurring-invoice.service.js.map +1 -0
- package/dist/services/refund.service.d.ts +44 -0
- package/dist/services/refund.service.js +373 -0
- package/dist/services/refund.service.js.map +1 -0
- package/dist/services/static-branding-resolver.d.ts +6 -0
- package/dist/services/static-branding-resolver.js +13 -0
- package/dist/services/static-branding-resolver.js.map +1 -0
- package/dist/types/index.d.ts +240 -0
- package/dist/types/index.js +19 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/payment-customer.types.d.ts +15 -0
- package/dist/types/payment-customer.types.js +3 -0
- package/dist/types/payment-customer.types.js.map +1 -0
- package/dist/types/recurring-invoice.types.d.ts +84 -0
- package/dist/types/recurring-invoice.types.js +3 -0
- package/dist/types/recurring-invoice.types.js.map +1 -0
- package/package.json +70 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upsert-payment-provider.input.js","sourceRoot":"","sources":["../../src/dto/upsert-payment-provider.input.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6CAAmD;AACnD,0EAA4C;AAC5C,qDAMyB;AAGlB,IAAM,0BAA0B,GAAhC,MAAM,0BAA0B;CAetC,CAAA;AAfY,gEAA0B;AAKrC;IAJC,IAAA,eAAK,GAAE;IACP,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;IACZ,IAAA,2BAAS,EAAC,EAAE,CAAC;;gEACO;AAKrB;IAHC,IAAA,eAAK,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;IAC7C,IAAA,4BAAU,GAAE;IACZ,IAAA,2BAAS,GAAE;;4DACO;AAInB;IAFC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,2BAAW,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;IAC5C,IAAA,4BAAU,GAAE;;0DACoB;qCAdtB,0BAA0B;IADtC,IAAA,mBAAS,GAAE;GACC,0BAA0B,CAetC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function IsMetadata(): PropertyDecorator;
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.IsMetadata = IsMetadata;
|
|
10
|
+
const class_validator_1 = require("class-validator");
|
|
11
|
+
const MAX_KEYS = 20;
|
|
12
|
+
const MAX_KEY_LENGTH = 200;
|
|
13
|
+
const MAX_VALUE_LENGTH = 2000;
|
|
14
|
+
let IsMetadataConstraint = class IsMetadataConstraint {
|
|
15
|
+
validate(value) {
|
|
16
|
+
if (value === null || value === undefined)
|
|
17
|
+
return true;
|
|
18
|
+
if (typeof value !== 'object' || Array.isArray(value))
|
|
19
|
+
return false;
|
|
20
|
+
const entries = Object.entries(value);
|
|
21
|
+
if (entries.length > MAX_KEYS)
|
|
22
|
+
return false;
|
|
23
|
+
for (const [key, val] of entries) {
|
|
24
|
+
if (typeof key !== 'string' || key.length > MAX_KEY_LENGTH)
|
|
25
|
+
return false;
|
|
26
|
+
if (typeof val !== 'string' || val.length > MAX_VALUE_LENGTH)
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
defaultMessage() {
|
|
32
|
+
return `Metadata must be a flat object with string values (max ${MAX_KEYS} keys, key length <= ${MAX_KEY_LENGTH}, value length <= ${MAX_VALUE_LENGTH})`;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
IsMetadataConstraint = __decorate([
|
|
36
|
+
(0, class_validator_1.ValidatorConstraint)({ name: 'isMetadata', async: false })
|
|
37
|
+
], IsMetadataConstraint);
|
|
38
|
+
function IsMetadata() {
|
|
39
|
+
return (0, class_validator_1.Validate)(IsMetadataConstraint);
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=is-metadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-metadata.js","sourceRoot":"","sources":["../../../src/dto/validators/is-metadata.ts"],"names":[],"mappings":";;;;;;;;AAiCA,gCAEC;AAnCD,qDAIyB;AAEzB,MAAM,QAAQ,GAAG,EAAE,CAAC;AACpB,MAAM,cAAc,GAAG,GAAG,CAAC;AAC3B,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAG9B,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IACxB,QAAQ,CAAC,KAAc;QACrB,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC;QACvD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QAEpE,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,KAAgC,CAAC,CAAC;QACjE,IAAI,OAAO,CAAC,MAAM,GAAG,QAAQ;YAAE,OAAO,KAAK,CAAC;QAE5C,KAAK,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,OAAO,EAAE,CAAC;YACjC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,MAAM,GAAG,cAAc;gBAAE,OAAO,KAAK,CAAC;YACzE,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,MAAM,GAAG,gBAAgB;gBAC1D,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,cAAc;QACZ,OAAO,0DAA0D,QAAQ,wBAAwB,cAAc,qBAAqB,gBAAgB,GAAG,CAAC;IAC1J,CAAC;CACF,CAAA;AApBK,oBAAoB;IADzB,IAAA,qCAAmB,EAAC,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;GACpD,oBAAoB,CAoBzB;AAED,SAAgB,UAAU;IACxB,OAAO,IAAA,0BAAQ,EAAC,oBAAoB,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export declare class PaymentException extends Error {
|
|
2
|
+
readonly code: string;
|
|
3
|
+
constructor(message: string, code: string);
|
|
4
|
+
}
|
|
5
|
+
export declare class InvalidInvoiceStateException extends PaymentException {
|
|
6
|
+
constructor(message: string);
|
|
7
|
+
}
|
|
8
|
+
export declare class PaymentAmountExceededException extends PaymentException {
|
|
9
|
+
constructor(message: string);
|
|
10
|
+
}
|
|
11
|
+
export declare class PaymentGatewayException extends PaymentException {
|
|
12
|
+
constructor(message: string);
|
|
13
|
+
}
|
|
14
|
+
export declare class DuplicatePaymentException extends PaymentException {
|
|
15
|
+
constructor(message: string);
|
|
16
|
+
}
|
|
17
|
+
export declare class InvoiceNotPayableException extends PaymentException {
|
|
18
|
+
constructor(message: string);
|
|
19
|
+
}
|
|
20
|
+
export declare class InvoiceNumberExhaustedException extends PaymentException {
|
|
21
|
+
constructor(message: string);
|
|
22
|
+
}
|
|
23
|
+
export declare class RefundNotAllowedException extends PaymentException {
|
|
24
|
+
constructor(message: string);
|
|
25
|
+
}
|
|
26
|
+
export declare class InvalidPaymentStateException extends PaymentException {
|
|
27
|
+
constructor(message: string);
|
|
28
|
+
}
|
|
29
|
+
export declare class InvalidRecurringInvoiceStateException extends PaymentException {
|
|
30
|
+
constructor(message: string);
|
|
31
|
+
}
|
|
32
|
+
export declare class UniqueConstraintViolationException extends PaymentException {
|
|
33
|
+
constructor(message?: string);
|
|
34
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UniqueConstraintViolationException = exports.InvalidRecurringInvoiceStateException = exports.InvalidPaymentStateException = exports.RefundNotAllowedException = exports.InvoiceNumberExhaustedException = exports.InvoiceNotPayableException = exports.DuplicatePaymentException = exports.PaymentGatewayException = exports.PaymentAmountExceededException = exports.InvalidInvoiceStateException = exports.PaymentException = void 0;
|
|
4
|
+
class PaymentException extends Error {
|
|
5
|
+
constructor(message, code) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.code = code;
|
|
8
|
+
this.name = this.constructor.name;
|
|
9
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.PaymentException = PaymentException;
|
|
13
|
+
class InvalidInvoiceStateException extends PaymentException {
|
|
14
|
+
constructor(message) {
|
|
15
|
+
super(message, 'INVALID_INVOICE_STATE');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.InvalidInvoiceStateException = InvalidInvoiceStateException;
|
|
19
|
+
class PaymentAmountExceededException extends PaymentException {
|
|
20
|
+
constructor(message) {
|
|
21
|
+
super(message, 'PAYMENT_AMOUNT_EXCEEDED');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.PaymentAmountExceededException = PaymentAmountExceededException;
|
|
25
|
+
class PaymentGatewayException extends PaymentException {
|
|
26
|
+
constructor(message) {
|
|
27
|
+
super(message, 'PAYMENT_GATEWAY_ERROR');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.PaymentGatewayException = PaymentGatewayException;
|
|
31
|
+
class DuplicatePaymentException extends PaymentException {
|
|
32
|
+
constructor(message) {
|
|
33
|
+
super(message, 'DUPLICATE_PAYMENT');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.DuplicatePaymentException = DuplicatePaymentException;
|
|
37
|
+
class InvoiceNotPayableException extends PaymentException {
|
|
38
|
+
constructor(message) {
|
|
39
|
+
super(message, 'INVOICE_NOT_PAYABLE');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.InvoiceNotPayableException = InvoiceNotPayableException;
|
|
43
|
+
class InvoiceNumberExhaustedException extends PaymentException {
|
|
44
|
+
constructor(message) {
|
|
45
|
+
super(message, 'INVOICE_NUMBER_EXHAUSTED');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.InvoiceNumberExhaustedException = InvoiceNumberExhaustedException;
|
|
49
|
+
class RefundNotAllowedException extends PaymentException {
|
|
50
|
+
constructor(message) {
|
|
51
|
+
super(message, 'REFUND_NOT_ALLOWED');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.RefundNotAllowedException = RefundNotAllowedException;
|
|
55
|
+
class InvalidPaymentStateException extends PaymentException {
|
|
56
|
+
constructor(message) {
|
|
57
|
+
super(message, 'INVALID_PAYMENT_STATE');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.InvalidPaymentStateException = InvalidPaymentStateException;
|
|
61
|
+
class InvalidRecurringInvoiceStateException extends PaymentException {
|
|
62
|
+
constructor(message) {
|
|
63
|
+
super(message, 'INVALID_RECURRING_INVOICE_STATE');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.InvalidRecurringInvoiceStateException = InvalidRecurringInvoiceStateException;
|
|
67
|
+
class UniqueConstraintViolationException extends PaymentException {
|
|
68
|
+
constructor(message = 'Unique constraint violation') {
|
|
69
|
+
super(message, 'UNIQUE_CONSTRAINT_VIOLATION');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.UniqueConstraintViolationException = UniqueConstraintViolationException;
|
|
73
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/exceptions/index.ts"],"names":[],"mappings":";;;AAQA,MAAa,gBAAiB,SAAQ,KAAK;IAGzC,YAAY,OAAe,EAAE,IAAY;QACvC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;QAElC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACF;AAVD,4CAUC;AAMD,MAAa,4BAA6B,SAAQ,gBAAgB;IAChE,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,uBAAuB,CAAC,CAAC;IAC1C,CAAC;CACF;AAJD,oEAIC;AAKD,MAAa,8BAA+B,SAAQ,gBAAgB;IAClE,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,yBAAyB,CAAC,CAAC;IAC5C,CAAC;CACF;AAJD,wEAIC;AAKD,MAAa,uBAAwB,SAAQ,gBAAgB;IAC3D,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,uBAAuB,CAAC,CAAC;IAC1C,CAAC;CACF;AAJD,0DAIC;AAKD,MAAa,yBAA0B,SAAQ,gBAAgB;IAC7D,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,mBAAmB,CAAC,CAAC;IACtC,CAAC;CACF;AAJD,8DAIC;AAMD,MAAa,0BAA2B,SAAQ,gBAAgB;IAC9D,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,qBAAqB,CAAC,CAAC;IACxC,CAAC;CACF;AAJD,gEAIC;AAMD,MAAa,+BAAgC,SAAQ,gBAAgB;IACnE,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,0BAA0B,CAAC,CAAC;IAC7C,CAAC;CACF;AAJD,0EAIC;AAMD,MAAa,yBAA0B,SAAQ,gBAAgB;IAC7D,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAC;IACvC,CAAC;CACF;AAJD,8DAIC;AAMD,MAAa,4BAA6B,SAAQ,gBAAgB;IAChE,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,uBAAuB,CAAC,CAAC;IAC1C,CAAC;CACF;AAJD,oEAIC;AAMD,MAAa,qCAAsC,SAAQ,gBAAgB;IACzE,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,iCAAiC,CAAC,CAAC;IACpD,CAAC;CACF;AAJD,sFAIC;AASD,MAAa,kCAAmC,SAAQ,gBAAgB;IACtE,YAAY,UAAkB,6BAA6B;QACzD,KAAK,CAAC,OAAO,EAAE,6BAA6B,CAAC,CAAC;IAChD,CAAC;CACF;AAJD,gFAIC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PaymentGateway } from './payment-gateway.interface';
|
|
2
|
+
import type { RecurringPaymentGateway } from './recurring-payment-gateway.interface';
|
|
3
|
+
export declare class GatewayRegistryService {
|
|
4
|
+
private readonly gateways;
|
|
5
|
+
register(gateway: PaymentGateway): void;
|
|
6
|
+
get(providerType: string): PaymentGateway;
|
|
7
|
+
getRecurring(providerType: string): PaymentGateway & RecurringPaymentGateway;
|
|
8
|
+
getAvailable(): string[];
|
|
9
|
+
private isRecurringCapable;
|
|
10
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.GatewayRegistryService = void 0;
|
|
10
|
+
const common_1 = require("@nestjs/common");
|
|
11
|
+
let GatewayRegistryService = class GatewayRegistryService {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.gateways = new Map();
|
|
14
|
+
}
|
|
15
|
+
register(gateway) {
|
|
16
|
+
this.gateways.set(gateway.providerType, gateway);
|
|
17
|
+
}
|
|
18
|
+
get(providerType) {
|
|
19
|
+
const gateway = this.gateways.get(providerType);
|
|
20
|
+
if (!gateway) {
|
|
21
|
+
throw new Error(`No payment gateway registered for provider type "${providerType}"`);
|
|
22
|
+
}
|
|
23
|
+
return gateway;
|
|
24
|
+
}
|
|
25
|
+
getRecurring(providerType) {
|
|
26
|
+
const gateway = this.get(providerType);
|
|
27
|
+
if (!this.isRecurringCapable(gateway)) {
|
|
28
|
+
throw new Error(`Gateway "${providerType}" does not support recurring payments`);
|
|
29
|
+
}
|
|
30
|
+
return gateway;
|
|
31
|
+
}
|
|
32
|
+
getAvailable() {
|
|
33
|
+
return Array.from(this.gateways.keys());
|
|
34
|
+
}
|
|
35
|
+
isRecurringCapable(gateway) {
|
|
36
|
+
return ('createOrRetrieveCustomer' in gateway &&
|
|
37
|
+
'createOffSessionPayment' in gateway &&
|
|
38
|
+
'createSetupSession' in gateway);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.GatewayRegistryService = GatewayRegistryService;
|
|
42
|
+
exports.GatewayRegistryService = GatewayRegistryService = __decorate([
|
|
43
|
+
(0, common_1.Injectable)()
|
|
44
|
+
], GatewayRegistryService);
|
|
45
|
+
//# sourceMappingURL=gateway-registry.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gateway-registry.service.js","sourceRoot":"","sources":["../../src/gateways/gateway-registry.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA4C;AAYrC,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IAA5B;QACY,aAAQ,GAAG,IAAI,GAAG,EAA0B,CAAC;IA+ChE,CAAC;IA5CC,QAAQ,CAAC,OAAuB;QAC9B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IACnD,CAAC;IAMD,GAAG,CAAC,YAAoB;QACtB,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAChD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CACb,oDAAoD,YAAY,GAAG,CACpE,CAAC;QACJ,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAMD,YAAY,CAAC,YAAoB;QAC/B,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QACvC,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC;YACtC,MAAM,IAAI,KAAK,CACb,YAAY,YAAY,uCAAuC,CAChE,CAAC;QACJ,CAAC;QACD,OAAO,OAAmD,CAAC;IAC7D,CAAC;IAGD,YAAY;QACV,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IAC1C,CAAC;IAEO,kBAAkB,CAAC,OAAuB;QAChD,OAAO,CACL,0BAA0B,IAAI,OAAO;YACrC,yBAAyB,IAAI,OAAO;YACpC,oBAAoB,IAAI,OAAO,CAChC,CAAC;IACJ,CAAC;CACF,CAAA;AAhDY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,mBAAU,GAAE;GACA,sBAAsB,CAgDlC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export interface PaymentGateway {
|
|
2
|
+
readonly providerType: string;
|
|
3
|
+
createPaymentSession(params: {
|
|
4
|
+
invoiceId: string;
|
|
5
|
+
amount: number;
|
|
6
|
+
currency: string;
|
|
7
|
+
customerEmail?: string;
|
|
8
|
+
description?: string;
|
|
9
|
+
successUrl: string;
|
|
10
|
+
cancelUrl: string;
|
|
11
|
+
metadata?: Record<string, string>;
|
|
12
|
+
expiresAt?: Date;
|
|
13
|
+
}): Promise<{
|
|
14
|
+
checkoutUrl: string;
|
|
15
|
+
providerPaymentId: string;
|
|
16
|
+
metadata?: Record<string, unknown>;
|
|
17
|
+
}>;
|
|
18
|
+
createRefund(params: {
|
|
19
|
+
providerPaymentId: string;
|
|
20
|
+
amount: number;
|
|
21
|
+
reason?: string;
|
|
22
|
+
}): Promise<{
|
|
23
|
+
providerRefundId: string;
|
|
24
|
+
status: 'PENDING' | 'PROCESSING' | 'SUCCEEDED' | 'FAILED';
|
|
25
|
+
}>;
|
|
26
|
+
getPaymentStatus(providerPaymentId: string): Promise<{
|
|
27
|
+
status: 'pending' | 'processing' | 'succeeded' | 'failed' | 'cancelled';
|
|
28
|
+
amount: number;
|
|
29
|
+
currency: string;
|
|
30
|
+
receiptUrl?: string;
|
|
31
|
+
}>;
|
|
32
|
+
cancelPayment(providerPaymentId: string): Promise<{
|
|
33
|
+
success: boolean;
|
|
34
|
+
}>;
|
|
35
|
+
handleWebhook(params: {
|
|
36
|
+
headers: Record<string, string>;
|
|
37
|
+
body: Buffer;
|
|
38
|
+
}): Promise<PaymentWebhookEvent>;
|
|
39
|
+
}
|
|
40
|
+
export type PaymentWebhookEventType = 'payment.processing' | 'payment.succeeded' | 'payment.failed' | 'payment.cancelled' | 'refund.succeeded' | 'refund.failed' | 'setup.succeeded';
|
|
41
|
+
export interface PaymentWebhookEvent {
|
|
42
|
+
type: PaymentWebhookEventType;
|
|
43
|
+
eventId: string;
|
|
44
|
+
providerPaymentId: string;
|
|
45
|
+
providerRefundId?: string;
|
|
46
|
+
amount: number;
|
|
47
|
+
currency: string;
|
|
48
|
+
receiptUrl?: string;
|
|
49
|
+
providerData: Record<string, unknown>;
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment-gateway.interface.js","sourceRoot":"","sources":["../../src/gateways/payment-gateway.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface RecurringPaymentGateway {
|
|
2
|
+
readonly providerType: string;
|
|
3
|
+
createOrRetrieveCustomer(params: {
|
|
4
|
+
email: string;
|
|
5
|
+
name?: string;
|
|
6
|
+
metadata?: Record<string, string>;
|
|
7
|
+
}): Promise<{
|
|
8
|
+
providerCustomerId: string;
|
|
9
|
+
}>;
|
|
10
|
+
createOffSessionPayment(params: {
|
|
11
|
+
providerCustomerId: string;
|
|
12
|
+
amount: number;
|
|
13
|
+
currency: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
metadata?: Record<string, string>;
|
|
16
|
+
}): Promise<{
|
|
17
|
+
providerPaymentId: string;
|
|
18
|
+
status: 'succeeded' | 'requires_action' | 'failed';
|
|
19
|
+
failureReason?: string;
|
|
20
|
+
clientSecret?: string;
|
|
21
|
+
receiptUrl?: string;
|
|
22
|
+
}>;
|
|
23
|
+
createSetupSession(params: {
|
|
24
|
+
providerCustomerId: string;
|
|
25
|
+
successUrl: string;
|
|
26
|
+
cancelUrl: string;
|
|
27
|
+
metadata?: Record<string, string>;
|
|
28
|
+
}): Promise<{
|
|
29
|
+
setupUrl: string;
|
|
30
|
+
providerSetupId: string;
|
|
31
|
+
}>;
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recurring-payment-gateway.interface.js","sourceRoot":"","sources":["../../src/gateways/recurring-payment-gateway.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { OnModuleInit } from '@nestjs/common';
|
|
2
|
+
import { ModuleRef } from '@nestjs/core';
|
|
3
|
+
import type { RawBodyRequest } from '@nestjs/common';
|
|
4
|
+
import type { Request } from 'express';
|
|
5
|
+
import { GatewayRegistryService } from '../gateway-registry.service';
|
|
6
|
+
import { PaymentService } from '../../services/payment.service';
|
|
7
|
+
import { RefundService } from '../../services/refund.service';
|
|
8
|
+
export declare const PAYMENTS_WEBHOOK = "payments_webhook";
|
|
9
|
+
export declare const PaymentsWebhook: () => <TFunction extends Function, Y>(target: TFunction | object, propertyKey?: string | symbol, descriptor?: TypedPropertyDescriptor<Y>) => void;
|
|
10
|
+
export declare class StripeWebhookController implements OnModuleInit {
|
|
11
|
+
private readonly moduleRef;
|
|
12
|
+
private readonly gatewayRegistry;
|
|
13
|
+
private readonly paymentService;
|
|
14
|
+
private readonly refundService;
|
|
15
|
+
private readonly logger;
|
|
16
|
+
private errorReporter;
|
|
17
|
+
constructor(moduleRef: ModuleRef, gatewayRegistry: GatewayRegistryService, paymentService: PaymentService, refundService: RefundService);
|
|
18
|
+
onModuleInit(): void;
|
|
19
|
+
handleStripeWebhook(req: RawBodyRequest<Request>): Promise<{
|
|
20
|
+
received: boolean;
|
|
21
|
+
}>;
|
|
22
|
+
private routeEvent;
|
|
23
|
+
private handleWithRetry;
|
|
24
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
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 StripeWebhookController_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.StripeWebhookController = exports.PaymentsWebhook = exports.PAYMENTS_WEBHOOK = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const core_1 = require("@nestjs/core");
|
|
19
|
+
const gateway_registry_service_1 = require("../gateway-registry.service");
|
|
20
|
+
const payment_service_1 = require("../../services/payment.service");
|
|
21
|
+
const refund_service_1 = require("../../services/refund.service");
|
|
22
|
+
const constants_1 = require("../../constants");
|
|
23
|
+
const MAX_RETRIES = 3;
|
|
24
|
+
const RETRY_DELAY_MS = 2000;
|
|
25
|
+
exports.PAYMENTS_WEBHOOK = 'payments_webhook';
|
|
26
|
+
const PaymentsWebhook = () => (0, common_1.applyDecorators)((0, common_1.SetMetadata)(exports.PAYMENTS_WEBHOOK, true), (0, common_1.SetMetadata)('isPublic', true), (0, common_1.SetMetadata)('skipTenant', true));
|
|
27
|
+
exports.PaymentsWebhook = PaymentsWebhook;
|
|
28
|
+
let StripeWebhookController = StripeWebhookController_1 = class StripeWebhookController {
|
|
29
|
+
constructor(moduleRef, gatewayRegistry, paymentService, refundService) {
|
|
30
|
+
this.moduleRef = moduleRef;
|
|
31
|
+
this.gatewayRegistry = gatewayRegistry;
|
|
32
|
+
this.paymentService = paymentService;
|
|
33
|
+
this.refundService = refundService;
|
|
34
|
+
this.logger = new common_1.Logger(StripeWebhookController_1.name);
|
|
35
|
+
this.errorReporter = null;
|
|
36
|
+
}
|
|
37
|
+
onModuleInit() {
|
|
38
|
+
try {
|
|
39
|
+
this.errorReporter = this.moduleRef.get(constants_1.WEBHOOK_ERROR_REPORTER, {
|
|
40
|
+
strict: false,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
this.errorReporter = null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async handleStripeWebhook(req) {
|
|
48
|
+
let stripeGateway;
|
|
49
|
+
try {
|
|
50
|
+
stripeGateway = this.gatewayRegistry.get('stripe');
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
throw new common_1.BadRequestException('Stripe gateway is not configured');
|
|
54
|
+
}
|
|
55
|
+
const rawBody = req.rawBody;
|
|
56
|
+
if (!rawBody) {
|
|
57
|
+
throw new common_1.BadRequestException('Missing raw body for webhook verification');
|
|
58
|
+
}
|
|
59
|
+
const headers = {};
|
|
60
|
+
for (const [key, value] of Object.entries(req.headers)) {
|
|
61
|
+
if (typeof value === 'string') {
|
|
62
|
+
headers[key] = value;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
let event;
|
|
66
|
+
try {
|
|
67
|
+
event = await stripeGateway.handleWebhook({
|
|
68
|
+
headers,
|
|
69
|
+
body: rawBody,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
this.logger.error(`Stripe webhook signature verification failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
74
|
+
throw new common_1.BadRequestException('Webhook signature verification failed');
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
await this.routeEvent(event);
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
this.logger.error(`Error processing Stripe webhook event ${event.eventId} (${event.type}): ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
81
|
+
this.errorReporter?.(error, {
|
|
82
|
+
tags: {
|
|
83
|
+
webhookEventType: event.type,
|
|
84
|
+
webhookEventId: event.eventId,
|
|
85
|
+
providerPaymentId: event.providerPaymentId,
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return { received: true };
|
|
90
|
+
}
|
|
91
|
+
async routeEvent(event) {
|
|
92
|
+
switch (event.type) {
|
|
93
|
+
case 'payment.succeeded':
|
|
94
|
+
await this.handleWithRetry(() => this.paymentService.handlePaymentSucceeded(event), event);
|
|
95
|
+
break;
|
|
96
|
+
case 'payment.failed':
|
|
97
|
+
await this.paymentService.handlePaymentFailed(event);
|
|
98
|
+
break;
|
|
99
|
+
case 'payment.processing':
|
|
100
|
+
await this.paymentService.handlePaymentProcessing(event);
|
|
101
|
+
break;
|
|
102
|
+
case 'refund.succeeded':
|
|
103
|
+
await this.refundService.handleRefundSucceeded(event);
|
|
104
|
+
break;
|
|
105
|
+
case 'refund.failed':
|
|
106
|
+
await this.refundService.handleRefundFailed(event);
|
|
107
|
+
break;
|
|
108
|
+
case 'setup.succeeded':
|
|
109
|
+
this.logger.log(`Payment method setup succeeded (event ${event.eventId})`);
|
|
110
|
+
break;
|
|
111
|
+
default:
|
|
112
|
+
this.logger.warn(`Unhandled webhook event type: ${event.type}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
async handleWithRetry(handler, event) {
|
|
116
|
+
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
|
117
|
+
try {
|
|
118
|
+
await handler();
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
if (attempt < MAX_RETRIES) {
|
|
123
|
+
this.logger.warn(`Attempt ${attempt}/${MAX_RETRIES} failed for event ${event.eventId}: ${error instanceof Error ? error.message : 'Unknown error'}. Retrying in ${RETRY_DELAY_MS}ms...`);
|
|
124
|
+
await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY_MS));
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
exports.StripeWebhookController = StripeWebhookController;
|
|
134
|
+
__decorate([
|
|
135
|
+
(0, common_1.Post)('stripe'),
|
|
136
|
+
(0, common_1.HttpCode)(200),
|
|
137
|
+
__param(0, (0, common_1.Req)()),
|
|
138
|
+
__metadata("design:type", Function),
|
|
139
|
+
__metadata("design:paramtypes", [Object]),
|
|
140
|
+
__metadata("design:returntype", Promise)
|
|
141
|
+
], StripeWebhookController.prototype, "handleStripeWebhook", null);
|
|
142
|
+
exports.StripeWebhookController = StripeWebhookController = StripeWebhookController_1 = __decorate([
|
|
143
|
+
(0, common_1.Controller)('webhooks'),
|
|
144
|
+
(0, exports.PaymentsWebhook)(),
|
|
145
|
+
__metadata("design:paramtypes", [core_1.ModuleRef,
|
|
146
|
+
gateway_registry_service_1.GatewayRegistryService,
|
|
147
|
+
payment_service_1.PaymentService,
|
|
148
|
+
refund_service_1.RefundService])
|
|
149
|
+
], StripeWebhookController);
|
|
150
|
+
//# sourceMappingURL=stripe-webhook.controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripe-webhook.controller.js","sourceRoot":"","sources":["../../../src/gateways/stripe/stripe-webhook.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAUwB;AACxB,uCAAyC;AAIzC,0EAAqE;AACrE,oEAAgE;AAChE,kEAA8D;AAC9D,+CAAyD;AAIzD,MAAM,WAAW,GAAG,CAAC,CAAC;AAGtB,MAAM,cAAc,GAAG,IAAI,CAAC;AAGf,QAAA,gBAAgB,GAAG,kBAAkB,CAAC;AAY5C,MAAM,eAAe,GAAG,GAAG,EAAE,CAClC,IAAA,wBAAe,EACb,IAAA,oBAAW,EAAC,wBAAgB,EAAE,IAAI,CAAC,EACnC,IAAA,oBAAW,EAAC,UAAU,EAAE,IAAI,C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AAC,eAAe,iBAAiB,cAAc,OAAO,CACvK,CAAC;oBACF,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC;gBACtE,CAAC;qBAAM,CAAC;oBACN,MAAM,KAAK,CAAC;gBACd,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;CACF,CAAA;AA7JY,0DAAuB;AAyB5B;IAFL,IAAA,aAAI,EAAC,QAAQ,CAAC;IACd,IAAA,iBAAQ,EAAC,GAAG,CAAC;IAEX,WAAA,IAAA,YAAG,GAAE,CAAA;;;;kEAsDP;kCAhFU,uBAAuB;IAFnC,IAAA,mBAAU,EAAC,UAAU,CAAC;IACtB,IAAA,uBAAe,GAAE;qCAQc,gBAAS;QACH,iDAAsB;QACvB,gCAAc;QACf,8BAAa;GAVpC,uBAAuB,CA6JnC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { PaymentGateway, PaymentWebhookEvent } from '../payment-gateway.interface';
|
|
2
|
+
import type { RecurringPaymentGateway } from '../recurring-payment-gateway.interface';
|
|
3
|
+
export declare class StripeGateway implements PaymentGateway, RecurringPaymentGateway {
|
|
4
|
+
readonly providerType = "stripe";
|
|
5
|
+
private readonly stripe;
|
|
6
|
+
private readonly webhookSecret;
|
|
7
|
+
private readonly logger;
|
|
8
|
+
constructor(secretKey: string, webhookSecret?: string);
|
|
9
|
+
createPaymentSession(params: {
|
|
10
|
+
invoiceId: string;
|
|
11
|
+
amount: number;
|
|
12
|
+
currency: string;
|
|
13
|
+
customerEmail?: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
successUrl: string;
|
|
16
|
+
cancelUrl: string;
|
|
17
|
+
metadata?: Record<string, string>;
|
|
18
|
+
expiresAt?: Date;
|
|
19
|
+
}): Promise<{
|
|
20
|
+
checkoutUrl: string;
|
|
21
|
+
providerPaymentId: string;
|
|
22
|
+
metadata?: Record<string, unknown>;
|
|
23
|
+
}>;
|
|
24
|
+
createRefund(params: {
|
|
25
|
+
providerPaymentId: string;
|
|
26
|
+
amount: number;
|
|
27
|
+
reason?: string;
|
|
28
|
+
}): Promise<{
|
|
29
|
+
providerRefundId: string;
|
|
30
|
+
status: 'PENDING' | 'PROCESSING' | 'SUCCEEDED' | 'FAILED';
|
|
31
|
+
}>;
|
|
32
|
+
getPaymentStatus(providerPaymentId: string): Promise<{
|
|
33
|
+
status: 'pending' | 'processing' | 'succeeded' | 'failed' | 'cancelled';
|
|
34
|
+
amount: number;
|
|
35
|
+
currency: string;
|
|
36
|
+
receiptUrl?: string;
|
|
37
|
+
paymentIntentId?: string;
|
|
38
|
+
}>;
|
|
39
|
+
private getCheckoutSessionStatus;
|
|
40
|
+
cancelPayment(providerPaymentId: string): Promise<{
|
|
41
|
+
success: boolean;
|
|
42
|
+
}>;
|
|
43
|
+
handleWebhook(params: {
|
|
44
|
+
headers: Record<string, string>;
|
|
45
|
+
body: Buffer;
|
|
46
|
+
}): Promise<PaymentWebhookEvent>;
|
|
47
|
+
createOrRetrieveCustomer(params: {
|
|
48
|
+
email: string;
|
|
49
|
+
name?: string;
|
|
50
|
+
metadata?: Record<string, string>;
|
|
51
|
+
}): Promise<{
|
|
52
|
+
providerCustomerId: string;
|
|
53
|
+
}>;
|
|
54
|
+
createOffSessionPayment(params: {
|
|
55
|
+
providerCustomerId: string;
|
|
56
|
+
amount: number;
|
|
57
|
+
currency: string;
|
|
58
|
+
description?: string;
|
|
59
|
+
metadata?: Record<string, string>;
|
|
60
|
+
}): Promise<{
|
|
61
|
+
providerPaymentId: string;
|
|
62
|
+
status: 'succeeded' | 'requires_action' | 'failed';
|
|
63
|
+
failureReason?: string;
|
|
64
|
+
clientSecret?: string;
|
|
65
|
+
receiptUrl?: string;
|
|
66
|
+
}>;
|
|
67
|
+
createSetupSession(params: {
|
|
68
|
+
providerCustomerId: string;
|
|
69
|
+
successUrl: string;
|
|
70
|
+
cancelUrl: string;
|
|
71
|
+
metadata?: Record<string, string>;
|
|
72
|
+
}): Promise<{
|
|
73
|
+
setupUrl: string;
|
|
74
|
+
providerSetupId: string;
|
|
75
|
+
}>;
|
|
76
|
+
private normalizeWebhookEvent;
|
|
77
|
+
private handleCheckoutSessionCompleted;
|
|
78
|
+
private handleSetupSessionCompleted;
|
|
79
|
+
private handlePaymentIntentProcessing;
|
|
80
|
+
private handlePaymentIntentFailed;
|
|
81
|
+
private handleChargeRefunded;
|
|
82
|
+
private mapPaymentIntentStatus;
|
|
83
|
+
private mapRefundStatus;
|
|
84
|
+
}
|