Skip to content

Commit

Permalink
Bugfix for Payment::refund(). #328
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Mar 8, 2016
1 parent c868b23 commit 480d9cb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/Payment/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,15 @@ public function reverseByTranscationId($transcationId)
*/
public function refund(
$orderNo,
$refundNo,
$totalFee,
$refundFee = null,
$opUserId = null,
$type = self::OUT_TRADE_NO
) {
$params = [
$type => $orderNo,
'out_refund_no' => $refundNo,
'total_fee' => $totalFee,
'refund_fee' => $refundFee ?: $totalFee,
'refund_fee_type' => $this->merchant->fee_type,
Expand All @@ -215,11 +217,12 @@ public function refund(
*/
public function refundByTranscationId(
$orderNo,
$refundNo,
$totalFee,
$refundFee = null,
$opUserId = null
) {
return $this->refund($orderNo, $totalFee, $refundFee, $opUserId, self::TRANSCATION_ID);
return $this->refund($orderNo, $refundNo, $totalFee, $refundFee, $opUserId, self::TRANSCATION_ID);
}

/**
Expand Down
9 changes: 6 additions & 3 deletions tests/Payment/PaymentAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,22 @@ public function testRefund()
{
$api = $this->getAPI();

$response = $api->refund('testTradeNo', 100);
$response = $api->refund('testTradeNo', 'testRefundNo', 100);
$this->assertEquals(API::API_REFUND, $response['api']);
$this->assertEquals('testRefundNo', $response['params']['out_refund_no']);
$this->assertEquals(100, $response['params']['total_fee']);
$this->assertEquals(100, $response['params']['refund_fee']);
$this->assertEquals('CNY', $response['params']['refund_fee_type']);
$this->assertEquals('testMerchantId', $response['params']['op_user_id']);
$this->assertEquals('testTradeNo', $response['params']['out_trade_no']);

$response = $api->refund('testTradeNo', 100, 50);
$response = $api->refund('testTradeNo','testRefundNo', 100, 50);
$this->assertEquals('testRefundNo', $response['params']['out_refund_no']);
$this->assertEquals(100, $response['params']['total_fee']);
$this->assertEquals(50, $response['params']['refund_fee']);

$response = $api->refund('testTradeNo', 100, 50, 'testRefundNo');
$response = $api->refund('testTradeNo', 'testRefundNo', 100, 50);
$this->assertEquals('testRefundNo', $response['params']['out_refund_no']);
$this->assertEquals(100, $response['params']['total_fee']);
$this->assertEquals(50, $response['params']['refund_fee']);
}
Expand Down

0 comments on commit 480d9cb

Please sign in to comment.