diff --git a/src/Gateway.php b/src/Gateway.php index 83dcc64..183fa64 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -8,6 +8,7 @@ use Omnipay\Gomypay\Message\FetchTransactionRequest; use Omnipay\Gomypay\Message\GetPaymentInfoRequest; use Omnipay\Gomypay\Message\PurchaseRequest; +use Omnipay\Gomypay\Message\VoidRequest; use Omnipay\Gomypay\Traits\HasGomypay; /** @@ -51,6 +52,11 @@ public function fetchTransaction(array $options = []) return $this->createRequest(FetchTransactionRequest::class, $options); } + public function void(array $options = []) + { + return $this->createRequest(VoidRequest::class, $options); + } + public function getPaymentInfo(array $options = []) { return $this->createRequest(GetPaymentInfoRequest::class, $options); diff --git a/src/Message/FetchTransactionRequest.php b/src/Message/FetchTransactionRequest.php index 801a933..2c0ffa5 100644 --- a/src/Message/FetchTransactionRequest.php +++ b/src/Message/FetchTransactionRequest.php @@ -24,7 +24,7 @@ public function sendData($data) $response = $this->httpClient->request( 'POST', $this->getUrl('CallOrder.aspx'), - ['content-type' => 'application/json'], + ['content-type' => 'application/x-www-form-urlencoded'], http_build_query($data) ); $data = json_decode((string) $response->getBody(), true); diff --git a/src/Message/VoidRequest.php b/src/Message/VoidRequest.php new file mode 100644 index 0000000..b7ddaf8 --- /dev/null +++ b/src/Message/VoidRequest.php @@ -0,0 +1,62 @@ +getParameter('Goods_Return'); + } + + /** + * 退貨註記請填 1(申請退貨) + */ + public function setGoodsRetrun($value) + { + return $this->setParameter('Goods_Return', $value); + } + + public function getGoodsReturnReason() + { + return $this->getParameter('Goods_Return_Reason'); + } + + /** + * 退貨原因 + */ + public function setGoodsReturnReason($value) + { + return $this->setParameter('Goods_Return_Reason', $value); + } + + public function getData() + { + return [ + 'Order_No' => $this->getTransactionId(), + 'CustomerId' => $this->getCustomerId(), + 'Str_Check' => $this->getStrCheck(), + 'Goods_Return' => $this->getGoodsReturn() ?: 1, + 'Goods_Return_Reason' => $this->getGoodsReturnReason() ?: '退貨', + ]; + } + + public function sendData($data) + { + $response = $this->httpClient->request( + 'POST', + $this->getUrl('GoodReturn.aspx'), + ['content-type' => 'application/x-www-form-urlencoded'], + http_build_query($data) + ); + $data = json_decode((string) $response->getBody(), true); + + return $this->response = new VoidResponse($this, $data); + } +} diff --git a/src/Message/VoidResponse.php b/src/Message/VoidResponse.php new file mode 100644 index 0000000..e71346a --- /dev/null +++ b/src/Message/VoidResponse.php @@ -0,0 +1,21 @@ +data['result']; + } + + public function getMessage() + { + return $this->data['ret_msg']; + } +} diff --git a/tests/Message/VoidRequestTest.php b/tests/Message/VoidRequestTest.php new file mode 100644 index 0000000..7ada723 --- /dev/null +++ b/tests/Message/VoidRequestTest.php @@ -0,0 +1,38 @@ +request = new VoidRequest($this->getHttpClient(), $this->getHttpRequest()); + $this->request->initialize([ + 'CustomerId' => '42816104A05', + 'Str_Check' => '2b1bef9d8ab6a81e9a2739c6ecc64ef8', + 'test_mode' => true, + + 'transaction_id' => 'AH15482399052114', + ]); + } + + public function testGetData() + { + $this->setMockHttpResponse('VoidSuccess.txt'); + $response = $this->request->send(); + + $this->assertFalse($response->isSuccessful()); + $this->assertEquals('申請退貨完成', $response->getMessage()); + $this->assertEquals('1', $response->getCode()); + } +} diff --git a/tests/Mock/VoidSuccess.txt b/tests/Mock/VoidSuccess.txt new file mode 100644 index 0000000..5595917 --- /dev/null +++ b/tests/Mock/VoidSuccess.txt @@ -0,0 +1,7 @@ +HTTP/1.1 200 OK +Server: Apache +Date: Sun, 11 May 2014 21:17:31 GMT +Content-Type: application/json; charset=utf-8 +Status: 200 OK + +{"result":"1","ret_msg":"申請退貨完成"}