# @edu-fe/pay

> A pay schema for edu-fe

Latest version **1.3.4** (published 2018-08-20) · UNLICENSED license · 0 weekly downloads

## Install

```sh
npm install @edu-fe/pay
pnpm add @edu-fe/pay
yarn add @edu-fe/pay
bun add @edu-fe/pay
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.4 |
| Published | 2018-08-20 |
| First published | 2018-05-02 |
| Weekly downloads | 0 |
| License | UNLICENSED |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 18.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | ccforeverd, mutu, shockw4ver |

## Links

- npm: https://www.npmjs.com/package/@edu-fe/pay
- npm.io page: https://npm.io/package/@edu-fe/pay

## Dependencies (4)

- [@edu-fe/os](https://npm.io/package/@edu-fe/os.md) ^1.1.3
- [@edu-fe/api](https://npm.io/package/@edu-fe/api.md) ^1.0.1
- [@edu-fe/login](https://npm.io/package/@edu-fe/login.md) ^1.1.11
- [@ccforeverd/tool-get](https://npm.io/package/@ccforeverd/tool-get.md) ^1.1.6

## Recent versions

- 1.3.4 (latest) — 2018-08-20
- 1.3.3 — 2018-08-02
- 1.3.2 — 2018-08-02
- 1.3.1 — 2018-08-02
- 1.3.0 — 2018-07-30
- 1.2.9 — 2018-07-30
- 1.2.8 — 2018-07-25
- 1.2.6 — 2018-05-31
- 1.2.5 — 2018-05-29
- 1.2.4 — 2018-05-28
- 1.2.3 — 2018-05-28
- 1.2.2 — 2018-05-28
- 1.2.1 — 2018-05-28
- 1.2.0 — 2018-05-28
- 1.1.17 — 2018-05-25
- … 48 more at https://npm.io/package/@edu-fe/pay/versions

## README

# @edu-fe/pay

```bash

  # yarn 安装
  $ yarn add @edu-fe/pay

  # npm 安装
  $ npm i -S @edu-fe/pay

```

``` js

  // new 即调用支付
  const pay = new Pay({
    courseId: '',
    type: 1
  })
  console.log(pay)

```

### 支付流程

```

    进入
      ↓
    判断是否登录 → 否 → login() → end
      ↓ 是
  ① 判断课程是否已购买 → 是 → hasBuyCallback() -> end
      ↓ 否 -- 以上为准备阶段
  ② 判断是否传入优惠券 → 是 → ⑤
      ↓ 否
  ③ 判断是否在购买页 → 是 → ⑤
      ↓ 否
  ④ 判断是否有可用的优惠券 → 是 → gotoPayment() 去支付页 -> end
      ↓ 否
  ⑤ 判断是否免费 → 是 → free() -> ⑥
      ↓ 否
    pay() 判断端
      ↓
  ⑥ 轮询订单状态 (有orderId时直接开启轮询, 没有时先通过courseId查询orderId然后轮询)
      ↘ h5支付宝支付: returnUrl 为当前页面, 后台会加上orderId, 进入页面时如果有orderId, 则开启轮询
      ↘ h5微信支付: 返回当前页面, 根据 courseId 来查询 orderId, 开启轮询
      ↘ 微信支付: 轮询
      ↘ 其他支付: 轮询
      ↓ 成功
    gotoResult(orderId) 去结果页, 在结果页中判断是否赠送
      ↓
    end

```

### 参数


| name                | typeof       | required      | default   | description  | other                                                      |
|---------------------|--------------|---------------|-----------|--------------|------------------------------------------------------------|
| courseId            | String       | yes           | -         | 商品Id         | -                                                          |
| type                | Number       | -             | 1         | 商品类型         | 1:课程 2:专题 8:畅读卡                                            |
| gotoResult          | Function     | yes           | -         | 去往结果页        | -                                                          |
| payment             | Boolean      | -             | false     | 是否在支付页调用支付   | -                                                          |
| gotoPayment         | Function     | -             | -         | 去往支付页        | 当 payment 不为 true 时会被调用, 如果没有传递 gotoPayment, 则直接执行支付       |
| couponId            | String       | -             | -         | 优惠券id        | -                                                          |
| price               | Number       | -             | -         | 价钱           | 不一定是实际支付价钱, 用于判断是否免费                                       |
| free                | Boolean      | -             | false     | 是否是免费支付      | 为 true 不会再判断 price 参数                                      |
| from                | String       | -             | 'edu_pay' | 订单来源         | 先取传入参数, 未传入则去链接中的 from 字段, from 字段为空时使用 'edu_pay'          |
| isSend              | Boolean      | -             | false     | 是否是赠送        | 赠送课程成功会调用 sendCallback                                     |
| theme               | Number       | -             | 1         | 赠送主题         | isSend 为 true 时会用到                                         |
| payWay              | Number       | yes when h5   | -         | 下单方式         | 9:支付宝 10:微信支付 (如果h5支付时没传, 则调用 gotoPayment)                 |
| thirdSession        | String       | yes when wxmp | -         | 小程序用户信息      | -                                                          |
| token               | String       | -             | -         | 分享唯一标示       | 用于分销                                                       |
| hasBuyCallback      | Function     | -             | -         | 已购买回调        | 几乎是必须                                                      |
| ~~sendCallback~~    | ~~Function~~ | -             | -         | ~~赠送回调(废弃)~~ | ~~isSend 为 true 时会用到~~                                     |
| ~~successCallback~~ | ~~Function~~ | -             | -         | ~~成功回调(废弃)~~ | ~~若 isSend 为true, 则先调用 sendCallback, 再调用 successCallback~~ |


### 实例属性和方法(有用的)

| name                                | async function | description | other               |
|-------------------------------------|----------------|-------------|---------------------|
| params                              | -              | 参数集合        | 传进去的和内部处理过的         |
| wpsSid                              | -              | 用户id        | -                   |
| resultData                          | -              | 支付结果返回数据    | { orderId, giftId } |
| getWpsSid()                         | yes            | 获取用户id      | 重新获取id              |
| getFrom()                           | no             | 获取from      | -                   |
| checkLogin(callback)                | yes            | 检查登录并调用     | -                   |
| checkCourse(courseId, type, wpsSid) | yes            | 检查课程是否已购买   | -                   |
| checkCoupon(courseId, type, wpsSid) | yes            | 检查课程是否有可用优惠 | -                   |
| pay()                               | yes            | 支付          | new 时会被调用           |
| pay5()                              | yes            | 从第五步开始的支付   | -                   |
| startLoop()                         | no             | 开启订单轮询      | -                   |
| stopLoop()                          | no             | 结束订单轮询      | -                   |
| finish()                            | no             | 支付成功        | -                   |

---
_Source: https://npm.io/package/@edu-fe/pay · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
