Skip to main content

Integration Flow

Detailed provider-specific integration flows, all operations, and advanced features of the Payment SDK.


US Integration Flow (Stripe + Bridge)

Complete flow for US-based platforms with USD payments and optional USDC conversion.

US Flow - Complete Sequence

Phase 1: Authentication & Customer Setup

import { 
createOakClient,
createCustomerService,
createProviderService
} from '@oaknetwork/payments-sdk';

const client = createOakClient({
environment: 'sandbox',
clientId: process.env.CLIENT_ID!,
clientSecret: process.env.CLIENT_SECRET!,
});

const customers = createCustomerService(client);
const providers = createProviderService(client);

// Register campaign creator
const creator = await customers.create({
email: 'creator@example.com',
country_code: 'US',
});

// Register creator with Stripe as connected account
const stripeReg = await providers.submitRegistration(creator.value.data.customer_id, {
provider: 'stripe',
target_role: 'connected_account',
provider_data: {
account_type: 'custom',
transfers_requested: true,
card_payments_requested: true,
tax_reporting_us_1099_k_requested: true,
payouts_debit_negative_balances: true,
},
});

// Use client_secret to load Stripe Connect onboarding UI
const { client_secret, publishable_key } = stripeReg.value.data.provider_response;

// Register creator with Bridge for crypto
const bridgeReg = await providers.submitRegistration(creator.value.data.customer_id, {
provider: 'bridge',
target_role: 'customer',
provider_data: {
callback_url: 'https://yourplatform.com/kyc-complete',
},
});

// Redirect to Bridge KYC
const { kyc_url, tos_url } = bridgeReg.value.data.provider_response;

Phase 2: Payment Collection

import { createPaymentService } from '@oaknetwork/payments-sdk';

const payments = createPaymentService(client);

const payment = await payments.create({
provider: 'stripe',
source: {
amount: 10000, // $100.00 in cents
customer: { id: backerCustomerId },
currency: 'usd',
payment_method: { type: 'card' },
capture_method: 'automatic',
},
destination: {
currency: 'usd',
customer: { id: creatorCustomerId },
},
confirm: true,
metadata: {
campaign_id: 'campaign_12345',
reward_tier: 'early_bird',
},
});

if (payment.ok) {
// Use client_secret to load Stripe payment UI
const { client_secret } = payment.value.data.provider_response;
}

Phase 3: Virtual Account for Auto-Conversion

import { createPaymentMethodService } from '@oaknetwork/payments-sdk';

const paymentMethods = createPaymentMethodService(client);

// Create Bridge virtual account (receives USD, converts to USDC)
const virtualAccount = await paymentMethods.add(creatorCustomerId, {
type: 'virtual_account',
provider: 'bridge',
source_currency: 'usd',
destination_currency: 'usdc',
provider_data: {
chain: 'ethereum',
evm_address: creatorWalletAddress,
},
});

const { bank_account_number, bank_routing_number } =
virtualAccount.value.data.provider_response.source_deposit_instructions;

// Link virtual account to Stripe as external account
const stripeExternal = await paymentMethods.add(creatorCustomerId, {
type: 'bank',
provider: 'stripe',
bank_name: 'Bridge Virtual Bank',
bank_account_number,
bank_routing_number,
bank_account_type: 'CHECKING',
bank_account_name: 'Creator Business',
currency: 'usd',
bank_metadata: {
virtual_account_id: virtualAccount.value.data.id,
},
});

Phase 4: Off-Ramp (USDC to Bank)

// Add real bank account to Bridge
const realBank = await paymentMethods.add(creatorCustomerId, {
type: 'bank',
provider: 'bridge',
bank_name: 'Chase',
bank_account_number: '123456789',
bank_routing_number: '021000021',
bank_account_type: 'CHECKING',
bank_account_name: 'Creator Account',
currency: 'usd',
});

// Create liquidation address (auto-converts incoming USDC to USD and sends to bank)
const liquidationAddress = await paymentMethods.add(creatorCustomerId, {
type: 'liquidation_address',
provider: 'bridge',
provider_data: {
chain: 'polygon',
currency: 'usdc',
destination_payment_rail: 'ach',
destination_currency: 'usd',
destination_payment_method_id: realBank.value.data.id,
},
});

// Creator sends USDC to this address to automatically receive USD in their bank
const { evm_address } = liquidationAddress.value.data.provider_response;
console.log('Send USDC to:', evm_address);

Brazil Integration Flow (PagarMe + Bridge)

Complete flow for Brazil-based platforms with BRL payments and optional BRLA conversion.

Brazil Flow - Complete Sequence

Card Payment

const payment = await payments.create({
provider: 'pagar_me',
source: {
amount: 10000, // R$100.00 in centavos
customer: { id: backerCustomerId },
currency: 'brl',
payment_method: { type: 'card' },
capture_method: 'automatic',
},
destination: {
customer: { id: creatorCustomerId },
currency: 'brl',
},
confirm: true,
metadata: {
campaign_id: 'campanha_12345',
},
});

PIX Payment

const pixPayment = await payments.create({
provider: 'pagar_me',
source: {
amount: 10000,
customer: { id: backerCustomerId },
currency: 'brl',
payment_method: {
type: 'pix',
expiry_date: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(), // 24 hours from now
},
},
confirm: true,
});

if (pixPayment.ok) {
// Display QR code to backer
// Payment confirmed via webhook when backer pays
}

Transfer BRLA to Wallet

import { createTransferService } from '@oaknetwork/payments-sdk';

const transfers = createTransferService(client);

const transfer = await transfers.create({
provider: 'brla',
source: {
customer: { id: creatorCustomerId },
amount: 10000,
currency: 'brla',
},
destination: {
customer: { id: creatorCustomerId },
payment_method: {
type: 'customer_wallet',
chain: 'polygon',
evm_address: '0x1234567890abcdef...',
},
},
});

Sell BRLA for BRL (Off-Ramp)

import { createSellService, createPaymentMethodService } from '@oaknetwork/payments-sdk';

const paymentMethods = createPaymentMethodService(client);
const sell = createSellService(client);

// Add PIX as payment method
const pixMethod = await paymentMethods.add(creatorCustomerId, {
type: 'pix',
pix_string: '12345678901', // CPF, phone, email, or random key
});

// Sell crypto → fiat via PIX
const sellOrder = await sell.create({
provider: 'bridge',
source: {
customer: { id: creatorCustomerId },
currency: 'brla',
amount: 10000,
},
destination: {
customer: { id: creatorCustomerId },
currency: 'brl',
payment_method: {
type: 'pix',
id: pixMethod.value.data.id,
},
},
});

Buy (On-Ramp) Flow

Convert fiat currency to cryptocurrency.

Buy (On-Ramp) Flow

import { createBuyService } from '@oaknetwork/payments-sdk';

const buy = createBuyService(client);

const buyOrder = await buy.create({
provider: 'bridge',
source: {
currency: 'usd',
},
destination: {
currency: 'usdc',
customer: { id: creatorCustomerId },
payment_method: {
type: 'customer_wallet',
chain: 'polygon',
evm_address: '0x1234567890abcdef...',
},
},
});

if (buyOrder.ok) {
const { source_deposit_instructions } = buyOrder.value.data.provider_response;
// Display bank details and deposit_message to customer
// USDC arrives in wallet when complete
}

Subscriptions Flow

Recurring billing with automatic payment collection.

Subscriptions Lifecycle

import { createPlanService } from '@oaknetwork/payments-sdk';

const plans = createPlanService(client);

// 1. Create a plan (draft)
const plan = await plans.create({
name: 'Premium Monthly',
description: 'Full access to all features',
frequency: 30, // Billing frequency in days
price: 2999,
currency: 'BRL',
start_date: '2026-04-01',
is_auto_renewable: true,
allow_amount_override: false,
created_by: 'admin',
});

// 2. Publish the plan (makes it available for subscriptions)
await plans.publish(plan.value.data.hash_id);

// 3. List plans
const allPlans = await plans.list({ page_no: 1, per_page: 10 });

// 4. Get plan details
const planDetails = await plans.details(plan.value.data.hash_id);

// 5. Update a plan
await plans.update(plan.value.data.hash_id, {
name: 'Premium Monthly (Updated)',
price: 3499,
currency: 'BRL',
frequency: 30,
start_date: '2026-04-01',
is_auto_renewable: true,
allow_amount_override: false,
created_by: 'admin',
});

// 6. Delete a plan
await plans.delete(plan.value.data.hash_id);

Webhook Events Reference

Webhook Event Categories

CategoryEventWhen Triggered
Provider Registrationprovider_registration.awaiting_confirmationKYC/ToS link generated
provider_registration.approvedKYC completed successfully
provider_registration.rejectedKYC failed
Paymentpayment.awaiting_confirmationPayment intent created
payment.capturedPayment successful
payment.failedPayment failed
payment.disputedChargeback initiated
payment.refundedRefund issued
Subscriptionsubscription.activatedSubscription started
subscription.renewedAuto-renewal successful
subscription.cancelledSubscription ended

Status Reference

Provider Registration Statuses

StatusMeaningNext Steps
not_submittedData saved locallySubmit to provider
awaiting_confirmationAwaiting user actionUser completes KYC/ToS
processingProvider reviewingWait for decision
approvedRegistration successfulReady for payments
rejectedRegistration failedCheck rejection reason

Payment Statuses

StatusMeaningPossible Actions
createdPayment object createdConfirm or cancel
awaiting_confirmationAwaiting user actionUser completes payment
capturedFunds capturedRefund if needed
failedPayment failedRetry with different method
refundedFully refundedNo further action

API Reference

Service Functions

ServiceFunctionParametersDescription
CustomerServicecreate(data)email, country_codeCreate a new customer
get(id)customer_idRetrieve customer details
list()List all customers
ProviderServicesubmitRegistration(id, data)customer_id, provider, target_role, provider_dataRegister customer with payment provider
getRegistrationStatus(id)customer_idGet registration status
PaymentServicecreate(data)provider, source, destination, confirm, metadataCreate payment intent
confirm(id)payment_idConfirm a payment
cancel(id)payment_idCancel a payment
PaymentMethodServiceadd(id, data)customer_id, type, provider, provider-specific fieldsAdd payment method
list(id)customer_idList customer's payment methods
delete(id, methodId)customer_id, payment_method_idRemove payment method
TransferServicecreate(data)provider, source, destinationTransfer funds to bank/wallet
BuyServicecreate(data)provider, source, destinationConvert fiat to crypto (on-ramp)
SellServicecreate(data)provider, source, destinationConvert crypto to fiat (off-ramp)
RefundServicecreate(data)payment_id, amount, reasonRefund a captured payment
PlanServicecreate(data)name, description, frequency, price, currency, start_dateCreate subscription plan
publish(id)plan_idPublish a draft plan
details(id)plan_idGet plan details
list(params)page_no, per_pageList plans with pagination
update(id, data)plan_id, plan fieldsUpdate a plan
delete(id)plan_idDelete a plan
WebhookServiceregister(data)url, descriptionRegister webhook endpoint

Common Parameter Values

ParameterTypeExample Values
providerstringstripe, pagar_me, bridge, brla
target_rolestringconnected_account, customer
currencystringusd, brl, usdc, brla
payment_method.typestringcard, pix, bank, customer_wallet, virtual_account, liquidation_address
capture_methodstringautomatic, manual

Next Steps