export function mappingMidtransTransaction(transaction) {
  const item_details = transaction.items?.map((item) => {
    return {
      quantity: Number(item.qty),
      price: Number(item.total_price) / Number(item.qty),
      name: item.item_name,
      category: item.item_category_name,
    };
  });

  if (transaction.payment_discount_total) {
    item_details.push({
      quantity: 1,
      price: -Number(transaction.payment_discount_total),
      name: 'discount',
    });
  }

  return {
    transaction_details: {
      order_id: transaction.id,
      gross_amount: Number(transaction.payment_total),
    },
    item_details: item_details,
    customer_details: {
      first_name: transaction.customer_name,
      email: transaction.customer_email,
      phone: transaction.customer_phone,
    },
  };
}
