# SDK

Source: https://checkslip.com/en/docs/sdk

Call the Checkslip API from your code with the official SDKs for JavaScript/TypeScript, Go, PHP and Rust. Install the one for your language; the SDK's methods send the HTTP requests for you.

Every example reads the API key from the CHECKSLIP_API_KEY environment variable. Keep keys on your server only. More in [Authentication with an API key](https://checkslip.com/en/docs/authentication).

The install commands name no version, so you get the latest release at install time. Each package page lists its versions and what changed.

Only a FOUND lookup uses a credit, in every SDK. Every outcome is explained in [Transfer lookup outcomes](https://checkslip.com/en/docs/outcomes).

## JavaScript / TypeScript

Package on [npm](https://www.npmjs.com/package/@checkslip/sdk) · [Source on GitHub](https://github.com/Checkslip/sdk-js)

### Install

```bash
npm install @checkslip/sdk
```

### Quick start

```typescript
import { Checkslip } from "@checkslip/sdk";

const checkslip = new Checkslip({ apiKey: process.env.CHECKSLIP_API_KEY });

const check = await checkslip.slips.lookup({
  qr: "00330006000001010306902126302105340875102TH9104F86F",
});

if (check.outcome === "FOUND" && "sender" in check.slip) {
  console.log(check.slip.amount.satang / 100, "THB");
}
```

## Go

Package on [pkg.go.dev](https://pkg.go.dev/github.com/Checkslip/sdk-go) · [Source on GitHub](https://github.com/Checkslip/sdk-go)

### Install

```bash
go get github.com/Checkslip/sdk-go
```

### Quick start

```go
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	"github.com/Checkslip/sdk-go"
)

func main() {
	client := checkslip.NewClient(os.Getenv("CHECKSLIP_API_KEY"))

	res, err := client.Slips.Lookup(context.Background(), &checkslip.LookupParams{
		QR: "00330006000001010306902126302105340875102TH9104F86F",
	})
	if err != nil {
		log.Fatal(err)
	}

	switch res.Outcome {
	case checkslip.OutcomeFound:
		fmt.Println("amount:", res.Slip.Amount)
	case checkslip.OutcomeNotFound:
		fmt.Println("the bank has no transfer for this reference")
	default:
		fmt.Println("outcome:", res.Outcome)
	}
}
```

## PHP

Package on [Packagist](https://packagist.org/packages/checkslip/sdk) · [Source on GitHub](https://github.com/Checkslip/sdk-php)

### Install

```bash
composer require checkslip/sdk
```

If your project has no PSR-18 client yet, add one. Guzzle is the common choice. The client finds an installed one by itself, so there is nothing to wire up.

```bash
composer require checkslip/sdk guzzlehttp/guzzle
```

### Quick start

```php
<?php

use Checkslip\Client;
use Checkslip\Model\Slip;

$checkslip = new Client(apiKey: getenv('CHECKSLIP_API_KEY'));

$check = $checkslip->slips->lookup(
    slip: '00330006000001010306902126302105340875102TH9104F86F',
);

if ($check->isFound() && $check->slip instanceof Slip) {
    echo $check->slip->amount->toBaht(), " THB\n";
}
```

## Rust

Package on [crates.io](https://crates.io/crates/checkslip) · [Source on GitHub](https://github.com/Checkslip/sdk-rust)

### Install

```bash
cargo add checkslip
```

The example runs on the tokio async runtime.

```bash
cargo add tokio --features "macros rt-multi-thread"
```

### Quick start

```rust
use checkslip::{Client, LookupRequest, Outcome};

#[tokio::main]
async fn main() -> checkslip::Result<()> {
    let client = Client::from_env()?; // reads CHECKSLIP_API_KEY

    let check = client
        .slips()
        .lookup(LookupRequest::qr("00330006000001010306902126302105340875102TH9104F86F"))
        .await?;

    match check.outcome {
        Outcome::Found => {
            let slip = check.slip.as_full().expect("FOUND carries the full record");
            println!("{} satang from {}", slip.amount.satang, slip.sender.bank.code);
        }
        other => println!("outcome {other}"),
    }
    Ok(())
}
```

You can send a slip image instead of the QR text. Each SDK README shows how.

Every request and response field is on [Look up a transfer with the bank](https://checkslip.com/en/docs/lookup-slip).
