Verxio Protocol

Redeem Voucher

Redeem a voucher for its value. This function performs comprehensive validation (merchant ID, expiry, usage limits, conditions) and executes the redemption with complete history tracking. Each redemption is recorded with timestamp, value, and transaction details.

import { redeemVoucher } from '@verxioprotocol/core'
import { publicKey, generateSigner } from '@metaplex-foundation/umi'

const result = await redeemVoucher(context, {
  voucherAddress: publicKey('VOUCHER_ADDRESS'),
  merchantId: 'coffee_brew_merchant_001', // String identifier for the merchant
  updateAuthority: generateSigner(context.umi), // Authority that can update the voucher
  redemptionAmount: 100, // Purchase amount for percentage-based vouchers
  redemptionDetails: {
    transactionId: 'tx_123',
    items: ['Coffee', 'Pastry'],
    totalAmount: 100,
    discountApplied: 25,
  },
})

Return Value

{
  instruction: TransactionBuilder, // Transaction instruction for execution
  validation: {
    errors: string[], // Validation errors if any
    voucher: VoucherData // Voucher data after validation
  },
  redemptionValue: number, // Calculated redemption value
  updatedVoucher: VoucherData // Voucher data after redemption
}

Key Features

  • Merchant Validation: Ensures vouchers can only be redeemed by the correct merchant
  • Comprehensive Validation: Checks expiry, usage limits, and conditions
  • Redemption History: Records each redemption with timestamp, value, and transaction details
  • Value Calculation: Automatically calculates redemption value based on voucher type and purchase amount

Redemption History

Each redemption is automatically recorded in the voucher's history, providing a complete audit trail of all transactions. This includes transaction IDs, items purchased, total amounts, and discounts applied.