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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ruraim/nestjs-midtrans

v0.0.12

Published

NestJS Midtrans SDK Module

Readme

NestJS Midtrans

Description

Midtrans API Wrapper for Nest JS, with this package you can easily integrate your Nest JS application with Midtrans Payment Gateway. Using zod for schema validation so you can import the schema and use it for validation in your application.

Status

Under Development

This package is still under development, so there are still many features that are not available yet. Will be stable on version 1.0.0

Table of Contents

Setup & Installation

Installation

Using NPM

$ npm i --save @ruraim/nestjs-midtrans

Using Yarn

$ yarn add @ruraim/nestjs-midtrans

Module Import

import { Module } from '@nestjs/common';
import { MidtransModule } from '@ruraim/nestjs-midtrans';

// using register method
@Module({
  imports: [
      MidtransModule.register({
        clientKey: 'client-key',
        serverKey: 'server-key',
        merchantId: 'merchant-id',
        sandbox: true, // default: false,
        isGlobal: true // default: false, register module globally
      })
    ],
})

// using registerAsync with dependencies
@Module({
  imports: [
      MidtransModule.registerAsync({
          useFactory: (config: ConfigService) => ({
              clientKey: config.get<string>('MIDTRANS_CLIENT_KEY'),
              serverKey: config.get<string>('MIDTRANS_SERVER_KEY'),
              merchantId: config.get<string>('MIDTRANS_MERCHANT_ID'),
              sandbox: config.get<string>('MIDTRANS_MODE') === 'sandbox',
          }),
          // using ConfigService from @nestjs/config to get .env value
          inject: [ConfigService],
          imports: [ConfigModule],
          isGlobal: true // default: false, register module globally
      })
    ],
})
export class AppModule {}

Inject Service


import { MidtransService } from '@ruraim/nestjs-midtrans';

@Injectable()
export class AppService {
    constructor(
        private readonly midtransService: MidtransService
    ) {}
}

Transaction

Charge Transaction

You can refer to Midtrans - Charge Transaction for more information about the payload or see Charge Schema file in the source code.

  const result = await this.midtransService.charge({
      payment_type: 'bank_transfer',
      transaction_details: {
          order_id: 'ORDER-ID-123',
          gross_amount: 200000
      },
      customer_details: {
          email: '[email protected]',
          first_name: 'John Doe',
          phone: '081234567890'
      },
      item_details: [
        {
          id: 'Item1',
          price: 100000,
          quantity: 1,
          name: 'Item 1'
        },
        {
          id: 'Item2',
          price: 50000,
          quantity: 2,
          name: 'Item 2'
        }
      ],
      bank_transfer: {
        bank: 'bca'
      }
  })
  console.log(result)

Check Transaction Status

  const result = await this.midtransService.getStatus('ORDER-ID-123')
  console.log(result)

Expire Transaction

  const result = await this.midtransService.expireTransaction('ORDER-ID-123')
  console.log(result)

Subscription

Create Subscription

You can refer to Midtrans - Create Subscription for more information about the payload or see Create Subscription Schema file in the source code.

  const result = await this.midtransService.createSubscription({
    name: 'Langganan bulanan',
    amount: 10000,
    currency: 'IDR',
    payment_type: 'credit_card',
    schedule: {
      interval: 1,
      interval_unit: 'month',
      max_interval: 12,
      start_time: '2023-07-15 00:00:00'
    },
    token: 'dummy_credit_card_token',
  })
  console.log(result)

Get Subscription

  const result = await this.midtransService.getSubscription('SUBSCRIPTION-ID-123')
  console.log(result)

Disable Subscription

  const result = await this.midtransService.disableSubscription('SUBSCRIPTION-ID-123')
  console.log(result)

Enable Subscription

  const result = await this.midtransService.enableSubscription('SUBSCRIPTION-ID-123')
  console.log(result)

Update Subscription

  const result = await this.midtransService.updateSubscription('4b9273ae-8bfa-4400-94fe-ba4b2b4af70f', {
      name: 'Langganan bulanan',
      amount: 50000,
      currency: 'IDR',
      token: 'dummy_credit_card_token'
  })
  console.log(result)

References

Support

If you like this package, you can support me by:

Stay in touch

If you have any question, feel free to contact me on:

License

MIT licensed.