0.0.2 • Published 2 years ago

@suxhk/pay-platform-js v0.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Installing

Package manager

Using npm:

$ npm install @suxhk/pay-platform-js

Using yarn:

$ yarn add @suxhk/pay-platform-js

Using pnpm:

$ pnpm add @suxhk/pay-platform-js

Once the package is installed, you can import the library using import or require approach:

import { getCloudFunction } from '@suxhk/pay-platform-js'

If you use require for importing

const { getCloudFunction }  = require('@suxhk/pay-platform-js')

You can import the library using browser

<script src="https://unpkg.com/@suxhk/pay-platform-js/dist/index.iife.js"></script>

<script>
  console.log(window.PayPlatformJs)
  /**
   * {
   *	getCloudFunction: ƒ ()
   * }
   */
</script>

<script>
  // For Example
  window.PayPlatformJs.getCloudFunction({ 
      token_id: '2023******1234',
      resourceAppid: 'wx***',
      resourceEnv: 'wx***'
  	})
    .then((result) => {
      console.log('🚀', result)
    })
    .catch((error) => {
      console.log('❌', error)
    })
</script>

CDN

Using unpkg CDN (ES5 UMD browser):

<script src="https://unpkg.com/@suxhk/pay-platform-js/dist/index.iife.js"></script>

or jsdelivr CDN

<script src="https://cdn.jsdelivr.net/npm/@suxhk/pay-platform-js/dist/index.iife.js"></script>

Example

Note CommonJS usage In order to gain the TypeScript typings (for intellisense / autocomplete) while using CommonJS imports with require(), use the following approach:

import { getCloudFunction } from '@suxhk/pay-platform-js'

// the `tokenId` is required
getCloudFunction({ 
    token_id: '2023******1234',
    resourceAppid: 'wx***',
    resourceEnv: 'wx***' 
  })
  .then(result => {
    // handle success
    console.log('🚀', result)
  })
  .catch(error => {
    // handle error
    console.log('❌', error)
  })
  .finally(()=> {
    // always executed
  })

Use Function Config

These are the available config options for making requests. Only the tokenId resourceAppid resourceEnv is required.

{
  // `tokenId resourceAppid resourceEnv`  is returned when the order is ordered
  
  token_id: '2023******1234', // token id
  resourceAppid: 'wx***', // 资源方 AppID
  resourceEnv: 'wx***' // 资源方环境 ID
      
}

Promises

@suxhk/pay-platform-js depends on a native ES5/6 Promise implementation to be supported.

Method

function call | Function | Definition | Return value | | ---------------- | ---------------- | ------------ | | getCloudFunction | H5拉起微信云函数 | Promise |

Wechat Documents

<a href="https://developers.weixin.qq.com/miniprogram/dev/wxcloud/guide/web/sdk.html"

      >Web SDK</a
    >

License

MIT

Thanks

0.0.2

2 years ago

0.0.1

2 years ago