Components
Version 17.05.2021
08.04.2022
- Added Monri components - CVV component documentation21.05.2021
- Added Crypto Currencies - PayCek documentation19.02.2021
- Updated Components Style section, addedborderTop
,borderRight
,borderBottom
andborderLeft
27.10.2020
- Updated addChangeListenersection, added selected installment event listener20.10.2020
- Updated addChangeListener section, added cvv event listener15.10.2020
Updated Components Style section, added 'box-shadow'
Added support for installments selection via showInstallmentsSelection
06.10.2020
- Updated Components Style section, added more supported properties and style object structure01.09.2020
- Updated supported_payment_methods section, added support forcard
payment method03.07.2020
- Added addChangeListener section30.06.2020
- Added supported_payment_methods section20.05.2020
- Some typo fixes and clarifications05.05.2020
- Initial version
Content
HTTPS requirements
All submissions of payment info using Components are made via a secure HTTPS connection. However, to protect yourself from certain forms of man-in-the-middle attacks, and to prevent your customers from seeing Mixed Content warnings in modern browsers, you must serve the page containing the payment form over HTTPS as well.
In short, the address of the page containing Components must start with https:// rather than just http://. If you are not familiar with the process of buying SSL certificates and integrating them with your server to enable a secure HTTPS connection, check out our security documentation for more information.
Creating New Payment on Merchant's Backend
This step is preferably executed when you have enough information to create customer's order.
You can find a demo on this link Demo Components
Check Payment API integration for more details.
Confirm payment on merchant's application
After you've created payment on a backend and sent client_secret
back to your application you need to confirm payment using Monri Components.
Steps:
ensure you have valid
client_secret
(created on backend using payment/new)create a custom payment form
confirm payment using
monri.confirmPayment
handle
ConfirmPaymentResponse
Creating a custom payment form
Creating a custom payment form with Components requires two steps
Set up Monri Components
Create your payment form
Step 1: Set up Monri Components
Components is available as part of Monri.js . To get started, include the following script on your pages. This script must always load directly from monri.com in order to remain PCI compliant—you can’t include it in a bundle or host a copy of it yourself.
Next, create an instance of Components:
Replace <authenticity-token>
with value provided in merchant dashboard. Replace <client-secret>
with value obtained in step Creating New Payment on Merchant's Backend
When you’re ready to accept live card payments, replace the authenticity_token
and merchant_key
with your production authenticity_token
and merchant_key
.
Monri Options
Additional options can be passed as optional second parameter to Monri
constructor, which additionally can customise Monri Components. Currently supported options are:
locale
locale which will be used (details below),fonts
list of fonts that will be used for custom styling (also explained below)
Step 1.1: localise components
Components can be localised via specifying locale
in Monri Options. For example, to use hr
locale in Monri Components (and all underlying components), {locale: 'hr'}
can be specified as a second parameter.
As of now, supported locales are:
hr
locale for Croatia (ICUhr_HR
)en
locale for USA (ICUen_US
)sr
locale for Serbia (ICUsr_SR
)
By "locale" here is assumed "language" only. Number format, date format, etc., as of time of writing, are not supported. By default, en
locale is used.
Step 1.2: style components
Components can be stylised via additionally provided fonts in Monri Options. Fonts are provided as an array of FontFace
objects, with these properties:
family
Family of the font face.src
Path to the font source. Path can be absolute (onlyhttp
andhttps
URI schemes are supported) or relative to the hostname of the hosting/parent web sitedisplay
Specifies how font files are loaded and displayed by browser. Supported values areauto
,block
,swap
,fallback
andoptional
. If this property is omitted,auto
is used by default. For more information about these values please see this link.weight
The weight of the fontstyle
Specifies the font style. Supported values arenormal
,italic
andoblique
. If omitted,normal
is used.stretch
Specifies front stretch property.unicode-range
The unicode range from font which browser will select to use. If omitted, all characters of font will be selected and thus available for use.
The family
and src
properties are required, others are optional and have default values.
List of fonts is passed as fonts
property in Monri Options, like:
Localization options and style option can be, of course, combined, like:
Step 2: Create your payment form
To securely collect card details from your customers, Components creates UI components for you that are hosted by Monri. They are then placed into your payment form, rather than you creating them directly.
To determine where to insert these components, create empty DOM elements (containers) with unique IDs within your payment form. We recommend placing your container within a <label>
or next to a <label>
with a for
attribute that matches the unique id
of the Element container. By doing so, the Element automatically gains focus when the customer clicks on the corresponding label.
For example:
(Note: if inserted payment form is invisible, this may be a CSS issue. Start diagnostics by removig class form-row
, the only one CSS in example)
When the form above has loaded, create an instance of an Component and mount it to the Component container created above:
The card
Component simplifies the form and minimises the number of fields required by inserting a single, flexible input field that securely collects all necessary card details.
In addition to the card component, we also offer a saved card component and cvv component. They can be easily created like as the card mentioned above. For example:
Default payment method is provided via supported payment_methods to change it on cvv component you can call setActivePaymentMethod where you have to provide valid token for saved card.
Styling components
Components can be styled via style
property of second parameter in create
method, as shown above in example. For all styling options please see section Components - style
Validation & listening to changes
Validating component
Components validates user input as it is typed. To help your customers catch mistakes, you should listen to change
events on the card
Component and display any errors:
Reacting to input element change - addChangeListener
addChangeListener
We support adding changeListener
via addChangeListener
method. To add change listener simply invoke:
It's possible to add change listener for:
Card number by using
card_number
Expiry date by using
expiry_date
Cvv by using
cvv
Card Number
To add card number change listener execute:
Event details
key:
card_number
event
data: object
bin:
String | null, min-length: 6, max-length: 6
, only available if user has entered at least 6 digits, null otherwisebrand:
String
, one ofvisa, master, amex etc
element:
String
- in this case it'scard_number
message:
String | null
- non null if card number input is invalidvalid:
boolean
- false if input is invalid
Example event data:
Save Card
To add save card change listener execute:
Event details
key:
save_card
event
data: object
checked:
boolean
element:
String
- in this case it'ssave_card
message:
String | null
- non null if card number input is invalidvalid:
boolean
- always true for this event
Example event data:
Expiry Date
To add expiry date change listener execute:
Event details
key:
expiry_date
event
data: object
month:
Number
, 1 - 12year:
Number
, eg 2024
element:
String
- in this case it'sexpiry_date
message:
String | null
- non null if expiry date is in past or invalidvalid:
boolean
- false if input is invalid
Example event data:
CVV Change Event
To add cvv change listener execute:
Event details
key:
cvv
event
data:
object
- empty objectelement:
String
- in this case it'scvv
message:
String | null
- non null if cvv is invalidvalid:
boolean
- false if input is invalid
Example event data:
Installments Event
To add selected installment change listener execute:
Event details
key:
installments
event
data: object
selectedInstallment:
Number
element:
String
- in this case it'sinstallments
message:
String | null
- non null if cvv is invalidvalid:
boolean
- false if input is invalid
Example event data:
Confirm Payment using Monri Components
Step 1: Invoke confirmPayment when you are ready to confirm order
The payment details collected using Components can be used to confirm payment.
Although payment can be confirmed at any moment it is a good practice to intercept form submit and then invoke monri.confirmPayment
.
confirmPayment
accepts two arguments:
component - component you've created using
components.create
transaction params
address
fullName
city
zip
phone
country
email
orderInfo
All transaction params fields are validated using rules defined in Variables - names, lengths and formats
Create an event handler that handles the submit
event on the form. The handler invokes confirmPayment
which confirms transaction and returns Result<PaymentResult>
.
IMPORTANT 3DS authentication is automatically handled by Monri Components library.
Card Component
Step 2: Handle Payment Result
The last step is to handle payment result. This step completely depends on application use case. Response can be submitted to the merchant's backend or handled in application.
If you want secure and stable transaction processed notification continue to the section Getting payment result on merchant's backend
Crypto Currencies
Paycek payments
Step 1: Set up PayCek Component
PayCek component is available as part of Monri.js. To get started include the following script on your pages. This script must always load directly from monri.com in order to remain PCI compliant you can’t include it in a bundle or host a copy of it yourself.
Test Environment
Production Environment
Next, create an instance of Components:
Replace <authenticity-token>
with value provided in merchant dashboard. Replace <client-secret>
with value obtained in step Creating New Payment on Merchant's Backend
When you’re ready to accept live payments, replace the authenticity_token
and merchant_key
with your production authenticity_token
and merchant_key
.
Monri Options
Additional options can be passed as optional second parameter to Monri
constructor, which additionally can customise Monri Components. Currently supported options are:
locale
locale which will be used (details below)
Step 1.1: localize components
Components can be localized via specifying locale
in Monri Options. For example, to use hr
locale in Monri Components (and all underlying components), {locale: 'hr'}
can be specified as a second parameter.
For more details check localize components
Step 2: Create your payment form
To determine where to insert these components, create empty DOM elements (containers) with unique IDs within your payment form. For example:
(Note: if inserted payment form is invisible, this may be a CSS issue. Start diagnostics by removing class form-row
, the only one CSS in example)
When the form above has loaded, create an instance of PayCek Component and mount it to the PayCek Component container created above:
Confirm Payment
Step 1: Invoke confirmPayment when you are ready to confirm order
Although payment can be confirmed at any moment it is a good practice to invoke monri.confirmPayment
.
confirmPayment
accepts two arguments:
component - component you've created using
components.create
transaction params
address
fullName
city
zip
phone
country
email
orderInfo
All transaction params fields are validated using rules defined in Variables - names, lengths and formats
Create an event handler that handles the submit
event on the form. The handler invokes confirmPayment
which confirms transaction.
Getting payment result on merchant's backend
Although you can easily collect payment result directly in application via onSuccess
call it's better to implement callback listener (WebHook) on your backend.
Requirements:
it must be available over the Internet
it must be secured (HTTPS)
it must be set in merchant's setup on Monri's dashboard (if you are not able to set this value contact support@monri.com)
How it works:
upon transaction processing and approval we'll send POST request to callback endpoint defined in merchant's settings
validate received request to check if it's from us
update/deliver order
Example of POST request sent to callback endpoint:
Body:
Headers:
header | value |
---|---|
accept-encoding | gzip;q=1.0,deflate;q=0.6,identity;q=0.3 |
authorization | WP3-callback d5e4528ad8a0e0f4262e518c663d5ff83cd4a8f381db68f9d30f99961409ceebb719c16d423757fc36c532b902c987012f5825dc8d32dde3a9b7ed95876be77a |
content-type | application/json |
http_authorization | WP3-callback d5e4528ad8a0e0f4262e518c663d5ff83cd4a8f381db68f9d30f99961409ceebb719c16d423757fc36c532b902c987012f5825dc8d32dde3a9b7ed95876be77a |
user-agent | Faraday v0.15.4 |
content-length | 621 |
connection | keep-alive |
Where authorization
and http_authorization
headers are created as:
digest = sha512(merchant_key + body)
You can check digest on this link Calculate Digest
authorization_header_value = WP3-callback digest
To check if request is valid check:
if authorization header schema is
WP3-callback
extract digest as second part
verify digest
Viewport meta tag requirements
In order to provide a great user experience for 3D Secure on all devices, you should set your page’s viewport width
to device-width
with the the viewport meta tag. There are several other viewport settings, and you can configure those based on your needs. Just make sure you include width=device-width
somewhere in your configuration.
For instance the following will work with Components:
If you already have this tag on your page and it includes width=device-width
, then you are all set.
Components
All Components accept a common set of options, and then some Component-specific options.
Style
Customize appearance using CSS properties. Styles are passed via the style
property of options.
Style property consist of four properties which represent the states of the component elements (e.g. card fields). There is base
property which defines style that is applied to each component element, and there are three additional properties which, if specified, will override the base
style. These properties are:
complete
style applied when component element is completed e.g. filled with valid valueempty
style applied when component element is empty (focus is moved away but element remained without entered value)invalid
style applied when component element contains invalid value. Style is applied only when element loses focus
Additionaly, as shown in example below, style property of label elements, input elements, remember card label element and select payment method element can be set explicitly.
Styles are applied to all component elements based on their state which had focus at least once. Currently, available style properties are as follows, all of string type and all optional:
Attribute | CSS attribute | Description |
---|---|---|
|
| size of the font |
|
| component element color |
|
| family of the font |
|
| selected font smoothing |
|
| variant of the font |
|
| font weight |
|
| font letter spacing |
|
| component element text decoration |
|
| component element text shadow |
|
| component element text transform |
|
| component element border |
|
| component element top border |
|
| component element right border |
|
| component element bottom border |
|
| component element left border |
|
| component element border radius |
|
| component element padding |
|
| component element margin |
|
| component element line height |
|
| component element text indent |
|
| component element position |
|
| component element top |
|
| component element bottom |
|
| component element left |
|
| component element right |
|
| component element width |
|
| component element background color |
|
| component element height |
|
| component element height |
Example of custom style:
Style object has structure like the one below, where empty fields can be omitted:
Component specific options
Card Component Options
Card component options extends shared component options with:
option | type | description | default value |
---|---|---|---|
| boolean | tokenize PAN when the client enters card info | false |
| boolean | offer the client to tokenize his PAN | false |
| boolean | show installments select if installments are enabled for merchant | false |
Option: tokenizePan
If enabled, PAN is tokenizen upon transaction approval and pan_token
value is populated in transaction response.
Example:
Option: tokenizePanOffered
If enabled save card for future payments
checkbox is presented to a customer. If user checks the checkbox, PAN is tokenized upon transaction approval and pan_token
value is populated in transaction response.
Example:
NOTICE
- if tokenizePan
is set to true
then tokenizePanOffered
is ignored. NOTICE
- setting tokenizePan
to true
requires user consent beforehand, in form of accepting terms and conditions or alike.
Option: showInstallmentsSelection
If enabled & merchant has enabled installments then dropdown for installments selection will be shown.
Example:
NOTICE
- if set to true
and not shown then installments for merchant are disabled. Contact [support@monri.com](mailto:support@monri.com?subject=Monri Components Installments-Enable for merchant)
Transactions API
Variables - names, lengths and formats
Here are the variables and their definitions used when generating JSON documents for API calls:
Buyer's profile
name | length | format | additional info |
---|---|---|---|
ch_full_name | 3-30 | alphanumeric | buyer's full name |
ch_address | 3-100 | alphanumeric | buyer's address |
ch_city | 3-30 | alphanumeric | buyer's city |
ch_zip | 3-9 | alphanumeric | buyer's zip |
ch_country | 2-3 | alphanumeric | buyer’s country in alpha2, alpha3 letter code or 3 digit ISO numeric code |
ch_phone | 3-30 | alphanumeric | buyer's phone |
ch_email | 3-100 | alphanumeric | buyer's email |
Order details
name | length | format | additional info |
---|---|---|---|
order_info | 3-100 | alphanumeric | short description of order being processed |
order_number | 1-40 | printable characters | unique identifier |
amount | 3-11 | integer | amount is in minor units, ie. 10.24 USD is sent as 1024 |
currency | predefined | alphabetic | possible values are USD, EUR or BAM |
Last updated