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

bkash-dynamic-payment

v1.0.1

Published

A Node.js application for integrating bKash dynamic charge payment.

Downloads

7

Readme

bKash Dynamic Charge Payment

Library to integrate bKash Dynamic Charge Payment on your backend application.

NPM Install

npm install bkash-dynamic-payment

Yarn Install

yarn add bkash-dynamic-payment

bkashConfig Setup (Sandbox)

const bkashConfig = {
  base_url : 'https://sbdynamic.pay.bka.sh/v1',
  username: '01300937619',
  password: '^Wl1a:vFM}=',
  app_key: '1zc62IvSLdUrKUBCNYT5mNv6dc',
  app_secret: 'ErLjX0BsABGk0T1ETpRbXoM7Gke3WtTWJcFxKTuUfQV234ZcKsO7'
 }

bkashConfig Setup (Live)

const bkashConfig = {
  base_url : 'https://sbdynamic.pay.bka.sh/v1',
  username: 'your_bkash_provide_username',
  password: 'your_bkash_provide_password',
  app_key: 'your_bkash_provide_app_key',
  app_secret: 'your_bkash_provide_app_secret'
 }

Without Agreement

bkashDynamicPaymentGateway.js

const express = require('express')
const { createPayment, executePayment, queryPayment, searchTransaction, refundTransaction } = require('bkash-dynamic-payment')
const cors = require('cors')
const bodyParser = require('body-parser')
const app = express()
const port = 3000

// Middleware setup
app.use(cors())
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))

// bKash Credentials setup
const bkashConfig = {
  base_url : 'bKash_base_url',
  username: 'your_bkash_username',
  password: 'your_bkash_password',
  app_key: 'your_bkash_app_key',
  app_secret: 'your_bkash_app_secret'
 }

app.post("/bkash-checkout", async(req, res) => {
  try {
    const { amount, callbackURL, orderId, reference } = req.body
    const paymentDetails = {
      amount: amount || 10,                                                 // your product price
      callbackURL : callbackURL || 'http://127.0.0.1:3000/bkash-callback',  // your callback route
      orderId : orderId || 'Order_101',                                     // your orderId
      reference : reference || '1'                                          // your reference
    }
    const result =  await createPayment(bkashConfig, paymentDetails)
    res.send(result)
  } catch (e) {
    console.log(e)
  }
})

app.get("/bkash-callback", async(req, res) => {
  try {
    const { status, paymentId } = req.query
    let result
    let response = {
      statusCode : '400',
      statusMessage : 'Payment Failed'
    }
    if(status === 'success')  result =  await executePayment(bkashConfig, paymentId)

    if(result?.transactionStatus === 'Completed'){
      // payment success
      // insert result in your db
      response.statusCode = '200'
      response.statusMessage = 'Payment Successful'
    }

    // You may use here WebSocket, server-sent events, or other methods to notify your client
    res.send(response)
  } catch (e) {
    console.log(e)
  }
})

// Add this route under admin middleware
app.post("/bkash-refund", async (req, res) => {
  try {
    const { paymentId, trxId, amount } = req.body
    const refundDetails = {
      paymentId,
      trxId,
      amount,
    }
    const result = await refundTransaction(bkashConfig, refundDetails)
    res.send(result)
  } catch (e) {
    console.log(e)
  }
})

app.get("/bkash-search", async (req, res) => {
  try {
    const { trxId } = req.query
    const result = await searchTransaction(bkashConfig, trxId)
    res.send(result)
  } catch (e) {
    console.log(e)
  }
})

app.get("/bkash-query", async (req, res) => {
  try {
    const { paymentId } = req.query
    const result = await queryPayment(bkashConfig, paymentId)
    res.send(result)
  } catch (e) {
    console.log(e)
  }
})

app.listen(port, () =>
  console.log(`Example app listening at http://127.0.0.1:${port}`)
)

Create Payment

  const paymentDetails = {
      amount: 10,                                      // your product price
      callbackURL : 'http://127.0.0.1:3000/callback',  // your callback route
      orderId : 'Order_101',                           // your orderId
      reference : '1'                                  // your reference
    }
const result =  await createPayment(bkashConfig, paymentDetails)

Execute Payment

const result =  await executePayment(bkashConfig, paymentId)

Query Payment

const result =  await queryPayment(bkashConfig, paymentId)

Search Transaction

const result =  await searchTransaction(bkashConfig, trxId)

Refund Transaction

const refundDetails = {
paymentId: "TR101001111",
trxId: "ASFFDDD8G",
amount: 10
}
const result =  await refundTransaction(bkashConfig, refundDetails)

With Agreement

const { createAgreement, executeAgreement, cancelAgreement, createPaymentWithAgreement, executePayment, queryPayment, searchTransaction, refundTransaction } = require('bkash-dynamic-payment')

Create Agreement

  const paymentDetails = {
      amount: 10,                                                // your product price
      callbackURL : 'http://127.0.0.1:3000/agreement-callback',  // your callback route
      orderId : 'Order_101',                                     // your orderId
      reference : '1'                                            // your reference
    }
const result =  await createAgreement(bkashConfig, paymentDetails)

Execute Agreement

const result =  await executeAgreement(bkashConfig, paymentId)

Cancel Agreement

const result =  await cancelAgreement(bkashConfig, agreementId)

Create Payment With Agreement

  const paymentDetails = {
      agreementId: "TokenizedMerchant01L3IKB6H1565072174986"            // agreementId from executeAgreement API
      amount: 10,                                                       // your product price
      callbackURL : 'http://127.0.0.1:3000/payment-callback',           // your callback route
      orderId : 'Order_101',                                            // your orderId
      reference : '1'                                                   // your reference
    }
const result =  await createPaymentWithAgreement(bkashConfig, paymentDetails)

Execute Payment

const result =  await executePayment(bkashConfig, paymentId)

Query Payment

const result =  await queryPayment(bkashConfig, paymentId)

Search Transaction

const result =  await searchTransaction(bkashConfig, trxId)

Refund Transaction

const refundDetails = {
paymentId: "TR101001111",
trxId: "ASFFDDD8G",
amount: 10
}
const result =  await refundTransaction(bkashConfig, refundDetails)