Question:
I’m trying to implement Payment functionality for my app extension, But I’ve never had the WixPayBackend.createPayment return anything but error “invalid response status” in the backend logs. I have no way to see what this response is, or why it’s failing.
BACKEND CODE - http-functions.js
export async function get_createTestPayment(request) {
const response = {
"headers": {
"Content-Type": "application/json"
}
}
try {
const payment = await wixPayBackend.createPayment({
items: [
{
name: "Test Product",
price: 9.99,
quantity: 1,
},
],
amount: 9.99,
currency: "USD",
userInfo: {
firstName: "Tes",
lastName: "Ter",
email: "Tester@test.com",
countryCode: 'USA',
phone: null,
},
});
console.log("GOT PAYMENT",payment);
response.body = payment;
return ok(response);
} catch (err) {
response.body = {
"error": err
}
return badRequest(response);
}
}
OR test_payment.web.js
import { Permissions, webMethod } from "wix-web-module";
import wixPayBackend from "wix-pay-backend";
export const create_test_payment = webMethod(
Permissions.Anyone,
() => {
return wixPayBackend.createPayment({
items: [
{
name: "Test Product",
price: 9.99,
quantity: 1,
},
],
amount: 9.99,
}).then((payment)=>{ return payment; });
}
);
I’d post my front-end code but since I haven’t gotten a successful payment return yet, I don’t think think that’s relevant to this backend issue.
on my site, I’ve enabled payments and set the currency. I’ve tried with the API and with the webMethod (Which is still giving me connection issues which I’m still waiting for any assistance on here.
Any ideas what the issue here is?
Product:
Wix Blocks, Wix Studio, Wix Pay
What are you trying to achieve:
Get a Payment object returned from the WixPayBackend.createPayment() function.
What have you already tried:
Tried various different ways of calling and formatting the data.
Additional information:
These are implemented in Wix Blocks in my extension app.
I update and refresh to my test site, which I then publish and go into the site to test.
The frontend is just a widget with a button that onclick should get the payment id from the backend (via api) then prompt the frontend wixPayFrontend with the payment ID, for the statically defined object. I’m just trying to test a single payment.
EDIT : I’ve tested this identical implementation on my site backend and it worked perfectly first try, with the webMethod. How do I convert the Site Backend payment method to my Blocks Extension App’s Backend and have it still work on the site? I’ve found the syntax for API calls to custom endpoints , but Web Modules defined in Blocks App don’t seem to work correctly, nor do payments work correctly in the Blocks App. Is there a secret method or syntax like API endpoints equivalent for these other functionalities between the Site backend and the Blocks App backend? In my head I can sort of see adding a button from the site side onto the widget page, and defining the payment code there, and defining the checkout logic function as a public method in my widget backend / widget function that could be called from the front-end … But That introduces some really fractured responsibility and negative design aspects. If it’s impossible to have payments working from inside blocks then it can’t be helped, but I’d really like to resolve this instead of going down that path.