npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@gait-as/vipps

v1.1.3

Published

Vipps package

Downloads

25

Readme

Vipps node library

Non-official Vipps eCommerce NPM package to manage Vipps eCom API.

Installation

npm install @gait-as/vipps

Pre-requisites

  • Node.js 8.0 or higher
  • Vipps API-keys
  • Vipps test account
  • Vipps test app
  • Vipps test merchant

Environment variables

VIPPS_SYSTEM_NAME=your-system-name
VIPPS_API_URL=https://apitest.vipps.no or https://api.vipps.no for production
VIPPS_CLIENT_ID=vipps-client-id
VIPPS_CLIENT_SECRET=vipps-client-secret
VIPPS_SUBSCRIPTION_KEY=vipps-subscription-key
VIPPS_SUBSCRIPTION_KEY_SECONDARY=vipps-subscription-key-secondary

Basic usage

Initialize

const Vipps = require('@gait-as/vipps');
const vipps = new Vipps() // This initializes the Vipps object with the environment variables

// OR Create a new instance with your own config
const vipps = new Vipps()
vipps.config({
    clientId: process.env.VIPPS_CLIENT_ID,
    clientSecret: process.env.VIPPS_CLIENT_SECRET,
    subscriptionKey: process.env.VIPPS_SUBSCRIPTION_KEY,
    merchantSerialNumber: process.env.VIPPS_MERCHANT_SERIAL_NUMBER,
});

const token = await vipps.authenticate(); // This will return a token for the Vipps API and set it in the Vipps object
const api = vipps.api; // This will return the Vipps API object

api.get('/url')...

Set/get Merchant Serial Number

...

vipps.setMsn('your-merchant-serial-number');
const msn = vipps.getMsn();

eCom API

Create express payment

This will create an express payment and return the payment URL and order Id.

/**
 * Data required for creating an order
 */
const orderData: VippsExpressOrderProps = {
    merchantInfo: {
        "paymentType": "eComm Express Payment",
        "shippingDetailsPrefix": "DT-",
        "staticShippingDetails": [
            {
                "isDefault": "Y",
                "priority": 1,
                "shippingCost": 90,
                "shippingMethod": "Bil",
                "shippingMethodId": "shippingMethodId1"
            },
            {
                "isDefault": "N",
                "priority": 2,
                "shippingCost": 200,
                "shippingMethod": "Sykkel",
                "shippingMethodId": "shippingMethodId2"
            }
        ]
    },
    customerInfo: {
        mobileNumber: '44444444',
    },
    transaction: {
        amount: 100,
        orderId: Date.now().toString(),
        transactionText: 'Test',
        useExplicitCheckoutFlow: true,
    }
}

const testOrder = async () => {
    /**
     * Initialize Vipps instance and automatically authenticate
     * This will use the credentials from the environment variables,
     * or the ones provided in the constructor
     */
    const vipps = await VippsEcommerce.getInstance()
    
    
    /**
     * Set vipps options required for the order
     * This will NOT default to environment variables
     */
    vipps.setOptions({
        callbackPrefix: 'https://gait-as-packages.herokuapp.com/api/vipps',
        consentRemovalPrefix: 'https://gait-as-packages.herokuapp.com/api/vipps',
        fallback: 'https://gait.no',
        merchantSerialNumber: '229350',
    })
    
    
    /**
     * Create the order and get the response
     * This will return a promise
     * The response will contain the url to redirect the user to, and the order id
     */
    const order: VippsExpressOrderResponse = await vipps.expressOrder(orderData)
        .then((response ) => {
            return response;
        })
        .catch((error) => {
            return error;
        })
    
    console.log(order);
}

Capture payment

Used for capturing a payment after the user has been redirected back to the merchant.

const testCapture = async (orderToCapture: VippsEcommerceCaptureOrderProps) => {
    const vipps = await VippsEcommerce.getInstance('229350')

    const capture = await vipps.captureOrder(orderToCapture)
        .then((response) => {
            return response;
        })
        .catch((error) => {
            console.log(error);
        })

    console.log(capture)
}

testCapture({
	orderId: '1671541910915',
	transactionText: 'Test',
})

Get order status

Used for getting the status of an order.

/**
 * Get the order details from the order id
 * This will return a promise
 * The response will contain the order details
 * This is useful for checking the status of the order
 */
const testOrderStatus = async (orderId: string) => {
	const vipps = await VippsEcommerce.getInstance()

	const orderDetails = await vipps.getOrderDetails(orderId)
		.then((response) => {
			return response;
		})
		.catch((error) => {
			console.log(error);
		})

	console.log(orderDetails)
}

testOrderStatus('1671541910915')