New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@hudoro/central-payment

Package Overview
Dependencies
Maintainers
4
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hudoro/central-payment

Backend bundling for express

latest
npmnpm
Version
0.0.1-beta.3
Version published
Maintainers
4
Created
Source

Hudoro Central Payment

Hudoro Central Payment is a package that provides centralized integration for payment systems, designed to facilitate communication with multiple payment service providers from a single point.

Package instalation

Instal package using pnpm

  pnpm add @hudoro/central-payment

Instal package using yarn

  yarn add @hudoro/central-payment

Instal package using npm

  npm i @hudoro/central-payment

Configuration

To start using the Midtrans integration, you need to initialize it with your Midtrans credentials:

import { transactionConfig } from 'your-package-name';

const midtransClient = transactionConfig({
  apiURL: 'https://api.midtrans.com',  // Use 'https://api.sandbox.midtrans.com' for testing
  snapURL: 'https://app.midtrans.com', // Use 'https://app.sandbox.midtrans.com' for testing
  serverKey: 'YOUR_SERVER_KEY'
});

Usage

Create Standard Transaction

Create a standard transaction via Midtrans Snap:

const createTransaction = async () => {
  try {
    const response = await midtransClient.createTransaction({
      transaction_details: {
        order_id: "ORDER-" + new Date().getTime(),
        gross_amount: 100000
      },
      customer_details: {
        name: "John Doe",
        email: "john@example.com"
      },
      item_details: [
        {
          name: "Product Name",
          price: 100000,
          quantity: 1
        }
      ],
      callbacks: {
        finish: "https://example.com/finish",
        error: "https://example.com/error",
        pending: "https://example.com/pending"
      }
    });
    
    console.log("Transaction token:", response.data.token);
    console.log("Redirect URL:", response.data.redirect_url);
    
    return response.data;
  } catch (error) {
    console.error("Error creating transaction:", error);
  }
};

Create QRIS Transaction

Create a QRIS dynamic transaction:

const createQrisTransaction = async () => {
  try {
    const response = await midtransClient.createQrisMidtransTransaction({
      transaction_details: {
        order_id: "QRIS-" + new Date().getTime(),
        gross_amount: 50000
      },
      customer_details: {
        name: "Customer Name",
        email: "customer@example.com"
      }
    });
    
    console.log("QRIS String:", response.data.qr_string);
    console.log("Expiry Time:", response.data.expiry_time);
    
    return response.data;
  } catch (error) {
    console.error("Error creating QRIS transaction:", error);
  }
};

Process Refund

Process a refund for a transaction:

const processRefund = async () => {
  try {
    const response = await midtransClient.refundTransaction({
      transactionCode: "ORDER-123456789",
      amount: 100000,
      reason: "Customer requested refund"
    });
    
    console.log("Refund Status:", response.data.status_message);
    
    return response.data;
  } catch (error) {
    console.error("Error processing refund:", error);
  }
};

Direct Refund

Process a direct online refund:

const processDirectRefund = async () => {
  try {
    const response = await midtransClient.directRefundTransaction({
      transactionCode: "ORDER-123456789",
      amount: 100000,
      reason: "Customer requested refund"
    });
    
    console.log("Direct Refund Status:", response.data.status_message);
    
    return response.data;
  } catch (error) {
    console.error("Error processing direct refund:", error);
  }
};

Cancel Transaction

Cancel a transaction:

  try {
    const response = await midtransClient.cancelTransaction("ORDER-123456789");
    
    console.log("Cancel Status:", response.data.status_message);
    
    return response.data;
  } catch (error) {
    console.error("Error cancelling transaction:", error);
  }
};

Data Types

The package includes TypeScript interfaces for all request and response objects:

ParameterTypes: Request parameters for creating transactions
MidtransResponse: Response for standard transactions
MidtransQrisDynamicResponse: Response for QRIS transactions
MidtransRefundResponse: Response for refund operations
RefundParams: Parameters for refund operations
ItemDetail: Structure for describing order items

FAQs

Package last updated on 16 Apr 2025

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