汇付SDK
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hfpay-lib/src/factory/impl/TradeFactory.php

155 lines
4.3 KiB

<?php
namespace Tansilu\HfPayLib\factory\impl;
use Tansilu\HfPayLib\exception\ParamsException;
use Tansilu\HfPayLib\factory\object\trade\CloseOrder;
use Tansilu\HfPayLib\factory\object\trade\DelayDivide;
use Tansilu\HfPayLib\factory\object\trade\DelayDivideRequest;
use Tansilu\HfPayLib\factory\object\trade\RefundGoodsRequest;
use Tansilu\HfPayLib\factory\object\trade\RefundGoodsResponse;
use Tansilu\HfPayLib\factory\object\trade\RefundInfo;
use Tansilu\HfPayLib\factory\object\trade\RefundRequest;
use Tansilu\HfPayLib\factory\object\trade\UnifiedOrder;
use Tansilu\HfPayLib\factory\object\trade\UnifiedOrderRequest;
use Tansilu\HfPayLib\factory\object\trade\WithdrawCashRequest;
use Tansilu\HfPayLib\factory\object\trade\WithdrawCashResponse;
use Tansilu\HfPayLib\http\Factory;
/**
* 交易接口
*/
class TradeFactory extends Factory
{
/**
* 统一下单
*
* @param UnifiedOrderRequest $request
*
* @return UnifiedOrder|null
* @throws ParamsException
* @see https://hfpay.cloudpnr.com/customers/nft/#/transaction/unifiedOrder
*/
function unifiedOrder(
UnifiedOrderRequest $request
): ?UnifiedOrder
{
$params = $request->toParams();
$result = $this->post('/api/hfpwallet/pay033', $params);
if (!$result->isSuccess()) {
return null;
}
return UnifiedOrder::make($result->getBody());
}
/**
* 延时分账确认
*
* @param DelayDivideRequest $request
*
* @return DelayDivide|null
* @throws ParamsException
*
* @see https://hfpay.cloudpnr.com/customers/nft/#/transaction/delayDivideConfirm
*/
function delayDivideConfirm(DelayDivideRequest $request): ?DelayDivide
{
$params = $request->toParams();
$result = $this->post('/api/hfpwallet/pay033', $params);
if (!$result->isSuccess()) {
return null;
}
return DelayDivide::make($result->getBody());
}
/**
* 关闭订单
*
* @param string $orderId
* @param string $orderDate
* @param string $merPriv
*
* @return CloseOrder|null
*
* @see https://hfpay.cloudpnr.com/customers/nft/#/transaction/closeOrder
*/
function closeOrder(string $orderId, string $orderDate, string $merPriv = ''): ?CloseOrder
{
$params = [
'order_id' => $orderId,
'order_date' => $orderDate,
];
if (!empty($merPriv)) {
$params['mer_priv'] = $merPriv;
}
$result = $this->post('/api/hfpwallet/pay034', $params);
if (!$result->isSuccess()) {
return null;
}
return CloseOrder::make($result->getBody());
}
/**
* 退款
*
* @param RefundRequest $request
*
* @return RefundInfo|null
* @throws ParamsException
*
* @see https://hfpay.cloudpnr.com/customers/nft/#/transaction/refund
*/
function refund(RefundRequest $request): ?RefundInfo
{
$params = $request->toParams();
$result = $this->post('/api/hfpay/reb001', $params);
if (!$result->isSuccess()) {
return null;
}
return RefundInfo::make($result->getBody());
}
/**
* 退货
*
* @param RefundGoodsRequest $request
*
* @return RefundGoodsResponse|null
* @throws ParamsException
*
* @see https://hfpay.cloudpnr.com/customers/nft/#/transaction/refundGoods
*/
function refundGoods(RefundGoodsRequest $request): ?RefundGoodsResponse
{
$params = $request->toParams();
$result = $this->post('/api/hfpay/reb002', $params);
if (!$result->isSuccess()) {
return null;
}
return RefundGoodsResponse::make($result->getBody());
}
/**
* 取现
*
* @param WithdrawCashRequest $request
*
* @return WithdrawCashResponse|null
* @throws ParamsException
*
* @see https://hfpay.cloudpnr.com/customers/nft/#/transaction/withdrawCash
*/
function withdrawCash(WithdrawCashRequest $request): ?WithdrawCashResponse
{
$params = $request->toParams();
$result = $this->post('/api/acou/cash01', $params);
if (!$result->isSuccess()) {
return null;
}
return WithdrawCashResponse::make($result->getBody());
}
}