PHP新手30天實戰金流
, Laravel6
退款是根據商家 capture 交易進行。
若商家還沒有 capture, 等於買家的錢還在自己的帳戶中,所以沒辦法進行退款。
$captureRefund = $capture->refundCapturedPayment($refundRequest, $this->apiContext);
public function MerchantCapture(Order $order,Request $request){
$amount=$request->all()['amount'];
$authorization = Authorization::get($order->authorize_id, $this->apiContext);
$amt = new Amount();
$amt->setCurrency($order->currency_code)
->setTotal($amount);
### Capture
$capture = new Capture();
$capture->setAmount($amt);
// Perform a capture
try {
$getCapture = $authorization->capture($capture, $this->apiContext);
$this->out->writeln("getCapture: " . $getCapture);
$order->update([
'capture_id' =>$getCapture->id,
]);
} catch (\Throwable $th) {
//throw $th;
$this->out->writeln("capture error: " . $th);
}
}
ps 為了Demo方便直接把商家取款的按鈕放在訂單上(好拉 其實是還沒有寫管理者介面 嗚嗚..)
{"name":"MALFORMED_REQUEST","message":"The requested resource was not found","information_link":"https://developer.paypal
並沒有找到 capture 交易。原因可能是 capture id 不對。
[{"issue":"PARTIAL_REFUND_NOT_ALLOWED","description":"You cannot do a refund less than the original capture amount."}],"links":[{"href":"https://developer.paypal.com/docs/api/payments/v2/#error-PARTIAL_REFUND_NOT_ALLOWED","rel":"information_link"}]}
錯誤來自 refund 金額低於 capture 金額,改成一樣就ok了