1.5.3 • Published 10 months ago

payshift v1.5.3

Weekly downloads
-
License
ISC
Repository
-
Last release
10 months ago

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
  • N-Genius Payments

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)
1.2.0

10 months ago

1.4.0

10 months ago

1.2.1

10 months ago

1.0.62

1 year ago

1.0.66

1 year ago

1.0.65

1 year ago

1.0.64

1 year ago

1.0.63

1 year ago

1.0.68

1 year ago

1.0.67

1 year ago

1.0.71

11 months ago

1.0.70

1 year ago

1.1.1

10 months ago

1.1.0

10 months ago

1.5.3

10 months ago

1.5.2

10 months ago

1.5.1

10 months ago

1.5.0

10 months ago

1.1.3

10 months ago

1.3.0

10 months ago

1.1.2

10 months ago

1.0.61

1 year ago

1.0.60

1 year ago

1.0.59

1 year ago

1.0.58

2 years ago

1.0.57

2 years ago

1.0.56

2 years ago

1.0.55

2 years ago

1.0.51

2 years ago

1.0.54

2 years ago

1.0.53

2 years ago

1.0.52

2 years ago

1.0.50

2 years ago

1.0.49

2 years ago

1.0.37

2 years ago

1.0.36

2 years ago

1.0.35

2 years ago

1.0.39

2 years ago

1.0.38

2 years ago

1.0.40

2 years ago

1.0.44

2 years ago

1.0.43

2 years ago

1.0.42

2 years ago

1.0.41

2 years ago

1.0.48

2 years ago

1.0.47

2 years ago

1.0.46

2 years ago

1.0.45

2 years ago

1.0.34

2 years ago

1.0.33

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.30

2 years ago

1.0.26

2 years ago

1.0.27

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago