❗️

Phasing Out

Due to PCI compliance changes, we are phasing out Tithely.js V1 by December 15, 2018.

In order to charge a card or bank account, the information must be tokenized using Tithely.js. This allows you to make donations to organizations without having the information touch your servers.

Include tithely.js

Make sure to use the right path for testing vs. when going live.

<!-- Testing -->
<script src="https://tithelydev.com/api-js/v1/tithely.js"></script>

<!-- Go Live -->
<script src="https://tithe.ly/api-js/v1/tithely.js"></script>

📘

Note

For testing, you may use http or https for Tithely.js. The live url requires https.

Create the tithely object

Use javascript to create a tithely object using your public key.

// Create the tithely object (passing your public key)
var tithely = new Tithely('pub_xxxxxxxx');

🚧

Warning

Never show your private key in javascript or HTML. Only use your public key.

Tokenize a card

Tokenize a credit or debit card by calling the add_payment_method() method.

// Example card object
var card = {
  card_number: '4242424242424242',
  card_expiry_month: '04',
  card_expiry_year: '2022',
  card_cvc: '123',
  postal_code: '' // Optional
};

// Tokenize card
tithely.add_payment_method(card, tithelyResponseCallback);

// Callback function
function tithelyResponseCallback(status, response) {
  if (response.error) {
    // Error handling here
    console.warn(response.error.message);
  }
  else {
    // Get the token
    var token = response.id;
    console.log(response);
    // What's next?
    // Send it server side by add this token to your form as a hidden field (or use AJAX).
  }
}

Tokenize a bank account

Tokenize a bank account the same way by calling the add_payment_method() method.

// Example bank account object
var bank_account = {
  routing_number : '110000000',
  account_number : '000123456789',
  name : 'Mike Rogers', // Name of the person or business that owns the bank account
  account_holder_type : 'individual' // Either "individual" or "company"
};

// Tokenize bank account
tithely.add_payment_method(bank_account, tithelyResponseCallback);

// Callback function
function tithelyResponseCallback(status, response) {
  if (response.error) {
    // Error handling here
    console.warn(response.error.message);
  }
  else {
    // Get the token
    var token = response.id;
    console.log(response);
    // What's next?
    // Send it server side by adding this token to your form as a hidden field (or use AJAX).
  }
}

How to use the token

  • On the server side, add a payment method using the token (see payment methods documentation) and then charge the donor (see charges documentation). This will allow you to charge the payment method multiple times without adding it over and over again.
  • On the server side, charge a user once (see quick charge documentation) using the token.