@belongnet/sdk
TypeScript icon, indicating that this package has built-in type declarations

0.1.5 • Public • Published

@belongnet/sdk

A JavaScript SDK for integrating with Belong.net

Version

Installation

NPM:

You can install using npm, yarn, or pnpm:

pnpm add @belongnet/sdk

# or
npm install @belongnet/sdk

# or
yarn add @belongnet/sdk

and then import it in your project:

import { createPaymentFrame } from '@belongnet/sdk'

CDN:

add to the bottom of your HTML file with the following content.

<script type="module">
  import { createPaymentFrame } from 'https://esm.sh/@belongnet/sdk'
</script>

Usage:

Use in your project:

createPaymentFrame({
  el: document.getElementById('belong-payment-frame'),
  params: {
    target: 'event-ticket',
    eventId: 'f9b2ea4c7be71407fcb6ed2c',
  },
})

Advanced Usage

Event listeners:

You can listen to the events from the payment frame.

import { isPaymentEvent } from '@belongnet/sdk'

function handlePayment(e: MessageEvent) {
  if (isPaymentEvent(e)) {
    switch (e.data.type) {
      case 'payment-success':
        console.log('payment-success', e.data.payload.link)
        break
      case 'payment-error':
        console.log('payment-error', e.data.payload)
        break
    }
  }
}

// add event listener
window.addEventListener('message', handlePayment)

// don't forget to remove the event listener
function onUnmount() {
  window.removeEventListener('message', handlePayment)
}

API

createPaymentFrame(options)

Creates a payment frame for embedding payment forms.

isPaymentEvent(event)

Checks if the provided event is a Belong payment event.

PaymentEvent

Loaded

  • Type: string
  • Default: "loaded"

PaymentCanceled

  • Type: string
  • Default: "payment-canceled"

PaymentError

  • Type: string
  • Default: "payment-error"

PaymentSuccess

  • Type: string
  • Default: "payment-success"

PaymentTarget

EventTicket

  • Type: string
  • Default: "event-ticket"

HubMinting

  • Type: string
  • Default: "hub-minting"

validateEvent(data)

Validates the provided payment event data.

validateParams(params)

Validates the provided parameters.

License

This project is licensed under the terms of the MIT license.


🤖 auto updated with automd

Readme

Keywords

Package Sidebar

Install

npm i @belongnet/sdk

Weekly Downloads

39

Version

0.1.5

License

MIT

Unpacked Size

31.9 kB

Total Files

33

Last publish

Collaborators

  • reslear
  • belongfoundation