Vue Paystack Component

2.0.4 · maintenance · verified Sun Apr 19

vue-paystack is a Vue 2.x component designed to integrate the Paystack payment gateway into web applications. It provides a `<paystack>` component that wraps the Paystack inline and popup payment experiences, allowing developers to configure payment details such as amount, email, and public key via props, and handle callbacks for success and closure events. The package is currently at version 2.0.4 and appears to have a sporadic release cadence, primarily focusing on maintaining compatibility with Vue 2.x. A key differentiator is its straightforward, declarative integration for Vue 2 projects, abstracting the direct Paystack API calls into a component-based structure. It is specifically designed for Vue 2 applications, with no explicit support for Vue 3.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to integrate the vue-paystack component into a Vue 2.x Single File Component, passing required props like amount, email, public key, and handling callback functions for payment success and closure.

<template>
    <paystack
        :amount="amount"
        :email="email"
        :paystackkey="paystackkey"
        :reference="reference"
        :callback="callback"
        :close="close"
        :embed="false"
    >
       <button>Make Payment</button>
    </paystack>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import paystack from 'vue-paystack';

export default defineComponent({
    components: {
        paystack
    },
    data() {
        return {
          paystackkey: process.env.VUE_APP_PAYSTACK_PUBLIC_KEY || 'pk_test_xxxxxxxxxxxxxxxxxxxxxxx', // Replace with your actual public key
          email: 'customer@example.com', // Customer email
          amount: 1000000, // Amount in kobo (10,000 NGN)
        };
    },
    computed: {
      reference(): string {
        // Generate a unique reference for each transaction
        return `PAY-${Date.now()}-${Math.floor(Math.random() * 1000000)}`;
      }
    },
    methods: {
      callback(response: any): void {
        console.log('Payment successful:', response);
        alert(`Payment successful! Reference: ${response.reference}`);
        // Verify payment on your backend using response.reference
      },
      close(): void {
          console.log('Payment window closed');
          alert('Payment was closed without completion.');
      }
    }
});
</script>

view raw JSON →