Methods & Usage
Usage
The SDK requires configuration during initialization:
Before initializing the SDK clients, you'll need a Google Places API Key from your Google Cloud Console. This key is required for location-based features and should be kept secure.
LiquidCommerce Client
import LiquidCommerce from '@liquidcommerce/cloud-sdk';
// Your Account token provided to you through
// your account representative
const client = await LiquidCommerce('YOUR_LIQUIDCOMMERCE_API_KEY', {
googlePlacesApiKey: 'YOUR_GOOGLE_PLACES_API_KEY',
env: 'stage' // or 'prod'
});
// Initialize the client
await client.init();LiquidCommerceOrders Client
import LiquidCommerceOrders from '@liquidcommerce/cloud-sdk';
// Your Account user and passoword will be provided to you
// through your account representative
const orderClient = await LiquidCommerceOrders({
userID: 'YOUR_ORDER_API_USER_ID',
password: 'YOUR_ORDER_API_PASSWORD',
env: LIQUID_COMMERCE_ENV.STAGE, // or PROD
});
// Initialize the client
await orderClient.init();Response Types
All API responses follow a consistent structure:
Methods
Address
While the SDK handles authentication automatically, you can also manually retrieve the authentication details:
Address
Services for address validation and lookup:
Catalog
Product catalog search and availability services:
Cart
Shopping cart management:
User
User profile and preferences management:
Payment Element
The Payment Element is a secure and modern UI component for collecting payment details. It simplifies PCI compliance by handling all sensitive information within an iframe.
Prerequisites
Before mounting the Payment Element, you must create a payment session. This can be tied to a user, cart, or checkout.
Integration
Initialize and Mount
The LiquidCommercePaymentElement function creates and manages the UI component.
Generate a Confirmation Token
Once the user has filled out the payment form, create a confirmation token. This token securely represents the payment details.
Confirm the Payment Session
Use the confirmation token to finalize the payment and retrieve the payment method details.
Lifecycle Management
Properly manage the element's lifecycle to ensure a smooth user experience and resource cleanup.
Legacy Payment
Use the new Payment Element integration that has the UI and API methods decoupled, allowing you to use the SDK entirely server side.
The payment system uses secure elements for handling sensitive payment data. Before using payment features, you must first create a user session.
Prerequisites
User Session Creation:
Payment Element Integration
Security Considerations
PCI Compliance: The payment element handles card data securely within an iframe, ensuring your application never directly touches sensitive payment information.
Token-Based: All payment data is tokenized - you only receive secure tokens that can't be used to retrieve the original card details.
Single Use: Payment tokens are single-use and expire after a short time period.
Domain Validation: Payment elements will only work on domains that have been pre-registered with your account.
Best Practices
Error Handling: Always implement proper error handling:
Cleanup: Always clean up payment elements when done:
When navigation away from payment page
After successful payment
After failed payment attempt
Before unmounting payment component
Event Handling: Monitor element state for better user experience:
Responsive Design
The payment element automatically adapts to:
Mobile and desktop viewports
Right-to-left languages
Dark/light themes
Different container sizes
Testing Cards
When testing payments in staging environment, use these test cards:
These cards will be accepted in test mode and will simulate successful payments. They should only be used in the staging environment, never in production.
Important Notes:
These cards work only in test/staging environment
Real cards will be declined in test mode
Test cards will be declined in production
All test transactions use simulated funds
Testing Environment Limitations β οΈ Important Testing Note When doing and checkout complete on the testing environment, certain transaction amount ranges may be intentionally restricted to simulate payment declines, gateway errors, or other failures. This allows you to verify that your integration can handle error scenarios correctly.
Example β Amounts that may trigger simulated errors:
$2000.00 β $2999.99: Processor Declined
$3000.00 β $3000.99: Processor Network Unavailable
$5001.00: Gateway Rejected (Application Incomplete)
For routine testing, avoid using these ranges unless you specifically want to test error-handling behavior.
Checkout
Checkout process management:
Checkout Payment
For direct checkout payments, the flow is similar but uses the checkout session:
Orders
Provides secure access to order data throughout the finalized states of the order lifecycle within the LiquidCommerce ecosystem.
Fetch by ID
Webhook Test
Error Handling
The SDK throws errors for various scenarios. Always wrap SDK calls in try-catch blocks:
Common error scenarios:
Authentication failures
Invalid parameters
Network errors
Resource not found
Rate limiting
Validation errors
Price Handling
All monetary values in the SDK are handled in cents (the smallest currency unit). For example:
$10.00 is represented as 1000
$5.99 is represented as 599
$0.50 is represented as 50
Last updated

