octopian-apis 1.0.25 → 1.0.26
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TransactionsAPIConstants } from "../web-services/darAlBerConstants";
|
|
2
2
|
import * as apiHandler from "../web-services/dabAPIHandler";
|
|
3
3
|
import { GetAttributeTypeValueList } from "../CoreServices/transactionsServices";
|
|
4
|
-
import { DABAddRequest } from "./requestsServices";
|
|
4
|
+
import { DABAddRequest, DABSubmitCart } from "./requestsServices";
|
|
5
5
|
|
|
6
6
|
//#region Requester
|
|
7
7
|
|
|
@@ -1286,6 +1286,7 @@ export async function DABGetPaymentURL(
|
|
|
1286
1286
|
) {
|
|
1287
1287
|
try {
|
|
1288
1288
|
let serviceID = getPaymentURLDTO.ServiceID;
|
|
1289
|
+
let isAddToCart = false;
|
|
1289
1290
|
if (serviceID === 0 && getPaymentURLDTO.ServiceAlias) {
|
|
1290
1291
|
// Fetch the list of services
|
|
1291
1292
|
const servicesList = await apiHandler.PostMethod(
|
|
@@ -1326,6 +1327,7 @@ export async function DABGetPaymentURL(
|
|
|
1326
1327
|
};
|
|
1327
1328
|
} else {
|
|
1328
1329
|
serviceID = service.ServiceId;
|
|
1330
|
+
isAddToCart = service.AddToCart;
|
|
1329
1331
|
}
|
|
1330
1332
|
}
|
|
1331
1333
|
|
|
@@ -1405,7 +1407,7 @@ export async function DABGetPaymentURL(
|
|
|
1405
1407
|
(attribute) => attribute.Alias === getPaymentURLDTO.PaymentURLAlias
|
|
1406
1408
|
);
|
|
1407
1409
|
if (paymentURL && paymentURL.Value) {
|
|
1408
|
-
DABAddRequest(
|
|
1410
|
+
let addrequestResult = await DABAddRequest(
|
|
1409
1411
|
{
|
|
1410
1412
|
ServiceId: serviceID,
|
|
1411
1413
|
AssetId: getPaymentURLDTO.AssetId,
|
|
@@ -1417,6 +1419,14 @@ export async function DABGetPaymentURL(
|
|
|
1417
1419
|
Timeout,
|
|
1418
1420
|
RequiredHeaderValue
|
|
1419
1421
|
);
|
|
1422
|
+
if (addrequestResult.StatusCode === 200 && isAddToCart) {
|
|
1423
|
+
DABSubmitCart({
|
|
1424
|
+
RequestId: addrequestResult.Result.RequestId,
|
|
1425
|
+
ShippingAddressId: 0,
|
|
1426
|
+
BillingAddressId: 0,
|
|
1427
|
+
PaymentMethod: "Card",
|
|
1428
|
+
});
|
|
1429
|
+
}
|
|
1420
1430
|
return {
|
|
1421
1431
|
Message: "Success",
|
|
1422
1432
|
StatusCode: 200,
|
|
@@ -1445,6 +1455,149 @@ export async function DABGetPaymentURL(
|
|
|
1445
1455
|
}
|
|
1446
1456
|
}
|
|
1447
1457
|
|
|
1458
|
+
/**
|
|
1459
|
+
* @description
|
|
1460
|
+
* Adds a service to the cart.
|
|
1461
|
+
*
|
|
1462
|
+
* @param {object} AddToCartDTO
|
|
1463
|
+
* Data object containing fields necessary for adding a service to the cart.
|
|
1464
|
+
* ServiceID: number
|
|
1465
|
+
* ServiceAlias: string
|
|
1466
|
+
* AssetId: number
|
|
1467
|
+
* ParametersValues: ParametersValues[]
|
|
1468
|
+
*
|
|
1469
|
+
* @param {string} AuthToken
|
|
1470
|
+
* Authentication token for authorization purposes.
|
|
1471
|
+
*
|
|
1472
|
+
* @param {number} Timeout
|
|
1473
|
+
* Time in milliseconds to wait before the request times out. Default is 30000.
|
|
1474
|
+
*
|
|
1475
|
+
* @param {string} RequiredHeaderValue
|
|
1476
|
+
* Value for any required header. Default is null.
|
|
1477
|
+
*
|
|
1478
|
+
* @returns
|
|
1479
|
+
* An object containing the response from the Add To Cart API,
|
|
1480
|
+
* including success message, status code, and any additional data returned by the API.
|
|
1481
|
+
* Message: Success,
|
|
1482
|
+
* StatusCode: 200,
|
|
1483
|
+
* Result: RequestId
|
|
1484
|
+
*/
|
|
1485
|
+
export async function DABAddToCart(
|
|
1486
|
+
AddToCartDTO,
|
|
1487
|
+
AuthToken = null,
|
|
1488
|
+
Timeout = 30000,
|
|
1489
|
+
RequiredHeaderValue = null
|
|
1490
|
+
) {
|
|
1491
|
+
try {
|
|
1492
|
+
let serviceID = AddToCartDTO.ServiceID;
|
|
1493
|
+
if (serviceID === 0 && AddToCartDTO.ServiceAlias) {
|
|
1494
|
+
// Fetch the list of services
|
|
1495
|
+
const servicesList = await apiHandler.PostMethod(
|
|
1496
|
+
TransactionsAPIConstants.uriGetServiceList(),
|
|
1497
|
+
{ PageSize: 1000, PageIndex: 0 },
|
|
1498
|
+
AuthToken,
|
|
1499
|
+
Timeout,
|
|
1500
|
+
RequiredHeaderValue,
|
|
1501
|
+
true
|
|
1502
|
+
);
|
|
1503
|
+
|
|
1504
|
+
// Validate the response
|
|
1505
|
+
if (!servicesList || !Array.isArray(servicesList.Result)) {
|
|
1506
|
+
return {
|
|
1507
|
+
Message: "Error",
|
|
1508
|
+
StatusCode: -1,
|
|
1509
|
+
Result: {
|
|
1510
|
+
ErrorMessage: "Could not fetch service list",
|
|
1511
|
+
ErrorRefNo: "-1",
|
|
1512
|
+
},
|
|
1513
|
+
};
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
// Find the service with the matching alias
|
|
1517
|
+
const service = servicesList.Result.find(
|
|
1518
|
+
(service) => service.Alias === AddToCartDTO.ServiceAlias
|
|
1519
|
+
);
|
|
1520
|
+
|
|
1521
|
+
// Check if the service was found
|
|
1522
|
+
if (!service) {
|
|
1523
|
+
return {
|
|
1524
|
+
Message: "Error",
|
|
1525
|
+
StatusCode: -1,
|
|
1526
|
+
Result: {
|
|
1527
|
+
ErrorMessage: `Service with alias ${AddToCartDTO.ServiceAlias} not found`,
|
|
1528
|
+
ErrorRefNo: "-1",
|
|
1529
|
+
},
|
|
1530
|
+
};
|
|
1531
|
+
} else {
|
|
1532
|
+
serviceID = service.ServiceId;
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
// Fetch the service parameters
|
|
1537
|
+
const serviceAttributes = await apiHandler.PostMethod(
|
|
1538
|
+
TransactionsAPIConstants.uriGetServiceRequestAttributeList(),
|
|
1539
|
+
{
|
|
1540
|
+
ServiceId: serviceID,
|
|
1541
|
+
AssetId: AddToCartDTO.AssetId,
|
|
1542
|
+
IsParameters: false,
|
|
1543
|
+
},
|
|
1544
|
+
AuthToken,
|
|
1545
|
+
Timeout,
|
|
1546
|
+
RequiredHeaderValue,
|
|
1547
|
+
true
|
|
1548
|
+
);
|
|
1549
|
+
|
|
1550
|
+
// Validate the service attributes response
|
|
1551
|
+
if (!serviceAttributes || !Array.isArray(serviceAttributes.Result)) {
|
|
1552
|
+
return {
|
|
1553
|
+
Message: "Error",
|
|
1554
|
+
StatusCode: -1,
|
|
1555
|
+
Result: {
|
|
1556
|
+
ErrorMessage: "Invalid response format for service parameters",
|
|
1557
|
+
ErrorRefNo: "-1",
|
|
1558
|
+
},
|
|
1559
|
+
};
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1562
|
+
serviceAttributes.Result.forEach((element) => {
|
|
1563
|
+
if (
|
|
1564
|
+
AddToCartDTO.ParametersValues.find(
|
|
1565
|
+
(param) => param.Alias === element.Alias
|
|
1566
|
+
)
|
|
1567
|
+
) {
|
|
1568
|
+
element.Value = AddToCartDTO.ParametersValues.find(
|
|
1569
|
+
(param) => param.Alias === element.Alias
|
|
1570
|
+
).Value;
|
|
1571
|
+
element.ExtendedValue = AddToCartDTO.ParametersValues.find(
|
|
1572
|
+
(param) => param.Alias === element.Alias
|
|
1573
|
+
).ExtendedValue;
|
|
1574
|
+
}
|
|
1575
|
+
});
|
|
1576
|
+
|
|
1577
|
+
let addrequestResult = await DABAddRequest(
|
|
1578
|
+
{
|
|
1579
|
+
ServiceId: serviceID,
|
|
1580
|
+
AssetId: AddToCartDTO.AssetId,
|
|
1581
|
+
BatchId: 0,
|
|
1582
|
+
ClientRequestAttributeDtos: serviceAttributes.Result,
|
|
1583
|
+
},
|
|
1584
|
+
AuthToken,
|
|
1585
|
+
Timeout,
|
|
1586
|
+
RequiredHeaderValue
|
|
1587
|
+
);
|
|
1588
|
+
return addrequestResult;
|
|
1589
|
+
} catch (error) {
|
|
1590
|
+
// Handle errors
|
|
1591
|
+
return {
|
|
1592
|
+
Message: "Error",
|
|
1593
|
+
StatusCode: -1,
|
|
1594
|
+
Result: {
|
|
1595
|
+
ErrorMessage: "Error fetching Payment URL",
|
|
1596
|
+
ErrorRefNo: "-1",
|
|
1597
|
+
},
|
|
1598
|
+
};
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1448
1601
|
/**
|
|
1449
1602
|
* @description
|
|
1450
1603
|
* Fetches the payment invoice details for a given invoice ID.
|
package/src/darAlBerServices.ts
CHANGED
|
@@ -1586,6 +1586,13 @@ interface DarAlBerServices {
|
|
|
1586
1586
|
Timeout?: number | null,
|
|
1587
1587
|
RequiredHeaderValue?: string
|
|
1588
1588
|
) => BaseResponse<string | BaseErrorResponse>;
|
|
1589
|
+
|
|
1590
|
+
DABAddToCart: (
|
|
1591
|
+
Input: GetPaymentURLInput,
|
|
1592
|
+
AuthToken?: string | null,
|
|
1593
|
+
Timeout?: number | null,
|
|
1594
|
+
RequiredHeaderValue?: string
|
|
1595
|
+
) => BaseResponse<AddRequestOutput | BaseErrorResponse>;
|
|
1589
1596
|
/**
|
|
1590
1597
|
* @description
|
|
1591
1598
|
* Fetches the payment invoice for a given invoice ID.
|