Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for Vipps refund, cancel, and capture #225

Merged
merged 3 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/node-service-api-request-handlers/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@crystallize/node-service-api-request-handlers",
"license": "MIT",
"version": "3.8.0",
"version": "3.9.0",
"author": "Crystallize <hello@crystallize.com> (https://crystallize.com)",
"contributors": [
"Sébastien Morel <sebastien@crystallize.com>"
Expand Down
3 changes: 3 additions & 0 deletions components/node-service-api-request-handlers/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ export * from './payments/vipps/fetchPayment';
export * from './payments/vipps/addReceiptOrder';
export * from './payments/vipps/fetchTokenFromOAuthCode';
export * from './payments/vipps/fetchUserInfoFromOAuthToken';
export * from './payments/vipps/capturePayment';
export * from './payments/vipps/cancelPayment';
export * from './payments/vipps/refundPayment';
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { createClient } from './client';
import { VippsAppCredentials } from './types';

export const cancelVippsPayment = async (orderId: string, credentials: VippsAppCredentials, body: any) => {
const client = await createClient({
...credentials,
fetchToken: false,
});
const cancelConfirmation = await client.put(`/ecomm/v2/payments/${orderId}/cancel`, body, orderId);

return cancelConfirmation;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { createClient } from './client';
import { VippsAppCredentials } from './types';

export const captureVippsPayment = async (orderId: string, credentials: VippsAppCredentials, body: any) => {
const client = await createClient({
...credentials,
fetchToken: false,
});
const capturedConfirmation = await client.post(`/ecomm/v2/payments/${orderId}/capture`, body, orderId);

return capturedConfirmation;
};
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ export const createClient = async ({
...init,
});
},
put: async <T>(endpoint: string, body: any, idempotencyKey: string, init?: RequestInit): Promise<T> => {
return fetchResult(`https://${origin}${endpoint}`, {
method: 'PUT',
headers: {
...(idempotencyKey.length > 0 ? { 'Idempotency-Key': idempotencyKey } : {}),
...authHeaders,
...extraHeaders,
},
body: JSON.stringify(body),
...init,
});
},
formEncodedPost: async <T>(
endpoint: string,
body: any,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { createClient } from './client';
import { VippsAppCredentials } from './types';

export const refundVippsPayment = async (orderId: string, credentials: VippsAppCredentials, body: any) => {
const client = await createClient({
...credentials,
fetchToken: false,
});
const refundConfirmation = await client.post(`/ecomm/v2/payments/${orderId}/refund`, body, orderId);

return refundConfirmation;
};
Loading