From b3bae0d7814a07e10584d20119430fa214b3443a Mon Sep 17 00:00:00 2001 From: Tomas Zijdemans Date: Fri, 4 Oct 2024 21:55:18 +0200 Subject: [PATCH 1/2] Add recurring --- sample_code/recurring_agreement_sample.ts | 110 + sample_code/recurring_charge_sample.ts | 108 + scripts/generate_types.ts | 17 +- src/api_proxy.ts | 14 + src/apis/recurring.ts | 333 ++ src/apis/util.ts | 18 + src/generated_types/recurring/types.gen.ts | 3524 ++++++++++++++++++++ src/types_external.ts | 21 + tests/mod_test.ts | 13 + tests/recurring_test.ts | 257 ++ tests/util_test.ts | 35 + 11 files changed, 4446 insertions(+), 4 deletions(-) create mode 100644 sample_code/recurring_agreement_sample.ts create mode 100644 sample_code/recurring_charge_sample.ts create mode 100644 src/apis/recurring.ts create mode 100644 src/apis/util.ts create mode 100644 src/generated_types/recurring/types.gen.ts create mode 100644 tests/recurring_test.ts create mode 100644 tests/util_test.ts diff --git a/sample_code/recurring_agreement_sample.ts b/sample_code/recurring_agreement_sample.ts new file mode 100644 index 0000000..7bfeadd --- /dev/null +++ b/sample_code/recurring_agreement_sample.ts @@ -0,0 +1,110 @@ +import "@std/dotenv/load"; +import { Client } from "../src/mod.ts"; + +// First, get your API keys from https://portal.vipps.no/ +// Here we assume they are stored in a .env file, see .env.example +const clientId = Deno.env.get("CLIENT_ID") || ""; +const clientSecret = Deno.env.get("CLIENT_SECRET") || ""; + +const merchantSerialNumber = Deno.env.get("MERCHANT_SERIAL_NUMBER") || ""; +const subscriptionKey = Deno.env.get("SUBSCRIPTION_KEY") || ""; + +const customerPhoneNumber = "4791234567"; + +// Create a client +const client = Client({ + merchantSerialNumber, + subscriptionKey, + useTestMode: true, + retryRequests: false, +}); + +// Grab a token +const accessToken = await client.auth.getToken(clientId, clientSecret); + +// Check if the token was retrieved successfully +if (!accessToken.ok) { + console.error("😟 Error retrieving token 😟"); + console.error(accessToken.error); + Deno.exit(1); +} + +const token = accessToken.data.access_token; + +const agreement = await client.recurring.agreement.create(token, { + pricing: { + type: "LEGACY", + amount: 2500, + currency: "NOK", + }, + interval: { + unit: "MONTH", + count: 1, + }, + merchantRedirectUrl: "https://example.com/redirect", + merchantAgreementUrl: "https://example.com/agreement", + phoneNumber: customerPhoneNumber, + productName: "MyNews Digital", +}); + +// Check if the agreement was created successfully +if (!agreement.ok) { + console.error("😟 Error creating agreement 😟"); + console.error(agreement.error); + Deno.exit(1); +} + +const agreementInfo = await client.recurring.agreement.info( + token, + agreement.data.agreementId, +); + +// Check if the agreement was retrieved successfully +if (!agreementInfo.ok) { + console.error("😟 Error retreiving agreement 😟"); + console.error(agreementInfo.error); + Deno.exit(1); +} + +const activatedAgreement = await client.recurring.agreement.forceAccept( + token, + agreement.data.agreementId, + { + phoneNumber: customerPhoneNumber, + }, +); + +// Check if the agreement was retrieved successfully +if (!activatedAgreement.ok) { + console.error("😟 Error force accepting the agreement 😟"); + console.error(activatedAgreement.error); + Deno.exit(1); +} + +const updatedAgreement = await client.recurring.agreement.update( + token, + agreement.data.agreementId, + { status: "STOPPED" }, +); + +// Check if the agreement was retrieved successfully +if (!updatedAgreement.ok) { + console.error("😟 Error updating agreement 😟"); + console.error(updatedAgreement.error); + Deno.exit(1); +} + +const listAgreements = await client.recurring.agreement.list( + token, + "STOPPED", + 1, +); + +// Check if the agreements was retrieved successfully +if (!listAgreements.ok) { + console.error("😟 Error retreiving agreements 😟"); + console.error(listAgreements.error); + Deno.exit(1); +} + +console.log(listAgreements.data); \ No newline at end of file diff --git a/sample_code/recurring_charge_sample.ts b/sample_code/recurring_charge_sample.ts new file mode 100644 index 0000000..a141579 --- /dev/null +++ b/sample_code/recurring_charge_sample.ts @@ -0,0 +1,108 @@ +import "@std/dotenv/load"; +import { Client } from "../src/mod.ts"; + +// First, get your API keys from https://portal.vipps.no/ +// Here we assume they are stored in a .env file, see .env.example +const clientId = Deno.env.get("CLIENT_ID") || ""; +const clientSecret = Deno.env.get("CLIENT_SECRET") || ""; + +const merchantSerialNumber = Deno.env.get("MERCHANT_SERIAL_NUMBER") || ""; +const subscriptionKey = Deno.env.get("SUBSCRIPTION_KEY") || ""; + +const customerPhoneNumber = "4791234567"; + +// Create a client +const client = Client({ + merchantSerialNumber, + subscriptionKey, + useTestMode: true, + retryRequests: false, +}); + +// Grab a token +const accessToken = await client.auth.getToken(clientId, clientSecret); + +// Check if the token was retrieved successfully +if (!accessToken.ok) { + console.error("😟 Error retrieving token 😟"); + console.error(accessToken.error); + Deno.exit(1); +} + +const token = accessToken.data.access_token; + +const agreement = await client.recurring.agreement.create(token, { + pricing: { + type: "LEGACY", + amount: 2500, + currency: "NOK", + }, + interval: { + unit: "MONTH", + count: 1, + }, + merchantRedirectUrl: "https://example.com/redirect", + merchantAgreementUrl: "https://example.com/agreement", + phoneNumber: customerPhoneNumber, + productName: "MyNews Digital", +}); + +// Check if the agreement was created successfully +if (!agreement.ok) { + console.error("😟 Error creating agreement 😟"); + console.error(agreement.error); + Deno.exit(1); +} + +const agreementId = agreement.data.agreementId; + +const acceptedAgreement = await client.recurring.agreement.forceAccept( + token, + agreementId, + { phoneNumber: customerPhoneNumber }, +); + +// Check if the agreement was accepted successfully +if (!acceptedAgreement.ok) { + console.error("😟 Error accepting agreement 😟"); + console.error(acceptedAgreement.error); + Deno.exit(1); +} + +// 10 days from now in YYYY-MM-DD format +const tenDaysFromToday = new Date(Date.now() + 10 * 24 * 60 * 60 * 1000) + .toISOString().split("T")[0]; + +const charge = await client.recurring.charge.create(token, agreementId, { + amount: 2500, + description: "MyNews Digital", + orderId: crypto.randomUUID(), + due: tenDaysFromToday, + retryDays: 5, + transactionType: "DIRECT_CAPTURE", + type: "RECURRING", +}); + +// Check if the charge was created successfully +if (!charge.ok) { + console.error("😟 Error creating charge 😟"); + console.error(charge.error); + Deno.exit(1); +} + +const chargeId = charge.data.chargeId || ""; + +const chargeInfo = await client.recurring.charge.info( + token, + agreementId, + chargeId, +); + +// Check if the charge info was fetched successfully +if (!chargeInfo.ok) { + console.error("😟 Error retrieving charge 😟"); + console.error(chargeInfo.error); + Deno.exit(1); +} + +console.log(chargeInfo.data); \ No newline at end of file diff --git a/scripts/generate_types.ts b/scripts/generate_types.ts index e92bc08..bffe583 100644 --- a/scripts/generate_types.ts +++ b/scripts/generate_types.ts @@ -27,8 +27,7 @@ await run(`rm -rf src/generated_types/checkout/index.ts`); // ePayment API await createClient({ - input: - "https://developer.vippsmobilepay.com/redocusaurus/epayment-swagger-id.yaml", + input: "https://developer.vippsmobilepay.com/redocusaurus/epayment-swagger-id.yaml", output: "src/generated_types/epayment", services: false, exportCore: false, @@ -37,10 +36,20 @@ await createClient({ await run(`rm -rf src/generated_types/epayment/index.ts`); +// Recurring API +await createClient({ + input: "https://developer.vippsmobilepay.com/redocusaurus/recurring-swagger-id.yaml", + output: "src/generated_types/recurring", + services: false, + exportCore: false, + schemas: false, +}); + +await run(`rm -rf src/generated_types/recurring/index.ts`); + // Webhooks API await createClient({ - input: - "https://developer.vippsmobilepay.com/redocusaurus/webhooks-swagger-id.yaml", + input: "https://developer.vippsmobilepay.com/redocusaurus/webhooks-swagger-id.yaml", output: "src/generated_types/webhooks", services: false, exportCore: false, diff --git a/src/api_proxy.ts b/src/api_proxy.ts index 96bc767..33dc561 100644 --- a/src/api_proxy.ts +++ b/src/api_proxy.ts @@ -1,6 +1,10 @@ import { authRequestFactory } from "./apis/auth.ts"; import { checkoutRequestFactory } from "./apis/checkout.ts"; import { ePaymentRequestFactory } from "./apis/epayment.ts"; +import { + agreementRequestFactory, + chargeRequestFactory, +} from "./apis/recurring.ts"; import { webhooksRequestFactory } from "./apis/webhooks.ts"; import type { ApiProxy, BaseClient, RequestFactory } from "./types_internal.ts"; @@ -8,6 +12,12 @@ export type SDKClient = { auth: ReturnType>; checkout: ReturnType>; payment: ReturnType>; + recurring: { + charge: ReturnType>; + agreement: ReturnType< + typeof proxifyFactory + >; + }; webhook: ReturnType>; }; @@ -21,6 +31,10 @@ export const proxifyClient = (client: BaseClient): SDKClient => { auth: proxifyFactory(client, authRequestFactory), checkout: proxifyFactory(client, checkoutRequestFactory), payment: proxifyFactory(client, ePaymentRequestFactory), + recurring: { + charge: proxifyFactory(client, chargeRequestFactory), + agreement: proxifyFactory(client, agreementRequestFactory), + }, webhook: proxifyFactory(client, webhooksRequestFactory), } as const; }; diff --git a/src/apis/recurring.ts b/src/apis/recurring.ts new file mode 100644 index 0000000..5c305a5 --- /dev/null +++ b/src/apis/recurring.ts @@ -0,0 +1,333 @@ +import type { + AgreementResponseV3, + AgreementStatus, + CaptureRequestV3, + ChargeReference, + ChargeResponseV3, + ChargeStatus, + CreateChargeAsyncV3, + CreateChargeAsyncV3Response, + CreateChargeV3, + DraftAgreementResponseV3, + DraftAgreementV3, + ErrorV3, + ForceAcceptAgreementV3, + PatchAgreementV3, + RefundRequest, +} from "../types_external.ts"; +import type { RequestData } from "../types_internal.ts"; +import { generatePathParams } from "./util.ts"; + +/** + * Factory object for creating and managing agreements. + */ +export const agreementRequestFactory = { + /** + * The API endpoint allows merchants to create agreements for a user to accept. + * Once the agreement is drafted, you will receive a vippsConfirmationUrl. + * This is used to redirect the user to the Vipps MobilePay landing page, + * or to the Vipps or MobilePay app when "isApp":true is used. + * + * If the user accepts or rejects the agreement, the user will be redirected back to + * whichever URL has been passed in merchantRedirectUrl. You must implement polling + * on the agreement to check when the status changes to active, instead of relying + * on the redirect back to the merchantRedirectUrl. We have no control over if a user + * is actually redirected back or not, this depends on what browser the user came from. + * + * Please note the different use cases for initialCharge and campaign. + * And when to use RESERVE_CAPTURE instead of DIRECT_CAPTURE as transactionType. + * More information about this can be found in the API documentation. + * + * @param token - The authentication token. + * @param body - The draft agreement data. + * @returns A `DraftAgreementResponseV3` or `ErrorV3` object. + */ + create: ( + token: string, + body: DraftAgreementV3, + ): RequestData => { + return { + url: "/recurring/v3/agreements", + method: "POST", + body, + token, + }; + }, + /** + * The API endpoint allows merchant to fetch all agreements. + * If no query status is supplied it will default to only retrieving active agreements. + * There is no way to list all Agreements with all statuses, this is due to performance. + * It is recommended to use the pageNumber and pageSize query to paginate the response. + * + * @param token - The authentication token. + * @param status - The status of the agreements to retrieve. + * @param createdAfter - Filter by createdAfter timestamp (in milliseconds) for paginating. Example: 1644572442944 + * @param pageNumber - Page number for paginating. + * @param pageSize - Page size for paginating (must be used in combination with pageNumber). Example: 500 + * + * @returns `Array` or `ErrorV3` object. + */ + list: ( + token: string, + status?: AgreementStatus, + createdAfter?: number, + pageNumber?: number, + pageSize?: number, + ): RequestData, ErrorV3> => { + const params = generatePathParams({ + status, + createdAfter, + pageNumber, + pageSize, + }); + return { + url: `/recurring/v3/agreements${params}`, + method: "GET", + token, + }; + }, + /** + * Fetch a single agreement for a user. Recommended to use when polling for status changes + * after sending an agreement to a user. + * + * @param token - The authentication token. + * @param agreementId - The ID of the agreement to retrieve. + * @returns A `AgreementResponseV3` or `ErrorV3` object. + */ + info: ( + token: string, + agreementId: string, + ): RequestData => { + return { + url: `/recurring/v3/agreements/${agreementId}`, + method: "GET", + token, + }; + }, + /** + * Updates the agreement. Note that when updating the status to STOPPED, you can not re-activate it. + * If you want to pause an agreement, we suggest leaving the agreement active and skipping + * the creation of charges as long as the agreement is paused in your systems. + * + * @param token - The authentication token. + * @param agreementId - The ID of the agreement to update. + * @param body - The patch data for the agreement. + * @returns unknown, void or a `ErrorV3` object. + */ + update: ( + token: string, + agreementId: string, + body: PatchAgreementV3, + ): RequestData => { + return { + url: `/recurring/v3/agreements/${agreementId}`, + method: "PATCH", + body, + token, + }; + }, + /** + * Forces an agreement to be accepted by the given customer phone number. + * This endpoint can only be used in the test environment. + * + * @param token - The authentication token. + * @param agreementId - The ID of the agreement to force accept. + * @param body - The force accept data for the agreement. + * @returns an empty object or a `ErrorV3` object. + */ + forceAccept: ( + token: string, + agreementId: string, + body: ForceAcceptAgreementV3, + ): RequestData => { + return { + url: `/recurring/v3/agreements/${agreementId}/accept`, + method: "PATCH", + body, + token, + }; + }, +}; + +/** + * Factory object for managing charge API requests. + */ +export const chargeRequestFactory = { + /** + * Creates a new recurring charge (payment) that will charge the user + * on the date specified. If the payment fails, + * the charge will be retried based on retryDays + * + * @param token - The authentication token. + * @param agreementId - The ID of the agreement. + * @param body - The request body containing the charge details. + * @returns A `ChargeReference` or `ErrorV3` object. + */ + create: ( + token: string, + agreementId: string, + body: CreateChargeV3, + ): RequestData => { + return { + url: `/recurring/v3/agreements/${agreementId}/charges`, + method: "POST", + body, + token, + }; + }, + /** + * Asynchronously creates multiple new recurring charges (payments) that + * will be automatically processed on the due date. If the payment fails, + * the charge will be retried based on retryDays + * + * @param token - The authentication token. + * @param body - The request body containing the charge details. + * @returns An `CreateChargeAsyncV3Response` object, or a `ErrorV3` object. + */ + createMultiple: ( + token: string, + body: Array, + ): RequestData => { + return { + url: `/recurring/v3/agreements/charges`, + method: "POST", + body, + token, + }; + }, + /** + * Fetches a single charge for a user. + * + * @param token - The authentication token. + * @param agreementId - The ID of the agreement. + * @param chargeId - The ID of the charge to retrieve. + * @returns A `ChargeResponseV3` or `ErrorV3` object. + */ + info: ( + token: string, + agreementId: string, + chargeId: string, + ): RequestData => { + return { + url: `/recurring/v3/agreements/${agreementId}/charges/${chargeId}`, + method: "GET", + token, + }; + }, + /** + * Retrieves information about a charge by its ID. A "special case" + * endpoint to fetch a single charge just by chargeId, when the + * agreementId is unknown. This is useful for investigating + * claims from customers, but not intended for automation. + * + * Please note: This is not a replacement for the normal endpoint + * for fetching charges + * + * @param token - The access token. + * @param chargeId - The ID of the charge. + * @returns A `ChargeResponseV3` or `ErrorV3` object. + */ + infoById: ( + token: string, + chargeId: string, + ): RequestData => { + return { + url: `/recurring/v3/charges/${chargeId}`, + method: "GET", + token, + }; + }, + /** + * Fetches all charges for a single agreement, including the optional + * initial charge. Supports filtering on status using query parameter. + * + * @param token - The authentication token. + * @param agreementId - The ID of the agreement. + * @param status - The status of the charges to retrieve (optional). + * @returns An array of `ChargeResponseV3` objects, or a `ErrorV3` object. + */ + list: ( + token: string, + agreementId: string, + status?: ChargeStatus, + ): RequestData, ErrorV3> => { + const params = generatePathParams({ status }); + return { + url: `/recurring/v3/agreements/${agreementId}/charges${params}`, + method: "GET", + token, + }; + }, + /** + * Cancels a pending, due or reserved charge. When cancelling a charge + * that is PARTIALLY_CAPTURED, the remaining funds on the charge + * will be released back to the customer. + * + * Note if you cancel an agreement, there is no need to cancel the + * charges that belongs to the agreement. This will be done automatically. + * + * @param token - The authentication token. + * @param agreementId - The ID of the agreement. + * @param chargeId - The ID of the charge. + * @returns unknown, void or a `ErrorV3` object. + */ + cancel: ( + token: string, + agreementId: string, + chargeId: string, + ): RequestData => { + return { + url: `/recurring/v3/agreements/${agreementId}/charges/${chargeId}`, + method: "DELETE", + token, + }; + }, + /** + * Captures a reserved charge. Only charges with transactionType + * RESERVE_CAPTURE can be captured. Can also do partial captures + * (captures a smaller part of the payment). + * + * @param token - The authentication token. + * @param agreementId - The ID of the agreement. + * @param chargeId - The ID of the charge. + * @param body - The request body containing the charge modification details. + * @returns void or a `RecurringErrorResponse` object. + */ + capture: ( + token: string, + agreementId: string, + chargeId: string, + body: CaptureRequestV3, + ): RequestData => { + return { + url: + `/recurring/v3/agreements/${agreementId}/charges/${chargeId}/capture`, + method: "POST", + body, + token, + }; + }, + /** + * Refunds a charge, can also do a partial refund + * (refunding a smaller part of the payment). + * + * @param token - The authentication token. + * @param agreementId - The ID of the agreement. + * @param chargeId - The ID of the charge. + * @param body - The request body containing the charge modification details. + * @returns void or a `RecurringErrorResponse` object. + */ + refund: ( + token: string, + agreementId: string, + chargeId: string, + body: RefundRequest, + ): RequestData => { + return { + url: `/recurring/v3/agreements/${agreementId}/charges/${chargeId}/refund`, + method: "POST", + body, + token, + }; + }, +}; diff --git a/src/apis/util.ts b/src/apis/util.ts new file mode 100644 index 0000000..0ebb152 --- /dev/null +++ b/src/apis/util.ts @@ -0,0 +1,18 @@ +/** + * Generates URL path parameters from a variable number of arguments. + * + * @param {Record} params - An object containing key-value pairs to be converted into URL path parameters. + * @returns {string} The generated URL path parameters. + */ +type Params = Record; + +export const generatePathParams = (params: Params): string => { + const queryString = Object.entries(params) + .filter(([_, value]) => value !== undefined && value !== null) + .map(([key, value]) => + `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}` + ) + .join("&"); + + return queryString ? `?${queryString}` : ""; +}; diff --git a/src/generated_types/recurring/types.gen.ts b/src/generated_types/recurring/types.gen.ts new file mode 100644 index 0000000..e6472ff --- /dev/null +++ b/src/generated_types/recurring/types.gen.ts @@ -0,0 +1,3524 @@ +// This file is auto-generated by @hey-api/openapi-ts + +/** + * Status of the agreement. + */ +export type AgreementStatus = "PENDING" | "ACTIVE" | "STOPPED" | "EXPIRED"; + +export type ChargeStatus = + | "PENDING" + | "DUE" + | "RESERVED" + | "CHARGED" + | "PARTIALLY_CAPTURED" + | "FAILED" + | "CANCELLED" + | "PARTIALLY_REFUNDED" + | "REFUNDED" + | "PROCESSING"; + +/** + * A summary of the amounts captured, refunded and cancelled + */ +export type ChargeSummary = { + /** + * The total amount which has been captured/charged, in case of status charged/partial capture. + * Amounts are specified in minor units. + * NOK and DKK: 1 kr = 100 øre. EUR: 1 Euro = 100 cent. + */ + captured: number; + /** + * The total amount which has been refunded, in case of status refund/partial refund. + * Amounts are specified in minor units. + * NOK and DKK: 1 kr = 100 øre. EUR: 1 Euro = 100 cent. + */ + refunded: number; + /** + * The total amount which has been cancelled. + * + * Amounts are specified in minor units. + * NOK and DKK: 1 kr = 100 øre. EUR: 1 Euro = 100 cent. + */ + cancelled: number; +}; + +/** + * List of events related to the charge. + */ +export type ChargeHistory = Array; + +/** + * Describes the operation that was performed on the charge + */ +export type ChargeEvent = { + /** + * Date and time of the event, as timestamp on the format `yyyy-MM-dd'T'HH:mm:ss'Z'`, + * with or without milliseconds. + */ + occurred: string; + event: "CREATE" | "RESERVE" | "CAPTURE" | "REFUND" | "CANCEL" | "FAIL"; + /** + * The amount related to the operation. + * Amounts are specified in minor units. + * NOK and DKK: 1 kr = 100 øre. EUR: 1 Euro = 100 cent. + */ + amount: number; + /** + * The idempotency key of the event + */ + idempotencyKey: string; + /** + * True if the operation was successful, false otherwise + */ + success: boolean; +}; + +export type event = + | "CREATE" + | "RESERVE" + | "CAPTURE" + | "REFUND" + | "CANCEL" + | "FAIL"; + +/** + * ISO-4217: https://www.iso.org/iso-4217-currency-codes.html + */ +export type Currency = "NOK"; + +/** + * Available types of currency are NOK, EUR and DKK + */ +export type CurrencyV3 = "NOK" | "EUR" | "DKK"; + +/** + * Country code for the agreement according to ISO 3166-2 (two capital letters). + * Needs to be set based on the merchant's market/country. Cross border agreements are not supported, + * e.g., Norwegian merchants can only create agreements for Norwegian customers and countryCode should be NO. + */ +export type CountryCode = "NO" | "DK" | "FI"; + +/** + * Type of transaction, either direct capture or reserve capture + */ +export type transactionType = "DIRECT_CAPTURE" | "RESERVE_CAPTURE"; + +export type ChargeTypeV2 = "INITIAL" | "RECURRING"; + +export type ChargeTypeV3 = "INITIAL" | "RECURRING" | "UNSCHEDULED"; + +export type ChargeCreationTypeV3 = "RECURRING" | "UNSCHEDULED"; + +/** + * Interval for subscription + */ +export type Interval = "YEAR" | "MONTH" | "WEEK" | "DAY"; + +export type DraftAgreementV2 = { + variableAmount?: variableAmountV2; + campaign?: campaignV2; + currency: Currency; + /** + * Customers phone number (if available). Used to simplify the + * following Vipps MobilePay interaction. + * The format is MSISDN: Digits only: Country code and subscriber + * number, but no prefix. + * If the phone number is a Norwegian phone number `(+47) 91 23 45 67`, the MSISDN representation is `4712345678`. + * See: https://en.wikipedia.org/wiki/MSISDN + */ + customerPhoneNumber?: string; + initialCharge?: InitialChargeV2; + interval: Interval; + /** + * Number of intervals between charges. Example: interval=week, + * intervalCount=2 to be able to charge every two weeks. + * Charges should occur at least once a year. + */ + intervalCount: number; + /** + * This optional parameter indicates whether payment request is triggered from + * Mobile App or Web browser. Based on this value, response will be + * redirect URL for Vipps MobilePay landing page or deeplink URL to connect vipps + * App. When isApp is set to true, URLs passed to us will not be + * validated as regular URLs. + * See: https://developer.vippsmobilepay.com/docs/knowledge-base/user-flow + */ + isApp?: boolean; + /** + * URL where you can send the customer to view/manage their + * subscription. Typically a "My page" where the user can change, pause, cancel, etc. + * The page must offer management tools, not just information about how to + * contact customer service, etc. + * We recommend letting users + * [log in](/docs/APIs/login-api), + * not with username and password. + * We do not have any specific requirements for the security of the page other than requiring HTTPS. + * Only HTTP or HTTPS scheme is allowed. + */ + merchantAgreementUrl: string; + /** + * URL where customer should be redirected after the agreement has been + * approved/rejected in the Vipps or MobilePay app. + * HTTPS and deeplinks are allowed (example: myApp://home) + */ + merchantRedirectUrl: string; + /** + * The price of the agreement. + * + * Amounts are specified in minor units. + * NOK: 1 kr = 100 øre. + */ + price: number; + /** + * Product name (short) + */ + productName: string; + /** + * Product description (longer) + */ + productDescription?: string; + /** + * Space-separated list of the required user information (e.g., "name phoneNumber") + * for the agreement. See the + * [Userinfo user guide](/docs/APIs/userinfo-api/userinfo-api-guide#scope) + * for details. + * Possible values are: + * - name + * - address + * - email + * - phoneNumber + * - birthDate + * - nin + */ + scope?: string; + /** + * If the property is set to `true`, it will cause a push notification + * to be sent to the given phone number immediately, without loading + * the landing page. + * This feature has to be specially enabled for eligible sales + * units: The sales units must be whitelisted by Vipps MobilePay. If the sales unit is not whitelisted, + * the request will fail and an error message will be returned (statusCode=403). + * See: https://developer.vippsmobilepay.com/docs/knowledge-base/landing-page + */ + skipLandingPage?: boolean; +}; + +export type DraftAgreementV3 = { + campaign?: campaignV3; + pricing: pricingRequest; + /** + * Customers phone number (if available). Used to simplify the + * following interaction. MSISDN: https://en.wikipedia.org/wiki/MSISDN + */ + phoneNumber?: (string) | null; + initialCharge?: InitialChargeV3; + interval?: TimePeriod; + /** + * This optional parameter indicates whether payment request is triggered from + * Mobile App or Web browser. Based on this value, response will be + * redirect URL for Vipps MobilePay landing page or deeplink URL to connect vipps + * App. When isApp is set to true, URLs passed to us will not be + * validated as regular URLs. + * See: https://developer.vippsmobilepay.com/docs/knowledge-base/user-flow + */ + isApp?: boolean; + /** + * URL where we can send the customer to view/manage their + * subscription. Typically a "My page" where the user can change, pause, cancel, etc. + * The page must offer actual management, not just information about how to + * contact customer service, etc. + * We recommend letting users + * [log in](/docs/APIs/login-api), + * not with username and password. + * We do not have any specific requirements for the security of the page other than requiring HTTPS. + * Only HTTPS scheme is allowed. + * This URL is required for Norwegian Merchants. + */ + merchantAgreementUrl?: string; + /** + * URL where customer should be redirected after the agreement has been + * approved/rejected in the Vipps mobile application. + * HTTPS and deeplinks are allowed (example: myApp://home) + */ + merchantRedirectUrl: string; + /** + * Product name (short) + */ + productName: string; + /** + * Product description (longer) + */ + productDescription?: string; + /** + * Space-separated list of the required user information (e.g., "name phoneNumber") + * for the agreement. See the + * [Userinfo user guide](/docs/APIs/userinfo-api/userinfo-api-guide#scope) + * for details. + * Possible values are: + * - name + * - address + * - email + * - phoneNumber + * - birthDate + * - nin + */ + scope?: string; + /** + * If the property is set to `true`, it will cause a push notification + * to be sent to the given phone number immediately, without loading + * the landing page. + * This feature has to be specially enabled for eligible sales + * units: The sales units must be whitelisted by Vipps MobilePay. If the sales unit is not whitelisted, + * the request will fail and an error message will be returned (statusCode=403). + * See: https://developer.vippsmobilepay.com/docs/knowledge-base/landing-page + */ + skipLandingPage?: boolean; + /** + * An optional external ID for the agreement. + * The `externalId` can be used by the merchant to map the `agreementId` + * to an ID in a subscription system or similar. + */ + externalId?: (string) | null; + countryCode?: CountryCode; +}; + +export type DraftAgreementResponseV2 = { + /** + * Reference of a an agreement which user may agree to. + * Initially the agreement is in a pending state waiting for user approval. + * It enters active state once the user has approved it in the Vipps or MobilePay app. + */ + agreementResource: string; + /** + * Id of a an agreement which user may agree to. + * Initially the agreement is in a pending state waiting for user approval. + * It enters active state once the user has approved it in the Vipps or MobilePay app. + */ + agreementId: string; + /** + * The `vippsConfirmationUrl` should be used to redirect the + * user to the Vipps MobilePay landing page in a desktop flow (with `https://`), + * or to the Vipps or MobilePay app in a mobile flow (with `vipps://`), where the + * user can then approve the agreement. + */ + vippsConfirmationUrl: string; + /** + * The Id of the initialCharge if given, otherwise `null`. + * If an `orderId` is specified this is used as the `chargeId` otherwise it is auto generated. + */ + chargeId: string; +}; + +export type DraftAgreementResponseV3 = { + /** + * Id of a an agreement which user may agree to. + * Initially the agreement is in a pending state waiting for user approval. + * It enters active state once the user has approved it in the Vipps or MobilePay app. + */ + agreementId: string; + /** + * UUID (RFC 4122) representation of agreementId + */ + uuid: string; + /** + * The `vippsConfirmationUrl` should be used to redirect the + * user to the Vipps MobilePay landing page in a desktop flow (with `https://`), + * or to the Vipps or MobilePay app in a mobile flow (with `vipps://`), where the + * user can then approve the agreement. + */ + vippsConfirmationUrl?: string; + /** + * The Id of the initialCharge if given, otherwise `null`. + * If an `orderId` is specified this is used as the `chargeId` otherwise it is auto generated. + */ + chargeId?: (string) | null; +}; + +export type AgreementResponseV2 = { + campaign?: campaignV2; + currency?: Currency; + /** + * Uniquely identifies this agreement + */ + id: string; + interval: Interval; + /** + * Number of intervals between charges. Example: interval=WEEK, intervalCount=2 to be able to charge every two weeks. Charges should occur at least once a year. + */ + intervalCount: number; + /** + * The price of the agreement. + * + * Amounts are specified in minor units. + * NOK: 1 kr = 100 øre. + */ + price: number; + /** + * Product name (short) + */ + productName: string; + /** + * Product description (longer) + */ + productDescription: string; + /** + * Date and time when agreement was started, in ISO 8601 format. + * This is when the agreement was activated. + */ + start?: (string) | null; + /** + * Date and time when agreement was stopped, in ISO 8601 format. + */ + stop?: (string) | null; + status?: AgreementStatus; + /** + * URL where we can send the customer to view/manage their + * subscription. Typically a "My page" where the user can change, pause, cancel, etc. + * The page must offer actual management, not just information about how to + * contact customer service, etc. + * We recommend letting users log in with Vipps MobilePay, not with username and password: + * https://developer.vippsmobilepay.com/docs/APIs/login-api + * We do not have any specific requirements for the security of the + * page other than requiring HTTPS. + */ + merchantAgreementUrl?: string; + /** + * User identifier (subject). Will be null if profile data was not requested. + */ + sub?: (string) | null; + /** + * The full path of the URL for the userinfo endpoint where the user data can be retrieved: + * [`GET:/vipps-userinfo-api/userinfo/{sub}`](/api/userinfo#operation/getUserinfo). + * This will be null if profile data was not requested. + */ + userinfoUrl?: (string) | null; + variableAmount?: variableAmountResponseV2; +}; + +export type AgreementResponseV3 = { + campaign?: (campaignResponseV3) | null; + pricing: pricingResponse; + /** + * Uniquely identifies this agreement + */ + id: string; + interval: TimePeriodResponse; + /** + * Product name (short) + */ + productName: string; + /** + * Product description (longer) + */ + productDescription?: string; + /** + * Date when agreement was created, in ISO 8601 format. + * This is when the agreement was initiated with the API. + */ + created: string; + /** + * Date and time when agreement was started, in ISO 8601 format. + * This is when the agreement was activated. + */ + start?: (string) | null; + /** + * Date and time when agreement was stopped, in ISO 8601 format. + */ + stop?: (string) | null; + status?: AgreementStatus; + /** + * URL where we can send the customer to view/manage their + * subscription. Typically a "My page" where the user can change, pause, cancel, etc. + * The page must offer actual management, not just information about how to + * contact customer service, etc. + * We recommend letting users log in with Vipps MobilePay, not with username and password: + * https://developer.vippsmobilepay.com/docs/APIs/login-api + * We do not have any specific requirements for the security of the + * page other than requiring HTTPS. + */ + merchantAgreementUrl: string; + /** + * URL where customer should be redirected after the agreement has been + * approved/rejected in the Vipps or MobilePay app. + * HTTPS and deeplinks are allowed (example: myApp://home) + */ + merchantRedirectUrl: string; + /** + * User identifier (subject). Will be null if profile data was not requested. + */ + sub?: (string) | null; + /** + * The full path of the URL for the userinfo endpoint where the user data can be retrieved.: + * [`GET:/vipps-userinfo-api/userinfo/{sub}`](/api/userinfo#operation/getUserinfo). + * This will be null if profile data was not requested. + */ + userinfoUrl?: (string) | null; + /** + * An optional external ID for the agreement. + * The `externalId` can be used by the merchant to map the `agreementId` + * to an ID in a subscription system or similar. + */ + externalId?: string; + countryCode: CountryCode; + /** + * UUID (RFC 4122) representation of ID + */ + uuid: string; + /** + * The `vippsConfirmationUrl` should be used to redirect the + * user to the Vipps MobilePay landing page in a desktop flow (with `https://`), + * or to the Vipps or MobilePay app in a mobile flow (with `vipps://`), where the + * user can then approve the agreement. + */ + vippsConfirmationUrl?: string; +}; + +export type PatchAgreementV2 = { + /** + * The suggested max amount that the customer should choose. + * + * Amounts are specified in minor units. + * NOK: 1 kr = 100 øre. + */ + suggestedMaxAmount?: number; + campaign?: campaignV2; + /** + * The price of the agreement. + * + * Price is specified in minor units. + * NOK: 1 kr = 100 øre. + */ + price?: number; + /** + * Product name (short) + */ + productName?: string; + /** + * Product description (longer) + */ + productDescription?: string; + /** + * URL where we can send the customer to view/manage their + * subscription. Typically a "My page" where the user can change, pause, cancel, etc. + * The page must offer actual management, not just information about how to + * contact customer service, etc. + * We recommend letting users log in with Vipps MobilePay, not with username and password: + * https://developer.vippsmobilepay.com/docs/APIs/login-api + * We do not have any specific requirements for the security of the + * page other than requiring HTTPS. + */ + merchantAgreementUrl?: string; + /** + * Status of the agreement. + */ + status?: "STOPPED"; +}; + +/** + * Status of the agreement. + */ +export type status = "STOPPED"; + +export type PatchAgreementV3 = { + /** + * Name of the product being subscribed to. + */ + productName?: string; + /** + * Product description (longer) + */ + productDescription?: string; + /** + * URL where we can send the customer to view/manage their + * subscription. Typically a "My page" where the user can change, pause, cancel, etc. + * The page must offer actual management, not just information about how to + * contact customer service, etc. + * We recommend letting users log in with Vipps MobilePay, not with username and password: + * https://developer.vippsmobilepay.com/docs/APIs/login-api + * We do not have any specific requirements for the security of the + * page other than requiring HTTPS. + */ + merchantAgreementUrl?: string; + /** + * An optional external ID for the agreement. + * The `externalId` can be used by the merchant to map the `agreementId` + * to an ID in a subscription system or similar. + */ + externalId?: string; + /** + * Status of the agreement. + */ + status?: "STOPPED"; + pricing?: PricingUpdateRequest; + /** + * The interval of the agreement. + * + * The interval is specified by the `type` and `period` properties. + * When the type is `RECURRING`, then the property `period` is required. + * When the type is `FLEXIBLE`, then the property `period` is not allowed. + */ + interval?: { + type?: "RECURRING" | "FLEXIBLE"; + period?: TimePeriod; + }; +}; + +export type type = "RECURRING" | "FLEXIBLE"; + +export type AgreementReference = { + /** + * Id of a an agreement which user may agree to. + * Initially the agreement is in a pending state waiting for user approval. + * It enters active state once the user has approved it in the Vipps or MobilePay app. + */ + agreementId: string; +}; + +export type variableAmountV2 = { + /** + * The suggested max amount that the customer should choose. + * + * Amounts are specified in minor units. + * NOK and DKK: 1 kr = 100 øre. EUR: 1 Euro = 100 cent. + */ + suggestedMaxAmount: number; +}; + +export type variableAmountResponseV2 = { + /** + * The suggested max amount that the customer should choose. + * + * Amounts are specified in minor units. + * NOK and DKK: 1 kr = 100 øre. EUR: 1 Euro = 100 cent. + */ + suggestedMaxAmount?: number; + /** + * The max amount chosen by the customer. + * + * Amounts are specified in minor units. + * NOK and DKK: 1 kr = 100 øre. EUR: 1 Euro = 100 cent. + */ + maxAmount?: number; +}; + +export type campaignV2 = { + /** + * The price of the agreement in the discount period. + * The lowering of the price will be displayed in-app. + * Price is specified in minor units. + * NOK and DKK: 1 kr = 100 øre. EUR: 1 Euro = 100 cent. + */ + campaignPrice: number; + /** + * The date and time the campaign ends. + */ + end: string; +} | null; + +export type campaignResponseV2 = { + /** + * The price of the agreement in the discount period. The lowering of the price will be displayed in-app. + * Price is specified in minor units. + * NOK: 1 kr = 100 øre. + */ + campaignPrice?: number; + /** + * The date and time the campaign starts. Must be UTC. + */ + start?: string; + /** + * The date and time the campaign ends. + * This is a required field when using `EVENT_CAMPAIGN`. + * Must be UTC. + */ + end?: string; +}; + +export type campaignV3 = priceCampaignV3 | periodCampaignV3 | eventCampaignV3; + +export type priceCampaignV3 = { + /** + * The type of campaign. This decides which properties are required + */ + type: "PRICE_CAMPAIGN"; + /** + * The price of the agreement in the discount period. The lowering of the price will be displayed in-app. + * + * Price is specified in minor units. + * NOK and DKK: 1 kr = 100 øre. EUR: 1 Euro = 100 cent. + */ + price: number; + /** + * The date and time the campaign ends. + * Needs to be UTC. + */ + end: string; +} | null; + +/** + * The type of campaign. This decides which properties are required + */ +export type type2 = "PRICE_CAMPAIGN"; + +export type periodCampaignV3 = { + /** + * The type of campaign. This decides which properties are required + */ + type: "PERIOD_CAMPAIGN"; + /** + * The price of the agreement in the discount period. The lowering of the price will be displayed in-app. + * + * Price is specified in minor units. + * NOK and DKK: 1 kr = 100 øre. EUR: 1 Euro = 100 cent. + */ + price: number; + period: TimePeriod; +} | null; + +/** + * The type of campaign. This decides which properties are required + */ +export type type3 = "PERIOD_CAMPAIGN"; + +export type eventCampaignV3 = { + /** + * The type of campaign. This decides which properties are required + */ + type: "EVENT_CAMPAIGN"; + /** + * The price of the agreement in the discount period. The lowering of the price will be displayed in-app. + * + * Price is specified in minor units. + * NOK and DKK: 1 kr = 100 øre. EUR: 1 Euro = 100 cent. + */ + price: number; + /** + * The date and time the campaign ends. Must be UTC. + */ + eventDate: string; + /** + * A short text that describes the event + */ + eventText: string; +} | null; + +/** + * The type of campaign. This decides which properties are required + */ +export type type4 = "EVENT_CAMPAIGN"; + +export type campaignResponseV3 = + | priceCampaignResponseV3 + | periodCampaignResponseV3 + | eventCampaignResponseV3 + | legacyCampaignResponseV3; + +export type priceCampaignResponseV3 = { + /** + * The type of campaign. This decides which properties are required + */ + type: "PRICE_CAMPAIGN" | "PERIOD_CAMPAIGN" | "EVENT_CAMPAIGN"; + /** + * The price of the agreement in the discount period. The lowering of the price will be displayed in-app. + * + * Price is specified in minor units. + * NOK and DKK: 1 kr = 100 øre. EUR: 1 Euro = 100 cent. + */ + price: number; + /** + * The date and time the campaign ends. Must be UTC. + */ + end: string; + /** + * The text displayed in the Vipps or MobilePay app to explain the campaign to the user + */ + explanation?: string; +}; + +/** + * The type of campaign. This decides which properties are required + */ +export type type5 = "PRICE_CAMPAIGN" | "PERIOD_CAMPAIGN" | "EVENT_CAMPAIGN"; + +export type periodCampaignResponseV3 = { + /** + * The type of campaign. This decides which properties are required + */ + type: "PRICE_CAMPAIGN" | "PERIOD_CAMPAIGN" | "EVENT_CAMPAIGN"; + /** + * The price of the agreement in the discount period. The lowering of the price will be displayed in-app. + * + * Price is specified in minor units. + * NOK and DKK: 1 kr = 100 øre. EUR: 1 Euro = 100 cent. + */ + price: number; + /** + * The date and time the campaign ends. + * Needs to be UTC. + */ + end: string; + period: TimePeriod; + /** + * The text displayed in the Vipps or MobilePay app to explain the campaign to the user + */ + explanation?: string; +}; + +export type eventCampaignResponseV3 = { + /** + * The type of campaign. This decides which properties are required + */ + type: "PRICE_CAMPAIGN" | "PERIOD_CAMPAIGN" | "EVENT_CAMPAIGN"; + /** + * The price of the agreement in the discount period. The lowering of the price will be displayed in-app. + * + * Price is specified in minor units. + * NOK and DKK: 1 kr = 100 øre. EUR: 1 Euro = 100 cent. + */ + price: number; + /** + * The date and time the campaign ends. Must be UTC. + */ + eventDate: string; + /** + * A short text that describes the event + */ + eventText: string; + /** + * The text displayed in the Vipps or MobilePay app to explain the campaign to the user + */ + explanation?: string; +}; + +export type legacyCampaignResponseV3 = { + /** + * The type of campaign. This decides which properties are required + */ + type: + | "PRICE_CAMPAIGN" + | "PERIOD_CAMPAIGN" + | "EVENT_CAMPAIGN" + | "LEGACY_CAMPAIGN"; + /** + * The price of the agreement in the discount period. The lowering of the price will be displayed in-app. + * + * Price is specified in minor units. + * NOK and DKK: 1 kr = 100 øre. EUR: 1 Euro = 100 cent. + */ + price: number; + /** + * The date and time the campaign ends. + * Needs to be UTC. + */ + end: string; + /** + * The text displayed in the Vipps or MobilePay app to explain the campaign to the user + */ + explanation?: string; +}; + +/** + * The type of campaign. This decides which properties are required + */ +export type type6 = + | "PRICE_CAMPAIGN" + | "PERIOD_CAMPAIGN" + | "EVENT_CAMPAIGN" + | "LEGACY_CAMPAIGN"; + +export type pricingRequest = { + /** + * The type of pricing. This decides which properties are required. + */ + type?: "LEGACY" | "VARIABLE" | "FLEXIBLE"; + currency: CurrencyV3; + /** + * The price of the agreement, required if type is LEGACY or not present. + * + * Amounts are specified in minor units. + * NOK and DKK: 1 kr = 100 øre. EUR: 1 Euro = 100 cent. + */ + amount?: number; + /** + * The suggested max amount that the customer should choose, required if type is VARIABLE. + * There are limits for each currency: + * - NOK: 20 000 kr (2000000 øre) + * - DKK: 300 000 kr (30000000 øre) + * - EUR: 2 000 Euro (200000 cent) + * + * Amounts are specified in minor units. + * NOK and DKK: 1 kr = 100 øre. EUR: 1 Euro = 100 cent. + */ + suggestedMaxAmount?: number; +}; + +/** + * The type of pricing. This decides which properties are required. + */ +export type type7 = "LEGACY" | "VARIABLE" | "FLEXIBLE"; + +export type pricingResponse = + | LegacyPricingResponse + | VariableAmountPricingResponse; + +export type LegacyPricingResponse = { + /** + * The type of pricing. This decides which properties are present. + */ + type: "LegacyPricingResponse"; + currency: CurrencyV3; + /** + * The price of the agreement, present if type is LEGACY. + * + * Amounts are specified in minor units. + * NOK and DKK: 1 kr = 100 øre. EUR: 1 Euro = 100 cent. + */ + amount: number; +}; + +export type VariableAmountPricingResponse = { + /** + * The type of pricing. This decides which properties are present. + */ + type: "VariableAmountPricingResponse"; + currency: CurrencyV3; + /** + * The suggested max amount that the customer should choose, present if type is VARIABLE. + * + * Amounts are specified in minor units. + * NOK and DKK: 1 kr = 100 øre. EUR: 1 Euro = 100 cent. + */ + suggestedMaxAmount: number; + /** + * The max amount chosen by the customer. + * + * Amounts are specified in minor units. + * NOK and DKK: 1 kr = 100 øre. EUR: 1 Euro = 100 cent. + */ + maxAmount?: number; +}; + +export type PricingUpdateRequest = { + /** + * The price of the agreement, can only be updated if agreement type is LEGACY + * + * Amounts are specified in minor units. + * NOK and DKK: 1 kr = 100 øre. EUR: 1 Euro = 100 cent. + */ + amount?: number; + /** + * The suggested max amount that the customer should choose, required if type is VARIABLE. + * There are limits for each currency: + * - NOK: 20 000 kr (2000000 øre) + * - DKK: 300 000 kr (30000000 øre) + * - EUR: 2 000 Euro (200000 cent) + * + * Amounts are specified in minor units. + * NOK and DKK: 1 kr = 100 øre. EUR: 1 Euro = 100 cent. + */ + suggestedMaxAmount?: number; +}; + +/** + * An initial charge for a new agreement. + * The charge will be processed immediately when the user approves the agreement. + */ +export type InitialChargeV2 = { + /** + * The amount that must be paid or approved before starting the agreement. + * + * Amounts are specified in minor units. + * NOK: 1 kr = 100 øre. + */ + amount: number; + currency: Currency; + /** + * This field is visible to the end user in-app + */ + description: string; + /** + * The type of payment to be made. + */ + transactionType: "RESERVE_CAPTURE" | "DIRECT_CAPTURE"; + /** + * An optional, but recommended `orderId` for the charge. + * If provided, this will be the `chargeId` for this charge. + * See: https://developer.vippsmobilepay.com/docs/knowledge-base/orderid/ + * If no `orderId` is specified, the `chargeId` will be automatically generated. + */ + orderId?: string; +}; + +/** + * The type of payment to be made. + */ +export type transactionType2 = "RESERVE_CAPTURE" | "DIRECT_CAPTURE"; + +/** + * An initial charge for a new agreement. + * The charge will be processed immediately when the user approves the agreement. + */ +export type InitialChargeV3 = { + /** + * The amount that must be paid or approved before starting the agreement. + * + * Amounts are specified in minor units. + * NOK and DKK: 1 kr = 100 øre. EUR: 1 Euro = 100 cent. + */ + amount: number; + /** + * This field is visible to the end user in-app + */ + description: string; + /** + * The type of payment to be made. + */ + transactionType: "RESERVE_CAPTURE" | "DIRECT_CAPTURE"; + /** + * An optional, but recommended `orderId` for the charge. + * If provided, this will be the `chargeId` for this charge. + * See: https://developer.vippsmobilepay.com/docs/knowledge-base/orderid/ + * If no `orderId` is specified, the `chargeId` will be automatically generated. + */ + orderId?: string; + /** + * An optional external ID for the charge + * The `externalId` can be used by the merchant to map the `chargeId` + * to an ID in a subscription system or similar. + */ + externalId?: string; +}; + +export type CreateChargeV2 = { + /** + * Amount to be paid by the customer. + * + * Amounts are specified in minor units. + * NOK: 1 kr = 100 øre. + */ + amount: number; + currency: Currency; + /** + * This field is visible to the end user in-app + */ + description: string; + /** + * The date when the charge is due to be processed. + * Must be in the format `YYYY-MM-DD` and ISO 8601. + */ + due: string; + /** + * The service will attempt to charge the customer for the number of days + * specified in `retryDays` after the `due` date. + * We recommend at least two days retry. + */ + retryDays: number; + /** + * An optional, but recommended `orderId` for the charge. + * If provided, this will be the `chargeId` for this charge. + * See: https://developer.vippsmobilepay.com/docs/knowledge-base/orderid/ + * If no `orderId` is specified, the `chargeId` will be automatically generated. + */ + orderId?: string; +}; + +export type CreateChargeV3 = { + /** + * Amount to be paid by the customer. + * + * Amounts are specified in minor units. + * NOK and DKK: 1 kr = 100 øre. EUR: 1 Euro = 100 cent. + */ + amount: number; + transactionType: transactionType; + type?: ChargeCreationTypeV3; + /** + * This field is visible to the end user in-app + */ + description: string; + /** + * The date when the charge is due to be processed. + * + * Must be at least two days in advance in the production environment, + * and at least one day in the test environment. + * + * If the charge is `DIRECT_CAPTURE`, the charge is processed and charged on the `due` date. + * If the charge is `RESERVE_CAPTURE`, the charge is `RESERVED` on `due` date. + * + * Must be in the format `YYYY-MM-DD` and ISO 8601. + * + * Required only for `RECURRING` charges + */ + due?: string; + /** + * The service will attempt to charge the customer for the number of days + * specified in `retryDays` after the `due` date. + * We recommend at least two days retry. + * + * Required only for `RECURRING` charges + */ + retryDays?: number; + /** + * An optional, but recommended `orderId` for the charge. + * If provided, this will be the `chargeId` for this charge. + * This is the unique identifier of the payment, from the payment is initiated and all the way to the settlement data. + * See: https://developer.vippsmobilepay.com/docs/knowledge-base/orderid/ + * If no `orderId` is specified, the `chargeId` will be automatically generated. + */ + orderId?: string; + /** + * An optional external ID for the charge, that takes the place of the `orderId` in settlement reports without overriding the default `chargeId` + * The `externalId` can be used by the merchant to map the `chargeId` to an ID in a subscription system or similar. + * Note that while `orderId` must be unique per merchant, `externalId` does not have this limitation, + * so you need to avoid assigning the same `externalId` to multiple charges if you want to keep them separate in settlement reports. + */ + externalId?: string; +}; + +export type CreateChargeAsyncV3 = { + /** + * Id of a an agreement which user may agree to. + * Initially the agreement is in a pending state waiting for user approval. + * It enters active state once the user has approved it in the Vipps or MobilePay app + */ + agreementId: string; + /** + * Amount to be paid by the customer. + * + * Amounts are specified in minor units. + * NOK and DKK: 1 kr = 100 øre. EUR: 1 Euro = 100 cent. + */ + amount: number; + transactionType: transactionType; + /** + * This field is visible to the end user in-app + */ + description: string; + /** + * The date when the charge is due to be processed. + * + * Must be at least two days in advance in the production environment, + * and at least one day in the test environment. + * + * If the charge is `DIRECT_CAPTURE`, the charge is processed and charged on the `due` date. + * If the charge is `RESERVE_CAPTURE`, the charge is `RESERVED` on `due` date. + * + * Must be in the format `YYYY-MM-DD` and ISO 8601. + */ + due: string; + /** + * The service will attempt to charge the customer for the number of days + * specified in `retryDays` after the `due` date. + * We recommend at least two days retry. + */ + retryDays: number; + /** + * This will be the `chargeId` for this charge. + * This is the unique identifier of the payment, from the payment is initiated and all the way to the settlement data. + * See: https://developer.vippsmobilepay.com/docs/knowledge-base/orderid/ + */ + orderId: string; + /** + * An optional external ID for the charge, that takes the place of the `orderId` in settlement reports without overriding the default `chargeId` + * The `externalId` can be used by the merchant to map the `chargeId` to an ID in a subscription system or similar. + * Note that while `orderId` must be unique per merchant, `externalId` does not have this limitation, + * so you need to avoid assigning the same `externalId` to multiple charges if you want to keep them separate in settlement reports. + */ + externalId?: string; +}; + +export type AsyncChargeResponse = { + invalidCharges: Array; + validCharges: Array<(string)>; +}; + +export type InvalidChargeResponse = { + chargeBatchItemDto: ChargeBatchItemDto; + errors: Array<(string)>; +}; + +export type ChargeBatchItemDto = { + due: string; + retryDays: number; + amount: number; + description: string; + transactionType: "DIRECT_CAPTURE" | "RESERVE_CAPTURE"; + orderId: string; + agreementId?: string; + externalId?: string; +}; + +export type ChargeReference = { + /** + * Unique identifier for this charge, up to 15 characters. + */ + chargeId?: string; +}; + +export type ChargeResponseV2 = { + /** + * Amount to be paid by the customer. + * + * Amounts are specified in minor units. + * NOK: 1 kr = 100 øre. + */ + amount: number; + /** + * The total amount which has been refunded, in case of status refund/partial refund. + * + * Amounts are specified in minor units. + * NOK: 1 kr = 100 øre. + */ + amountRefunded: number; + /** + * Description of the charge. + */ + description: string; + /** + * The due date for this charge. + */ + due: string; + /** + * Identifier for this charge (for this customer's subscription). + */ + id: string; + status: ChargeStatus; + /** + * Contains null until the status has reached CHARGED. + */ + transactionId: string; + type: ChargeTypeV2; + /** + * Identifies the reason why the charged has been marked as `FAILED`: + * * `user_action_required` - The user's card can not fulfil the payment. The user needs to take action in the app. + * Examples: Card is blocked for ecommerce, insufficient funds, expired card. + * + * * `charge_amount_too_high` - The user's max amount is too low. The user needs to update their max amount in the Vipps or MobilePay app. + * + * * `non_technical_error` - Something went wrong with charging the user. + * Examples: User has deleted their Vipps MobilePay Profile. + * + * * `technical_error` - Something went wrong in Recurring while performing the payment. + * Examples: Failure in Recurring, failure in downstream services. + */ + failureReason?: + | "user_action_required" + | "charge_amount_too_high" + | "non_technical_error" + | "technical_error"; + /** + * Description for the failure reason. + */ + failureDescription?: string; +}; + +/** + * Identifies the reason why the charged has been marked as `FAILED`: + * * `user_action_required` - The user's card can not fulfil the payment. The user needs to take action in the app. + * Examples: Card is blocked for ecommerce, insufficient funds, expired card. + * + * * `charge_amount_too_high` - The user's max amount is too low. The user needs to update their max amount in the Vipps or MobilePay app. + * + * * `non_technical_error` - Something went wrong with charging the user. + * Examples: User has deleted their Vipps MobilePay Profile. + * + * * `technical_error` - Something went wrong in Recurring while performing the payment. + * Examples: Failure in Recurring, failure in downstream services. + */ +export type failureReason = + | "user_action_required" + | "charge_amount_too_high" + | "non_technical_error" + | "technical_error"; + +export type ChargeResponseV3 = { + /** + * Amount to be paid by the customer. + * + * Amounts are specified in minor units. + * NOK and DKK: 1 kr = 100 øre. EUR: 1 Euro = 100 cent. + */ + amount: number; + currency: CurrencyV3; + /** + * Description of the charge + */ + description: string; + /** + * The due date for this charge + */ + due: string; + /** + * Identifier for this charge (for this customer's subscription). + */ + id: string; + /** + * Id of the agreement the charge belongs to + */ + agreementId: string; + /** + * An optional external ID for the charge + * The `externalId` can be used by the merchant to map the `chargeId` + * to an ID in a subscription system or similar. + */ + externalId: string; + /** + * An optional external ID for the agreement + * The `externalId` can be used by the merchant to map the `agreementId` + * to an ID in a subscription system or similar. + */ + externalAgreementId?: string; + /** + * The service will attempt to charge the customer for the number of days + * specified in `retryDays` after the `due` date. + * We recommend at least two days retry. + */ + retryDays: number; + status: ChargeStatus; + /** + * Contains null until the status has reached CHARGED + */ + transactionId: string; + type: ChargeTypeV3; + transactionType: transactionType; + /** + * Identifies the reason why the charged has been marked as `FAILED`: + * * `user_action_required` - The user's card can not fulfil the payment, user needs to take action in the Vipps or MobilePay app. + * Examples: Card is blocked for ecommerce, insufficient funds, expired card. + * + * * `charge_amount_too_high` - The user's max amount is too low, user needs to update their max amount in the Vipps or MobilePay app. + * + * * `non_technical_error` - Something went wrong with charging the user. + * Examples: User has deleted their Vipps MobilePay Profile. + * + * * `technical_error` - Something went wrong in Recurring while performing the payment. + * Examples: Failure in Recurring, failure in downstream services. + */ + failureReason?: + | ( + | "user_action_required" + | "charge_amount_too_high" + | "non_technical_error" + | "technical_error" + ) + | null; + /** + * Description for the failure reason + */ + failureDescription?: string; + summary: ChargeSummary; + history: ChargeHistory; +}; + +export type RefundRequest = { + /** + * The amount to refund on a captured/charged charge. + * + * Amounts are specified in minor units. + * NOK and DKK: 1 kr = 100 øre. EUR: 1 Euro = 100 cent. + */ + amount: number; + /** + * A textual description of the operation, which will be displayed in the user's app. + */ + description: string; +}; + +export type CaptureRequestV3 = { + /** + * The amount to capture on a reserved charge. + * Amounts are specified in minor units. + * NOK and DKK: 1 kr = 100 øre. EUR: 1 Euro = 100 cent. + */ + amount: number; + /** + * Deprecated. Description in CreateChargeV3 is used instead. + * @deprecated + */ + description?: string; +}; + +/** + * A period of time, defined by a unit (DAY, WEEK, ...) and a count (number of said units) + */ +export type TimePeriod = { + /** + * Unit of time + */ + unit: "YEAR" | "MONTH" | "WEEK" | "DAY"; + /** + * Number of units in the time period. Example: unit=week, count=2 to define two weeks + */ + count: number; +}; + +/** + * Unit of time + */ +export type unit = "YEAR" | "MONTH" | "WEEK" | "DAY"; + +/** + * A period of time, defined by a unit (DAY, WEEK, ...) and a count (number of said units) + */ +export type TimePeriodResponse = { + /** + * Unit of time + */ + unit?: "YEAR" | "MONTH" | "WEEK" | "DAY"; + /** + * Number of units in the time period. Example: unit=week, count=2 to define two weeks + */ + count?: number; + /** + * Textual representation used in Vipps MobilePay to describe the time period + */ + text?: string; +}; + +export type ForceAcceptAgreement = { + customerPhoneNumber: string; +}; + +export type ForceAcceptAgreementV3 = { + phoneNumber: string; +}; + +/** + * An error from Microsoft Azure. We have limited control of these errors, + * and can not give as detailed information as with the errors from our own code. + * The most important property is the HTTP status code. + */ +export type ErrorFromAzure = { + responseInfo: { + responseCode: number; + responseMessage: string; + }; + result: { + /** + * When possible: A description of what went wrong. + */ + message: string; + }; +}; + +/** + * An error from Vipps MobilePay. + * The most important property is the HTTP status code. + * The response body contains more details of the error. + */ +export type ErrorV2 = { + /** + * Field that caused the error + */ + field?: string; + /** + * The error message + */ + message?: string; + /** + * The code for the specific error + */ + code?: string; + /** + * A unique ID for this error, useful for searching in logs + */ + contextId?: string; +}; + +export type ErrorArray = Array; + +/** + * The standard error object, based on RFC 7807. See https://developer.vippsmobilepay.com/docs/APIs/recurring-api/recurring-api-problems/ + */ +export type ErrorV3 = { + /** + * Path to type of error + */ + type?: string; + /** + * Short description of the error + */ + title?: string; + /** + * HTTP status returned with the problem + */ + status?: number; + /** + * Details about the error + */ + detail?: string; + /** + * The path of the request + */ + instance?: string; + /** + * An unique ID for the request + */ + contextId?: string; + extraDetails?: Array; +}; + +/** + * extra details about the error + */ +export type ExtraDetails = { + /** + * Name of the field related to the error + */ + name?: string; + /** + * Details about the error + */ + reason?: string; +}; + +/** + * The agreement identifier (ID) + */ +export type ParameterAgreementId = string; + +/** + * The charge identifier (ID) + */ +export type ParameterChargeId = string; + +/** + * The subscription key for your sales unit. See [API keys](/docs/knowledge-base/api-keys/). Keep it secret. + */ +export type ParameterOcp_Apim_Subscription_Key = string; + +/** + * The access token is a base64-encoded string that is required for all API requests. It is a JWT (JSON Web Token). The access token is fetched from the + * [`POST:/accesstoken/get`](/api/access-token#tag/Authorization-Service/operation/fetchAuthorizationTokenUsingPost) + * endpoint. + * It is valid for 1 hour in the test environment and 24 hours in the production environment. + */ +export type ParameterAuthorization = string; + +/** + * An Idempotency key must be provided to ensure idempotent requests. + * Key size can be between 1 to 40 characters. + * Key must not contain '#', '?', '/' or '\\' + */ +export type ParameterIdempotency_Key = string; + +/** + * When returned from an endpoint, this indicates that there is more data than can be returned in one response. + * Repeating the request with the received token in the Continuation-Token header will return the next page of data. + * When not returned, the end of the data has been reached. + * + * Continuation-Tokens are short-lived, so they cannot be used several minutes/hours after received. + */ +export type ParameterContinuation_Token = string; + +/** + * The Merchant Serial Number (MSN) is a unique ID for the sales unit + * for which this payment is made. + * This is a required parameter if you are a Recurring partner + * making payments on behalf of a merchant. + * The partner must use the merchant's MSN (not the partner's MSN). + * This parameter is optional, and recommended, for regular Vipps MobilePay + * merchants making payments for themselves. + */ +export type ParameterMerchant_Serial_Number = string; + +/** + * Filter by the `status` of the agreement. + */ +export type ParameterAgreementStatusQuery = AgreementStatus; + +/** + * Filter by createdAfter timestamp (in milliseconds) for paginating. + */ +export type ParameterCreatedAfterQuery = number; + +/** + * Filter by status of the charge. + */ +export type ParameterChargeStatusQuery = ChargeStatus; + +/** + * Filter by status of the charge. + */ +export type ParameterChargeStatusQueryV3 = ChargeStatus; + +/** + * Page number for paginating. + */ +export type ParameterPageNumberQuery = number; + +/** + * Page size for paginating (must be used in combination with pageNumber). + */ +export type ParameterPageSizeQuery = number; + +/** + * The name of the ecommerce solution. One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ +export type ParameterVipps_System_Name = string; + +/** + * The version number of the ecommerce solution. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ +export type ParameterVipps_System_Version = string; + +/** + * The name of the ecommerce plugin (if applicable). One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ +export type ParameterVipps_System_Plugin_Name = string; + +/** + * The version number of the ecommerce plugin (if applicable). + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ +export type ParameterVipps_System_Plugin_Version = string; + +/** + * The content type must be `application/json` + */ +export type ParameterContent_Type = string; + +export type ListAgreementsData = { + /** + * The access token is a base64-encoded string that is required for all API requests. It is a JWT (JSON Web Token). The access token is fetched from the + * [`POST:/accesstoken/get`](/api/access-token#tag/Authorization-Service/operation/fetchAuthorizationTokenUsingPost) + * endpoint. + * It is valid for 1 hour in the test environment and 24 hours in the production environment. + */ + authorization: string; + /** + * The content type must be `application/json` + */ + contentType?: string; + /** + * Filter by createdAfter timestamp (in milliseconds) for paginating. + */ + createdAfter?: number; + /** + * The Merchant Serial Number (MSN) is a unique ID for the sales unit + * for which this payment is made. + * This is a required parameter if you are a Recurring partner + * making payments on behalf of a merchant. + * The partner must use the merchant's MSN (not the partner's MSN). + * This parameter is optional, and recommended, for regular Vipps MobilePay + * merchants making payments for themselves. + */ + merchantSerialNumber?: string; + /** + * The subscription key for your sales unit. See [API keys](/docs/knowledge-base/api-keys/). Keep it secret. + */ + ocpApimSubscriptionKey: string; + /** + * Filter by the `status` of the agreement. + */ + status?: AgreementStatus; + /** + * The name of the ecommerce solution. One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemName?: string; + /** + * The name of the ecommerce plugin (if applicable). One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginName?: string; + /** + * The version number of the ecommerce plugin (if applicable). + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginVersion?: string; + /** + * The version number of the ecommerce solution. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemVersion?: string; +}; + +export type ListAgreementsResponse = Array; + +export type DraftAgreementData = { + /** + * The access token is a base64-encoded string that is required for all API requests. It is a JWT (JSON Web Token). The access token is fetched from the + * [`POST:/accesstoken/get`](/api/access-token#tag/Authorization-Service/operation/fetchAuthorizationTokenUsingPost) + * endpoint. + * It is valid for 1 hour in the test environment and 24 hours in the production environment. + */ + authorization: string; + /** + * The content type must be `application/json` + */ + contentType?: string; + /** + * The Merchant Serial Number (MSN) is a unique ID for the sales unit + * for which this payment is made. + * This is a required parameter if you are a Recurring partner + * making payments on behalf of a merchant. + * The partner must use the merchant's MSN (not the partner's MSN). + * This parameter is optional, and recommended, for regular Vipps MobilePay + * merchants making payments for themselves. + */ + merchantSerialNumber?: string; + /** + * The subscription key for your sales unit. See [API keys](/docs/knowledge-base/api-keys/). Keep it secret. + */ + ocpApimSubscriptionKey: string; + requestBody: DraftAgreementV2; + /** + * The name of the ecommerce solution. One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemName?: string; + /** + * The name of the ecommerce plugin (if applicable). One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginName?: string; + /** + * The version number of the ecommerce plugin (if applicable). + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginVersion?: string; + /** + * The version number of the ecommerce solution. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemVersion?: string; +}; + +export type DraftAgreementResponse = DraftAgreementResponseV2; + +export type FetchAgreementData = { + /** + * The agreement identifier (ID) + */ + agreementId: string; + /** + * The access token is a base64-encoded string that is required for all API requests. It is a JWT (JSON Web Token). The access token is fetched from the + * [`POST:/accesstoken/get`](/api/access-token#tag/Authorization-Service/operation/fetchAuthorizationTokenUsingPost) + * endpoint. + * It is valid for 1 hour in the test environment and 24 hours in the production environment. + */ + authorization: string; + /** + * The content type must be `application/json` + */ + contentType?: string; + /** + * The Merchant Serial Number (MSN) is a unique ID for the sales unit + * for which this payment is made. + * This is a required parameter if you are a Recurring partner + * making payments on behalf of a merchant. + * The partner must use the merchant's MSN (not the partner's MSN). + * This parameter is optional, and recommended, for regular Vipps MobilePay + * merchants making payments for themselves. + */ + merchantSerialNumber?: string; + /** + * The subscription key for your sales unit. See [API keys](/docs/knowledge-base/api-keys/). Keep it secret. + */ + ocpApimSubscriptionKey: string; + /** + * The name of the ecommerce solution. One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemName?: string; + /** + * The name of the ecommerce plugin (if applicable). One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginName?: string; + /** + * The version number of the ecommerce plugin (if applicable). + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginVersion?: string; + /** + * The version number of the ecommerce solution. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemVersion?: string; +}; + +export type FetchAgreementResponse = AgreementResponseV2; + +export type UpdateAgreementPutData = { + /** + * The agreement identifier (ID) + */ + agreementId: string; + /** + * The access token is a base64-encoded string that is required for all API requests. It is a JWT (JSON Web Token). The access token is fetched from the + * [`POST:/accesstoken/get`](/api/access-token#tag/Authorization-Service/operation/fetchAuthorizationTokenUsingPost) + * endpoint. + * It is valid for 1 hour in the test environment and 24 hours in the production environment. + */ + authorization: string; + /** + * The content type must be `application/json` + */ + contentType?: string; + /** + * The Merchant Serial Number (MSN) is a unique ID for the sales unit + * for which this payment is made. + * This is a required parameter if you are a Recurring partner + * making payments on behalf of a merchant. + * The partner must use the merchant's MSN (not the partner's MSN). + * This parameter is optional, and recommended, for regular Vipps MobilePay + * merchants making payments for themselves. + */ + merchantSerialNumber?: string; + /** + * The subscription key for your sales unit. See [API keys](/docs/knowledge-base/api-keys/). Keep it secret. + */ + ocpApimSubscriptionKey: string; + /** + * agreement + */ + requestBody: PatchAgreementV2; + /** + * The name of the ecommerce solution. One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemName?: string; + /** + * The name of the ecommerce plugin (if applicable). One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginName?: string; + /** + * The version number of the ecommerce plugin (if applicable). + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginVersion?: string; + /** + * The version number of the ecommerce solution. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemVersion?: string; +}; + +export type UpdateAgreementPutResponse = AgreementReference; + +export type UpdateAgreementPatchData = { + /** + * The agreement identifier (ID) + */ + agreementId: string; + /** + * The access token is a base64-encoded string that is required for all API requests. It is a JWT (JSON Web Token). The access token is fetched from the + * [`POST:/accesstoken/get`](/api/access-token#tag/Authorization-Service/operation/fetchAuthorizationTokenUsingPost) + * endpoint. + * It is valid for 1 hour in the test environment and 24 hours in the production environment. + */ + authorization: string; + /** + * The content type must be `application/json` + */ + contentType?: string; + /** + * The Merchant Serial Number (MSN) is a unique ID for the sales unit + * for which this payment is made. + * This is a required parameter if you are a Recurring partner + * making payments on behalf of a merchant. + * The partner must use the merchant's MSN (not the partner's MSN). + * This parameter is optional, and recommended, for regular Vipps MobilePay + * merchants making payments for themselves. + */ + merchantSerialNumber?: string; + /** + * The subscription key for your sales unit. See [API keys](/docs/knowledge-base/api-keys/). Keep it secret. + */ + ocpApimSubscriptionKey: string; + /** + * agreement + */ + requestBody: PatchAgreementV2; + /** + * The name of the ecommerce solution. One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemName?: string; + /** + * The name of the ecommerce plugin (if applicable). One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginName?: string; + /** + * The version number of the ecommerce plugin (if applicable). + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginVersion?: string; + /** + * The version number of the ecommerce solution. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemVersion?: string; +}; + +export type UpdateAgreementPatchResponse = AgreementReference; + +export type AcceptUsingPatchData = { + /** + * The agreement identifier (ID) + */ + agreementId: string; + /** + * The access token is a base64-encoded string that is required for all API requests. It is a JWT (JSON Web Token). The access token is fetched from the + * [`POST:/accesstoken/get`](/api/access-token#tag/Authorization-Service/operation/fetchAuthorizationTokenUsingPost) + * endpoint. + * It is valid for 1 hour in the test environment and 24 hours in the production environment. + */ + authorization: string; + /** + * The content type must be `application/json` + */ + contentType?: string; + /** + * The Merchant Serial Number (MSN) is a unique ID for the sales unit + * for which this payment is made. + * This is a required parameter if you are a Recurring partner + * making payments on behalf of a merchant. + * The partner must use the merchant's MSN (not the partner's MSN). + * This parameter is optional, and recommended, for regular Vipps MobilePay + * merchants making payments for themselves. + */ + merchantSerialNumber?: string; + /** + * The subscription key for your sales unit. See [API keys](/docs/knowledge-base/api-keys/). Keep it secret. + */ + ocpApimSubscriptionKey: string; + requestBody: ForceAcceptAgreement; + /** + * The name of the ecommerce solution. One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemName?: string; + /** + * The name of the ecommerce plugin (if applicable). One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginName?: string; + /** + * The version number of the ecommerce plugin (if applicable). + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginVersion?: string; + /** + * The version number of the ecommerce solution. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemVersion?: string; +}; + +export type AcceptUsingPatchResponse = { + [key: string]: unknown; +}; + +export type ListAgreementsV3Data = { + /** + * The access token is a base64-encoded string that is required for all API requests. It is a JWT (JSON Web Token). The access token is fetched from the + * [`POST:/accesstoken/get`](/api/access-token#tag/Authorization-Service/operation/fetchAuthorizationTokenUsingPost) + * endpoint. + * It is valid for 1 hour in the test environment and 24 hours in the production environment. + */ + authorization: string; + /** + * The content type must be `application/json` + */ + contentType?: string; + /** + * Filter by createdAfter timestamp (in milliseconds) for paginating. + */ + createdAfter?: number; + /** + * The Merchant Serial Number (MSN) is a unique ID for the sales unit + * for which this payment is made. + * This is a required parameter if you are a Recurring partner + * making payments on behalf of a merchant. + * The partner must use the merchant's MSN (not the partner's MSN). + * This parameter is optional, and recommended, for regular Vipps MobilePay + * merchants making payments for themselves. + */ + merchantSerialNumber?: string; + /** + * The subscription key for your sales unit. See [API keys](/docs/knowledge-base/api-keys/). Keep it secret. + */ + ocpApimSubscriptionKey: string; + /** + * Page number for paginating. + */ + pageNumber?: number; + /** + * Page size for paginating (must be used in combination with pageNumber). + */ + pageSize?: number; + /** + * Filter by the `status` of the agreement. + */ + status?: AgreementStatus; + /** + * The name of the ecommerce solution. One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemName?: string; + /** + * The name of the ecommerce plugin (if applicable). One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginName?: string; + /** + * The version number of the ecommerce plugin (if applicable). + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginVersion?: string; + /** + * The version number of the ecommerce solution. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemVersion?: string; +}; + +export type ListAgreementsV3Response = Array; + +export type DraftAgreementV3Data = { + /** + * The access token is a base64-encoded string that is required for all API requests. It is a JWT (JSON Web Token). The access token is fetched from the + * [`POST:/accesstoken/get`](/api/access-token#tag/Authorization-Service/operation/fetchAuthorizationTokenUsingPost) + * endpoint. + * It is valid for 1 hour in the test environment and 24 hours in the production environment. + */ + authorization: string; + /** + * The content type must be `application/json` + */ + contentType?: string; + /** + * An Idempotency key must be provided to ensure idempotent requests. + * Key size can be between 1 to 40 characters. + * Key must not contain '#', '?', '/' or '\\' + */ + idempotencyKey: string; + /** + * The Merchant Serial Number (MSN) is a unique ID for the sales unit + * for which this payment is made. + * This is a required parameter if you are a Recurring partner + * making payments on behalf of a merchant. + * The partner must use the merchant's MSN (not the partner's MSN). + * This parameter is optional, and recommended, for regular Vipps MobilePay + * merchants making payments for themselves. + */ + merchantSerialNumber?: string; + /** + * The subscription key for your sales unit. See [API keys](/docs/knowledge-base/api-keys/). Keep it secret. + */ + ocpApimSubscriptionKey: string; + requestBody: DraftAgreementV3; + /** + * The name of the ecommerce solution. One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemName?: string; + /** + * The name of the ecommerce plugin (if applicable). One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginName?: string; + /** + * The version number of the ecommerce plugin (if applicable). + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginVersion?: string; + /** + * The version number of the ecommerce solution. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemVersion?: string; +}; + +export type DraftAgreementV3Response = DraftAgreementResponseV3; + +export type FetchAgreementV3Data = { + /** + * The agreement identifier (ID) + */ + agreementId: string; + /** + * The access token is a base64-encoded string that is required for all API requests. It is a JWT (JSON Web Token). The access token is fetched from the + * [`POST:/accesstoken/get`](/api/access-token#tag/Authorization-Service/operation/fetchAuthorizationTokenUsingPost) + * endpoint. + * It is valid for 1 hour in the test environment and 24 hours in the production environment. + */ + authorization: string; + /** + * The content type must be `application/json` + */ + contentType?: string; + /** + * The Merchant Serial Number (MSN) is a unique ID for the sales unit + * for which this payment is made. + * This is a required parameter if you are a Recurring partner + * making payments on behalf of a merchant. + * The partner must use the merchant's MSN (not the partner's MSN). + * This parameter is optional, and recommended, for regular Vipps MobilePay + * merchants making payments for themselves. + */ + merchantSerialNumber?: string; + /** + * The subscription key for your sales unit. See [API keys](/docs/knowledge-base/api-keys/). Keep it secret. + */ + ocpApimSubscriptionKey: string; + /** + * The name of the ecommerce solution. One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemName?: string; + /** + * The name of the ecommerce plugin (if applicable). One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginName?: string; + /** + * The version number of the ecommerce plugin (if applicable). + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginVersion?: string; + /** + * The version number of the ecommerce solution. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemVersion?: string; +}; + +export type FetchAgreementV3Response = AgreementResponseV3; + +export type UpdateAgreementPatchV3Data = { + /** + * The agreement identifier (ID) + */ + agreementId: string; + /** + * The access token is a base64-encoded string that is required for all API requests. It is a JWT (JSON Web Token). The access token is fetched from the + * [`POST:/accesstoken/get`](/api/access-token#tag/Authorization-Service/operation/fetchAuthorizationTokenUsingPost) + * endpoint. + * It is valid for 1 hour in the test environment and 24 hours in the production environment. + */ + authorization: string; + /** + * The content type must be `application/json` + */ + contentType?: string; + /** + * An Idempotency key must be provided to ensure idempotent requests. + * Key size can be between 1 to 40 characters. + * Key must not contain '#', '?', '/' or '\\' + */ + idempotencyKey: string; + /** + * The Merchant Serial Number (MSN) is a unique ID for the sales unit + * for which this payment is made. + * This is a required parameter if you are a Recurring partner + * making payments on behalf of a merchant. + * The partner must use the merchant's MSN (not the partner's MSN). + * This parameter is optional, and recommended, for regular Vipps MobilePay + * merchants making payments for themselves. + */ + merchantSerialNumber?: string; + /** + * The subscription key for your sales unit. See [API keys](/docs/knowledge-base/api-keys/). Keep it secret. + */ + ocpApimSubscriptionKey: string; + /** + * agreement + */ + requestBody: PatchAgreementV3; + /** + * The name of the ecommerce solution. One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemName?: string; + /** + * The name of the ecommerce plugin (if applicable). One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginName?: string; + /** + * The version number of the ecommerce plugin (if applicable). + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginVersion?: string; + /** + * The version number of the ecommerce solution. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemVersion?: string; +}; + +export type UpdateAgreementPatchV3Response = unknown | void; + +export type AcceptUsingPatchv3Data = { + /** + * The agreement identifier (ID) + */ + agreementId: string; + /** + * The access token is a base64-encoded string that is required for all API requests. It is a JWT (JSON Web Token). The access token is fetched from the + * [`POST:/accesstoken/get`](/api/access-token#tag/Authorization-Service/operation/fetchAuthorizationTokenUsingPost) + * endpoint. + * It is valid for 1 hour in the test environment and 24 hours in the production environment. + */ + authorization: string; + /** + * The content type must be `application/json` + */ + contentType?: string; + /** + * An Idempotency key must be provided to ensure idempotent requests. + * Key size can be between 1 to 40 characters. + * Key must not contain '#', '?', '/' or '\\' + */ + idempotencyKey: string; + /** + * The Merchant Serial Number (MSN) is a unique ID for the sales unit + * for which this payment is made. + * This is a required parameter if you are a Recurring partner + * making payments on behalf of a merchant. + * The partner must use the merchant's MSN (not the partner's MSN). + * This parameter is optional, and recommended, for regular Vipps MobilePay + * merchants making payments for themselves. + */ + merchantSerialNumber?: string; + /** + * The subscription key for your sales unit. See [API keys](/docs/knowledge-base/api-keys/). Keep it secret. + */ + ocpApimSubscriptionKey: string; + requestBody: ForceAcceptAgreementV3; + /** + * The name of the ecommerce solution. One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemName?: string; + /** + * The name of the ecommerce plugin (if applicable). One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginName?: string; + /** + * The version number of the ecommerce plugin (if applicable). + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginVersion?: string; + /** + * The version number of the ecommerce solution. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemVersion?: string; +}; + +export type AcceptUsingPatchv3Response = { + [key: string]: unknown; +}; + +export type ListChargesData = { + /** + * The agreement identifier (ID) + */ + agreementId: string; + /** + * The access token is a base64-encoded string that is required for all API requests. It is a JWT (JSON Web Token). The access token is fetched from the + * [`POST:/accesstoken/get`](/api/access-token#tag/Authorization-Service/operation/fetchAuthorizationTokenUsingPost) + * endpoint. + * It is valid for 1 hour in the test environment and 24 hours in the production environment. + */ + authorization: string; + /** + * Filter by status of the charge. + */ + chargeStatus?: ChargeStatus; + /** + * The content type must be `application/json` + */ + contentType?: string; + /** + * The Merchant Serial Number (MSN) is a unique ID for the sales unit + * for which this payment is made. + * This is a required parameter if you are a Recurring partner + * making payments on behalf of a merchant. + * The partner must use the merchant's MSN (not the partner's MSN). + * This parameter is optional, and recommended, for regular Vipps MobilePay + * merchants making payments for themselves. + */ + merchantSerialNumber?: string; + /** + * The subscription key for your sales unit. See [API keys](/docs/knowledge-base/api-keys/). Keep it secret. + */ + ocpApimSubscriptionKey: string; + /** + * The name of the ecommerce solution. One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemName?: string; + /** + * The name of the ecommerce plugin (if applicable). One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginName?: string; + /** + * The version number of the ecommerce plugin (if applicable). + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginVersion?: string; + /** + * The version number of the ecommerce solution. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemVersion?: string; +}; + +export type ListChargesResponse = Array; + +export type CreateChargeData = { + /** + * The agreement identifier (ID) + */ + agreementId: string; + /** + * The access token is a base64-encoded string that is required for all API requests. It is a JWT (JSON Web Token). The access token is fetched from the + * [`POST:/accesstoken/get`](/api/access-token#tag/Authorization-Service/operation/fetchAuthorizationTokenUsingPost) + * endpoint. + * It is valid for 1 hour in the test environment and 24 hours in the production environment. + */ + authorization: string; + /** + * The content type must be `application/json` + */ + contentType?: string; + /** + * An Idempotency key must be provided to ensure idempotent requests. + * Key size can be between 1 to 40 characters. + * Key must not contain '#', '?', '/' or '\\' + */ + idempotencyKey: string; + /** + * The Merchant Serial Number (MSN) is a unique ID for the sales unit + * for which this payment is made. + * This is a required parameter if you are a Recurring partner + * making payments on behalf of a merchant. + * The partner must use the merchant's MSN (not the partner's MSN). + * This parameter is optional, and recommended, for regular Vipps MobilePay + * merchants making payments for themselves. + */ + merchantSerialNumber?: string; + /** + * The subscription key for your sales unit. See [API keys](/docs/knowledge-base/api-keys/). Keep it secret. + */ + ocpApimSubscriptionKey: string; + requestBody: CreateChargeV2; + /** + * The name of the ecommerce solution. One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemName?: string; + /** + * The name of the ecommerce plugin (if applicable). One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginName?: string; + /** + * The version number of the ecommerce plugin (if applicable). + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginVersion?: string; + /** + * The version number of the ecommerce solution. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemVersion?: string; +}; + +export type CreateChargeResponse = ChargeReference; + +export type FetchChargeData = { + /** + * The agreement identifier (ID) + */ + agreementId: string; + /** + * The access token is a base64-encoded string that is required for all API requests. It is a JWT (JSON Web Token). The access token is fetched from the + * [`POST:/accesstoken/get`](/api/access-token#tag/Authorization-Service/operation/fetchAuthorizationTokenUsingPost) + * endpoint. + * It is valid for 1 hour in the test environment and 24 hours in the production environment. + */ + authorization: string; + /** + * The charge identifier (ID) + */ + chargeId: string; + /** + * The content type must be `application/json` + */ + contentType?: string; + /** + * The Merchant Serial Number (MSN) is a unique ID for the sales unit + * for which this payment is made. + * This is a required parameter if you are a Recurring partner + * making payments on behalf of a merchant. + * The partner must use the merchant's MSN (not the partner's MSN). + * This parameter is optional, and recommended, for regular Vipps MobilePay + * merchants making payments for themselves. + */ + merchantSerialNumber?: string; + /** + * The subscription key for your sales unit. See [API keys](/docs/knowledge-base/api-keys/). Keep it secret. + */ + ocpApimSubscriptionKey: string; + /** + * The name of the ecommerce solution. One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemName?: string; + /** + * The name of the ecommerce plugin (if applicable). One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginName?: string; + /** + * The version number of the ecommerce plugin (if applicable). + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginVersion?: string; + /** + * The version number of the ecommerce solution. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemVersion?: string; +}; + +export type FetchChargeResponse = ChargeResponseV2; + +export type CancelChargeData = { + /** + * The agreement identifier (ID) + */ + agreementId: string; + /** + * The access token is a base64-encoded string that is required for all API requests. It is a JWT (JSON Web Token). The access token is fetched from the + * [`POST:/accesstoken/get`](/api/access-token#tag/Authorization-Service/operation/fetchAuthorizationTokenUsingPost) + * endpoint. + * It is valid for 1 hour in the test environment and 24 hours in the production environment. + */ + authorization: string; + /** + * The charge identifier (ID) + */ + chargeId: string; + /** + * The content type must be `application/json` + */ + contentType?: string; + /** + * The Merchant Serial Number (MSN) is a unique ID for the sales unit + * for which this payment is made. + * This is a required parameter if you are a Recurring partner + * making payments on behalf of a merchant. + * The partner must use the merchant's MSN (not the partner's MSN). + * This parameter is optional, and recommended, for regular Vipps MobilePay + * merchants making payments for themselves. + */ + merchantSerialNumber?: string; + /** + * The subscription key for your sales unit. See [API keys](/docs/knowledge-base/api-keys/). Keep it secret. + */ + ocpApimSubscriptionKey: string; + /** + * The name of the ecommerce solution. One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemName?: string; + /** + * The name of the ecommerce plugin (if applicable). One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginName?: string; + /** + * The version number of the ecommerce plugin (if applicable). + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginVersion?: string; + /** + * The version number of the ecommerce solution. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemVersion?: string; +}; + +export type CancelChargeResponse = ChargeResponseV2; + +export type CaptureChargeData = { + /** + * The agreement identifier (ID) + */ + agreementId: string; + /** + * The access token is a base64-encoded string that is required for all API requests. It is a JWT (JSON Web Token). The access token is fetched from the + * [`POST:/accesstoken/get`](/api/access-token#tag/Authorization-Service/operation/fetchAuthorizationTokenUsingPost) + * endpoint. + * It is valid for 1 hour in the test environment and 24 hours in the production environment. + */ + authorization: string; + /** + * The charge identifier (ID) + */ + chargeId: string; + /** + * The content type must be `application/json` + */ + contentType?: string; + /** + * An Idempotency key must be provided to ensure idempotent requests. + * Key size can be between 1 to 40 characters. + * Key must not contain '#', '?', '/' or '\\' + */ + idempotencyKey: string; + /** + * The Merchant Serial Number (MSN) is a unique ID for the sales unit + * for which this payment is made. + * This is a required parameter if you are a Recurring partner + * making payments on behalf of a merchant. + * The partner must use the merchant's MSN (not the partner's MSN). + * This parameter is optional, and recommended, for regular Vipps MobilePay + * merchants making payments for themselves. + */ + merchantSerialNumber?: string; + /** + * The subscription key for your sales unit. See [API keys](/docs/knowledge-base/api-keys/). Keep it secret. + */ + ocpApimSubscriptionKey: string; + /** + * The name of the ecommerce solution. One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemName?: string; + /** + * The name of the ecommerce plugin (if applicable). One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginName?: string; + /** + * The version number of the ecommerce plugin (if applicable). + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginVersion?: string; + /** + * The version number of the ecommerce solution. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemVersion?: string; +}; + +export type CaptureChargeResponse = { + [key: string]: unknown; +}; + +export type RefundChargeData = { + /** + * The agreement identifier (ID) + */ + agreementId: string; + /** + * The access token is a base64-encoded string that is required for all API requests. It is a JWT (JSON Web Token). The access token is fetched from the + * [`POST:/accesstoken/get`](/api/access-token#tag/Authorization-Service/operation/fetchAuthorizationTokenUsingPost) + * endpoint. + * It is valid for 1 hour in the test environment and 24 hours in the production environment. + */ + authorization: string; + /** + * The charge identifier (ID) + */ + chargeId: string; + /** + * The content type must be `application/json` + */ + contentType?: string; + /** + * An Idempotency key must be provided to ensure idempotent requests. + * Key size can be between 1 to 40 characters. + * Key must not contain '#', '?', '/' or '\\' + */ + idempotencyKey: string; + /** + * The Merchant Serial Number (MSN) is a unique ID for the sales unit + * for which this payment is made. + * This is a required parameter if you are a Recurring partner + * making payments on behalf of a merchant. + * The partner must use the merchant's MSN (not the partner's MSN). + * This parameter is optional, and recommended, for regular Vipps MobilePay + * merchants making payments for themselves. + */ + merchantSerialNumber?: string; + /** + * The subscription key for your sales unit. See [API keys](/docs/knowledge-base/api-keys/). Keep it secret. + */ + ocpApimSubscriptionKey: string; + requestBody: RefundRequest; + /** + * The name of the ecommerce solution. One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemName?: string; + /** + * The name of the ecommerce plugin (if applicable). One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginName?: string; + /** + * The version number of the ecommerce plugin (if applicable). + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginVersion?: string; + /** + * The version number of the ecommerce solution. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemVersion?: string; +}; + +export type RefundChargeResponse = { + [key: string]: unknown; +}; + +export type ListChargesV3Data = { + /** + * The agreement identifier (ID) + */ + agreementId: string; + /** + * The access token is a base64-encoded string that is required for all API requests. It is a JWT (JSON Web Token). The access token is fetched from the + * [`POST:/accesstoken/get`](/api/access-token#tag/Authorization-Service/operation/fetchAuthorizationTokenUsingPost) + * endpoint. + * It is valid for 1 hour in the test environment and 24 hours in the production environment. + */ + authorization: string; + /** + * The content type must be `application/json` + */ + contentType?: string; + /** + * When returned from an endpoint, this indicates that there is more data than can be returned in one response. + * Repeating the request with the received token in the Continuation-Token header will return the next page of data. + * When not returned, the end of the data has been reached. + * + * Continuation-Tokens are short-lived, so they cannot be used several minutes/hours after received. + */ + continuationToken?: string; + /** + * The Merchant Serial Number (MSN) is a unique ID for the sales unit + * for which this payment is made. + * This is a required parameter if you are a Recurring partner + * making payments on behalf of a merchant. + * The partner must use the merchant's MSN (not the partner's MSN). + * This parameter is optional, and recommended, for regular Vipps MobilePay + * merchants making payments for themselves. + */ + merchantSerialNumber?: string; + /** + * The subscription key for your sales unit. See [API keys](/docs/knowledge-base/api-keys/). Keep it secret. + */ + ocpApimSubscriptionKey: string; + /** + * Filter by status of the charge. + */ + status?: ChargeStatus; + /** + * The name of the ecommerce solution. One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemName?: string; + /** + * The name of the ecommerce plugin (if applicable). One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginName?: string; + /** + * The version number of the ecommerce plugin (if applicable). + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginVersion?: string; + /** + * The version number of the ecommerce solution. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemVersion?: string; +}; + +export type ListChargesV3Response = Array; + +export type CreateChargeV3Data = { + /** + * The agreement identifier (ID) + */ + agreementId: string; + /** + * The access token is a base64-encoded string that is required for all API requests. It is a JWT (JSON Web Token). The access token is fetched from the + * [`POST:/accesstoken/get`](/api/access-token#tag/Authorization-Service/operation/fetchAuthorizationTokenUsingPost) + * endpoint. + * It is valid for 1 hour in the test environment and 24 hours in the production environment. + */ + authorization: string; + /** + * The content type must be `application/json` + */ + contentType?: string; + /** + * An Idempotency key must be provided to ensure idempotent requests. + * Key size can be between 1 to 40 characters. + * Key must not contain '#', '?', '/' or '\\' + */ + idempotencyKey: string; + /** + * The Merchant Serial Number (MSN) is a unique ID for the sales unit + * for which this payment is made. + * This is a required parameter if you are a Recurring partner + * making payments on behalf of a merchant. + * The partner must use the merchant's MSN (not the partner's MSN). + * This parameter is optional, and recommended, for regular Vipps MobilePay + * merchants making payments for themselves. + */ + merchantSerialNumber?: string; + /** + * The subscription key for your sales unit. See [API keys](/docs/knowledge-base/api-keys/). Keep it secret. + */ + ocpApimSubscriptionKey: string; + requestBody: CreateChargeV3; + /** + * The name of the ecommerce solution. One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemName?: string; + /** + * The name of the ecommerce plugin (if applicable). One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginName?: string; + /** + * The version number of the ecommerce plugin (if applicable). + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginVersion?: string; + /** + * The version number of the ecommerce solution. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemVersion?: string; +}; + +export type CreateChargeV3Response = ChargeReference; + +export type CreateChargeAsyncV3Data = { + /** + * The access token is a base64-encoded string that is required for all API requests. It is a JWT (JSON Web Token). The access token is fetched from the + * [`POST:/accesstoken/get`](/api/access-token#tag/Authorization-Service/operation/fetchAuthorizationTokenUsingPost) + * endpoint. + * It is valid for 1 hour in the test environment and 24 hours in the production environment. + */ + authorization: string; + /** + * The content type must be `application/json` + */ + contentType?: string; + /** + * An Idempotency key must be provided to ensure idempotent requests. + * Key size can be between 1 to 40 characters. + * Key must not contain '#', '?', '/' or '\\' + */ + idempotencyKey: string; + /** + * The Merchant Serial Number (MSN) is a unique ID for the sales unit + * for which this payment is made. + * This is a required parameter if you are a Recurring partner + * making payments on behalf of a merchant. + * The partner must use the merchant's MSN (not the partner's MSN). + * This parameter is optional, and recommended, for regular Vipps MobilePay + * merchants making payments for themselves. + */ + merchantSerialNumber?: string; + /** + * The subscription key for your sales unit. See [API keys](/docs/knowledge-base/api-keys/). Keep it secret. + */ + ocpApimSubscriptionKey: string; + requestBody: Array; + /** + * The name of the ecommerce solution. One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemName?: string; + /** + * The name of the ecommerce plugin (if applicable). One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginName?: string; + /** + * The version number of the ecommerce plugin (if applicable). + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginVersion?: string; + /** + * The version number of the ecommerce solution. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemVersion?: string; +}; + +export type CreateChargeAsyncV3Response = AsyncChargeResponse; + +export type FetchChargeV3Data = { + /** + * The agreement identifier (ID) + */ + agreementId: string; + /** + * The access token is a base64-encoded string that is required for all API requests. It is a JWT (JSON Web Token). The access token is fetched from the + * [`POST:/accesstoken/get`](/api/access-token#tag/Authorization-Service/operation/fetchAuthorizationTokenUsingPost) + * endpoint. + * It is valid for 1 hour in the test environment and 24 hours in the production environment. + */ + authorization: string; + /** + * The charge identifier (ID) + */ + chargeId: string; + /** + * The content type must be `application/json` + */ + contentType?: string; + /** + * The Merchant Serial Number (MSN) is a unique ID for the sales unit + * for which this payment is made. + * This is a required parameter if you are a Recurring partner + * making payments on behalf of a merchant. + * The partner must use the merchant's MSN (not the partner's MSN). + * This parameter is optional, and recommended, for regular Vipps MobilePay + * merchants making payments for themselves. + */ + merchantSerialNumber?: string; + /** + * The subscription key for your sales unit. See [API keys](/docs/knowledge-base/api-keys/). Keep it secret. + */ + ocpApimSubscriptionKey: string; + /** + * The name of the ecommerce solution. One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemName?: string; + /** + * The name of the ecommerce plugin (if applicable). One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginName?: string; + /** + * The version number of the ecommerce plugin (if applicable). + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginVersion?: string; + /** + * The version number of the ecommerce solution. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemVersion?: string; +}; + +export type FetchChargeV3Response = ChargeResponseV3; + +export type CancelChargeV3Data = { + /** + * The agreement identifier (ID) + */ + agreementId: string; + /** + * The access token is a base64-encoded string that is required for all API requests. It is a JWT (JSON Web Token). The access token is fetched from the + * [`POST:/accesstoken/get`](/api/access-token#tag/Authorization-Service/operation/fetchAuthorizationTokenUsingPost) + * endpoint. + * It is valid for 1 hour in the test environment and 24 hours in the production environment. + */ + authorization: string; + /** + * The charge identifier (ID) + */ + chargeId: string; + /** + * The content type must be `application/json` + */ + contentType?: string; + /** + * An Idempotency key must be provided to ensure idempotent requests. + * Key size can be between 1 to 40 characters. + * Key must not contain '#', '?', '/' or '\\' + */ + idempotencyKey: string; + /** + * The Merchant Serial Number (MSN) is a unique ID for the sales unit + * for which this payment is made. + * This is a required parameter if you are a Recurring partner + * making payments on behalf of a merchant. + * The partner must use the merchant's MSN (not the partner's MSN). + * This parameter is optional, and recommended, for regular Vipps MobilePay + * merchants making payments for themselves. + */ + merchantSerialNumber?: string; + /** + * The subscription key for your sales unit. See [API keys](/docs/knowledge-base/api-keys/). Keep it secret. + */ + ocpApimSubscriptionKey: string; + /** + * The name of the ecommerce solution. One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemName?: string; + /** + * The name of the ecommerce plugin (if applicable). One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginName?: string; + /** + * The version number of the ecommerce plugin (if applicable). + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginVersion?: string; + /** + * The version number of the ecommerce solution. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemVersion?: string; +}; + +export type CancelChargeV3Response = unknown | void; + +export type FetchChargeByIdV3Data = { + /** + * The access token is a base64-encoded string that is required for all API requests. It is a JWT (JSON Web Token). The access token is fetched from the + * [`POST:/accesstoken/get`](/api/access-token#tag/Authorization-Service/operation/fetchAuthorizationTokenUsingPost) + * endpoint. + * It is valid for 1 hour in the test environment and 24 hours in the production environment. + */ + authorization: string; + /** + * The charge identifier (ID) + */ + chargeId: string; + /** + * The content type must be `application/json` + */ + contentType?: string; + /** + * The Merchant Serial Number (MSN) is a unique ID for the sales unit + * for which this payment is made. + * This is a required parameter if you are a Recurring partner + * making payments on behalf of a merchant. + * The partner must use the merchant's MSN (not the partner's MSN). + * This parameter is optional, and recommended, for regular Vipps MobilePay + * merchants making payments for themselves. + */ + merchantSerialNumber?: string; + /** + * The subscription key for your sales unit. See [API keys](/docs/knowledge-base/api-keys/). Keep it secret. + */ + ocpApimSubscriptionKey: string; + /** + * The name of the ecommerce solution. One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemName?: string; + /** + * The name of the ecommerce plugin (if applicable). One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginName?: string; + /** + * The version number of the ecommerce plugin (if applicable). + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginVersion?: string; + /** + * The version number of the ecommerce solution. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemVersion?: string; +}; + +export type FetchChargeByIdV3Response = ChargeResponseV3; + +export type CaptureChargeV3Data = { + /** + * The agreement identifier (ID) + */ + agreementId: string; + /** + * The access token is a base64-encoded string that is required for all API requests. It is a JWT (JSON Web Token). The access token is fetched from the + * [`POST:/accesstoken/get`](/api/access-token#tag/Authorization-Service/operation/fetchAuthorizationTokenUsingPost) + * endpoint. + * It is valid for 1 hour in the test environment and 24 hours in the production environment. + */ + authorization: string; + /** + * The charge identifier (ID) + */ + chargeId: string; + /** + * The content type must be `application/json` + */ + contentType?: string; + /** + * An Idempotency key must be provided to ensure idempotent requests. + * Key size can be between 1 to 40 characters. + * Key must not contain '#', '?', '/' or '\\' + */ + idempotencyKey: string; + /** + * The Merchant Serial Number (MSN) is a unique ID for the sales unit + * for which this payment is made. + * This is a required parameter if you are a Recurring partner + * making payments on behalf of a merchant. + * The partner must use the merchant's MSN (not the partner's MSN). + * This parameter is optional, and recommended, for regular Vipps MobilePay + * merchants making payments for themselves. + */ + merchantSerialNumber?: string; + /** + * The subscription key for your sales unit. See [API keys](/docs/knowledge-base/api-keys/). Keep it secret. + */ + ocpApimSubscriptionKey: string; + requestBody: CaptureRequestV3; + /** + * The name of the ecommerce solution. One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemName?: string; + /** + * The name of the ecommerce plugin (if applicable). One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginName?: string; + /** + * The version number of the ecommerce plugin (if applicable). + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginVersion?: string; + /** + * The version number of the ecommerce solution. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemVersion?: string; +}; + +export type CaptureChargeV3Response = unknown | void; + +export type RefundChargeV3Data = { + /** + * The agreement identifier (ID) + */ + agreementId: string; + /** + * The access token is a base64-encoded string that is required for all API requests. It is a JWT (JSON Web Token). The access token is fetched from the + * [`POST:/accesstoken/get`](/api/access-token#tag/Authorization-Service/operation/fetchAuthorizationTokenUsingPost) + * endpoint. + * It is valid for 1 hour in the test environment and 24 hours in the production environment. + */ + authorization: string; + /** + * The charge identifier (ID) + */ + chargeId: string; + /** + * The content type must be `application/json` + */ + contentType?: string; + /** + * An Idempotency key must be provided to ensure idempotent requests. + * Key size can be between 1 to 40 characters. + * Key must not contain '#', '?', '/' or '\\' + */ + idempotencyKey: string; + /** + * The Merchant Serial Number (MSN) is a unique ID for the sales unit + * for which this payment is made. + * This is a required parameter if you are a Recurring partner + * making payments on behalf of a merchant. + * The partner must use the merchant's MSN (not the partner's MSN). + * This parameter is optional, and recommended, for regular Vipps MobilePay + * merchants making payments for themselves. + */ + merchantSerialNumber?: string; + /** + * The subscription key for your sales unit. See [API keys](/docs/knowledge-base/api-keys/). Keep it secret. + */ + ocpApimSubscriptionKey: string; + requestBody: RefundRequest; + /** + * The name of the ecommerce solution. One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemName?: string; + /** + * The name of the ecommerce plugin (if applicable). One word in lowercase letters is good. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginName?: string; + /** + * The version number of the ecommerce plugin (if applicable). + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemPluginVersion?: string; + /** + * The version number of the ecommerce solution. + * See [HTTP headers](/docs/knowledge-base/http-headers). + */ + vippsSystemVersion?: string; +}; + +export type RefundChargeV3Response = void; + +export type $OpenApiTs = { + "/recurring/v2/agreements": { + get: { + req: ListAgreementsData; + res: { + /** + * OK' + */ + 200: Array; + /** + * Possible error responses. + * Errors can be from both our own code (where we have full control) and + * from Microsoft Azure (where we rely on standard functionality). + */ + default: ErrorArray | ErrorFromAzure; + }; + }; + post: { + req: DraftAgreementData; + res: { + /** + * Created + */ + 201: DraftAgreementResponseV2; + /** + * Possible error responses. + * Errors can be from both our own code (where we have full control) and + * from Microsoft Azure (where we rely on standard functionality). + */ + default: ErrorArray | ErrorFromAzure; + }; + }; + }; + "/recurring/v2/agreements/{agreementId}": { + get: { + req: FetchAgreementData; + res: { + /** + * OK + */ + 200: AgreementResponseV2; + /** + * Possible error responses. + * Errors can be from both our own code (where we have full control) and + * from Microsoft Azure (where we rely on standard functionality). + */ + default: ErrorArray | ErrorFromAzure; + }; + }; + put: { + req: UpdateAgreementPutData; + res: { + /** + * OK + */ + 200: AgreementReference; + /** + * Possible error responses. + * Errors can be from both our own code (where we have full control) and + * from Microsoft Azure (where we rely on standard functionality). + */ + default: ErrorArray | ErrorFromAzure; + }; + }; + patch: { + req: UpdateAgreementPatchData; + res: { + /** + * OK + */ + 200: AgreementReference; + /** + * Possible error responses. + * Errors can be from both our own code (where we have full control) and + * from Microsoft Azure (where we rely on standard functionality). + */ + default: ErrorArray | ErrorFromAzure; + }; + }; + }; + "/recurring/v2/agreements/{agreementId}/accept": { + patch: { + req: AcceptUsingPatchData; + res: { + /** + * OK + */ + 200: { + [key: string]: unknown; + }; + /** + * Possible error responses. + * Errors can be from both our own code (where we have full control) and + * from Microsoft Azure (where we rely on standard functionality). + */ + default: ErrorArray | ErrorFromAzure; + }; + }; + }; + "/recurring/v3/agreements": { + get: { + req: ListAgreementsV3Data; + res: { + /** + * OK + */ + 200: Array; + }; + }; + post: { + req: DraftAgreementV3Data; + res: { + /** + * Created + */ + 201: DraftAgreementResponseV3; + /** + * Standard problem response. + */ + 400: ErrorV3; + /** + * Standard problem response. + */ + 403: ErrorV3; + /** + * Standard problem response. + */ + 409: ErrorV3; + }; + }; + }; + "/recurring/v3/agreements/{agreementId}": { + get: { + req: FetchAgreementV3Data; + res: { + /** + * OK + */ + 200: AgreementResponseV3; + /** + * Standard problem response. + */ + 404: ErrorV3; + }; + }; + patch: { + req: UpdateAgreementPatchV3Data; + res: { + /** + * Accepted. Request accepted, the action will likely succeed but has not yet been enacted. + */ + 202: unknown; + /** + * No content + */ + 204: void; + /** + * Standard problem response. + */ + 400: ErrorV3; + /** + * Standard problem response. + */ + 404: ErrorV3; + }; + }; + }; + "/recurring/v3/agreements/{agreementId}/accept": { + patch: { + req: AcceptUsingPatchv3Data; + res: { + /** + * OK + */ + 204: { + [key: string]: unknown; + }; + /** + * Standard problem response. + */ + 400: ErrorV3; + /** + * Standard problem response. + */ + 404: ErrorV3; + }; + }; + }; + "/recurring/v2/agreements/{agreementId}/charges": { + get: { + req: ListChargesData; + res: { + /** + * Success + */ + 200: Array; + /** + * Possible error responses. + * Errors can be from both our own code (where we have full control) and + * from Microsoft Azure (where we rely on standard functionality). + */ + default: ErrorArray | ErrorFromAzure; + }; + }; + post: { + req: CreateChargeData; + res: { + /** + * OK + */ + 201: ChargeReference; + /** + * Possible error responses. + * Errors can be from both our own code (where we have full control) and + * from Microsoft Azure (where we rely on standard functionality). + */ + default: ErrorArray | ErrorFromAzure; + }; + }; + }; + "/recurring/v2/agreements/{agreementId}/charges/{chargeId}": { + get: { + req: FetchChargeData; + res: { + /** + * Success + */ + 200: ChargeResponseV2; + /** + * Possible error responses. + * Errors can be from both our own code (where we have full control) and + * from Microsoft Azure (where we rely on standard functionality). + */ + default: ErrorArray | ErrorFromAzure; + }; + }; + delete: { + req: CancelChargeData; + res: { + /** + * Success + */ + 200: ChargeResponseV2; + /** + * Possible error responses. + * Errors can be from both our own code (where we have full control) and + * from Microsoft Azure (where we rely on standard functionality). + */ + default: ErrorArray | ErrorFromAzure; + }; + }; + }; + "/recurring/v2/agreements/{agreementId}/charges/{chargeId}/capture": { + post: { + req: CaptureChargeData; + res: { + /** + * Success + */ + 200: { + [key: string]: unknown; + }; + /** + * Possible error responses. + * Errors can be from both our own code (where we have full control) and + * from Microsoft Azure (where we rely on standard functionality). + */ + default: ErrorArray | ErrorFromAzure; + }; + }; + }; + "/recurring/v2/agreements/{agreementId}/charges/{chargeId}/refund": { + post: { + req: RefundChargeData; + res: { + /** + * Success + */ + 200: { + [key: string]: unknown; + }; + /** + * Possible error responses. + * Errors can be from both our own code (where we have full control) and + * from Microsoft Azure (where we rely on standard functionality). + */ + default: ErrorArray | ErrorFromAzure; + }; + }; + }; + "/recurring/v3/agreements/{agreementId}/charges": { + get: { + req: ListChargesV3Data; + res: { + /** + * Success + */ + 200: Array; + /** + * Standard problem response. + */ + 404: ErrorV3; + }; + }; + post: { + req: CreateChargeV3Data; + res: { + /** + * Created + */ + 201: ChargeReference; + /** + * Standard problem response. + */ + 400: ErrorV3; + /** + * Standard problem response. + */ + 404: ErrorV3; + /** + * Standard problem response. + */ + 409: ErrorV3; + }; + }; + }; + "/recurring/v3/agreements/charges": { + post: { + req: CreateChargeAsyncV3Data; + res: { + /** + * None, some or all charges passed API level validation. + */ + 202: Array; + }; + }; + }; + "/recurring/v3/agreements/{agreementId}/charges/{chargeId}": { + get: { + req: FetchChargeV3Data; + res: { + /** + * Success + */ + 200: ChargeResponseV3; + /** + * Standard problem response. + */ + 404: ErrorV3; + }; + }; + delete: { + req: CancelChargeV3Data; + res: { + /** + * Accepted. Request accepted, the action will likely succeed but has not yet been enacted. + */ + 202: unknown; + /** + * No content + */ + 204: void; + /** + * Standard problem response. + */ + 400: ErrorV3; + /** + * Standard problem response. + */ + 404: ErrorV3; + /** + * Standard problem response. + */ + 409: ErrorV3; + }; + }; + }; + "/recurring/v3/charges/{chargeId}": { + get: { + req: FetchChargeByIdV3Data; + res: { + /** + * Success + */ + 200: ChargeResponseV3; + /** + * Standard problem response. + */ + 404: ErrorV3; + }; + }; + }; + "/recurring/v3/agreements/{agreementId}/charges/{chargeId}/capture": { + post: { + req: CaptureChargeV3Data; + res: { + /** + * Accepted. Request accepted, the action will likely succeed but has not yet been enacted. + */ + 202: unknown; + /** + * No content + */ + 204: void; + /** + * Standard problem response. + */ + 400: ErrorV3; + /** + * Standard problem response. + */ + 404: ErrorV3; + /** + * Standard problem response. + */ + 409: ErrorV3; + }; + }; + }; + "/recurring/v3/agreements/{agreementId}/charges/{chargeId}/refund": { + post: { + req: RefundChargeV3Data; + res: { + /** + * No content + */ + 204: void; + /** + * The standard error object, based on RFC 7807. See https://developer.vippsmobilepay.com/docs/APIs/recurring-api/recurring-api-problems/ + */ + 400: unknown; + /** + * Standard problem response. + */ + 404: ErrorV3; + /** + * Standard problem response. + */ + 409: ErrorV3; + }; + }; + }; +}; diff --git a/src/types_external.ts b/src/types_external.ts index b57cade..56026d4 100644 --- a/src/types_external.ts +++ b/src/types_external.ts @@ -84,6 +84,27 @@ export type { RefundPaymentResponse, } from "./generated_types/epayment/types.gen.ts"; +/** + * Recurring API + */ +export type { + AgreementResponseV3, + AgreementStatus, + CaptureRequestV3, + ChargeReference, + ChargeResponseV3, + ChargeStatus, + CreateChargeAsyncV3, + CreateChargeAsyncV3Response, + CreateChargeV3, + DraftAgreementResponseV3, + DraftAgreementV3, + ErrorV3, + ForceAcceptAgreementV3, + PatchAgreementV3, + RefundRequest, +} from "./generated_types/recurring/types.gen.ts"; + /** * Webhooks API */ diff --git a/tests/mod_test.ts b/tests/mod_test.ts index 52724f9..b766bb1 100644 --- a/tests/mod_test.ts +++ b/tests/mod_test.ts @@ -14,6 +14,19 @@ Deno.test("Client - available functions", () => { assertEquals(typeof client.payment.refund, "function"); assertEquals(typeof client.payment.forceApprove, "function"); assertEquals(typeof client.payment.history, "function"); + assertEquals(typeof client.recurring.agreement.create, "function") + assertEquals(typeof client.recurring.agreement.forceAccept, "function") + assertEquals(typeof client.recurring.agreement.info, "function") + assertEquals(typeof client.recurring.agreement.list, "function") + assertEquals(typeof client.recurring.agreement.update, "function") + assertEquals(typeof client.recurring.charge.create, "function") + assertEquals(typeof client.recurring.charge.cancel, "function") + assertEquals(typeof client.recurring.charge.capture, "function") + assertEquals(typeof client.recurring.charge.createMultiple, "function") + assertEquals(typeof client.recurring.charge.info, "function") + assertEquals(typeof client.recurring.charge.infoById, "function") + assertEquals(typeof client.recurring.charge.list, "function") + assertEquals(typeof client.recurring.charge.refund, "function") assertEquals(typeof client.webhook.list, "function"); assertEquals(typeof client.webhook.register, "function"); assertEquals(typeof client.webhook.delete, "function"); diff --git a/tests/recurring_test.ts b/tests/recurring_test.ts new file mode 100644 index 0000000..6e1ac03 --- /dev/null +++ b/tests/recurring_test.ts @@ -0,0 +1,257 @@ +import { assert, assertEquals } from "@std/assert"; +import { + agreementRequestFactory, + chargeRequestFactory, +} from "../src/apis/recurring.ts"; + +Deno.test("create - should return the correct RequestData object", () => { + const token = "your-auth-token"; + const agreementId = "your-agreement-id"; + + const requestData = chargeRequestFactory.create(token, agreementId, { + amount: 1000, + transactionType: "DIRECT_CAPTURE", + type: "RECURRING", + description: "Test charge", + due: "2030-12-31", + retryDays: 5, + externalId: "test-charge-123", + orderId: "test-order-123", + }); + + assert(requestData.url, `/recurring/v3/agreements/${agreementId}/charges`); + assert(requestData.method, "POST"); +}); + +Deno.test("create multiple - should return the correct RequestData object", () => { + const token = "your-auth-token"; + + const requestData = chargeRequestFactory.createMultiple(token, [{ + amount: 1000, + transactionType: "DIRECT_CAPTURE", + agreementId: "your-agreement-id", + description: "Test charge", + due: "2030-12-31", + retryDays: 5, + externalId: "test-charge-123", + orderId: "test-order-123", + }]); + + assert(requestData.url, `/recurring/v3/agreements/charges`); + assert(requestData.method, "POST"); +}); + +Deno.test("info - should return the correct RequestData object", () => { + const token = "your-auth-token"; + const agreementId = "your-agreement-id"; + const chargeId = "your-charge-id"; + + const requestData = chargeRequestFactory.info(token, agreementId, chargeId); + + assert( + requestData.url, + `/recurring/v3/agreements/${agreementId}/charges/${chargeId}`, + ); + assert(requestData.method, "GET"); +}); + +Deno.test("infoById should return the correct RequestData object", () => { + const token = "your-access-token"; + const chargeId = "your-charge-id"; + + const requestData = chargeRequestFactory.infoById(token, chargeId); + + assert(requestData.url, "/recurring/v3/agreements/charges/your-charge-id"); + assert(requestData.method, "GET"); +}); + +Deno.test("list should return the correct RequestData object", () => { + const token = "your-access-token"; + const agreementId = "your-agreement-id"; + const status = "CHARGED"; + + const requestData = chargeRequestFactory.list(token, agreementId, status); + + assert( + requestData.url, + "/recurring/v3/agreements/your-agreement-id/charges?status=CHARGED", + ); + assert(requestData.method, "GET"); +}); + +Deno.test("list should return the correct RequestData object without search query", () => { + const token = "your-access-token"; + const agreementId = "your-agreement-id"; + + const requestData = chargeRequestFactory.list(token, agreementId); + + assert( + requestData.url, + "/recurring/v3/agreements/your-agreement-id/charges", + ); +}); + +Deno.test("cancel should return the correct RequestData object", () => { + const token = "your-access-token"; + const agreementId = "your-agreement-id"; + const chargeId = "your-charge-id"; + + const requestData = chargeRequestFactory.cancel(token, agreementId, chargeId); + + assert( + requestData.url, + "/recurring/v3/agreements/your-agreement-id/charges/your-charge-id", + ); + assert(requestData.method, "DELETE"); +}); + +Deno.test("capture should return the correct RequestData object", () => { + const token = "your-access-token"; + const agreementId = "your-agreement-id"; + const chargeId = "your-charge-id"; + const body = { amount: 1000, description: "Test charge" }; + + const requestData = chargeRequestFactory.capture( + token, + agreementId, + chargeId, + body, + ); + + assert( + requestData.url, + "/recurring/v3/agreements/your-agreement-id/charges/your-charge-id/capture", + ); + assert(requestData.method, "POST"); +}); + +Deno.test("refund should return the correct RequestData object", () => { + const token = "your-access-token"; + const agreementId = "your-agreement-id"; + const chargeId = "your-charge-id"; + const body = { amount: 1000, description: "Test charge" }; + + const requestData = chargeRequestFactory.refund( + token, + agreementId, + chargeId, + body, + ); + + assert( + requestData.url, + "/recurring/v3/agreements/your-agreement-id/charges/your-charge-id/refund", + ); + assert(requestData.method, "POST"); +}); + +Deno.test("agreements - create - check correct url in TEST/MT", () => { + const expected = { + url: "/recurring/v3/agreements", + method: "POST", + body: { + pricing: { type: "LEGACY", amount: 2500, currency: "NOK" }, + interval: { unit: "MONTH", count: 1 }, + merchantRedirectUrl: "https://example.com/redirect", + merchantAgreementUrl: "https://example.com/agreement", + phoneNumber: "4712345678", + productName: "MyNews Digital", + }, + token: "testtoken", + }; + + const actual = agreementRequestFactory.create("testtoken", { + pricing: { + type: "LEGACY", + amount: 2500, + currency: "NOK", + }, + interval: { + unit: "MONTH", + count: 1, + }, + merchantRedirectUrl: "https://example.com/redirect", + merchantAgreementUrl: "https://example.com/agreement", + phoneNumber: "4712345678", + productName: "MyNews Digital", + }) as unknown; + + assertEquals(actual, expected); +}); + +Deno.test("list - should return the correct RequestData object", () => { + const token = "your-auth-token"; + const status = "ACTIVE"; + const createdAfter = 1628764800; + + const expected = { + url: "/recurring/v3/agreements?status=ACTIVE&createdAfter=1628764800", + method: "GET", + token: "your-auth-token", + }; + + const actual = agreementRequestFactory.list( + token, + status, + createdAfter, + ) as unknown; + + assertEquals(actual, expected); +}); + +Deno.test("info - should return the correct RequestData object", () => { + const token = "your-auth-token"; + const agreementId = "your-agreement-id"; + + const expected = { + url: "/recurring/v3/agreements/your-agreement-id", + method: "GET", + token: "your-auth-token", + }; + + const actual = agreementRequestFactory.info(token, agreementId) as unknown; + + assertEquals(actual, expected); +}); + +Deno.test("update - should return the correct RequestData object", () => { + const token = "your-auth-token"; + const agreementId = "your-agreement-id"; + const body = { pricing: { amount: 1000, suggestedMaxAmount: 10000 } }; + + const expected = { + url: "/recurring/v3/agreements/your-agreement-id", + method: "PATCH", + body: { pricing: { amount: 1000, suggestedMaxAmount: 10000 } }, + token: "your-auth-token", + }; + + const actual = agreementRequestFactory.update( + token, + agreementId, + body, + ) as unknown; + + assertEquals(actual, expected); +}); + +Deno.test("forceAccept - should return the correct RequestData object", () => { + const token = "your-auth-token"; + const agreementId = "your-agreement-id"; + const body = { phoneNumber: "4791234567" }; + + const actual = agreementRequestFactory.forceAccept( + token, + agreementId, + body, + ) as unknown; + + const expected = { + url: "/recurring/v3/agreements/your-agreement-id/accept", + method: "PATCH", + body: { phoneNumber: "4791234567" }, + token: "your-auth-token", + }; + + assertEquals(actual, expected); +}); diff --git a/tests/util_test.ts b/tests/util_test.ts new file mode 100644 index 0000000..c1ccd14 --- /dev/null +++ b/tests/util_test.ts @@ -0,0 +1,35 @@ +import { assertEquals } from "@std/assert"; +import { generatePathParams } from "../src/apis/util.ts"; + +Deno.test("generatePathParams - with various parameters", () => { + const params = { + status: "active", + createdAfter: 1627849200, + pageNumber: 1, + pageSize: 20, + isActive: true, + }; + const result = generatePathParams(params); + const expected = + "?status=active&createdAfter=1627849200&pageNumber=1&pageSize=20&isActive=true"; + assertEquals(result, expected); +}); + +Deno.test("generatePathParams - with empty parameters", () => { + const params = {}; + const result = generatePathParams(params); + const expected = ""; + assertEquals(result, expected); +}); + +Deno.test("generatePathParams - with undefined and null values", () => { + const params = { + status: "active", + createdAfter: null, + pageNumber: undefined, + pageSize: 20, + }; + const result = generatePathParams(params); + const expected = "?status=active&pageSize=20"; + assertEquals(result, expected); +}); From fbf169f5e5701463f298e90e933c3d1e7b379e31 Mon Sep 17 00:00:00 2001 From: Tomas Zijdemans Date: Fri, 4 Oct 2024 21:56:31 +0200 Subject: [PATCH 2/2] fmt --- src/api_proxy.ts | 2 +- tests/mod_test.ts | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/api_proxy.ts b/src/api_proxy.ts index 33dc561..63d1058 100644 --- a/src/api_proxy.ts +++ b/src/api_proxy.ts @@ -13,10 +13,10 @@ export type SDKClient = { checkout: ReturnType>; payment: ReturnType>; recurring: { - charge: ReturnType>; agreement: ReturnType< typeof proxifyFactory >; + charge: ReturnType>; }; webhook: ReturnType>; }; diff --git a/tests/mod_test.ts b/tests/mod_test.ts index b766bb1..05ba7bd 100644 --- a/tests/mod_test.ts +++ b/tests/mod_test.ts @@ -14,19 +14,19 @@ Deno.test("Client - available functions", () => { assertEquals(typeof client.payment.refund, "function"); assertEquals(typeof client.payment.forceApprove, "function"); assertEquals(typeof client.payment.history, "function"); - assertEquals(typeof client.recurring.agreement.create, "function") - assertEquals(typeof client.recurring.agreement.forceAccept, "function") - assertEquals(typeof client.recurring.agreement.info, "function") - assertEquals(typeof client.recurring.agreement.list, "function") - assertEquals(typeof client.recurring.agreement.update, "function") - assertEquals(typeof client.recurring.charge.create, "function") - assertEquals(typeof client.recurring.charge.cancel, "function") - assertEquals(typeof client.recurring.charge.capture, "function") - assertEquals(typeof client.recurring.charge.createMultiple, "function") - assertEquals(typeof client.recurring.charge.info, "function") - assertEquals(typeof client.recurring.charge.infoById, "function") - assertEquals(typeof client.recurring.charge.list, "function") - assertEquals(typeof client.recurring.charge.refund, "function") + assertEquals(typeof client.recurring.agreement.create, "function"); + assertEquals(typeof client.recurring.agreement.forceAccept, "function"); + assertEquals(typeof client.recurring.agreement.info, "function"); + assertEquals(typeof client.recurring.agreement.list, "function"); + assertEquals(typeof client.recurring.agreement.update, "function"); + assertEquals(typeof client.recurring.charge.create, "function"); + assertEquals(typeof client.recurring.charge.cancel, "function"); + assertEquals(typeof client.recurring.charge.capture, "function"); + assertEquals(typeof client.recurring.charge.createMultiple, "function"); + assertEquals(typeof client.recurring.charge.info, "function"); + assertEquals(typeof client.recurring.charge.infoById, "function"); + assertEquals(typeof client.recurring.charge.list, "function"); + assertEquals(typeof client.recurring.charge.refund, "function"); assertEquals(typeof client.webhook.list, "function"); assertEquals(typeof client.webhook.register, "function"); assertEquals(typeof client.webhook.delete, "function");