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 🙏

© 2024 – Pkg Stats / Ryan Hefner

momo-payment-api

v1.0.3

Published

payment momo lib develop by minhduc

Downloads

9

Readme

Process flow

Create Payment

Flow

Refund Payment

Refund

Installation

The first, Momo partner must be successfully registered. Use the package manager npm to install.

npm i momo-payment-api
yarn add momo-payment-api

Usage

Develop

import { MomoPayment } from "momo-payment-api";
import {
  ICreatePayment,
  IRefundPayment,
  IResponsePayment,
} from "momo-payment-api/src/type";

// Read the input parameter on https://developers.momo.vn/v3/en/docs/payment/api/payment-api/init
class MomoPaymentService {
  private momoPayment: any;

  /**
   * @param partnerCode
   * @param accessKey
   * @param secretKey
   * @param enviroment = production -> live || development -> sanbox
   */
  constructor(
    partnerCode: string,
    accessKey: string,
    secretKey: string,
    enviroment: string = "development"
  ) {
    this.momoPayment = new MomoPayment(
      partnerCode,
      accessKey,
      secretKey,
      enviroment
    );
  }

  async createPayment(input: ICreatePayment) {
    try {
      const result: IResponsePayment = await this.momoPayment.createPayment(
        input
      );

      // handle your code here

      return result;
    } catch (error) {
      throw error;
    }
  }

  async refundPayment(input: IRefundPayment) {
    try {
      const result = await this.momoPayment.refundPayment(input);
      return result.data;
    } catch (error) {
      throw error;
    }
  }

  // inpUrl: khi thanh toán thành công sẽ gọi vào api và trỏ tới service này
  async confirmPayment(body: IResponseSuccessPayment) {
    try {
      // handle your code here
    } catch (error) {
      throw error;
    }
  }
}

Paramater

export interface ICreatePayment {
  subPartnerCode?: string; // Định danh duy nhất của tài khoản M4B của bạn
  storeName?: string; // Tên đối tác
  storeId?: string; // Mã cửa hàng
  requestId: string; // Định danh duy nhất cho mỗi yêu cầu
  orderId: string; // Mã đơn hàng của đối tác
  amount: number; // Số tiền cần thanh toán Nhỏ Nhất: 1.000 VND Tối đa: 50.000.000 VND Tiền tệ: VND Kiểu dữ liệu: Long
  orderInfo: string; // Thông tin đơn hàng
  ipnUrl: string; // API của đối tác. Được MoMo sử dụng để gửi kết quả thanh toán theo phương thức IPN (server-to-server)
  extraData?: string; // mặc định "" Encode base64 theo định dạng Json: {"key": "value"} VD: {"username": "momo"} -> extraData: eyJ1c2VybmFtZSI6ICJtb21vIn0=
  redirectUrl: string; // URL này được sử dụng để chuyển trang (redirect) từ MoMo về trang mua hàng của đối tác sau khi khách hàng thanh toán.
  requestType?: string; // captureWallet
  items?: Array<IItems>; // Danh sách các sản phẩm hiển thị trên trang thanh toán. Tối đa: 50 loại sản phẩm
  deliveryInfo?: IDeliveryInfo; // Thông tin giao hàng của đơn hàng
  userInfo?: IUserInfo; // Thông tin người dùng
  referenceId?: string; // Mã tham chiếu phụ của đối tác. Ví dụ dùng trong các trường hợp như mã khách hàng, mã hộ gia đình, mã hóa đơn, mã thuê bao v.v
  autoCapture?: boolean; // Nếu giá trị false, giao dịch sẽ không tự động capture. Mặc định là true
  lang?: string; // Ngôn ngữ của message được trả về (vi hoặc en); Mặc định 'en'
}

export interface IRefundPayment {
  subPartnerCode?: string;
  orderId: string;
  requestId: string;
  amount: number; // Số tiền cần hoàn
  transId: string; // 	Mã giao dịch của MoMo; Đây là Id do MoMo cung cấp cho giao dịch mua thành công của hàng hóa/dịch vụ này
  lang?: string; // default 'en'
  description?: string; // Mô tả chi tiết yêu cầu hoàn tiền
}

Response

// Phản hồi từ momo khi tạo payment
export interface IResponsePayment {
  partnerCode: string;
  requestId: string;
  orderId: string;
  amount: number;
  responseTime: number;
  message: string;
  resultCode: number; // O -> success
  /*xem thêm code tại: 
  https://developers.momo.vn/v3/vi/docs/payment/api/result-handling/resultcode/
  */
  payUrl: string;
  deeplink: string;
  qrCodeUrl: string;
}

// Phản hồi từ momo khi thanh toán thành công
export interface IResponseSuccessPayment {
  partnerCode: sring;
  orderId: string;
  requestId: string;
  amount: number;
  orderInfo: string;
  orderType: string;
  transId: string;
  resultCode: number;
  message: string;
  payType: string;
  responseTime: number;
  extraData: string;
  signature: string;
}

Important

Mail: [email protected] Documentation: https://developers.momo.vn/

License

MIT