A JavaScript SDK for integrating with Belong.net
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'
add to the bottom of your HTML file with the following content.
<script type="module">
import { createPaymentFrame } from 'https://esm.sh/@belongnet/sdk'
</script>
Use in your project:
createPaymentFrame({
el: document.getElementById('belong-payment-frame'),
params: {
target: 'event-ticket',
eventId: 'f9b2ea4c7be71407fcb6ed2c',
},
})
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)
}
Creates a payment frame for embedding payment forms.
Checks if the provided event is a Belong payment event.
-
Type:
string
-
Default:
"loaded"
-
Type:
string
-
Default:
"payment-canceled"
-
Type:
string
-
Default:
"payment-error"
-
Type:
string
-
Default:
"payment-success"
-
Type:
string
-
Default:
"event-ticket"
-
Type:
string
-
Default:
"hub-minting"
Validates the provided payment event data.
Validates the provided parameters.
This project is licensed under the terms of the MIT license.
🤖 auto updated with automd