Socket
Book a DemoInstallSign in
Socket

@xct007/midtrans-client

Package Overview
Dependencies
Maintainers
0
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xct007/midtrans-client

Unofficial Midtrans Payment API Client Library

latest
Source
npmnpm
Version
0.0.3
Version published
Maintainers
0
Created
Source

Unofficial Midtrans Client Library

An unofficial Midtrans Payment API Client Library for Node.js.

npm version license CI Status

Installation

npm install @xct007/midtrans-client

Usage

import the library

// CommonJS
const MidtransClient = require("@xct007/midtrans-client").default;

// ES Modules
import MidtransClient from "@xct007/midtrans-client";

Initialize the client

const { Core, Snap, Iris } = new MidtransClient({
 sandbox: true, // Set to false for production
 clientKey: "YOUR_CLIENT_KEY",
 serverKey: "YOUR_SERVER_KEY",
 throwHttpErrors: true,
});

Core API Example

Core.charge({
 payment_type: "bank_transfer",
 transaction_details: {
  order_id: "order-id-" + new Date().getTime(),
  gross_amount: 10000,
 },
 bank_transfer: {
  bank: "bca",
 },
})
 .then((response) => {
  console.log("Charge Response:", response);
 })
 .catch((error) => {
  console.error("Charge Error:", error);
 });

Explore more Core API methods on examples/core.

Snap API Example

Snap.create({
 transaction_details: {
  order_id: "order-id-" + new Date().getTime(),
  gross_amount: 10000,
 },
})
 .then((response) => {
  console.log("Snap Token:", response.token);
  console.log("Redirect URL:", response.redirect_url);
 })
 .catch((error) => {
  console.error("Snap Error:", error);
 });

Explore more Snap API methods on examples/snap.

Iris API Example

Iris.ping()
 .then((response) => {
  console.log("Ping Response:", response);
 })
 .catch((error) => {
  console.error("Ping Error:", error);
 });

Explore more Iris API methods on examples/iris.

Documentation

For hands-on examples, please refer to the examples directory.

For detailed API documentation, please refer to the Midtrans API Documentation.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • This library is unofficial and maintained by xct007.
  • This library is inspired by the official Midtrans Node.js Client
  • Special thanks to Midtrans team.

Keywords

api

FAQs

Package last updated on 16 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts