Skip to main content

SDKs

Our SDKs make it easier to integrate with Vipps MobilePay by providing the following functionality:

FunctionalityJavaScript SDK.Net SDK
Getting authorization
Initiating Checkout sessions
Handling payments
Handling webhooks

Prerequisites

As a prerequisite to using an SDK, you must have signed up as an organization with Vipps MobilePay and have your test credentials from the merchant portal.

Installation

The following steps show how to start using the SDK in an empty project:

The SDK is available on npm and deno.land for use in Deno, Node, or other JavaScript runtimes.

note

If you are using Deno or Bun, all you need is a recent version installed.

If you are using Node:

  1. Make sure you have Node.js 20 or newer installed

  2. Initialize your project in a new directory (yarn init or npm init).

  3. Install the SDK into your project directory:

    npm i @vippsmobilepay/sdk or yarn add @vippsmobilepay/sdk

  4. Open your package.json file and add "type": "module".

Usage

The SDK is packaged as an ECMAScript Module (ESM). To import the SDK, add the following to your JavaScript or Typescript file.

import { Client } from "https://deno.land/x/vipps_mobilepay_sdk/mod.ts";
tip

If you are using Typescript and would like to import the types for the APIs, simply add them to your import statement:

import { Client, type CreatePaymentRequest }

For a collection of code examples, see the Sample folder on GitHub

Configuration and authorization

Most SDK methods will require a token. To generate it, use your API keys Remember: Keep the API keys secret.

FunctionalityJavaScript SDK.Net SDKAPI
Authentication,
Get access token
Client.auth.getTokenVipps.net.VippsApiAuthorization endpoint
// Create a client
const client = Client({
merchantSerialNumber,
subscriptionKey,
useTestMode: true,
retryRequests: false,
});

// Get a token
const accessToken = await client.auth.getToken(clientId, clientSecret);

To run against the test environment, set useTestMode to true (default false).

If you'd like the SDK to not retry failed requests, set retryRequests to false (default true).

Update the code samples to use your API Keys (i.e., client_id, client_secret, Ocp-Apim-Subscription-Key, and Merchant-Serial-Number).

Checkout

All Checkout API endpoints are supported. Review the Checkout documentation for details about this flow.

FunctionalityJavaScript SDKAPI
Create checkout session and get session infoClient.checkout
[create, info]
Checkout API endpoints
Checkout code sample:
// Create a checkout session
const checkout = await client.checkout.create(clientId, clientSecret, {
merchantInfo: {
callbackUrl: "https://example.com/callbackUrl",
returnUrl: "https://example.com/page-customer-returns-to-after-success-or-failure-or-cancel",
},
transaction: {
amount: {
currency: "NOK",
value: 1000, // This value equals NOK 10,-
},
paymentDescription: "One pair of socks.",
},
});

For checkout usage, the SDK is compatible with backend frameworks (such as Node, Deno, Remix, NextJS, Gatsby, and others). Do not use the SDK together with React, Vue, Svelte, Angular, or other frontend frameworks (except when SSR), as this could expose your API keys. Use the SDK for backend applications only. Always keep your client keys safe and hide them from the frontend application. See the Sample folder on GitHub.

ePayment

All the ePayment API endpoints are supported. Review the ePayment documentation for details about this flow.

FunctionalityJavaScript SDKAPI
Handle payment states and modificationsClient.payment
[cancel, capture, create, forceApprove, history, info, refund]
ePayment API endpoints
// Create a payment
const payment = await client.payment.create(token, {
amount: {
currency: "NOK",
value: 1000, // This value equals 10 NOK
},
paymentMethod: { type: "WALLET" },
customer: { phoneNumber: "4712345678" },
returnUrl: `https://yourwebsite.com/redirect`,
userFlow: "WEB_REDIRECT",
paymentDescription: "One pair of socks",
});
note

Important: All test users must manually approve at least one payment in Vipps or MobilePay app before POST:/epayment/v1/payments/{reference}/approve can be used for that user. If this has not been done, you will get an error. This is because the user needs to be registered as "BankID verified" in the backend, and this happens automatically in the test environment when using the Vipps or MobilePay app, but not with "force approve".

Your implementation will need webhooks to get the status of epayments. See Webhooks for examples.

See the Sample folder on GitHub.

Webhooks

All the Webhooks API v1 endpoints are supported. Review the Webhooks documentation for details about this flow.

FunctionalityJavaScript SDKAPI
WebhooksClient.webhook
[register, list, delete]
Webhooks API endpoints

See the Sample folder on GitHub.

Error handling

Errors, including network failures, misconfiguration, or temporarily unavailable services, may arise. Please try to handle all potential errors thrown by the SDK.

Getting involved

The SDKs are open-source and publicly available. Questions, bug reports, and pull requests are always welcome on GitHub.

Help me

If you aren't sure what to do, see the Getting started page.

Help us improve our documentation

Did you find what you were looking for?