Hello everyone,
i’m trying to achieve some API post to a payment facility method (because wix currently doesn’t support split payment, i’m trying to use another method). There is this company : https://www.ips-payment.com/ , doing this split payment (3 times).
My goal, catch informations of the clients on their cart page, and redirect them on the api with this informations.
They gave me this to input :
curl --location --request POST 'https://wws.ips-payment.com/' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'MerchantKey=YourAPIKey' \
--data-urlencode 'amount=100' \
--data-urlencode 'RefOrder=0000011111333666' \
--data-urlencode 'Customer_Email=yourclient@yourclient.com' \
--data-urlencode 'Lease=3'
I used a convertor cURL to Fetch (kigiri.github.io) , provided by the great @Yisrael (Wix)
fetch("https://wws.ips-payment.com/?MerchantKey=YourAPIKey&amount=100&RefOrder=0000011111333666&Customer_Email=yourclient@yourclient.com&Lease=3", { headers: { "Content-Type": "application/x-www-form-urlencoded" }, method: "POST" })
So i told me, let’s go fetch this out, but i writted my code here :
Backend (tried both .JSW and .JS)
import { created, serverError } from 'wix-http-functions';
import wixStores from 'wix-stores';
import wixData from 'wix-data';
let MerchantKey = "3618601a7d1fda92bAPI601a7d1fda92c"
let amount = "";
let email = "";
let RefOrder = "";
let Lease = 3
let url = 'https://wws.ips-payment.com/';
export async function postCartInfos(request) {
await wixStores.getCurrentCart().then((Cartdata) => {
amount = Cartdata.totals.total;
RefOrder = Cartdata._id;
Lease = 3;
})
let fullUrl = url + '/' + "MerchantKey=" + MerchantKey + '/' + "amount=" + amount + '/' + "Customer_Email=" + email + '/' + "RefOrder=" + RefOrder + '/' + "Lease=3" + '/'
return fetch(fullUrl, {
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
method: "POST",
body : {
MerchantKey : MerchantKey,
amount : amount,
Customer_Email : email,
RefOrder : RefOrder,
Lease : Lease,
}
})
.then((httpResponse) => {
if (httpResponse.ok) {
return httpResponse.json();
} else {
return Promise.reject("Fetch did not succeed");
}
})
}
Front end :
import { fetch } from 'wix-fetch';
import wixStores from 'wix-stores';
import wixData from 'wix-data';
import wixUsers from 'wix-users'
import wixLocation from 'wix-location'
import { postCartInfos } from 'backend/CURL'
let MerchantKey = "3618601a7d1fda92bAPI601a7d1fda92c"
let amount = "";
let email = "";
let RefOrder = "";
let Lease = 3
let url = 'https://wws.ips-payment.com/';
$w.onReady(function () {
getCartInfo();
console.log(amount)
if (amount >= 400) {
$w("#input1").enable()
$w("#button3").enable()
}
});
export async function getCartInfo() {
await wixStores.getCurrentCart().then((Cartdata) => {
amount = Cartdata.totals.total;
RefOrder = Cartdata._id;
Lease = 3;
console.log(Cartdata.totals.total)
console.log(Cartdata._id)
console.log(Cartdata)
})
if (amount >= 400) {
$w("#input1").enable()
$w("#button3").enable()
}
}
export function button3_click(event) {
postCartInfos()
.then(httpResponse => {
console.log("httpResponse: " + httpResponse);
})
console.log(amount)
console.log(RefOrder)
}
export function button3_dblClick(event) {
let fullUrl = url + "MerchantKey=" + MerchantKey + '/' + "amount=" + amount + '/' + "Customer_Email=" + email + '/' + "RefOrder=" + RefOrder + '/' + "Lease=3" + '/'
fetch(fullUrl, {
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
method: "POST"
})
wixLocation.to(url)
}
export function input1_change(event) {
email = $w("#input1").value
console.log(email)
}
I know i’m using a lot of stuff, the code seams to work, but nothing goes to the post !
Thanks in advance (i’ve red a lot of posts about fetch, saw videos, and i’m getting tired not to fine ! )