Skip to content

Card Payment Frontend API ​

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
saveCardCheckedNBooleantrue
ignoreUserCheckedCacheNBooleanfalse
hideRecommendAccountNBooleanfalse
openTermsInCurrentPageNBooleanfalse
termsPopupConfigNObject-
>>showMaskNBooleantrue
>>closeOnClickMaskNBooleantrue

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
loadTriggered when the component completes loadingObject
- type:Component type card/applepay/googlepay
- code:Response code SUCCESS indicates that the loading is successful, and the rest of the enumerations indicate that the loading failed
- msg:response message

Example:

js
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.

js
// 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 errors
    console.log(error);
  })

canMakePayment Response:

js
// Successful API example
{
  code: 'APPLY_SUCCESS',
  data: {
    // Card indentification
    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
js
// Uneditable status
PMdropin.emit('setDisabled', true)

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

1.4.7 emit.setRtl ​

  • Set component layout from right to left
  • Type: Boolean
  • Default: false
js
// 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
js
// Set 0 - 1 grayscale value
PMdropin.emit('setGrayscale', '1')

Was this page helpful?

Thank you for your help in improving PayerMax Product Docs!

Released under the MIT License.