nezha-docs
name | gateway | Support actions | Support callback | Remark |
---|---|---|---|---|
alipay_app | Alipay APP payment | Payment/Payment Inquiry/Refund | pay | |
alipay_qr | Alipay scan code payment | Payment/Payment Inquiry/Refund | pay | |
alipay_wap | Alipay mobile website payment | Payment/Payment Inquiry/Refund | pay | |
alipay_web | Alipay PC website payment | Payment/Payment Inquiry/Refund | pay | |
wechat_app | WeChat APP payment | Payment/Payment Inquiry/Refund/Refund Inquiry | Payment Notice/Refund Notice | |
wechat_h5 | WeChat H5 payment | Payment/Payment Inquiry/Refund/Refund Inquiry | Payment Notice/Refund Notice | Built-in function of grabbing payment links |
wechat_mina | WeChat Mini Program Payment | Payment/Payment Inquiry/Refund/Refund Inquiry | Payment Notice/Refund Notice | |
wechat_official | WeChat official account payment | Payment/Payment Inquiry/Refund/Refund Inquiry | Payment Notice/Refund Notice | |
wechat_qr | WeChat scan code payment | Payment/Payment Inquiry/Refund/Refund Inquiry | Payment Notice/Refund Notice | |
union_web | UnionPay web payment | Payment/Payment Inquiry | payment notice | older version |
union_app | UnionPay web payment | pay | payment notice | older version |
paypal_express_checkout | PayPal Express Checkout | Payment/Payment Inquiry | payment notice | unstable |
pingan_wechat_h5 | Ping An Bank WeChat H5 payment | Payment/Payment Inquiry/Refund | pay | |
wechatoversea_official | WeChat cross-border public account payment | Payment/Payment Inquiry/Refund | pay |
When connecting to third-party payments, especially when connecting to multiple third-party payments, you need to read third-party documents and spend a lot of time assembling and debugging parameters. For example, calling a third-party to place an order and create a payment. If you need to connect to WeChat and Alipay at the same time, , then you need to collect documents, which can be imagined to be very troublesome (actually, it’s okay... hhh...).
This component provides three parts for communicating with third parties:
Each part is divided into different actions. Each action is bound to a fixed form (Form), and the content of each form is fixed.
For example, when actively calling a third-party to place an order and create a payment (ChargeRequest), the form he uses is ChargeRequestForm
. After filling out the form and passing in the component, the component can process the parameters and call the third-party payment.
In this way, you only need to understand the form content of the component to connect to multiple third-party payments, once and for all (hhh does not exist).
Here we take Alipay PC website payment as an example. If you need to use other payment gateways, you only need to modify $gateway
passed in when instantiating Cashier
.
Note that the base currency unit used by the component is cents.
<?php
use Runner NezhaCashier Cashier ;
// 按格式组装好配置
$ config = [
' app_id ' => ' xxxx ' ,
' app_private_key ' => ' xxxxx ' ,
' alipay_public_key ' => ' xxxxx ' ,
];
// 创建实例, 传入要使用的 Gateway
$ cashier = new Cashier ( ' alipay_web ' , $ config );
Create payment
<?php
// 组装 ChargeRequestForm
$ data = [
' order_id ' => ' 151627101400000071 ' ,
' subject ' => ' testing ' ,
' amount ' => 1 ,
' currency ' => ' CNY ' ,
' description ' => ' testing description ' ,
' return_url ' => ' https://www.baidu.com ' ,
' expired_at ' => ' 2018-01-23 19:00:00 ' ,
];
$ form = $ cashier -> charge ( $ data );
// 以 laravel 为例
return redirect ( $ form -> get ( ' charge_url ' ));
Check payment
<?php
$ form = $ cashier -> query ([
' order_id ' => ' 151627101400000071 ' ,
]);
var_dump ( ' paid ' === $ form -> get ( ' status ' ));
receive notifications
<?php
$ form = $ cashier -> notify ( ' charge ' );
var_dump ( ' paid ' === $ form -> get ( ' status ' ));
var_dump ( $ form -> get ( ' trade_sn ' )); // 取得第三方交易号
Refund
<?php
$ form = $ cashier -> refund ([
' order_id ' => ' 151627101400000071 ' ,
' refund_id ' => ' 3151627101400000071 ' ,
' total_amount ' => 1 ,
' refund_amount ' => 1 ,
]);
Field name | Is it necessary | Field description | Remark |
---|---|---|---|
order_id | yes | Order number | |
subject | yes | Order title | |
amount | yes | Order amount | Please note that some payment channels have upper limit on the amount. |
currency | yes | Order currency | Pay attention to payment channels |
description | yes | Order description | Payment channels will have different length limits |
user_ip | no | User IP | |
return_url | no | callback address | The web type payment channel must be filled in |
show_url | no | display address | |
body | no | Order details | I should delete this parameter |
expired_at | no | Expiration time | unix timestamp |
created_at | no | creation time | Unix timestamp, you can’t believe that you even need this?? |
Others are still to be added...
Q : What are the advantages compared to other SDKs?
A : No matter how elegant or easy-to-use the SDK is, most of them require you to pass in the parameters according to the third-party parameter names. Then you have to read the documentation and do a lot of processing in the code. What I want is, from After fetching the order from the database, it can be processed once to access multiple payments.
Q : Is it unnecessary to read the third-party payment documents?
A : No, I suggest you still need to look at it, and some payments in the component (such as WeChat official account) need to pass in some special parameters. The component just helps you solve the annoying calling problem.
MIT