Skip to content

Commit

Permalink
Merge pull request #339 from overtrue/develop
Browse files Browse the repository at this point in the history
Fix bug: Payment::downloadBill() response error.
  • Loading branch information
overtrue committed Mar 16, 2016
2 parents 02a7031 + 90d85b3 commit 1a024ea
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
17 changes: 10 additions & 7 deletions src/Payment/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public function downloadBill($date, $type = self::BILL_TYPE_ALL)
'bill_type' => $type,
];

return $this->request(self::API_DOWNLOAD_BILL, $params);
return $this->request(self::API_DOWNLOAD_BILL, $params, 'post', [], true)->getBody();
}

/**
Expand Down Expand Up @@ -371,14 +371,15 @@ public function getMerchant()
/**
* Make a API request.
*
* @param string $api
* @param array $params
* @param string $method
* @param array $options
* @param string $api
* @param array $params
* @param string $method
* @param array $options
* @param boolean $options
*
* @return \EasyWeChat\Support\Collection
*/
protected function request($api, array $params, $method = 'post', array $options = [])
protected function request($api, array $params, $method = 'post', array $options = [], $returnResponse = false)
{
$params['appid'] = $this->merchant->app_id;
$params['mch_id'] = $this->merchant->merchant_id;
Expand All @@ -390,7 +391,9 @@ protected function request($api, array $params, $method = 'post', array $options
'body' => XML::build($params),
], $options);

return $this->parseResponse($this->getHttp()->request($api, $method, $options));
$response = $this->getHttp()->request($api, $method, $options);

return $returnResponse ? $response : $this->parseResponse($response);
}

/**
Expand Down
23 changes: 22 additions & 1 deletion tests/Payment/PaymentAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use EasyWeChat\Payment\Merchant;
use EasyWeChat\Payment\Order;
use EasyWeChat\Support\XML;
use Psr\Http\Message\ResponseInterface;

class PaymentAPITest extends PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -184,7 +185,27 @@ public function testQueryRefund()
*/
public function testDownloadBill()
{
$api = $this->getAPI();
$http = Mockery::mock(Http::class);

$http->shouldReceive('request')->andReturnUsing(function ($api, $method, $options) {
$params = XML::parse($options['body']);
$response = Mockery::mock(ResponseInterface::class);
$response->shouldReceive('getBody')->andReturn(compact('api', 'params'));

return $response;
});

$merchant = new Merchant([
'fee_type' => 'CNY',
'merchant_id' => 'testMerchantId',
'app_id' => 'wxTestAppId',
'device_info' => 'testDeviceInfo',
'key' => 'testKey',
'notify_url' => 'merchant_default_notify_url',
]);

$api = Mockery::mock('EasyWeChat\Payment\API[getHttp]', [$merchant]);
$api->shouldReceive('getHttp')->andReturn($http);

$response = $api->downloadBill('20150901');
$this->assertEquals(API::API_DOWNLOAD_BILL, $response['api']);
Expand Down

0 comments on commit 1a024ea

Please sign in to comment.