Discussions
CreateACheckout is not a valid operation.
over 1 year ago by null
This is my strapi backend:
use strict";
const sdk = require("api")("@paymongo/v2#5u9922cl2759teo");
/**
* order controller
*/
const { createCoreController } = require("@strapi/strapi").factories;
module.exports = createCoreController("api::order.order", ({ strapi }) => ({
async create(ctx) {
const { products } = ctx.request.body;
const lineItems = products.map((product) => ({
amount: Math.round(product.price * 100),
currency: "PHP",
description: product.desc,
// images: [product.image],
name: product.name,
quantity: product.quantity,
}));
const data = {
attributes: {
cancel_url: "http://example.com/cancel",
billing: {
address: {
line1: "123 Main St.",
line2: "Suite 1",
city: "Makati",
state: "Metro Manila",
postal_code: "1234",
country: "PH",
},
name: "John Doe",
email: "[email protected]",
phone: "+639123456789",
},
description: "My order",
line_items: lineItems,
payment_method_types: ["card"],
reference_number: "123456",
send_email_receipt: false,
show_description: true,
show_line_items: true,
success_url: "http://example.com/success",
statement_descriptor: "My Business",
},
};
try {
sdk.auth("sk_test_SsQLejeRVDfVskZevWq4Dtku");
const response = await sdk.createACheckout({ data: data });
const checkout = response.data;
await strapi.services.order.create({
paymongo_checkout_id: checkout.data.id,
products,
});
ctx.send({ checkout });
} catch (error) {
console.error(error);
ctx.badRequest(error);
}
},
}));
And this is the error I received:
Error: Sorry, `createACheckout` does not appear to be a valid operation on this API.
at Proxy.<anonymous> (D:\Users\rules\Desktop\JS\Anciado Furniture\Api\anciado-furniture-api\node_modules\api\dist\index.js:173:47)
at step (D:\Users\rules\Desktop\JS\Anciado Furniture\Api\anciado-furniture-api\node_modules\api\dist\index.js:33:23)
at Object.next (D:\Users\rules\Desktop\JS\Anciado Furniture\Api\anciado-furniture-api\node_modules\api\dist\index.js:14:53)
at D:\Users\rules\Desktop\JS\Anciado Furniture\Api\anciado-furniture-api\node_modules\api\dist\index.js:8:71
at new Promise (<anonymous>)
at __awaiter (D:\Users\rules\Desktop\JS\Anciado Furniture\Api\anciado-furniture-api\node_modules\api\dist\index.js:4:12)
at Proxy.accessorHandler (D:\Users\rules\Desktop\JS\Anciado Furniture\Api\anciado-furniture-api\node_modules\api\dist\index.js:165:28)
at Object.create (D:\Users\rules\Desktop\JS\Anciado Furniture\Api\anciado-furniture-api\src\api\order\controllers\order.js:53:36)
at dispatch (D:\Users\rules\Desktop\JS\Anciado Furniture\Api\anciado-furniture-api\node_modules\koa-compose\index.js:42:32)
at returnBodyMiddleware (D:\Users\rules\Desktop\JS\Anciado Furniture\Api\anciado-furniture-api\node_modules\@strapi\strapi\lib\services\server\compose-endpoint.js:52:24)
And I was curious on what operations are available so I did this:
console.log("Available operations in PayMongo SDK:");
Object.getOwnPropertyNames(sdk).forEach((operation) => {
console.log("- " + operation);
});
And it console logged this:
Available operations in PayMongo SDK:
- auth
- config
- server
There's no CreateACheckout, retrieveListOfPossibleMerchantPaymentMethods