JavaScript Widget

JavaScript Widget is our embeddable credit card field plugin that allows the merchant to provide a seamless payment experience to a customer without taking the liability of handling or storing sensitive cardholder information. It can be added in a few simple lines of code.

How to implement the Javascript Widget

  1. Include PaidYET's JavaScript library.
    <script src="https://cdn.paidyet.com/paynowv5.js"></script>
    
  2. Create HTML placeholder where you want the credit card fields to appear, then implement a method to trigger the payment processing. A button with an onclick event handler is shown in the following example.
    <div id="card-element-cof"></div>
    <div id="card-errors"></div>
    <button onclick="PaidYET.processPayment(callback);">Process</button>
    
  3. Initiate the card fields for a credit card payment. The {paypage subdomain} string should be replaced with the subdomain of your paypage. The JSON settings object is required. Configurable parameters that can be sent with the settings object are listed below.
    PaidYET.init('{paypage subdomain}');
    PaidYET.renderForm(settings);
    
  4. Add a callback function to handle the results. The name of this function should be the same of that which is passed into PaidYET's processPayment` function in step 2 above. The logic and operations within your callback function are dependent on the needs of your implementation.
    function callback(e) {
      if (e.success) {
        alert('Successful Request');
      }
    };
    
    The contents of the event object e in the context of your callback function are as follows:
    {
      success: Boolean,
      token: String, 
      type: String, 
      cc_last4: String
    }
    

Settings

This is a JSON object used to configure how the widget works on your page. These settings should be sent in a JSON key value format.

FieldTypeRequiredDescriptionDefault
elementstringYesThe string ID of the HTML element that the credit card form should be inserted into.
modestringNoThis configured whether the widget will securely tokenize a credit card for processing later or process a sale transaction on the credit card immediately.
Possible Values:
-sale: Process a sale transaction for a determined amount on the customers credit card.
-cardonfile: Securely tokenize a credit card. The unique token can be used to charge the customers credit card at a later time. The token can be sent in via our REST API.
sale
amountdecimalNoThis field is used to send in a default amount that will appear in the credit card form. If the hideamount field is true, this field should be sent to determine the amount charged on the customers credit card. This field is ignored if the mode is cardonfile.
notestringNoA string value sent along with the credit card transaction. This value will show up in the reports with the transaction.
hideamountbooleanNoHide the amount field from showing on form. If this field is hidden and you are processing a credit card, you will need to send in a default amount using the amount field. false
hidenotesbooleanNoHide the notes field from showing on the form.false
hidezipboolenNoHide the zip field from showing on the form. If zip is required and this field is true, use the zip field to send in a value.false
styleobjectNoThis is a JSON object used to style the elements of the widget.

Style Object


FieldDescriptionExample
paddingTopThe amount of empty space at the top of the widget'7px'
paddingBottomThe amount of empty space at the bottom of the widget'7px'
paddingLeftThe amount of empty space at the left of the widget'7px'
paddingRightThe amount of empty space at the right of the widget'7px'
borderRadiusThe amount of rounding on the border corners of the input fields'7px'
borderSizeThe width of the border around the input fields'7px'
borderColorThe color in hex code of the border around the input fields'#ececec'
Form FieldsThe following fields are for styling individual form fields.
These are nested JSON objects that can be sent to style the individual field.
Possible elements:
borderSize
borderColor
width
maxWidth
cvvThe styling that just pertains to the cvv field. {
'borderSize': '3px',
'borderColor': '#ececec',
'width': '80px',
'maxWidth': '80px'
}
cardnumberThe styling that just pertains to the cardnumber field.{
'borderSize': '3x',
'borderColor': '#ececec'
}
cardexpThe styling that just pertains to the cardexp field.{
'width': '80px'
}
amountThe styling that just pertains to the amount field.{
'width': '180px'
}
noteThe styling that just pertains to the note field.{
'borderSize': '8px'
}