npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@prakrit_m/tmn-voucher

v1.0.5

Published

ไลบรารี TypeScript สำหรับการแลกคูปองอั่งเปา TrueMoney Wallet

Readme

@prakrit_m/tmn-voucher 🎟️

ไลบรารี TypeScript สำหรับการแลกคูปองอั่งเปา TrueMoney Wallet

เติมเงิน Truewallet ด้วยซองอั่งเปา

NPM version NPM Downloads NPM Last Update License: ISC

🌟 Features

  • ใช้งานง่ายและครอบคลุมฟีเจอร์ที่จำเป็น
  • รองรับ TypeScript
  • สามารถแลกคูปองได้เมื่อตรงตามเงื่อนไขที่กำหนด
  • มีการตรวจสอบและ validate ข้อมูลก่อนการแลกคูปอง
  • จัดการและแยกประเภท Error Code ได่ง่าย

🚀 Installation

ติดตั้งแพ็กเกจ:

# npm
npm install @prakrit_m/tmn-voucher

# yarn
yarn add @prakrit_m/tmn-voucher

# pnpm
pnpm add @prakrit_m/tmn-voucher

📖 Usage

นำเข้าฟังก์ชัน redeemvouchers และใช้มันเพื่อแลกคูปองซองอั่งเปา TrueMoney Wallet

import redeemvouchers from "@prakrit_m/tmn-voucher";

// ตัวอย่างข้อมูลสำหรับแลกคูปอง
const phoneNumber = "0812345678";
const voucherUrl = "https://gift.truemoney.com/campaign/?v=YOUR_VOUCHER_CODE";

// ตัวเลือกเพิ่มเติมจะระบุหรือไม่ก็ได้ เช่น จำนวนเงิน
const options = {
  amount: 10000, // จำนวนเงินในหน่วยสตางค์ (100 บาท) กรณีที่ยอดเงินไม่ตรงจะไม่ทำการ redeem
};

// ใช้ Promises
function redeemWithPromise() {
  redeemvouchers(phoneNumber, voucherUrl, options)
    .then((response) => {
      if (response.success) {
        console.log(`🎉 แลกคูปองสำเร็จ: ${response.amount} สตางค์`);
      } else {
        handleVoucherError(response);
      }
    })
    .catch((error) => {
      console.error("❌ เกิดข้อผิดพลาดในการแลกคูปอง:", error);
    });
}

// ใช้ Async/Await
async function redeemWithAsync() {
  try {
    const response = await redeemvouchers(phoneNumber, voucherUrl, options);
    if (response.success) {
      console.log(`🎉 แลกคูปองสำเร็จ: ${response.amount} สตางค์`);
    } else {
      handleVoucherError(response);
    }
  } catch (error) {
    console.error("❌ เกิดข้อผิดพลาดในการแลกคูปอง:", error);
  }
}

// ฟังก์ชันจัดการ Error จากการแลกคูปอง
function handleVoucherError(response: { code: string; message: string }) {
  switch (response.code) {
    case "VOUCHER_NOT_FOUND":
      console.warn("🔍 ไม่พบคูปอง");
      break;
    case "VOUCHER_EXPIRED":
      console.warn("⏳ คูปองหมดอายุ");
      break;
    case "VOUCHER_OUT_OF_STOCK":
      console.warn("❌ คูปองถูกใช้ไปแล้ว");
      break;
    case "CANNOT_GET_OWN_VOUCHER":
      console.warn("🚫 ไม่สามารถใช้คูปองตัวเองได้");
      break;
    case "CONDITION_NOT_MET":
      console.warn("🚫 ไม่ตรงเงื่อนไข");
      break;
    default:
      console.warn(`⚠️ การแลกคูปองล้มเหลว: ${response.message}`);
  }
}

// เรียกใช้ฟังก์ชันตัวอย่าง
redeemWithPromise();
redeemWithAsync();

กรณีที่ไม่ได้ระบุพารามิเตอร์ options จะเป็นการ redeem โดยไม่เช็คเงื่อนไขใดๆก่อน

กรณีที่มีการระบุ options ถ้าไม่ตรงกับเงื่อนไขใดๆจะไม่ทำการ redeem

📚 API

redeemvouchers(phoneNumber: string, voucherUrl: string, options?: Options): Promise<ReturnData>

แลกคูปอง TrueMoney

  • phoneNumber: หมายเลขโทรศัพท์ที่เชื่อมโยงกับบัญชี TrueMoney ที่ต้องการรับเงิน
  • voucherUrl: URL คูปองอั่งเปา
  • options: เงื่อนไขเพิ่มเติม (ถ้ามี)
    • amount: จำนวนเงินที่ต้องการแลกในหน่วยสตางค์

คืนค่าเป็น Promise ที่ resolve เป็นวัตถุ ReturnData

Data

interface Data {
  voucher: Voucher;
  owner_profile: Profile;
  redeemer_profile: RedeemerProfile;
  my_ticket: MyTicket;
  tickets: MyTicket[];
}

interface Voucher {
  voucher_id: string;
  amount_baht: string;
  redeemed_amount_baht: string;
  member: number;
  status: "active" | "redeemed" | "expired";
  link: string;
  detail: string;
  expire_date: number;
  type: "R" | "F";
  redeemed: number;
  available: number;
}

interface Profile {
  full_name: string;
}

interface RedeemerProfile {
  mobile_number: string;
}

interface MyTicket {
  mobile: string;
  update_date: number;
  amount_baht: string;
  full_name: string;
  profile_pic: string | null;
}

Data ประกอบด้วยข้อมูลดังนี้:

  • voucher: ข้อมูลคูปอง
  • owner_profile: โปรไฟล์ของเจ้าของคูปอง
  • redeemer_profile: โปรไฟล์ของผู่ที่จะแลกคูปอง
  • my_ticket: ข้อมูลบัญชีของผู้รับเงินแล้ว
  • tickets: รายการข้อมูลบัญชีของผู้รับเงินแล้ว

🛠️ Types

Options

type Options {
  amount: number; // จำนวนเงินในหน่วยสตางค์ 100-20000000
}

ReturnData

type ReturnData =
  | {
      // กรณี redeem สำเร็จ
      success: true;
      code: "SUCCESS";
      message: string; // ข้อความจาก TrueMoney
      amount: number; // จำนวนเงินเป็นสตางค์
      data: Data; // ข้อมูลจาก TrueMoney
    }
  | {
      // กรณี redeem ไม่สำเร็จ
      success: false;
      code: string;
      message: string; // ข้อความจาก TrueMoney
      data?: Data | null; // ข้อมูลจาก TrueMoney
    };

📋 Response Codes

| Code | Description | Success | | ----------------------------- | ----------------------------------- | ------- | | SUCCESS | สำเร็จ | true | | BAD_PARAM | พารามิเตอร์ไม่ถูกต้อง | false | | VOUCHER_NOT_FOUND | ไม่พบคูปอง | false | | VOUCHER_OUT_OF_STOCK | คูปองถูกใช้ไปแล้ว | false | | VOUCHER_EXPIRED | คูปองหมดอายุ | false | | CANNOT_GET_OWN_VOUCHER | ไม่สามารถแลกคูปองของตัวเองได้ | false | | TARGET_USER_NOT_FOUND | ไม่พบหมายเลขโทรศัพท์ | false | | TARGET_USER_REDEEMED | ผู้ใช้นี้เคยแลกคูปองแล้ว | false | | TARGET_USER_STATUS_INACTIVE | บัญชีผู้รับถูกระงับหรือไม่ได้ใช้งาน | false | | CONDITION_NOT_MET | ไม่ตรงเงื่อนไข (options) | false | | INVALID_INPUT | ข้อมูลไม่ถูกต้อง | false | | MAINTENANCE | อยู่ในช่วงการบำรุงรักษา | false | | INTERNAL_ERROR | Internal server error | false |

📄 License

This is a third-party SDK, not an official TrueMoney.
SDK นี้พัฒนาโดยบุคคลภายนอก ไม่ใช่ผลิตภัณฑ์อย่างเป็นทางการจาก TrueMoney

Licensed under ISC