Skip to content

Detailed configuration

This page introduc all configuration details of the card components.

1. API

Use PMdropin.API.

APIDescriptionDetails
createInstantiate a built-in componentrefer to create
mountMount instantiated component to div tagrefer to mount
onListen eventsrefer to on
emitTrigger eventsrefer to emit

1.1 create

Used to initialize components, please use PMdropin.create(ComponentName, Options).

ComponentName Explanation

ComponentNameField TypeDescription
CardStringCard Compoment

Options Explanation

OptionsRequired Or NotField TypeDefault Value
clientKeyYString-
sessionKeyYString-
sandboxNBooleanfalse
languageNStringen
themeNStringlight
customLocalizationNObject-
customThemeNObject-
grayscaleNString'0'
isRtlNBooleanfalse
hideSaveCardNBooleanfalse
hideCardBrandsNBooleanfalse
hideCardHolderNameNBooleanfalse

1.2 mount

Used to mount initialization component instances, please use PMdropin.mount(Tag).

Tag Explanation

TagDescription
idThe value of the id element that needs to be mounted, such as PMdropin.mount('#card-frame')
classThe value of the class element that needs to be mounted, such as PMdropin.mount('.card-frame')

1.3 on

Used to listen to component built-in response events, please use PMdropin.on(Event, CallbackFunction).

Event Explanation

TagDescriptionReturned Value
readyTriggered when the component completes loadingnull
form-checkMonitor card component verification status real-timerefer to Event Response

Example:

PMdropin.on('form-check', function(event) {
  if (event.isFormValid) {
    // Form verification passed
  }
});

1.4 emit

Used to call component built-in methods, please use PMdropin.emit(Event, Params).

EventParamsDescription
canMakePayment-Get card identification
switchLanguagestringSwitch language
switchThemestringSwitch theme
addLocalizationObjectAdd customized language
addThemeObjectAdd customized theme
setDisabledBooleanSet component availability status
setRtlBooleanSet component layout from right to left
setGrayscalestringSet component page grayscale
1.4.1 emit.canMakePayment

Check whether the current component status meets the conditions for initiating payment, and return the card identification if the verification passes.

// Example
PMdropin.emit('canMakePayment')
  .then(function(response) {
    // Verification successful
    if (response.code === 'APPLY_SUCCESS') {
      // Get paymentToken 
      var paymentToken = response.data.paymentToken
      // Go for subsequent payment operations
    }
  })
  .catch(function(error) {
    // Catching internal exception errors
    console.log(error);
  })

canMakePayment Response:

// Success API example
{
  code: 'APPLY_SUCCESS',
  data: {
    // Card identification
    paymentToken: 'xxx'
  },
  msg: ''
}

// Failed API example
{
  code: 'FORM_INVALID',
  msg: 'Invalid params: cvv'
}
CODE码Description
APPLY_SUCCESSSuccessfully obtain paymentToken
FORM_INVALIDForm validation failed
UNKNOWN_ISSUEException information
1.4.2 emit.switchLanguage
1.4.3 emit.switchTheme
1.4.4 emit.addLocalization
1.4.5 emit.addTheme
1.4.6 emit.setDisabled
  • Set component availability status
  • Type: Boolean
  • Default: false
// Uneditable state
PMdropin.emit('setDisabled', true)

// Editable state
PMdropin.emit('setDisabled', false)

1.4.7 emit.setRtl
  • Set component layout from right to left
  • Type: Boolean
  • Default: false
// Right to left layout
PMdropin.emit('setRtl', true)

// Left to right layout
PMdropin.emit('setRtl', false)

1.4.8 emit.setGrayscale
  • Set component page grayscale
  • Type: String
  • Default: 0
// Set 0-1 grayscale value
PMdropin.emit('setGrayscale', '1')

Released under the MIT License.