PHP新手30天實戰金流
, Laravel6
ECPay 退款,只有信用卡可以直接退,其餘收款方式皆需要賣家自行處理
ECPay 信用卡退款函式
//信用卡關帳/退刷/取消/放棄的方法
function DoAction() {
return $arFeedback = ECPay_DoAction::CheckOut(array_merge($this->Action,
array('MerchantID' => $this->MerchantID, 'EncryptType' => $this->EncryptType)
) ,
$this->HashKey ,$this->HashIV ,$this->ServiceURL);
}
第三方信用卡刷退比較
支付連 PChomePay:可全部刷退 / 部分刷退(每日次數無限制)
綠界科技 ECPay:可全部刷退 / 部分刷退(每日次數無限制)
藍新金流 NewebPay:可全部刷退 / 部分刷退(每日一次)
axios.post('{{ route('order.applyRefund', $order) }}', { reason: input }).then(function () {
swal('申請退款成功', '', 'success').then(function () {
location.reload();
});
})
public function applyRefund(Order $order, ApplyRefundRequest $request)
{
$this->authorize('own', $order);
try {
$paymentController = new PaymentController();
$paymentController->refund($order, $request);
} catch (\Throwable $th) {
//throw $th;
$out->writeln("error: ".$th);
}
if (!$order->paid_at) {
throw new InvalidRequestException('該訂單未支付,不可退款');
}
if ($order->refund_status !== Order::REFUND_STATUS_PENDING) {
throw new InvalidRequestException('該訂單已經申請過退款,請勿重複申請');
}
$extra = $order->extra ? : [];
$extra['refund_reason'] = $request->input('reason');
$order->update([
'refund_status' => Order::REFUND_STATUS_APPLIED,
'extra' => $extra,
]);
return $order;
}
$obj = new ECPay_AllInOne();
$ThatTime ="20:00:00";
if (time() >= strtotime($ThatTime)) {
$action = 'R';
}else {
$action = 'N';
}
$obj->DoAction();
$the_action_arr =array(
'MerchantTradeNo' => $order['payment_no'],
'TradeNo' => $order['trade_no'],
'Action' => $action,
'TotalAmount' => $order['total_amount']
);
$capture = array(
'MerchantTradeNo' => $order['payment_no'],
'CaptureAMT' => 0,
'UserRefundAMT' => 0,
'PlatformID' => ''
);
$tradeNo = array(
'DateType' => '',
'BeginDate' => $order['trade_no'],
'EndDate' => '',
'MediaFormated' => ''
);
$obj->Capture = $capture;
$obj->TradeNo = $tradeNo;
$obj->Action = $the_action_arr;
不知道原因
在 ECPay sdk 的 DoAction 函式:
{
"ServiceURL": "https://payment.ecpay.com.tw/CreditDetail/DoAction",
"ServiceMethod": "ServiceMethod",
"HashKey": "5294y06JbISpM5x9",
"HashIV": "v77hoKGq4kWxNNIS",
"MerchantID": "2000214",
"PaymentType": "aio",
"Send": {
"ReturnURL": "http://aa9beef5.ngrok.io/payment/website/listenPayResult",
"ClientBackURL": "http://aa9beef5.ngrok.io/orders",
"OrderResultURL": "http://aa9beef5.ngrok.io/payment/website/notify",
"MerchantTradeNo": "01029503931569996183",
"MerchantTradeDate": "2019/10/02 14:25:49",
"PaymentType": "aio",
"TotalAmount": "6623",
"TradeDesc": "ecpay test",
"ChoosePayment": "Credit",
"Remark": "",
"ChooseSubPayment": "",
"NeedExtraPaidInfo": "N",
"DeviceSource": "",
"IgnorePayment": "",
"PlatformID": "",
"InvoiceMark": "",
"Items": [],
"StoreID": "",
"CustomField1": "",
"CustomField2": "",
"CustomField3": "",
"CustomField4": "",
"HoldTradeAMT": 0
},
"SendExtend": [],
"Query": {
"MerchantTradeNo": "",
"TimeStamp": ""
},
"Action": {
"MerchantTradeNo": "01029503931569996183",
"TradeNo": "1910021403031486",
"Action": "N",
"TotalAmount": "6623"
},
"EncryptType": "1",
"Capture": {
"MerchantTradeNo": "",
"CaptureAMT": 0,
"UserRefundAMT": 0,
"PlatformID": ""
},
"TradeNo": {
"DateType": "",
"BeginDate": "",
"EndDate": "",
"MediaFormated": ""
},
"Trade": {
"CreditRefundId": "",
"CreditAmount": "",
"CreditCheckCode": ""
},
"Funding": {
"PayDateType": "",
"StartDate": "",
"EndDate": ""
}
}