-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #162 from maxsky/master
Add complete refund notify and adjust composer.json file.
- Loading branch information
Showing
8 changed files
with
339 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
namespace Omnipay\Alipay\Requests; | ||
|
||
use Omnipay\Alipay\Responses\AopCompleteRefundResponse; | ||
use Omnipay\Alipay\Responses\AopTradeQueryResponse; | ||
|
||
class AopCompleteRefundRequest extends AbstractAopRequest | ||
{ | ||
|
||
/** | ||
* Get the raw data array for this message. The format of this varies from gateway to | ||
* gateway, but will usually be either an associative array, or a SimpleXMLElement. | ||
* | ||
* @return mixed | ||
*/ | ||
public function getData() | ||
{ | ||
$this->validateParams(); | ||
|
||
return $this->getParams(); | ||
} | ||
|
||
|
||
public function validateParams() | ||
{ | ||
$this->validate('params'); | ||
} | ||
|
||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getParams() | ||
{ | ||
return $this->getParameter('params'); | ||
} | ||
|
||
|
||
/** | ||
* Send the request with specified data | ||
* | ||
* @param mixed $data The data to send | ||
* | ||
* @return AopCompleteRefundResponse | ||
*/ | ||
public function sendData($data) | ||
{ | ||
$request = new AopNotifyRequest($this->httpClient, $this->httpRequest); | ||
$request->initialize(['params' => $data]); | ||
$request->setEndpoint($this->getEndpoint()); | ||
$request->setAlipayPublicKey($this->getAlipayPublicKey()); | ||
$data = $request->send()->getData(); | ||
|
||
if (!array_get($data, 'trade_status')) { | ||
$tn = array_get($data, 'trade_no'); | ||
|
||
$request = new AopTradeQueryRequest($this->httpClient, $this->httpRequest); | ||
$request->initialize($this->getParameters()); | ||
$request->setEndpoint($this->getEndpoint()); | ||
$request->setBizContent(['trade_no' => $tn]); | ||
$request->setPrivateKey($this->getPrivateKey()); | ||
|
||
/** | ||
* @var AopTradeQueryResponse $response | ||
*/ | ||
$response = $request->send(); | ||
|
||
$tradeStatus = $response->getAlipayResponse('trade_status'); | ||
|
||
$data['trade_status'] = $tradeStatus; | ||
} | ||
return $this->response = new AopCompleteRefundResponse($this, $data); | ||
} | ||
|
||
|
||
/** | ||
* @param $value | ||
* | ||
* @return $this | ||
*/ | ||
public function setParams($value) | ||
{ | ||
return $this->setParameter('params', $value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Omnipay\Alipay\Responses; | ||
|
||
use Omnipay\Alipay\Requests\AopCompletePurchaseRequest; | ||
|
||
class AopCompleteRefundResponse extends AbstractResponse | ||
{ | ||
|
||
/** | ||
* @var AopCompletePurchaseRequest | ||
*/ | ||
protected $request; | ||
|
||
/** | ||
* Is the response successful? | ||
* | ||
* @return boolean | ||
*/ | ||
public function isSuccessful() | ||
{ | ||
return true; | ||
} | ||
|
||
public function getResponseText() | ||
{ | ||
if ($this->isSuccessful()) { | ||
return 'success'; | ||
} else { | ||
return 'fail'; | ||
} | ||
} | ||
|
||
public function isRefunded() | ||
{ | ||
$trade_status = array_get($this->data, 'trade_status'); | ||
if ($trade_status) { | ||
// 全额退款为 TRADE_CLOSED;非全额退款为 TRADE_SUCCESS | ||
if ($trade_status == 'TRADE_CLOSED' || $trade_status == 'TRADE_SUCCESS') { | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} elseif (array_get($this->data, 'code') == '10000') { | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
Oops, something went wrong.