cashramp
v0.0.4
Published
Cashramp API NodeJS SDK
Downloads
23
Maintainers
Readme
Cashramp SDK
This is the official NodeJS SDK for Cashramp's API.
➕ Installation
# NPM
npm install cashramp --save
or
# Yarn
yarn add cashramp
👨🏾💻 Quick Start
// CommonJS
const Cashramp = require("cashramp");
// ES6 import
import Cashramp from "cashramp";
const cashrampAPI = new Cashramp({
env: "test", // Can be either `test` or `live`
secretKey: "CSHRMP-SECK_apE0rjq1tiWl6VLB",
});
// Example: Fetch available countries
const response = await cashrampAPI.getAvailableCountries();
if (response.success) {
console.log(response.result);
} else {
console.log(response.error);
}
API Reference
Queries
getAvailableCountries()
: Fetch the countries that Cashramp is available ingetMarketRate({ countryCode })
: Fetch the Cashramp market rate for a countrygetPaymentMethodTypes({ country })
: Fetch the payment method types available in a countrygetRampableAssets()
: Fetch the assets you can on/offramp with the Onchain RampgetRampLimits()
: Fetch the Onchain Ramp limitsgetPaymentRequest({ reference })
: Fetch the details of a payment requestgetAccount()
: Fetch the account information for the authenticated user.
Mutations
confirmTransaction({ paymentRequest, transactionHash })
: Confirm a crypto transfer sent into Cashramp's Secure Escrow addressinitiateHostedPayment({ amount, paymentType, countryCode, currency, email, reference, redirectUrl, firstName, lastName })
: Initiate a payment requestcancelHostedPayment({ paymentRequest })
: Cancel an ongoing payment requestcreateCustomer({ firstName, lastName, email, country })
: Create a new customer profileaddPaymentMethod({ customer, paymentMethodType, fields })
: Add a payment method for an existing customerwithdrawOnchain({ address, amountUsd })
: Withdraw from your balance to an onchain wallet address
Custom Queries
For advanced use cases where the provided methods don't cover your specific needs, you can use the sendRequest
method to send custom GraphQL queries:
const query = `
query {
availableCountries {
id
name
code
currency {
isoCode
name
}
}
}
`;
const response = await cashrampAPI.sendRequest({
name: "availableCountries",
query,
});
if (response.success) {
console.log(response.result); // `result` contains the list of countries
}
Error Handling
All methods in the SDK return a response object with a success
boolean. When success
is false
, an error
property will be available with details about the error. Always check the success
property before accessing the result
.
TypeScript Support
This SDK includes TypeScript definitions out of the box. No additional types package is needed.
Documentation
For detailed API documentation, visit Cashramp's API docs.