basit / laravel-fastpay-integration
将FastPay支付网关集成到Laravel应用程序中
1.1.0
2023-08-06 11:28 UTC
Requires
- php: ^8.1
- illuminate/support: ^10.16
README
本软件包提供了与Fastpay的集成,允许您在Laravel应用程序中发起支付、验证支付、处理退款以及验证退款。
翻译
我们已提供不同语言的README翻译
请注意,这些翻译是通过Google Translate完成的,可能不完全准确。如果您发现任何不准确之处或有改进建议,请随时告知我们。您的反馈对我们非常重要!
安装
您可以通过composer安装此软件包
composer require basit/laravel-fastpay-integration
使用以下命令发布配置文件
php artisan vendor:publish --tag="fastpay"
安装软件包后,请确保将以下环境变量添加到您的.env文件中
FASTPAY_ENVIRONMENT="" FASTPAY_STORE_ID="" FASTPAY_STORE_PASSWORD=""
注意:请确保根据您的需求在.env文件中将FASTPAY_ENVIRONMENT变量设置为“staging”或“production”。
用法
1. 发起支付
use Basit\FastpayPayment\Fastpay; $cart = [ [ "name" => "Scarf", "qty" => 1, "unit_price" => 5000, ], [ "name" => "T-Shirt", "qty" => 2, "unit_price" => 10000, ] ]; // Replace YOUR_ORDER_ID with the unique identifier for your customer's order $orderId = "YOUR_ORDER_ID"; $response = Fastpay::initiate($orderId, $cart);
成功响应
{
"code": 200,
"messages": ["Payment Initiation request processed successfully."],
"data": {
"redirect_uri": "https://staging-pgw.fast-pay.iq/pay?token=fc334490-348d-4040-87d9-dc33ae5xxxxx"
}
}
支付通知验证(IPN URL)
在将用户重定向回您的网站之前,Fastpay会将带有支付信息的POST请求发送到您的IPN URL。此IPN通知对于验证交易和防止欺诈支付至关重要。您应该设置IPN URL以处理这些支付通知并根据接收到的数据进行验证。
当Fastpay向您的IPN URL发送IPN通知时,POST请求将包含以下数据
gw_transaction_id:事务的字母数字标识符。merchant_order_id:您的订单的字母数字标识符(用此值替换YOUR_ORDER_ID)。received_amount:表示收到支付金额的十进制值。currency:表示货币的字符串(例如,IQD)。status:表示支付状态的字符串(例如,“成功”)。customer_name:包含客户名称的字符串。customer_mobile_number:包含客户电话号码的字符串。at:事务的日期和时间,格式为“Y-m-d H:i:s”(例如,“2020-11-26 13:54:01”)。
您应使用这些信息来验证支付并确保交易是真实且准确的。
2. 验证支付
use Basit\FastpayPayment\Fastpay; // Replace YOUR_ORDER_ID with the merchant_order_id received from the IPN callback $merchantOrderId = "YOUR_ORDER_ID"; $response = Fastpay::validate($merchantOrderId);
成功响应
{
"code": 200,
"messages": [],
"data": {
"gw_transaction_id": "CUL1NUB713",
"merchant_order_id": "LAREVEORD1005",
"received_amount": "5000.00",
"currency": "IQD",
"customer_name": "John Doe",
"customer_mobile_number": "+964xxxxxxxxxx",
"at": "2023-06-14 18:06:30",
"transaction_id": "AXGOSG5527",
"order_id": "516867551564444475",
"customer_account_no": "+964xxxxxxxxxx",
"status": "Success",
"received_at": "2023-06-14 18:06:30"
}
}
3. 处理退款
use Basit\FastpayPayment\Fastpay; // Replace YOUR_ORDER_ID with the merchant_order_id for the order to be refunded $merchantOrderId = "YOUR_ORDER_ID"; // Replace CUSTOMER_PHONE_NUMBER with the customer's phone number $msisdn = "CUSTOMER_PHONE_NUMBER"; // Replace AMOUNT_TO_REFUND with the amount to be refunded (float) $amount = AMOUNT_TO_REFUND; $response = Fastpay::refund($merchantOrderId, $msisdn, $amount);
成功响应
{
"code": 200,
"messages": [],
"data": {
"summary": {
"recipient": {
"name": "John Doe",
"mobile_number": "+9640101010101",
"avatar": "https://revamp.fast-pay.iq/image/revamp.jpg",
}
"refund_invoice_id": "AUJHMA1634"
}
}
}
4. 验证退款
use Basit\FastpayPayment\Fastpay; // Replace YOUR_ORDER_ID with the merchant_order_id received from the IPN callback $merchantOrderId = "YOUR_ORDER_ID"; $response = Fastpay::refundValidate($merchantOrderId);
成功响应
{
"code": 200,
"messages": [],
"data": {
"order_id": "LAREVEORD5006",
"refund_status": true,
"status_checked_at": "2021-03-01 00:00:05"
}
}
更新日志
有关最近更改的更多信息,请参阅更新日志。
贡献
欢迎为此项目做出贡献
发现了问题或错误?
如果您遇到任何问题、错误或对此软件包有任何疑问,我们鼓励您在我们的GitHub Issues页面上报告。在创建新问题之前,请检查问题是否已报告。在报告问题时,请尽可能提供详细信息,包括复现步骤、预期行为和实际行为。
我们重视您的反馈,并将尽力及时解决问题。您的贡献对于改进此软件包至关重要。
鸣谢
许可
麻省理工学院许可证(MIT)。请参阅许可文件获取更多信息。