Skip to content

Commit

Permalink
Fix notification signature generation
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkGL committed Mar 24, 2022
1 parent 2948376 commit 67136c7
Show file tree
Hide file tree
Showing 44 changed files with 296 additions and 121 deletions.
5 changes: 3 additions & 2 deletions lib/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
export { DbCalculation } from "./models/directbilling/service/db.calculation";
export { DbProvider } from "./models/directbilling/service/db.provider";
export { DbProvider, DbProviderID } from "./models/directbilling/db.provider";
export { DbService, DbServiceNotify } from "./models/directbilling/service/db.service";
export { PartialDbService } from "./models/directbilling/service/partial.db.service";
export { DbGenerationResponse } from "./models/directbilling/transaction/db.generation.response";
export { DbTransactionRequest } from "./models/directbilling/transaction/db.transaction.request";
export { DbTransactionStatus } from "./models/directbilling/transaction/db.transaction.status";
export { DbTransaction } from "./models/directbilling/transaction/db.transaction";
export { PartialDbTransaction } from "./models/directbilling/transaction/partial.db.transaction";
export { DBServiceStatus } from "./models/directbilling/service/db.service.status";
export { PaginatedResponse } from "./models/response/paginated.response";
export { AmountType } from "./models/amount.type";
export { ServiceStatus } from "./models/service.status";
export { SmsNumber } from "./models/sms/service/sms.number";
export { SmsService } from "./models/sms/service/sms.service";
export { SmsServiceType } from "./models/sms/service/sms.service.type";
export { SmsTransaction } from "./models/sms/transaction/sms.transaction";
export { VerificationResponse } from "./models/sms/verification.response";
export { SMSServiceStatus } from "./models/sms/service/sms.service.status";
export { DirectBilling } from "./payments/directbilling";
export { Sms } from "./payments/sms";
export { SmsXml } from "./payments/sms.xml";
11 changes: 7 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SmsXml = exports.Sms = exports.DirectBilling = exports.SmsServiceType = exports.ServiceStatus = exports.AmountType = exports.DbTransactionStatus = exports.DbProvider = void 0;
var db_provider_1 = require("./models/directbilling/service/db.provider");
exports.SmsXml = exports.Sms = exports.DirectBilling = exports.SMSServiceStatus = exports.SmsServiceType = exports.AmountType = exports.DBServiceStatus = exports.DbTransactionStatus = exports.DbProviderID = exports.DbProvider = void 0;
var db_provider_1 = require("./models/directbilling/db.provider");
Object.defineProperty(exports, "DbProvider", { enumerable: true, get: function () { return db_provider_1.DbProvider; } });
Object.defineProperty(exports, "DbProviderID", { enumerable: true, get: function () { return db_provider_1.DbProviderID; } });
var db_transaction_status_1 = require("./models/directbilling/transaction/db.transaction.status");
Object.defineProperty(exports, "DbTransactionStatus", { enumerable: true, get: function () { return db_transaction_status_1.DbTransactionStatus; } });
var db_service_status_1 = require("./models/directbilling/service/db.service.status");
Object.defineProperty(exports, "DBServiceStatus", { enumerable: true, get: function () { return db_service_status_1.DBServiceStatus; } });
var amount_type_1 = require("./models/amount.type");
Object.defineProperty(exports, "AmountType", { enumerable: true, get: function () { return amount_type_1.AmountType; } });
var service_status_1 = require("./models/service.status");
Object.defineProperty(exports, "ServiceStatus", { enumerable: true, get: function () { return service_status_1.ServiceStatus; } });
var sms_service_type_1 = require("./models/sms/service/sms.service.type");
Object.defineProperty(exports, "SmsServiceType", { enumerable: true, get: function () { return sms_service_type_1.SmsServiceType; } });
var sms_service_status_1 = require("./models/sms/service/sms.service.status");
Object.defineProperty(exports, "SMSServiceStatus", { enumerable: true, get: function () { return sms_service_status_1.SMSServiceStatus; } });
// Payments
var directbilling_1 = require("./payments/directbilling");
Object.defineProperty(exports, "DirectBilling", { enumerable: true, get: function () { return directbilling_1.DirectBilling; } });
Expand Down
12 changes: 12 additions & 0 deletions lib/models/directbilling/db.provider.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export declare enum DbProvider {
PLAY = "play",
PLUS = "plus",
ORANGE = "orange",
T_MOBILE = "t-mobile"
}
export declare enum DbProviderID {
ORANGE = 1,
PLUS = 2,
PLAY = 3,
T_MOBILE = 4
}
17 changes: 17 additions & 0 deletions lib/models/directbilling/db.provider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DbProviderID = exports.DbProvider = void 0;
var DbProvider;
(function (DbProvider) {
DbProvider["PLAY"] = "play";
DbProvider["PLUS"] = "plus";
DbProvider["ORANGE"] = "orange";
DbProvider["T_MOBILE"] = "t-mobile";
})(DbProvider = exports.DbProvider || (exports.DbProvider = {}));
var DbProviderID;
(function (DbProviderID) {
DbProviderID[DbProviderID["ORANGE"] = 1] = "ORANGE";
DbProviderID[DbProviderID["PLUS"] = 2] = "PLUS";
DbProviderID[DbProviderID["PLAY"] = 3] = "PLAY";
DbProviderID[DbProviderID["T_MOBILE"] = 4] = "T_MOBILE";
})(DbProviderID = exports.DbProviderID || (exports.DbProviderID = {}));
2 changes: 1 addition & 1 deletion lib/models/directbilling/service/db.calculation.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DbProvider } from './db.provider';
import { DbProvider } from '../db.provider';
export interface DbCalculation {
[DbProvider.PLAY]: DbCalculationAmount;
[DbProvider.PLUS]: DbCalculationAmount;
Expand Down
2 changes: 1 addition & 1 deletion lib/models/directbilling/service/db.calculation.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const db_provider_1 = require("./db.provider");
const db_provider_1 = require("../db.provider");
6 changes: 3 additions & 3 deletions lib/models/directbilling/service/db.service.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ServiceStatus } from '../../service.status';
import { DbProvider } from './db.provider';
import { DBServiceStatus } from '../service/db.service.status';
import { DbProvider } from '../db.provider';
export interface DbService {
id: string;
name: string;
suffix: string;
status: ServiceStatus;
status: DBServiceStatus;
api?: DbServiceNotify;
providers: DbServiceProviders;
commissions: DbServiceProvidersCommission;
Expand Down
2 changes: 1 addition & 1 deletion lib/models/directbilling/service/db.service.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const db_provider_1 = require("./db.provider");
const db_provider_1 = require("../db.provider");
6 changes: 6 additions & 0 deletions lib/models/directbilling/service/db.service.status.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export declare enum DBServiceStatus {
SERVICE_NEW = "service_db_new",
SERVICE_ACTIVE = "service_db_active",
SERVICE_REJECTED = "service_db_rejected",
SERVICE_ONGOING_REGISTRATION = "service_db_ongoing_registration"
}
10 changes: 10 additions & 0 deletions lib/models/directbilling/service/db.service.status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DBServiceStatus = void 0;
var DBServiceStatus;
(function (DBServiceStatus) {
DBServiceStatus["SERVICE_NEW"] = "service_db_new";
DBServiceStatus["SERVICE_ACTIVE"] = "service_db_active";
DBServiceStatus["SERVICE_REJECTED"] = "service_db_rejected";
DBServiceStatus["SERVICE_ONGOING_REGISTRATION"] = "service_db_ongoing_registration";
})(DBServiceStatus = exports.DBServiceStatus || (exports.DBServiceStatus = {}));
4 changes: 2 additions & 2 deletions lib/models/directbilling/service/partial.db.service.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ServiceStatus } from '../../service.status';
import { DBServiceStatus } from './db.service.status';
export interface PartialDbService {
id: string;
name: string;
suffix: string;
status: ServiceStatus;
status: DBServiceStatus;
created_at: Date;
}
18 changes: 18 additions & 0 deletions lib/models/directbilling/transaction/db.notifications.request.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { DbServiceNotify } from '../service/db.service';
import { DbTransactionStatus } from '../transaction/db.transaction.status';
import { DbProviderID } from '../db.provider';
export interface DbNotificationRequest {
id: string;
service_id: number;
status: DbTransactionStatus;
values?: {
net?: number;
gross?: number;
partner?: number;
};
returns?: DbServiceNotify;
control?: string;
number_from?: string;
provider: DbProviderID;
signature?: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
2 changes: 1 addition & 1 deletion lib/models/directbilling/transaction/db.transaction.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DbTransactionStatus } from './db.transaction.status';
import { DbProvider } from '../service/db.provider';
import { DbProvider } from '../db.provider';
export interface DbTransaction {
id: string;
status: DbTransactionStatus;
Expand Down
10 changes: 6 additions & 4 deletions lib/models/directbilling/transaction/db.transaction.status.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export declare enum DbTransactionStatus {
SERVICE_DB_NEW = "service_db_new",
SERVICE_DB_ACTIVE = "service_db_active",
SERVICE_DB_REJECTED = "service_db_rejected",
SERVICE_DB_ONGOING_REGISTRATION = "service_db_ongoing_registration"
TRANSACTION_DB_NEW = "transaction_db_new",
TRANSACTION_DB_CONFIRMED = "transaction_db_confirmed",
TRANSACTION_DB_REJECTED = "transaction_db_rejected",
TRANSACTION_DB_CANCELED = "transaction_db_canceled",
TRANSACTION_DB_PAYED = "transaction_db_payed",
TRANSACTION_DB_GENERATE_ERROR = "transaction_db_generate_error"
}
10 changes: 6 additions & 4 deletions lib/models/directbilling/transaction/db.transaction.status.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
exports.DbTransactionStatus = void 0;
var DbTransactionStatus;
(function (DbTransactionStatus) {
DbTransactionStatus["SERVICE_DB_NEW"] = "service_db_new";
DbTransactionStatus["SERVICE_DB_ACTIVE"] = "service_db_active";
DbTransactionStatus["SERVICE_DB_REJECTED"] = "service_db_rejected";
DbTransactionStatus["SERVICE_DB_ONGOING_REGISTRATION"] = "service_db_ongoing_registration";
DbTransactionStatus["TRANSACTION_DB_NEW"] = "transaction_db_new";
DbTransactionStatus["TRANSACTION_DB_CONFIRMED"] = "transaction_db_confirmed";
DbTransactionStatus["TRANSACTION_DB_REJECTED"] = "transaction_db_rejected";
DbTransactionStatus["TRANSACTION_DB_CANCELED"] = "transaction_db_canceled";
DbTransactionStatus["TRANSACTION_DB_PAYED"] = "transaction_db_payed";
DbTransactionStatus["TRANSACTION_DB_GENERATE_ERROR"] = "transaction_db_generate_error";
})(DbTransactionStatus = exports.DbTransactionStatus || (exports.DbTransactionStatus = {}));
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DbProvider } from '../service/db.provider';
import { DbProvider } from '../db.provider';
import { DbTransactionStatus } from './db.transaction.status';
export interface PartialDbTransaction {
id: string;
Expand Down
4 changes: 2 additions & 2 deletions lib/models/sms/service/sms.service.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { SmsServiceType } from './sms.service.type';
import { ServiceStatus } from '../../service.status';
import { SMSServiceStatus } from './sms.service.status';
export interface SmsService {
id: number;
type: SmsServiceType;
status: ServiceStatus;
status: SMSServiceStatus;
name: string;
prefix: string;
suffix: string;
Expand Down
10 changes: 10 additions & 0 deletions lib/models/sms/service/sms.service.status.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export declare enum SMSServiceStatus {
SERVICE_NEW = "service_new",
SERVICE_ACTIVE = "service_active",
SERVICE_BLOCKED = "service_blocked",
SERVICE_DELETED = "service_deleted",
SERVICE_SECOND_VERIFY = "service_second_verify",
SERVICE_REJECTED = "service_rejected",
SERVICE_VERIFY = "service_verify",
SERVICE_ONGOING_REGISTRATION = "service_ongoing_registration"
}
14 changes: 14 additions & 0 deletions lib/models/sms/service/sms.service.status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SMSServiceStatus = void 0;
var SMSServiceStatus;
(function (SMSServiceStatus) {
SMSServiceStatus["SERVICE_NEW"] = "service_new";
SMSServiceStatus["SERVICE_ACTIVE"] = "service_active";
SMSServiceStatus["SERVICE_BLOCKED"] = "service_blocked";
SMSServiceStatus["SERVICE_DELETED"] = "service_deleted";
SMSServiceStatus["SERVICE_SECOND_VERIFY"] = "service_second_verify";
SMSServiceStatus["SERVICE_REJECTED"] = "service_rejected";
SMSServiceStatus["SERVICE_VERIFY"] = "service_verify";
SMSServiceStatus["SERVICE_ONGOING_REGISTRATION"] = "service_ongoing_registration";
})(SMSServiceStatus = exports.SMSServiceStatus || (exports.SMSServiceStatus = {}));
2 changes: 2 additions & 0 deletions lib/payments/directbilling.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { PartialDbTransaction } from '../models/directbilling/transaction/partia
import { DbTransaction } from '../models/directbilling/transaction/db.transaction';
import { DbGenerationResponse } from '../models/directbilling/transaction/db.generation.response';
import { DbTransactionRequest } from '../models/directbilling/transaction/db.transaction.request';
import { DbNotificationRequest } from '../models/directbilling/transaction/db.notifications.request';
export declare class DirectBilling {
private readonly key;
private readonly password;
Expand All @@ -21,4 +22,5 @@ export declare class DirectBilling {
createTransaction(serviceId: number, key: string, request: DbTransactionRequest): Promise<DbGenerationResponse | undefined>;
checkNotification(key: string, body: any): DbTransaction | undefined;
generateSignature(key: string, request: DbTransactionRequest): string;
generateSignatureNotification(key: string, request: DbNotificationRequest): string;
}
36 changes: 27 additions & 9 deletions lib/payments/directbilling.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class DirectBilling {
});
}
/*
https://docs-new.simpay.pl/typescript/?typescript#directbilling-pobieranie-listy-uslug
https://docs.simpay.pl/typescript/?typescript#directbilling-pobieranie-listy-uslug
*/
getServices() {
return __awaiter(this, void 0, void 0, function* () {
Expand Down Expand Up @@ -59,7 +59,7 @@ class DirectBilling {
});
}
/*
https://docs-new.simpay.pl/typescript/?typescript#directbilling-pobieranie-informacji-o-usludze
https://docs.simpay.pl/typescript/?typescript#directbilling-pobieranie-informacji-o-usludze
*/
getService(id) {
return __awaiter(this, void 0, void 0, function* () {
Expand All @@ -74,15 +74,15 @@ class DirectBilling {
});
}
/*
https://docs-new.simpay.pl/typescript/?typescript#directbilling-kalkulacja-prowizji
https://docs.simpay.pl/typescript/?typescript#directbilling-kalkulacja-prowizji
*/
calculateCommission(serviceId, amount) {
return __awaiter(this, void 0, void 0, function* () {
return (yield this.client.get(`/${serviceId}/calculate?amount=${amount}`)).data.data;
});
}
/*
https://docs-new.simpay.pl/typescript/?typescript#directbilling-pobieranie-listy-transakcji
https://docs.simpay.pl/typescript/?typescript#directbilling-pobieranie-listy-transakcji
*/
getTransactions(serviceId) {
return __awaiter(this, void 0, void 0, function* () {
Expand Down Expand Up @@ -118,7 +118,7 @@ class DirectBilling {
});
}
/*
https://docs-new.simpay.pl/typescript/?typescript#directbilling-pobieranie-informacji-o-transakcji
https://docs.simpay.pl/typescript/?typescript#directbilling-pobieranie-informacji-o-transakcji
*/
getTransaction(serviceId, transactionId) {
return __awaiter(this, void 0, void 0, function* () {
Expand All @@ -129,7 +129,7 @@ class DirectBilling {
});
}
/*
https://docs-new.simpay.pl/typescript/?typescript#directbilling-generowanie-transakcji
https://docs.simpay.pl/typescript/?typescript#directbilling-generowanie-transakcji
*/
createTransaction(serviceId, key, request) {
return __awaiter(this, void 0, void 0, function* () {
Expand All @@ -138,16 +138,16 @@ class DirectBilling {
});
}
/*
https://docs-new.simpay.pl/shell/?shell#directbilling-generowanie-transakcji
https://docs.simpay.pl/shell/?shell#directbilling-generowanie-transakcji
*/
checkNotification(key, body) {
const signature = this.generateSignature(key, body);
const signature = this.generateSignatureNotification(key, body);
if (body.signature !== signature)
return undefined;
return body;
}
/*
https://docs-new.simpay.pl/shell/?shell#directbilling-generowanie-transakcji
https://docs.simpay.pl/shell/?shell#directbilling-generowanie-transakcji
*/
generateSignature(key, request) {
var _a, _b;
Expand All @@ -163,5 +163,23 @@ class DirectBilling {
].filter(e => e !== undefined && e !== null);
return hashing_1.Hashing.sha256(elements.join('|'));
}
generateSignatureNotification(key, request) {
var _a, _b, _c, _d, _e;
const elements = [
request.id,
request.service_id,
request.status,
(_a = request.values) === null || _a === void 0 ? void 0 : _a.net,
(_b = request.values) === null || _b === void 0 ? void 0 : _b.gross,
(_c = request.values) === null || _c === void 0 ? void 0 : _c.partner,
(_d = request.returns) === null || _d === void 0 ? void 0 : _d.success,
(_e = request.returns) === null || _e === void 0 ? void 0 : _e.failure,
request.control,
request.number_from,
request.provider,
key
].filter(e => e !== undefined && e !== null);
return hashing_1.Hashing.sha256(elements.join('|'));
}
}
exports.DirectBilling = DirectBilling;
Loading

0 comments on commit 67136c7

Please sign in to comment.