Skip to content

Commit

Permalink
Additional headers with informations
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkGL committed Mar 31, 2023
1 parent 95d60a2 commit fb21c02
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 31 deletions.
2 changes: 2 additions & 0 deletions lib/payments/directbilling.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class DirectBilling {
headers: {
'X-SIM-KEY': this.key,
'X-SIM-PASSWORD': this.password,
'X-SIM-VERSION': '2.2.2',
'X-SIM-PLATFORM': 'TYPESCRIPT',
}
});
}
Expand Down
2 changes: 2 additions & 0 deletions lib/payments/sms.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Sms {
headers: {
'X-SIM-KEY': this.key,
'X-SIM-PASSWORD': this.password,
'X-SIM-VERSION': '2.2.2',
'X-SIM-PLATFORM': 'TYPESCRIPT',
}
});
}
Expand Down
5 changes: 3 additions & 2 deletions lib/tests/directbilling.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ const run = () => __awaiter(void 0, void 0, void 0, function* () {
// https://docs.simpay.pl/pl/typescript/?typescript#directbilling-kalkulacja-prowizji
console.log(yield db.calculateCommission(158, 10.00));
// https://docs.simpay.pl/pl/typescript/?typescript#directbilling-pobieranie-listy-transakcji
console.log(yield db.getTransactions(158));
const transactionsList = yield db.getTransactions(158);
console.log(transactionsList);
console.log(yield db.getTransactionsPaginated(158, 1, 100));
// https://docs.simpay.pl/pl/typescript/?typescript#directbilling-pobieranie-informacji-o-transakcji
console.log(yield db.getTransaction(158, '559911'));
console.log(yield db.getTransaction(158, transactionsList === null || transactionsList === void 0 ? void 0 : transactionsList[0].id));
// https://docs.simpay.pl/pl/typescript/?typescript#directbilling-generowanie-transakcji
console.log(yield db.createTransaction(158, 'key', {
amount: 10.00,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "simpay-typescript-api",
"author": "Rafał Więcek",
"version": "2.2.1",
"version": "2.2.2",
"description": "SimPay.pl API",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
14 changes: 8 additions & 6 deletions src/payments/directbilling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ export class DirectBilling {
headers: {
'X-SIM-KEY': this.key,
'X-SIM-PASSWORD': this.password,
'X-SIM-VERSION': '2.2.2',
'X-SIM-PLATFORM': 'TYPESCRIPT',
}
});
}

/*
https://docs.simpay.pl/typescript/?typescript#directbilling-pobieranie-listy-uslug
https://docs.simpay.pl/pl/typescript/?typescript#directbilling-pobieranie-listy-uslug
*/
async getServices(): Promise<PartialDbService[]> {
const result = [];
Expand Down Expand Up @@ -71,7 +73,7 @@ export class DirectBilling {
}

/*
https://docs.simpay.pl/typescript/?typescript#directbilling-pobieranie-informacji-o-usludze
https://docs.simpay.pl/pl/typescript/?typescript#directbilling-pobieranie-informacji-o-usludze
*/
async getService(id: number): Promise<DbService | undefined> {
try {
Expand All @@ -86,14 +88,14 @@ export class DirectBilling {
}

/*
https://docs.simpay.pl/typescript/?typescript#directbilling-kalkulacja-prowizji
https://docs.simpay.pl/pl/typescript/?typescript#directbilling-kalkulacja-prowizji
*/
async calculateCommission(serviceId: number, amount: number): Promise<DbCalculation | undefined> {
return (await this.client.get(`/${serviceId}/calculate?amount=${amount}`)).data.data;
}

/*
https://docs.simpay.pl/typescript/?typescript#directbilling-pobieranie-listy-transakcji
https://docs.simpay.pl/pl/typescript/?typescript#directbilling-pobieranie-listy-transakcji
*/
async getTransactions(serviceId: number): Promise<PartialDbTransaction[]> {
const result = [];
Expand Down Expand Up @@ -137,7 +139,7 @@ export class DirectBilling {
}

/*
https://docs.simpay.pl/typescript/?typescript#directbilling-pobieranie-informacji-o-transakcji
https://docs.simpay.pl/pl/typescript/?typescript#directbilling-pobieranie-informacji-o-transakcji
*/
async getTransaction(serviceId: number, transactionId: string): Promise<DbTransaction | undefined> {
const transaction = (await this.client.get(`/${serviceId}/transactions/${transactionId}`)).data.data;
Expand All @@ -149,7 +151,7 @@ export class DirectBilling {
}

/*
https://docs.simpay.pl/typescript/?typescript#directbilling-generowanie-transakcji
https://docs.simpay.pl/pl/typescript/?typescript#directbilling-generowanie-transakcji
*/
async createTransaction(serviceId: number, key: string, request: DbTransactionRequest): Promise<DbGenerationResponse | undefined> {
request.signature = this.generateSignature(key, request);
Expand Down
20 changes: 11 additions & 9 deletions src/payments/sms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ export class Sms {
headers: {
'X-SIM-KEY': this.key,
'X-SIM-PASSWORD': this.password,
'X-SIM-VERSION': '2.2.2',
'X-SIM-PLATFORM': 'TYPESCRIPT',
}
});
}

/*
https://docs.simpay.pl/typescript/?typescript#sms-pobieranie-listy-uslug
https://docs.simpay.pl/pl/typescript/?typescript#sms-pobieranie-listy-uslug
*/
async getServices(): Promise<SmsService[]> {
const result = [];
Expand Down Expand Up @@ -66,7 +68,7 @@ export class Sms {
}

/*
https://docs.simpay.pl/typescript/?typescript#sms-pobieranie-informacji-o-usludze
https://docs.simpay.pl/pl/typescript/?typescript#sms-pobieranie-informacji-o-usludze
*/
async getService(id: number): Promise<SmsService | undefined> {
const service = (await this.client.get(`/${id}`)).data.data;
Expand All @@ -77,7 +79,7 @@ export class Sms {
}

/*
https://docs.simpay.pl/typescript/?typescript#sms-pobieranie-listy-transakcji
https://docs.simpay.pl/pl/typescript/?typescript#sms-pobieranie-listy-transakcji
*/
async getTransactions(serviceId: number): Promise<SmsTransaction[]> {
const result = [];
Expand Down Expand Up @@ -119,7 +121,7 @@ export class Sms {
}

/*
https://docs.simpay.pl/typescript/?typescript#sms-pobieranie-informacji-o-transakcji
https://docs.simpay.pl/pl/typescript/?typescript#sms-pobieranie-informacji-o-transakcji
*/
async getTransaction(serviceId: number, transactionId: number): Promise<SmsTransaction | undefined> {
const transaction = (await this.client.get(`/${serviceId}/transactions/${transactionId}`)).data.data;
Expand All @@ -130,7 +132,7 @@ export class Sms {
}

/*
https://docs.simpay.pl/typescript/?typescript#sms-pobieranie-dostepnych-numerow-dla-uslugi
https://docs.simpay.pl/pl/typescript/?typescript#sms-pobieranie-dostepnych-numerow-dla-uslugi
*/
async getServiceNumbers(serviceId: number): Promise<SmsNumber[]> {
const result = [];
Expand Down Expand Up @@ -160,14 +162,14 @@ export class Sms {
}

/*
https://docs.simpay.pl/typescript/?typescript#sms-informacji-o-pojedynczym-numerze-uslugi
https://docs.simpay.pl/pl/typescript/?typescript#sms-informacji-o-pojedynczym-numerze-uslugi
*/
async getServiceNumber(serviceId: number, number: number): Promise<SmsNumber> {
return (await this.client.get(`/${serviceId}/numbers/${number}`)).data.data;
}

/*
https://docs.simpay.pl/typescript/?typescript#sms-pobieranie-wszystkich-dostepnych-numerow
https://docs.simpay.pl/pl/typescript/?typescript#sms-pobieranie-wszystkich-dostepnych-numerow
*/
async getNumbers(): Promise<SmsNumber[]> {
const result = [];
Expand Down Expand Up @@ -197,14 +199,14 @@ export class Sms {
}

/*
https://docs.simpay.pl/typescript/?typescript#sms-pobieranie-pojedynczego-numeru-sms
https://docs.simpay.pl/pl/typescript/?typescript#sms-pobieranie-pojedynczego-numeru-sms
*/
async getNumber(number: number): Promise<SmsNumber | undefined> {
return (await this.client.get(`/numbers/${number}`)).data.data;
}

/*
https://docs.simpay.pl/typescript/?typescript#sms-weryfikacja-poprawnosci-kodu
https://docs.simpay.pl/pl/typescript/?typescript#sms-weryfikacja-poprawnosci-kodu
*/
async verifySmsCode(serviceId: number, code: string, number?: number): Promise<VerificationResponse | undefined> {
const response = (await this.client.post(`/${serviceId}`, { code, number })).data.data;
Expand Down
8 changes: 4 additions & 4 deletions src/payments/sms.xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class SmsXml {
constructor(private apiKey: string) {}

/*
https://docs.simpay.pl/typescript/?typescript#smsxml-odbieranie-informacji-o-sms
https://docs.simpay.pl/pl/typescript/?typescript#smsxml-odbieranie-informacji-o-sms
*/
checkParameters(map: any): boolean {
for (const param of SmsXml.params) {
Expand All @@ -46,7 +46,7 @@ export class SmsXml {
}

/*
https://docs.simpay.pl/typescript/?typescript#smsxml-odbieranie-informacji-o-sms
https://docs.simpay.pl/pl/typescript/?typescript#smsxml-odbieranie-informacji-o-sms
*/
generateCode(): string {
let result = '';
Expand All @@ -59,14 +59,14 @@ export class SmsXml {
}

/*
https://docs.simpay.pl/typescript/?typescript#smsxml-odbieranie-informacji-o-sms
https://docs.simpay.pl/pl/typescript/?typescript#smsxml-odbieranie-informacji-o-sms
*/
getSmsValue(phone: string): number {
return SmsXml.codes[phone];
}

/*
https://docs.simpay.pl/typescript/?typescript#smsxml-odbieranie-informacji-o-sms
https://docs.simpay.pl/pl/typescript/?typescript#smsxml-odbieranie-informacji-o-sms
*/
generateXml(text: string) {
return `<?xml version="1.0" encoding="UTF-8"?><sms-response>${text.normalize('NFKD')}<sms-text></sms-text></sms-response>`;
Expand Down
18 changes: 9 additions & 9 deletions src/tests/sms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@ import { Sms } from "../payments/sms";
const run = async () => {
const sms = new Sms('0b4dca15', '3eea38f407073ff0abff956b57d71783');

// https://docs.simpay.pl/typescript/?typescript#sms-pobieranie-listy-uslug
// https://docs.simpay.pl/pl/typescript/?typescript#sms-pobieranie-listy-uslug
console.log( await sms.getServices() );
console.log( await sms.getServicesPaginated(1, 100));

// https://docs.simpay.pl/typescript/?typescript#sms-pobieranie-informacji-o-usludze
// https://docs.simpay.pl/pl/typescript/?typescript#sms-pobieranie-informacji-o-usludze
console.log( await sms.getService(3549));

// https://docs.simpay.pl/typescript/?typescript#sms-pobieranie-listy-transakcji
// https://docs.simpay.pl/pl/typescript/?typescript#sms-pobieranie-listy-transakcji
console.log( await sms.getTransactions(3549));
console.log( await sms.getTransactionsPaginated(3549, 1, 100));

// https://docs.simpay.pl/typescript/?typescript#sms-pobieranie-informacji-o-transakcji
// https://docs.simpay.pl/pl/typescript/?typescript#sms-pobieranie-informacji-o-transakcji
console.log( await sms.getTransaction(3549, 2216609));

// https://docs.simpay.pl/typescript/?typescript#sms-pobieranie-dostepnych-numerow-dla-uslugi
// https://docs.simpay.pl/pl/typescript/?typescript#sms-pobieranie-dostepnych-numerow-dla-uslugi
console.log( await sms.getServiceNumbers(3549));
console.log( await sms.getServiceNumbersPaginated(3549, 1, 100));

// https://docs.simpay.pl/typescript/?typescript#sms-informacji-o-pojedynczym-numerze-uslugi
// https://docs.simpay.pl/pl/typescript/?typescript#sms-informacji-o-pojedynczym-numerze-uslugi
console.log( await sms.getServiceNumber(3549, 7055));

// https://docs.simpay.pl/typescript/?typescript#sms-pobieranie-wszystkich-dostepnych-numerow
// https://docs.simpay.pl/pl/typescript/?typescript#sms-pobieranie-wszystkich-dostepnych-numerow
console.log( await sms.getNumbers());
console.log( await sms.getNumbersPaginated(1, 100));

// https://docs.simpay.pl/typescript/?typescript#sms-pobieranie-pojedynczego-numeru-sms
// https://docs.simpay.pl/pl/typescript/?typescript#sms-pobieranie-pojedynczego-numeru-sms
console.log( await sms.getNumber(7055));

// https://docs.simpay.pl/typescript/?typescript#sms-weryfikacja-poprawnosci-kodu
// https://docs.simpay.pl/pl/typescript/?typescript#sms-weryfikacja-poprawnosci-kodu
console.log( await sms.verifySmsCode(3549, '81FFC5', 7055));
console.log( await sms.verifySmsCode(3549, '81FFC5'));
};
Expand Down

0 comments on commit fb21c02

Please sign in to comment.