medusa-payment-tamara
Version:
Tamara payment gateway plugin for Medusa
32 lines (31 loc) • 1.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const medusa_core_utils_1 = require("medusa-core-utils");
class ItemsService {
constructor({ cartService }) {
this.cartService = cartService;
}
async getCart(id) {
return this.cartService.retrieveWithTotals(id, { relations: ["region", "items", "items.variant", "customer", "shipping_methods"] });
}
async getitems(context) {
const cart = await this.getCart(context.resource_id);
const currency_code = cart.region.currency_code.toUpperCase();
const items = cart.items;
const itemsArray = items.map((item) => {
return {
reference_id: item.variant.id,
type: "physical",
name: item.title,
sku: item.variant.sku || item.variant.id,
quantity: item.quantity,
total_amount: {
amount: (0, medusa_core_utils_1.humanizeAmount)(item.unit_price, currency_code),
currency: currency_code
}
};
});
return itemsArray;
}
}
exports.default = ItemsService;