@goweekdays/core 2.4.2 → 2.5.0
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/CHANGELOG.md +6 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.js +141 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +145 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -1
package/dist/index.mjs
CHANGED
|
@@ -906,9 +906,11 @@ var SPACES_BUCKET = process.env.SPACES_BUCKET;
|
|
|
906
906
|
var PAYPAL_CLIENT_ID = process.env.PAYPAL_CLIENT_ID ?? "";
|
|
907
907
|
var PAYPAL_CLIENT_SECRET = process.env.PAYPAL_CLIENT_SECRET ?? "";
|
|
908
908
|
var PAYPAL_API_URL = process.env.PAYPAL_API_URL ?? "https://api-m.sandbox.paypal.com";
|
|
909
|
+
var PAYPAL_WEBHOOK_ID = process.env.PAYPAL_WEBHOOK_ID ?? "";
|
|
909
910
|
var XENDIT_SECRET_KEY = process.env.XENDIT_SECRET_KEY ?? "";
|
|
910
911
|
var XENDIT_BASE_URL = process.env.XENDIT_BASE_URL ?? "https://api.xendit.co";
|
|
911
912
|
var DOMAIN = process.env.DOMAIN || "localhost";
|
|
913
|
+
var APP_ORG = process.env.APP_ORG || "http://localhost/organizations/create";
|
|
912
914
|
|
|
913
915
|
// src/resources/user/user.service.ts
|
|
914
916
|
import {
|
|
@@ -3502,6 +3504,11 @@ function useAppService() {
|
|
|
3502
3504
|
code: "ride",
|
|
3503
3505
|
name: "Ride",
|
|
3504
3506
|
description: "Transportation and ride services."
|
|
3507
|
+
},
|
|
3508
|
+
{
|
|
3509
|
+
code: "job",
|
|
3510
|
+
name: "jobs",
|
|
3511
|
+
description: "Job listings and recruitment services."
|
|
3505
3512
|
}
|
|
3506
3513
|
];
|
|
3507
3514
|
const session = useAtlas9.getClient()?.startSession();
|
|
@@ -6340,6 +6347,118 @@ function usePlanController() {
|
|
|
6340
6347
|
};
|
|
6341
6348
|
}
|
|
6342
6349
|
|
|
6350
|
+
// src/resources/utils/paypal.service.ts
|
|
6351
|
+
import {
|
|
6352
|
+
Client,
|
|
6353
|
+
Environment,
|
|
6354
|
+
OrdersController,
|
|
6355
|
+
CheckoutPaymentIntent,
|
|
6356
|
+
OrderApplicationContextUserAction
|
|
6357
|
+
} from "@paypal/paypal-server-sdk";
|
|
6358
|
+
function usePaypalService() {
|
|
6359
|
+
const paypalClient = new Client({
|
|
6360
|
+
clientCredentialsAuthCredentials: {
|
|
6361
|
+
oAuthClientId: PAYPAL_CLIENT_ID,
|
|
6362
|
+
oAuthClientSecret: PAYPAL_CLIENT_SECRET
|
|
6363
|
+
},
|
|
6364
|
+
timeout: 0,
|
|
6365
|
+
environment: isDev ? Environment.Sandbox : Environment.Production
|
|
6366
|
+
});
|
|
6367
|
+
function addOrder({
|
|
6368
|
+
amount = 0,
|
|
6369
|
+
currency = "PHP",
|
|
6370
|
+
customId = "",
|
|
6371
|
+
returnUrl = "",
|
|
6372
|
+
cancelUrl = "",
|
|
6373
|
+
action = "pay"
|
|
6374
|
+
} = {}) {
|
|
6375
|
+
return new OrdersController(paypalClient).createOrder({
|
|
6376
|
+
body: {
|
|
6377
|
+
intent: CheckoutPaymentIntent.Capture,
|
|
6378
|
+
purchaseUnits: [
|
|
6379
|
+
{
|
|
6380
|
+
amount: {
|
|
6381
|
+
currencyCode: currency,
|
|
6382
|
+
value: amount.toFixed(2)
|
|
6383
|
+
},
|
|
6384
|
+
customId
|
|
6385
|
+
}
|
|
6386
|
+
],
|
|
6387
|
+
applicationContext: {
|
|
6388
|
+
returnUrl,
|
|
6389
|
+
cancelUrl,
|
|
6390
|
+
userAction: action === "pay" ? OrderApplicationContextUserAction.PayNow : action === "continue" ? OrderApplicationContextUserAction.Continue : void 0
|
|
6391
|
+
}
|
|
6392
|
+
},
|
|
6393
|
+
prefer: "return=minimal"
|
|
6394
|
+
});
|
|
6395
|
+
}
|
|
6396
|
+
function captureOrder(id) {
|
|
6397
|
+
return new OrdersController(paypalClient).captureOrder({ id });
|
|
6398
|
+
}
|
|
6399
|
+
async function verifyWebhook(headers, body, webhookId = PAYPAL_WEBHOOK_ID) {
|
|
6400
|
+
const authAlgo = headers["paypal-auth-algo"];
|
|
6401
|
+
const certUrl = headers["paypal-cert-url"];
|
|
6402
|
+
const transmissionId = headers["paypal-transmission-id"];
|
|
6403
|
+
const transmissionSig = headers["paypal-transmission-sig"];
|
|
6404
|
+
const transmissionTime = headers["paypal-transmission-time"];
|
|
6405
|
+
if (!authAlgo || !certUrl || !transmissionId || !transmissionSig || !transmissionTime) {
|
|
6406
|
+
return {
|
|
6407
|
+
verified: false,
|
|
6408
|
+
verificationStatus: "FAILURE"
|
|
6409
|
+
};
|
|
6410
|
+
}
|
|
6411
|
+
const auth = Buffer.from(
|
|
6412
|
+
`${PAYPAL_CLIENT_ID}:${PAYPAL_CLIENT_SECRET}`
|
|
6413
|
+
).toString("base64");
|
|
6414
|
+
const tokenResponse = await fetch(`${PAYPAL_API_URL}/v1/oauth2/token`, {
|
|
6415
|
+
method: "POST",
|
|
6416
|
+
headers: {
|
|
6417
|
+
Authorization: `Basic ${auth}`,
|
|
6418
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
6419
|
+
},
|
|
6420
|
+
body: "grant_type=client_credentials"
|
|
6421
|
+
});
|
|
6422
|
+
if (!tokenResponse.ok) {
|
|
6423
|
+
throw new Error("Failed to obtain PayPal access token");
|
|
6424
|
+
}
|
|
6425
|
+
const tokenData = await tokenResponse.json();
|
|
6426
|
+
const accessToken = tokenData.access_token;
|
|
6427
|
+
const verifyResponse = await fetch(
|
|
6428
|
+
`${PAYPAL_API_URL}/v1/notifications/verify-webhook-signature`,
|
|
6429
|
+
{
|
|
6430
|
+
method: "POST",
|
|
6431
|
+
headers: {
|
|
6432
|
+
Authorization: `Bearer ${accessToken}`,
|
|
6433
|
+
"Content-Type": "application/json"
|
|
6434
|
+
},
|
|
6435
|
+
body: JSON.stringify({
|
|
6436
|
+
auth_algo: authAlgo,
|
|
6437
|
+
cert_url: certUrl,
|
|
6438
|
+
transmission_id: transmissionId,
|
|
6439
|
+
transmission_sig: transmissionSig,
|
|
6440
|
+
transmission_time: transmissionTime,
|
|
6441
|
+
webhook_id: webhookId,
|
|
6442
|
+
webhook_event: body
|
|
6443
|
+
})
|
|
6444
|
+
}
|
|
6445
|
+
);
|
|
6446
|
+
if (!verifyResponse.ok) {
|
|
6447
|
+
throw new Error("Failed to verify PayPal webhook signature");
|
|
6448
|
+
}
|
|
6449
|
+
const verifyData = await verifyResponse.json();
|
|
6450
|
+
return {
|
|
6451
|
+
verified: verifyData.verification_status === "SUCCESS",
|
|
6452
|
+
verificationStatus: verifyData.verification_status
|
|
6453
|
+
};
|
|
6454
|
+
}
|
|
6455
|
+
return {
|
|
6456
|
+
addOrder,
|
|
6457
|
+
captureOrder,
|
|
6458
|
+
verifyWebhook
|
|
6459
|
+
};
|
|
6460
|
+
}
|
|
6461
|
+
|
|
6343
6462
|
// src/resources/organization/organization.service.ts
|
|
6344
6463
|
function useOrgService() {
|
|
6345
6464
|
const { add: addOrg } = useOrgRepo();
|
|
@@ -6350,6 +6469,7 @@ function useOrgService() {
|
|
|
6350
6469
|
const { getDefault } = usePlanRepo();
|
|
6351
6470
|
const { add: addSubscription } = useSubscriptionRepo();
|
|
6352
6471
|
const { add: addSubscriptionTransaction } = useSubscriptionTransactionRepo();
|
|
6472
|
+
const { addOrder: addPaypalOrder } = usePaypalService();
|
|
6353
6473
|
async function add(value) {
|
|
6354
6474
|
const { error } = schemaOrgAdd.validate(value);
|
|
6355
6475
|
if (error) {
|
|
@@ -6444,8 +6564,22 @@ function useOrgService() {
|
|
|
6444
6564
|
},
|
|
6445
6565
|
session
|
|
6446
6566
|
);
|
|
6567
|
+
const order = await addPaypalOrder({
|
|
6568
|
+
amount,
|
|
6569
|
+
currency: plan.currency,
|
|
6570
|
+
customId: subscriptionId,
|
|
6571
|
+
returnUrl: `${APP_ORG}/organizations/success`,
|
|
6572
|
+
cancelUrl: `${APP_ORG}/organizations/cancel`,
|
|
6573
|
+
action: "pay"
|
|
6574
|
+
});
|
|
6447
6575
|
await session?.commitTransaction();
|
|
6448
|
-
|
|
6576
|
+
const paypalOrderLink = JSON.parse(order.body.toString()).links.find(
|
|
6577
|
+
(link) => link.rel === "approve"
|
|
6578
|
+
);
|
|
6579
|
+
return {
|
|
6580
|
+
org: String(org),
|
|
6581
|
+
paypalOrderLink: paypalOrderLink ? paypalOrderLink.href : ""
|
|
6582
|
+
};
|
|
6449
6583
|
} catch (error2) {
|
|
6450
6584
|
await session?.abortTransaction();
|
|
6451
6585
|
throw error2;
|
|
@@ -6478,10 +6612,10 @@ function useOrgController() {
|
|
|
6478
6612
|
return;
|
|
6479
6613
|
}
|
|
6480
6614
|
try {
|
|
6481
|
-
const
|
|
6615
|
+
const data = await _add(value);
|
|
6482
6616
|
res.json({
|
|
6483
6617
|
message: "Organization created successfully.",
|
|
6484
|
-
data
|
|
6618
|
+
data
|
|
6485
6619
|
});
|
|
6486
6620
|
return;
|
|
6487
6621
|
} catch (error2) {
|
|
@@ -9739,9 +9873,14 @@ function useUtilController() {
|
|
|
9739
9873
|
}
|
|
9740
9874
|
}
|
|
9741
9875
|
}
|
|
9876
|
+
async function paypalWebhook(req, res, next) {
|
|
9877
|
+
console.log(req.body);
|
|
9878
|
+
return res.status(200).send("OK");
|
|
9879
|
+
}
|
|
9742
9880
|
return {
|
|
9743
9881
|
healthCheck,
|
|
9744
|
-
setGitHubVariables
|
|
9882
|
+
setGitHubVariables,
|
|
9883
|
+
paypalWebhook
|
|
9745
9884
|
};
|
|
9746
9885
|
}
|
|
9747
9886
|
|
|
@@ -10007,6 +10146,7 @@ export {
|
|
|
10007
10146
|
ACCESS_TOKEN_SECRET,
|
|
10008
10147
|
APP_ACCOUNT,
|
|
10009
10148
|
APP_MAIN,
|
|
10149
|
+
APP_ORG,
|
|
10010
10150
|
DEFAULT_USER_EMAIL,
|
|
10011
10151
|
DEFAULT_USER_FIRST_NAME,
|
|
10012
10152
|
DEFAULT_USER_LAST_NAME,
|
|
@@ -10025,6 +10165,7 @@ export {
|
|
|
10025
10165
|
PAYPAL_API_URL,
|
|
10026
10166
|
PAYPAL_CLIENT_ID,
|
|
10027
10167
|
PAYPAL_CLIENT_SECRET,
|
|
10168
|
+
PAYPAL_WEBHOOK_ID,
|
|
10028
10169
|
PORT,
|
|
10029
10170
|
REDIS_HOST,
|
|
10030
10171
|
REDIS_PASSWORD,
|