paystack-nestjs
Version:
A library for integrating Paystack with NestJS. Supports webhooks
51 lines • 2.75 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
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;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PaystackWebhookController = void 0;
const common_1 = require("@nestjs/common");
const decorators_1 = require("./decorators");
const payload_service_1 = require("./payload.service");
const webhook_service_1 = require("./webhook.service");
let PaystackWebhookController = class PaystackWebhookController {
constructor(config, payloadService, webhookService) {
var _a;
this.config = config;
this.payloadService = payloadService;
this.webhookService = webhookService;
this.requestBodyProperty =
((_a = this.config.webhookConfig) === null || _a === void 0 ? void 0 : _a.requestBodyProperty) || 'body';
}
async handlePaystackEvents(signature, req) {
const body = req[this.requestBodyProperty];
const eventPayload = this.payloadService.tryHydratePayload(signature, body);
await this.webhookService.handleWebhookEvent(eventPayload);
}
};
__decorate([
(0, common_1.Post)(),
(0, common_1.HttpCode)(common_1.HttpStatus.OK),
__param(0, (0, common_1.Headers)('x-paystack-signature')),
__param(1, (0, common_1.Request)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Object]),
__metadata("design:returntype", Promise)
], PaystackWebhookController.prototype, "handlePaystackEvents", null);
PaystackWebhookController = __decorate([
(0, common_1.Controller)('/paystack/webhook'),
__param(0, (0, decorators_1.InjectPaystackModuleConfig)()),
__metadata("design:paramtypes", [Object, payload_service_1.PaystackPayloadService,
webhook_service_1.PaystackWebhookService])
], PaystackWebhookController);
exports.PaystackWebhookController = PaystackWebhookController;
//# sourceMappingURL=webhook.controller.js.map