From 9d2224051180ad08d860e208054043f5973879d3 Mon Sep 17 00:00:00 2001 From: Ionut Cioflan Date: Tue, 19 Nov 2019 18:19:43 +0200 Subject: [PATCH 01/15] Add support for sandbox --- src/BaseAbstractGateway.php | 7 ++++ src/Message/CloseOrderRequest.php | 15 ++++++- src/Message/CreateMicroOrderRequest.php | 5 ++- src/Message/CreateOrderRequest.php | 53 +++++++++---------------- src/Message/QueryOrderRequest.php | 16 +++++++- src/Message/QueryRefundRequest.php | 15 ++++++- 6 files changed, 71 insertions(+), 40 deletions(-) diff --git a/src/BaseAbstractGateway.php b/src/BaseAbstractGateway.php index 93a85e1..403258d 100644 --- a/src/BaseAbstractGateway.php +++ b/src/BaseAbstractGateway.php @@ -6,6 +6,13 @@ abstract class BaseAbstractGateway extends AbstractGateway { + public function getDefaultParameters() + { + return array( + 'environment' => 'production' + ); + } + public function setTradeType($tradeType) { $this->setParameter('trade_type', $tradeType); diff --git a/src/Message/CloseOrderRequest.php b/src/Message/CloseOrderRequest.php index 3a6f46f..8c5795c 100644 --- a/src/Message/CloseOrderRequest.php +++ b/src/Message/CloseOrderRequest.php @@ -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 @@ -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); diff --git a/src/Message/CreateMicroOrderRequest.php b/src/Message/CreateMicroOrderRequest.php index 752a563..301367b 100644 --- a/src/Message/CreateMicroOrderRequest.php +++ b/src/Message/CreateMicroOrderRequest.php @@ -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 @@ -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); diff --git a/src/Message/CreateOrderRequest.php b/src/Message/CreateOrderRequest.php index c9e79af..c1282d1 100644 --- a/src/Message/CreateOrderRequest.php +++ b/src/Message/CreateOrderRequest.php @@ -14,8 +14,21 @@ */ class CreateOrderRequest extends BaseAbstractRequest { - protected $endpoint = 'https://api.mch.weixin.qq.com/pay/unifiedorder'; + protected $endpoint = 'https://api.mch.weixin.qq.com/pay/unifiedorder'; + protected $sandboxEndpoint = 'https://api.mch.weixin.qq.com/sandboxnew/pay/unifiedorder'; + + /** + * @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 @@ -42,7 +55,7 @@ public function getData() $this->validate('open_id'); } - $data = array( + $data = [ 'appid' => $this->getAppId(),//* 'mch_id' => $this->getMchId(), 'sub_appid' => $this->getSubAppId(), @@ -63,7 +76,7 @@ public function getData() 'limit_pay' => $this->getLimitPay(), 'openid' => $this->getOpenId(),//*(trade_type=JSAPI) 'nonce_str' => md5(uniqid()),//* - ); + ]; $data = array_filter($data); @@ -72,7 +85,6 @@ public function getData() return $data; } - /** * @return mixed */ @@ -81,7 +93,6 @@ public function getTradeType() return $this->getParameter('trade_type'); } - /** * @return mixed */ @@ -90,7 +101,6 @@ public function getDeviceInfo() return $this->getParameter('device_Info'); } - /** * @return mixed */ @@ -99,7 +109,6 @@ public function getBody() return $this->getParameter('body'); } - /** * @return mixed */ @@ -108,7 +117,6 @@ public function getDetail() return $this->getParameter('detail'); } - /** * @return mixed */ @@ -117,7 +125,6 @@ public function getAttach() return $this->getParameter('attach'); } - /** * @return mixed */ @@ -126,7 +133,6 @@ public function getOutTradeNo() return $this->getParameter('out_trade_no'); } - /** * @return mixed */ @@ -135,7 +141,6 @@ public function getFeeType() return $this->getParameter('fee_type'); } - /** * @return mixed */ @@ -144,7 +149,6 @@ public function getTotalFee() return $this->getParameter('total_fee'); } - /** * @return mixed */ @@ -153,7 +157,6 @@ public function getSpbillCreateIp() return $this->getParameter('spbill_create_ip'); } - /** * @return mixed */ @@ -162,7 +165,6 @@ public function getTimeStart() return $this->getParameter('time_start'); } - /** * @return mixed */ @@ -171,7 +173,6 @@ public function getTimeExpire() return $this->getParameter('time_expire'); } - /** * @return mixed */ @@ -180,7 +181,6 @@ public function getGoodsTag() return $this->getParameter('goods_tag'); } - /** * @return mixed */ @@ -189,7 +189,6 @@ public function getNotifyUrl() return $this->getParameter('notify_url'); } - /** * @return mixed */ @@ -198,7 +197,6 @@ public function getLimitPay() return $this->getParameter('limit_pay'); } - /** * @return mixed */ @@ -207,7 +205,6 @@ public function getOpenId() return $this->getParameter('open_id'); } - /** * @param mixed $deviceInfo */ @@ -216,7 +213,6 @@ public function setDeviceInfo($deviceInfo) $this->setParameter('device_Info', $deviceInfo); } - /** * @param mixed $body */ @@ -225,7 +221,6 @@ public function setBody($body) $this->setParameter('body', $body); } - /** * @param mixed $detail */ @@ -234,7 +229,6 @@ public function setDetail($detail) $this->setParameter('detail', $detail); } - /** * @param mixed $attach */ @@ -243,7 +237,6 @@ public function setAttach($attach) $this->setParameter('attach', $attach); } - /** * @param mixed $outTradeNo */ @@ -252,7 +245,6 @@ public function setOutTradeNo($outTradeNo) $this->setParameter('out_trade_no', $outTradeNo); } - /** * @param mixed $feeType */ @@ -261,7 +253,6 @@ public function setFeeType($feeType) $this->setParameter('fee_type', $feeType); } - /** * @param mixed $totalFee */ @@ -270,7 +261,6 @@ public function setTotalFee($totalFee) $this->setParameter('total_fee', $totalFee); } - /** * @param mixed $spbillCreateIp */ @@ -279,7 +269,6 @@ public function setSpbillCreateIp($spbillCreateIp) $this->setParameter('spbill_create_ip', $spbillCreateIp); } - /** * @param mixed $timeStart */ @@ -288,7 +277,6 @@ public function setTimeStart($timeStart) $this->setParameter('time_start', $timeStart); } - /** * @param mixed $timeExpire */ @@ -297,7 +285,6 @@ public function setTimeExpire($timeExpire) $this->setParameter('time_expire', $timeExpire); } - /** * @param mixed $goodsTag */ @@ -306,13 +293,11 @@ public function setGoodsTag($goodsTag) $this->setParameter('goods_tag', $goodsTag); } - public function setNotifyUrl($notifyUrl) { $this->setParameter('notify_url', $notifyUrl); } - /** * @param mixed $tradeType */ @@ -321,7 +306,6 @@ public function setTradeType($tradeType) $this->setParameter('trade_type', $tradeType); } - /** * @param mixed $limitPay */ @@ -330,7 +314,6 @@ public function setLimitPay($limitPay) $this->setParameter('limit_pay', $limitPay); } - /** * @param mixed $openId */ @@ -343,7 +326,7 @@ public function setOpenId($openId) /** * Send the request with specified data * - * @param mixed $data The data to send + * @param mixed $data The data to send * * @return ResponseInterface * @throws \Psr\Http\Client\Exception\NetworkException @@ -352,7 +335,7 @@ public function setOpenId($openId) 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 CreateOrderResponse($this, $payload); diff --git a/src/Message/QueryOrderRequest.php b/src/Message/QueryOrderRequest.php index c8ccabb..5dbeeb4 100644 --- a/src/Message/QueryOrderRequest.php +++ b/src/Message/QueryOrderRequest.php @@ -17,6 +17,20 @@ class QueryOrderRequest extends BaseAbstractRequest { protected $endpoint = 'https://api.mch.weixin.qq.com/pay/orderquery'; + protected $sandboxEndpoint = 'https://api.mch.weixin.qq.com/sandboxnew/pay/orderquery'; + + + /** + * @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 @@ -95,7 +109,7 @@ public function setTransactionId($transactionId) 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 QueryOrderResponse($this, $payload); diff --git a/src/Message/QueryRefundRequest.php b/src/Message/QueryRefundRequest.php index 0935f46..767a6c0 100644 --- a/src/Message/QueryRefundRequest.php +++ b/src/Message/QueryRefundRequest.php @@ -17,6 +17,19 @@ class QueryRefundRequest extends BaseAbstractRequest { protected $endpoint = 'https://api.mch.weixin.qq.com/pay/refundquery'; + protected $sandboxEndpoint = 'https://api.mch.weixin.qq.com/sandboxnew/pay/refundquery'; + + /** + * @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 @@ -153,7 +166,7 @@ public function setRefundId($refundId) */ 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); From 4ae1427ec10ff0c04cb77e126e5bb14f62c61539 Mon Sep 17 00:00:00 2001 From: Ionut Cioflan Date: Wed, 20 Nov 2019 11:35:00 +0200 Subject: [PATCH 02/15] Add missing getEnvironment() method --- src/Message/BaseAbstractRequest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Message/BaseAbstractRequest.php b/src/Message/BaseAbstractRequest.php index 30959db..cd212f3 100644 --- a/src/Message/BaseAbstractRequest.php +++ b/src/Message/BaseAbstractRequest.php @@ -10,6 +10,10 @@ */ abstract class BaseAbstractRequest extends AbstractRequest { + public function getEnvironment() + { + return $this->getParameter('environment'); + } /** * @return mixed From c300634f0bf0bf96eb97c1cb33b0e42e3d60adc9 Mon Sep 17 00:00:00 2001 From: Ionut Cioflan Date: Thu, 21 Nov 2019 11:26:17 +0200 Subject: [PATCH 03/15] Add sandbox getSignKey request/response --- src/Message/SandboxGetSignKeyRequest.php | 64 +++++++++++++++++++++++ src/Message/SandboxGetSignKeyResponse.php | 33 ++++++++++++ src/NativeGateway.php | 10 ++++ 3 files changed, 107 insertions(+) create mode 100644 src/Message/SandboxGetSignKeyRequest.php create mode 100644 src/Message/SandboxGetSignKeyResponse.php diff --git a/src/Message/SandboxGetSignKeyRequest.php b/src/Message/SandboxGetSignKeyRequest.php new file mode 100644 index 0000000..0f9dcd0 --- /dev/null +++ b/src/Message/SandboxGetSignKeyRequest.php @@ -0,0 +1,64 @@ + + */ +class SandboxGetSignKeyRequest + extends BaseAbstractRequest +{ + protected $endpoint = 'https://api.mch.weixin.qq.com/sandboxnew/pay/getsignkey'; + + /** + * 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 + * @throws InvalidRequestException + */ + public function getData() + { + $this->validate( + 'mch_id' + ); + + $data = array( + 'mch_id' => $this->getMchId(), + 'nonce_str' => md5(uniqid('', true)),//* + ); + + $data = array_filter($data); + + $data['sign'] = Helper::sign($data, $this->getApiKey()); + + return $data; + } + + /** + * Send the request with specified data + * + * @param mixed $data The data to send + * + * @return ResponseInterface + * @throws NetworkException + * @throws RequestException + */ + public function sendData($data) + { + $request = $this->httpClient->request('POST', $this->endpoint, [], Helper::array2xml($data)); + $response = $request->getBody(); + $responseData = Helper::xml2array($response); + + return $this->response = new SandboxGetSignKeyResponse($this, $responseData); + } +} \ No newline at end of file diff --git a/src/Message/SandboxGetSignKeyResponse.php b/src/Message/SandboxGetSignKeyResponse.php new file mode 100644 index 0000000..509d57f --- /dev/null +++ b/src/Message/SandboxGetSignKeyResponse.php @@ -0,0 +1,33 @@ + + */ +class SandboxGetSignKeyResponse + extends BaseAbstractResponse +{ + /** + * @var SandboxGetSignKeyRequest + */ + protected $request; + + /** + * Is the response successful? + * + * @return boolean + */ + public function isSuccessful() + { + return ($this->getData()['return_code'] ?? null) === 'SUCCESS'; + } + + public function getSandboxKey() + { + return $this->getData()['sandbox_signkey'] ?? null; + } +} \ No newline at end of file diff --git a/src/NativeGateway.php b/src/NativeGateway.php index d834492..ceb621d 100644 --- a/src/NativeGateway.php +++ b/src/NativeGateway.php @@ -29,4 +29,14 @@ public function shortenUrl($parameters = array()) { return $this->createRequest('\Omnipay\WechatPay\Message\ShortenUrlRequest', $parameters); } + + /** + * @param array $parameters + * + * @return \Omnipay\WechatPay\Message\DownloadBillRequest + */ + public function getSandboxSignKey($parameters = array()) + { + return $this->createRequest(\Omnipay\WechatPay\Message\SandboxGetSignKeyRequest::class, $parameters); + } } From 265777d800637e0cf72ef91fe11bf82529e98093 Mon Sep 17 00:00:00 2001 From: Ionut Cioflan Date: Thu, 21 Nov 2019 11:27:17 +0200 Subject: [PATCH 04/15] Add sandbox getSignKey request/response --- src/Message/SandboxGetSignKeyRequest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Message/SandboxGetSignKeyRequest.php b/src/Message/SandboxGetSignKeyRequest.php index 0f9dcd0..d34047c 100644 --- a/src/Message/SandboxGetSignKeyRequest.php +++ b/src/Message/SandboxGetSignKeyRequest.php @@ -17,7 +17,7 @@ class SandboxGetSignKeyRequest extends BaseAbstractRequest { - protected $endpoint = 'https://api.mch.weixin.qq.com/sandboxnew/pay/getsignkey'; + protected $sandboxEndpoint = 'https://api.mch.weixin.qq.com/sandboxnew/pay/getsignkey'; /** * Get the raw data array for this message. The format of this varies from gateway to @@ -55,7 +55,7 @@ public function getData() */ public function sendData($data) { - $request = $this->httpClient->request('POST', $this->endpoint, [], Helper::array2xml($data)); + $request = $this->httpClient->request('POST', $this->sandboxEndpoint, [], Helper::array2xml($data)); $response = $request->getBody(); $responseData = Helper::xml2array($response); From 44786d63cd0cf521b1126abb2ba5901642ec8878 Mon Sep 17 00:00:00 2001 From: Ionut Cioflan Date: Thu, 21 Nov 2019 11:51:51 +0200 Subject: [PATCH 05/15] Abstract gateway - add environment setter/getter --- src/BaseAbstractGateway.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/BaseAbstractGateway.php b/src/BaseAbstractGateway.php index 403258d..d32f688 100644 --- a/src/BaseAbstractGateway.php +++ b/src/BaseAbstractGateway.php @@ -13,6 +13,16 @@ public function getDefaultParameters() ); } + public function getEnvironment() + { + return $this->getParameter('environment'); + } + + public function setEnvironment($environment) + { + $this->setParameter('environment', $environment); + } + public function setTradeType($tradeType) { $this->setParameter('trade_type', $tradeType); From 5a2621968a5f2841db54de41763ceb97434b02e2 Mon Sep 17 00:00:00 2001 From: Ionut Cioflan Date: Thu, 21 Nov 2019 11:58:26 +0200 Subject: [PATCH 06/15] SandboxGetSignKeyResponse - add return message --- src/Message/SandboxGetSignKeyResponse.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Message/SandboxGetSignKeyResponse.php b/src/Message/SandboxGetSignKeyResponse.php index 509d57f..52f4da3 100644 --- a/src/Message/SandboxGetSignKeyResponse.php +++ b/src/Message/SandboxGetSignKeyResponse.php @@ -30,4 +30,9 @@ public function getSandboxKey() { return $this->getData()['sandbox_signkey'] ?? null; } + + public function getReturnMessage() + { + return $this->getData()['return_msg'] ?? $this->getData()['retmsg'] ?? null; + } } \ No newline at end of file From 98eb6d904d1edc9b818c085bf67de86b6a66f2d0 Mon Sep 17 00:00:00 2001 From: Ionut Cioflan Date: Fri, 22 Nov 2019 14:56:45 +0200 Subject: [PATCH 07/15] SandboxGetSignKey * Fix phpdoc --- src/NativeGateway.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NativeGateway.php b/src/NativeGateway.php index ceb621d..523b3f2 100644 --- a/src/NativeGateway.php +++ b/src/NativeGateway.php @@ -33,7 +33,7 @@ public function shortenUrl($parameters = array()) /** * @param array $parameters * - * @return \Omnipay\WechatPay\Message\DownloadBillRequest + * @return \Omnipay\WechatPay\Message\SandboxGetSignKeyRequest */ public function getSandboxSignKey($parameters = array()) { From 879bc0dd7dd4d9cb7633a36d5683f10653800f9e Mon Sep 17 00:00:00 2001 From: Ionut Cioflan Date: Fri, 22 Nov 2019 17:34:47 +0200 Subject: [PATCH 08/15] BaseAbstractResponse - implement getTransactionReference, getTransactionId methods --- src/Message/BaseAbstractResponse.php | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Message/BaseAbstractResponse.php b/src/Message/BaseAbstractResponse.php index 4b25f45..2df897e 100644 --- a/src/Message/BaseAbstractResponse.php +++ b/src/Message/BaseAbstractResponse.php @@ -6,11 +6,11 @@ /** * Class BaseAbstractResponse + * * @package Omnipay\WechatPay\Message */ abstract class BaseAbstractResponse extends AbstractResponse { - /** * Is the response successful? * @@ -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; } } From 8c86790581a1a37b14ffd03e9a9c3a9a0d3920bc Mon Sep 17 00:00:00 2001 From: Ionut Cioflan Date: Mon, 25 Nov 2019 11:59:04 +0200 Subject: [PATCH 09/15] BaseAbstractRequest - implement setEnvironment --- src/Message/BaseAbstractRequest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Message/BaseAbstractRequest.php b/src/Message/BaseAbstractRequest.php index cd212f3..eec29c1 100644 --- a/src/Message/BaseAbstractRequest.php +++ b/src/Message/BaseAbstractRequest.php @@ -15,6 +15,11 @@ public function getEnvironment() return $this->getParameter('environment'); } + public function setEnvironment($envinronment) + { + return $this->setParameter('environment', $envinronment); + } + /** * @return mixed */ From ca84b744bcd178df8fc462d4395ba7c5936c8773 Mon Sep 17 00:00:00 2001 From: Cazacu Catalin Date: Wed, 27 Nov 2019 18:15:55 +0200 Subject: [PATCH 10/15] - add support for sandbox --- src/Message/RefundOrderRequest.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Message/RefundOrderRequest.php b/src/Message/RefundOrderRequest.php index 651ef2b..b5de996 100644 --- a/src/Message/RefundOrderRequest.php +++ b/src/Message/RefundOrderRequest.php @@ -18,6 +18,21 @@ class RefundOrderRequest extends BaseAbstractRequest { protected $endpoint = 'https://api.mch.weixin.qq.com/secapi/pay/refund'; + protected $sandboxEndpoint = 'https://api.mch.weixin.qq.com/sandboxnew/pay/orderquery'; + + + /** + * @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 @@ -268,7 +283,7 @@ public function sendData($data) 'ssl_key' => $this->getKeyPath(), ]; - $result = $client->request('POST', $this->endpoint, $options)->getBody()->getContents(); + $result = $client->request('POST', $this->getEndpoint(), $options)->getBody()->getContents(); $responseData = Helper::xml2array($result); From 07e3f91949388f81a315b1318361c207fd962bd3 Mon Sep 17 00:00:00 2001 From: Cazacu Catalin Date: Wed, 27 Nov 2019 18:25:28 +0200 Subject: [PATCH 11/15] - add support for sandbox --- src/Message/RefundOrderRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Message/RefundOrderRequest.php b/src/Message/RefundOrderRequest.php index b5de996..93fbc28 100644 --- a/src/Message/RefundOrderRequest.php +++ b/src/Message/RefundOrderRequest.php @@ -18,7 +18,7 @@ class RefundOrderRequest extends BaseAbstractRequest { protected $endpoint = 'https://api.mch.weixin.qq.com/secapi/pay/refund'; - protected $sandboxEndpoint = 'https://api.mch.weixin.qq.com/sandboxnew/pay/orderquery'; + protected $sandboxEndpoint = 'https://api.mch.weixin.qq.com/sandboxnew/pay/refund'; /** From 9abea8886ab37e4b33d15f61f682b53c754e8e2c Mon Sep 17 00:00:00 2001 From: Ionut Cioflan Date: Thu, 19 Nov 2020 11:03:36 +0200 Subject: [PATCH 12/15] Fix code format --- src/Message/SandboxGetSignKeyRequest.php | 3 +-- src/Message/SandboxGetSignKeyResponse.php | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Message/SandboxGetSignKeyRequest.php b/src/Message/SandboxGetSignKeyRequest.php index d34047c..34644bf 100644 --- a/src/Message/SandboxGetSignKeyRequest.php +++ b/src/Message/SandboxGetSignKeyRequest.php @@ -14,8 +14,7 @@ * @package Omnipay\WechatPay\Message * @author Ionut Cioflan */ -class SandboxGetSignKeyRequest - extends BaseAbstractRequest +class SandboxGetSignKeyRequest extends BaseAbstractRequest { protected $sandboxEndpoint = 'https://api.mch.weixin.qq.com/sandboxnew/pay/getsignkey'; diff --git a/src/Message/SandboxGetSignKeyResponse.php b/src/Message/SandboxGetSignKeyResponse.php index 52f4da3..50a094d 100644 --- a/src/Message/SandboxGetSignKeyResponse.php +++ b/src/Message/SandboxGetSignKeyResponse.php @@ -8,8 +8,7 @@ * @package Omnipay\WechatPay\Message * @author Ionut Cioflan */ -class SandboxGetSignKeyResponse - extends BaseAbstractResponse +class SandboxGetSignKeyResponse extends BaseAbstractResponse { /** * @var SandboxGetSignKeyRequest @@ -23,16 +22,26 @@ class SandboxGetSignKeyResponse */ public function isSuccessful() { - return ($this->getData()['return_code'] ?? null) === 'SUCCESS'; + return isset($this->getData()['return_code']) && $this->getData()['return_code'] === 'SUCCESS'; } public function getSandboxKey() { - return $this->getData()['sandbox_signkey'] ?? null; + return isset($this->getData()['sandbox_signkey']) ? $this->getData()['sandbox_signkey'] : null; } public function getReturnMessage() { - return $this->getData()['return_msg'] ?? $this->getData()['retmsg'] ?? null; + if (isset($this->getData()['return_msg'])) { + return $this->getData()['return_msg']; + } + + + if (isset($this->getData()['retmsg'])) { + return $this->getData()['retmsg']; + } + + return null; } + } \ No newline at end of file From f353f2831b4979b520e92d8ad538dafbca9e15ca Mon Sep 17 00:00:00 2001 From: Ionut Cioflan Date: Thu, 19 Nov 2020 11:09:33 +0200 Subject: [PATCH 13/15] Fix code format --- src/Message/SandboxGetSignKeyRequest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Message/SandboxGetSignKeyRequest.php b/src/Message/SandboxGetSignKeyRequest.php index 34644bf..66c4c2c 100644 --- a/src/Message/SandboxGetSignKeyRequest.php +++ b/src/Message/SandboxGetSignKeyRequest.php @@ -60,4 +60,5 @@ public function sendData($data) return $this->response = new SandboxGetSignKeyResponse($this, $responseData); } + } \ No newline at end of file From 836ea268757398870480cd542249349f84d67bc1 Mon Sep 17 00:00:00 2001 From: Ionut Cioflan Date: Thu, 19 Nov 2020 11:11:03 +0200 Subject: [PATCH 14/15] Fix code format --- src/Message/SandboxGetSignKeyRequest.php | 1 - src/Message/SandboxGetSignKeyResponse.php | 1 - 2 files changed, 2 deletions(-) diff --git a/src/Message/SandboxGetSignKeyRequest.php b/src/Message/SandboxGetSignKeyRequest.php index 66c4c2c..34644bf 100644 --- a/src/Message/SandboxGetSignKeyRequest.php +++ b/src/Message/SandboxGetSignKeyRequest.php @@ -60,5 +60,4 @@ public function sendData($data) return $this->response = new SandboxGetSignKeyResponse($this, $responseData); } - } \ No newline at end of file diff --git a/src/Message/SandboxGetSignKeyResponse.php b/src/Message/SandboxGetSignKeyResponse.php index 50a094d..ae0ae98 100644 --- a/src/Message/SandboxGetSignKeyResponse.php +++ b/src/Message/SandboxGetSignKeyResponse.php @@ -43,5 +43,4 @@ public function getReturnMessage() return null; } - } \ No newline at end of file From 18646da0559979a0d15e99a7d2c909f9d575ee7c Mon Sep 17 00:00:00 2001 From: Ionut Cioflan Date: Thu, 19 Nov 2020 11:14:34 +0200 Subject: [PATCH 15/15] Fix code format --- src/Message/SandboxGetSignKeyRequest.php | 2 +- src/Message/SandboxGetSignKeyResponse.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Message/SandboxGetSignKeyRequest.php b/src/Message/SandboxGetSignKeyRequest.php index 34644bf..1de48e5 100644 --- a/src/Message/SandboxGetSignKeyRequest.php +++ b/src/Message/SandboxGetSignKeyRequest.php @@ -60,4 +60,4 @@ public function sendData($data) return $this->response = new SandboxGetSignKeyResponse($this, $responseData); } -} \ No newline at end of file +} diff --git a/src/Message/SandboxGetSignKeyResponse.php b/src/Message/SandboxGetSignKeyResponse.php index ae0ae98..f29dc20 100644 --- a/src/Message/SandboxGetSignKeyResponse.php +++ b/src/Message/SandboxGetSignKeyResponse.php @@ -43,4 +43,4 @@ public function getReturnMessage() return null; } -} \ No newline at end of file +}