## Glide NodeJS SDK

Nodejs SDK for [Glide](https://doc.ourglide.com/).

### Installation

```
npm install glide-nodejs-sdk
or
yarn add glide-nodejs-sdk
```

### Usage

```js
// import the library
import Glide from "glide";

const glide = new Glide("your-secret-key", "your-public-key");
```

### Introduction

Our goal is to give access to financial opportunity anywhere in emerging markets. Great products don’t make you think.

### Examples

Glide SDK made use of the standard Javascript Promise. it support both then-catch syntax and async-await.

#### Using Then-Catch

```js
glide.customer
	.getAll({ page: 1 })
	.then((response) => {
		console.log("Customer list: ", response.customers);
		console.log("Metadata: ", response.metadata);
	})
	.catch((error) => {
		console.log("An error occurred: ", error);
	});
```

#### Or you can use the Async-Await syntax

```js
try {
	const response = await glide.customer.getAll({ page: 1 });

	console.log("Customer list: ", response.customers);
	console.log("Metadata: ", response.metadata);
} catch (error) {
	console.log("An error occurred: ", error);
}
```

Note: All examples in this documentation will make use of the async-await syntax.

### BVN APIs

Resolve BVN details

##### Basic

```js
const response = await glide.bvn.basic("12345678901");

console.log("Basic details: ", response);
```

##### With image and more details

```js
const response = await glide.bvn.withImage("12345678901");

console.log("More details with image: ", response);
```

### Customer APIs

To get list of all customers

```js
const response = await glide.customer.getAll({ page: 1 });

console.log("Customer list: ", response.customers);
console.log("Metadata: ", response.metadata);
```

Update customer information

```js
const updatedRecord = await glide.customer.update("customer-id", {
	firstName: "Updated",
	lastName: "Good",
});

console.log("Updated record", updatedRecord);
```

List all customer transactions

```js
const response = await glide.customer.transactions({ customerId: "customer-id", page: 1, type: "CREDIT" });

console.log("Transaction list", response.transactions);
console.log("Metadata information about pagination", response.metadata);
```

### Wallet APIs

To create a new customer wallet

```js
/*
 * @params firstName First name
 * @params lastName Last name
 * @params phoneNumber Phone number.
 * @params dateOfBirth Date of birth
 * @params customerId The customer ID
 *
 * @params bvn Optional BVN.
 * @params metadata Optional metadata information.
 */

const response = await glide.wallet.createCustomerWallet({
	firstName: "Rilwan",
	lastName: "Customer",
	phoneNumber: "08030223345",
	dateOfBirth: "1991-09-13",
	bvn: "01234567890",
	customerId: "49d4ea6d-d3dc-490c-800d-7c50b89cf8ff", //optional: customer to be charged for the transaction
	metadata: {
		// optional
		"some-data": "some value",
		"more-data": "more value",
	},
});

console.log("Wallet: ", response.wallet);
console.log("Customer: ", response.customer);
```

To get the list of all customer wallets

```js
const wallets = await glide.wallet.allCustomerWallets();
console.log("Customer wallets: ", wallets);
```

To get a customer wallet details

```js
/*
 * @params customerId customer ID
 */
const response = await glide.wallet.getCustomerWallet("49d4ea6d-d3dc-490c-800d-7c50b89cf8ff");
console.log("Customer wallet details: ", response);
```

To credit customer wallet

```js
/*
 * @params amount The amount to be transfered.
 * @params reference Optional reference number.
 * @params customerId Customer ID of the customer to be credited.
 * @params metadata Optional transaction metadata.
 */

const response = await glide.wallet.creditCustomerWallet({
	amount: 1000,
	reference: "13k34jk4j54234",
	customerId: "982c9510-24ef-4c85-aea4-fa2408e5ab0d",
	metadata: {
		"some-data": "sample data",
		"more-data": "any value here",
	},
});
console.log("Transaction details: ", response);
```

To debit customer wallet

```js
/*
 * @params amount The amount to be transfered.
 * @params reference Optional reference number.
 * @params customerId Customer ID of the customer to be debited.
 * @params metadata Optional transaction metadata.

 */
const response = await glide.wallet.debitCustomerWallet({
	amount: 1000,
	reference: "13k34jk4j54234",
	customerId: "982c9510-24ef-4c85-aea4-fa2408e5ab0d",
	metadata: {
		"some-data": "sample data",
		"more-data": "any value here",
	},
});
console.log("Transaction details: ", response);
```

To set customer wallet transaction pin

```js
const response = await glide.wallet.setWalletTransactionPin({
	pin: "1234",
	customerId: "982c9510-24ef-4c85-aea4-fa2408e5ab0d",
});
console.log(response.message);
```

Get wallet settle balance.

```js
const balance = await glide.wallet.getSettlementBalance();
console.log("Total amount to balance customer wallets: ", balance);
```

Settle customer balances.

```js
const completed = await glide.wallet.settleCustomerBalances();

console.log(completed ? "Settlement completed successfully" : "Unable to settle customer balances");
```

Freeze customer wallet.

```js
/*
 * @params customerId
 */

const completed = await glide.wallet.closeCustomerWallet("982c9510-24ef-4c85-aea4-fa2408e5ab0d");

console.log(completed ? "Customer wallet successfully frozen" : "Unable to freeze customer wallet");
```

UnFreeze customer wallet.

```js
/*
 * @params customerId
 */

const completed = await glide.wallet.enableCustomerWallet("982c9510-24ef-4c85-aea4-fa2408e5ab0d");

console.log(completed ? "Customer wallet successfully enabled" : "Unable to unfreeze customer wallet");
```

Perform wallet to wallet transfer.

```js
/*
 * @params amount The amount to be transfered.
 * @params toCustomerId Customer ID of the customer to be credited.
 * @params fromCustomerId Customer ID of the customer to be debited.
 */

const completed = await glide.wallet.walletToWalletTransfer({
	amount: 270,
	toCustomerId: "982c9510-24ef-4c85-aea4-fa2408e5ab0d",
	fromCustomerId: "49d4ea6d-d3dc-490c-800d-7c50b89cf8ff",
});

console.log(completed ? "Transaction completed successfully." : "An error occurred while completing the transaction");
```

Make a batch transaction debitting multiple customer wallet simultaneously.

```js
/*
 * @params batchReference A unique reference number for the batch.
 * @params amount The amount to be transfered.
 * @params reference A unique reference number for the individual transaction.
 * @params customerId Customer ID of the customer to be credited.
 */

const response = await glide.wallet.batchDebitCustomerWallets({
	batchReference: "88adsf8hssa43sefas8df8ahhjefasdff8",
	transactions: [
		{
			amount: 500,
			reference: "dkfajdfsdjjjssd23sfjasdfasdkfjds9",
			customerId: "f75774b0-6f99-4029-92a9-2dfe7e15d3f0",
		},
		{
			amount: 300,
			reference: "dkfajdfsdjjjdsfjasd45fssasdkfjds10",
			customerId: "de304d11-ca4e-491f-8851-9ca09a0084a3",
		},
	],
});

const { data, message } = response;

console.log(message);

console.log("Failed transactions: ", data.rejected);
console.log("Failed transactions: ", data.rejected);
console.log("Batch transaction reference: ", data.batchReference);
```

Make a batch transaction crediting multiple customer wallet simultaneously.

```js
/*
 * @params batchReference A unique reference number for the batch.
 * @params amount The amount to be transfered.
 * @params reference A unique reference number for the individual transaction.
 * @params customerId Customer ID of the customer to be credited.
 */

const response = await glide.wallet.batchCreditCustomerWallets({
	batchReference: "8ede8w340dk3erowr3ef5",
	transactions: [
		{
			amount: 1000,
			reference: "okdrfadd3freaksd4f",
			customerId: "6c415ca9-0cc9-41cf-ac46-a79e3b6df8dc",
		},
		{
			amount: 50000,
			reference: "okdf3arded4faeksdfd",
			customerId: "33b18d9a-194f-4f36-a259-004e68fcd3fc",
		},
	],
});

const { data, message } = response;

console.log(message);

console.log("Failed transactions: ", data.rejected);
console.log("Failed transactions: ", data.rejected);
console.log("Batch transaction reference: ", data.batchReference);
```

Enable customer to perform batch transaction by crediting multiple customer wallet simultaneously.

```js
/*
 * @params recipients The customers and amount to be credited.
 * @params customerId Customer ID of the customer initializing the transaction.
 */

const response = await glide.wallet.customerBatchCreditCustomerWallets({
	batchReference: "88adsf8hssasefas8df8ahhjefasdff8",
	customerId: "6c415ca9-0cc9-41cf-ac46-a79e3b6df8dc",
	recipients: [
		{
			amount: 200,
			reference: "dkfajdfsdjjjssdsfjasdfasdkfjds9",
			customerId: "c938a018-8987-4411-97c5-e456868741e8",
		},
		{
			amount: 300,
			reference: "dkfajdfsdjjjdsfjasdfssasdkfjds10",
			customerId: "33b18d9a-194f-4f36-a259-004e68fcd3fc",
		},
	],
});

const { data, message } = response;

console.log(message);

console.log("Failed transactions: ", data.rejected);
console.log("Failed transactions: ", data.rejected);
console.log("Batch transaction reference: ", data.batchReference);
```

Reverse batch transaction

```js
/*
 * @params customerId Customer ID of the customer initializing the transaction.
 */

const response = await glide.wallet.reverseBatchTransaction("88adsf8hssa43sefas8df8ahhjefasdff8");

const { data, message } = response;

console.log(message);

console.log("Failed transactions: ", data.rejected);
console.log("Failed transactions: ", data.rejected);
console.log("Batch transaction reference: ", data.batchReference);
```

### Merchant APIs

Get merchant profile information

```js
const profile = await glide.merchant.profile();

console.log("Profile information: ", profile);
```

Update merchant details

```js
const completed = await glide.merchant.updateProfile({
	canLogin: true,
	sendEmail: true,
	businessType: "FINANCIAL-SERVICES",
	callbackURL: "https://product.com/callback/glide",
	sandboxCallbackURL: "http://testing.com/callback/glide",
});

console.log(completed ? "Profile successfully updated" : "An error occurred while completing profile update");
```

Get merchant wallet information

```js
const wallet = await glide.merchant.getWallet();

console.log("The wallet informmation: ", wallet);
```

Get merchant transaction information

```js
const response = await glide.merchant.getTransactions({
	page: 1,
	type: "ALL",
});

console.log("Transaction informmation: ", response.transactions);
console.log("Page metadata/pagination information: ", response.metadata);
```

### Card Service APIs

Create a new card for the customer

```js
const response = await glide.card.create({
	address1: "20 Cresent Road, Ogba, Lagos",
	address2: "20 Adewale Street, Surulere, Lagos",
	customerId: "c938a018-8987-4411-97c5-e456868741e8",
});

console.log("Card successfully created.");
```

Activate card

```js
const response = await glide.card.activate({
	last6: "000352",
	customerId: "c938a018-8987-4411-97c5-e456868741e8",
});

console.log("Card activated");
```

Fund card

```js
const response = await glide.card.fund({
	amount: 2000,
	customerId: "c938a018-8987-4411-97c5-e456868741e8",
});

console.log("Card funded");
```

Get card balance

```js
const balance = await glide.card.getBalance("customer-wallet-id");

console.log("Card balance: ", balance);
```
