@bcc-code/payment-client 1.3.0 → 1.3.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/README.md +2 -1
- package/dist/index.d.mts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +8 -2
- package/dist/index.mjs +8 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -61,8 +61,9 @@ const payment = await client.createPayment({
|
|
|
61
61
|
]
|
|
62
62
|
})
|
|
63
63
|
|
|
64
|
-
// Get payment status
|
|
64
|
+
// Get payment status (use { sync: true } after redirect e.g. Vipps to fetch latest from provider)
|
|
65
65
|
const status = await client.getPayment(payment.paymentId)
|
|
66
|
+
// status.paymentMethod (e.g. "vipps"), status.providerStatus (e.g. "CANCELLED") when known
|
|
66
67
|
|
|
67
68
|
// Get receipt
|
|
68
69
|
const receipt = await client.getReceipt(payment.paymentId)
|
package/dist/index.d.mts
CHANGED
|
@@ -64,6 +64,10 @@ interface PaymentResponse {
|
|
|
64
64
|
amount: number;
|
|
65
65
|
currency: string;
|
|
66
66
|
status: string;
|
|
67
|
+
/** Payment method used (e.g. "vipps", "scheme") when known from provider. */
|
|
68
|
+
paymentMethod?: string | null;
|
|
69
|
+
/** Raw status from the provider (e.g. "AUTHORISED", "CANCELLED") when known. */
|
|
70
|
+
providerStatus?: string | null;
|
|
67
71
|
payerUid: string;
|
|
68
72
|
orgId: string;
|
|
69
73
|
createdAt: string;
|
|
@@ -172,7 +176,14 @@ declare class PaymentClient {
|
|
|
172
176
|
private timeout?;
|
|
173
177
|
constructor(options: PaymentClientOptions);
|
|
174
178
|
createPayment(request: CreatePaymentRequest): Promise<CreatePaymentResponse>;
|
|
175
|
-
|
|
179
|
+
/**
|
|
180
|
+
* Get payment status and details.
|
|
181
|
+
* @param paymentId - Payment ID
|
|
182
|
+
* @param options.sync - When true, asks the API to fetch latest status from the provider (e.g. after redirect). Use on first request after returning from Vipps/redirect.
|
|
183
|
+
*/
|
|
184
|
+
getPayment(paymentId: string, options?: {
|
|
185
|
+
sync?: boolean;
|
|
186
|
+
}): Promise<PaymentResponse | null>;
|
|
176
187
|
getReceipt(paymentId: string): Promise<PaymentReceiptResponse | null>;
|
|
177
188
|
getTotalAmountByPrefix(prefix: string): Promise<number>;
|
|
178
189
|
getPaymentMethods(options?: GetPaymentMethodsOptions): Promise<PaymentMethodsConfigResponse>;
|
package/dist/index.d.ts
CHANGED
|
@@ -64,6 +64,10 @@ interface PaymentResponse {
|
|
|
64
64
|
amount: number;
|
|
65
65
|
currency: string;
|
|
66
66
|
status: string;
|
|
67
|
+
/** Payment method used (e.g. "vipps", "scheme") when known from provider. */
|
|
68
|
+
paymentMethod?: string | null;
|
|
69
|
+
/** Raw status from the provider (e.g. "AUTHORISED", "CANCELLED") when known. */
|
|
70
|
+
providerStatus?: string | null;
|
|
67
71
|
payerUid: string;
|
|
68
72
|
orgId: string;
|
|
69
73
|
createdAt: string;
|
|
@@ -172,7 +176,14 @@ declare class PaymentClient {
|
|
|
172
176
|
private timeout?;
|
|
173
177
|
constructor(options: PaymentClientOptions);
|
|
174
178
|
createPayment(request: CreatePaymentRequest): Promise<CreatePaymentResponse>;
|
|
175
|
-
|
|
179
|
+
/**
|
|
180
|
+
* Get payment status and details.
|
|
181
|
+
* @param paymentId - Payment ID
|
|
182
|
+
* @param options.sync - When true, asks the API to fetch latest status from the provider (e.g. after redirect). Use on first request after returning from Vipps/redirect.
|
|
183
|
+
*/
|
|
184
|
+
getPayment(paymentId: string, options?: {
|
|
185
|
+
sync?: boolean;
|
|
186
|
+
}): Promise<PaymentResponse | null>;
|
|
176
187
|
getReceipt(paymentId: string): Promise<PaymentReceiptResponse | null>;
|
|
177
188
|
getTotalAmountByPrefix(prefix: string): Promise<number>;
|
|
178
189
|
getPaymentMethods(options?: GetPaymentMethodsOptions): Promise<PaymentMethodsConfigResponse>;
|
package/dist/index.js
CHANGED
|
@@ -56,13 +56,19 @@ var PaymentClient = class {
|
|
|
56
56
|
}
|
|
57
57
|
return await response.json();
|
|
58
58
|
}
|
|
59
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Get payment status and details.
|
|
61
|
+
* @param paymentId - Payment ID
|
|
62
|
+
* @param options.sync - When true, asks the API to fetch latest status from the provider (e.g. after redirect). Use on first request after returning from Vipps/redirect.
|
|
63
|
+
*/
|
|
64
|
+
async getPayment(paymentId, options) {
|
|
60
65
|
const token = await this.getAuthToken();
|
|
61
66
|
const controller = new AbortController();
|
|
62
67
|
if (this.timeout) {
|
|
63
68
|
setTimeout(() => controller.abort(), this.timeout);
|
|
64
69
|
}
|
|
65
|
-
const
|
|
70
|
+
const url = options?.sync ? `${this.baseUrl}/api/v1/payments/${paymentId}?sync=true` : `${this.baseUrl}/api/v1/payments/${paymentId}`;
|
|
71
|
+
const response = await fetch(url, {
|
|
66
72
|
headers: {
|
|
67
73
|
"Authorization": `Bearer ${token}`,
|
|
68
74
|
"X-Tenant-ID": this.tenantId
|
package/dist/index.mjs
CHANGED
|
@@ -30,13 +30,19 @@ var PaymentClient = class {
|
|
|
30
30
|
}
|
|
31
31
|
return await response.json();
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Get payment status and details.
|
|
35
|
+
* @param paymentId - Payment ID
|
|
36
|
+
* @param options.sync - When true, asks the API to fetch latest status from the provider (e.g. after redirect). Use on first request after returning from Vipps/redirect.
|
|
37
|
+
*/
|
|
38
|
+
async getPayment(paymentId, options) {
|
|
34
39
|
const token = await this.getAuthToken();
|
|
35
40
|
const controller = new AbortController();
|
|
36
41
|
if (this.timeout) {
|
|
37
42
|
setTimeout(() => controller.abort(), this.timeout);
|
|
38
43
|
}
|
|
39
|
-
const
|
|
44
|
+
const url = options?.sync ? `${this.baseUrl}/api/v1/payments/${paymentId}?sync=true` : `${this.baseUrl}/api/v1/payments/${paymentId}`;
|
|
45
|
+
const response = await fetch(url, {
|
|
40
46
|
headers: {
|
|
41
47
|
"Authorization": `Bearer ${token}`,
|
|
42
48
|
"X-Tenant-ID": this.tenantId
|