Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/BaseAbstractGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@

abstract class BaseAbstractGateway extends AbstractGateway
{
public function getDefaultParameters()
{
return array(
'environment' => 'production'
);
}

public function getEnvironment()
{
return $this->getParameter('environment');
}

public function setEnvironment($environment)
{
$this->setParameter('environment', $environment);
}

public function setTradeType($tradeType)
{
$this->setParameter('trade_type', $tradeType);
Expand Down
9 changes: 9 additions & 0 deletions src/Message/BaseAbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@
*/
abstract class BaseAbstractRequest extends AbstractRequest
{
public function getEnvironment()
{
return $this->getParameter('environment');
}

public function setEnvironment($envinronment)
{
return $this->setParameter('environment', $envinronment);
}

/**
* @return mixed
Expand Down
24 changes: 22 additions & 2 deletions src/Message/BaseAbstractResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

/**
* Class BaseAbstractResponse
*
* @package Omnipay\WechatPay\Message
*/
abstract class BaseAbstractResponse extends AbstractResponse
{

/**
* Is the response successful?
*
Expand All @@ -20,6 +20,26 @@ public function isSuccessful()
{
$data = $this->getData();

return isset($data['result_code']) && $data['result_code'] == 'SUCCESS';
return isset($data['result_code']) && $data['result_code'] === 'SUCCESS';
}

/**
* Gateway Reference
*
* @return null|string A reference provided by the gateway to represent this transaction
*/
public function getTransactionReference()
{
return $this->getData()['transaction_id'] ?? null;
}

/**
* Get the transaction ID as generated by the merchant website.
*
* @return string
*/
public function getTransactionId()
{
return $this->getData()['out_trade_no'] ?? null;
}
}
15 changes: 14 additions & 1 deletion src/Message/CloseOrderRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ class CloseOrderRequest extends BaseAbstractRequest
{
protected $endpoint = 'https://api.mch.weixin.qq.com/pay/closeorder';

protected $sandboxEndpoint = 'https://api.mch.weixin.qq.com/sandboxnew/pay/closeorder';

/**
* @return string
*/
public function getEndpoint()
{
if ($this->getEnvironment() == 'production') {
return $this->endpoint;
}

return $this->sandboxEndpoint;
}

/**
* Get the raw data array for this message. The format of this varies from gateway to
Expand Down Expand Up @@ -73,7 +86,7 @@ public function setOutTradeNo($outTradeNo)
public function sendData($data)
{
$body = Helper::array2xml($data);
$response = $this->httpClient->request('POST', $this->endpoint, [], $body)->getBody();
$response = $this->httpClient->request('POST', $this->getEndpoint(), [], $body)->getBody();
$payload = Helper::xml2array($response);

return $this->response = new CloseOrderResponse($this, $payload);
Expand Down
5 changes: 3 additions & 2 deletions src/Message/CreateMicroOrderRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
*/
class CreateMicroOrderRequest extends CreateOrderRequest
{
protected $endpoint = 'https://api.mch.weixin.qq.com/pay/micropay';
protected $endpoint = 'https://api.mch.weixin.qq.com/pay/micropay';

protected $sandboxEndpoint = 'https://api.mch.weixin.qq.com/sandboxnew/pay/micropay';

/**
* Get the raw data array for this message. The format of this varies from gateway to
Expand Down Expand Up @@ -77,7 +78,7 @@ public function setAuthCode($authCode)
*/
public function sendData($data)
{
$request = $this->httpClient->request('POST', $this->endpoint, [], Helper::array2xml($data));
$request = $this->httpClient->request('POST', $this->getEndpoint(), [], Helper::array2xml($data));
$response = $request->getBody();
$responseData = Helper::xml2array($response);

Expand Down
Loading