These are the current available methods to manipulate the payment form:
Render a payment form into a given DOM selector: return a promise
with the KR
object and result.
const selector = `#myPaymentForm` // DOM selector
const { KR, result } = await KR.renderElements(selector)
NOTE: if nothing is provided renderElements will search the complete DOM for the supported HTML elements
Attach a payment form to a given DOM selector: return a promise
with the KR
object and result.
const selector = `#myPaymentForm` // DOM selector
const { KR, result } = await KR.attachForm(selector)
Add a payment form to a given DOM selector: return a promise
with the KR
object and result.
const selector = `#myPaymentForm` // DOM selector
const { KR, result } = await KR.addForm(selector)
Warning
Only for cards payment method
Display a generated payment form: return a promise
with the KR
object.
const { result } = await KR.addForm(selector)
const { KR } = await KR.showForm(result.formId)
Hide a generated payment form: return a promise
with the KR
object.
const { result } = await KR.addForm(selector)
const { KR } = await KR.hideForm(result.formId)
Set the configuration of the payment form on runtime: return a promise
with the KR
object.
const { KR } = await KR.setFormConfig({
formToken: `DEMO-TOKEN-TO-BE-REPLACED`,
language: `en-US`
})
Note
Please see the type definition file for the list of available configuration options.
Validate the payment form: return a promise
with the KR
object and validation result.
const { KR, result } = await KR.validateForm()
if (result.error) {
// Handle error
} else {
// Handle success
}
Submit the payment form: return a promise
with the KR
object.
const { KR } = await KR.submit()
Open the given payment method: return a promise
with the KR
object. The payment method must be
available in the payment form.
const { KR } = await KR.openPaymentMethod('cards')
On popin mode, open the payment form in a popin: return a promise
with the KR
object.
const { KR } = await KR.openPopin()
On popin mode, close the payment form in a popin: return a promise
with the KR
object.
const { KR } = await KR.closePopin()
Sets the label of the submit button: return a promise
with the KR
object.
const { KR } = await KR.button.setLabel('Pay now')
Enable the submit button: return a promise
with the KR
object.
const { KR } = await KR.button.enable()
Disable the submit button: return a promise
with the KR
object.
const { KR } = await KR.button.disable()
Show the loading spinner on the submit button: return a promise
with the KR
object.
const { KR } = await KR.button.showSpinner()
Hide the loading spinner on the submit button: return a promise
with the KR
object.
const { KR } = await KR.button.hideSpinner()
Set a brand on the cards payment form: return a promise
with the KR
object.
const { KR } = await KR.setBrand('visa')
Remove all generated payment forms: return a promise
with the KR
object.
const { KR } = await KR.removeForms()
Remove all event callbacks: return a promise
with the KR
object.
const { KR } = await KR.removeEventCallbacks()