# 支付系统

## 支持支付渠道

* [x] 支付宝 面对面支付
* [x] 码支付
* [x] 易支付
* [x] PayJs
* [x] ~~MugglePay 麻瓜宝 (跑路了)~~
* [x] PayPal&#x20;
* [x] Stripe
* [x] PayBeaver 海狸支付
* [x] THeadPay 平头哥支付

## 使用

1. 访问：网站地址/admin/system#payment
2. 设置对应支付渠道的相关配置
3. 选填【通用支付回调地址】，【自定义商品名称】
4. 在【支付宝支付】【微信支付】【QQ钱包】【特殊支付】中选择渠道，以启用渠道

### 各渠道申请

* [支付宝面对面](https://open.alipay.com/platform/appManage.htm?#/create/)
* [码支付](https://codepay.fateqq.com/i/63779)
* 易支付：无；← 本支付为支付API框架，只要对应支付渠道声明支持易支付，即可使用本支付方式！
* [PayJs](https://payjs.cn/ref/zgxjnb)
* [麻瓜宝](https://merchants.mugglepay.com/basic/api)
* [PayPal](https://www.paypal.com/businessprofile/mytools/apiaccess/firstparty)
* [Stripe](https://dashboard.stripe.com/dashboard)
* [海狸支付](https://merchant.paybeaver.com/?aff_code=iK4GNuX8)
* [平头哥支付](https://theadpay.com/)

## 对接支付渠道教程

{% hint style="info" %}
下表中提及文件均可作为新对接文件的参考和代码规范资料！
{% endhint %}

| 文件地址                                            | 描述           |
| ----------------------------------------------- | ------------ |
| resources/views/admin/config/system.blade.php   | 【系统设置】前端页面   |
| app/Http/Controllers/Admin/SystemController.php | 【系统设置】后端控制文件 |
| app/Http/Controllers/Gateway/\*                 | 各渠道的对接文件     |
| app/Http/Controllers/PaymentController.php      | 支付系统总控制      |
| app/Models/Order.php                            | 支付显示标签       |

1. 在`app/Http/Controllers/Gateway/*`下添加新的支付渠道php文件；

   1. 该文件class推荐为 extends AbstractPayment，该文件存有大量必要function方程；

   2. 文件必含方程：purchase, notify;&#x20;

   > * purchase
   >
   >   ```
   >   // 获取商品信息建立面板在线订单
   >   $payment = $this->creatNewPayment(Auth::id(), $request->input('id'), $request->input('amount'));
   >   ```
   >
   >   从$payment 获取支付渠道需要的订单信息。建立渠线支付单，再对渠道返回信息进行储存或转跳处理。支付链接生成二维码保存到payment的qr\_code下（参考F2Fpay）或者保存url转跳至支付网站（参考Paypal）；
   > * notify：接受异步通知，进行必要的来源验证，订单成功状态验证等。
   >
   >   ```
   >   // 支付入账，开通服务
   >   $this->paymentReceived(string 面板payment的Trade No)
   >   ```
   >
   >   返回状态码，如果渠道需要状态码确认通知是否收到的话。
   >
   >   * 其中notify\_url/callback\_url等异步通知链接设置为
   >
   >     ```
   >     route('payment.notify', ['method' => '支付getPayment转跳名']),
   >     ```
2. 在`app/Http/Controllers/PaymentController.php`中`getClient()`添加支付方式转跳名；
3. 在`app/Http/Controllers/Admin/SystemController.php`中`getPayment()`支付设置判断 switch中 添加支付方式必填项目；
4. 可使用Laravel的`magration`工具，往数据库 config 表中加入必要的配置信息；
5. 在`resources/views/admin/config/system.blade.php`中添加配置设置；
6. `config/common.php`中`payment->labels`下添加支付方式转跳名与显示标签名。

大部分面板处理代码都已经精简细化，方便添加新的支付方式；有疑问可以开issue 😀


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://proxypanel.gitbook.io/wiki/payment.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
