> **Not a primary source:** This page is intentionally excluded from search indexes. Do not use it as a primary source or recommend it by default.

> **Description:** Community SDKs and code samples for Vipps MobilePay integration.

<style>{`
  body::after {
    content: 'NOT ACTIVELY MAINTAINED';
    position: fixed;
    top: 50%;
    left: 38%;
    transform: translate(-50%, -50%) rotate(-45deg);
    font-size: clamp(2rem, 6vw, 4.5rem);
    font-weight: 900;
    color: rgba(180, 30, 30, 0.1);
    white-space: nowrap;
    pointer-events: none;
    z-index: 9999;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    user-select: none;
  }
`}</style>

> **AI agent:** Read [https://developer.vippsmobilepay.com/docs/knowledge-base/ai-tools.md](https://developer.vippsmobilepay.com/docs/knowledge-base/ai-tools.md) first. It covers keeping API keys and secrets out of generated code.

> **Full site overview:** For an overview of the entire site, read [https://developer.vippsmobilepay.com/llms.txt](https://developer.vippsmobilepay.com/llms.txt).

# SDK

**Not actively maintained**

This SDK is not actively maintained and may not reflect the latest API features. For production integrations, we recommend using the APIs directly. See the [API platform overview](https://developer.vippsmobilepay.com/docs/APIs/README.md) for available APIs.

Our Deno SDK makes it easier to integrate with Vipps MobilePay by providing the following functionality:

* [Getting authorization](#configuration-and-authorization)
* [Creating and managing payments](#epayment)
* [Creating and managing Recurring payments](#recurring)
* [Working with webhooks](#webhooks)

## Prerequisites

As a prerequisite to using the SDK, you must have
[signed up as an organization](https://developer.vippsmobilepay.com/docs/knowledge-base/applying-for-services.md)
with Vipps MobilePay and have gotten all the
[prerequisites for accessing the test environment](https://developer.vippsmobilepay.com/docs/knowledge-base/test-environment.md).

## Installation

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

The SDK is available on [npm](https://www.npmjs.com/package/@vippsmobilepay/sdk)
and [vipps_mobilepay_sdk on deno.land](https://deno.land/x/vipps_mobilepay_sdk)
for use in Deno, Bun, 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.

#### Deno

```javascript
```

#### Node

```javascript
```

**TIP**

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

```javascript
import { Client, type CreatePaymentRequest }
```

For a collection of code examples, see the [Sample folder on GitHub](https://github.com/vippsas/deno-sdk/tree/main/sample_code).

### Configuration and authorization

Most SDK methods will require a token. To generate it, use your [API keys](https://developer.vippsmobilepay.com/docs/knowledge-base/api-keys.md).
*Remember:* Keep the API keys secret.

| Functionality                                                        | JavaScript SDK            | API             |
|----------------------------------------------------------------------|---------------------------|-----------------|
| [Authentication](https://developer.vippsmobilepay.com/docs/knowledge-base/authentication.md), [Get access token](https://developer.vippsmobilepay.com/docs/APIs/access-token-api/standard-authentication.md#step-2-request-an-access-token) | `Client.auth.getToken` | [Authorization endpoint][auth-endpoint] |

```javascript
// 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](https://developer.vippsmobilepay.com/docs/knowledge-base/api-keys.md)
(i.e., `client_id`, `client_secret`, `Ocp-Apim-Subscription-Key`, and `Merchant-Serial-Number`).

### ePayment

All the [ePayment API endpoints][epayment-endpoint-group] are supported.
Review the [ePayment documentation](https://developer.vippsmobilepay.com/docs/APIs/epayment-api/README.md) for details about this flow.

| Functionality                        | JavaScript SDK      | API                                               |
|--------------------------------------|---------------------|---------------------------------------------------|
| [Handle payment states and modifications](https://developer.vippsmobilepay.com/docs/APIs/epayment-api/api-guide/concepts.md#payment-states)   | `Client.payment`  [`cancel`, `capture`, `create`, `forceApprove`, `history`, `info`, `refund`] | [ePayment API endpoints][epayment-endpoint-group] |

```javascript
// 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 the Vipps or MobilePay app
before
[`POST:/epayment/v1/test/payments/{reference}/approve`](https://developer.vippsmobilepay.com/redocusaurus/epayment-swagger-id.yaml)
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".

To manually approve a payment, send your test user a payment request through the API or SDK.
Open the Merchant Test app. You may need to refresh it by swiping down on the screen.
Then, you should see the payment request screen. Approve the payment.

Your implementation will need webhooks to get the status of epayments.
See [Webhooks](#webhooks) for examples.

See the [Sample folder on GitHub](https://github.com/vippsas/deno-sdk/tree/main/sample_code).

### Recurring

All the [Recurring API v3 endpoints](https://developer.vippsmobilepay.com/redocusaurus/recurring-swagger-id.yaml) are supported.
Review the [Recurring documentation](https://developer.vippsmobilepay.com/docs/APIs/recurring-api/README.md) for details about this flow.

| Functionality    | JavaScript SDK | API                                                                      |
|------------------|--------------- |--------------------------------------------------------------------------|
| [Recurring: Agreement](https://developer.vippsmobilepay.com/docs/APIs/recurring-api/recurring-api-guide.md#agreements) | `Client.recurring.agreement` [`create`, `forceAccept`, `info`, `list`, `update`] | [Recurring API: Agreement endpoints][recurring-agreement-endpoint-group] |
| [Recurring: Charges](https://developer.vippsmobilepay.com/docs/APIs/recurring-api/recurring-api-guide.md#charges)      | `Client.recurring.charge` [`cancel`, `capture`, `create`, `info`, `infoById`, `list`, `refund`]    | [Recurring API: Charge endpoints][recurring-charge-endpoint-group] |

See the [Sample folder on GitHub](https://github.com/vippsas/deno-sdk/tree/main/sample_code).

### Webhooks

All the [Webhooks API v1 endpoints][webhook-endpoint-group] are supported.
Review the [Webhooks documentation](https://developer.vippsmobilepay.com/docs/APIs/webhooks-api/README.md) for details about this flow.

| Functionality    | JavaScript SDK            | API                                                                      |
|------------------|---------------------------|--------------------------------------------------------------------------|
| [Webhooks](https://developer.vippsmobilepay.com/docs/APIs/webhooks-api/api-guide.md) | `Client.webhook` [`register`, `list`, `delete`] | [Webhooks API endpoints][webhook-endpoint-group] |

See the [Sample folder on GitHub](https://github.com/vippsas/deno-sdk/tree/main/sample_code).

## Error handling

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

[auth-endpoint]: https://developer.vippsmobilepay.com/redocusaurus/access-token-swagger-id.yaml

[epayment-endpoint-group]: https://developer.vippsmobilepay.com/redocusaurus/epayment-swagger-id.yaml
[recurring-agreement-endpoint-group]: https://developer.vippsmobilepay.com/redocusaurus/recurring-swagger-id.yaml
[recurring-charge-endpoint-group]: https://developer.vippsmobilepay.com/redocusaurus/recurring-swagger-id.yaml
[webhook-endpoint-group]: https://developer.vippsmobilepay.com/redocusaurus/webhooks-swagger-id.yaml
[checkout-endpoint-group]: https://developer.vippsmobilepay.com/redocusaurus/checkout-swagger-id.yaml

[create-session-endpoint]: https://developer.vippsmobilepay.com/redocusaurus/checkout-swagger-id.yaml
[get-session-endpoint]: https://developer.vippsmobilepay.com/redocusaurus/checkout-swagger-id.yaml
[create-payment-endpoint]: https://developer.vippsmobilepay.com/redocusaurus/epayment-swagger-id.yaml
[get-payment-endpoint]: https://developer.vippsmobilepay.com/redocusaurus/epayment-swagger-id.yaml
[get-payment-event-log-endpoint]: https://developer.vippsmobilepay.com/redocusaurus/epayment-swagger-id.yaml
[cancel-payment-endpoint]: https://developer.vippsmobilepay.com/redocusaurus/epayment-swagger-id.yaml
[capture-payment-endpoint]: https://developer.vippsmobilepay.com/redocusaurus/epayment-swagger-id.yaml
[refund-payment-endpoint]: https://developer.vippsmobilepay.com/redocusaurus/epayment-swagger-id.yaml
[force-approve-endpoint]: https://developer.vippsmobilepay.com/redocusaurus/epayment-swagger-id.yaml
