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

@koomipay/vue2

v1.3.0

Published

Koomipay vue2 components

Downloads

48

Readme

@koomipay/vue

Vue components for Koomipay B2B payment service

Getting started

How to use

First, install @koomipay/vue2 using the following command.

npm install @koomipay/vue2 --save

CSS

Import koomipay.css file to your Vue project to properly display the checkout component

The file is located at

@koomipay/vue2/dist/koomipay.css

Create Koomipay Client

To create a new Koomipay client, use the createClient() method from the package, and pass in the Checkout API Key getting from Koomipay Portal

import { createClient } from "@koomipay/vue2"

const config = useRuntimeConfig()
const koomipayClient = createClient({ apiKey: config.public.apiKey })

Get available Payment Methods

Then get all the available payment methods for your Merchant Account by calling the getPaymentMethods() method

const result = await koomipayClient.getPaymentMethods({
  amount: { currency: "SGD", price: 100 },
  countryCode: "SG",
})

Checkout

Depending on your scenario, you can use either checkout() method (normal checkout without capturing) or instantCheckout(), which will trigger a capturing immediately after checkout

const response = await koomipayClient.instantCheckout({
  orderID: "Order #01",
  paymentMethod: paymentData,
  amount: {
    currency: "SGD",
    price: 100,
  },
  items: [
    {
      productID: "product_01",
      productName: "Product 01",
      quantity: 1,
      price: 100,
    },
  ],
  returnUrl: document.location.origin + "/api/checkout/callback",
})

Remember to check the response for 3Ds redirect url

if (response?.data?.success) {
  const { data } = response.data
  if (data.resultCode === "Authorised") {
    window.location.href = "/checkout/success"
  } else if (data.resultCode === "RedirectShopper") {
    window.open(data.redirect3ds)
  }
}

Full example

Before you setup the checkout page, you should get api key from Koomipay

<script>
import { CheckoutContainer, createClient } from "@koomipay/vue2"

export default {
  name: "Checkout",
  data() {
    const koomipayClient = createClient({ apiKey: #YOUR_API_KEY })

    return {
      valid: false
      paymentData: {}
      paymentMethods: []
      selectedPaymentMethod: null
    }
  },
  async mounted() {
    const result = await koomipayClient.getPaymentMethods({
      amount: { currency: "SGD", price: 100 },
      countryCode: "SG",
    })
    if (result && result.length) {
      this.paymentMethods= [...result]
      this.selectedPaymentMethod= result[0]
    }
  },
  methods: {
    async handleSubmit() {
      try {
        const response = await koomipayClient.instantCheckout({
          orderID: "Order #01",
          paymentMethod: this.paymentData,
          amount: {
            currency: "SGD",
            price: 100,
          },
          items: [{
            productID: 'product_01',
            productName: 'Product 01',
            quantity: 1,
            price: 100,
          }],
          returnUrl: document.location.origin + "/api/checkout/callback",
        })
    
        if (response && response.data && response.data.success) {
          const { data } = response.data
          if (data.resultCode === "Authorised") {
            window.location.href = "/checkout/success"
          } else if (data.resultCode === "RedirectShopper") {
            window.open(data.redirect3ds)
          }
        }
      } catch (error) {
        console.log(error)
      }
    },
    
    handleChangeValidity(newValid) {
      this.valid= newValid
    },
    
    handleChange(newData) {
      this.paymentData = newData
    }
  }
}
</script>
<template>
  <form>
    <div v-for="method in paymentMethods">
      <input type="radio" name="method" @click="() => (selectedPaymentMethod = method)" />
      <span>
        {{ method.name }}
      </span>
    </div>
    <CheckoutContainer
      v-if="!!selectedPaymentMethod"
      :client="koomipayClient"
      :amount="{ currency: 'SGD', price: 100 }"
      :paymentMethod="selectedPaymentMethod"
      @onValid="handleChangeValidity"
      @onChange="handleChange"
    />
    <button @click="handleSubmit" :disabled="!valid" />
  </form>
</template>

TypeScript support

Vue Koomipay is packaged with TypeScript declarations. Some types are pulled from @koomipay/vue2 — be sure to add @koomipay/vue2 as a dependency to your project for full TypeScript support.