Longswipe Developer Documentation

website·Indexed 31 days ago

https://developer.longswipe.com

Documentation for integrating the Longswipe payment voucher system and digital gifting platform. Includes a REST API for managing customers, invoices, and voucher redemption, as well as official SDKs for React, Flutter, Node.js, Golang, and PHP.

Tokens
11.3K
Snippets
67
Records
89
Agent score
53%

What's inside Longswipe

  1. Understand the Longswipe Invoice Workflow

    The Longswipe platform allows users to create invoices on behalf of merchants. To prevent fraudulent or unauthorized billing, invoices must follow a specific lifecycle:

    1. A user creates and submits an invoice to a merchant.
    2. The merchant reviews the invoice and can either Approve it (making it payable) or Reject it (preventing payment).
    3. Only approved invoices can be paid and processed. Approval can be performed via the merchant dashboard or the API.
  2. Understand Longswipe Flutter SDK implementation

    The Longswipe Flutter SDK functions by embedding a WebView using flutter_inappwebview to load the Longswipe JavaScript widget. It utilizes JavaScript channels for communication between the Flutter layer and the web-based payment process. The permission_handler package is used to manage the necessary hardware permissions.
  3. Fetch voucher details using Longswipe PHP SDK

    Use the fetchVoucherDetails method to retrieve information about a voucher. You must provide a parameters array containing voucherCode, amount, and receivingCurrencyId. lockPin and walletAddress are optional.
    try {
        $params = [
            'voucherCode' => 'VOUCHER123',
            'amount' => 1000,
            'receivingCurrencyId' => '2eedd32', // Replace with actual receiving currency ID
            'lockPin' => '1234', // Optional
            'walletAddress' => '0x123...' // Optional
        ];
    
        $voucherDetails = $client->fetchVoucherDetails($params);
    
        if ($voucherDetails['status'] === 'success') {
            $charges = $voucherDetails['data']['charges'];
            $voucher = $voucherDetails['data']['voucher'];
        }
    } catch (LongswipeException $e) {
        echo "Error: " . $e->getMessage();
    }
  4. Implement Longswipe for Decentralized Applications (DAPPS)

    Use Longswipe in DAPPS to enable real-time on-chain payments and checkouts. This improves user trust by allowing users to send value without the mandatory requirement of connecting their wallets.
  5. Integrate Longswipe using the Flutter SDK

    The Longswipe Flutter SDK allows merchants to implement a checkout flow that accepts vouchers as payment using crypto stable assets (e.g., USDT, USDC) across multiple blockchain networks. Key capabilities include programmatic voucher redemption, ready-to-use UI components for payment forms, and voucher verification.
  6. Create a Longswipe Webhook

    To set up a webhook for event-driven communication, you must have an active account with administrator privileges and a publicly accessible HTTPS endpoint.

    1. Log in to the Dashboard:
    2. Navigate to the App Sidebar in your application list and select the specific App.
    3. Click the Add Webhook URL button.
    4. Enter your HTTPS endpoint URL and save.
    5. Use the Test button next to the URL to verify the connection.
  7. Install Longswipe PHP SDK

    The Longswipe PHP plugin allows applications to validate and process payment vouchers. It requires PHP 7.4 or higher, as well as the curl and json extensions.
    composer require longswipe/longswipe-payment
  8. Configure accepted invoice currencies

    Merchants must explicitly add currencies to their account before users can select them when creating invoices. To configure these in the dashboard:

    1. Navigate to Invoices in the sidebar.
    2. Click the Add Accepted Currency button in the top-right corner.
    3. Select the desired currency from the modal.
    4. Click Set Currency to confirm.
  9. Verify Longswipe Webhook Signatures

    To ensure requests are authentically sent by Longswipe, validate the x-longswipe-signature header using the webhook secret key found in your dashboard. Longswipe uses sha512 encryption for these signatures. Use a timing-safe comparison to prevent timing attacks.
    const crypto = require('crypto');
    
    function verifyWebhookSignature(payload, signature, secret) {
      const hmac = crypto.createHmac('sha512', secret);
      const calculatedSignature = hmac.update(payload).digest('hex');
      return crypto.timingSafeEqual(
        Buffer.from(calculatedSignature, 'hex'),
        Buffer.from(signature, 'hex')
      );
    }
  10. Integrate Longswipe using the React SDK

    The Longswipe React SDK provides tools for integrating voucher redemption and payment flows into React applications. It includes a pre-built VoucherRedemption component, custom hooks for building bespoke UIs, a comprehensive API client, and native TypeScript support.