BadKiko / plisio-android-sdk

Fork of Android SDK to accept crypto payments with Plisio

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Plisio Android SDK

JitPack

Plisio Android SDK provides a subset of the Plisio API to implement payments for White Label invoices and customizable prebuilt UI components.

This is fork of SDK where added creating invoice with internal api

Use Plisio API or one of the Plisio server libraries to create invoices and listen for callbacks on your server.

Installation

repositories {
    mavenCentral()
    maven("https://jitpack.io")
}

dependencies {
    // Plisio UI Compose - prebuilt UI made with Jetpack Compose
    implementation("com.github.BadKiko.plisio-android-sdk:ui-compose:0.0.9")
    // Plisio SDK - API only without a prebuilt UI
    implementation("com.github.BadKiko.plisio-android-sdk:sdk:0.0.9")
}

Using prebuilt UI

import net.plisio.sdk.ui.compose.*
@Composable
fun Example() {
    val paymentViewModel = plisioPaymentViewModel()
    val paymentStep by paymentViewModel.paymentStep.collectAsState()
    var isPaymentSheetVisible by rememberSaveable { mutableStateOf(false) }
    val context = LocalContext.current

    // Optional, use a regular Button instead if you want to customize it
    PlisioPaymentButton(
        // Used to show a status indicator inside of the button
        paymentStep = paymentStep,
        onClick = {
            // Load an new invoice
            paymentViewModel.newInvoice(
                                context,
                                "gffMLve_v5mAQ8wvOAdFHlTN1IQroWS_ZhGK3xX7cXjfouYAyYmxCC62DrPromlx",
                                "BTC",
                                "RUB",
                                "400",
                                "ETH,BTC,USDT_TRX,TRX",
                                "Buy",
                                UUID.randomUUID().toString(),
                                30
                            )
            // Show the payment sheet
            isPaymentSheetVisible = true
        }
    )

    // The sheet will fill all available space and show as a bottom sheet or a dialog depending on the screen size
    PlisioPaymentSheet(
        isVisible = isPaymentSheetVisible,
        setVisibility = { isPaymentSheetVisible = it },
        paymentStep = paymentStep
    )
}

The demo project shows how to use and customize the prebuilt UI.

See PlisioStyle, PlisioPaymentSheet and PlisioPaymentButton code/documentation for all available customization options.

SDK-only usage

Using PlisioPaymentViewModel to load an invoice and manage its state

In Compose

import net.plisio.sdk.ui.compose.*
@Composable
fun Example() {
    val paymentViewModel = plisioPaymentViewModel()
    val paymentStep by paymentViewModel.paymentStep.collectAsState()
    // Use paymentStep to make your UI
    Text("Payment step: $paymentStep")
}

In a regular Activity

import net.plisio.sdk.viewmodels.*
class ExampleActivity: ComponentActivity() {
    val paymentViewModel: PlisioPaymentViewModel by viewModels()
    
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        // Collect the paymentStep flow
        lifecycleScope.launch {
            repeatOnLifecycle(Lifecycle.State.STARTED) {
                paymentViewModel.paymentStep.collectLatest { paymentStep ->
                    // Update your UI here
                }
            }
        }
    }
    
    // Create an invoice on your server, get invoice id and viewKey from your server and pass them to loadInvoice()
    fun loadInvoice(id: PlisioInvoiceID, viewKey: String) {
        paymentViewModel.loadInvoice(id, viewKey)
    }
}

Using API directly

suspend fun PlisioClient.getInvoice(id: PlisioInvoiceID, viewKey: String): Result<PlisioInvoiceDetails>
suspend fun PlisioClient.setUserEmail(email: String, id: PlisioInvoiceID, viewKey: String): Result<PlisioInvoiceDetails>
suspend fun PlisioClient.setCurrency(currency: PlisioCryptoCurrencyID, id: PlisioInvoiceID, viewKey: String): Result<PlisioInvoiceDetails>

Configuration

PlisioClient options can be set at any time before loading an invoice. Example with an Application subclass:

import net.plisio.sdk.PlisioClient
class App: Application() {
    override fun onCreate() {
        super.onCreate()
        // Log Plisio errors, show more error details in the prebuilt UI
        PlisioClient.configure(
            enableLogging = true,
            showErrorDetails = true
        )
    }
}

About

Fork of Android SDK to accept crypto payments with Plisio

License:MIT License


Languages

Language:Kotlin 100.0%