Skip to content

decorator.js

James ZHANG edited this page Jan 19, 2022 · 5 revisions

Decorator

Decorate the Axios instance

Kind: global class

new Decorator(config)

Decorate factory

Param Type Description
config object configuration
config.mchid string The merchant ID
config.serial string The serial number of the merchant certificate
config.privateKey string | Buffer The merchant private key certificate
config.certs object The wechatpay provider size configuration, {serial: publicKey} pair
[config.secret] string The merchant secret key string
[config.merchant] object The merchant certificates, more @see {import('tls').createSecureContext}
[config.merchant.cert] string | Buffer The merchant cert chains in PEM format
[config.merchant.key] string | Buffer The merchant private keys in PEM format
[config.merchant.pfx] string | Buffer The merchant PFX or PKCS12 encoded private key and certificate chain.
[config.merchant.passphrase] string | Buffer The merchant shared passphrase used for a single private key and/or a PFX.

decorator.v2 ⇒ AxiosInstance

Getter APIv2's client (xmlBased)

Kind: instance property of Decorator
Returns: AxiosInstance - - The axios instance

decorator.v3 ⇒ AxiosInstance

Getter APIv3's client (jsonBased)

Kind: instance property of Decorator
Returns: AxiosInstance - - The axios instance

decorator.request([pathname], [method], [data], [config]) ⇒ PromiseLike

Request the remote pathname by a HTTP method verb

Kind: instance method of Decorator
Returns: PromiseLike - - The AxiosPromise

Param Type Description
[pathname] string The pathname string.
[method] string The method string.
[data] object | Buffer The data.
[config] object The config.

Decorator.defaults

Kind: static property of Decorator
Properties

Name Type Description
defaults object The defaults configuration whose pased in Axios.

Decorator.withDefaults(config) ⇒ object

Deep merge the input with the defaults

Kind: static method of Decorator
Returns: object - - With the built-in configuration.

Param Type Description
config object The configuration.

Decorator.xmlBased(config) ⇒ AxiosInstance

Create an APIv2's client

Kind: static method of Decorator
Returns: AxiosInstance - - The axios instance

Param Type Description
config object configuration
[config.mchid] string The merchant ID
[config.secret] string The merchant secret key string
[config.merchant] object The merchant certificates, more @see {import('tls').createSecureContext}
[config.merchant.cert] string | Buffer The merchant cert chains in PEM format
[config.merchant.key] string | Buffer The merchant private keys in PEM format
[config.merchant.pfx] string | Buffer The merchant PFX or PKCS12 encoded private key and certificate chain.
[config.merchant.passphrase] string | Buffer The merchant shared passphrase used for a single private key and/or a PFX.

Decorator.requestInterceptor() ⇒ function

APIv3's requestInterceptor

Kind: static method of Decorator
Returns: function - Named signer function

Decorator.responseVerifier(certs) ⇒ function

APIv3's responseVerifier

Kind: static method of Decorator
Returns: function - Named as verifier function

Param Type Description
certs object The wechatpay platform serial and certificate(s), {serial: publicKey} pair

Decorator.jsonBased(config) ⇒ AxiosInstance

Create an APIv3's client

Kind: static method of Decorator
Returns: AxiosInstance - - The axios instance

Param Type Description
config object configuration
config.mchid string The merchant ID
config.serial string The serial number of the merchant certificate
config.privateKey string | Buffer The merchant private key certificate
config.certs object The wechatpay platform serial and certificate(s), {serial: publicKey} pair