Core Concepts

Orders & Order Types

Understanding the six order types and when to use each

Orders & Order Types

Orders are the core transaction entities in Koywe Payments. Each order type serves a specific purpose in your payment operations.

Order Types Overview

Koywe Payments supports six distinct order types:

TypePurposeOriginDestinationUse Case
PAYINAccept customer paymentsExternal (customer)Virtual balanceE-commerce checkout
PAYOUTPay providersVirtual balanceExternal (provider bank)Vendor payments
BALANCE_TRANSFERCurrency exchangeVirtual balance (currency A)Virtual balance (currency B)Convert COP to USD
ONRAMPBuy cryptoVirtual balance (fiat)Crypto walletBuy USDC with COP
OFFRAMPSell cryptoCrypto walletVirtual balance (fiat)Sell BTC for COP
PAYMENT_LINKPayment linkExternal (customer)Virtual balanceInvoice payment

Order Status Lifecycle

All orders follow a similar status progression:

Status Descriptions:

StatusDescriptionActions Available
PENDINGOrder created, waiting for paymentCancel, Check status
PROCESSINGPayment being processedCheck status
PAIDPayment confirmed, settlement in progressCheck status
COMPLETEDFunds delivered, order completeView details
FAILEDPayment or settlement failedRetry, Contact support
CANCELLEDOrder cancelledView details
EXPIREDPayment window expiredCreate new order

PAYIN - Accept Customer Payments

Accept payments from customers into your virtual balance.

When to Use

  • E-commerce checkout
  • Service payments
  • Subscription billing
  • Invoice payments
  • Donation collection

Flow Diagram

Required Fields

1{
2 "type": "PAYIN", // Order type
3 "originCurrencySymbol": "COP", // Fiat currency
4 "destinationCurrencySymbol": "COP", // Same as origin
5 "amountIn": 50000, // Amount to collect
6 "description": "Payment for Order #12345", // Customer-facing description
7 "paymentMethods": [ // At least one payment method
8 {
9 "method": "PSE", // Payment method code
10 "extra": "BANCOLOMBIA" // Additional data (e.g., bank)
11 }
12 ],
13 "successUrl": "https://yoursite.com/success", // Redirect after success
14 "failedUrl": "https://yoursite.com/failed" // Redirect after failure
15}

Optional Fields

1{
2 "contactId": "cnt_abc123", // Link to customer contact
3 "externalId": "order-12345", // Your internal reference
4 "metadata": { "orderId": "12345" }, // Custom data
5 "dueDate": "2025-11-14T23:59:59Z" // Payment deadline
6}

Example

Node.js
1async function createPayinOrder(token, orgId, merchantId) {
2 const response = await axios.post(
3 `https://api-sandbox.koywe.com/api/v1/organizations/${orgId}/merchants/${merchantId}/orders`,
4 {
5 type: 'PAYIN',
6 originCurrencySymbol: 'COP',
7 destinationCurrencySymbol: 'COP',
8 amountIn: 50000,
9 description: 'Payment for Order #12345',
10 externalId: `order-${Date.now()}`,
11 paymentMethods: [
12 {
13 method: 'PSE',
14 extra: 'BANCOLOMBIA'
15 }
16 ],
17 successUrl: 'https://yoursite.com/success',
18 failedUrl: 'https://yoursite.com/failed'
19 },
20 {
21 headers: {
22 'Authorization': `Bearer ${token}`,
23 'Content-Type': 'application/json'
24 }
25 }
26 );
27
28 return response.data;
29}
30
31const order = await createPayinOrder(token, orgId, merchantId);
32console.log('Payment URL:', order.paymentUrl);
33// Redirect customer to order.paymentUrl

Complete PAYIN Integration Guide โ†’


PAYOUT - Pay Providers

Send payments from your virtual balance to external bank accounts.

When to Use

  • Vendor payments
  • Contractor payouts
  • Refunds to customers
  • Affiliate commissions
  • Partner settlements

Flow Diagram

Required Fields

1{
2 "type": "PAYOUT", // Order type
3 "originCurrencySymbol": "COP", // Fiat currency
4 "destinationCurrencySymbol": "COP", // Same as origin
5 "amountIn": 100000, // Amount to send
6 "destinationAccountId": "ba_xyz789", // Provider's bank account ID
7 "description": "Payment for Invoice #456" // Internal description
8}

Optional Fields

1{
2 "contactId": "cnt_provider123", // Link to provider contact
3 "externalId": "invoice-456", // Your internal reference
4 "metadata": { "invoiceId": "456" } // Custom data
5}

Example

Node.js
1async function createPayoutOrder(token, orgId, merchantId, contactId, bankAccountId) {
2 // 1. Check balance first
3 const balances = await getMerchantBalances(token, orgId, merchantId);
4 const copBalance = balances.find(b => b.currencySymbol === 'COP');
5
6 if (copBalance.availableBalance < 100000) {
7 throw new Error('Insufficient balance');
8 }
9
10 // 2. Create payout order
11 const response = await axios.post(
12 `https://api-sandbox.koywe.com/api/v1/organizations/${orgId}/merchants/${merchantId}/orders`,
13 {
14 type: 'PAYOUT',
15 originCurrencySymbol: 'COP',
16 destinationCurrencySymbol: 'COP',
17 amountIn: 100000,
18 contactId: contactId,
19 destinationAccountId: bankAccountId,
20 description: 'Payment for Invoice #456',
21 externalId: `invoice-456-${Date.now()}`
22 },
23 {
24 headers: {
25 'Authorization': `Bearer ${token}`,
26 'Content-Type': 'application/json'
27 }
28 }
29 );
30
31 return response.data;
32}
33
34const payout = await createPayoutOrder(token, orgId, merchantId, 'cnt_provider', 'ba_xyz789');
35console.log('Payout created:', payout.id);

Important: Always check your virtual account balance before creating PAYOUT orders. The order will fail if you have insufficient funds.

Complete PAYOUT Integration Guide โ†’


BALANCE_TRANSFER - Currency Exchange

Transfer funds between different currency virtual accounts (instant currency exchange).

When to Use

  • Convert COP to USD for international payments
  • Rebalance currency holdings
  • Lock in exchange rates
  • Prepare funds for specific currency payouts

Flow Diagram

Required Fields

1{
2 "type": "BALANCE_TRANSFER", // Order type
3 "originCurrencySymbol": "COP", // Source currency
4 "destinationCurrencySymbol": "USD", // Target currency
5 "amountIn": 1000000 // Amount to convert (1M COP)
6}

Example

Node.js
1async function transferCurrency(token, orgId, merchantId) {
2 // 1. Get quote for exchange rate
3 const quote = await axios.post(
4 `https://api-sandbox.koywe.com/api/v1/organizations/${orgId}/merchants/${merchantId}/quotes`,
5 {
6 type: 'BALANCE_TRANSFER',
7 originCurrencySymbol: 'COP',
8 destinationCurrencySymbol: 'USD',
9 amountIn: 1000000
10 },
11 { headers: { 'Authorization': `Bearer ${token}` } }
12 );
13
14 console.log('Exchange rate:', quote.data.exchangeRate);
15 console.log('Will receive:', quote.data.amountOut, 'USD');
16
17 // 2. Create transfer order
18 const response = await axios.post(
19 `https://api-sandbox.koywe.com/api/v1/organizations/${orgId}/merchants/${merchantId}/orders`,
20 {
21 type: 'BALANCE_TRANSFER',
22 originCurrencySymbol: 'COP',
23 destinationCurrencySymbol: 'USD',
24 amountIn: 1000000,
25 quoteId: quote.data.id // Use quote to lock rate
26 },
27 { headers: { 'Authorization': `Bearer ${token}` } }
28 );
29
30 return response.data;
31}
32
33const transfer = await transferCurrency(token, orgId, merchantId);
34console.log('Transfer completed instantly:', transfer.status); // "COMPLETED"

Instant Settlement: BALANCE_TRANSFER orders complete instantly. No waiting for external confirmations.

Complete Balance Transfer Guide โ†’


ONRAMP - Buy Cryptocurrency

Convert fiat currency to cryptocurrency.

Uses Deals Endpoint: ONRAMP operations use the /deals endpoint. Deals can be paid in full or partially, with each payment creating orders that execute the crypto purchase.

When to Use

  • Buy crypto for treasury
  • Offer crypto purchases to users
  • Hedge with stablecoins
  • Pay crypto-native providers

Supported Cryptocurrencies

SymbolNameNetworks
USDCUSD CoinEthereum, Polygon, BSC
USDTTetherEthereum, Polygon, BSC
ETHEthereumEthereum
BTCBitcoinBitcoin
MATICPolygonPolygon
BNBBNBBSC

Required Fields for Quote

1{
2 "type": "ONRAMP",
3 "originCurrencySymbol": "COP", // Fiat currency
4 "destinationCurrencySymbol": "USDC", // Crypto currency
5 "amountIn": 50000 // Fiat amount
6}

Required Fields for Deal

1{
2 "type": "ONRAMP",
3 "destinationAccountId": "wallet_abc123", // Crypto wallet ID
4 "quoteId": "quote_xyz789" // Quote ID
5}

Simplified: Deals only need the destination account and quote ID. The amounts and currencies come from the quote.

Example

Node.js
1async function buyUSDC(token, orgId, merchantId, walletId) {
2 // 1. Get quote
3 const quote = await axios.post(
4 `https://api-sandbox.koywe.com/api/v1/organizations/${orgId}/merchants/${merchantId}/quotes`,
5 {
6 type: 'ONRAMP',
7 originCurrencySymbol: 'COP',
8 destinationCurrencySymbol: 'USDC',
9 amountIn: 50000
10 },
11 { headers: { 'Authorization': `Bearer ${token}` } }
12 );
13
14 console.log('Will receive:', quote.data.amountOut, 'USDC');
15 console.log('Exchange rate:', quote.data.exchangeRate);
16 console.log('Network fee:', quote.data.networkFee);
17
18 // 2. Create deal (not order!)
19 const response = await axios.post(
20 `https://api-sandbox.koywe.com/api/v1/organizations/${orgId}/merchants/${merchantId}/deals`,
21 {
22 type: 'ONRAMP',
23 destinationAccountId: walletId,
24 quoteId: quote.data.id
25 },
26 { headers: { 'Authorization': `Bearer ${token}` } }
27 );
28
29 return response.data;
30}
31
32const deal = await buyUSDC(token, orgId, merchantId, 'wallet_abc123');
33console.log('ONRAMP deal created:', deal.id);
34console.log('Deal can be paid in full or partially');

Partial Payments: ONRAMP deals can be paid in multiple installments. Each payment creates an order that purchases the proportional amount of crypto. Great for dollar-cost averaging!

Balance Required: By default, sufficient balance in your virtual account is required to close an ONRAMP deal. Deals execute automatically when funds are credited to your account. Pre-approved merchants can operate without upfront balance.

Complete ONRAMP Guide โ†’


OFFRAMP - Sell Cryptocurrency

Convert cryptocurrency to fiat currency.

Uses Deals Endpoint: OFFRAMP operations use the /deals endpoint. Unlike ONRAMP, OFFRAMP deals must be paid completely (no partial payments). The deal creates orders when fully funded.

When to Use

  • Sell crypto holdings
  • Convert crypto payments to fiat
  • Realize crypto gains
  • Prepare fiat for operations

Required Fields for Quote

1{
2 "type": "OFFRAMP",
3 "originCurrencySymbol": "USDC", // Crypto currency
4 "destinationCurrencySymbol": "COP", // Fiat currency
5 "amountIn": 10 // Crypto amount (10 USDC)
6}

Required Fields for Deal

1{
2 "type": "OFFRAMP",
3 "destinationAccountId": "va_cop_12345", // Virtual account ID
4 "quoteId": "quote_xyz789" // Quote ID
5}

Complete Payment Only: OFFRAMP deals must be funded completely. Partial payments are not supported.

Example

Node.js
1async function sellUSDC(token, orgId, merchantId) {
2 // 1. Get quote
3 const quote = await axios.post(
4 `https://api-sandbox.koywe.com/api/v1/organizations/${orgId}/merchants/${merchantId}/quotes`,
5 {
6 type: 'OFFRAMP',
7 originCurrencySymbol: 'USDC',
8 destinationCurrencySymbol: 'COP',
9 amountIn: 10 // 10 USDC
10 },
11 { headers: { 'Authorization': `Bearer ${token}` } }
12 );
13
14 console.log('Will receive:', quote.data.amountOut, 'COP');
15
16 // 2. Create deal (not order!)
17 const response = await axios.post(
18 `https://api-sandbox.koywe.com/api/v1/organizations/${orgId}/merchants/${merchantId}/deals`,
19 {
20 type: 'OFFRAMP',
21 destinationAccountId: 'va_cop_12345', // Virtual account for COP
22 quoteId: quote.data.id
23 },
24 { headers: { 'Authorization': `Bearer ${token}` } }
25 );
26
27 return response.data;
28}
29
30const deal = await sellUSDC(token, orgId, merchantId);
31console.log('OFFRAMP deal created:', deal.id);
32console.log('Deposit address:', deal.depositAddress);
33console.log('Send full crypto amount to complete');
34// Funds will be credited to COP virtual account after crypto received

Complete Funding: After creating the deal, you must send the full crypto amount to the provided deposit address. Once received, the deal creates orders and credits your virtual account with fiat.

Complete OFFRAMP Guide โ†’


Generate shareable payment links with a complete Koywe-branded checkout flow - no contact or payment method needed upfront!

No Contact Required

Customer enters their own information in the checkout

No Payment Method

Customer selects their preferred payment method

Koywe-Branded UI

Beautiful, secure checkout hosted by Koywe

Share Anywhere

Send via email, WhatsApp, SMS, or QR code

When to Use

  • E-commerce checkout: Simple payment collection without complex integration
  • Invoice payments: Send payment link for issued invoices
  • Email/WhatsApp: Share payment requests directly
  • QR code payments: Generate QR for in-person payments
  • One-time collections: Quick payment requests without storing customer data

How It Works

Differences from PAYIN

FeaturePAYINPAYMENT_LINK
ContactOptional but recommendedNot needed - customer enters data
Payment MethodMust be specifiedCustomer selects from all available
Checkout UIRedirect to payment providerKoywe-branded checkout flow
Data CollectionYou collect customer dataKoywe collects customer data
Best ForIntegrated checkout experienceStandalone payment requests

Minimal Required Fields

Thatโ€™s it! No contact, no payment method, no customer details needed. Just amount and description.

1{
2 "type": "PAYMENT_LINK", // Order type
3 "originCurrencySymbol": "COP", // Currency
4 "destinationCurrencySymbol": "COP", // Same as origin
5 "amountIn": 75000, // Amount to collect
6 "description": "Invoice #789" // Shows to customer
7}

Optional Fields

1{
2 "dueDate": "2025-11-14T23:59:59Z", // Link expiry
3 "externalId": "invoice-789", // Your reference
4 "successUrl": "https://yoursite.com/success", // Redirect after payment
5 "failedUrl": "https://yoursite.com/failed" // Redirect on failure
6}

Complete Example

1// Minimal example - just create and share!
2async function createPaymentLink(amount, description) {
3 const response = await axios.post(
4 `https://api-sandbox.koywe.com/api/v1/organizations/${orgId}/merchants/${merchantId}/orders`,
5 {
6 type: 'PAYMENT_LINK',
7 originCurrencySymbol: 'COP',
8 destinationCurrencySymbol: 'COP',
9 amountIn: amount,
10 description: description
11 },
12 { headers: { 'Authorization': `Bearer ${token}` } }
13 );
14
15 return response.data;
16}
17
18// Usage
19const link = await createPaymentLink(75000, 'Invoice #789 - Web Design');
20console.log('Share this link:', link.paymentUrl);
21
22// Send via email, WhatsApp, SMS, or generate QR code
23await sendEmail(customerEmail, {
24 subject: 'Payment Request - Invoice #789',
25 body: `Please pay here: ${link.paymentUrl}`
26});

Response:

1{
2 "id": "ord_abc123",
3 "type": "PAYMENT_LINK",
4 "status": "PENDING",
5 "paymentUrl": "https://checkout.koywe.com/pay/ord_abc123",
6 "amountIn": 75000,
7 "originCurrencySymbol": "COP",
8 "description": "Invoice #789 - Web Design",
9 "createdAt": "2025-11-13T15:00:00Z"
10}

Customer Experience: When customers open the payment link, theyโ€™ll see a Koywe-branded checkout where they can:

  1. Review payment details
  2. Enter their personal information
  3. Select their preferred payment method (PSE, PIX, Nequi, etc.)
  4. Complete the payment

Order Metadata and External IDs

External ID (Idempotency)

Use externalId to ensure idempotent order creation:

1{
2 "externalId": "order-12345-20251113" // Your unique identifier
3}

Benefits:

  • Safe to retry failed requests
  • Prevents duplicate orders
  • Links to your internal systems

Metadata

Store custom data with orders:

1{
2 "metadata": {
3 "orderId": "12345",
4 "customerId": "cust_67890",
5 "source": "mobile_app",
6 "campaign": "summer_sale"
7 }
8}

Use cases:

  • Track order source
  • Store campaign information
  • Link to internal systems
  • Custom reporting fields

Next Steps