Skip to content

Frontend API

1. API

Use PMdropin.API.

API描述详情
createInstantiate a built-in component参阅create
mountMount instantiated component to div tag参阅mount
onListen events参阅on
emitTrigger events参阅emit

1.1 create

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

ComponentName Explanation

ComponentNameField TypeDescription
applepaystringApplePay Compoment

Options Explanation

OptionsRequired Or NotField TypeDefault Value
clientKeyYString-
sessionKeyYString-
sandboxNBooleanfalse
themeNStringlight
payButtonStyleNString-

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('#applepay-frame')
classThe value of the class element that needs to be mounted, such as PMdropin.mount('.applepay-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
payButtonClickTriggered when the ApplePay button is clickednull

Example:

js
PMdropin.on('payButtonClick', function(event) {
  // achieve paymentToken and orderAndPay
  applePay.emit('setDisabled', true)
  applePay.emit('canMakePayment')
    .then(res => {
      const paymentToken = res?.data?.paymentToken 
      if(paymentToken){
        orderAndPay()
      }else{ 
        applePay.emit('setDisabled', false)
      }
    })
    .catch(err => {
      applePay.emit('payFail')
      applePay.emit('setDisabled', false) 
    })
    
});

1.4 emit

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

EventParamsDescription
canMakePayment-Get the payment token
switchThemestringSwitch theme
setDisabledBooleanSet the component available state
setPayButtonStylestringSet the button style
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.

canMakePayment Response:

CodeDescription
APPLY_SUCCESSGet paymentToken successfully
UNKNOWN_ISSUEException information
1.4.2 emit.switchTheme
  • Set the button theme
  • Type: Boolean
  • Default: light
Theme NameTheme typeEffect Preview
Whitelight 默认
Blackdark
1.4.3 emit.setDisabled
  • Set the component available state
  • Type: Boolean
  • Default: false
js
// Button disabled state
PMdropin.emit('setDisabled', true)

// Button enabled state
PMdropin.emit('setDisabled', false)
1.4.4 emit.setPayButtonStyle
  • Set the button style
  • Type: Boolean
  • Default: false
js
// Set the width, height, padding, and border radius of the ApplePay button
PMdropin.emit('payButtonStyle', `width:20rem;height:4rem;border-radius: 4rem;padding:1rem 4rem;`)

Was this page helpful?

Thank you for your help in improving PayerMax Product Docs!

Last updated:

Released under the MIT License.