1.0.19 • Published 7 months ago

@bullring/payment-widget v1.0.19

Weekly downloads
-
License
ISC
Repository
-
Last release
7 months ago

@bullring/payment-widget

Lightning payment widget for web applications.

Getting Started

  1. Download Bullring app from App Store or Play Store
  2. Create account and verify identity
  3. Add bank account
  4. Copy merchant ID from app settings
  5. Install widget:

Installation

npm install @bullring/payment-widget

Or using yarn:

yarn add @bullring/payment-widget

Or using pnpm:

pnpm add @bullring/payment-widget

Basic Usage

Vanilla JavaScript/HTML

<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" href="https://unpkg.com/@bullring/payment-widget/dist/styles.css">
  <script type="module" src="https://unpkg.com/@bullring/payment-widget"></script>
</head>
<body>
  <bullring-payment-widget
    invoice-amount="100"
    merchant-id="your-merchant-id"
    merchant-name="Your Store"
  </bullring-payment-widget>

  <script>
    const widget = document.querySelector('bullring-payment-widget');
    
    widget.addEventListener('payment-success', (e) => {
      console.log('Payment successful:', e.detail);
    });

    widget.addEventListener('payment-error', (e) => {
      console.error('Payment failed:', e.detail);
    });

    widget.addEventListener('close', (e) => {
      console.log('Widget closed, transaction ID:', e.detail);
    });
  </script>
</body>
</html>

React

import "@bullring/payment-widget";

const PaymentComponent = () => {
  const handlePaymentSuccess = (data: any) => {
    console.log('Payment successful:', data);
  };

  const handlePaymentError = (error: Error) => {
    console.error('Payment failed:', error);
  };

  const handleClose = (txId: string) => {
    console.log('Widget closed:', txId);
  };

  return (
     <bullring-payment-widget
          invoice-amount={1000}
          merchant-id={"e6095fa1-4d03-4d6b-8fa8-e77009484a6e"}
          onpaymentSuccess={(txid) => console.log("Payment received:", txid)}
          onpaymentError={(txid) => console.log("Payment received:", txid)}
          onclose={() => {
            console.log("yey!");
            setCount(0);
          }}
        />
  );
};

Vue

<template>
  <bullring-payment-widget
    :invoice-amount="100"
    merchant-id="your-merchant-id"
    merchant-name="Your Store"
    @payment-success="handlePaymentSuccess"
    @payment-error="handlePaymentError"
    @close="handleClose"
  />
</template>

<script setup lang="ts">
import '@bullring/payment-widget';
import '@bullring/payment-widget/dist/styles.css';

const handlePaymentSuccess = (data: any) => {
  console.log('Payment successful:', data);
};

const handlePaymentError = (error: Error) => {
  console.error('Payment failed:', error);
};

const handleClose = (txId: string) => {
  console.log('Widget closed:', txId);
};
</script>

Angular

// app.module.ts
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule],
  schemas: [CUSTOM_ELEMENTS_SCHEMA], // Required for web components
  bootstrap: [AppComponent]
})
export class AppModule {}

// app.component.ts
import { Component, OnInit } from '@angular/core';
import '@bullring/payment-widget';
import '@bullring/payment-widget/dist/styles.css';

@Component({
  selector: 'app-root',
  template: `
    <bullring-payment-widget
      [invoice-amount]="100"
      [merchant-id]="merchantId"
      [merchant-name]="merchantName"
      (paymentSuccess)="onPaymentSuccess($event)"
      (paymentError)="onPaymentError($event)"
      (close)="onClose($event)">
    </bullring-payment-widget>
  `
})
export class AppComponent {
  merchantId = 'your-merchant-id';
  merchantName = 'Your Store';

  onPaymentSuccess(event: CustomEvent) {
    console.log('Payment successful:', event.detail);
  }

  onPaymentError(event: CustomEvent) {
    console.error('Payment failed:', event.detail);
  }

  onClose(event: CustomEvent) {
    console.log('Widget closed:', event.detail);
  }
}

Svelte

<script lang="ts">
  import '@bullring/payment-widget';
  import '@bullring/payment-widget/dist/styles.css';

  const handlePaymentSuccess = (event: CustomEvent) => {
    console.log('Payment successful:', event.detail);
  };

  const handlePaymentError = (event: CustomEvent) => {
    console.error('Payment failed:', event.detail);
  };

  const handleClose = (event: CustomEvent) => {
    console.log('Widget closed:', event.detail);
  };
</script>

<bullring-payment-widget
  invoice-amount={100}
  merchant-id="your-merchant-id"
  merchant-name="Your Store"
  on:payment-success={handlePaymentSuccess}
  on:payment-error={handlePaymentError}
  on:close={handleClose}
/>

API Reference

Props

PropTypeRequiredDescription
invoice-amountnumberYesPayment amount in the merchant's preferred currency
merchant-idstringYesYour Bullring merchant ID
merchant-namestringNoDisplay name for your store

Events

EventDetail TypeDescription
payment-successPaymentResponseFired when payment is successfully completed
payment-errorErrorFired when an error occurs during payment
closestringFired when the widget is closed (includes transaction ID)

PaymentResponse Type

interface PaymentResponse {
  lightningInvoice: string;
  id: string;
  paymentHash: string | null;
  paymentRequestAmount: number;
  paymentRequestCurrency: string;
  invoiceCurrency: string;
  invoiceAmount: number;
  status: 'unpaid' | 'paid' | 'expired';
  note: string;
  createdAt: string;
  updatedAt: string;
}

Styling

The widget comes with default styles, but you can customize its appearance using CSS variables:

:root {
  /* Add your custom styles here */
}

Browser Support

The widget works in all modern browsers that support Web Components:

  • Chrome/Edge (latest)
  • Firefox (latest)
  • Safari (latest)

Internationalization

Currently supports:

  • English
  • Portuguese

Language detected automatically from browser settings.

Contact

Website: https://bullring.finance

Email: developer@bullring.finance

License

MIT

Support

For support, please contact developer@bullring.finance

1.0.19

7 months ago

1.0.18

7 months ago

1.0.17

7 months ago

1.0.16

7 months ago

1.0.15

7 months ago

1.0.14

7 months ago

1.0.13

9 months ago

1.0.12

9 months ago

1.0.11

9 months ago

1.0.10

9 months ago

1.0.8

9 months ago

1.0.6

9 months ago

1.0.5

9 months ago

1.0.4

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago