Skip to main content

Overview

The PseClient provides utilities for PSE (Pagos Seguros en Línea) payments, including:
  • Listing available Colombian banks for PSE
  • Creating PSE swap orders with automatic payment execution
Access it via bloque.swap.pse.

Constructor

The PseClient is automatically initialized as part of the SwapClient.
import { Bloque } from '@bloque/sdk';

const bloque = new Bloque({ apiKey: 'your-api-key' });
const pseClient = bloque.swap.pse;

Methods

banks()

Retrieves the list of financial institutions available for PSE payments.
async banks(): Promise<ListBanksResult>

Returns

ListBanksResult
object

Example

const result = await bloque.swap.pse.banks();

for (const bank of result.banks) {
  console.log(`${bank.code}: ${bank.name}`);
}

// Output:
// 1: Banco de Bogotá
// 2: Banco Popular
// 3: Bancolombia
// ...

create()

Creates a PSE swap order with optional automatic payment execution.
async create(params: CreatePseOrderParams): Promise<CreatePseOrderResult>

Parameters

params
CreatePseOrderParams
required
PSE order parameters

Returns

CreatePseOrderResult
object

Example

// Step 1: Find available rates
const rates = await bloque.swap.findRates({
  fromAsset: 'COP/2',
  toAsset: 'DUSD/6',
  fromMediums: ['pse'],
  toMediums: ['kusama'],
  amountSrc: '10000000' // 100,000.00 COP
});

// Step 2: Get available banks
const { banks } = await bloque.swap.pse.banks();
const bancolombia = banks.find(b => b.name.includes('Bancolombia'));

// Step 3: Create order with auto-execution
const result = await bloque.swap.pse.create({
  rateSig: rates.rates[0].sig,
  toMedium: 'kusama',
  amountSrc: '10000000',
  depositInformation: {
    urn: 'did:bloque:account:card:usr-xxx:crd-xxx'
  },
  args: {
    bankCode: bancolombia.code,
    userType: 0, // Natural person
    customerEmail: '[email protected]',
    userLegalIdType: 'CC',
    userLegalId: '1234567890',
    customerData: {
      fullName: 'Juan Pérez',
      phoneNumber: '+573001234567'
    }
  }
});

// Step 4: Redirect user to PSE checkout
if (result.execution?.result.how?.url) {
  window.location.href = result.execution.result.how.url;
}

console.log('Order ID:', result.order.id);
console.log('Status:', result.order.status);

PSE Payment Flow

The PSE payment flow involves the following steps:
  1. Find rates: Use swap.findRates() to get available exchange rates
  2. List banks: Use pse.banks() to get available banks
  3. Create order: Use pse.create() with payment args to create and auto-execute the order
  4. Redirect: Redirect the user to the PSE checkout URL returned in execution.result.how.url
  5. Complete payment: User completes payment on the PSE platform
  6. Callback: PSE notifies Bloque of payment completion via webhook
  7. Funds deposited: Funds are deposited to the specified account URN

Fee Structure for PSE

PSE orders include multiple fee components:
const rate = rates.rates[0];

// Example fee breakdown:
for (const component of rate.fee.components) {
  switch (component.name) {
    case 'pse_fee':
      console.log('PSE transaction fee:', component.amount);
      break;
    case 'take_rate':
      console.log('Platform fee:', component.percentage, '%');
      break;
    case 'exchange_rate':
      console.log('Exchange rate:', component.pair);
      break;
  }
}

console.log('Total fee:', rate.fee.value);
console.log('Formula:', rate.fee.formula);

Webhook Notifications

You can specify a webhookUrl to receive order status updates:
const result = await bloque.swap.pse.create({
  rateSig: rates.rates[0].sig,
  toMedium: 'kusama',
  amountSrc: '10000000',
  webhookUrl: 'https://your-app.com/webhooks/pse',
  // ... other params
});
Webhook payload will include:
  • Order ID
  • Status updates
  • Transaction details

Error Handling

import { BloqueConfigError, BloqueValidationError } from '@bloque/sdk-core';

try {
  const result = await bloque.swap.pse.create(params);
} catch (error) {
  if (error instanceof BloqueConfigError) {
    console.error('Not connected to a session');
  } else if (error instanceof BloqueValidationError) {
    console.error('Invalid parameters:', error.message);
  } else {
    console.error('Unexpected error:', error);
  }
}
  • Bank - PSE bank details
  • ListBanksResult - Result of listing banks
  • CreatePseOrderParams - Parameters for creating PSE orders
  • CreatePseOrderResult - Result of creating PSE order
  • PsePaymentArgs - PSE payment arguments
  • PseCustomerData - Customer data for PSE
  • DepositInformation - Deposit account details
  • SwapOrder - Swap order details
  • ExecutionResult - Auto-execution result

Build docs developers (and LLMs) love