Skip to main content

Introduction

Installation:

npm install cloudhands

Initialization:

To get started, you need to create a payment key on cloudhands.ai.

Once created, you can initialize your SDK by passing in the payment key:

let csdk = new CloudhandsSDK(<your payment key here>);

When that is done, you can begin to use the SDK in your project.

Sample Usage

import CloudhandsSDK, {
CloudhandsButton,
CloudhandsPurchaseResult,
} from "cloudhands";
const clientId = "<payment key here>";
let csdk = new CloudhandsSDK(clientId);
//define onsuccess function
function onPaymentSuccess(result: CloudhandsPurchaseResult) {
// use transaction id to get transaction details
csdk.GetTransaction(result.transaction_id!).then((transaction) => {
console.log("Transaction details:", transaction);
});
}
//let charge = csdk.CreateCharge(0.5, "test", ChargeType.Each, {}); // last two args are optional
let charge = csdk.CreateCharge(0.3, "test event");
const ch_button = CloudhandsButton(csdk, charge, onPaymentSuccess);
// Could also append to a specific element or div instead of body
// const specificElement = document.getElementById("specific-element-id");
document.body.appendChild(ch_button);

Important functions

CreateCharge(CreateCharge(charge: number, event_name: string, charge_type: ChargeType = ChargeType.Each, metadata = {}) -> CloudhandsCharge
  • wrapper to quickly and simply build a charge object for use with the SDK
  • event_name: the product/service/event name you want to charge the user for
  • charge_type: optional, what type of charge - ChargeType.Each for a one-time payment
  • metadata: optional, any relevant metadata you want to include, just a key-value struct
  • returns: CloudhandsCharge objectGetTransaction(transactionId: string) -> Promise<CloudhandsTransaction | null>
  • retrieve details of a given transaction, including if payment is successfully processed
  • transaction_id: reference id for a transaction, returned when user pays
  • returns: CloudhandsTransaction object

Important types

CloudhandsCharge = {
author_id: string;
sdk_version: string;
charge_type: ChargeType;
charge: number ;
event_name: string;
metadata: any;
}
CloudhandsTransaction = {
author_id: string;
user_id: string;
amount?: number;
type?: string;
date?: string;
description?: string;
processed?: string;
process_state: TransactionState;
}
CloudhandsPurchaseResult = {
success: boolean;
message?: string;
transaction_id?: string;
}
enum TransactionState {
Pending,
Complete,
Failed
}
enum ChargeType {
Each,
Monthly
}

Button usage

CloudhandsButton can be used with the SDK to quickly set up the entire payment flow

Sample usage:

const ch_button = CloudhandsButton(
<your initialized sdk object>,
<charge object you create>,
<on payment success function callback>,
);
// Could also append to a specific element or div instead of body
// const specificElement = document.getElementById("specific-element-id");
document.body.appendChild(ch_button);