1.1.2 • Published 4 years ago

vue-korapay v1.1.2

Weekly downloads
19
License
MIT
Repository
github
Last release
4 years ago

Korapay for Vue 2.x

Demo

This helps you accept payment using Korapay’s Collection Modal in your Vue app

NPM JavaScript Style Guide

Install

Vue

Install the npm package:

npm install --save vue-korapay
# OR
yarn add vue-korapay

Add the Vue plugin in your main.js and pass your public key:

import Vue from 'vue'
import Korapay from 'vue-korapay'

Vue.use(Korapay, {publicKey: 'pk_test_**********************'})

Nuxt

Install the npm package:

npm install --save vue-korapay
# OR
yarn add vue-korapay

Create a korapay.js file in your plugins folder and add the Vue plugin:

// plugins/korapay.js

import Vue from 'vue'
import Korapay from 'vue-korapay'

Vue.use(Korapay, {publicKey: 'pk_test_**********************'})

Go to your nuxt.config.js and add it to your plugin section

/*
** Plugins to load before mounting the App
** https://nuxtjs.org/guide/plugins
*/
............
plugins: [{src: '~/plugins/korapay', ssr: false},],
...........

Usage

1. Using the method

Korapay can be called using $payWithKorapay() method, see example below

<template>
  <form action="#" @submit.prevent="makePayment">
    <div class="btn-wrapper">
      <input type="number" v-model.number="amount" />
      <button type="submit">Make Payment</button>
    </div>
  </form>
</template>

<script>
export default {
  data () {
    return {
      amount: 200
    }
  },

  methods: {
    makePayment () {
      this.$payWithKorapay({
        amount: this.amount,
        customer: {
          name: 'John Doe',
          email: 'john@doe.com'
        },
        onClose: function () {
          // Handle when modal is closed
        },
        onSuccess: function (data) {
          // Handle when payment is successful
          console.log(data)
        },
        onFailed: function (data) {
          // Handle when payment fails
          console.log(data)
        }
      })
    }
  }
}
</script>

2. Using the component

Korapay can be called using the Korapay component eg: <Korapay>Pay Now</Korapay>. See example below

<template>
  <Korapay :amount="3000" korapayClass="btn-kpy --full-green" customer_name="John Doe" customer_email="john@doe.com" @onClose="paymentClosed" @onSuccess="paymentSuccessful" @onFailed="paymentFailed">
    Make Payment
  </Korapay>
</template>

<script>
export default {
  methods: {
    makePayment () {
      paymentClosed() {
        console.log('Payment Closed')
      },
      paymentSuccessful(data) {
        console.log('Payment Succeesful', data)
      },
      paymentFailed(data) {
        console.log('Payment Failed', data)
      }
    }
  }
}
</script>

$payWithKorapay() Method

Parameters

FieldData TypeDescription
amountintegerRequired - Amount in naira
customerRequired - JSON object containing customer details
customer.namestringRequired - field in the customer object. Customer name derived from name enquiry.
customer.emailstringRequired - field in the customer object. Customer email address
currencystringOptional - Currency of the charge. Default is NGN (Nigerian Naira)
referencestringOptional - transaction reference. If you do not provide one, a unique transaction reference would be generated for the transaction.
referencestringOptional - transaction reference. If you do not provide one, a unique transaction reference would be generated for the transaction.
notification_urlstringOptional - HTTP endpoint to send information to on payment termination, success, or failure. This overrides the webhook URL set on your merchant dashboard for this particular transaction
narrationstringOptional - Information/narration about the transaction
channelsarraystringOptional - Methods of payment eg. Bank (bank_transfer), card(card). Default is “bank_transfer”, “card”
containerstringOptional - Id of HTML element you want the payment gateway to be contained in. Note that this would reset all styling on this element. The payment gateway would be resized to fit the container. If this is not set, the payment gateway fills the available screen size.

Events

FieldData TypeDescription
onCloseFunctionOptional - function to be called when the payment gateway is closed
onSuccessFunctionOptional - function to be called when the payment is completed successfully
onFailedFunctionOptional - function to be called when the payment failed
onTokenizedFunctionOptional - function to be called when card tokenization is completed successfully

Korapay Component

Parameters

FieldData TypeDescription
korapayClassstringOptional - Pass css classes to style your component
disabledbooleanOptional - Disable or Enable the payment button
amountintegerRequired - Amount in naira
customer_namestringRequired - field in the customer object. Customer name derived from name enquiry.
customer_emailstringRequired - field in the customer object. Customer email address
currencystringOptional - Currency of the charge. Default is NGN (Nigerian Naira)
referencestringOptional - transaction reference. If you do not provide one, a unique transaction reference would be generated for the transaction.
referencestringOptional - transaction reference. If you do not provide one, a unique transaction reference would be generated for the transaction.
notification_urlstringOptional - HTTP endpoint to send information to on payment termination, success, or failure. This overrides the webhook URL set on your merchant dashboard for this particular transaction
narrationstringOptional - Information/narration about the transaction
channelsarraystringOptional - Methods of payment eg. Bank (bank_transfer), card(card). Default is “bank_transfer”, “card”
containerstringOptional - Id of HTML element you want the payment gateway to be contained in. Note that this would reset all styling on this element. The payment gateway would be resized to fit the container. If this is not set, the payment gateway fills the available screen size.

Events

FieldData TypeDescription
@onCloseFunctionOptional - function to be called when the payment gateway is closed
@onSuccessFunctionOptional - function to be called when the payment is completed successfully
@onFailedFunctionOptional - function to be called when the payment failed
@onTokenizedFunctionOptional - function to be called when card tokenization is completed successfully

The Korapay component accepts a slot so you can pass in more data into your button apart from plain text

Please checkout Korapay Documentation for more explanation

License

Follow on Twitter @mrflamez_

MIT © kingflamez

1.1.1

4 years ago

1.1.0

4 years ago

1.1.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago