Skip to main content

Installation & Usage

Installation#

You can add Checkout to your project like this:

index.html
<script src="https://checkout.sendcashpay.com/lib/lib.bundle.js"></script>

Usage#

To initialise Checkout:

SendcashPay.init({    siteName: "<your site or app name>",    siteUrl: "<your site url>",    siteLogo: "<url to your logo>",    publicKey: "<your Sendcash Pay public key>"})

Creating a bank transfer charge#

To create a transfer charge to any bank account:

const result = await SendcashPay.charge({    signature: "<not your signature token - a signature that verifies you're initiating a transaction>",    amount: "<how much you want to charge in Naira>",    userId: "<a unique identifier for your user>",    destinationAccountNumber: "<recipient account number>",    destinationBankCode: "<recipient bank code>",    transactionReference: "<a unique identifier for your transaction>",    name: "optional: <the sender's full name if you want us to ensure that they're sending from their own bank account>"});
tip

Passing name into the .charge() function above compares your end-user's name with the name on the bank account being charged. If they don't match, the payment fails.

This only works for personal bank accounts (not business/corporate). Note that this is a client-side validation and shouldn't be entirely relied on. Further validation should be done upon receiving webhook status updates.

tip

You can retrieve a list of banks and their codes by making a GET request to https://checkout.sendcashpay.com/banks.json

Building the request signature#

For Sendcash Pay to know that a request to charge a bank account is truly coming from you and not a bad actor, you must pass the Sendcash Pay charge function a signature. Use the Signature Token provided to you during the onboarding process to generate a signature that is a hex digest of an HMAC-SHA256 hash of your charge arguments concatenated as follows:

user_id:payment_reference:amount_kobo:destination_account_number:destination_bank_code

Below is an example of the request signature generation in ruby:

payload = "#{payment.user_id}:#{payment.reference}:#{payment.amount_kobo}:#{payment.destination_account_number}:#{payment.destination_bank_code}"OpenSSL::HMAC.hexdigest('sha256', ENV['SENDCASHPAY_SIGNATURE_TOKEN'], payload)
tip

amount_kobo should be the kobo value of the amount you want to charge.

caution
  1. You should never make your signature token public.
  2. You should never generate your request signature on the client-side. Always request the signature from your server.

Making a charge to your default settlement bank account#

const result = SendcashPay.chargeToDefaultAccount({    signature: "<a signature that verifies you're initiating a transaction>",    amount: "<how much you want to charge in Naira>",    userId: "<a unique identifier for your user>",    transactionReference: "<a unique identifier for your transaction>",    name: "optional: <the sender's full name if you want us to ensure that they're sending from their own bank account>"})

Response#

If the transfer charge was successfully created, then result will be:

{ paymentId: "<the transaction reference you passed in earlier>"}
caution

You shouldn't give your users value at this point. That should be done on the server-side and will be explained in the next section of this guide.

If the transfer charge fails or the user closes Checkout, then result will be:

null

Next steps#

In the next section, we'll go over how to validate a transfer charge's success or failure without our webhooks.