Cari Finance SDKs
The recommended way to interact with the Cari Finance API is by using one of our official SDKs. Today, Cari Finance offers fine-tuned JavaScript, Ruby, PHP, Python, and Go libraries to make your life easier and give you the best experience when consuming the API.
JavaScript SDK
Our JavaScript SDK provides a comprehensive solution for integrating Cari Finance into your web applications. It consists of two main components:
- Server-side SDK: For making API calls to create charges, manage customers, etc.
- Client-side SDK: For securely collecting payment information from your customers
Installation
Currently, the Cari Finance JavaScript SDK is only available via CDN:
<script src="https://cdn.cari.finance/js/cari-finance.min.js"></script>
Note: npm and yarn packages are coming soon!
Basic Usage
// Initialize the SDK with your publishable key
const cariFinance = new CariFinance("pk_test_27436257e3fe4b0fa266f4a6f59047a3");
// Create elements instance
const elements = cariFinance.elements();
// Create and mount a payment form
const paymentForm = elements.create("paymentForm");
paymentForm.mount("#payment-form");
// Handle payment submission
document
.querySelector("#payment-form")
.addEventListener("submit", async (e) => {
e.preventDefault();
// Get payment data
const paymentData = paymentForm.getPaymentData();
// Add additional payment details
paymentData.amount = 1000; // $10.00 (in cents)
paymentData.currency = "usd";
// Process payment
try {
const result = await cariFinance.charges.create(paymentData);
console.log("Payment successful", result);
} catch (error) {
console.error("Payment failed", error);
}
});
Client-side payment elements
Our client-side SDK provides customizable UI components for collecting payment information securely. The SDK automatically handles the tokenization of sensitive payment details, ensuring you never have to handle raw card data.
Available Elements
- Name
card
- Type
- Element
- Description
A complete credit card input field that collects card number, expiry, and CVC.
- Name
mobilePayment
- Type
- Element
- Description
Input fields for mobile payment information.
- Name
bankAccount
- Type
- Element
- Description
Input fields for bank account information.
- Name
paymentForm
- Type
- Element
- Description
A complete payment form with tabs for all supported payment methods.
Creating and mounting elements
// Create a card element
const cardElement = elements.create("card");
// Mount it to the DOM
cardElement.mount("#card-element");
// Listen for events
cardElement.on("change", (event) => {
console.log("Card details changed", event);
});
Auto-mounting
The SDK supports automatic mounting when included via script tag:
<script
src="https://cdn.cari.finance/js/cari-finance.min.js"
data-publishable-key="pk_test_27436257e3fe4b0fa266f4a6f59047a3"
data-auto-mount
data-mount-element="#payment-form"></script>
<div id="payment-form"></div>
Environment handling
The SDK automatically determines the environment (test or live) based on the prefix of your publishable key:
- Keys starting with
pk_test_
will use the test environment - Keys starting with
pk_live_
will use the live environment
There's no need to explicitly specify the environment when initializing the SDK.
Official libraries
In addition to our JavaScript SDK, we offer a range of official SDKs for other programming languages to make integrating with Cari Finance as seamless as possible.
Official libraries
PHP
Our PHP SDK provides a fluent interface to the Cari Finance API, with support for Laravel and other PHP frameworks.
Ruby
The Ruby SDK includes built-in support for Rails applications and comes with comprehensive documentation and examples.
Node.js
Our Node.js SDK provides Promise-based methods for all API endpoints and TypeScript definitions for better development experience.
Python
The Python SDK supports both synchronous and asynchronous operations, with Django integration and comprehensive test coverage.
Go
Our Go SDK offers a lightweight, concurrent implementation with strong typing and comprehensive error handling.