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

payshift

v1.0.56

Published

unified payment api for multiple payment processors

Downloads

164

Readme

Payshift

unified payment api for multiple payment processors

Installation

npm install payshift

Supported Payment Processors

  • Alipay
  • Wechat Pay
  • Stripe
  • Paypal
  • EPay
  • Multiple EPay instances with round robin algorithm to split your cashflow and risk
  • CCBill

Usage

import {
  Payshift,
  AlipayProvider,
  StripeProvider,
  WechatPayProvider,
  EPayProvider,
  EPayClusterProvider
} from "payshift"
import { privateKeyPath, alipayPublicKeyPath, appId } from "your alipay config"
import { testKey, endpointSecret } from "your stripe config"
import { apiKey, mcid, publicKeyPath } from "your wechatpay config"
import { pid, key, endpoint } from "your epay config"

const alipay = new AlipayProvider({ 
  appId,
  privateKey: fs.readFileSync(path.join(__filename, privateKeyPath))
  alipayPublicKey: fs.readFileSync(path.join(__filename, alipayPublicKeyPath))
})
const stripe = new StripeProvider(testKey)
const wechat = new WechatPayProvider(appId, mcid, publicKeyPath, privateKeyPath, apiKey)
const epay = new EPayProvider(endpoint, pid, key)
const anotherEPay = new EPayProvider(anotherEndpoint, anotherPid, anotherKey)
const epayCluster = new EPayClusterProvder([epay, anotherEPay])

const payshift = new Payshift([alipay, stripe, wechat, epay, epayCluster], {
  stripeEndpointSecret: endpointSecret
})
// webhooks server, used for notify_url for some payments
payshift.startWebServer('http://localhost:3000', 3000)

// optionally, you can use mongodb to save your txns in "payshift" database
payshit.usedb()

// handle webhooks using the internal webhook server
payshift.on('charge.succeeded', async event => {
  // handle event, eg. update the status of your order
  // throwing any error will fail the webhook to the payment processor as well
})

Where event is a PayshiftEvent

type PayshiftEvent = {
  amount?: number, // in cents
  title?: string,
  outTradeNo?: string,
  tradeNo?: string,
  provider: PayshiftProviderName,
  name: PayshiftEventName,
  currency?: CurrencyCode,
  accountId?: string,
}

Then

// depending on your channel, res varys
const res = await payshift.createCharge({
  outTradeNo: '123123123',
  title: 'item',
  amount: 1,
  channel: 'alipay_mobile_web',
  currency: CurrencyCode.CNY,
  returnUrl: 'http://taobao.com',
  clientIp: '127.0.0.1',
})

// in this case for alipay_mobile_web, res.data is a string of url
return res.data

Supported Payment Channels

type PayshiftChannel = 'stripe_web' | 'alipay_web' | 'wechat_qrcode' |
'wechat_mobile_web' | 'alipay_mobile_web' | 'epay_alipay' | 'epay_wechat_pay' |
'epay_cluster_alipay' | 'epay_cluster_wechat_pay' | 'order2faka' | 'paypal' | 'ccbill_web'

Using Provider Alone

Of course you can use provider independently

const provider = new StripeProvider(testKey)
const accountId = await provider.createAccount({
  country: 'JP',
  type: 'express',
  business_type: 'individual',
  capabilities: { transfers: { requested: true }},
  tos_acceptance: { service_agreement: 'recipient' },
})
const url = await provider.createAccountLink(accountId, 'http://taobao.com', 'http://taobao.com')
console.log(url)