PowerBoard Client SDK

This guide will provide you with instructions on how-to initialise & customise your PowerBoard Widget integration.

What is the Hosted Client SDK?

PowerBoard offers an extensively customisable client sdk that accepts all available payment methods, supports input validation, and built-in 3DS 2.0 capability.

  • It is a solution for collecting and handling payment sources in a secure way.
  • With the client SDK you can create a payment form widget as an independent part or use it directly inside your payment form.
  • The SDK supports a number of methods for customising the widget to your websites needs (styling, form fields, etc)

👍

Getting started with the Client SDK

To work with the widget you will need public_key or access_token

Also you will need a gateway id from your connected services in PowerBoard.


Environments

<script src="https://widget.preproduction.powerboard.commbank.com.au/sdk/latest/widget.umd.min.js"></script> 
<script>
    var widget = new cba.HtmlWidget('#widget', 'PUBLIC_KEY', 'GATEWAY_ID');
    widget.setEnv("preproduction_cba");
    widget.load();
</script> 
<div id="widget"></div>
<script src="https://widget.powerboard.commbank.com.au/sdk/latest/widget.umd.min.js"></script> 
<script>
    var widget = new cba.HtmlWidget('#widget', 'PUBLIC_KEY', 'GATEWAY_ID');
    widget.setEnv("production_cba");
    widget.load();
</script> 
<div id="widget"></div>

Widget Customisation

📘

Please note that the steps and code samples are generalised, so you may need to adjust them to fit your application.



Widget Classes

setFormFields

Description

Set list with widget form field, which will be shown in form. Also, you can set the required validation for these fields.

widget.setFormFields(['phone',
    'email',
    'first_name*',
    'last_name',
    'phone2',
    'address_line1',
    'address_line1',
    'address_line2',
    'address_state',
    'address_country',
    'address_city',
    'address_postcode',
    'address_company'
]);

Configurable Parameters

ParameterType
card_namestring
expire_monthstring
expire_yearstring
card_ccvstring
first_namestring
last_namestring
emailstring
phonestring
phone2string
address_line1string
address_line2string
address_statestring
address_citystring
address_postcodestring
address_companystring

Preview

Widget Preview

setFormElements

Description

Allows merchants to set and configure Widget Form elements, including:

  • visibility
  • required
  • label
  • placeholder
  • value
widget.setFormElements([
      {
          field:  'card_name*',
          placeholder: 'Input your card holder name...',
          label: 'Card Holder Name',
          value: 'Houston',
      },
      {
          field:  'email',
          placeholder: 'Input your email, like [email protected]',
          label: 'Email for the receipt',
          value: '[email protected]',
      },
  ])

Configurable Parameters

ParameterType
card_namestring
expire_monthstring
expire_yearstring
card_ccvstring
first_namestring
last_namestring
emailstring
phonestring
phone2string
address_line1string
address_line2string
address_statestring
address_citystring
address_postcodestring
address_companystring

Preview

Widget preview

setStyles

Description

Allows to set and configure styling for the Widget

widget.setStyles({
      background_color: 'rgb(0, 0, 0)',
      border_color: 'yellow',
      text_color: '#FFFFAA',
      button_color: 'rgba(255, 255, 255, 0.9)',
      font_size: '20px',
      font_family: 'fantasy'
  });

Configurable Parameters

ParameterType
background_colorstring
text_colorstring
border_colorstring
button_colorstring
error_colorstring
success_colorstring
font_sizestring
font_familystring

setTexts

Description

Method to set different texts within the widget.

  • visibility
  • required
  • label
  • placeholder
  • value
widget.setTexts({
      title: 'Your card',
      finish_text: 'Payment resource was successfully accepted',
      title_description: '* indicates required field',
      submit_button: 'Save',
      submit_button_processing: 'Load...',
  });

Configurable Parameter

ParameterType
[title]string
[title_h1]string
[title_h2]string
[title_h3]string
[title_h4]string
[title_h5]string
[title_h5]string
[title_h6]string
[finish_text]string
[title_description]string
[submit_button]string
[submit_button_processing]string

Preview

Widget

setElementStyle

Description

Method for setting customisation of the PowerBoard Widget elements and relevant states.

Element states are as follows:

  • error
  • focus
  • hover
widget.setElementStyle('input', {
  border: 'green solid 1px'
});
 
widget.setElementStyle('input', 'focus', {
  border: 'blue solid 1px'
});
 
widget.setElementStyle('input', 'error', {
 border: 'red solid 1px'
});
 
widget.setElementStyle('input', 'hover', {
  border: 'blue solid 1px'
});

Configurable Parameter

ParameterType
[title]string
[title_h1]string
[title_h2]string
[title_h3]string
[title_h4]string
[title_h5]string
[title_h5]string
[title_h6]string
[finish_text]string
[title_description]string
[submit_button]string
[submit_button_processing]string

Preview

widget-setElementStyle

setFormValues

Description

Method to set predefined values for the form fields inside the widget.

widget.setFormValues({
      email: '[email protected]',
      card_name: 'Houston'
  });

Configurable Parameters

ParameterType
card_namestring
expire_monthstring
expire_yearstring
card_ccvstring
first_namestring
last_namestring
emailstring
phonestring
phone2string
address_line1string
address_line2string
address_statestring
address_citystring
address_postcodestring
address_companystring

Preview

widget-setFormValues

setFormLables

Description

Method to set custom form field labels.

widget.setFormLabels({
      card_name: 'Card Holder Name ABC'
  })

Configurable Parameters

ParameterType
card_namestring
expire_monthstring
expire_yearstring
card_ccvstring
first_namestring
last_namestring
emailstring
phonestring
phone2string
address_line1string
address_line2string
address_statestring
address_citystring
address_postcodestring
address_companystring

Preview

widget

setFormPlaceholders

Description

Method to set custom form field labels.

widget.setFormPlaceholders({
      card_name: 'Input your card holder name...',
      email: 'Input your email, like [email protected]'
  })

Configurable Parameters

ParameterType
card_namestring
expire_monthstring
expire_yearstring
card_ccvstring
first_namestring
last_namestring
emailstring
phonestring
phone2string
address_line1string
address_line2string
address_statestring
address_citystring
address_postcodestring
address_companystring

Preview

widget

setHiddenElements

Description

Using this method, you can set hidden elements for the widget.

widget.setHiddenElements(['submit_button']);

Configurable Parameters

ParametersType
SUBMIT_BUTTONstring

Preview

widget-setHiddenElements

setRefId

Description

Method to set a custom reference when using the widget.

widget.setRefId('abc-1234567');

Configurable Parameters

ParametersType
idstring

Preview


{
    "event": "finish",
    "purpose": "payment_source",
    "message_source": "widget.paydock",
    "ref_id": "abc-1234567",
    "widget_id": "7ff7ff74-dedb-236d-0383-4d7afc8ad462",
    "payment_source": "27f2efcf-df0c-4d3e-b094-17d272c4ba97"
}

setSupportedCardIcons

Description

Sets icons of supported card types.

widget.setSupportedCardIcons(['mastercard', 'visa', 'amex']);

Configurable Parameters

ParametersTypedefault
AMEXstring"amex"
JAPCBstring"japcb"
MASTERCARDstring"mastercard"
VISAstring"visa"

Preview

setSupportedCardIcons

validateCardNumberInput

Description

Validation extension will only enforce the supported cards listed prior and everything else will get a not supported prompt

widget.setSupportedCardIcons(['mastercard', 'visa'], validateCardNumberInput = true);

setWebHookDestination

Description

Destination where customer will receive all successful responses. Response will contain “data” object with “payment_source” or other parameters, in depending on 'purpose'

widget.setWebHookDestination('http://google.com');

Configurable Parameters

ParametersTypeDescription
urlstringYour endpoint for POST request

setSuccessRedirectUrl

Description

URL to which the Customer will be redirected to after the success finish

widget.setSuccessRedirectUrl('google.com/search?q=success');

Configurable Parameters

ParametersType
urlstring

setErrorRedirectUrl

Description

URL to which the Customer will be redirected to if an error is triggered in the process of operation

widget.setErrorRedirectUrl('google.com/search?q=error');

Configurable Parameters

ParametersType
urlstring

setFormFields

Description

Set list with widget form field, which will be shown in form. Also you can set the required validation for these fields

widget.setFormFields(['phone', 'email', 'first_name*']);

Configurable Parameters

ParametersTypeDescription
fields[ 'Array' ].name of fields which can be shown in a widget. If after a name of a field, you put “*”, this field will be required on client-side. (For validation, you can specify any fields, even those that are shown by default: card_number, expiration, etc... )

load

Description

The final method to beginning, the load process of widget to html


on

Description

htmlWidget.on(eventName, [cb]) ⇒ Promise.<(IEventData|IEventMetaData|IEventFinishData|IFormValidation)> | void

Listen to events of widget.

widget.on('form_submit', function (data) {
     console.log(data);
});
// or
 widget.on('form_submit').then(function (data) {
     console.log(data);
});

Configurable Parameters

ParametersTypeDescription
eventNamestringAvailable events found here: events

trigger

Description

This callback will be called for every specified trigger

Configurable Parameters

ParametersTypeDescription
triggerstriggerNamesubmit_form, tab
dataITriggerDataData which will be sent to the widget

getValidationState

Description

This method will check the validation state of the form

Returns IFormValidation response

widget.getValidationState();

isValidForm

Description

This method will check if the form is valid

Returns Boolean - Form is valid

widget.isValidForm();

isInvalidForm

Description

Using this method you can check if a specific form field is invalid

Returns Boolean - Field is invalid

widget.isInvalidField(field);

Configurable Parameters

ParametersTypeDescription
fieldstringfield name

isInvalidFieldByValidator

Description

Using this method you can check if a specific field is invalid

Returns Boolean - Field is invalid

widget.isInvalidFieldByValidator(field, validator);

Configurable Parameters

ParametersTypeDescription
fieldstringfield name
validatorstringValidator name: Available values: required, cardNumberValidator, expireDateValidation

hide

Description

Using this method you can hide the widget after load

widget.hide([saveSize = False]);

Configurable Parameters

ParametersTypeDescription
saveSizeBooleanUsing this param you can save the iFrame's size. Default = false

show

Description

This method will show the widget after using hide

widget.show()

reload

Description

This method will reload the widget

widget.reload()

hideElements

Description

Use this method to hide any elements inside the widget

widget.hideElements(['submit_button', 'email']);

Configurable Parameters

ParametersTypeDescription
elementsarrayList of elements which will be hidden

interceptSubmitForm

Description

Widget will intercept submit of your form for processing widget

Process: click by submit button in your form --> submit widget ---> submit your form

Kind: instance method of HtmlWidget
Note: submit button in widget will be hidden.

<form id="myForm">
     <button type="submit">Submit</button>
 </form>
<!--
-->
<script>
    widget.interceptSubmitForm('#myForm');
</script>

showElements

Description

Use this method to show elements inside the widget

widget.showElements(['submit_button', 'email']);

Configurable Parameters

ParametersTypeDescription
elementsarrayList of elements which will be shown

updateFormValues

Description

Method for updating values of the form fields within the widget

widget.updateFormValues({
      email: '[email protected]',
      card_name: 'Houston'
  });

Configurable Parameters

ParametersTypeDescription
fieldValuesIFormValuesList of fields and values to be updated

onFinishInsert

Description

After the finish event of the widget, data (dataType) will be inserted into the input (selector)

widget.onFinishInsert(selector, dataType);

Configurable Parameters

ParametersTypeDescription
selectorstringcss selector
dataTypestringdata type of IEventData Object

useAutoResize

Description

Use this method to resize the iFrame according to content height

widget.useAutoResize();

usePhoneCountryMask

Description

Method to set a country code mask for the phone input

widget.usePhoneCountryMask([options]);

Configurable Parameters

ParametersTypeDescription
optionsObjectObject defining the configurable options for the phone mask
option.default_countrystringSet a default country for the mask
options.preferred_countriesarraySet list of preferred countries for the top of the select box
options.only_countriesarraySet list of countries to show in the select box.

Events

List of available event names

Event nametypedefaultResponse
AFTER_LOADstring"afterLoad"Returns IEventData event object
SUBMITstring"submit"Returns IEventData event object
FINISHstring"finish"Returns IEventFinishData event object
VALIDATIONstring"validation"Returns IFormValidation event object
VALIDATION_ERRORstring"validationError"Returns IFormValidation event object
SYSTEM_ERRORstring"systemError"Returns IEventData event object
META_CHANGEstring"metaChange"Returns IEventMetaData event object
RESIZEstring"resize"Returns IEventData event object

Interfaces

IEventData

ParameterTypeDescription
eventstringEvent name
purposestringsystem variable. Purpose of the event
message_sourcestringsystem variable. Event source
ref_idstringcustom value for identifying the result of the processed operation

IEventMetaData

ParameterTypeDescription
eventstringEvent name
purposestringsystem variable. Purpose of the event
message_sourcestringsystem variable. Event source
ref_idstringcustom value for indentifying the result of the processed operation
configuration_tokenstringToken received from our API with widget data
typestringPayment type, 'card' or 'bank account'
gateway_typestringGateway type
card_number_last4stringLast 4 digits of the card
card_schemestringCard Scheme
card_number_lengthstringCard number length

IEventFinishData

ParameterTypeDescription
eventstringEvent name
purposestringsystem variable. Purpose of the event
message_sourcestringsystem variable. Event source
ref_idstringcustom value for identifying the result of the processed operation
payment_sourcestringOne time token returned from PowerBoard

IFormValidation

ParameterTypeDescription
eventstringEvent name
purposestringsystem variable. Purpose of the event
message_sourcestringsystem variable. Event source
ref_idstringcustom value for identifying the result of the processed operation
form_validbooleanBoolean identifying if the form is valid
invalid_fieldsarrayinvalid form fields
invalid_showed_fieldsarraylist of fields on which the error is already displayed
validatorsarraylist of validators with fields

Appendix A - Advanced Widget Customisation

Elements which can accept custom styling are as follows:

  • input
  • submit_button
  • label
  • title
  • title_description

Please refer to https://developer.mozilla.org/en-US/docs/Web/CSS for further information on CSS properties.

Input Example

  widget.setElementStyle('input', {
        border: 'red solid 10px',
        border_radius: '30px'
    });

ParameterType
[color]string
[border]string
[border_radius]string
[background_color]string
[height]string
[text_decoration]string
[font_size]string
[font_family]string
[transition]string
[line_height]string
[font_weight]string
[padding]string
[margin]string

Submit Button Example

 widget.setElementStyle('submit_button', {
        border: 'green solid 10px',
        border_radius: '30px'
    });
ParameterType
[color]string
[border]string
[border_radius]string
[background_color]string
[text_decoration]string
[font_size]string
[font_family]string
[padding]string
[margin]string
[transition]string
[line_height]string
[font_weight]string
[opacity]string

Label Example

 widget.setElementStyle('label', {
        color: 'rebeccapurple'
    });
ParameterType
[color]string
[text_decoration]string
[font_size]string
[font_family]string
[line_height]string
[font_weight]string
[padding]string
[margin]string

Title Example

 widget.setElementStyle('title', {
        text_decoration: 'underline'
    });
ParameterType
[color]string
[text_decoration]string
[font_size]string
[font_family]string
[line_height]string
[font_weight]string
[padding]string
[margin]string
[text-align]string

Title Description Example

 widget.setElementStyle('title_description', {
        font_size: '42px'
    });
ParameterType
[color]string
[text_decoration]string
[font_size]string
[font_family]string
[line_height]string
[font_weight]string
[padding]string
[margin]string
[text-align]string

Appendix B - Manual Submission Trigger

If you wish to manually submit the credit card form and not use the pre-rendered 'submit' button, please use the following:

widget.setHiddenElements(['submit_button']); // Hides Pre-Rendered Submit Button

widget.trigger('submit_form'); // Manually triggers form submission and generates One-Time-Token