c) Receiving the response

To notify the payment result, provide the URL of an endpoint on your server. The information encrypted in AES will be sent to this URL. Decipher the chain and get the response .

How does the POST notification work?


The result of a charge is sent asynchronously to your server by POST , to the URL provided by the Merchant Administrator during configuration. The encrypted information will be sent to this end point in a parameter called strResponse .




Step 1: Configure your endpoint

Indicates the URL, provided by the Commerce Administrator during the configuration, to the service in charge of processing the result of a payment.

If you wish, use a service like Beeceptor, Mockbin, Webhook Tester, RequestBin, etc.


Paso 2: Send a message

Choose among the types of messages that you should consider for your business logic and simulate the notification by clicking on the corresponding button:

When the link was generated without the promociones element

 

When the link was generated with the promociones element

 

REQUEST (this is what we sent to the endpoint)


					

 

RESPONSE (this is what the endpoint answered)


				

Step 3: Decipher the notification to your endpoint


Once the notification has been obtained in your endpoint, you can decipher it with the appropriate SDK to your server, and within response you will find the result, which you must use to apply your business logic.

Example


								import webPayPlus.AESCrypto
String originalString ="This is the string to be processed";
String decodedString=URLDecoder.decode(originalString, "UTF-8");
String key = "5dcc67393750523cd165f17e1efadd21";
String decryptedString = 
  AESCrypto.decrypt(decodedString, secretKey);
							
								<?php
include('/AESCrypto.php'); 
$originalString = 'Este es el texto a procesar';
$decodedString = string urldecode ( string $originalString );
$key = '5dcc67393750523cd165f17e1efadd21'; //Llave de 128 bits
$decryptedString = AESCrypto::desencriptar($decodedString, $key);
?>
							
								using AESCrypto.cs
string originalString ="[USE THE CHAIN OF EXAMPLE ONE]";
string key = "5DCC67393750523CD165F17E1EFADD21";
string decryptedString =
  AESCrypto.decrypt(key, originalString);
string finalString = decrypt.Replace("%", "%25").Replace(" ", "%20").Replace("+", "%2B").Replace("=", "%3D").Replace("/", "%2F");
							


				

Understanding the notification


Once the payment response has been decrypted, within <CENTEROFPAYMENTS> , in the element <response> you will find the result, which you must occupy to apply your business logic.

Decrypted response example


						<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<CENTEROFPAYMENTS>
  <reference>INVOICE001</reference>
  <response>approved</response>
  <foliocpagos>000551635</foliocpagos>
  <auth>473347</auth>
  <cd_response>0C</cd_response>
  <cd_error/>
  <nb_error/>
  <time>17:38:40</time>
  <date>27/07/2016</date>
  <nb_company>SANDBOX MIT</nb_company>
  <nb_merchant>1234567 WEBPAYPLUS</nb_merchant>
  <cc_type>CREDITO/BANCO MIT/Visa</cc_type>
  <tp_operation>VENTA</tp_operation>
  <cc_name/>
  <cc_number>1234</cc_number>
  <amount>400.00</amount>
  <id_url>SNDBX001</id_url>
  <cc_mask>545454XXXXXX1234</cc_mask>
  <email>client@email.com</email>
  <datos_adicionales>
    <data id="1" display="true">
      <label>Size</label>
      <value>Large</value>
    </data>
    <data id="2" display="false">
      <label>Color</label>
      <value>Blue</value>
    </data>
  </datos_adicionales>
</CENTEROFPAYMENTS>
					
Table A: Element response
Response Description of the response You must
approved Transaction approved by the issuing bank. Proceed with the delivery of the good or service.
denied Transaction rejected by the issuing bank. Ask your client to provide another card.
error Error in the information provided when submitting the authorization request. Contact MIT Service Center
Table B: Elements cd_error y nb_error
cd_error nb_error
03 There is a problem with the configuration. The company, branch or user data is incorrect. Contact the site administrator (CODE03).
05 There is a problem with the configuration. The branch does not is configured to make that type of transaction. Contact to the site administrator (CODE05).
08 The amount is less than the amount allowed for the promotion selected months. Contact the Site Administrator (CODE08).
09 The amount is greater than allowed. Contact the Site administrator (CODE09).
11 The transaction was rejected during the day. Try another card or otherwise, try again tomorrow.
16 The amount is greater than allowed. Contact the Site administrator (CODE16).

How does the REDIRECT work?


By default, once your client has completed an intention to pay, the response will be displayed on a page with our design and image, hosted on our servers.

If you wish, you can use an exit page hosted on your server, with your message, design and image, in the URL provided by the Commerce Administrator during the configuration as - Redirect in the browser .

To recover control of the browser, the response of a charge is sent synchronously to your server via GET , to the URL provided by the Merchant Administrator during the configuration.



Important: The exit page only serves to regain control in the browser and does not replace the POST Notification, which invariably you should contemplate in your development, as the only sure method of knowing the result.

Try it now!


Step 1: Indicate your exit page

Indicate the URL, provided by the Commerce Administrator during configuration, to the output page responsible for processing the answer

Indicate the URL, provided by the Commerce Administrator during the configuration, to the service in charge of processing the result of a charge.
If you wish, modify the value to test your exit or thanks page.


Step 2: Send the GET

Choose among the types of messages that you should consider in your business logic and simulate the answer by clicking on the corresponding button:

 

GET (this is what we sent to your exit page)


					

 

Getting the result


You can get the parameters on your page to continue your flow in the usual way. In this way, you will know when a Client has completed his intention to pay.

Exit page example

						<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page language="java" import="java.net.URLDecoder"%>
<%
//Variables
String nbResponse="";
String idLiga ="";
String referencia = "";
String importe = "";
String email="";
String nuAut="";

//Obtain the parameters from the request
if (request.getParameter("nbResponse") !=null && !request.getParameter("nbResponse").isEmpty()){
	nbResponse = request.getParameter("nbResponse");
};

if (request.getParameter("idLiga") !=null && !request.getParameter("idLiga").isEmpty()){
	idLiga = request.getParameter("idLiga");
};

if (request.getParameter("referencia") !=null && !request.getParameter("referencia").isEmpty()){
	referencia = request.getParameter("referencia");
};

if (request.getParameter("importe") !=null && !request.getParameter("importe").isEmpty()){
	importe = request.getParameter("importe"); 
};

if (request.getParameter("email") !=null && !request.getParameter("email").isEmpty()){
	email = request.getParameter("email");
};

if (request.getParameter("nuAut") !=null && !request.getParameter("nuAut").isEmpty()){
	nuAut = request.getParameter("nuAut");
};
%>

<!DOCTYPE html>
<html>
<head>
</head>
<body onload="window.history.replaceState(null, null, window.location.pathname);">
<% if (nbResponse.equalsIgnoreCase("Aprobado") && nuAut !=""){
// Apply your business logic here
// for example, you can use
// - idLiga or reference to link them to an order or command.
// - email to send a thank you message to your client.
// - amount to compare the amount paid with the one you sent when generating the league.
// NOTE: All approved payments have a nuAut authorization number
%>
<h1>Thank you for your purchase of <%=importe%>!</h1>
<p>You will receive an email shortly at <%=email%></p><%
} else if (nbResponse.equalsIgnoreCase("Rechazado")){
// Apply your business logic here
%>
<h1>Sorry, your payment for <%=importe%> has been rejected by your bank.</h1>
<%} else {%>
<h1>Sorry, we can not process the response</h1>
<%} %>
</body>
</html>
					

Understanding the result


Important: The exit page only serves to regain control in the browser and does not replace the POST Notification, which invariably you should contemplate in your development, as the only sure method of knowing the result. Use them only as a basis to validate the POST response you received in your endpoint.

The parameters that you receive in your exit page are:

Table C: Parameter nbResponse
Value Description You should
Aprobado Transaction approved by the issuing bank. Validate with the POST record received in your endpoint before proceeding with the delivery of the good or service.
Rechazado Transaction rejected by the issuing bank. Ask your client to provide another card.

Congratulations!
You have concluded with the Integration Guide.

Now is a good time to request the productive credentials to the Commerce Administrator.