cybersource-brunei-payauth 0.2.2 → 0.2.3
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 +1 -1
- package/src/httpClient.js +42 -5
- package/src/payments.js +5 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cybersource-brunei-payauth",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Cybersource payer-authentication (3-D Secure) + payments client for Brunei merchants. Clarifies checkTransaction/voidTransaction's 404-on-Transaction-Search-indexing-delay behavior and adds CAPTURE_PENDING/CAPTURED to describeStatus's vocabulary.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
package/src/httpClient.js
CHANGED
|
@@ -20,6 +20,43 @@ function createHttpClient({
|
|
|
20
20
|
);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
function extractCybersourceError(parsed, status) {
|
|
24
|
+
if (parsed?.errorInformation) {
|
|
25
|
+
return {
|
|
26
|
+
reason: parsed.errorInformation.reason || "UNKNOWN_ERROR",
|
|
27
|
+
|
|
28
|
+
message:
|
|
29
|
+
parsed.errorInformation.message ||
|
|
30
|
+
`Cybersource request failed with status ${status}`,
|
|
31
|
+
|
|
32
|
+
details: {
|
|
33
|
+
...parsed.errorInformation,
|
|
34
|
+
transactionId: parsed.id,
|
|
35
|
+
clientReferenceInformation: parsed.clientReferenceInformation,
|
|
36
|
+
status: parsed.status,
|
|
37
|
+
rawResponse: parsed,
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (parsed?.errors?.length) {
|
|
43
|
+
return {
|
|
44
|
+
reason: parsed.errors[0]?.reason || "UNKNOWN_ERROR",
|
|
45
|
+
message:
|
|
46
|
+
parsed.errors[0]?.message ||
|
|
47
|
+
`Cybersource request failed with status ${status}`,
|
|
48
|
+
details: parsed.errors,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
reason: parsed?.reason || "UNKNOWN_ERROR",
|
|
54
|
+
message:
|
|
55
|
+
parsed?.message || `Cybersource request failed with status ${status}`,
|
|
56
|
+
details: parsed?.details || parsed,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
23
60
|
async function request(method, path, body) {
|
|
24
61
|
const date = new Date().toUTCString();
|
|
25
62
|
const signatureHeaders = buildSignatureHeaders({
|
|
@@ -69,13 +106,13 @@ function createHttpClient({
|
|
|
69
106
|
}
|
|
70
107
|
|
|
71
108
|
if (!response.ok) {
|
|
109
|
+
const error = extractCybersourceError(parsed, response.status);
|
|
110
|
+
|
|
72
111
|
throw new CyberSourceApiError({
|
|
73
112
|
status: response.status,
|
|
74
|
-
reason:
|
|
75
|
-
message:
|
|
76
|
-
|
|
77
|
-
`Cybersource request failed with status ${response.status}`,
|
|
78
|
-
details: parsed.details || parsed,
|
|
113
|
+
reason: error.reason,
|
|
114
|
+
message: error.message,
|
|
115
|
+
details: error.details,
|
|
79
116
|
});
|
|
80
117
|
}
|
|
81
118
|
|
package/src/payments.js
CHANGED
|
@@ -51,11 +51,11 @@ async function authorize(
|
|
|
51
51
|
saveCard = false,
|
|
52
52
|
},
|
|
53
53
|
) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
if (!authenticationResult) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
"authorize requires authenticationResult: no 3-D Secure authentication result was provided",
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
59
|
|
|
60
60
|
// Cybersource requires processingInformation.commerceIndicator on every payer-authenticated
|
|
61
61
|
// authorization — it does not derive it from consumerAuthenticationInformation server-side, and
|