@edutecka-mz/edpay-sdk 0.0.0-stage → 1.0.1
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/LICENSE +21 -0
- package/README.md +133 -2
- package/dist/client.d.ts +22 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +88 -0
- package/dist/client.js.map +1 -0
- package/dist/edpay.js +192 -0
- package/dist/exceptions.d.ts +9 -0
- package/dist/exceptions.d.ts.map +1 -0
- package/dist/exceptions.js +22 -0
- package/dist/exceptions.js.map +1 -0
- package/dist/frontend.d.ts +57 -0
- package/dist/frontend.d.ts.map +1 -0
- package/dist/frontend.js +221 -0
- package/dist/frontend.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/resources/checkout.d.ts +11 -0
- package/dist/resources/checkout.d.ts.map +1 -0
- package/dist/resources/checkout.js +25 -0
- package/dist/resources/checkout.js.map +1 -0
- package/dist/resources/customers.d.ts +11 -0
- package/dist/resources/customers.d.ts.map +1 -0
- package/dist/resources/customers.js +20 -0
- package/dist/resources/customers.js.map +1 -0
- package/dist/resources/invoices.d.ts +17 -0
- package/dist/resources/invoices.d.ts.map +1 -0
- package/dist/resources/invoices.js +38 -0
- package/dist/resources/invoices.js.map +1 -0
- package/dist/resources/payment-links.d.ts +11 -0
- package/dist/resources/payment-links.d.ts.map +1 -0
- package/dist/resources/payment-links.js +25 -0
- package/dist/resources/payment-links.js.map +1 -0
- package/dist/resources/payments.d.ts +11 -0
- package/dist/resources/payments.d.ts.map +1 -0
- package/dist/resources/payments.js +25 -0
- package/dist/resources/payments.js.map +1 -0
- package/dist/resources/subscriptions.d.ts +18 -0
- package/dist/resources/subscriptions.d.ts.map +1 -0
- package/dist/resources/subscriptions.js +41 -0
- package/dist/resources/subscriptions.js.map +1 -0
- package/dist/types.d.ts +59 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/webhooks.d.ts +9 -0
- package/dist/webhooks.d.ts.map +1 -0
- package/dist/webhooks.js +65 -0
- package/dist/webhooks.js.map +1 -0
- package/package.json +58 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Edutecka Servicos Tecnologicos Lda
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,134 @@
|
|
|
1
|
-
#
|
|
1
|
+
# EDPay JavaScript / TypeScript SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The official JavaScript and TypeScript SDK for server-side Node.js applications. It can also be used in browser code through its frontend helpers, but **never expose a private API key in a browser or other untrusted environment**.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- Node.js 20 or later
|
|
8
|
+
- npm, pnpm, or yarn
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
Install the package from npm:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm install @edutecka-mz/edpay-sdk
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The package import name is `@edutecka-mz/edpay-sdk`.
|
|
19
|
+
|
|
20
|
+
## Create a payment from a Node.js service
|
|
21
|
+
|
|
22
|
+
Store the keys in the server environment, not in source control:
|
|
23
|
+
|
|
24
|
+
```dotenv
|
|
25
|
+
EDPAY_PUBLIC_KEY=pk_test_...
|
|
26
|
+
EDPAY_PRIVATE_KEY=sk_test_...
|
|
27
|
+
EDPAY_METHOD=method_id_from_payment_methods
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { EDPayClient } from "@edutecka-mz/edpay-sdk";
|
|
32
|
+
|
|
33
|
+
const edpay = new EDPayClient({
|
|
34
|
+
publicKey: process.env.EDPAY_PUBLIC_KEY!,
|
|
35
|
+
privateKey: process.env.EDPAY_PRIVATE_KEY!,
|
|
36
|
+
environment: "sandbox",
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const payment = await edpay.payments.create({
|
|
40
|
+
amount_minor: 50000, // 500.00 MZN
|
|
41
|
+
currency: "MZN",
|
|
42
|
+
method: process.env.EDPAY_METHOD, // Select an ID supported by the account/API.
|
|
43
|
+
reference: "ORDER-10492",
|
|
44
|
+
description: "Example order",
|
|
45
|
+
idempotencyKey: "ORDER-10492",
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
console.log(payment);
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
By default, the client uses `https://api-pay.edutecka.com`; set `baseUrl` only when EDPay provides a different API host for your account. Sandbox or production access is determined by the API keys. The client sends `X-EDPay-Public-Key` and `X-EDPay-Private-Key` headers. `idempotencyKey` is sent as the `Idempotency-Key` header. Payment amounts are expressed in minor currency units. The `method` is dynamic and should be an identifier returned by `GET /v1/public/payment-methods` or otherwise supported for the account; do not hard-code a particular gateway into a multi-gateway flow.
|
|
52
|
+
|
|
53
|
+
Browser checkout helpers are available from the frontend-only entry point. Use a public key only; never bundle a private key into browser code:
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import { EDPay } from "@edutecka-mz/edpay-sdk/frontend";
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
To retrieve a payment:
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
const payment = await edpay.payments.retrieve("PAYMENT_ID");
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Create a hosted checkout session
|
|
66
|
+
|
|
67
|
+
Create the session on your server, then send the customer to the hosted checkout URL returned by the API:
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
const session = await edpay.checkout.createSession({
|
|
71
|
+
amount_minor: 50000,
|
|
72
|
+
currency: "MZN",
|
|
73
|
+
success_url: "https://merchant.example/checkout/success",
|
|
74
|
+
cancel_url: "https://merchant.example/checkout/cancel",
|
|
75
|
+
reference: "ORDER-10492",
|
|
76
|
+
idempotencyKey: "ORDER-10492-checkout",
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
console.log(session);
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The SDK sends this request to `POST /v1/checkout/sessions`. Confirm payment using a verified webhook or a server-side payment lookup; a browser redirect alone is not proof of payment.
|
|
83
|
+
|
|
84
|
+
## Verify webhook signatures
|
|
85
|
+
|
|
86
|
+
Use the raw request body and the `X-EDPay-Signature` header before parsing or processing an event. For example, in a Next.js route handler:
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import { verifyWebhookSignature } from "@edutecka-mz/edpay-sdk";
|
|
90
|
+
|
|
91
|
+
export async function POST(request: Request) {
|
|
92
|
+
const rawBody = await request.text();
|
|
93
|
+
const signature = request.headers.get("x-edpay-signature") ?? "";
|
|
94
|
+
const secret = process.env.EDPAY_WEBHOOK_SECRET!;
|
|
95
|
+
|
|
96
|
+
if (!verifyWebhookSignature(rawBody, signature, secret)) {
|
|
97
|
+
return new Response("Invalid signature", { status: 400 });
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const event = JSON.parse(rawBody);
|
|
101
|
+
if (event.type === "payment.succeeded") {
|
|
102
|
+
// Update the matching order idempotently using event.data.
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return Response.json({ received: true });
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Official documentation
|
|
110
|
+
|
|
111
|
+
- [SDK installation and integration guide](https://docs-pay.edutecka.com/sdks/)
|
|
112
|
+
- [Payments API reference](https://docs-pay.edutecka.com/api/payments/)
|
|
113
|
+
- [Authentication and API keys](https://docs-pay.edutecka.com/guides/authentication/)
|
|
114
|
+
- [Webhooks](https://docs-pay.edutecka.com/api/webhooks/)
|
|
115
|
+
|
|
116
|
+
## Other official SDK repositories
|
|
117
|
+
|
|
118
|
+
- [PHP SDK](https://github.com/edutecka/edpay-php-sdk)
|
|
119
|
+
- [Python SDK](https://github.com/edutecka/edpay-python-sdk)
|
|
120
|
+
- [Java SDK](https://github.com/edutecka/edpay-java-sdk)
|
|
121
|
+
- [.NET SDK](https://github.com/edutecka/edpay-dot-net-sdk)
|
|
122
|
+
|
|
123
|
+
## Official plugin repositories
|
|
124
|
+
|
|
125
|
+
- [WooCommerce (WordPress)](https://github.com/edutecka/edpay-woocommerce-plugin)
|
|
126
|
+
- [Shopify](https://github.com/edutecka/edpay-shopify-app)
|
|
127
|
+
- [Magento / Adobe Commerce](https://github.com/edutecka/edpay-magento2-module) — integration preview; not production-ready
|
|
128
|
+
- [PrestaShop](https://github.com/edutecka/edpay-prestashop-module)
|
|
129
|
+
- [OpenCart](https://github.com/edutecka/edpay-opencart-extension)
|
|
130
|
+
- [WHMCS](https://github.com/edutecka/edpay-whmcs-gateway)
|
|
131
|
+
|
|
132
|
+
## License
|
|
133
|
+
|
|
134
|
+
MIT. See [LICENSE](LICENSE).
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { EDPayClientOptions } from "./types.js";
|
|
2
|
+
import { PaymentsResource } from "./resources/payments.js";
|
|
3
|
+
import { CheckoutResource } from "./resources/checkout.js";
|
|
4
|
+
import { PaymentLinksResource } from "./resources/payment-links.js";
|
|
5
|
+
import { CustomersResource } from "./resources/customers.js";
|
|
6
|
+
import { InvoicesResource } from "./resources/invoices.js";
|
|
7
|
+
import { SubscriptionsResource } from "./resources/subscriptions.js";
|
|
8
|
+
export declare class EDPayClient {
|
|
9
|
+
private readonly publicKey;
|
|
10
|
+
private readonly privateKey;
|
|
11
|
+
private readonly baseUrl;
|
|
12
|
+
private readonly timeoutMs;
|
|
13
|
+
readonly payments: PaymentsResource;
|
|
14
|
+
readonly checkout: CheckoutResource;
|
|
15
|
+
readonly paymentLinks: PaymentLinksResource;
|
|
16
|
+
readonly customers: CustomersResource;
|
|
17
|
+
readonly invoices: InvoicesResource;
|
|
18
|
+
readonly subscriptions: SubscriptionsResource;
|
|
19
|
+
constructor(options: EDPayClientOptions);
|
|
20
|
+
request<T = any>(method: string, path: string, body?: unknown, customHeaders?: Record<string, string>): Promise<T>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IAEnC,SAAgB,QAAQ,EAAE,gBAAgB,CAAC;IAC3C,SAAgB,QAAQ,EAAE,gBAAgB,CAAC;IAC3C,SAAgB,YAAY,EAAE,oBAAoB,CAAC;IACnD,SAAgB,SAAS,EAAE,iBAAiB,CAAC;IAC7C,SAAgB,QAAQ,EAAE,gBAAgB,CAAC;IAC3C,SAAgB,aAAa,EAAE,qBAAqB,CAAC;gBAEzC,OAAO,EAAE,kBAAkB;IAwBjC,OAAO,CAAC,CAAC,GAAG,GAAG,EACnB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,OAAO,EACd,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACrC,OAAO,CAAC,CAAC,CAAC;CA8Cd"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EDPayClient = void 0;
|
|
4
|
+
const exceptions_js_1 = require("./exceptions.js");
|
|
5
|
+
const payments_js_1 = require("./resources/payments.js");
|
|
6
|
+
const checkout_js_1 = require("./resources/checkout.js");
|
|
7
|
+
const payment_links_js_1 = require("./resources/payment-links.js");
|
|
8
|
+
const customers_js_1 = require("./resources/customers.js");
|
|
9
|
+
const invoices_js_1 = require("./resources/invoices.js");
|
|
10
|
+
const subscriptions_js_1 = require("./resources/subscriptions.js");
|
|
11
|
+
class EDPayClient {
|
|
12
|
+
publicKey;
|
|
13
|
+
privateKey;
|
|
14
|
+
baseUrl;
|
|
15
|
+
timeoutMs;
|
|
16
|
+
payments;
|
|
17
|
+
checkout;
|
|
18
|
+
paymentLinks;
|
|
19
|
+
customers;
|
|
20
|
+
invoices;
|
|
21
|
+
subscriptions;
|
|
22
|
+
constructor(options) {
|
|
23
|
+
if (!options?.publicKey || !options?.privateKey) {
|
|
24
|
+
throw new Error("EDPayClient requires both publicKey and privateKey.");
|
|
25
|
+
}
|
|
26
|
+
this.publicKey = options.publicKey;
|
|
27
|
+
this.privateKey = options.privateKey;
|
|
28
|
+
this.timeoutMs = options.timeoutMs ?? 30000;
|
|
29
|
+
if (options.baseUrl) {
|
|
30
|
+
this.baseUrl = options.baseUrl.replace(/\/+$/, "");
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
this.baseUrl =
|
|
34
|
+
options.baseUrl || "https://api-pay.edutecka.com";
|
|
35
|
+
}
|
|
36
|
+
this.payments = new payments_js_1.PaymentsResource(this);
|
|
37
|
+
this.checkout = new checkout_js_1.CheckoutResource(this);
|
|
38
|
+
this.paymentLinks = new payment_links_js_1.PaymentLinksResource(this);
|
|
39
|
+
this.customers = new customers_js_1.CustomersResource(this);
|
|
40
|
+
this.invoices = new invoices_js_1.InvoicesResource(this);
|
|
41
|
+
this.subscriptions = new subscriptions_js_1.SubscriptionsResource(this);
|
|
42
|
+
}
|
|
43
|
+
async request(method, path, body, customHeaders) {
|
|
44
|
+
const url = `${this.baseUrl}${path}`;
|
|
45
|
+
const headers = {
|
|
46
|
+
"X-EDPay-Public-Key": this.publicKey,
|
|
47
|
+
"X-EDPay-Private-Key": this.privateKey,
|
|
48
|
+
"Content-Type": "application/json",
|
|
49
|
+
Accept: "application/json",
|
|
50
|
+
"User-Agent": "EDPay-Node-SDK/1.0.0",
|
|
51
|
+
...customHeaders,
|
|
52
|
+
};
|
|
53
|
+
const controller = new AbortController();
|
|
54
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
55
|
+
try {
|
|
56
|
+
const response = await fetch(url, {
|
|
57
|
+
method,
|
|
58
|
+
headers,
|
|
59
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
60
|
+
signal: controller.signal,
|
|
61
|
+
});
|
|
62
|
+
clearTimeout(timer);
|
|
63
|
+
const text = await response.text();
|
|
64
|
+
let data = null;
|
|
65
|
+
if (text) {
|
|
66
|
+
try {
|
|
67
|
+
data = JSON.parse(text);
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
data = { raw: text };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (!response.ok) {
|
|
74
|
+
const errorMsg = data?.message || data?.error || `HTTP ${response.status} ${response.statusText}`;
|
|
75
|
+
throw new exceptions_js_1.EDPayError(errorMsg, response.status, data);
|
|
76
|
+
}
|
|
77
|
+
return data;
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
clearTimeout(timer);
|
|
81
|
+
if (err instanceof exceptions_js_1.EDPayError)
|
|
82
|
+
throw err;
|
|
83
|
+
throw new exceptions_js_1.EDPayError(err.message || "Network request failed", 0);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.EDPayClient = EDPayClient;
|
|
88
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AACA,mDAA6C;AAC7C,yDAA2D;AAC3D,yDAA2D;AAC3D,mEAAoE;AACpE,2DAA6D;AAC7D,yDAA2D;AAC3D,mEAAqE;AAErE,MAAa,WAAW;IACL,SAAS,CAAS;IAClB,UAAU,CAAS;IACnB,OAAO,CAAS;IAChB,SAAS,CAAS;IAEnB,QAAQ,CAAmB;IAC3B,QAAQ,CAAmB;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,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YACxD,CAAC;YAED,OAAO,IAAS,CAAC;QACnB,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,IAAI,GAAG,YAAY,0BAAU;gBAAE,MAAM,GAAG,CAAC;YACzC,MAAM,IAAI,0BAAU,CAAC,GAAG,CAAC,OAAO,IAAI,wBAAwB,EAAE,CAAC,CAAC,CAAC;QACnE,CAAC;IACH,CAAC;CACF;AAxFD,kCAwFC"}
|
package/dist/edpay.js
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EDPay JavaScript SDK (Frontend / Browser Bundle)
|
|
3
|
+
* https://pay.edutecka.com
|
|
4
|
+
* (c) Edutecka Pay Lda. All rights reserved.
|
|
5
|
+
*/
|
|
6
|
+
(function (global) {
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
function EDPay(options) {
|
|
10
|
+
if (!(this instanceof EDPay)) {
|
|
11
|
+
return new EDPay(options);
|
|
12
|
+
}
|
|
13
|
+
if (typeof options === 'string') {
|
|
14
|
+
this.publicKey = options;
|
|
15
|
+
this.baseUrl = 'https://pay.edutecka.com';
|
|
16
|
+
} else if (options && typeof options === 'object') {
|
|
17
|
+
if (!options.publicKey) {
|
|
18
|
+
throw new Error('EDPay requires a valid publicKey (pk_live_... or pk_test_...).');
|
|
19
|
+
}
|
|
20
|
+
this.publicKey = options.publicKey;
|
|
21
|
+
if (options.baseUrl) {
|
|
22
|
+
this.baseUrl = options.baseUrl.replace(/\/+$/, '');
|
|
23
|
+
} else {
|
|
24
|
+
this.baseUrl = options.environment === 'sandbox'
|
|
25
|
+
? 'https://sandbox.pay.edutecka.com'
|
|
26
|
+
: 'https://pay.edutecka.com';
|
|
27
|
+
}
|
|
28
|
+
} else {
|
|
29
|
+
throw new Error('EDPay requires an options object or public key string.');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
EDPay.prototype.resolveUrl = function (options) {
|
|
34
|
+
if (options.paymentUrl) {
|
|
35
|
+
return options.paymentUrl;
|
|
36
|
+
}
|
|
37
|
+
if (options.token) {
|
|
38
|
+
return this.baseUrl + '/pay?token=' + encodeURIComponent(options.token) + '&pk=' + encodeURIComponent(this.publicKey);
|
|
39
|
+
}
|
|
40
|
+
throw new Error("EDPay: Either 'token' or 'paymentUrl' must be provided.");
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
EDPay.prototype.redirectToCheckout = function (options) {
|
|
44
|
+
var url = this.resolveUrl(options);
|
|
45
|
+
window.location.href = url;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
EDPay.prototype.openModal = function (options) {
|
|
49
|
+
options = options || {};
|
|
50
|
+
var checkoutUrl = this.resolveUrl(options);
|
|
51
|
+
|
|
52
|
+
// Overlay backdrop
|
|
53
|
+
var overlay = document.createElement('div');
|
|
54
|
+
overlay.id = 'edpay-modal-overlay';
|
|
55
|
+
overlay.style.cssText = 'position:fixed;top:0;left:0;width:100vw;height:100vh;background:rgba(0,0,0,0.65);backdrop-filter:blur(4px);z-index:999999;display:flex;align-items:center;justify-content:center;padding:16px;box-sizing:border-box;opacity:0;transition:opacity 0.25s ease-in-out;';
|
|
56
|
+
|
|
57
|
+
// Modal Card
|
|
58
|
+
var modal = document.createElement('div');
|
|
59
|
+
modal.style.cssText = 'position:relative;width:100%;max-width:480px;height:min(680px,92vh);background:#ffffff;border-radius:20px;overflow:hidden;box-shadow:0 25px 50px -12px rgba(0,0,0,0.35);display:flex;flex-direction:column;';
|
|
60
|
+
|
|
61
|
+
// Close button
|
|
62
|
+
var closeBtn = document.createElement('button');
|
|
63
|
+
closeBtn.type = 'button';
|
|
64
|
+
closeBtn.innerHTML = '×';
|
|
65
|
+
closeBtn.setAttribute('aria-label', 'Fechar');
|
|
66
|
+
closeBtn.style.cssText = 'position:absolute;top:12px;right:12px;width:32px;height:32px;border:none;border-radius:50%;background:rgba(0,0,0,0.08);color:#333;font-size:22px;line-height:1;cursor:pointer;z-index:10;display:flex;align-items:center;justify-content:center;';
|
|
67
|
+
|
|
68
|
+
// Iframe
|
|
69
|
+
var iframe = document.createElement('iframe');
|
|
70
|
+
iframe.src = checkoutUrl;
|
|
71
|
+
iframe.style.cssText = 'width:100%;height:100%;border:none;';
|
|
72
|
+
iframe.allow = 'payment';
|
|
73
|
+
|
|
74
|
+
modal.appendChild(closeBtn);
|
|
75
|
+
modal.appendChild(iframe);
|
|
76
|
+
overlay.appendChild(modal);
|
|
77
|
+
document.body.appendChild(overlay);
|
|
78
|
+
|
|
79
|
+
requestAnimationFrame(function () {
|
|
80
|
+
overlay.style.opacity = '1';
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
function cleanup() {
|
|
84
|
+
window.removeEventListener('message', handleMessage);
|
|
85
|
+
overlay.style.opacity = '0';
|
|
86
|
+
setTimeout(function () {
|
|
87
|
+
if (overlay.parentNode) {
|
|
88
|
+
overlay.parentNode.removeChild(overlay);
|
|
89
|
+
}
|
|
90
|
+
}, 250);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function handleClose() {
|
|
94
|
+
cleanup();
|
|
95
|
+
if (typeof options.onClose === 'function') {
|
|
96
|
+
options.onClose();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
closeBtn.addEventListener('click', handleClose);
|
|
101
|
+
overlay.addEventListener('click', function (e) {
|
|
102
|
+
if (e.target === overlay) {
|
|
103
|
+
handleClose();
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
function handleMessage(event) {
|
|
108
|
+
if (!event.data || typeof event.data !== 'object') return;
|
|
109
|
+
var type = event.data.type;
|
|
110
|
+
var payload = event.data.payload;
|
|
111
|
+
|
|
112
|
+
if (type === 'edpay:payment_success' || type === 'edpay:success') {
|
|
113
|
+
if (typeof options.onSuccess === 'function') {
|
|
114
|
+
options.onSuccess(payload);
|
|
115
|
+
}
|
|
116
|
+
setTimeout(handleClose, 1500);
|
|
117
|
+
} else if (type === 'edpay:payment_failed' || type === 'edpay:error') {
|
|
118
|
+
if (typeof options.onError === 'function') {
|
|
119
|
+
options.onError(payload);
|
|
120
|
+
}
|
|
121
|
+
} else if (type === 'edpay:close') {
|
|
122
|
+
handleClose();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
window.addEventListener('message', handleMessage);
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
close: handleClose
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
EDPay.prototype.mount = function (options) {
|
|
134
|
+
options = options || {};
|
|
135
|
+
var target = typeof options.container === 'string'
|
|
136
|
+
? document.getElementById(options.container)
|
|
137
|
+
: options.container;
|
|
138
|
+
|
|
139
|
+
if (!target) {
|
|
140
|
+
throw new Error("EDPay: Target container '" + options.container + "' not found.");
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
var checkoutUrl = this.resolveUrl(options);
|
|
144
|
+
var iframe = document.createElement('iframe');
|
|
145
|
+
iframe.src = checkoutUrl;
|
|
146
|
+
iframe.style.cssText = 'width:' + (options.width || '100%') + ';height:' + (options.height || '620px') + ';border:none;border-radius:16px;';
|
|
147
|
+
iframe.allow = 'payment';
|
|
148
|
+
|
|
149
|
+
target.innerHTML = '';
|
|
150
|
+
target.appendChild(iframe);
|
|
151
|
+
|
|
152
|
+
function handleMessage(event) {
|
|
153
|
+
if (!event.data || typeof event.data !== 'object') return;
|
|
154
|
+
var type = event.data.type;
|
|
155
|
+
var payload = event.data.payload;
|
|
156
|
+
|
|
157
|
+
if (type === 'edpay:payment_success' || type === 'edpay:success') {
|
|
158
|
+
if (typeof options.onSuccess === 'function') options.onSuccess(payload);
|
|
159
|
+
} else if (type === 'edpay:payment_failed' || type === 'edpay:error') {
|
|
160
|
+
if (typeof options.onError === 'function') options.onError(payload);
|
|
161
|
+
} else if (type === 'edpay:close') {
|
|
162
|
+
if (typeof options.onClose === 'function') options.onClose();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
window.addEventListener('message', handleMessage);
|
|
167
|
+
|
|
168
|
+
return {
|
|
169
|
+
unmount: function () {
|
|
170
|
+
window.removeEventListener('message', handleMessage);
|
|
171
|
+
if (iframe.parentNode) {
|
|
172
|
+
iframe.parentNode.removeChild(iframe);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
EDPay.prototype.checkout = function (options) {
|
|
179
|
+
options = options || {};
|
|
180
|
+
if (options.mode === 'embedded' || options.container) {
|
|
181
|
+
return this.mount(options);
|
|
182
|
+
}
|
|
183
|
+
if (options.mode === 'redirect') {
|
|
184
|
+
return this.redirectToCheckout(options);
|
|
185
|
+
}
|
|
186
|
+
return this.openModal(options);
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
global.EDPay = EDPay;
|
|
190
|
+
global.EdPay = EDPay;
|
|
191
|
+
|
|
192
|
+
})(typeof window !== 'undefined' ? window : this);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare class EDPayError extends Error {
|
|
2
|
+
readonly statusCode: number;
|
|
3
|
+
readonly responseData: unknown;
|
|
4
|
+
constructor(message: string, statusCode?: number, responseData?: unknown);
|
|
5
|
+
}
|
|
6
|
+
export declare class SignatureVerificationError extends EDPayError {
|
|
7
|
+
constructor(message?: string);
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=exceptions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exceptions.d.ts","sourceRoot":"","sources":["../src/exceptions.ts"],"names":[],"mappings":"AAAA,qBAAa,UAAW,SAAQ,KAAK;IACnC,SAAgB,UAAU,EAAE,MAAM,CAAC;IACnC,SAAgB,YAAY,EAAE,OAAO,CAAC;gBAE1B,OAAO,EAAE,MAAM,EAAE,UAAU,SAAM,EAAE,YAAY,GAAE,OAAc;CAM5E;AAED,qBAAa,0BAA2B,SAAQ,UAAU;gBAC5C,OAAO,SAAoC;CAIxD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SignatureVerificationError = exports.EDPayError = void 0;
|
|
4
|
+
class EDPayError extends Error {
|
|
5
|
+
statusCode;
|
|
6
|
+
responseData;
|
|
7
|
+
constructor(message, statusCode = 400, responseData = null) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = "EDPayError";
|
|
10
|
+
this.statusCode = statusCode;
|
|
11
|
+
this.responseData = responseData;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.EDPayError = EDPayError;
|
|
15
|
+
class SignatureVerificationError extends EDPayError {
|
|
16
|
+
constructor(message = "Invalid EDPay webhook signature") {
|
|
17
|
+
super(message, 400);
|
|
18
|
+
this.name = "SignatureVerificationError";
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.SignatureVerificationError = SignatureVerificationError;
|
|
22
|
+
//# sourceMappingURL=exceptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exceptions.js","sourceRoot":"","sources":["../src/exceptions.ts"],"names":[],"mappings":";;;AAAA,MAAa,UAAW,SAAQ,KAAK;IACnB,UAAU,CAAS;IACnB,YAAY,CAAU;IAEtC,YAAY,OAAe,EAAE,UAAU,GAAG,GAAG,EAAE,eAAwB,IAAI;QACzE,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;CACF;AAVD,gCAUC;AAED,MAAa,0BAA2B,SAAQ,UAAU;IACxD,YAAY,OAAO,GAAG,iCAAiC;QACrD,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QACpB,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC3C,CAAC;CACF;AALD,gEAKC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export interface EDPayFrontendOptions {
|
|
2
|
+
publicKey: string;
|
|
3
|
+
environment?: "production" | "sandbox";
|
|
4
|
+
baseUrl?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface OpenModalOptions {
|
|
7
|
+
token?: string;
|
|
8
|
+
paymentUrl?: string;
|
|
9
|
+
onSuccess?: (data: any) => void;
|
|
10
|
+
onError?: (error: any) => void;
|
|
11
|
+
onClose?: () => void;
|
|
12
|
+
}
|
|
13
|
+
export interface MountOptions extends OpenModalOptions {
|
|
14
|
+
container: string | HTMLElement;
|
|
15
|
+
width?: string;
|
|
16
|
+
height?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface CheckoutOptions extends OpenModalOptions {
|
|
19
|
+
mode?: "modal" | "embedded" | "redirect";
|
|
20
|
+
container?: string | HTMLElement;
|
|
21
|
+
width?: string;
|
|
22
|
+
height?: string;
|
|
23
|
+
}
|
|
24
|
+
export declare class EDPay {
|
|
25
|
+
private readonly publicKey;
|
|
26
|
+
private readonly baseUrl;
|
|
27
|
+
constructor(options: EDPayFrontendOptions | string);
|
|
28
|
+
private resolveUrl;
|
|
29
|
+
/**
|
|
30
|
+
* Unified checkout initiator supporting modal, embedded iframe, or direct redirect.
|
|
31
|
+
*/
|
|
32
|
+
checkout(options: CheckoutOptions): {
|
|
33
|
+
close?: () => void;
|
|
34
|
+
unmount?: () => void;
|
|
35
|
+
} | void;
|
|
36
|
+
/**
|
|
37
|
+
* Redirects the browser directly to the hosted payment page.
|
|
38
|
+
*/
|
|
39
|
+
redirectToCheckout(options: {
|
|
40
|
+
token?: string;
|
|
41
|
+
paymentUrl?: string;
|
|
42
|
+
}): void;
|
|
43
|
+
/**
|
|
44
|
+
* Opens an interactive payment modal overlay with iframe on the current page.
|
|
45
|
+
*/
|
|
46
|
+
openModal(options: OpenModalOptions): {
|
|
47
|
+
close: () => void;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Embeds the checkout iframe inside a designated container element.
|
|
51
|
+
*/
|
|
52
|
+
mount(options: MountOptions): {
|
|
53
|
+
unmount: () => void;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export declare const EDPayFrontend: typeof EDPay;
|
|
57
|
+
//# sourceMappingURL=frontend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frontend.d.ts","sourceRoot":"","sources":["../src/frontend.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,YAAY,GAAG,SAAS,CAAC;IACvC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,CAAC;IAChC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;IAC/B,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,MAAM,WAAW,YAAa,SAAQ,gBAAgB;IACpD,SAAS,EAAE,MAAM,GAAG,WAAW,CAAC;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,eAAgB,SAAQ,gBAAgB;IACvD,IAAI,CAAC,EAAE,OAAO,GAAG,UAAU,GAAG,UAAU,CAAC;IACzC,SAAS,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,KAAK;IAChB,OAAO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