---
title: EMBED Credit Card Script
slug: embed-credit-card-script
createdAt: 2022-03-23T02:38:33.000Z
---

Used to tokenize credit card data before submitting data to FeatherPay API for Saving Credit Card

From your frontend code:

1. Embed JavaScript
2. Initialize Script
3. Specify Configuration
4. Read token from `onSuccess`  function call



\#1) Embed JavaScript

- Include (for Prod):

:::BlockQuote
\<**script** src="https\://pay.featherpay.io/featherpaycard.js">\</**script**>
:::

- Include (for Sandbox):

:::BlockQuote
\<**script** src="https\://gfp-pay.acdev.io/featherpaycard.js">\</**script**>
:::

\#2) Initialize Script

```javascript
new FeatherPayCreditCard({ selector: '#form' });
```

\#3) Specify Configuration

:::ApiMethodV2
```json
{
  "tab": "examples",
  "url": "From embedded Script",
  "name": "Specify Configuration",
  "method": "GET",
  "request": {
    "pathParameters": [],
    "queryParameters": [],
    "headerParameters": [],
    "bodyDataParameters": [
      {
        "kind": "required",
        "name": "selector",
        "type": "string",
        "description": "Set when Initializing Script.  Any CSS selector for a single target element on the webpage or any node on the webpage page."
      },
      {
        "kind": "required",
        "name": "mode",
        "type": "string",
        "children": [],
        "description": "`production` or `sandbox`.  \n\nDefault: `sandbox`"
      },
      {
        "kind": "optional",
        "name": "mount",
        "type": "string",
        "children": [],
        "description": "`before`, `after`, `replace`, or `false`. \n\nDefault: `replace`. \n\n`before` will mount before the supplied selector.\n\n`after` will mount after the supplied selector\n\n`replace` will remove all children of the selector and insert the form into it\n"
      },
      {
        "kind": "optional",
        "name": "fields",
        "type": "Array",
        "children": [],
        "description": "Each field with the expectation of submit can have its name, label, and type changed. The submit field can only have its label change."
      },
      {
        "kind": "required",
        "name": "displayFields",
        "type": "Array",
        "children": [],
        "description": "An array of arrays containing the name of fields.\n\nWill change what wrapper and the order the fields are rendered in. Removing a field from this will prevent it from rendering. Required fields, creditcard, expiry, cvv."
      },
      {
        "kind": "optional",
        "name": "onReady",
        "type": "Object",
        "children": [],
        "description": "Default: false\n\nA method to execute when the form is ready to be mounted or nothing at all."
      },
      {
        "kind": "optional",
        "name": "onChange",
        "type": "string",
        "children": [],
        "description": "Default: false\n\nA method to execute when a form field is changed or nothing at all.\n\nArgs: The field string (creditcard, cvv), the html input field, the field value, and the validation status of the field."
      },
      {
        "kind": "optional",
        "name": "onInvalid",
        "type": "string",
        "children": [],
        "description": "Default: false\n\nA method to execute when the form is set to invalid (cant be submitted) or nothing at all."
      },
      {
        "kind": "optional",
        "name": "onValid",
        "type": "string",
        "children": [],
        "description": "Default: false\n\nA method to execute when the form is set to valid (can be submitted) or nothing at all."
      },
      {
        "kind": "optional",
        "name": "onSubmit",
        "type": "string",
        "children": [],
        "description": "Default: false\n\nA method to execute when the form is submitted or nothing at all.\n\nThe form submission can be blocked by passing a return value of false in the supplied onSubmit method. \n\nArgs: An object of the current form values."
      },
      {
        "kind": "optional",
        "name": "onSuccess",
        "type": "string",
        "children": [],
        "description": "Default: false\n\nA method to execute when the form has been submitted successfully or nothing at all.\n\nAn object of the current form values, FeatherPay save payment object "
      },
      {
        "kind": "optional",
        "name": "onFailure",
        "type": "string",
        "children": [],
        "description": "Default: false\n\nA method to execute when the form has failed to be submitted successfully or nothing at all."
      }
    ],
    "formDataParameters": []
  },
  "results": {
    "languages": [
      {
        "id": "Ws4FZPO14lm1bOVHpyYXs",
        "code": "{\n    \"name\": \"Cake's name\",\n  }",
        "language": "200",
        "customLabel": ""
      },
      {
        "id": "re1nCDSV-TAHvwEP3MnwW",
        "code": "{\n    \"message\": \"Ain't no cake like that.\"\n  }",
        "language": "404",
        "customLabel": ""
      }
    ],
    "selectedLanguageId": "Ws4FZPO14lm1bOVHpyYXs"
  },
  "examples": {
    "languages": [
      {
        "id": "9fXTufcliPh_TyspykUH0",
        "code": "const defaultConfig =\n{\n    mode: 'production',\n    mount: 'replace',\n    fields:\n    {\n        name:\n        {\n            name: 'name',\n            label: 'Name on Card',\n            type: 'text'\n        },\n        creditcard:\n        {\n            name: 'creditcard',\n            label: 'Credit Card Number',\n            type: 'tel'\n        },\n        expiry:\n        {\n            name: 'expiry',\n            label: 'Expiry Date',\n            type: 'tel'\n        },\n        cvv:\n        {\n            name: 'cvv',\n            label: 'CVV',\n            type: 'number'\n        },\n        zipcode:\n        {\n            name: 'zipcode',\n            label: 'Zipcode',\n            type: 'tel'\n        },\n        submit:\n        {\n            label: 'Submit'\n        }\n    },\n    displayFields: [['name'],['creditcard'],['expiry','cvv','zipcode'],['submit']],\n    onReady: false,\n    onChange: false,\n    onInvalid: false,\n    onValid: false,\n    onSubmit: false,\n    onSuccess: false,\n    onFailure: false\n};",
        "language": "javascript",
        "customLabel": ""
      }
    ],
    "selectedLanguageId": "9fXTufcliPh_TyspykUH0"
  },
  "description": "Tokenize Credit Card Data",
  "currentNewParameter": {
    "label": "Body Parameter",
    "value": "bodyDataParameters"
  }
}
```
:::

\#4) FeatherPay Sample Card Response that will be set as an argument in `onSuccess`&#x20;

```javascript
{
    "cardType": "visa",
    "ephemeralToken": "9422925921134242",
    "paymentType": "CardPointeOrderPayment",
    "orderPaymentType": "CardPointeOrderPayment",
    "expiry": "1123",
    "paymentSubType": "Card not present"
}
```

