How to fetch response from third party payment system?

I have created a lightbox using this html code from third party payment system (Datatrans) for the payment process and it works fine. How can I fetch the response programmatically?

Is there way to receive and process respionse XML from any payment system at all?
Thanks a lot.

import {fetch} from ‘wix-fetch’;
import xmljs from ‘xml-js’;

export function postPayment() {
const url = “https://api.sandbox.datatrans.com/upp/jsp/XML_authorize.jsp”;
console.log(“in Post Payment”)

var convert = xmljs
var xml =
‘<?xml version="1.0" encoding="UTF-8" ?>’ +
‘’ +
‘’ +
‘’ +
‘’ +
‘50’ +
‘XXX’ +
‘XXXXXX’ +
‘12’ +
‘21’ +
‘XXXXXXXXXX’ +
‘’ +
‘’ +
‘’ +
‘’;

console.log('xmlL ’ + xml)
var result1 = convert.xml2json(xml, {compact: true , spaces: 4});
var result2 = convert.xml2json(xml, {compact: false , spaces: 4});
// console.log(result1, ‘\n’, result2);

const key = ‘XXXXXXXXXXXXX=’
const headers = {
“Authorization”: "Bearer " + key,
“Content-Type”: “Content-Type: application/xml”
};

const params = ‘merchantId=XXXXXX&refno=1234567890&amount=85&theme=DT2015’;
// const data = from=${sender}&to=${recipient}&subject=${subject}&text=${body};

const request = {
“method”: “post”,
“headers”: headers,
“body”: xml
};

return fetch(url, request)
.then( (httpResponse) => {
if (httpResponse.ok) {

return httpResponse.text();
} else {
return Promise.reject(“Fetch did not succeed”);
}
} )
.then( (text ) => {
var converted = convert.xml2json(text, {compact: true , trim: true , alwaysArray: false });
return converted;
})
.then(res => {
var converted = JSON.parse(res);
var resp_code = converted[“authorizationService”][“body”][“transaction”][“response”][“responseCode”][“_text”];
var resp_msg = converted[“authorizationService”][“body”][“transaction”][“response”][“responseMessage”][“_text”];
var resp_tid = converted[“authorizationService”][“body”][“transaction”][“response”][“uppTransactionId”][“_text”];
console.log('response Code: ’ + resp_code);
console.log('response Message: ’ + resp_msg);
console.log('response TransactionId: ’ + resp_tid);
console.log('converted: ’ + converted);
return converted;
})
. catch (err => console.log(‘Error’ + err));

}

https://stackoverflow.com/questions/54988271/how-to-add-xml-data-to-wix-page
https://www.wix.com/corvid/forum/community-discussion/parse-xml-string-from-fetch-api
https://github.com/nashwaan/xml-js#readme

Hi thanks a lot, I have seen those links and used them. The problem I face is payment goes through indeed but there is now way of checking response in wix? I just want to get back to wix word “authorised”. I just want to get any information back from payment system to wix through lightbox iframe or any other way.
I use iframe in the lightbox at the moment.

Lightbox page code:
import wixWindow from ‘wix-window’;

$w.onReady( function () {
let received = wixWindow.lightbox.getContext();
console.log("Received: ", received);
// $w(‘#Pay_lightboxReceive1’).text = received.pageSend1;
// $w(‘#lightBoxReceive2’).text = received.pageSend2;
} );

export function closeButton_click(event) {
wixWindow.lightbox.close( {
“Response”: “Test”
// “lightBoxSend2”: $w(‘#lightBoxSend2’).value
} );
}

Iframe code:

Pay

Okay, so as you are using html on your lightbox, you will need to first get the response back from the html to your lightbox first by using the html component.

How do I send data between my page and an HTML Component?
You can send and receive messages between your page and an HTML Component using the postMessage() and onMessage() functions.

https://support.wix.com/en/article/corvid-working-with-the-html-element
https://www.wix.com/corvid/reference/$w.HtmlComponent.html
https://www.wix.com/corvid/forum/corvid-tips-and-updates/example-fullscreen-with-htmlcomponent

Then you would have values to pass back to the page from the lightbox using the code.

How do I pass data between a page and a lightbox?
When you open a lightbox using the openLightbox() function, you can pass an object containing data to be used in the lightbox. In the lightbox’s code, you call the getContext() function to retrieve the data sent by the openLightbox() function.

When you close the lightbox using the close() function, you can pass an object containing data to be used by the page that opened the lightbox. This data is retrieved from the resolution of the Promise returned by the openLightbox() function.

https://www.wix.com/corvid/reference/wix-window.lightbox.html

You might just be easier to have the html component popup on screen when needed and not in the lightbox, so simply collapse it on load through the properties panel and expand it in code when needed, especially if you use the full screen version etc.

See this example of one payment processor:

Stripe Payment Processing

Integrate the Stripe Payment processing system into a site. Three levels of user access are demonstrated: visitor, freemium (registered), and premium (paid).

Hi

Thanks a lot, the only data I get back is not related to datatrans. Even though I do get response. Please see video attached.

Hello

Thank you. I have checked this example before posting this topic. With Stripe example we actually pass card number, expiry date and cvv through user input on wix to stripe which would then make fetching reply easy. With this payment system Datatrans everything has to be input and processed within their iframe which i embed into lightbox (not wix iframe which thing within I know) and then reply comes as word “authorised” in lightbox …and that is what I am unable to fetch.

Closed due to spam.