Integration using a microframe solution
Overview
Payment Page microframe is an embedded payment solution by ecommpay that allows merchants to use the essential functionality of the ecommpay payment form while retaining full control of the checkout experience for their customers with the least amount of setup effort. Payment Page microframe provides the capability necessary to establish a one-page checkout process with the minimalist payment form (which contains only three required fields) and the button for submitting the payment developed on the merchant side.
The basic steps of the customer payment scenario with the microframe solution are the following:
- The customer indicates the readiness to pay in the merchant's web service. The microframe solution is invoked and the payment form is displayed to the customer.
- The customer provides payment information by filling in the fields on the form and clicks the button to pay.
- As the processing of the payment starts, the payment form can be hidden and a preloader element (configured on the web service side) can be shown to the customer.
- Once the payment has been processed, the customer is redirected to the page with the payment result information.
Processing of the payment may also require performing additional steps. If the specified payment information is invalid or any of the fields is left empty, the customer can be notified via a message set up on the web service side and shown on the same page where the payment form is embedded. If the 3‑D Secure authentication with the challenge flow is required to process the payment, the customer is redirected to the ACS page. If, due to the payment method specifics, submitting additional customer information is required (their billing address, for example), this information should be collected before the microframe solution is invoked and should be specified in the initial request to open the solution.
Setup
To implement the ecommpay microframe solution:
- Set up data signing using one of the specialised SDKs in the web service backend.
- Set up the checkout page where the microframe is to be invoked. Use the following links to add ecommpay CSS and JavaScript libraries:
- Make sure that all necessary parameters are collected before the ecommpay widget (
EPayWidget
) is run to invoke the microframe.The minimum set of required microframe invocation parameters to be used in the web service integration project is presented below. The comprehensive list of parameters used in requests for opening Payment Page can be found in this article.
Keep in mind that you can use both the HTTP POST and GET methods for sending requests when you work with the widget.
There are two methods that can be used to run the EPayWidget
to invoke the microframe:
bind
(EPayWidget.bind
)—if the payment form should be opened with a button click.run
(EPayWidget.run
)—if the payment form should be opened upon any other event in the user interface.
Once the microframe has been invoked, there are two ways how you can set up the submission of the payment form to initialise the payment. You can:
- Set up sending the
epframe.embedded_mode.submit
message to the microframe. - Use the
data-epwidget="ep-run-transaction"
attribute for your payment button.
As a rule, the payment form is submitted when the customer clicks the Pay button in the invoked microframe, but you can configure it differently, if need be.
The following are the steps to prepare the code to invoke the microframe.
- Create a widget container:
<div class="container"> <div id="widget-container"></div> </div>
- On the server side of the web service, create an object containing parameters for opening the payment form (below) and signature (to simplify the process, use SDKs for data signing). The list of parameters must include the
target_element
with the identifier of the widget container. - Pass this object to the client side.
- Depending on your needs, you can either add the microframe invocation event handler or set up processing of the
epframe.loaded
messages (the detailed description of the communication between the web service and the microframe with the use of the postMessage method can be found below).configObj.onLoaded = () => {console.log('Microframe is loaded')};
- Set up sending the
epframe.embedded_mode.submit
message to the microframe to submit the payment form, or use thedata-epwidget="ep-run-transaction"
attribute for your payment button. - If you need to open the payment form by the button click, then use the
EPayWidget.bind()
method and specify the identifier of the button.EPayWidget.bind('showMicroframeButtonId', configObj)
Otherwise, use the
EPayWidget.run
method to invoke the microframe.EPayWidget.run(configObj)
The following is an example of the HTML code for the web service frontend that runs the widget using merchant.js script.
If necessary, you can customise the appearance of the payment form using the Payment Page Designer in Dashboard. You can modify the colour of different elements and the texts on the form (for a detailed guide on how to work with the Payment Page Designer, go to Customisation).
Once you set up the solution, you can test payment processing using test cards details (use 4000 0000 0000 0077
for a purchase to be processed and 4111 1111 1111 1111
for a purchase to be declined) and proceed to taking real payments using the microframe.
Workflow
By default, using the ecommpay microframe solution allows processing one-step purchases. This type of checkout works right out-of-the-box and requires no additional setup. The communication between the ecommpay microframe and the merchant web service is handled with the use of the postMessage method. The event handler functions necessary to establish the interaction are included in the merchant.js
library and are enough to ensure essential communication. The messages sent from the microframe to the merchant web service are intended more for informational purposes rather than functional use: that is, the way they are utilised on the web service side is at the discretion of the merchant. However, the epframe.embedded_mode.submit
message sent from the merchant web service to the microframe has functional use and is necessary for ensuring proper initiation of payment processing. The description of messages and the events that trigger them can be found in the table below.
If the payment request is submitted and no additional steps are required for payment processing, the payment status information is sent in a message from the microframe to the checkout page and directly to the web service backend (via callbacks) after the payment is completed. If the 3‑D Secure authentication is required, the customer is redirected to the 3‑D Secure authentication page automatically.
The following is a step-by-step description of the payment flow with the communication between the web service and the ecommpay microframe with the use of the postMessage method:
-
When the customer is ready to pay, invoke
EPayWidget.run
. Once the microframe loads, it sends anepframe.loaded
message (to signify that the contents of the microframe is loaded). -
Once the customer confirms the payment, the merchant web service sends the
epframe.embedded_mode.submit
message to the microframe to submit the payment form. - The microframe responds with the result of the accuracy check in an
epframe.validation.status.change
postMessage. - If there is insufficient payment data, the missing data can be submitted via the
epframe.embedded_mode.submit
postMessage. - If the customer is redirected to an ACS page for 3‑D Secure authentication, once all actions on the redirection page are completed, the customer is redirected to one of the URLs passed as a value of the
redirect_success_url
orredirect_fail_url
parameter depending on the final payment status. - Whenever the microframe receives a callback indicating the final payment status, it sends one of the following messages containing the payment status:
[epframe.card.verify.success]
[epframe.card.verify.fail]
[epframe.payment.success]
[epframe.payment.fail]
In addition to receiving messages with the payment status, you can monitor up-to-date payment processing information at the API level—through callbacks sent automatically according to a set of specified conditions (to learn more, see Callbacks) and responses to payment status requests (to learn more, see Checking current payment information). You can also view consolidated payment processing data in the Dashboard interface.
Message handling
The following is an example of the JavaScript code that can be used to work with the postMessage method.
function handleErrors(errors) { if (!Object.values(errors).length) { $errorsContainer.classList.add('invisible') return; } clearErrorContainer() $errorsContainer.classList.remove('invisible') Object.values(errors).forEach((item) => { let li = document.createElement('li') li.textContent = item $errorsContainer.appendChild(li) }) } function clearErrorContainer() { $errorsContainer.innerHTML = ''; };
- inbound—a message the microframe sends to your web service. Your web service is expected to handle it accordingly.
- outbound—a message your web service sends to the microframe. The web service is expected to handle the response to such a message accordingly.
Message | Description and example |
---|---|
epframe.loaded |
Event: microframe is loadedloader.hide(); iframe.show() |
epframe.embedded_mode.submit |
Event: the customer confirms payment by clicking the Pay button on your checkout page.var message = {"message":"epframe.embedded_mode.submit"}; message.from_another_domain = true; window.postMessage(JSON.stringify(message)) |
epframe.validation.status.change |
Event: accuracy verification result is sent(data) => {var errors = []; jQuery.each(data.data, function( key, value ) {errors.push(value);});} |
epframe.card.verify.success |
Event: the card verification is complete{const redirect_success_url = "https://ur_success_url.com";
window.location.replace(redirect_success_url);} |
epframe.card.verify.fail |
Event: the card verification has failed{const redirect_fail_url = "https://ur_failed_url.com";
window.location.replace(redirect_fail_url);} |
epframe.payment.success |
Event: the final status is delivered, the payment is complete{const redirect_success_url = "https://ur_success_url.com";
window.location.replace(redirect_success_url);} |
epframe.payment.fail |
Event: the final status is delivered, the payment is declined{const redirect_fail_url = "https://ur_failed_url.com";
window.location.replace(redirect_fail_url);} |
Required parameters
This is a common list of parameters necessary for using the solution. It can sometimes be expanded depending on the specifics of the merchant's project. Contact your account manager for more details.
Parameter | Description |
---|---|
project_id |
Project identifier assigned by ecommpay at the stage of integration. |
payment_id |
Payment identifier unique within the merchant's project. |
signature |
Request signature generated after all required parameters have been specified (for more information, see Signature generation and verification) |
payment_amount |
Payment amount in the smallest currency units. |
payment_currency |
Payment currency code in the ISO 4217 alpha-3 format. |
customer_id |
Identifier of the customer within the merchant's project. |
customer_first_name |
First name of the customer. |
customer_last_name |
Last name of the customer. |
customer_email |
Email of the customer. |
redirect_success_url |
The URL for the customer to be redirected to when the payment has been completed. |
redirect_fail_url |
The URL for the customer to be redirected to when the payment is declined. |
avs_post_code |
Customer's postal code passed in case of the AVS check. Required for customers with a UK issued card (can be submitted in a clarification message). |
avs_street_address |
Customer's street address passed in case of the AVS check. Required for customers with a UK issued card (can be submitted in a clarification message). |
force_payment_method |
Identifier of the payment method that is opened to customers without an option to select another one. |
In addition, keep in mind that requests for card payments must contain either the customer_email
or the customer_phone
parameter. It is also recommended that for 3‑D Secure you pass the information about the customer's billing address using the following parameters.
Parameter | Description |
---|---|
|
Country of the customer's billing address in the ISO 3166-1 alpha-2 format (learn more). |
|
Postal code of the customer's billing address. |
|
City of the customer's billing address. |
|
Street of the customer's billing address. |