Paychoice.js API Reference

Paychoice.js API Reference

Overview

This describes the resources that make up the official Paychoice.js API documentation. If you have any problems or requests please contact support.

Examples will need to be altered to use the correct public key.

An example of using Paychoice.js is available on Paychoice’s GitHub page.

Schema

The API is provided over HTTPS, and accessed from secure.paychoice.com.au for production or sandbox.paychoice.com.au for testing.

Environment API Location
Live https://secure.paychoice.com.au/api/v3/paychoice.js
Testing https://sandbox.paychoice.com.au/api/v3/paychoice.js

Public Key

The public key is a key which can be published publicly in your web pages and javascript. Use the setPublicKey operation to set the public key for the Paychoice.js API.

Example
Paychoice.setPublicKey('pk_xxxxxxxxxxxx');

cardType

Gets the credit card scheme type. Returns a string with the possible values of American Express, Discover, JCB, MasterCard, Visa, Unknown.

Paychoice.cardType(cardNumber) :: returns string

cardNumber

  • Type: string
  • The primary account number on the front of the credit card.

createToken

Stores the credit card details securely and returns a token which can be used only once at a later date to charge the credit card on the server side.

If you wish to use the token more than once, you should use the createDurableToken() function instead.

The merchants public key must be set by calling setPublicKey() before using this function.

Paychoice.createToken(cardInfo, callback) :: returns object

cardInfo

  • Type: object
  • A map of the credit cards information.

name

  • Type: string
  • The name of the credit card holder located on the front of the credit card.

number

  • Type: string
  • The primary account number on the front of the credit card.

cvv

  • Type: integer
  • The CVV/CVC located on the back of the credit card.

expiry_month

  • Type: integer
  • A two digit value representing the expiration month for the credit card.

expiry_year

  • Type: integer
  • A two digit value representing the expiration year for the credit card.

callback

  • Type: function(integer status, object result)
  • The function which gets called after communicating with the Paychoice server. The function gets passed two parameters: an integer http status code response and a result object in the form of an error or card depending on whether the credit card is valid and was successfully saved.

createDurableToken

Stores the credit card details securely and returns a token which can be used at a later date to charge the credit card on the server side.

The returned token from this function can be used more than once. If you only want to use the token once, please refer to the createToken() function.

The merchants public key must be set by calling setPublicKey() before using this function.

Paychoice.createDurableToken(cardInfo, callback) :: returns object

cardInfo

  • Type: object
  • A map of the credit cards information.

name

  • Type: string
  • The name of the credit card holder located on the front of the credit card.

number

  • Type: string
  • The primary account number on the front of the credit card.

cvv

  • Type: integer
  • The CVV/CVC located on the back of the credit card.

expiry_month

  • Type: integer
  • A two digit value representing the expiration month for the credit card.

expiry_year

  • Type: integer
  • A two digit value representing the expiration year for the credit card.

callback

  • Type: function(integer status, object result)
  • The function which gets called after communicating with the Paychoice server. The function gets passed two parameters: an integer http status code response and a result object in the form of an error or card depending on whether the credit card is valid and was successfully saved.

setPublicKey

Sets the public key to be used when connecting to the merchants account.

Paychoice.setPublicKey(publicKey)

publicKey

  • Type: string
  • The public key which is assigned to the merchant account.

validateCardNumber

Validates the credit card number. This function should be used to validate the users input and can be used in conjunction with jQuery validate.

Paychoice.validateCardNumber(cardNumber) :: returns boolean

cardNumber

  • Type: string
  • The primary account number located on the front of the credit card.

validateCVV

Validates the credit cards CVV/CVC. This function should be used to validate the users input and can be used in conjunction with jQuery validate.

Paychoice.validateCVV(cardCvv) :: returns boolean

cardCvv

  • Type: string
  • The CVV/CVC located on the back of the credit card.

validateExpiry

Validates the credit cards expiry date. This function should be used to validate the users input and can be used in conjunction with jQuery validate.

Paychoice.validateExpiry(month, year) :: returns boolean

month

  • Type: integer
  • A two digit value representing the expiration month for the credit card.

year

  • Type: integer
  • A two digit value representing the expiration year for the credit card.

validateToken

Validates a credit card token which was previously issued by .createToken(). This is function is a way to check if the token has expired or already been used.

The merchants public key must be set by calling setPublicKey() before using this function.

Paychoice.validateToken(token) :: returns boolean

token

  • Type: string
  • The credit card token which was previously issued by .createToken().

Objects are returned from operations which have completed.

Error

{
  "error": {
    "message": "{the error message}",
    "param": "{the parameter which the message refers to}"
  },
  "object_type": "error"
}

Card

{
  "card": {
    "card_name": "John Citizen",
    "card_type": "Visa",
    "expiry_month": "12",
    "expiry_year": "14",
    "link": {
      "href": "/api/v3/token/ffe98527-add1-4048-9cdf-cc03da0e84a8",
      "rel": "self"
    },
    "masked_number": "411111XXXXXX1111",
    "token": "ffe98527-add1-4048-9cdf-cc03da0e84a8"
  },
  "object_type": "card"
}
(*) Required Fields