-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
203 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
<?php | ||
|
||
namespace Omnipay\NewebPay\Message; | ||
|
||
use Omnipay\Common\Exception\InvalidResponseException; | ||
use Omnipay\NewebPay\Traits\HasDefaults; | ||
|
||
class VoidRequest extends AbstractRequest | ||
{ | ||
use HasDefaults; | ||
|
||
protected $liveEndpoint = 'https://core.newebpay.com/API/CreditCard/Cancel'; | ||
|
||
protected $testEndpoint = 'https://ccore.newebpay.com/API/CreditCard/Cancel'; | ||
|
||
public function getEndpoint() | ||
{ | ||
return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint; | ||
} | ||
|
||
/** | ||
* 藍新金流交易序號. | ||
* 與商店訂單編號二擇一填入 | ||
* | ||
* @param string $value | ||
* @return self | ||
*/ | ||
public function setTradeNo($value) | ||
{ | ||
return $this->setTransactionReference($value); | ||
} | ||
|
||
/** | ||
* @return ?string | ||
*/ | ||
public function getTradeNo() | ||
{ | ||
return $this->getTransactionReference(); | ||
} | ||
|
||
/** | ||
* 單號類別. | ||
* 只限定填數字 1 或 2 | ||
* 1 表示使用商店訂單編號 | ||
* 2 表示使用藍新金流交易單號 | ||
* | ||
* @param int $value | ||
* @return self | ||
*/ | ||
public function setIndexType($value) | ||
{ | ||
return $this->setParameter('IndexType', $value); | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getIndexType() | ||
{ | ||
return $this->getParameter('IndexType') ?: 1; | ||
} | ||
|
||
public function getData() | ||
{ | ||
$data = array_filter([ | ||
'RespondType' => $this->getRespondType(), | ||
'Version' => $this->getVersion() ?: '1.0', | ||
'Amt' => (int) $this->getAmount(), | ||
'MerchantOrderNo' => $this->getTransactionId(), | ||
'TradeNo' => $this->getTransactionReference(), | ||
'IndexType' => $this->getIndexType(), | ||
'TimeStamp' => $this->getTimeStamp(), | ||
], static function ($value) { | ||
return $value !== null && $value !== ''; | ||
}); | ||
|
||
return $data; | ||
} | ||
|
||
/** | ||
* @throws InvalidResponseException | ||
*/ | ||
public function sendData($data) | ||
{ | ||
$response = $this->httpClient->request('POST', $this->getEndpoint(), [ | ||
'Content-Type' => 'application/x-www-form-urlencoded', | ||
], http_build_query([ | ||
'MerchantID_' => $this->getMerchantID(), | ||
'PostData_' => $this->encrypt($data), | ||
])); | ||
|
||
$result = []; | ||
parse_str(trim((string) $response->getBody()), $result); | ||
|
||
if (! hash_equals($result['CheckCode'], $this->checkCode($result))) { | ||
throw new InvalidResponseException('Incorrect CheckCode'); | ||
} | ||
|
||
return $this->response = new VoidResponse($this, $result); | ||
} | ||
} |
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,31 @@ | ||
<?php | ||
|
||
namespace Omnipay\NewebPay\Message; | ||
|
||
class VoidResponse extends AbstractResponse | ||
{ | ||
public function isSuccessful() | ||
{ | ||
return $this->getCode() === 'SUCCESS'; | ||
} | ||
|
||
public function getCode() | ||
{ | ||
return $this->data['Status']; | ||
} | ||
|
||
public function getMessage() | ||
{ | ||
return $this->data['Message']; | ||
} | ||
|
||
public function getTransactionId() | ||
{ | ||
return $this->data["MerchantOrderNo"]; | ||
} | ||
|
||
public function getTransactionReference() | ||
{ | ||
return $this->data["TradeNo"]; | ||
} | ||
} |
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,13 @@ | ||
HTTP/1.1 200 OK | ||
Content-Type: text/html; charset=UTF-8 | ||
Strict-Transport-Security: max-age=63072000 | ||
X-Akamai-Transformed: 9 234 0 pmb=mRUM,1 | ||
Expires: Sun, 12 Nov 2023 13:33:03 GMT | ||
Cache-Control: max-age=0, no-cache, no-store | ||
Pragma: no-cache | ||
Date: Sun, 12 Nov 2023 13:33:03 GMT | ||
Content-Length: 234 | ||
Connection: keep-alive | ||
Server-Timing: cdn-cache; desc=MISS, edge; dur=55, origin; dur=51, ak_p; desc="1699795982548_1752377015_139633467_10571_2669_5_828_-";dur=1 | ||
|
||
Status=TRA10047&Message=該交易不為授權成功狀態,不可放棄授權&MerchantID=MS350766787&Amt=500&MerchantOrderNo=test002&TradeNo=23111221191660146&CheckCode=479CE7E56302B9E30275BD0C440AC47D4F8A519D2C893C64BC172A35A9A473B6 |
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,13 @@ | ||
HTTP/1.1 200 OK | ||
Content-Type: text/html; charset=UTF-8 | ||
Strict-Transport-Security: max-age=63072000 | ||
X-Akamai-Transformed: 9 234 0 pmb=mRUM,1 | ||
Expires: Sun, 12 Nov 2023 13:33:03 GMT | ||
Cache-Control: max-age=0, no-cache, no-store | ||
Pragma: no-cache | ||
Date: Sun, 12 Nov 2023 13:33:03 GMT | ||
Content-Length: 234 | ||
Connection: keep-alive | ||
Server-Timing: cdn-cache; desc=MISS, edge; dur=55, origin; dur=51, ak_p; desc="1699795982548_1752377015_139633467_10571_2669_5_828_-";dur=1 | ||
|
||
Status=SUCCESS&Message=放棄授權成功&MerchantID=MS127874575&Amt=30&MerchantOrderNo=Vanespl_ec_1641348593&TradeNo=23111221191660146&CheckCode=A71CAB190914DD9432C49B49AA71A5A291EFFFBFFE149417818C0E04D3BEB40B |