@sealcode/przelewy24
v0.1.2
Published
przelewy24 integration helper
Downloads
2
Readme
Przelewy24 Integrator
Usage
- Add the P24SessionsCollection to your app:
lang=js, name=src/back/collections/p24-sessions.ts
import { P24SessionsCollection } from "@sealcode/przelewy24";
export default class P24Sessions extends P24SessionsCollection {}
- Create an instance of the P24 class somewhere in your code:
lang=js
import {
P24Flow,
P24SealiousStorage,
Przelewy24,
P24Session,
P24NotifBody,
} from "@sealcode/przelewy24";
import _locreq from "locreq";
import { P24Sessions } from "./collections/collections";
import { P24StatusCallbackURL } from "./routes/urls";
const locreq = _locreq(__dirname);
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
const secrets = locreq("secrets.json") as Record<
"przelewy24",
{ base_url: string; posid: number; api_key: string; crc: string }
>;
const P24 = new Przelewy24<App>(
secrets.przelewy24.base_url,
process.env.SEALIOUS_BASE_URL || "http://localhost:8080",
P24StatusCallbackURL,
{
posid: secrets.przelewy24.posid,
apiKey: secrets.przelewy24.api_key,
crc: secrets.przelewy24.crc,
},
new P24SealiousStorage(P24Sessions),
{
testFlow: new P24Flow(
(session: P24Session) => `/status/${session.id}`,
async (app: App, paid: session: P24Session, notif: P24NotifBody) => {
console.log("PAID!", session, notif);
}
),
}
);
export default P24;
- Mount the status handler URL to your routes:
import { Context } from "koa";
import { Page } from "@sealcode/sealgen";
import P24 from "../../przelewy24";
export const actionName = "P24Status";
export default new (class P24StatusPage extends Page {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async canAccess(_: Context) {
return { canAccess: true, message: "" };
}
async render(ctx: Context) {
await P24.handleStatusRequest(ctx.query);
return "OK";
}
})();