🚀 Appfinity Pay Later SDK

Complete API Documentation for Third-Party Integration

v1.0.0 Production Ready 100% Test Coverage

📋 Overview

The Appfinity Pay Later SDK enables third-party platforms to seamlessly integrate our Pay Later solution into their applications. Our SDK provides a complete credit system with instant approvals, flexible repayment options, and comprehensive fraud protection.

✨ Key Features

🎯 Perfect For: E-commerce platforms, gaming platforms, subscription services, marketplace applications, and any platform requiring flexible payment solutions.

🔐 Authentication

All API requests require authentication using Platform API Keys. Contact our team to get your production API keys.

API Key Types

Environment Key Format Usage
Sandbox pk_test_... Development and testing
Production pk_live_... Live transactions

Authentication Headers

// Required headers for all API requests Headers: 'X-Platform-API-Key': 'your_platform_api_key' 'X-Platform-ID': 'your_platform_id' 'Content-Type': 'application/json'

⚡ SDK Integration Flow

Complete guide to integrating Appfinity Pay Later SDK into your application:

Step 1: Include the SDK

Add our JavaScript SDK to your website. The SDK handles all Pay Later interactions, UI components, and API communications:

<!-- Include the Appfinity Pay Later SDK --> <script src="https://appfinitystore.com/js/appfinity-sdk.js"></script> <!-- Optional: Include CSS for default styling --> <link rel="stylesheet" href="https://appfinitystore.com/css/paylater-ui.css">

Step 2: Initialize the SDK

Initialize the SDK with your platform credentials:

Appfinity.init({ platformId: "SLOTGAME", baseUrl: "appfinitystore.com", apiKey: "SLOT_eueue_your_key" }); const startFlow = () => { Appfinity.startFlow({ email: "user@example.com", deductAmount: 50, callbackFunction: (res) => { console.log("PayLater callback", res); if(res.success) { // redirect to success page } else { // redirect to failure page } } }); }

Note: The deductAmount parameter is optional and is used when you want to immediately purchase coins from the Appfinity wallet. When provided, the system will attempt to deduct the specified amount from the user's wallet during Step 1 of the flow. The response of this deduction operation will be received in the callbackFunction, allowing you to handle success or failure scenarios accordingly.

Expected Response Format

The callbackFunction(res) will receive a response object with the following structure:

// Success Response { success: true, message: "Wallet balance deducted successfully", data: { wallet: { amountDeducted: 50, currency: "USD", description: "SDK deduction", email: "user@example.com", eventId: 98, newBalance: 250, platformId: "your_platform_id" previousBalance: 300, transactionAt: "2025-09-23T11:32:58.947Z", userId: "your_user_id" } } } // Error Response { success: false, message: "Insufficient wallet balance", error: { code: "INSUFFICIENT_FUNDS", details: "Current balance: $25.50, Required: $50.00" } } // Other possible error codes: // "INVALID_AMOUNT" - Amount is invalid or negative // "USER_NOT_FOUND" - User account not found // "WALLET_LOCKED" - User wallet is temporarily locked // "NETWORK_ERROR" - Connection or server error

Step 3: Add Pay Later Button

Add the Pay Later button to your checkout page:

<button onclick="startFlow()" id="pay-later-btn" class="paylater-button"> <span>Pay Later</span> <small>Get instant approval</small> </button>

Step 4: Optional Parameters

The startFlow function can contain additional user parameters for better user experience:

// The startFlow can contain other parameters like first_name, last_name, date_of_birth, address, city, zip, country Appfinity.startFlow({ email: "user@example.com", first_name: "John", last_name: "Doe" }); // etc

Step 5: Wallet API Endpoints

Use these wallet API endpoints to manage user balances and transactions:

// Get wallet balance fetch('/v1/wallet/balance', { method: 'GET', headers: { 'Content-Type': 'application/json', 'x-api-key': 'your_api_key', 'x-platform-id': 'your_platform_id' } }) .then(response => response.json()) .then(data => console.log('Balance:', data.balance)); // Deduct from wallet fetch('/v1/wallet/deduct', { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-api-key': 'your_api_key', 'Idempotency-Key': `deduct-${Date.now()}-${Math.random()}` }, body: JSON.stringify({ amount: 50.00, description: 'Game purchase', metadata: { orderId: 'order_123', productId: 'game_coins' } }) }) .then(response => response.json()) .then(data => { if (data.success) { console.log('Deduction successful:', data.newBalance); } else { console.error('Deduction failed:', data.message); } }); // Expected Response: { "success": true, "message": "Wallet deduction successful", "data": { "transaction_id": "txn_abc123def456", "amount_deducted": 50.00, "previous_balance": 200.00, "new_balance": 150.00, "currency": "USD", "description": "Game purchase", "timestamp": "2024-01-15T10:30:00Z" } }

Step 6: Get Transaction History

Retrieve wallet transaction history for user account management:

// Get wallet transaction history fetch('/v1/wallet/transactions', { method: 'GET', headers: { 'Content-Type': 'application/json', 'x-api-key': 'your_api_key', 'x-platform-id': 'your_platform_id' } }) .then(response => response.json()) .then(data => { if (data.success) { console.log('Transaction history:', data.transactions); // Display transactions in UI data.transactions.forEach(transaction => { console.log(`${transaction.type}: ${transaction.amount} - ${transaction.description}`); }); } else { console.error('Failed to get transactions:', data.message); } }); // Expected Response: { "success": true, "data": { "transactions": [ { "id": "txn_abc123def456", "type": "debit", "amount": -50.00, "balance_after": 150.00, "description": "Game purchase", "metadata": { "orderId": "order_123", "productId": "game_coins" }, "timestamp": "2024-01-15T10:30:00Z", "status": "completed" }, { "id": "txn_def456ghi789", "type": "credit", "amount": 100.00, "balance_after": 200.00, "description": "Wallet top-up", "timestamp": "2024-01-14T15:20:00Z", "status": "completed" } ], "pagination": { "current_page": 1, "total_pages": 3, "total_transactions": 25, "per_page": 10 } } } // Required headers for all wallet API requests: // - Content-Type: application/json // - x-api-key: Your platform API key // - x-platform-id: Your platform ID // - Idempotency-Key: Unique key for POST requests (prevents duplicate transactions)

💡 Integration Best Practices

  • Always check eligibility before showing Pay Later options
  • Handle all event types to provide smooth user experience
  • Verify payments server-side for security and compliance
  • Implement proper error handling and user feedback
  • Test thoroughly in sandbox environment before going live
  • Monitor payment status and handle edge cases

🔗 API Endpoints

Complete reference for all Pay Later API endpoints:

GET Get Wallet Balance

Endpoint: /v1/wallet

Retrieve the current wallet balance for a user.

Query Parameters

Parameter Type Required Description
email string Required User's email address
Success Response (200):
{ "success": true, "data": { "balance": 150.00, "currency": "USD", "available_credit": 500.00 } }

POST Apply for Pay Later

Endpoint: /v1/paylater/apply

Submit a Pay Later credit application.

Request Body

Parameter Type Required Description
email string Required User's email address
amount number Required Credit amount requested
currency string Optional Currency code (default: USD)
country string Optional Country code (auto-detected)
Success Response (200):
{ "success": true, "data": { "application_id": "app_123456", "status": "approved", "credit_limit": 500.00, "expires_at": "2024-12-31T23:59:59Z" } }

GET Check Application Status

Endpoint: /v1/paylater/status

Check the status of a Pay Later application.

Query Parameters

Parameter Type Required Description
email string Required User's email address
application_id string Optional Specific application ID
Success Response (200):
{ "success": true, "data": { "application_id": "app_123456", "status": "approved", "credit_limit": 500.00, "available_credit": 500.00, "currency": "USD", "expires_at": "2024-12-31T23:59:59Z", "created_at": "2024-01-15T09:00:00Z", "approved_at": "2024-01-15T09:15:00Z" } }

POST Activate Pay Later Account

Endpoint: /v1/paylater/activate

Activate an approved Pay Later account.

Request Body

Parameter Type Required Description
email string Required User's email address
application_id string Required Approved application ID
Success Response (200):
{ "success": true, "message": "Pay Later account activated successfully", "data": { "account_id": "acc_789012345", "status": "active", "credit_limit": 500.00, "available_credit": 500.00, "currency": "USD", "activated_at": "2024-01-15T10:00:00Z" } }

GET Transaction History

Endpoint: /v1/paylater/transactions

Retrieve transaction history for a user.

Query Parameters

Parameter Type Required Description
email string Required User's email address
limit number Optional Number of transactions to return (default: 10, max: 100)
offset number Optional Number of transactions to skip (default: 0)
Success Response (200):
{ "success": true, "data": { "transactions": [ { "id": "txn_paylater_123", "type": "purchase", "amount": 299.99, "status": "completed", "description": "Premium subscription purchase", "merchant": "GameStore Pro", "created_at": "2024-01-15T10:30:00Z", "due_date": "2024-02-15T23:59:59Z" }, { "id": "txn_paylater_124", "type": "repayment", "amount": -149.99, "status": "completed", "description": "Partial repayment", "created_at": "2024-01-10T14:20:00Z" } ], "pagination": { "total": 25, "limit": 10, "offset": 0, "has_more": true } } }

POST Auto Pay Due Balance

Endpoint: /v1/due-balance/pay-auto

Automatically processes payment for outstanding due balance using saved payment methods or wallet funds.

Request Body

Parameter Type Required Description
email string Required User's email address
amount number Required Amount to pay from due balance
payment_method string Optional Payment method preference (auto, wallet, card). Default: auto
Success Response (200):
{ "success": true, "message": "Auto payment processed successfully", "data": { "payment_id": "pay_auto_123456", "amount": 50.00, "currency": "USD", "payment_method_used": "wallet", "remaining_balance": 100.00, "status": "completed", "processed_at": "2024-01-15T12:30:00Z", "transaction_id": "txn_auto_789012" } }
Error Response (400):
{ "success": false, "error": "Insufficient funds", "message": "No available payment methods with sufficient balance", "data": { "wallet_balance": 25.00, "required_amount": 50.00, "available_methods": ["wallet"] } }

🆘 Support & Resources

📚 Additional Documentation

🔧 Technical Support

Need Help? Our technical team is here to assist with your integration:

🚀 Production Checklist

Get Production API Keys

Contact our team to obtain your production API credentials.

Test All Scenarios

Run the complete test suite and verify all integration points.

Configure Webhooks

Set up webhook endpoints for real-time transaction updates.

Monitor Performance

Implement logging and monitoring for production usage.

🎉 Ready for Production! The Appfinity Pay Later SDK is production-ready with 100% test coverage, comprehensive documentation, and full technical support.