Skip to content

Commit

Permalink
Fix payment tools API (#660)
Browse files Browse the repository at this point in the history
* Fix.

* Fix.
  • Loading branch information
mingyoung authored and overtrue committed Apr 22, 2017
1 parent a407161 commit a3fcf13
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
9 changes: 5 additions & 4 deletions src/Payment/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ class API extends AbstractAPI
const API_QUERY_REFUND = '/pay/refundquery';
const API_DOWNLOAD_BILL = '/pay/downloadbill';
const API_REPORT = '/payitil/report';
const API_URL_SHORTEN = '/tools/shorturl';
const API_AUTH_CODE_TO_OPENID = '/tools/authcodetoopenid';

const API_URL_SHORTEN = 'https://api.mch.weixin.qq.com/tools/shorturl';
const API_AUTH_CODE_TO_OPENID = 'https://api.mch.weixin.qq.com/tools/authcodetoopenid';

// order id types.
const TRANSACTION_ID = 'transaction_id';
Expand Down Expand Up @@ -321,7 +322,7 @@ public function downloadBill($date, $type = self::BILL_TYPE_ALL)
*/
public function urlShorten($url)
{
return $this->request($this->wrapApi(self::API_URL_SHORTEN), ['long_url' => $url]);
return $this->request(self::API_URL_SHORTEN, ['long_url' => $url]);
}

/**
Expand Down Expand Up @@ -359,7 +360,7 @@ public function report($api, $timeConsuming, $resultCode, $returnCode, array $ot
*/
public function authCodeToOpenId($authCode)
{
return $this->request($this->wrapApi(self::API_AUTH_CODE_TO_OPENID), ['auth_code' => $authCode]);
return $this->request(self::API_AUTH_CODE_TO_OPENID, ['auth_code' => $authCode]);
}

/**
Expand Down
21 changes: 16 additions & 5 deletions tests/Payment/PaymentAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class PaymentAPITest extends TestCase
*
* @return API
*/
public function getAPI()
public function getAPI($sandboxEnabled = false)
{
$http = \Mockery::mock(Http::class);

Expand All @@ -51,7 +51,7 @@ public function getAPI()
$api->shouldReceive('wrapApi')->passthru();
$api->shouldReceive('getHttp')->andReturn($http);

return $api;
return $api->sandboxMode($sandboxEnabled);
}

/**
Expand Down Expand Up @@ -229,10 +229,15 @@ public function testDownloadBill()
public function testUrlShorten()
{
$api = $this->getAPI();

$response = $api->urlShorten('http://easywechat.org');

$this->assertEquals($api->wrapApi(API::API_URL_SHORTEN), $response['api']);
$this->assertEquals('https://api.mch.weixin.qq.com/tools/shorturl', $response['api']);
$this->assertEquals('http://easywechat.org', $response['params']['long_url']);

$sandboxPayment = $this->getAPI(true);
$response = $sandboxPayment->urlShorten('http://easywechat.org');

$this->assertEquals('https://api.mch.weixin.qq.com/tools/shorturl', $response['api']);
$this->assertEquals('http://easywechat.org', $response['params']['long_url']);
}

Expand All @@ -245,7 +250,13 @@ public function testAuthCodeToOpenId()

$response = $api->authCodeToOpenId('authcode');

$this->assertEquals($api->wrapApi(API::API_AUTH_CODE_TO_OPENID), $response['api']);
$this->assertEquals('https://api.mch.weixin.qq.com/tools/authcodetoopenid', $response['api']);
$this->assertEquals('authcode', $response['params']['auth_code']);

$sandboxPayment = $this->getAPI(true);
$response = $sandboxPayment->authCodeToOpenId('authcode');

$this->assertEquals('https://api.mch.weixin.qq.com/tools/authcodetoopenid', $response['api']);
$this->assertEquals('authcode', $response['params']['auth_code']);
}

Expand Down

0 comments on commit a3fcf13

Please sign in to comment.