# ping-pay

> ### 安装方法 ```linux $ npm i @hetao/hetao-pay -S ```

Latest version **2.1.8** (published 2020-12-21) · ISC license · 0 weekly downloads

## Install

```sh
npm install ping-pay
pnpm add ping-pay
yarn add ping-pay
bun add ping-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 | 2.1.8 |
| Published | 2020-12-21 |
| First published | 2020-12-21 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 475.6 KB |
| Known vulnerabilities | 0 (+26 in 2 direct dependencies) |
| Install scripts | no |
| Maintainers | feimo |

## Links

- npm: https://www.npmjs.com/package/ping-pay
- Repository: https://git.corp.hetao101.com/tangbinbin/npm-hetao-pay
- npm.io page: https://npm.io/package/ping-pay

## Dependencies (7)

- [axios](https://npm.io/package/axios.md) ^0.19.0
- [jquery](https://npm.io/package/jquery.md) ^3.4.1
- [js-cookie](https://npm.io/package/js-cookie.md) ^2.2.1
- [pingpp-js](https://npm.io/package/pingpp-js.md) ^2.2.14
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.6.2
- [@babel/runtime-corejs2](https://npm.io/package/@babel/runtime-corejs2.md) ^7.7.4
- [@babel/runtime-corejs3](https://npm.io/package/@babel/runtime-corejs3.md) ^7.7.4

## Recent versions

- 2.1.8 (latest) — 2020-12-21

## README

# npm-hetao-pay

### 安装方法
```linux
    $ npm i @hetao/hetao-pay -S
```

### 引用方法
```javascript
    import { hetaoPay } from "@hetao/hetao-pay";
```

### API
`hetaoPay({data | charge})`

> `data` 或 `charge` 两个参数其中必须存在一个，传入一个参数即可，如果两个同时存在会按`charge`参数调用支付。

`data` 参数为创建订单所需要的全部参数，传入`data`参数后会自动调用getOrder方法并调起支付。

`charge`参数为ping++ charge信息或nowpay charge信息。
```javascript
    import { hetaoPay } from "@hetao/hetao-pay";

    // charge 直接调用支付方法
    hetaoPay({charge}).then(res => {
        // pay success && res === 'success'
    }).catch(error => {
        // pay error | fail | cancel | res.err_code !== 0
        // pay error | fail | cancel | res !== 'success'
    });

    //调用招商银行的现在支付需要传入merchantId参数
    hetaoPay({charge: {merchantId: 'nowpay', charge: charge}});

    // data 先下单再调用支付方法
    hetaoPay({data}).then(res => {
        // pay success && res.err_code === 0 && res === 'success'
    }).catch(error => {
        // pay error || fail || cancel || res.err_code !== 0 || res !== 'success'
    });
```

`getOrder(data)`

创建订单，返回订单信息

`data`参数为创建订单所需要的全部参数。
``` javascript
    import { getOrder, hetaoPay } from "@hetao/hetao-pay";

    getOrder(data).then(res => {
        // res.err_code === 0
        let charge = res.data.charge;
        hetaoPay({charge});
    }).catch(error => {
        // error || res.err_code !== 0
    });
```

`payCheck({orderNumber [, i, max, requireType, successUrl]})`

根据`prderNumber`查询订单支付状态.

`i` 订单查询次数的起始值，默认：0。

`max` 订单查询的最大次数，默认：4。

`requireType` 区分`course-shop`系统订单和`shop`系统订单，默认`shop`。

`successUrl` 设置支付成功url后，订单校验为支付成功时页面会直接跳至指定url，否则执行回调函数。

```javascript
    payCheck({orderNumber}).then(res => {
        // 支付成功 data && data.paid
    }).catch(error => {
        // catch || !data.paid
        // 查询4次无支付成功
    });

    // 验证成功后直接跳转到指定url
    payCheck({
        orderNumber,
        successUrl: `${window.location.origin}/studentInfo?classId=${classId}&activityId=${activityId}`
    });
```

### 参数说明
创建订单的`data`对象分为`md`、`course-shop`和`shop`三种模式，默认为`shop`模式。
- `md`模式会将请求到发送到node中间层做中转处理广告数据埋点，参数中需要附带广告统计所需参数。
- `course-shop`模式会将请求直接发送到course-shop服务获取订单信息。
- `shop`模式会将请求直接发送到shop服务获取订单信息，其中又分为微信内和微信外两种数据结构。

```javascript
/* md模式 */
{
    requireType: 'md',
    orderData: {
        phone_number,
        activity_id,
        pay_channel
    },
    adtag,
    adData: {
        type,
        link,
        clickId,
        phoneNumber,
        adtag
    }
}

/* course-shop模式 */
{
    requireType: 'course-shop',
    itemId,
    userId,
    classId,
    payChannel: 'wx_pub',
    openId
}

/* shop模式 微信内 */
{
    requireType: 'shop',
    course_package_id,
    term_id,
    activity_id,
    phone_number,
    pay_channel,
    verificationcode
}

/* shop模式 微信外 */
{
    requireType: 'shop',
    course_package_id,
    term_id,
    user_id,
    open_id,
    activity_id,
    phone_number,
    pay_channel
}
```

### 项目地址
[gitlab](https://git.corp.hetao101.com/tangbinbin/npm-hetao-pay)
[本地npm](https://npm.corp.hetao101.com/#/detail/@hetao/hetao-pay)

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